diff --git a/src/lib/common.h b/src/lib/common.h index 201df30..0df2338 100644 --- a/src/lib/common.h +++ b/src/lib/common.h @@ -40,6 +40,11 @@ #define PIXEL_ARGB(a, r, g, b) ((a) << 24) | ((r) << 16) | ((g) << 8) | (b) +#define PIXEL_A(argb) (((argb) >> 24) & 0xff) +#define PIXEL_R(argb) (((argb) >> 16) & 0xff) +#define PIXEL_G(argb) (((argb) >> 8) & 0xff) +#define PIXEL_B(argb) (((argb) ) & 0xff) + #ifdef DO_MMX_ASM int __imlib_get_cpuid(void); diff --git a/src/modules/loaders/loader_bmp.c b/src/modules/loaders/loader_bmp.c index 0193cb9..fc868fa 100644 --- a/src/modules/loaders/loader_bmp.c +++ b/src/modules/loaders/loader_bmp.c @@ -941,9 +941,9 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity) for (j = 0; j < im->w; j++) { pixel = im->data[im->w * (im->h - i - 1) + j]; - WriteleByte(f, pixel & 0xff); - WriteleByte(f, (pixel >> 8) & 0xff); - WriteleByte(f, (pixel >> 16) & 0xff); + WriteleByte(f, PIXEL_B(pixel)); + WriteleByte(f, PIXEL_G(pixel)); + WriteleByte(f, PIXEL_R(pixel)); } for (j = 0; j < pad; j++) WriteleByte(f, 0); diff --git a/src/modules/loaders/loader_jpeg.c b/src/modules/loaders/loader_jpeg.c index 314b61d..3957987 100644 --- a/src/modules/loaders/loader_jpeg.c +++ b/src/modules/loaders/loader_jpeg.c @@ -286,10 +286,11 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity) /* convcert scaline from ARGB to RGB packed */ for (j = 0, i = 0; i < im->w; i++) { - buf[j++] = ((*ptr) >> 16) & 0xff; - buf[j++] = ((*ptr) >> 8) & 0xff; - buf[j++] = ((*ptr)) & 0xff; - ptr++; + DATA32 pixel = *ptr++; + + buf[j++] = PIXEL_R(pixel); + buf[j++] = PIXEL_G(pixel); + buf[j++] = PIXEL_B(pixel); } /* write scanline */ jbuf = (JSAMPROW *) (&buf); diff --git a/src/modules/loaders/loader_png.c b/src/modules/loaders/loader_png.c index fb9541f..a6533e5 100644 --- a/src/modules/loaders/loader_png.c +++ b/src/modules/loaders/loader_png.c @@ -347,13 +347,16 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity) { for (j = 0, x = 0; x < im->w; x++) { - data[j++] = (ptr[x] >> 16) & 0xff; - data[j++] = (ptr[x] >> 8) & 0xff; - data[j++] = (ptr[x]) & 0xff; + DATA32 pixel = ptr[x]; + + data[j++] = PIXEL_R(pixel); + data[j++] = PIXEL_G(pixel); + data[j++] = PIXEL_B(pixel); } row_ptr = (png_bytep) data; } png_write_rows(png_ptr, &row_ptr, 1); + if (progress) { char per; diff --git a/src/modules/loaders/loader_pnm.c b/src/modules/loaders/loader_pnm.c index 1b63b3c..b29c626 100644 --- a/src/modules/loaders/loader_pnm.c +++ b/src/modules/loaders/loader_pnm.c @@ -467,12 +467,13 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity) bptr = buf; for (x = 0; x < im->w; x++) { - bptr[0] = ((*ptr) >> 16) & 0xff; - bptr[1] = ((*ptr) >> 8) & 0xff; - bptr[2] = ((*ptr)) & 0xff; - bptr[3] = ((*ptr) >> 24) & 0xff; + DATA32 pixel = *ptr++; + + bptr[0] = PIXEL_R(pixel); + bptr[1] = PIXEL_G(pixel); + bptr[2] = PIXEL_B(pixel); + bptr[3] = PIXEL_A(pixel); bptr += 4; - ptr++; } fwrite(buf, im->w * 4, 1, f); if (progress && @@ -495,11 +496,12 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity) bptr = buf; for (x = 0; x < im->w; x++) { - bptr[0] = ((*ptr) >> 16) & 0xff; - bptr[1] = ((*ptr) >> 8) & 0xff; - bptr[2] = ((*ptr)) & 0xff; + DATA32 pixel = *ptr++; + + bptr[0] = PIXEL_R(pixel); + bptr[1] = PIXEL_G(pixel); + bptr[2] = PIXEL_B(pixel); bptr += 3; - ptr++; } fwrite(buf, im->w * 3, 1, f); if (progress && diff --git a/src/modules/loaders/loader_tga.c b/src/modules/loaders/loader_tga.c index 9b2f715..88818ee 100644 --- a/src/modules/loaders/loader_tga.c +++ b/src/modules/loaders/loader_tga.c @@ -122,27 +122,17 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity) for (y = 0; y < im->h; y++) { int x; - unsigned char r, g, b, a; /* for each pixel in the row */ for (x = 0; x < im->w; x++) { + DATA32 pixel = *dataptr++; + + *bufptr++ = PIXEL_B(pixel); + *bufptr++ = PIXEL_G(pixel); + *bufptr++ = PIXEL_R(pixel); if (im->flags & F_HAS_ALPHA) - { - READ_RGBA(dataptr, r, g, b, a); - *bufptr++ = b; - *bufptr++ = g; - *bufptr++ = r; - *bufptr++ = a; - } - else - { - READ_RGB(dataptr, r, g, b); - *bufptr++ = b; - *bufptr++ = g; - *bufptr++ = r; - } - dataptr++; + *bufptr++ = PIXEL_A(pixel); } /* end for (each pixel in row) */ /* report progress every row */ diff --git a/src/modules/loaders/loader_tiff.c b/src/modules/loaders/loader_tiff.c index af26481..d4998c3 100644 --- a/src/modules/loaders/loader_tiff.c +++ b/src/modules/loaders/loader_tiff.c @@ -524,13 +524,13 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity) { pixel = data[(y * im->w) + x]; - r = (pixel >> 16) & 0xff; - g = (pixel >> 8) & 0xff; - b = pixel & 0xff; + r = PIXEL_R(pixel); + g = PIXEL_G(pixel); + b = PIXEL_B(pixel); if (has_alpha) { /* TIFF makes you pre-mutiply the rgb components by alpha */ - a = (pixel >> 24) & 0xff; + a = PIXEL_A(pixel); alpha_factor = ((double)a / 255.0); r *= alpha_factor; g *= alpha_factor;