summaryrefslogtreecommitdiffstats
path: root/libdimension-png/png.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-04-10 05:24:10 +0000
committerTavian Barnes <tavianator@gmail.com>2009-04-10 05:24:10 +0000
commitc1212cee3b7955304435c9659b9572109407ce36 (patch)
treec3a6bc255736f17fb3aa7e8d0fda086e3772b4c8 /libdimension-png/png.c
parentb3e653271c711a6b4eb2cfdc6ea078a541cd684a (diff)
downloaddimension-c1212cee3b7955304435c9659b9572109407ce36.tar.xz
Use dmnsn_set_pixel and dmnsn_get_pixel in libdimension-png.
Diffstat (limited to 'libdimension-png/png.c')
-rw-r--r--libdimension-png/png.c42
1 files changed, 16 insertions, 26 deletions
diff --git a/libdimension-png/png.c b/libdimension-png/png.c
index 49f1d6c..1c12dcf 100644
--- a/libdimension-png/png.c
+++ b/libdimension-png/png.c
@@ -32,7 +32,7 @@ dmnsn_png_write_canvas(const dmnsn_canvas *canvas, FILE *file)
png_uint_32 width, height;
unsigned int x, y;
uint16_t *row = NULL;
- dmnsn_color *pixel;
+ dmnsn_color color;
dmnsn_sRGB sRGB;
width = canvas->x;
@@ -80,8 +80,8 @@ dmnsn_png_write_canvas(const dmnsn_canvas *canvas, FILE *file)
for (y = 0; y < height; ++y) {
for (x = 0; x < width; ++x) {
/* Invert the rows. PNG coordinates are fourth quadrant. */
- pixel = canvas->pixels + (height - y - 1)*width + x;
- sRGB = dmnsn_sRGB_from_color(*pixel);
+ color = dmnsn_get_pixel(canvas, x, height - y - 1);
+ sRGB = dmnsn_sRGB_from_color(color);
if (sRGB.R <= 0.0) {
row[4*x] = 0;
@@ -107,7 +107,7 @@ dmnsn_png_write_canvas(const dmnsn_canvas *canvas, FILE *file)
row[4*x + 2] = sRGB.B*UINT16_MAX;
}
- row[4*x + 3] = (pixel->filter + pixel->trans)*UINT16_MAX;
+ row[4*x + 3] = (color.filter + color.trans)*UINT16_MAX;
}
png_write_row(png_ptr, (png_bytep)row);
}
@@ -130,7 +130,7 @@ dmnsn_png_read_canvas(dmnsn_canvas **canvas, FILE *file)
png_bytep image = NULL;
png_bytep *row_pointers = NULL;
unsigned int x, y;
- dmnsn_color *pixel;
+ dmnsn_color color;
dmnsn_sRGB sRGB;
png_bytep png_pixel;
@@ -219,7 +219,6 @@ dmnsn_png_read_canvas(dmnsn_canvas **canvas, FILE *file)
if (color_type & PNG_COLOR_MASK_ALPHA) {
for (x = 0; x < width; ++x) {
for (y = 0; y < height; ++y) {
- pixel = (*canvas)->pixels + (height - y - 1)*width + x;
png_pixel = image + 8*(y*width + x);
sRGB.R = ((double)((png_pixel[0] << UINT16_C(8)) + png_pixel[1]))
@@ -229,17 +228,15 @@ dmnsn_png_read_canvas(dmnsn_canvas **canvas, FILE *file)
sRGB.B = ((double)((png_pixel[4] << UINT16_C(8)) + png_pixel[5]))
/UINT16_MAX;
- *pixel = dmnsn_color_from_sRGB(sRGB);
-
- pixel->filter = 0.0;
- pixel->trans = ((double)((png_pixel[6] << UINT16_C(8))
- + png_pixel[7]))/UINT16_MAX;
+ color = dmnsn_color_from_sRGB(sRGB);
+ color.trans = ((double)((png_pixel[6] << UINT16_C(8))
+ + png_pixel[7]))/UINT16_MAX;
+ dmnsn_set_pixel(*canvas, color, x, height - y - 1);
}
}
} else {
for (x = 0; x < width; ++x) {
for (y = 0; y < height; ++y) {
- pixel = (*canvas)->pixels + (height - y - 1)*width + x;
png_pixel = image + 6*(y*width + x);
sRGB.R = ((double)((png_pixel[0] << UINT16_C(8)) + png_pixel[1]))
@@ -249,10 +246,8 @@ dmnsn_png_read_canvas(dmnsn_canvas **canvas, FILE *file)
sRGB.B = ((double)((png_pixel[4] << UINT16_C(8)) + png_pixel[5]))
/UINT16_MAX;
- *pixel = dmnsn_color_from_sRGB(sRGB);
-
- pixel->filter = 0.0;
- pixel->trans = 0.0;
+ color = dmnsn_color_from_sRGB(sRGB);
+ dmnsn_set_pixel(*canvas, color, x, height - y - 1);
}
}
}
@@ -261,33 +256,28 @@ dmnsn_png_read_canvas(dmnsn_canvas **canvas, FILE *file)
if (color_type & PNG_COLOR_MASK_ALPHA) {
for (x = 0; x < width; ++x) {
for (y = 0; y < height; ++y) {
- pixel = (*canvas)->pixels + (height - y - 1)*width + x;
png_pixel = image + 4*(y*width + x);
sRGB.R = ((double)png_pixel[0])/UINT8_MAX;
sRGB.G = ((double)png_pixel[1])/UINT8_MAX;
sRGB.B = ((double)png_pixel[2])/UINT8_MAX;
- *pixel = dmnsn_color_from_sRGB(sRGB);
-
- pixel->filter = 0.0;
- pixel->trans = ((double)png_pixel[3])/UINT8_MAX;
+ color = dmnsn_color_from_sRGB(sRGB);
+ color.trans = ((double)png_pixel[3])/UINT8_MAX;
+ dmnsn_set_pixel(*canvas, color, x, height - y - 1);
}
}
} else {
for (x = 0; x < width; ++x) {
for (y = 0; y < height; ++y) {
- pixel = (*canvas)->pixels + (height - y - 1)*width + x;
png_pixel = image + 3*(y*width + x);
sRGB.R = ((double)png_pixel[0])/UINT8_MAX;
sRGB.G = ((double)png_pixel[1])/UINT8_MAX;
sRGB.B = ((double)png_pixel[2])/UINT8_MAX;
- *pixel = dmnsn_color_from_sRGB(sRGB);
-
- pixel->filter = 0.0;
- pixel->trans = 0.0;
+ color = dmnsn_color_from_sRGB(sRGB);
+ dmnsn_set_pixel(*canvas, color, x, height - y - 1);
}
}
}