Use macro for pixel color access in savers

This commit is contained in:
Kim Woelders 2019-11-09 07:48:34 +01:00
parent 755dc017f2
commit 3e082b2310
7 changed files with 40 additions and 39 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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 &&

View File

@ -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 */

View File

@ -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;