|
|
@@ -56,6 +56,9 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type) |
|
|
|
case PIPI_PIXELS_RGBA32: |
|
|
|
bytes = img->w * img->h * 4 * sizeof(uint8_t); |
|
|
|
break; |
|
|
|
case PIPI_PIXELS_BGR24: |
|
|
|
bytes = img->w * img->h * 3 * sizeof(uint8_t); |
|
|
|
break; |
|
|
|
case PIPI_PIXELS_RGBA_F: |
|
|
|
bytes = img->w * img->h * 4 * sizeof(float); |
|
|
|
break; |
|
|
@@ -81,6 +84,26 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type) |
|
|
|
dest[4 * (y * img->w + x) + i] |
|
|
|
= u8tof32(src[4 * (y * img->w + x) + i]); |
|
|
|
} |
|
|
|
else if(img->last_modified == PIPI_PIXELS_BGR24 |
|
|
|
&& type == PIPI_PIXELS_RGBA_F) |
|
|
|
{ |
|
|
|
uint8_t *src = (uint8_t *)img->p[PIPI_PIXELS_BGR24].pixels; |
|
|
|
float *dest = (float *)img->p[type].pixels; |
|
|
|
|
|
|
|
init_tables(); |
|
|
|
|
|
|
|
for(y = 0; y < img->h; y++) |
|
|
|
for(x = 0; x < img->w; x++) |
|
|
|
{ |
|
|
|
dest[4 * (y * img->w + x)] |
|
|
|
= u8tof32(src[3 * (y * img->w + x) + 2]); |
|
|
|
dest[4 * (y * img->w + x) + 1] |
|
|
|
= u8tof32(src[3 * (y * img->w + x) + 1]); |
|
|
|
dest[4 * (y * img->w + x) + 2] |
|
|
|
= u8tof32(src[3 * (y * img->w + x)]); |
|
|
|
dest[4 * (y * img->w + x) + 3] = 1.0; |
|
|
|
} |
|
|
|
} |
|
|
|
else if(img->last_modified == PIPI_PIXELS_RGBA_F |
|
|
|
&& type == PIPI_PIXELS_RGBA32) |
|
|
|
{ |
|
|
@@ -117,6 +140,42 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if(img->last_modified == PIPI_PIXELS_RGBA_F |
|
|
|
&& type == PIPI_PIXELS_BGR24) |
|
|
|
{ |
|
|
|
float *src = (float *)img->p[PIPI_PIXELS_RGBA_F].pixels; |
|
|
|
uint8_t *dest = (uint8_t *)img->p[type].pixels; |
|
|
|
|
|
|
|
init_tables(); |
|
|
|
|
|
|
|
for(y = 0; y < img->h; y++) |
|
|
|
for(x = 0; x < img->w; x++) |
|
|
|
for(i = 0; i < 3; i++) |
|
|
|
{ |
|
|
|
double p, e; |
|
|
|
uint8_t d; |
|
|
|
|
|
|
|
p = src[4 * (y * img->w + x) + i]; |
|
|
|
|
|
|
|
if(p < 0.) d = 0.; |
|
|
|
else if(p > 1.) d = 255; |
|
|
|
else d = (int)(255.999 * pow(p, 1. / GAMMA)); |
|
|
|
|
|
|
|
dest[3 * (y * img->w + x) + i] = d; |
|
|
|
|
|
|
|
e = p - u8tof32(d); |
|
|
|
if(x < img->w - 1) |
|
|
|
src[4 * (y * img->w + x + 1) + i] += e * .4375; |
|
|
|
if(y < img->h - 1) |
|
|
|
{ |
|
|
|
if(x < img->w - 1) |
|
|
|
src[4 * ((y + 1) * img->w + x - 1) + i] += e * .1875; |
|
|
|
src[4 * ((y + 1) * img->w + x) + i] += e * .3125; |
|
|
|
if(x < img->w - 1) |
|
|
|
src[4 * ((y + 1) * img->w + x + 1) + i] += e * .0625; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
memset(img->p[type].pixels, 0, bytes); |
|
|
|