forked from old/legacy-imlib2
Use macro for pixel color access in savers
This commit is contained in:
parent
755dc017f2
commit
3e082b2310
|
@ -40,6 +40,11 @@
|
||||||
|
|
||||||
#define PIXEL_ARGB(a, r, g, b) ((a) << 24) | ((r) << 16) | ((g) << 8) | (b)
|
#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
|
#ifdef DO_MMX_ASM
|
||||||
int __imlib_get_cpuid(void);
|
int __imlib_get_cpuid(void);
|
||||||
|
|
||||||
|
|
|
@ -941,9 +941,9 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
||||||
for (j = 0; j < im->w; j++)
|
for (j = 0; j < im->w; j++)
|
||||||
{
|
{
|
||||||
pixel = im->data[im->w * (im->h - i - 1) + j];
|
pixel = im->data[im->w * (im->h - i - 1) + j];
|
||||||
WriteleByte(f, pixel & 0xff);
|
WriteleByte(f, PIXEL_B(pixel));
|
||||||
WriteleByte(f, (pixel >> 8) & 0xff);
|
WriteleByte(f, PIXEL_G(pixel));
|
||||||
WriteleByte(f, (pixel >> 16) & 0xff);
|
WriteleByte(f, PIXEL_R(pixel));
|
||||||
}
|
}
|
||||||
for (j = 0; j < pad; j++)
|
for (j = 0; j < pad; j++)
|
||||||
WriteleByte(f, 0);
|
WriteleByte(f, 0);
|
||||||
|
|
|
@ -286,10 +286,11 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
||||||
/* convcert scaline from ARGB to RGB packed */
|
/* convcert scaline from ARGB to RGB packed */
|
||||||
for (j = 0, i = 0; i < im->w; i++)
|
for (j = 0, i = 0; i < im->w; i++)
|
||||||
{
|
{
|
||||||
buf[j++] = ((*ptr) >> 16) & 0xff;
|
DATA32 pixel = *ptr++;
|
||||||
buf[j++] = ((*ptr) >> 8) & 0xff;
|
|
||||||
buf[j++] = ((*ptr)) & 0xff;
|
buf[j++] = PIXEL_R(pixel);
|
||||||
ptr++;
|
buf[j++] = PIXEL_G(pixel);
|
||||||
|
buf[j++] = PIXEL_B(pixel);
|
||||||
}
|
}
|
||||||
/* write scanline */
|
/* write scanline */
|
||||||
jbuf = (JSAMPROW *) (&buf);
|
jbuf = (JSAMPROW *) (&buf);
|
||||||
|
|
|
@ -347,13 +347,16 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
||||||
{
|
{
|
||||||
for (j = 0, x = 0; x < im->w; x++)
|
for (j = 0, x = 0; x < im->w; x++)
|
||||||
{
|
{
|
||||||
data[j++] = (ptr[x] >> 16) & 0xff;
|
DATA32 pixel = ptr[x];
|
||||||
data[j++] = (ptr[x] >> 8) & 0xff;
|
|
||||||
data[j++] = (ptr[x]) & 0xff;
|
data[j++] = PIXEL_R(pixel);
|
||||||
|
data[j++] = PIXEL_G(pixel);
|
||||||
|
data[j++] = PIXEL_B(pixel);
|
||||||
}
|
}
|
||||||
row_ptr = (png_bytep) data;
|
row_ptr = (png_bytep) data;
|
||||||
}
|
}
|
||||||
png_write_rows(png_ptr, &row_ptr, 1);
|
png_write_rows(png_ptr, &row_ptr, 1);
|
||||||
|
|
||||||
if (progress)
|
if (progress)
|
||||||
{
|
{
|
||||||
char per;
|
char per;
|
||||||
|
|
|
@ -467,12 +467,13 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
||||||
bptr = buf;
|
bptr = buf;
|
||||||
for (x = 0; x < im->w; x++)
|
for (x = 0; x < im->w; x++)
|
||||||
{
|
{
|
||||||
bptr[0] = ((*ptr) >> 16) & 0xff;
|
DATA32 pixel = *ptr++;
|
||||||
bptr[1] = ((*ptr) >> 8) & 0xff;
|
|
||||||
bptr[2] = ((*ptr)) & 0xff;
|
bptr[0] = PIXEL_R(pixel);
|
||||||
bptr[3] = ((*ptr) >> 24) & 0xff;
|
bptr[1] = PIXEL_G(pixel);
|
||||||
|
bptr[2] = PIXEL_B(pixel);
|
||||||
|
bptr[3] = PIXEL_A(pixel);
|
||||||
bptr += 4;
|
bptr += 4;
|
||||||
ptr++;
|
|
||||||
}
|
}
|
||||||
fwrite(buf, im->w * 4, 1, f);
|
fwrite(buf, im->w * 4, 1, f);
|
||||||
if (progress &&
|
if (progress &&
|
||||||
|
@ -495,11 +496,12 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
||||||
bptr = buf;
|
bptr = buf;
|
||||||
for (x = 0; x < im->w; x++)
|
for (x = 0; x < im->w; x++)
|
||||||
{
|
{
|
||||||
bptr[0] = ((*ptr) >> 16) & 0xff;
|
DATA32 pixel = *ptr++;
|
||||||
bptr[1] = ((*ptr) >> 8) & 0xff;
|
|
||||||
bptr[2] = ((*ptr)) & 0xff;
|
bptr[0] = PIXEL_R(pixel);
|
||||||
|
bptr[1] = PIXEL_G(pixel);
|
||||||
|
bptr[2] = PIXEL_B(pixel);
|
||||||
bptr += 3;
|
bptr += 3;
|
||||||
ptr++;
|
|
||||||
}
|
}
|
||||||
fwrite(buf, im->w * 3, 1, f);
|
fwrite(buf, im->w * 3, 1, f);
|
||||||
if (progress &&
|
if (progress &&
|
||||||
|
|
|
@ -122,27 +122,17 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
||||||
for (y = 0; y < im->h; y++)
|
for (y = 0; y < im->h; y++)
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
unsigned char r, g, b, a;
|
|
||||||
|
|
||||||
/* for each pixel in the row */
|
/* for each pixel in the row */
|
||||||
for (x = 0; x < im->w; x++)
|
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)
|
if (im->flags & F_HAS_ALPHA)
|
||||||
{
|
*bufptr++ = PIXEL_A(pixel);
|
||||||
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++;
|
|
||||||
} /* end for (each pixel in row) */
|
} /* end for (each pixel in row) */
|
||||||
|
|
||||||
/* report progress every row */
|
/* report progress every row */
|
||||||
|
|
|
@ -524,13 +524,13 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
||||||
{
|
{
|
||||||
pixel = data[(y * im->w) + x];
|
pixel = data[(y * im->w) + x];
|
||||||
|
|
||||||
r = (pixel >> 16) & 0xff;
|
r = PIXEL_R(pixel);
|
||||||
g = (pixel >> 8) & 0xff;
|
g = PIXEL_G(pixel);
|
||||||
b = pixel & 0xff;
|
b = PIXEL_B(pixel);
|
||||||
if (has_alpha)
|
if (has_alpha)
|
||||||
{
|
{
|
||||||
/* TIFF makes you pre-mutiply the rgb components by 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);
|
alpha_factor = ((double)a / 255.0);
|
||||||
r *= alpha_factor;
|
r *= alpha_factor;
|
||||||
g *= alpha_factor;
|
g *= alpha_factor;
|
||||||
|
|
Loading…
Reference in New Issue