From 4b6903786148fdc8042ccc53c5c225c64ec91b85 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Tue, 2 Nov 1999 13:32:39 +0000 Subject: [PATCH] fix a little of the rend code - never testyed that bit... andf the imlib2_view works nicely iwth zooming too :) SVN revision: 1145 --- demo/view.c | 138 ++++++++++++++++++++++++++++++++++++++---- loaders/loader_argb.c | 6 +- loaders/loader_jpeg.c | 9 ++- loaders/loader_pnm.c | 19 ++++-- src/rend.c | 14 ++++- 5 files changed, 159 insertions(+), 27 deletions(-) diff --git a/demo/view.c b/demo/view.c index 013afde..5826a45 100644 --- a/demo/view.c +++ b/demo/view.c @@ -12,11 +12,12 @@ Display *disp; Window win; -Pixmap pm; +Pixmap pm = 0; Visual *vis; Colormap cm; int depth; int image_width = 0, image_height = 0; +Imlib_Image bg_im = NULL; static void progress(Imlib_Image im, char percent, int update_x, int update_y, @@ -26,20 +27,22 @@ static void progress(Imlib_Image im, char percent, int update_x, int update_y, int update_w, int update_h) { - static Imlib_Image bg_im = NULL; - /* first time it's called */ if (image_width == 0) { int x, y, onoff; - image_width = imlib_image_get_width(im); + image_width = imlib_image_get_width(im); image_height = imlib_image_get_height(im); + if (pm) + XFreePixmap(disp, pm); pm = XCreatePixmap(disp, win, image_width, image_height, depth); + if (bg_im) + imlib_free_image_and_decache(bg_im); bg_im = imlib_create_image(image_width, image_height); for (y = 0; y < image_height; y += 8) { - onoff = y & 0x1; + onoff = (y / 8) & 0x1; for (x = 0; x < image_width; x += 8) { Imlib_Color col; @@ -67,7 +70,7 @@ progress(Imlib_Image im, char percent, int update_x, int update_y, } imlib_render_image_part_on_drawable_at_size(bg_im, disp, pm, vis, cm, depth, - 0, 1, 0, + 0, 0, 0, 0, 0, image_width, image_height, 0, 0, @@ -78,7 +81,12 @@ progress(Imlib_Image im, char percent, int update_x, int update_y, XMapWindow(disp, win); XSync(disp, False); } -/* + imlib_blend_image_onto_image(im, bg_im, 0, 1, 0, + update_x, update_y, + update_w, update_h, + update_x, update_y, + update_w, update_h, + NULL, IMLIB_OP_COPY); imlib_render_image_part_on_drawable_at_size(bg_im, disp, pm, vis, cm, depth, 0, 1, 0, @@ -86,7 +94,7 @@ progress(Imlib_Image im, char percent, int update_x, int update_y, update_w, update_h, update_x, update_y, update_w, update_h, - NULL, IMLIB_OP_COPY);*/ + NULL, IMLIB_OP_COPY); XSetWindowBackgroundPixmap(disp, win, pm); XClearArea(disp, win, update_x, update_y, update_w, update_h, False); } @@ -96,8 +104,12 @@ main (int argc, char **argv) { Imlib_Image *im = NULL; char *file = NULL; - - file = argv[1]; + int no = 1; + + if (argc < 2) + return 1; + + file = argv[no]; disp = XOpenDisplay(NULL); vis = DefaultVisual(disp, DefaultScreen(disp)); depth = DefaultDepth(disp, DefaultScreen(disp)); @@ -106,7 +118,16 @@ main (int argc, char **argv) 10, 10, 0, 0, 0); XSelectInput(disp, win, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | PointerMotionMask); - im = imlib_load_image_with_progress_callback(file, progress, 0); + im = imlib_load_image_with_progress_callback(file, progress, 10); + while (!im) + { + no++; + if (no == argc) + exit(0); + file = argv[no]; + image_width = 0; + im = imlib_load_image_with_progress_callback(file, progress, 10); + } if (!im) { fprintf(stderr, "Image format not available\n"); @@ -116,18 +137,109 @@ main (int argc, char **argv) { int x, y, b; XEvent ev; + static int zoom_mode = 0, zx, zy; + static double zoom = 1.0; + char aa = 0, dith = 0; XNextEvent(disp, &ev); switch (ev.type) { - case Expose: + case ButtonPress: + b = ev.xbutton.button; + x = ev.xbutton.x; + y = ev.xbutton.y; + if (b == 3) + { + zoom_mode = 1; + zx = x; + zy = y; + imlib_render_image_part_on_drawable_at_size + (bg_im, + disp, pm, vis, cm, depth, + 0, 1, 0, + 0, 0, image_width, image_height, + 0, 0, image_width, image_height, + NULL, IMLIB_OP_COPY); + XSetWindowBackgroundPixmap(disp, win, pm); + XClearWindow(disp, win); + } break; case ButtonRelease: - exit(0); + b = ev.xbutton.button; + x = ev.xbutton.x; + y = ev.xbutton.y; + if (b == 3) + zoom_mode = 0; + if (b == 1) + { + no++; + if (no == argc) + exit(0); + file = argv[no]; + image_width = 0; + zoom = 1.0; + zoom_mode = 0; + imlib_free_image_and_decache(im); + im = imlib_load_image_with_progress_callback(file, progress, 10); + while (!im) + { + no++; + if (no == argc) + exit(0); + file = argv[no]; + image_width = 0; + im = imlib_load_image_with_progress_callback(file, progress, 10); + } + } break; case MotionNotify: + while (XCheckTypedWindowEvent(disp, win, MotionNotify, &ev)); x = ev.xmotion.x; y = ev.xmotion.y; + if (zoom_mode) + { + int sx, sy, sw, sh, dx, dy, dw, dh; + + zoom = ((double)x - (double)zx) / 32.0; + if (zoom < 0) + zoom = 1.0 + ((zoom * 32.0) / ((double)(zx + 1))); + else + zoom += 1.0; + if (zoom <= 0.0001) + zoom = 0.0001; + if (zoom > 1.0) + { + dx = 0; + dy = 0; + dw = image_width; + dh = image_height; + + sx = zx - (zx / zoom); + sy = zy - (zy / zoom); + sw = image_width / zoom; + sh = image_height / zoom; + } + else + { + dx = zx - (zx * zoom); + dy = zy - (zy * zoom); + dw = image_width * zoom; + dh = image_height * zoom; + + sx = 0; + sy = 0; + sw = image_width; + sh = image_height; + } + imlib_render_image_part_on_drawable_at_size + (bg_im, + disp, pm, vis, cm, depth, + aa, dith, 0, + sx, sy, sw, sh, dx, dy, dw, dh, + NULL, IMLIB_OP_COPY); + XSetWindowBackgroundPixmap(disp, win, pm); + XClearWindow(disp, win); + } default: break; diff --git a/loaders/loader_argb.c b/loaders/loader_argb.c index c34f3d6..ad429c2 100644 --- a/loaders/loader_argb.c +++ b/loaders/loader_argb.c @@ -102,7 +102,8 @@ load (ImlibImage *im, int l; per = (char)((100 * y) / im->h); - if ((per - pper) >= progress_granularity) + if (((per - pper) >= progress_granularity) || + (y == (im->h - 1))) { l = y - pl; progress(im, per, 0, (y - l), im->w, l); @@ -163,7 +164,8 @@ save (ImlibImage *im, int l; per = (char)((100 * y) / im->h); - if ((per - pper) >= progress_granularity) + if (((per - pper) >= progress_granularity) || + (y == (im->h - 1))) { l = y - pl; progress(im, per, 0, (y - l), im->w, l); diff --git a/loaders/loader_jpeg.c b/loaders/loader_jpeg.c index 9700199..0d5b8c1 100644 --- a/loaders/loader_jpeg.c +++ b/loaders/loader_jpeg.c @@ -141,7 +141,8 @@ load (ImlibImage *im, int per; per = (l * 100) / h; - if ((per - count) >= progress_granularity) + if (((per - count) >= progress_granularity) || + ((h - l) <= cinfo.rec_outbuf_height)) { count = per; progress(im, per, 0, prevy, w, scans + l - prevy); @@ -178,7 +179,8 @@ load (ImlibImage *im, int per; per = (l * 100) / h; - if ((per - count) >= progress_granularity) + if (((per - count) >= progress_granularity) || + ((h - l) <= cinfo.rec_outbuf_height)) { count = per; progress(im, per, 0, prevy, w, l + scans - prevy); @@ -283,7 +285,8 @@ save (ImlibImage *im, int l; per = (char)((100 * y) / im->h); - if ((per - pper) >= progress_granularity) + if (((per - pper) >= progress_granularity) || + (y == (im->h - 1))) { l = y - pl; progress(im, per, 0, (y - l), im->w, l); diff --git a/loaders/loader_pnm.c b/loaders/loader_pnm.c index df473f3..17365b8 100644 --- a/loaders/loader_pnm.c +++ b/loaders/loader_pnm.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "image.h" char load (ImlibImage *im, @@ -237,7 +238,8 @@ load (ImlibImage *im, int l; per = (char)((100 * y) / im->h); - if ((per - pper) >= progress_granularity) + if (((per - pper) >= progress_granularity) || + (y == (im->h - 1))) { l = y - pl; progress(im, per, 0, (y - l), im->w, l); @@ -294,7 +296,8 @@ load (ImlibImage *im, int l; per = (char)((100 * y) / im->h); - if ((per - pper) >= progress_granularity) + if (((per - pper) >= progress_granularity) || + (y == (im->h - 1))) { l = y - pl; progress(im, per, 0, (y - l), im->w, l); @@ -341,7 +344,8 @@ load (ImlibImage *im, int l; per = (char)((100 * y) / im->h); - if ((per - pper) >= progress_granularity) + if (((per - pper) >= progress_granularity) || + (y == (im->h - 1))) { l = y - pl; progress(im, per, 0, (y - l), im->w, l); @@ -398,7 +402,8 @@ load (ImlibImage *im, int l; per = (char)((100 * y) / im->h); - if ((per - pper) >= progress_granularity) + if (((per - pper) >= progress_granularity) || + (y == (im->h - 1))) { l = y - pl; progress(im, per, 0, (y - l), im->w, l); @@ -474,7 +479,8 @@ save (ImlibImage *im, int l; per = (char)((100 * y) / im->h); - if ((per - pper) >= progress_granularity) + if (((per - pper) >= progress_granularity) || + (y == (im->h - 1))) { l = y - pl; progress(im, per, 0, (y - l), im->w, l); @@ -517,7 +523,8 @@ save (ImlibImage *im, int l; per = (char)((100 * y) / im->h); - if ((per - pper) >= progress_granularity) + if (((per - pper) >= progress_granularity) || + (y == (im->h - 1))) { l = y - pl; progress(im, per, 0, (y - l), im->w, l); diff --git a/src/rend.c b/src/rend.c index 181dffa..c9d5e65 100644 --- a/src/rend.c +++ b/src/rend.c @@ -213,12 +213,20 @@ __imlib_RenderImage(Display *d, ImlibImage *im, if (anitalias) { if (IMAGE_HAS_ALPHA(im)) - __imlib_ScaleAARGBA(ypoints, xpoints, buf, xapoints, yapoints, xup, yup, dx, dy + y, 0, 0, dw, hh, dw, im->w); + __imlib_ScaleAARGBA(ypoints, xpoints, buf, xapoints, + yapoints, xup, yup, + ((sx * dw) / sw), ((sy * dh) / sh) + y, + 0, 0, dw, hh, dw, im->w); else - __imlib_ScaleAARGB(ypoints, xpoints, buf, xapoints, yapoints, xup, yup, dx, dy + y, 0, 0, dw, hh, dw, im->w); + __imlib_ScaleAARGB(ypoints, xpoints, buf, xapoints, + yapoints, xup, yup, + ((sx * dw) / sw), ((sy * dh) / sh) + y, + 0, 0, dw, hh, dw, im->w); } else - __imlib_ScaleSampleRGBA(ypoints, xpoints, buf, dx, dy + y, 0, 0, dw, hh, dw); + __imlib_ScaleSampleRGBA(ypoints, xpoints, buf, + ((sx * dw) / sw), ((sy * dh) / sh) + y, + 0, 0, dw, hh, dw); jump = 0; pointer = buf; if (cmod)