1
From 991f4ebaeaba35386d3cdc860f434c66c77bef9f Mon Sep 17 00:00:00 2001
2
From: =?UTF-8?q?Bastien=20ROUCARI=C3=88S?= <roucaries.bastien@gmail.com>
3
Date: Wed, 15 Jun 2011 23:41:00 +0200
4
Subject: [PATCH] Revised PNG8 reduction to work with a special case
6
This patch fix png that reduces to 256 opaque colors plus transparency.
8
A build of the package in testing is fine, a build of the package in unstable
9
is broken. tango-icon-theme's install process does a "convert input.png
12
This is a know bug of imagemagick fixed in 6.6.9.8
14
cherry picked from commit a5a4705b639217c893861d802c3cf4c0a749943
16
Author: Glenn Randers-Pehrson <glennrp@imagemagick.org>
17
Bug-Debian: http://bugs.debian.org/609177
18
Last-Update: 2011-06-15
19
Applied-Upstream: 6.6.9.8
21
git-svn-id: https://www.imagemagick.org/subversion/ImageMagick/trunk@4429 aa41f4f7-0bf4-0310-aa73-e5a19afd5a74
23
coders/png.c | 99 ++++++++++++++++++++++++++++++++++++++++++++-------------
24
1 files changed, 76 insertions(+), 23 deletions(-)
26
diff --git a/coders/png.c b/coders/png.c
27
index 6ff2916..6afd815 100644
30
@@ -7013,6 +7013,7 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
31
ping_need_colortype_warning,
38
@@ -7202,15 +7203,17 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
39
/* Normally we run this just once, but in the case of writing PNG8
40
* we reduce the transparency to binary and run again, then if there
41
* are still too many colors we reduce to a simple 4-4-4-1, then 3-3-3-1
42
- * RGBA palette and run again, and finally to a simple 3-3-2-1 RGBA
43
- * palette. The final reduction can only fail if there are still 256
44
- * colors present and one of them has both transparent and opaque instances.
45
+ * RGBA palette and run again, and then to a simple 3-3-2-1 RGBA
46
+ * palette. Then (To do) we take care of a final reduction that is only
47
+ * needed if there are still 256 colors present and one of them has both
48
+ * transparent and opaque instances.
51
+ tried_332 = MagickFalse;
52
tried_333 = MagickFalse;
53
tried_444 = MagickFalse;
60
@@ -7759,9 +7762,13 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
62
for (x=0; x < (ssize_t) image->columns; x++)
64
- SetOpacityPixelComponent(r,
65
- ((GetOpacityPixelComponent(r) > TransparentOpacity/2) ?
66
- TransparentOpacity : OpaqueOpacity));
67
+ if (GetOpacityPixelComponent(r) > TransparentOpacity/2)
69
+ SetOpacityPixelComponent(r,TransparentOpacity);
70
+ SetRGBPixelComponents(r,image->background_color);
73
+ SetOpacityPixelComponent(r,OpaqueOpacity);
77
@@ -7814,11 +7821,7 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
79
for (x=0; x < (ssize_t) image->columns; x++)
81
- if (GetOpacityPixelComponent(r) == TransparentOpacity)
83
- SetRGBPixelComponents(r,image->background_color);
86
+ if (GetOpacityPixelComponent(r) == OpaqueOpacity)
88
hi4=ScaleQuantumToChar(GetRedPixelComponent(r)) & 0xf0;
89
SetRedPixelComponent(r,ScaleCharToQuantum((hi4 | (hi4 >>
90
@@ -7895,11 +7898,7 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
92
for (x=0; x < (ssize_t) image->columns; x++)
94
- if (GetOpacityPixelComponent(r) == TransparentOpacity)
96
- SetRGBPixelComponents(r,image->background_color);
99
+ if (GetOpacityPixelComponent(r) == OpaqueOpacity)
101
hi3=ScaleQuantumToChar(GetRedPixelComponent(r)) & 0xe0;
103
@@ -7947,12 +7946,14 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
107
- if (image_colors == 0 || image_colors > 256)
108
+ if (tried_332 == MagickFalse && (image_colors == 0 || image_colors > 256))
110
if (logging != MagickFalse)
111
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
112
" Quantizing the background color to 3-3-2");
114
+ tried_332 = MagickTrue;
116
/* Red and green were already done so we only quantize the blue
119
@@ -7977,11 +7978,7 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
121
for (x=0; x < (ssize_t) image->columns; x++)
123
- if (GetOpacityPixelComponent(r) == TransparentOpacity)
125
- SetRGBPixelComponents(r,image->background_color);
128
+ if (GetOpacityPixelComponent(r) == OpaqueOpacity)
130
hi2=ScaleQuantumToChar(GetBluePixelComponent(r)) & 0xc0;
131
SetBluePixelComponent(r,ScaleCharToQuantum(
132
@@ -8011,6 +8008,62 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
137
+ if (image_colors == 0 || image_colors > 256)
139
+ /* Take care of special case with 256 colors + 1 transparent
140
+ * color. We don't need to quantize to 2-3-2-1; we only need to
141
+ * eliminate one color, so we'll merge the two darkest red
142
+ * colors (0x49, 0, 0) -> (0x24, 0, 0).
144
+ if (ScaleQuantumToChar(image->background_color.red) == 0x49 &&
145
+ ScaleQuantumToChar(image->background_color.green) == 0x00 &&
146
+ ScaleQuantumToChar(image->background_color.blue) == 0x00)
148
+ image->background_color.red=ScaleCharToQuantum(0x24);
151
+ if (image->colormap == NULL)
153
+ for (y=0; y < (ssize_t) image->rows; y++)
155
+ r=GetAuthenticPixels(image,0,y,image->columns,1,
158
+ if (r == (PixelPacket *) NULL)
161
+ for (x=0; x < (ssize_t) image->columns; x++)
163
+ if (ScaleQuantumToChar(GetRedPixelComponent(r)) == 0x49 &&
164
+ ScaleQuantumToChar(GetGreenPixelComponent(r)) == 0x00 &&
165
+ ScaleQuantumToChar(GetBluePixelComponent(r)) == 0x00 &&
166
+ GetOpacityPixelComponent(r) == OpaqueOpacity)
168
+ SetRedPixelComponent(r,ScaleCharToQuantum(0x24));
173
+ if (SyncAuthenticPixels(image,exception) == MagickFalse)
181
+ for (i=0; i<image_colors; i++)
183
+ if (ScaleQuantumToChar(image->colormap[i].red) == 0x49 &&
184
+ ScaleQuantumToChar(image->colormap[i].green) == 0x00 &&
185
+ ScaleQuantumToChar(image->colormap[i].blue) == 0x00)
187
+ image->colormap[i].red=ScaleCharToQuantum(0x24);
193
/* END OF BUILD_PALETTE */