Changeset 3712
- Timestamp:
- 02/23/11 20:28:37 (2 years ago)
- Location:
- ImageMagick/trunk
- Files:
-
- 2 edited
-
ChangeLog (modified) (2 diffs)
-
coders/png.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ImageMagick/trunk/ChangeLog
r3711 r3712 1 1 2011-02-23 6.6.7-10 Cristy <quetzlzacatenango@image...> 2 * Return MagickEpsilon for GetResizeFilterWeight() rather th en 0 (reference2 * Return MagickEpsilon for GetResizeFilterWeight() rather than 0 (reference 3 3 http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=18132). 4 4 … … 8 8 * Eliminated a number of redundant tests for gray images in the PNG encoder. 9 9 * Removed now-unused IsMonochromeImage() function from coders/png.c 10 * Scan the colormap instead of all of the pixels, when possible, to 11 determine whether the image received by the PNG encoder is grayscale 12 or black-and-white. 10 13 11 14 2011-02-22 6.6.7-9 Cristy <quetzlzacatenango@image...> -
ImageMagick/trunk/coders/png.c
r3709 r3712 113 113 #define MNG_COALESCE_LAYERS /* In 5.4.4, this interfered with MMAP'ed files. */ 114 114 #define MNG_INSERT_LAYERS /* Troublesome, but seem to work as of 5.4.4 */ 115 #define BUILD_PNG_PALETTE /* This works as of 6.6.6 */116 115 #if defined(MAGICKCORE_JPEG_DELEGATE) 117 116 # define JNG_SUPPORTED /* Not finished as of 5.5.2. See "To do" comments. */ … … 6954 6953 #endif 6955 6954 6956 #ifdef BUILD_PNG_PALETTE 6957 if (mng_info->write_png_colortype < 8 /* all */) 6958 { 6959 /* 6960 * Sometimes we get DirectClass images that have 256 colors or fewer. 6961 * This code will build a colormap. 6962 * 6963 * Also, sometimes we get PseudoClass images with an out-of-date 6964 * colormap. This code will replace the colormap with a new one. 6965 * Sometimes we get PseudoClass images that have more than 256 colors. 6966 * This code will delete the colormap and change the image to 6967 * DirectClass. 6968 * 6969 * If image->matte is MagickFalse, we ignore the opacity channel 6970 * even though it sometimes contains left-over non-opaque values. 6971 * 6972 * Also we gather some information (number of opaque, transparent, 6973 * and semitransparent pixels, and whether the image has any non-gray 6974 * pixels) that we might need later. If the user wants to force 6975 * GrayAlpha or RGBA (colortype 4 or 6) we probably don't need any 6976 * of that. 6977 */ 6978 6979 ExceptionInfo 6980 *exception; 6981 6982 int 6983 n; 6984 6985 PixelPacket 6986 opaque[260], 6987 semitransparent[260], 6988 transparent[260]; 6989 6990 register IndexPacket 6991 *indexes; 6992 6993 register const PixelPacket 6994 *s, 6995 *q; 6955 { 6956 /* BUILD_PALETTE 6957 * 6958 * Sometimes we get DirectClass images that have 256 colors or fewer. 6959 * This code will build a colormap. 6960 * 6961 * Also, sometimes we get PseudoClass images with an out-of-date 6962 * colormap. This code will replace the colormap with a new one. 6963 * Sometimes we get PseudoClass images that have more than 256 colors. 6964 * This code will delete the colormap and change the image to 6965 * DirectClass. 6966 * 6967 * If image->matte is MagickFalse, we ignore the opacity channel 6968 * even though it sometimes contains left-over non-opaque values. 6969 * 6970 * Also we gather some information (number of opaque, transparent, 6971 * and semitransparent pixels, and whether the image has any non-gray 6972 * pixels or only black-and-white pixels) that we might need later. 6973 * 6974 * Even if the user wants to force GrayAlpha or RGBA (colortype 4 or 6) 6975 * we need to check for bogus non-opaque values, at least. 6976 */ 6977 6978 ExceptionInfo 6979 *exception; 6980 6981 int 6982 n; 6983 6984 PixelPacket 6985 opaque[260], 6986 semitransparent[260], 6987 transparent[260]; 6988 6989 register IndexPacket 6990 *indexes; 6991 6992 register const PixelPacket 6993 *s, 6994 *q; 6995 6996 if (logging != MagickFalse) 6997 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 6998 " Enter BUILD_PALETTE:"); 6999 7000 if (logging != MagickFalse) 7001 { 7002 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7003 " image->columns=%.20g",(double) image->columns); 7004 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7005 " image->rows=%.20g",(double) image->rows); 7006 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7007 " image->matte=%.20g",(double) image->matte); 7008 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7009 " image->depth=%.20g",(double) image->depth); 7010 7011 if (image->colormap != NULL) 7012 { 7013 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7014 " Original colormap:"); 7015 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7016 " i (red,green,blue,opacity)"); 7017 7018 for (i=0; i < 256; i++) 7019 { 7020 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7021 " %d (%d,%d,%d,%d)", 7022 (int) i, 7023 (int) image->colormap[i].red, 7024 (int) image->colormap[i].green, 7025 (int) image->colormap[i].blue, 7026 (int) image->colormap[i].opacity); 7027 } 7028 7029 for (i=image->colors - 10; i < (ssize_t) image->colors; i++) 7030 { 7031 if (i > 255) 7032 { 7033 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7034 " %d (%d,%d,%d,%d)", 7035 (int) i, 7036 (int) image->colormap[i].red, 7037 (int) image->colormap[i].green, 7038 (int) image->colormap[i].blue, 7039 (int) image->colormap[i].opacity); 7040 } 7041 } 7042 } 7043 7044 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7045 " image->colors=%d",(int) image->colors); 7046 7047 if (image->colors == 0) 7048 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7049 " (zero means unknown)"); 7050 7051 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7052 " Regenerate the colormap"); 7053 } 7054 7055 exception=(&image->exception); 7056 7057 image_colors=0; 7058 7059 for (y=0; y < (ssize_t) image->rows; y++) 7060 { 7061 q=GetAuthenticPixels(image,0,y,image->columns,1,exception); 7062 7063 if (q == (PixelPacket *) NULL) 7064 break; 7065 7066 for (x=0; x < (ssize_t) image->columns; x++) 7067 { 7068 if (image->matte == MagickFalse || q->opacity == OpaqueOpacity) 7069 { 7070 if (number_opaque < 259) 7071 { 7072 if (number_opaque == 0) 7073 { 7074 opaque[0]=*q; 7075 opaque[0].opacity=OpaqueOpacity; 7076 number_opaque=1; 7077 } 7078 7079 for (i=0; i< (ssize_t) number_opaque; i++) 7080 { 7081 if (IsColorEqual(opaque+i, (PixelPacket *) q)) 7082 break; 7083 } 7084 7085 if (i == (ssize_t) number_opaque && 7086 number_opaque < 259) 7087 { 7088 number_opaque++; 7089 opaque[i] = *q; 7090 opaque[i].opacity = OpaqueOpacity; 7091 } 7092 } 7093 } 7094 else if (q->opacity == TransparentOpacity) 7095 { 7096 if (number_transparent < 259) 7097 { 7098 if (number_transparent == 0) 7099 { 7100 transparent[0]=*q; 7101 ping_trans_color.red=(unsigned short)(q->red); 7102 ping_trans_color.green=(unsigned short) (q->green); 7103 ping_trans_color.blue=(unsigned short) (q->blue); 7104 ping_trans_color.gray=(unsigned short) (q->blue); 7105 number_transparent = 1; 7106 } 7107 7108 for (i=0; i< (ssize_t) number_transparent; i++) 7109 { 7110 if (IsColorEqual(transparent+i, (PixelPacket *) q)) 7111 break; 7112 } 7113 7114 if (i == (ssize_t) number_transparent && 7115 number_transparent < 259) 7116 { 7117 number_transparent++; 7118 transparent[i] = *q; 7119 } 7120 } 7121 } 7122 else 7123 { 7124 if (number_semitransparent < 259) 7125 { 7126 if (number_semitransparent == 0) 7127 { 7128 semitransparent[0]=*q; 7129 number_semitransparent = 1; 7130 } 7131 7132 for (i=0; i< (ssize_t) number_semitransparent; i++) 7133 { 7134 if (IsColorEqual(semitransparent+i, 7135 (PixelPacket *) q) && 7136 q->opacity == semitransparent[i].opacity) 7137 break; 7138 } 7139 7140 if (i == (ssize_t) number_semitransparent && 7141 number_semitransparent < 259) 7142 { 7143 number_semitransparent++; 7144 semitransparent[i] = *q; 7145 } 7146 } 7147 } 7148 q++; 7149 } 7150 } 7151 7152 if (ping_exclude_bKGD == MagickFalse) 7153 { 7154 /* Add the background color to the palette, if it 7155 * isn't already there. 7156 */ 7157 for (i=0; i<number_opaque; i++) 7158 { 7159 if (IsColorEqual(opaque+i, 7160 &image->background_color)) 7161 break; 7162 } 7163 7164 if (number_opaque < 259 && i == number_opaque) 7165 { 7166 opaque[i]=image->background_color; 7167 opaque[i].opacity = OpaqueOpacity; 7168 number_opaque++; 7169 } 7170 } 7171 7172 image_colors=number_opaque+number_transparent+number_semitransparent; 6996 7173 6997 7174 if (logging != MagickFalse) 6998 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 6999 " Enter BUILD_PALETTE:"); 7175 { 7176 if (image_colors > 256) 7177 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7178 " image has more than 256 colors"); 7179 7180 else 7181 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7182 " image has %d colors",image_colors); 7183 } 7184 7185 if (mng_info->write_png_colortype != 7 && /* We won't need this info */ 7186 mng_info->write_png_colortype != 3) /* for these color types */ 7187 { 7188 ping_have_color=MagickFalse; 7189 ping_have_non_bw=MagickFalse; 7190 7191 if(image_colors > 256) 7192 { 7193 for (y=0; y < (ssize_t) image->rows; y++) 7194 { 7195 q=GetAuthenticPixels(image,0,y,image->columns,1,exception); 7196 7197 if (q == (PixelPacket *) NULL) 7198 break; 7199 7200 /* Worst case is black-and-white; we are looking at every 7201 * pixel twice. 7202 */ 7203 7204 if (ping_have_color == MagickFalse) 7205 { 7206 s=q; 7207 for (x=0; x < (ssize_t) image->columns; x++) 7208 { 7209 if (s->red != s->green || s->red != s->blue) 7210 { 7211 ping_have_color=MagickTrue; 7212 ping_have_non_bw=MagickTrue; 7213 break; 7214 } 7215 s++; 7216 } 7217 } 7218 7219 if (ping_have_non_bw == MagickFalse) 7220 { 7221 s=q; 7222 for (x=0; x < (ssize_t) image->columns; x++) 7223 { 7224 if (s->red != 0 && s->red != QuantumRange) 7225 { 7226 ping_have_non_bw=MagickTrue; 7227 } 7228 s++; 7229 } 7230 } 7231 } 7232 } 7233 } 7234 7235 if (image_colors < 257) 7236 { 7237 PixelPacket 7238 colormap[260]; 7239 7240 /* 7241 * Initialize image colormap. 7242 */ 7243 7244 if (logging != MagickFalse) 7245 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7246 " Sort the new colormap"); 7247 7248 /* Sort palette, transparent first */; 7249 7250 n = 0; 7251 7252 for (i=0; i<number_transparent; i++) 7253 colormap[n++] = transparent[i]; 7254 7255 for (i=0; i<number_semitransparent; i++) 7256 colormap[n++] = semitransparent[i]; 7257 7258 for (i=0; i<number_opaque; i++) 7259 colormap[n++] = opaque[i]; 7260 7261 7262 /* image_colors < 257; search the colormap instead of the pixels 7263 * to get ping_have_color and ping_have_non_bw 7264 */ 7265 for (i=0; i<n; i++) 7266 { 7267 if (ping_have_color == MagickFalse) 7268 { 7269 if (colormap[i].red != colormap[i].green || 7270 colormap[i].red != colormap[i].blue) 7271 { 7272 ping_have_color=MagickTrue; 7273 ping_have_non_bw=MagickTrue; 7274 break; 7275 } 7276 } 7277 7278 if (ping_have_non_bw == MagickFalse) 7279 { 7280 if (colormap[i].red != 0 && colormap[i].red != QuantumRange) 7281 ping_have_non_bw=MagickTrue; 7282 } 7283 } 7284 7285 if ((mng_info->ping_exclude_tRNS == MagickFalse || 7286 (number_transparent == 0 && number_semitransparent == 0)) && 7287 (((mng_info->write_png_colortype-1) == 7288 PNG_COLOR_TYPE_PALETTE) || 7289 (mng_info->write_png_colortype == 0))) 7290 { 7291 if (logging != MagickFalse) 7292 { 7293 if (n != (ssize_t) image_colors) 7294 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7295 " image_colors (%d) and n (%d) don't match", 7296 image_colors, n); 7297 7298 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7299 " AcquireImageColormap"); 7300 } 7301 7302 image->colors = image_colors; 7303 7304 if (AcquireImageColormap(image,image_colors) == 7305 MagickFalse) 7306 ThrowWriterException(ResourceLimitError, 7307 "MemoryAllocationFailed"); 7308 7309 for (i=0; i< (ssize_t) image_colors; i++) 7310 image->colormap[i] = colormap[i]; 7311 7312 if (logging != MagickFalse) 7313 { 7314 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7315 " image->colors=%d (%d)", 7316 (int) image->colors, image_colors); 7317 7318 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7319 " Update the pixel indexes"); 7320 } 7321 7322 for (y=0; y < (ssize_t) image->rows; y++) 7323 { 7324 q=GetAuthenticPixels(image,0,y,image->columns,1, 7325 exception); 7326 7327 if (q == (PixelPacket *) NULL) 7328 break; 7329 7330 indexes=GetAuthenticIndexQueue(image); 7331 7332 for (x=0; x < (ssize_t) image->columns; x++) 7333 { 7334 for (i=0; i< (ssize_t) image_colors; i++) 7335 { 7336 if ((image->matte == MagickFalse || 7337 image->colormap[i].opacity == q->opacity) && 7338 (IsColorEqual(&image->colormap[i], 7339 (PixelPacket *) q))) 7340 { 7341 indexes[x]=(IndexPacket) i; 7342 break; 7343 } 7344 } 7345 q++; 7346 } 7347 7348 if (SyncAuthenticPixels(image,exception) == MagickFalse) 7349 break; 7350 } 7351 } 7352 } 7000 7353 7001 7354 if (logging != MagickFalse) 7002 7355 { 7003 7356 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7004 " image->columns=%.20g",(double) image->columns); 7005 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7006 " image->rows=%.20g",(double) image->rows); 7007 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7008 " image->matte=%.20g",(double) image->matte); 7009 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7010 " image->depth=%.20g",(double) image->depth); 7357 " image->colors=%d", (int) image->colors); 7011 7358 7012 7359 if (image->colormap != NULL) 7013 {7014 (void) LogMagickEvent(CoderEvent,GetMagickModule(),7015 " Original colormap:");7016 (void) LogMagickEvent(CoderEvent,GetMagickModule(),7017 " i (red,green,blue,opacity)");7018 7019 for (i=0; i < 256; i++)7020 7360 { 7021 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7022 " %d (%d,%d,%d,%d)", 7023 (int) i, 7024 (int) image->colormap[i].red, 7025 (int) image->colormap[i].green, 7026 (int) image->colormap[i].blue, 7027 (int) image->colormap[i].opacity); 7028 } 7029 7030 for (i=image->colors - 10; i < (ssize_t) image->colors; i++) 7031 { 7032 if (i > 255) 7033 { 7034 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7035 " %d (%d,%d,%d,%d)", 7036 (int) i, 7037 (int) image->colormap[i].red, 7038 (int) image->colormap[i].green, 7039 (int) image->colormap[i].blue, 7040 (int) image->colormap[i].opacity); 7041 } 7042 } 7043 } 7044 7045 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7046 " image->colors=%d",(int) image->colors); 7047 7048 if (image->colors == 0) 7049 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7050 " (zero means unknown)"); 7051 7052 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7053 " Regenerate the colormap"); 7054 } 7055 7056 exception=(&image->exception); 7057 7058 ping_have_color=MagickFalse; 7059 ping_have_non_bw=MagickFalse; 7060 image_colors=0; 7061 7062 for (y=0; y < (ssize_t) image->rows; y++) 7063 { 7064 q=GetAuthenticPixels(image,0,y,image->columns,1,exception); 7065 7066 if (q == (PixelPacket *) NULL) 7067 break; 7068 7069 /* Worst case is black-and-white; we are looking at every 7070 * pixel twice. 7071 * 7072 * TO DO: Do the following 2 loops over the colormap, if 7073 * possible, after it has been generated, instead of over 7074 * the pixels. Only resort to looping over the pixels 7075 * when more than 256 colors (or gray levels) are present. 7076 */ 7077 7078 if (ping_have_color == MagickFalse) 7079 { 7080 s=q; 7081 for (x=0; x < (ssize_t) image->columns; x++) 7361 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7362 " i (red,green,blue,opacity)"); 7363 7364 for (i=0; i < (ssize_t) image->colors; i++) 7082 7365 { 7083 if ( s->red != s->green || s->red != s->blue)7366 if (i < 300 || i >= image->colors - 10) 7084 7367 { 7085 ping_have_color=MagickTrue; 7086 ping_have_non_bw=MagickTrue; 7087 break; 7368 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7369 " %d (%d,%d,%d,%d)", 7370 (int) i, 7371 (int) image->colormap[i].red, 7372 (int) image->colormap[i].green, 7373 (int) image->colormap[i].blue, 7374 (int) image->colormap[i].opacity); 7088 7375 } 7089 s++;7090 7376 } 7091 7377 } 7092 7378 7093 if (ping_have_non_bw == MagickFalse) 7094 { 7095 s=q; 7096 for (x=0; x < (ssize_t) image->columns; x++) 7097 { 7098 if (s->red != 0 && s->red != QuantumRange) 7099 { 7100 ping_have_non_bw=MagickTrue; 7101 break; 7102 } 7103 s++; 7104 } 7105 } 7106 7107 for (x=0; x < (ssize_t) image->columns; x++) 7108 { 7109 if (image->matte == MagickFalse || q->opacity == OpaqueOpacity) 7110 { 7111 if (number_opaque < 259) 7112 { 7113 if (number_opaque == 0) 7114 { 7115 opaque[0]=*q; 7116 opaque[0].opacity=OpaqueOpacity; 7117 number_opaque=1; 7118 } 7119 7120 for (i=0; i< (ssize_t) number_opaque; i++) 7121 { 7122 if (IsColorEqual(opaque+i, (PixelPacket *) q)) 7123 break; 7124 } 7125 7126 if (i == (ssize_t) number_opaque && 7127 number_opaque < 259) 7128 { 7129 number_opaque++; 7130 opaque[i] = *q; 7131 opaque[i].opacity = OpaqueOpacity; 7132 } 7133 } 7134 } 7135 else if (q->opacity == TransparentOpacity) 7136 { 7137 if (number_transparent < 259) 7138 { 7139 if (number_transparent == 0) 7140 { 7141 transparent[0]=*q; 7142 ping_trans_color.red=(unsigned short)(q->red); 7143 ping_trans_color.green=(unsigned short) (q->green); 7144 ping_trans_color.blue=(unsigned short) (q->blue); 7145 ping_trans_color.gray=(unsigned short) (q->blue); 7146 number_transparent = 1; 7147 } 7148 7149 for (i=0; i< (ssize_t) number_transparent; i++) 7150 { 7151 if (IsColorEqual(transparent+i, (PixelPacket *) q)) 7152 break; 7153 } 7154 7155 if (i == (ssize_t) number_transparent && 7156 number_transparent < 259) 7157 { 7158 number_transparent++; 7159 transparent[i] = *q; 7160 } 7161 } 7162 } 7163 else 7164 { 7165 if (number_semitransparent < 259) 7166 { 7167 if (number_semitransparent == 0) 7168 { 7169 semitransparent[0]=*q; 7170 number_semitransparent = 1; 7171 } 7172 7173 for (i=0; i< (ssize_t) number_semitransparent; i++) 7174 { 7175 if (IsColorEqual(semitransparent+i, 7176 (PixelPacket *) q) && 7177 q->opacity == semitransparent[i].opacity) 7178 break; 7179 } 7180 7181 if (i == (ssize_t) number_semitransparent && 7182 number_semitransparent < 259) 7183 { 7184 number_semitransparent++; 7185 semitransparent[i] = *q; 7186 } 7187 } 7188 } 7189 q++; 7190 } 7191 } 7192 7193 image_colors=number_opaque+number_transparent+number_semitransparent; 7194 7195 if (logging != MagickFalse) 7196 { 7197 if (image_colors > 256) 7198 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7199 " image has more than 256 colors"); 7200 7201 else 7202 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7203 " image has %d colors",image_colors); 7204 } 7205 7206 if (image_colors < 257) 7207 { 7208 PixelPacket 7209 colormap[260]; 7210 7211 /* 7212 Initialize image colormap. 7213 */ 7214 7215 if (logging != MagickFalse) 7216 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7217 " Sort the new colormap"); 7218 7219 /* Sort palette, transparent first */; 7220 7221 n = 0; 7222 7223 for (i=0; i<number_transparent; i++) 7224 colormap[n++] = transparent[i]; 7225 7226 for (i=0; i<number_semitransparent; i++) 7227 colormap[n++] = semitransparent[i]; 7228 7229 for (i=0; i<number_opaque; i++) 7230 colormap[n++] = opaque[i]; 7231 7232 if (ping_exclude_bKGD == MagickFalse) 7233 { 7234 /* Add the background color to the palette, if it 7235 * isn't already there. 7236 */ 7237 for (i=0; i<number_opaque; i++) 7238 { 7239 if (IsColorEqual(opaque+i, 7240 &image->background_color)) 7241 break; 7242 } 7243 7244 if (number_opaque < 257 && i == number_opaque) 7245 { 7246 opaque[i]=image->background_color; 7247 opaque[i].opacity = OpaqueOpacity; 7248 number_opaque++; 7249 } 7250 } 7251 7252 if ((mng_info->ping_exclude_tRNS == MagickFalse || 7253 (number_transparent == 0 && number_semitransparent == 0)) && 7254 (((mng_info->write_png_colortype-1) == 7255 PNG_COLOR_TYPE_PALETTE) || 7256 (mng_info->write_png_colortype == 0))) 7257 { 7258 if (logging != MagickFalse) 7259 { 7260 if (n != (ssize_t) image_colors) 7261 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7262 " image_colors (%d) and n (%d) don't match", 7263 image_colors, n); 7264 7265 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7266 " AcquireImageColormap"); 7267 } 7268 7269 image->colors = image_colors; 7270 7271 if (AcquireImageColormap(image,image_colors) == 7272 MagickFalse) 7273 ThrowWriterException(ResourceLimitError, 7274 "MemoryAllocationFailed"); 7275 7276 for (i=0; i< (ssize_t) image_colors; i++) 7277 image->colormap[i] = colormap[i]; 7278 7279 if (logging != MagickFalse) 7280 { 7281 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7282 " image->colors=%d (%d)", 7283 (int) image->colors, image_colors); 7284 7285 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7286 " Update the pixel indexes"); 7287 } 7288 7289 for (y=0; y < (ssize_t) image->rows; y++) 7290 { 7291 q=GetAuthenticPixels(image,0,y,image->columns,1, 7292 exception); 7293 7294 if (q == (PixelPacket *) NULL) 7295 break; 7296 7297 indexes=GetAuthenticIndexQueue(image); 7298 7299 for (x=0; x < (ssize_t) image->columns; x++) 7300 { 7301 for (i=0; i< (ssize_t) image_colors; i++) 7302 { 7303 if ((image->matte == MagickFalse || 7304 image->colormap[i].opacity == q->opacity) && 7305 (IsColorEqual(&image->colormap[i],(PixelPacket *) q))) 7306 { 7307 indexes[x]=(IndexPacket) i; 7308 break; 7309 } 7310 } 7311 q++; 7312 } 7313 7314 if (SyncAuthenticPixels(image,exception) == MagickFalse) 7315 break; 7316 } 7317 } 7318 } 7319 7320 if (logging != MagickFalse) 7321 { 7322 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7323 " image->colors=%d", (int) image->colors); 7324 7325 if (image->colormap != NULL) 7326 { 7327 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7328 " i (red,green,blue,opacity)"); 7329 7330 for (i=0; i < (ssize_t) image->colors; i++) 7331 { 7332 if (i < 300 || i >= image->colors - 10) 7333 { 7334 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7335 " %d (%d,%d,%d,%d)", 7336 (int) i, 7337 (int) image->colormap[i].red, 7338 (int) image->colormap[i].green, 7339 (int) image->colormap[i].blue, 7340 (int) image->colormap[i].opacity); 7341 } 7342 } 7343 } 7344 7345 if (logging != MagickFalse) 7346 { 7347 if (number_transparent < 257) 7348 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7349 " number_transparent = %d", 7350 number_transparent); 7351 else 7352 7353 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7354 " number_transparent > 256"); 7355 7356 if (number_opaque < 257) 7357 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7358 " number_opaque = %d", 7359 number_opaque); 7360 else 7361 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7362 " number_opaque > 256"); 7363 7364 if (number_semitransparent < 257) 7365 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7366 " number_semitransparent = %d", 7367 number_semitransparent); 7368 else 7369 7370 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7371 " number_semitransparent > 256"); 7372 } 7379 if (number_transparent < 257) 7380 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7381 " number_transparent = %d", 7382 number_transparent); 7383 else 7384 7385 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7386 " number_transparent > 256"); 7387 7388 if (number_opaque < 257) 7389 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7390 " number_opaque = %d", 7391 number_opaque); 7392 7393 else 7394 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7395 " number_opaque > 256"); 7396 7397 if (number_semitransparent < 257) 7398 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7399 " number_semitransparent = %d", 7400 number_semitransparent); 7401 7402 else 7403 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7404 " number_semitransparent > 256"); 7405 7406 if (ping_have_non_bw == MagickFalse) 7407 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7408 " All pixels and the background are black or white"); 7409 7410 else if (ping_have_color == MagickFalse) 7411 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7412 " All pixels and the background are gray"); 7413 7414 else 7415 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7416 " At least one pixel or the background is non-gray"); 7373 7417 7374 7418 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 7375 7419 " Exit BUILD_PALETTE:"); 7376 } 7377 } 7378 #endif /* BUILD_PNG_PALETTE */ 7420 } 7421 } 7379 7422 7380 7423 /* Force sub-8-bit grayscale images, except for black-and-white images, … … 8006 8049 } 8007 8050 8008 #if 0/* TO DO: Enable this when low bit-depth grayscale is working */8051 #if 1 /* TO DO: Enable this when low bit-depth grayscale is working */ 8009 8052 else if (ping_color_type == 8010 8053 PNG_COLOR_TYPE_GRAY && image_colors < 17 && … … 8044 8087 ping_bit_depth=4; 8045 8088 } 8046 #endif /* 0*/8089 #endif /* 1 */ 8047 8090 } 8048 8091 … … 8781 8824 for (y=0; y < (ssize_t) image->rows; y++) 8782 8825 { 8783 8784 if (logging != MagickFalse) 8826 if (logging != MagickFalse && y == 0) 8785 8827 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 8786 8828 " Writing row of pixels (0)");
Note: See TracChangeset
for help on using the changeset viewer.
