Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More configurable antialiasing #465

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions man/feh.pre
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,47 @@ add multiple paths.
.
Disable anti-aliasing for zooming, background setting etc.
.
.It Cm --aa-scroll int
.
0 disable antialiasing for scroll
.
.Pp
.
1 enable antialiasing after scroll
.

.It Cm --aa-scroll-page int
.
0 disable antialiasing for scroll-page
.
.Pp
.
1 enable antialiasing after scroll-page
.
.It Cm --aa-pan int
.
0 disable antialiasing for pan
.
.Pp
.
1 enable antialiasing after pan
.
.Pp
.
2 enable antialiasing during pan
.
.It Cm --aa-zoom int
.
0 disable antialiasing for zoom
.
.Pp
.
1 enable antialiasing after zoom
.
.Pp
.
2 enable antialiasing during zoom
.
.It Cm -I , --fullindex
.
Same as index mode, but with additional information below the thumbnails.
Expand Down
36 changes: 29 additions & 7 deletions src/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ static void feh_event_handle_ButtonPress(XEvent * ev)
- (winwid->im_click_offset_y * winwid->zoom);

winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 0);
if(opt.antialiasing_zoom == 0)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_zoom == 1 || opt.antialiasing_zoom == 2)
winwidget_render_image(winwid, 0, 0);

} else if (feh_is_bb(EVENT_zoom_out, button, state)) {
D(("Zoom_Out Button Press event\n"));
Expand Down Expand Up @@ -295,7 +298,10 @@ static void feh_event_handle_ButtonPress(XEvent * ev)
- (winwid->im_click_offset_y * winwid->zoom);

winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 0);
if(opt.antialiasing_zoom == 0)
Copy link
Contributor

@Ferada Ferada Jun 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block is copied too many times, make it a (well, several) function maybe?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(opt.antialiasing_zoom == 0)
if (opt.antialiasing_zoom == 0)

And so on for all the rest to match the existing style.

winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_zoom == 1 || opt.antialiasing_zoom == 2)
winwidget_render_image(winwid, 0, 0);

} else if (feh_is_bb(EVENT_reload_image, button, state)) {
D(("Reload Button Press event\n"));
Expand Down Expand Up @@ -353,7 +359,10 @@ static void feh_event_handle_ButtonRelease(XEvent * ev)
opt.mode = MODE_NORMAL;
winwid->mode = MODE_NORMAL;
winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 0);
if(opt.antialiasing_pan == 0)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_pan == 1 || opt.antialiasing_pan == 2)
winwidget_render_image(winwid, 0, 0);
} else if (opt.mode == MODE_NEXT) {
opt.mode = MODE_NORMAL;
winwid->mode = MODE_NORMAL;
Expand Down Expand Up @@ -399,7 +408,10 @@ static void feh_event_handle_ButtonRelease(XEvent * ev)
} else
winwidget_sanitise_offsets(winwid);

