forked from old/legacy-imlib2
fix a little of the rend code - never testyed that bit...
andf the imlib2_view works nicely iwth zooming too :) SVN revision: 1145
This commit is contained in:
parent
107bda1907
commit
4b69037861
136
demo/view.c
136
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;
|
||||
int no = 1;
|
||||
|
||||
file = argv[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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <X11/Xlib.h>
|
||||
#include <X11/extensions/XShm.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <ctype.h>
|
||||
#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);
|
||||
|
|
14
src/rend.c
14
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)
|
||||
|
|
Loading…
Reference in New Issue