mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 20:38:08 +01:00
I was trying to optimize this w/o using this, hope the change is right.
This commit is contained in:
129
wrlib/xpixmap.c
129
wrlib/xpixmap.c
@@ -45,6 +45,12 @@ get_shifts(unsigned long mask)
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define NORMALIZE_RED(pixel) ((rshift>0) ? ((pixel) & rmask) >> rshift \
|
||||||
|
: ((pixel) & rmask) << -rshift)
|
||||||
|
#define NORMALIZE_GREEN(pixel) ((gshift>0) ? ((pixel) & gmask) >> gshift \
|
||||||
|
: ((pixel) & gmask) << -gshift)
|
||||||
|
#define NORMALIZE_BLUE(pixel) ((bshift>0) ? ((pixel) & bmask) >> bshift \
|
||||||
|
: ((pixel) & bmask) << -bshift)
|
||||||
|
|
||||||
RImage*
|
RImage*
|
||||||
RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask)
|
RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask)
|
||||||
@@ -62,7 +68,7 @@ RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask)
|
|||||||
|
|
||||||
img = RCreateImage(image->width, image->height, mask!=NULL);
|
img = RCreateImage(image->width, image->height, mask!=NULL);
|
||||||
if (!img) {
|
if (!img) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -86,59 +92,86 @@ RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask)
|
|||||||
|
|
||||||
data = img->data;
|
data = img->data;
|
||||||
|
|
||||||
#define NORMALIZE_RED(pixel) ((rshift>0) ? ((pixel) & rmask) >> rshift \
|
|
||||||
: ((pixel) & rmask) << -rshift)
|
|
||||||
#define NORMALIZE_GREEN(pixel) ((gshift>0) ? ((pixel) & gmask) >> gshift \
|
|
||||||
: ((pixel) & gmask) << -gshift)
|
|
||||||
#define NORMALIZE_BLUE(pixel) ((bshift>0) ? ((pixel) & bmask) >> bshift \
|
|
||||||
: ((pixel) & bmask) << -bshift)
|
|
||||||
|
|
||||||
if (image->depth==1) {
|
if (image->depth==1) {
|
||||||
for (y = 0; y < image->height; y++) {
|
if (mask) {
|
||||||
for (x = 0; x < image->width; x++) {
|
for (y = 0; y < image->height; y++) {
|
||||||
pixel = XGetPixel(image, x, y);
|
for (x = 0; x < image->width; x++) {
|
||||||
if (pixel) {
|
pixel = XGetPixel(image, x, y);
|
||||||
*data++ = 0;
|
if (pixel) {
|
||||||
*data++ = 0;
|
*data++ = 0;
|
||||||
*data++ = 0;
|
*data++ = 0;
|
||||||
} else {
|
*data++ = 0;
|
||||||
*data++ = 0xff;
|
} else {
|
||||||
*data++ = 0xff;
|
*data++ = 0xff;
|
||||||
*data++ = 0xff;
|
*data++ = 0xff;
|
||||||
}
|
*data++ = 0xff;
|
||||||
if (mask)
|
}
|
||||||
*data++ = 0;
|
data++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for (y = 0; y < image->height; y++) {
|
||||||
|
for (x = 0; x < image->width; x++) {
|
||||||
|
pixel = XGetPixel(image, x, y);
|
||||||
|
if (pixel) {
|
||||||
|
*data++ = 0;
|
||||||
|
*data++ = 0;
|
||||||
|
*data++ = 0;
|
||||||
|
} else {
|
||||||
|
*data++ = 0xff;
|
||||||
|
*data++ = 0xff;
|
||||||
|
*data++ = 0xff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for (y = 0; y < image->height; y++) {
|
if (mask) {
|
||||||
for (x = 0; x < image->width; x++) {
|
for (y = 0; y < image->height; y++) {
|
||||||
pixel = XGetPixel(image, x, y);
|
for (x = 0; x < image->width; x++) {
|
||||||
*(data++) = NORMALIZE_RED(pixel);
|
pixel = XGetPixel(image, x, y);
|
||||||
*(data++) = NORMALIZE_GREEN(pixel);
|
*(data++) = NORMALIZE_RED(pixel);
|
||||||
*(data++) = NORMALIZE_BLUE(pixel);
|
*(data++) = NORMALIZE_GREEN(pixel);
|
||||||
if (mask)
|
*(data++) = NORMALIZE_BLUE(pixel);
|
||||||
*(data++) = 0;
|
data++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for (y = 0; y < image->height; y++) {
|
||||||
|
for (x = 0; x < image->width; x++) {
|
||||||
|
pixel = XGetPixel(image, x, y);
|
||||||
|
*(data++) = NORMALIZE_RED(pixel);
|
||||||
|
*(data++) = NORMALIZE_GREEN(pixel);
|
||||||
|
*(data++) = NORMALIZE_BLUE(pixel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data = img->data;
|
|
||||||
|
|
||||||
#define MIN(a,b) ((a)<(b)?(a):(b))
|
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||||
if (mask) {
|
if (mask) {
|
||||||
for (y = 0; y < MIN(mask->height, image->height); y++) {
|
data = img->data;
|
||||||
for (x = 0; x < image->width; x++) {
|
data += 3; /* Skip R, G & B */
|
||||||
|
for (y = 0; y < MIN(mask->height, image->height); y++) {
|
||||||
data += 3; /* Skip R, G & B */
|
for (x = 0; x < MIN(mask->width, image->width); x++) {
|
||||||
|
if (mask->width <= image->width && XGetPixel(mask, x, y)) {
|
||||||
if (mask->width <= image->width && XGetPixel(mask, x, y)) {
|
*data = 0xff;
|
||||||
*(data++) = 0xff;
|
} else {
|
||||||
} else {
|
*data = 0;
|
||||||
*(data++) = 0;
|
}
|
||||||
}
|
data += 4;
|
||||||
}
|
}
|
||||||
}
|
for (; x < image->width; x++) {
|
||||||
|
*data = 0;
|
||||||
|
data += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (; y < image->height; y++) {
|
||||||
|
for (x = 0; x < image->width; x++) {
|
||||||
|
*data = 0;
|
||||||
|
data += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user