winwidget_render_image(winwid, 0, 0);
if(opt.antialiasing_zoom == 0)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_zoom == 1 || opt.antialiasing_zoom == 2)
winwidget_render_image(winwid, 0, 0);

} else if (feh_is_bb(EVENT_blur, button, state)) {
D(("Disabling Blur mode\n"));
Expand Down Expand Up @@ -554,7 +566,10 @@ static void feh_event_handle_MotionNotify(XEvent * ev)
winwid->im_y = winwid->click_offset_y
- (winwid->im_click_offset_y * winwid->zoom);

winwidget_render_image(winwid, 0, 1);
if(opt.antialiasing_zoom == 0 || opt.antialiasing_zoom == 1)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_zoom == 2)
winwidget_render_image(winwid, 0, 0);
}
} else if ((opt.mode == MODE_PAN) || (opt.mode == MODE_NEXT)) {
int orig_x, orig_y;
Expand Down Expand Up @@ -621,7 +636,11 @@ static void feh_event_handle_MotionNotify(XEvent * ev)

if ((winwid->im_x != orig_x)
|| (winwid->im_y != orig_y))
winwidget_render_image(winwid, 0, 1);
if(opt.antialiasing_pan == 0 || opt.antialiasing_pan == 1)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_pan == 2)
winwidget_render_image(winwid, 0, 0);

}
} else if (opt.mode == MODE_ROTATE) {
while (XCheckTypedWindowEvent(disp, ev->xmotion.window, MotionNotify, ev));
Expand All @@ -641,7 +660,10 @@ static void feh_event_handle_MotionNotify(XEvent * ev)
}
winwid->im_angle = (ev->xmotion.x - winwid->w / 2) / ((double) winwid->w / 2) * 3.1415926535;
D(("angle: %f\n", winwid->im_angle));
winwidget_render_image(winwid, 0, 1);
if(opt.antialiasing_zoom == 0 || opt.antialiasing_zoom == 1)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_zoom == 2)
winwidget_render_image(winwid, 0, 0);
}
} else if (opt.mode == MODE_BLUR) {
while (XCheckTypedWindowEvent(disp, ev->xmotion.window, MotionNotify, ev));
Expand Down
10 changes: 10 additions & 0 deletions src/help.raw
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ OPTIONS
--action[1-9] Extra actions triggered by pressing keys <1>to <9>
-G, --draw-actions Show the defined actions in the image window
--force-aliasing Disable antialiasing
--aa-scroll NUM 0 disable antialiasing for scroll
1 enable antialiasing after scroll
--aa-scroll-page NUM 0 disable antialiasing for scroll-page
1 enable antialiasing after scroll-page
--aa-pan NUM 0 disable antialiasing for pan
1 enable antialiasing after pan
2 enable antialiasing during pan
--aa-zoom NUM 0 disable antialiasing for zoom
1 enable antialiasing after zoom
2 enable antialiasing during zoom
-m, --montage Enable montage mode
-i, --index Create an index print of all images
--info CMD Run CMD and show its output in the image window
Expand Down
65 changes: 52 additions & 13 deletions src/keyevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,42 +493,66 @@ void feh_event_handle_generic(winwidget winwid, unsigned int state, KeySym keysy
else if (feh_is_kp(EVENT_scroll_right, state, keysym, button)) {
winwid->im_x -= opt.scroll_step;;
winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 1);
if(opt.antialiasing_scroll == 0)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_scroll == 1)
winwidget_render_image(winwid, 0, 0);
}
else if (feh_is_kp(EVENT_scroll_left, state, keysym, button)) {
winwid->im_x += opt.scroll_step;
winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 1);
if(opt.antialiasing_scroll == 0)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_scroll == 1)
winwidget_render_image(winwid, 0, 0);
}
else if (feh_is_kp(EVENT_scroll_down, state, keysym, button)) {
winwid->im_y -= opt.scroll_step;
winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 1);
if(opt.antialiasing_scroll == 0)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_scroll == 1)
winwidget_render_image(winwid, 0, 0);
}
else if (feh_is_kp(EVENT_scroll_up, state, keysym, button)) {
winwid->im_y += opt.scroll_step;
winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 1);
if(opt.antialiasing_scroll == 0)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_scroll == 1)
winwidget_render_image(winwid, 0, 0);
}
else if (feh_is_kp(EVENT_scroll_right_page, state, keysym, button)) {
winwid->im_x -= winwid->w;
winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 0);
if(opt.antialiasing_scroll_page == 0)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_scroll_page == 1)
winwidget_render_image(winwid, 0, 0);
}
else if (feh_is_kp(EVENT_scroll_left_page, state, keysym, button)) {
winwid->im_x += winwid->w;
winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 0);
if(opt.antialiasing_scroll_page == 0)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_scroll_page == 1)
winwidget_render_image(winwid, 0, 0);
}
else if (feh_is_kp(EVENT_scroll_down_page, state, keysym, button)) {
winwid->im_y -= winwid->h;
winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 0);
if(opt.antialiasing_scroll_page == 0)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_scroll_page == 1)
winwidget_render_image(winwid, 0, 0);
}
else if (feh_is_kp(EVENT_scroll_up_page, state, keysym, button)) {
winwid->im_y += winwid->h;
winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 0);
if(opt.antialiasing_scroll_page == 0)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_scroll_page == 1)
winwidget_render_image(winwid, 0, 0);
}
else if (feh_is_kp(EVENT_jump_back, state, keysym, button)) {
if (opt.slideshow)
Expand Down Expand Up @@ -613,7 +637,10 @@ void feh_event_handle_generic(winwidget winwid, unsigned int state, KeySym keysy
winwid->im_y = (winwid->h / 2) - (((winwid->h / 2) - winwid->im_y) /
winwid->old_zoom * winwid->zoom);
winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 0);
if(opt.antialiasing_zoom == 0)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_zoom == 1 || opt.antialiasing_zoom == 2)
winwidget_render_image(winwid, 0, 0);
}
else if (feh_is_kp(EVENT_zoom_out, state, keysym, button)) {
winwid->old_zoom = winwid->zoom;
Expand All @@ -627,24 +654,36 @@ void feh_event_handle_generic(winwidget winwid, unsigned int state, KeySym keysy
winwid->im_y = (winwid->h / 2) - (((winwid->h / 2) - winwid->im_y) /
winwid->old_zoom * winwid->zoom);
winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 0);
if(opt.antialiasing_zoom == 0)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_zoom == 1 || opt.antialiasing_zoom == 2)
winwidget_render_image(winwid, 0, 0);
}
else if (feh_is_kp(EVENT_zoom_default, state, keysym, button)) {
winwid->zoom = 1.0;
winwidget_center_image(winwid);
winwidget_render_image(winwid, 0, 0);
if(opt.antialiasing_zoom == 0)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_zoom == 1 || opt.antialiasing_zoom == 2)
winwidget_render_image(winwid, 0, 0);
}
else if (feh_is_kp(EVENT_zoom_fit, state, keysym, button)) {
feh_calc_needed_zoom(&winwid->zoom, winwid->im_w, winwid->im_h, winwid->w, winwid->h);
winwidget_center_image(winwid);
winwidget_render_image(winwid, 0, 0);
if(opt.antialiasing_zoom == 0)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_zoom == 1 || opt.antialiasing_zoom == 2)
winwidget_render_image(winwid, 0, 0);
}
else if (feh_is_kp(EVENT_zoom_fill, state, keysym, button)) {
int save_zoom = opt.zoom_mode;
opt.zoom_mode = ZOOM_MODE_FILL;
feh_calc_needed_zoom(&winwid->zoom, winwid->im_w, winwid->im_h, winwid->w, winwid->h);
winwidget_center_image(winwid);
winwidget_render_image(winwid, 0, 0);
if(opt.antialiasing_zoom == 0)
winwidget_render_image(winwid, 0, 1);
else if(opt.antialiasing_zoom == 1 || opt.antialiasing_zoom == 2)
winwidget_render_image(winwid, 0, 0);
opt.zoom_mode = save_zoom;
}
else if (feh_is_kp(EVENT_render, state, keysym, button)) {
Expand Down
56 changes: 56 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ void init_parse_options(int argc, char **argv)
/* if we're using xinerama, then enable it by default */
opt.xinerama = 1;
opt.xinerama_index = -1;
opt.antialiasing_scroll_page = 1;
opt.antialiasing_pan = 1;
opt.antialiasing_zoom = 1;

#endif /* HAVE_LIBXINERAMA */

feh_getopt_theme(argc, argv);
Expand Down Expand Up @@ -425,6 +429,10 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
{"conversion-timeout" , 1, 0, 245},
{"version-sort" , 0, 0, 246},
{"offset" , 1, 0, 247},
{"aa-scroll" , 1, 0, 248},
{"aa-scroll-page", 1, 0, 249},
{"aa-pan" , 1, 0, 250},
{"aa-zoom" , 1, 0, 251},
{0, 0, 0, 0}
};
int optch = 0, cmdx = 0;
Expand Down Expand Up @@ -762,6 +770,10 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
break;
case 235:
opt.force_aliasing = 1;
opt.antialiasing_scroll = 0;
opt.antialiasing_scroll_page = 0;
opt.antialiasing_pan = 0;
opt.antialiasing_zoom = 0;
break;
case 236:
opt.no_fehbg = 1;
Expand Down Expand Up @@ -810,6 +822,50 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
opt.offset_flags = XParseGeometry(optarg, &opt.offset_x,
&opt.offset_y, (unsigned int *)&discard, (unsigned int *)&discard);
break;
case 248:
if(!opt.force_aliasing) {
if(atoi(optarg) == 0 || atoi(optarg) == 1) {
opt.antialiasing_scroll = atoi(optarg);
} else {
weprintf("Unrecognised aa-scroll option \"%s\". "
"Defaulting to 0", optarg);
opt.antialiasing_scroll = 0;
}
}
break;
case 249:
if(!opt.force_aliasing) {
if(atoi(optarg) == 0 || atoi(optarg) == 1) {
opt.antialiasing_scroll_page = atoi(optarg);
} else {
weprintf("Unrecognised aa-scroll-page mode \"%s\". "
"Defaulting to 1", optarg);
opt.antialiasing_scroll_page = 1;
}
}
break;
case 250:
if(!opt.force_aliasing) {
if(atoi(optarg) == 0 || atoi(optarg) == 1 || atoi(optarg) == 2) {
opt.antialiasing_pan = atoi(optarg);
} else {
weprintf("Unrecognised aa-pan mode \"%s\". "
"Defaulting to 1", optarg);
opt.antialiasing_pan = 1;
}
}
break;
case 251:
if(!opt.force_aliasing) {
if(atoi(optarg) == 0 || atoi(optarg) == 1 || atoi(optarg) == 2) {
opt.antialiasing_zoom = atoi(optarg);
} else {
weprintf("Unrecognised aa-zoom mode \"%s\". "
"Defaulting to 1", optarg);
opt.antialiasing_zoom = 1;
}
}
break;
default:
break;
}
Expand Down
4 changes: 4 additions & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ struct __fehoptions {
char *index_info;

int force_aliasing;
int antialiasing_scroll;
int antialiasing_scroll_page;
int antialiasing_pan;
int antialiasing_zoom;
int thumb_w;
int thumb_h;
int limit_w;
Expand Down