~ubuntu-branches/ubuntu/saucy/imagemagick/saucy

« back to all changes in this revision

Viewing changes to debian/patches/0004-Revised-PNG8-reduction-to-work-with-a-special-case.patch

  • Committer: Package Import Robot
  • Author(s): Michael Terry
  • Date: 2012-07-10 11:21:50 UTC
  • mfrom: (6.2.24 sid)
  • Revision ID: package-import@ubuntu.com-20120710112150-liko2z4agqah3n5t
Tags: 8:6.7.7.10-2ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Make ufraw-batch (universe) a suggestion instead of a recommendation.
  - Don't set MAKEFLAGS in debian/rules; just pass it to the build.
* debian/control:
  - Build-Depend on libtiff5-dev instead of libtiff-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
5
 
 
6
 
This patch fix png that reduces to 256 opaque colors plus transparency.
7
 
 
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
10
 
/target/output.png".
11
 
 
12
 
This is a know bug of imagemagick fixed in 6.6.9.8
13
 
 
14
 
cherry picked from commit a5a4705b639217c893861d802c3cf4c0a749943
15
 
 
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
20
 
 
21
 
git-svn-id: https://www.imagemagick.org/subversion/ImageMagick/trunk@4429 aa41f4f7-0bf4-0310-aa73-e5a19afd5a74
22
 
---
23
 
 coders/png.c |   99 ++++++++++++++++++++++++++++++++++++++++++++-------------
24
 
 1 files changed, 76 insertions(+), 23 deletions(-)
25
 
 
26
 
diff --git a/coders/png.c b/coders/png.c
27
 
index 6ff2916..6afd815 100644
28
 
--- a/coders/png.c
29
 
+++ b/coders/png.c
30
 
@@ -7013,6 +7013,7 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
31
 
     ping_need_colortype_warning,
32
 
 
33
 
     status,
34
 
+    tried_332,
35
 
     tried_333,
36
 
     tried_444;
37
 
 
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.
49
 
    */
50
 
 
51
 
+  tried_332 = MagickFalse;
52
 
   tried_333 = MagickFalse;
53
 
   tried_444 = MagickFalse;
54
 
 
55
 
-  for (j=0; j<5; j++)
56
 
