mirror of
https://github.com/gryf/wmaker.git
synced 2026-01-03 20:34:14 +01:00
fixed bug in texture panel
This commit is contained in:
@@ -141,3 +141,101 @@ RScaleImage(RImage *image, unsigned new_width, unsigned new_height)
|
||||
return img;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RImage*
|
||||
RSmoothScaleImage(RImage *image, unsigned new_width, unsigned new_height)
|
||||
{
|
||||
int ox;
|
||||
int px, py;
|
||||
register int x, y, t;
|
||||
int dx, dy;
|
||||
unsigned char *sr, *sg, *sb, *sa;
|
||||
unsigned char *dr, *dg, *db, *da;
|
||||
RImage *img;
|
||||
|
||||
assert(new_width >= 0 && new_height >= 0);
|
||||
|
||||
if (new_width == image->width && new_height == image->height)
|
||||
return RCloneImage(image);
|
||||
|
||||
img = RCreateImage(new_width, new_height, image->data[3]!=NULL);
|
||||
|
||||
if (!img)
|
||||
return NULL;
|
||||
|
||||
dx = (image->width<<16)/new_width;
|
||||
dy = (image->height<<16)/new_height;
|
||||
|
||||
py = 0;
|
||||
|
||||
dr = img->data[0];
|
||||
dg = img->data[1];
|
||||
db = img->data[2];
|
||||
da = img->data[3];
|
||||
|
||||
if (image->data[3]!=NULL) {
|
||||
int ot;
|
||||
ot = -1;
|
||||
for (y=0; y<new_height; y++) {
|
||||
t = image->width*(py>>16);
|
||||
|
||||
sr = image->data[0]+t;
|
||||
sg = image->data[1]+t;
|
||||
sb = image->data[2]+t;
|
||||
sa = image->data[3]+t;
|
||||
|
||||
ot = t;
|
||||
ox = 0;
|
||||
px = 0;
|
||||
for (x=0; x<new_width; x++) {
|
||||
px += dx;
|
||||
|
||||
*(dr++) = *sr;
|
||||
*(dg++) = *sg;
|
||||
*(db++) = *sb;
|
||||
*(da++) = *sa;
|
||||
|
||||
t = (px - ox)>>16;
|
||||
ox += t<<16;
|
||||
|
||||
sr += t;
|
||||
sg += t;
|
||||
sb += t;
|
||||
sa += t;
|
||||
}
|
||||
py += dy;
|
||||
}
|
||||
} else {
|
||||
int ot;
|
||||
ot = -1;
|
||||
for (y=0; y<new_height; y++) {
|
||||
t = image->width*(py>>16);
|
||||
|
||||
sr = image->data[0]+t;
|
||||
sg = image->data[1]+t;
|
||||
sb = image->data[2]+t;
|
||||
|
||||
ot = t;
|
||||
ox = 0;
|
||||
px = 0;
|
||||
for (x=0; x<new_width; x++) {
|
||||
px += dx;
|
||||
|
||||
*(dr++) = *sr;
|
||||
*(dg++) = *sg;
|
||||
*(db++) = *sb;
|
||||
|
||||
t = (px-ox)>>16;
|
||||
ox += t<<16;
|
||||
|
||||
sr += t;
|
||||
sg += t;
|
||||
sb += t;
|
||||
}
|
||||
py += dy;
|
||||
}
|
||||
}
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user