summaryrefslogtreecommitdiffstats
path: root/libdimension-png
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-03-20 04:06:50 +0000
committerTavian Barnes <tavianator@gmail.com>2009-03-20 04:06:50 +0000
commitc2b6e6197d2707c49ba653bac39b8b6caa039c72 (patch)
treee8849a9d025f3b822899fcab7199cf171ebacc86 /libdimension-png
parent047d3248896d375a8fbc80dbbf573b81a3e5a927 (diff)
downloaddimension-c2b6e6197d2707c49ba653bac39b8b6caa039c72.tar.xz
Fix color handling.
Diffstat (limited to 'libdimension-png')
-rw-r--r--libdimension-png/png.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/libdimension-png/png.c b/libdimension-png/png.c
index dbcd21a..49f1d6c 100644
--- a/libdimension-png/png.c
+++ b/libdimension-png/png.c
@@ -83,22 +83,28 @@ dmnsn_png_write_canvas(const dmnsn_canvas *canvas, FILE *file)
pixel = canvas->pixels + (height - y - 1)*width + x;
sRGB = dmnsn_sRGB_from_color(*pixel);
- if (sRGB.R < 1.0) {
- row[4*x] = sRGB.R*UINT16_MAX;
- } else {
+ if (sRGB.R <= 0.0) {
+ row[4*x] = 0;
+ } else if (sRGB.R >= 1.0) {
row[4*x] = UINT16_MAX;
+ } else {
+ row[4*x] = sRGB.R*UINT16_MAX;
}
- if (sRGB.G < 1.0) {
- row[4*x + 1] = sRGB.G*UINT16_MAX;
- } else {
+ if (sRGB.G <= 0.0) {
+ row[4*x + 1] = 0;
+ } else if (sRGB.G >= 1.0) {
row[4*x + 1] = UINT16_MAX;
- }
-
- if (sRGB.B < 1.0) {
- row[4*x + 2] = sRGB.B*UINT16_MAX;
} else {
+ row[4*x + 1] = sRGB.G*UINT16_MAX;
+ }
+
+ if (sRGB.B <= 0.0) {
+ row[4*x + 2] = 0;
+ } else if (sRGB.B >= 1.0) {
row[4*x + 2] = UINT16_MAX;
+ } else {
+ row[4*x + 2] = sRGB.B*UINT16_MAX;
}
row[4*x + 3] = (pixel->filter + pixel->trans)*UINT16_MAX;