+  for (j=0; j<6; j++)
57
 
   {
58
 
     /* BUILD_PALETTE
59
 
      *
60
 
@@ -7759,9 +7762,13 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
61
 
 
62
 
           for (x=0; x < (ssize_t) image->columns; x++)
63
 
           {
64
 
-              SetOpacityPixelComponent(r,
65
 
-              ((GetOpacityPixelComponent(r) > TransparentOpacity/2) ?
66
 
-                   TransparentOpacity : OpaqueOpacity));
67
 
+              if (GetOpacityPixelComponent(r) > TransparentOpacity/2)
68
 
+                {
69
 
+                  SetOpacityPixelComponent(r,TransparentOpacity);
70
 
+                  SetRGBPixelComponents(r,image->background_color);
71
 
+                }
72
 
+              else
73
 
+                  SetOpacityPixelComponent(r,OpaqueOpacity);
74
 
               r++;
75
 
           }
76
 
   
77
 
@@ -7814,11 +7821,7 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
78
 
 
79
 
             for (x=0; x < (ssize_t) image->columns; x++)
80
 
             {
81
 
-              if (GetOpacityPixelComponent(r) == TransparentOpacity)
82
 
-                {
83
 
-                  SetRGBPixelComponents(r,image->background_color);
84
 
-                }
85
 
-              else
86
 
+              if (GetOpacityPixelComponent(r) == OpaqueOpacity)
87
 
                 {
88
 
                   hi4=ScaleQuantumToChar(GetRedPixelComponent(r)) & 0xf0;
89
 
                   SetRedPixelComponent(r,ScaleCharToQuantum((hi4 | (hi4 >>
90
 
@@ -7895,11 +7898,7 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
91
 
 
92
 
             for (x=0; x < (ssize_t) image->columns; x++)
93
 
             {
94
 
-              if (GetOpacityPixelComponent(r) == TransparentOpacity)
95
 
-                {
96
 
-                  SetRGBPixelComponents(r,image->background_color);
97
 
-                }
98
 
-              else
99
 
+              if (GetOpacityPixelComponent(r) == OpaqueOpacity)
100
 
                 {
101
 
                   hi3=ScaleQuantumToChar(GetRedPixelComponent(r)) & 0xe0;
102
 
                   hi2=hi3 & 0xc0;
103
 
@@ -7947,12 +7946,14 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
104
 
         continue;
105
 
       }
106
 
 
107
 
-    if (image_colors == 0 || image_colors > 256)
108
 
+    if (tried_332 == MagickFalse && (image_colors == 0 || image_colors > 256))
109
 
       {
110
 
         if (logging != MagickFalse)
111
 
            (void) LogMagickEvent(CoderEvent,GetMagickModule(),
112
 
                "    Quantizing the background color to 3-3-2");
113
 
 
114
 
+        tried_332 = MagickTrue;
115
 
+
116
 
         /* Red and green were already done so we only quantize the blue
117
 
          * channel
118
 
          */
119
 
@@ -7977,11 +7978,7 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
120
 
 
121
 
             for (x=0; x < (ssize_t) image->columns; x++)
122
 
             {
123
 
-              if (GetOpacityPixelComponent(r) == TransparentOpacity)
124
 
-                {
125
 
-                  SetRGBPixelComponents(r,image->background_color);
126
 
-                }
127
 
-              else
128
 
+              if (GetOpacityPixelComponent(r) == OpaqueOpacity)
129
 
                 {
130
 
                   hi2=ScaleQuantumToChar(GetBluePixelComponent(r)) & 0xc0;
131
 
                   SetBluePixelComponent(r,ScaleCharToQuantum(
132
 
@@ -8011,6 +8008,62 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
133
 
       continue;
134
 
     }
135
 
     break;
136
 
+
137
 
+    if (image_colors == 0 || image_colors > 256)
138
 
+    {
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).
143
 
+       */
144
 
+      if (ScaleQuantumToChar(image->background_color.red) == 0x49 &&
145
 
+          ScaleQuantumToChar(image->background_color.green) == 0x00 &&
146
 
+          ScaleQuantumToChar(image->background_color.blue) == 0x00)
147
 
+      {
148
 
+         image->background_color.red=ScaleCharToQuantum(0x24);
149
 
+      }
150
 
+  
151
 
+      if (image->colormap == NULL)
152
 
+      {
153
 
+        for (y=0; y < (ssize_t) image->rows; y++)
154
 
+        {
155
 
+          r=GetAuthenticPixels(image,0,y,image->columns,1,
156
 
+              exception);
157
 
+  
158
 
+          if (r == (PixelPacket *) NULL)
159
 
+            break;
160
 
+  
161
 
+          for (x=0; x < (ssize_t) image->columns; x++)
162
 
+          {
163
 
+            if (ScaleQuantumToChar(GetRedPixelComponent(r)) == 0x49 &&
164
 
+                ScaleQuantumToChar(GetGreenPixelComponent(r)) == 0x00 &&
165
 
+                ScaleQuantumToChar(GetBluePixelComponent(r)) == 0x00 &&
166
 
+                GetOpacityPixelComponent(r) == OpaqueOpacity)
167
 
+              {
168
 
+                SetRedPixelComponent(r,ScaleCharToQuantum(0x24));
169
 
+              }
170
 
+            r++;
171
 
+          }
172
 
+      
173
 
+          if (SyncAuthenticPixels(image,exception) == MagickFalse)
174
 
+             break;
175
 
+  
176
 
+        }
177
 
+      }
178
 
+
179
 
+      else
180
 
+      {
181
 
+         for (i=0; i<image_colors; i++)
182
 
+         {
183
 
+            if (ScaleQuantumToChar(image->colormap[i].red) == 0x49 &&
184
 
+                ScaleQuantumToChar(image->colormap[i].green) == 0x00 &&
185
 
+                ScaleQuantumToChar(image->colormap[i].blue) == 0x00)
186
 
+            {
187
 
+               image->colormap[i].red=ScaleCharToQuantum(0x24);
188
 
+            }
189
 
+         }
190
 
+      }
191
 
+    }
192
 
   }
193
 
   /* END OF BUILD_PALETTE */
194
 
 
195
 
1.7.5.3
196