forked from old/legacy-imlib2
allow for flipping whilst scaling and rendering... :)
SVN revision: 2589
This commit is contained in:
parent
2676818732
commit
2fbc8d2424
14
src/api.c
14
src/api.c
|
@ -830,8 +830,8 @@ imlib_blend_image_onto_image(Imlib_Image source_image,
|
|||
__imlib_DirtyImage(im_dst);
|
||||
__imlib_DirtyPixmapsForImage(im_dst);
|
||||
/* FIXME: hack to get around infinite loops for scaling down too far */
|
||||
if ((destination_width < (source_width >> 7)) ||
|
||||
(destination_height < (source_height >> 7)))
|
||||
if ((abs(destination_width) < (source_width >> 7)) ||
|
||||
(abs(destination_height) < (source_height >> 7)))
|
||||
__imlib_BlendImageToImage(im_src, im_dst, 0, ctxt_blend,
|
||||
merge_alpha, source_x, source_y, source_width,
|
||||
source_height, destination_x, destination_y,
|
||||
|
@ -1102,15 +1102,15 @@ imlib_create_cropped_image(int x, int y, int width, int height)
|
|||
im_old->loader->load(im_old, NULL, 0, 1);
|
||||
if (!(im_old->data))
|
||||
return NULL;
|
||||
im = __imlib_CreateImage(width, height, NULL);
|
||||
im->data = malloc(width * height *sizeof(DATA32));
|
||||
im = __imlib_CreateImage(abs(width), abs(height), NULL);
|
||||
im->data = malloc(abs(width * height) *sizeof(DATA32));
|
||||
if (!(im->data))
|
||||
{
|
||||
__imlib_FreeImage(im);
|
||||
return NULL;
|
||||
}
|
||||
__imlib_BlendImageToImage(im_old, im, 0, 0, 0,
|
||||
x, y, width, height,
|
||||
x, y, abs(width), abs(height),
|
||||
0, 0, width, height, NULL, IMLIB_OP_COPY);
|
||||
return (Imlib_Image)im;
|
||||
}
|
||||
|
@ -1128,8 +1128,8 @@ imlib_create_cropped_scaled_image(int source_x, int source_y, int source_width,
|
|||
im_old->loader->load(im_old, NULL, 0, 1);
|
||||
if (!(im_old->data))
|
||||
return NULL;
|
||||
im = __imlib_CreateImage(destination_width, destination_height, NULL);
|
||||
im->data = malloc(destination_width * destination_height *sizeof(DATA32));
|
||||
im = __imlib_CreateImage(abs(destination_width), abs(destination_height), NULL);
|
||||
im->data = malloc(abs(destination_width * destination_height) *sizeof(DATA32));
|
||||
if (!(im->data))
|
||||
{
|
||||
__imlib_FreeImage(im);
|
||||
|
|
18
src/blend.c
18
src/blend.c
|
@ -972,8 +972,8 @@ __imlib_BlendImageToImage(ImlibImage *im_src, ImlibImage *im_dst,
|
|||
sh = ssh;
|
||||
dx = ddx;
|
||||
dy = ddy;
|
||||
dw = ddw;
|
||||
dh = ddh;
|
||||
dw = abs(ddw);
|
||||
dh = abs(ddh);
|
||||
/* don't do anything if we have a 0 width or height image to render */
|
||||
/* if the input rect size < 0 don't render either */
|
||||
if ((dw <= 0) || (dh <= 0) || (sw <= 0) || (sh <= 0))
|
||||
|
@ -985,9 +985,9 @@ __imlib_BlendImageToImage(ImlibImage *im_src, ImlibImage *im_dst,
|
|||
psh = sh;
|
||||
CLIP(sx, sy, sw, sh, 0, 0, im_src->w, im_src->h);
|
||||
if (psx != sx)
|
||||
dx += ((sx - psx) * ddw) / ssw;
|
||||
dx += ((sx - psx) * abs(ddw)) / ssw;
|
||||
if (psy != sy)
|
||||
dy += ((sy - psy) * ddh) / ssh;
|
||||
dy += ((sy - psy) * abs(ddh)) / ssh;
|
||||
if (psw != sw)
|
||||
dw = (dw * sw) / psw;
|
||||
if (psh != sh)
|
||||
|
@ -1009,17 +1009,17 @@ __imlib_BlendImageToImage(ImlibImage *im_src, ImlibImage *im_dst,
|
|||
return;
|
||||
}
|
||||
if (psx != dx)
|
||||
sx += ((dx - psx) * ssw) / ddw;
|
||||
sx += ((dx - psx) * ssw) / abs(ddw);
|
||||
if (psy != dy)
|
||||
sy += ((dy - psy) * ssh) / ddh;
|
||||
sy += ((dy - psy) * ssh) / abs(ddh);
|
||||
if (psw != dw)
|
||||
sw = (sw * dw) / psw;
|
||||
if (psh != dh)
|
||||
sh = (sh * dh) / psh;
|
||||
dxx = dx - psx;
|
||||
dyy = dy - psy;
|
||||
dxx += (x2 * ddw) / ssw;
|
||||
dyy += (y2 * ddh) / ssh;
|
||||
dxx += (x2 * abs(ddw)) / ssw;
|
||||
dyy += (y2 * abs(ddh)) / ssh;
|
||||
|
||||
if ((dw > 0) && (sw == 0))
|
||||
sw = 1;
|
||||
|
@ -1033,7 +1033,7 @@ __imlib_BlendImageToImage(ImlibImage *im_src, ImlibImage *im_dst,
|
|||
return;
|
||||
}
|
||||
/* if we are scaling the image at all make a scaling buffer */
|
||||
if (!((sw == dw) && (sh == dh)))
|
||||
if (!((sw == dw) && (sh == dh) && (ddw > 0) && (ddh > 0)))
|
||||
{
|
||||
scaleinfo = __imlib_CalcScaleInfo(im_src, ssw, ssh, ddw, ddh, aa);
|
||||
if (!scaleinfo) return;
|
||||
|
|
10
src/rend.c
10
src/rend.c
|
@ -51,13 +51,13 @@ __imlib_RenderImage(Display *d, ImlibImage *im,
|
|||
(!(im->flags & F_HAS_ALPHA)), NULL);
|
||||
|
||||
/* dont do anything if we have a 0 widht or height image to render */
|
||||
if ((dw <= 0) || (dh <= 0))
|
||||
if ((dw == 0) || (dh == 0))
|
||||
return;
|
||||
/* if the input rect size < 0 dont render either */
|
||||
if ((sw <= 0) || (sh <= 0))
|
||||
return;
|
||||
/* if the output is too big (8k arbitary limit here) dont bother */
|
||||
if ((dw > 8192) || (dh > 8192))
|
||||
if ((abs(dw) > 8192) || (abs(dh) > 8192))
|
||||
return;
|
||||
/* clip the source rect to be within the actual image */
|
||||
psx = sx;
|
||||
|
@ -76,13 +76,13 @@ __imlib_RenderImage(Display *d, ImlibImage *im,
|
|||
dh = (dh * sh) / psh;
|
||||
/* do a second check to see if we now have invalid coords */
|
||||
/* dont do anything if we have a 0 widht or height image to render */
|
||||
if ((dw <= 0) || (dh <= 0))
|
||||
if ((dw == 0) || (dh == 0))
|
||||
return;
|
||||
/* if the input rect size < 0 dont render either */
|
||||
if ((sw <= 0) || (sh <= 0))
|
||||
return;
|
||||
/* if the output is too big (8k arbitary limit here) dont bother */
|
||||
if ((dw > 8192) || (dh > 8192))
|
||||
if ((abs(dw) > 8192) || (abs(dh) > 8192))
|
||||
return;
|
||||
/* if we are scaling the image at all make a scaling buffer */
|
||||
if (!((sw == dw) && (sh == dh)))
|
||||
|
@ -90,6 +90,8 @@ __imlib_RenderImage(Display *d, ImlibImage *im,
|
|||
scaleinfo = __imlib_CalcScaleInfo(im, sw, sh, dw, dh, antialias);
|
||||
if (!scaleinfo) return;
|
||||
}
|
||||
/*\ Sign not needed anymore \*/
|
||||
dw = abs(dw); dh = abs(dh);
|
||||
ct = __imlib_GetContext(d, v, cm, depth);
|
||||
actual_depth = depth;
|
||||
if (depth == 16)
|
||||
|
|
45
src/scale.c
45
src/scale.c
|
@ -28,8 +28,12 @@ __imlib_CalcYPoints(DATA32 *src, int sw, int sh, int dh, int b1, int b2)
|
|||
{
|
||||
DATA32 **p;
|
||||
int i, j = 0;
|
||||
int val, inc;
|
||||
int val, inc, rv = 0;
|
||||
|
||||
if (dh < 0) {
|
||||
dh = -dh;
|
||||
rv = 1;
|
||||
}
|
||||
p = malloc((dh + 1) * sizeof(DATA32 *));
|
||||
if (dh < (b1 + b2))
|
||||
{
|
||||
|
@ -65,6 +69,13 @@ __imlib_CalcYPoints(DATA32 *src, int sw, int sh, int dh, int b1, int b2)
|
|||
p[j++] = src + ((val >> 16) * sw);
|
||||
val += inc;
|
||||
}
|
||||
if (rv)
|
||||
for (i = dh / 2; --i >= 0; )
|
||||
{
|
||||
DATA32 *tmp = p[i];
|
||||
p[i] = p[dh - i - 1];
|
||||
p[dh - i - 1] = tmp;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -72,8 +83,12 @@ static int *
|
|||
__imlib_CalcXPoints(int sw, int dw, int b1, int b2)
|
||||
{
|
||||
int *p, i, j = 0;
|
||||
int val, inc;
|
||||
int val, inc, rv = 0;
|
||||
|
||||
if (dw < 0) {
|
||||
dw = -dw;
|
||||
rv = 1;
|
||||
}
|
||||
p = malloc((dw + 1) * sizeof(int));
|
||||
if (dw < (b1 + b2))
|
||||
{
|
||||
|
@ -109,14 +124,25 @@ __imlib_CalcXPoints(int sw, int dw, int b1, int b2)
|
|||
p[j++] = (val >> 16);
|
||||
val += inc;
|
||||
}
|
||||
if (rv)
|
||||
for (i = dw / 2; --i >= 0; )
|
||||
{
|
||||
int tmp = p[i];
|
||||
p[i] = p[dw - i - 1];
|
||||
p[dw - i - 1] = tmp;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static int *
|
||||
__imlib_CalcApoints(int s, int d, int b1, int b2, int up)
|
||||
{
|
||||
int *p, i, v, j = 0;
|
||||
|
||||
int *p, i, v, j = 0, rv = 0;
|
||||
|
||||
if (d < 0) {
|
||||
rv = 1;
|
||||
d = -d;
|
||||
}
|
||||
p = malloc(d * sizeof(int));
|
||||
if (d < (b1 + b2))
|
||||
{
|
||||
|
@ -181,6 +207,15 @@ __imlib_CalcApoints(int s, int d, int b1, int b2, int up)
|
|||
for (i = 0; i < b2; i++)
|
||||
p[j++] = (1 << (16 + 14)) + (1 << 14);
|
||||
}
|
||||
if (rv)
|
||||
{
|
||||
for (i = d / 2; --i >= 0; )
|
||||
{
|
||||
int tmp = p[i];
|
||||
p[i] = p[d - i - 1];
|
||||
p[d - i - 1] = tmp;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -212,7 +247,7 @@ __imlib_CalcScaleInfo(ImlibImage *im, int sw, int sh, int dw, int dh, char aa)
|
|||
|
||||
isi->pix_assert = im->data + im->w * im->h;
|
||||
|
||||
isi->xup_yup = (dw > sw) + ((dh > sh) << 1);
|
||||
isi->xup_yup = (abs(dw) >= sw) + ((abs(dh) >= sh) << 1);
|
||||
|
||||
isi->xpoints = __imlib_CalcXPoints(im->w, scw,
|
||||
im->border.left, im->border.right);
|
||||
|
|
|
@ -80,7 +80,7 @@ int main (int argc, char **argv)
|
|||
/**
|
||||
* Parse all the command line arguments
|
||||
*/
|
||||
if (!strcmp(argv[1], "-help"))
|
||||
if ((argc > 1) && (!strcmp(argv[1], "-help"))
|
||||
{
|
||||
printf ("Imlib2 program test. (Imlib v2.0.0.4)\n");
|
||||
printf ("usage: imlib2 [options] [file]\n");
|
||||
|
|
Loading…
Reference in New Issue