76
77
#include "magick/static.h"
77
78
#include "magick/statistic.h"
78
79
#include "magick/string_.h"
80
#include "magick/string-private.h"
79
81
#include "magick/transform.h"
80
82
#include "magick/utility.h"
81
83
#if defined(MAGICKCORE_PNG_DELEGATE)
83
85
/* Suppress libpng pedantic warnings that were added in
84
86
* libpng-1.2.41 and libpng-1.4.0. If you are working on
85
* migration to libpng-2.0, remove these defines and then
87
* migration to libpng-1.5, remove these defines and then
86
88
* fix any code that generates warnings.
88
#define PNG_DEPRECATED /* Use of this function is deprecated */
89
#define PNG_USE_RESULT /* The result of this function must be checked */
90
#define PNG_NORETURN /* This function does not return */
91
#define PNG_ALLOCATED /* The result of the function is new memory */
92
#define PNG_DEPSTRUCT /* Access to this struct member is deprecated */
90
/* #define PNG_DEPRECATED Use of this function is deprecated */
91
/* #define PNG_USE_RESULT The result of this function must be checked */
92
/* #define PNG_NORETURN This function does not return */
93
/* #define PNG_ALLOCATED The result of the function is new memory */
94
/* #define PNG_DEPSTRUCT Access to this struct member is deprecated */
564
548
assert(image != (Image *) NULL);
565
549
assert(image->signature == MagickSignature);
566
550
if (image->debug != MagickFalse)
567
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
551
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
552
" CompressColorMapTransFirst %s (%.20g colors)",image->filename,
553
(double) image->colors);
568
554
if (image->storage_class != PseudoClass || image->colors > 256 ||
569
555
image->colors < 2)
557
if (image->debug != MagickFalse)
559
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
560
" Could not compress colormap");
561
if (image->colors > 256 || image->colors == 0)
571
567
marker=(unsigned char *) AcquireQuantumMemory(image->colors,sizeof(*marker));
572
568
if (marker == (unsigned char *) NULL)
573
569
ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
583
579
Mark colors that are present.
585
number_colors=(long) image->colors;
581
number_colors=(ssize_t) image->colors;
586
582
for (i=0; i < number_colors; i++)
588
584
marker[i]=MagickFalse;
589
585
opacity[i]=OpaqueOpacity;
592
for (y=0; y < (long) image->rows; y++)
588
for (y=0; y < (ssize_t) image->rows; y++)
594
590
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
595
591
if (p == (const PixelPacket *) NULL)
597
indices=GetVirtualIndexQueue(image);
593
indexes=GetVirtualIndexQueue(image);
598
594
if (image->matte != MagickFalse)
599
for (x=0; x < (long) image->columns; x++)
595
for (x=0; x < (ssize_t) image->columns; x++)
601
marker[(int) indices[x]]=MagickTrue;
602
opacity[(int) indices[x]]=p->opacity;
603
if (indices[x] > top_used)
597
marker[(int) indexes[x]]=MagickTrue;
598
opacity[(int) indexes[x]]=GetOpacityPixelComponent(p);
599
if (indexes[x] > top_used)
608
for (x=0; x < (long) image->columns; x++)
604
for (x=0; x < (ssize_t) image->columns; x++)
610
marker[(int) indices[x]]=MagickTrue;
611
if (indices[x] > top_used)
606
marker[(int) indexes[x]]=MagickTrue;
607
if (indexes[x] > top_used)
1060
1056
if (logging != MagickFalse)
1061
1057
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
1062
" Writing %c%c%c%c chunk, length: %lu",
1063
type[0],type[1],type[2],type[3],(unsigned long) length);
1058
" Writing %c%c%c%c chunk, length: %.20g",
1059
type[0],type[1],type[2],type[3],(double) length);
1065
#endif /* PNG_LIBPNG_VER > 95 */
1061
#endif /* PNG_LIBPNG_VER > 10011 */
1067
1063
#if defined(__cplusplus) || defined(c_plusplus)
1071
#if PNG_LIBPNG_VER > 95
1067
#if PNG_LIBPNG_VER > 10011
1073
1069
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1775
1792
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1777
1794
png_pixels=(unsigned char *) NULL;
1778
if (setjmp(ping->jmpbuf))
1795
if (setjmp(png_jmpbuf(ping)))
1781
1798
PNG image is corrupt.
1783
1800
png_destroy_read_struct(&ping,&ping_info,&end_info);
1784
1801
#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
1785
(void) UnlockSemaphoreInfo(png_semaphore);
1802
UnlockSemaphoreInfo(png_semaphore);
1787
1804
if (logging != MagickFalse)
1788
1805
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
1789
1806
" exit ReadOnePNGImage() with error.");
1790
1807
if (image != (Image *) NULL)
1809
InheritException(exception,&image->exception);
1792
1812
return(GetFirstImageInList(image));
1795
1815
Prepare PNG for reading.
1797
1818
mng_info->image_found++;
1798
1819
png_set_sig_bytes(ping,8);
1799
1820
if (LocaleCompare(image_info->magick,"MNG") == 0)
1842
1864
asm_flags=png_get_asm_flags(ping);
1843
1865
png_set_asm_flags(ping, asm_flags & ~mmx_disable_mask);
1847
1870
png_read_info(ping,ping_info);
1848
if (ping_info->bit_depth < 8)
1872
png_get_IHDR(ping,ping_info,&ping_width,&ping_height,
1873
&ping_bit_depth,&ping_color_type,
1874
&ping_interlace_method,&ping_compression_method,
1875
&ping_filter_method);
1877
(void) png_get_tRNS(ping, ping_info, &ping_trans_alpha, &ping_num_trans,
1880
(void) png_get_bKGD(ping, ping_info, &ping_background);
1882
if (ping_bit_depth < 8)
1850
if (((int) ping_info->color_type == PNG_COLOR_TYPE_PALETTE))
1851
png_set_packing(ping);
1884
if (((int) ping_color_type == PNG_COLOR_TYPE_PALETTE))
1886
png_set_packing(ping);
1853
image->depth=ping_info->bit_depth;
1891
image->depth=ping_bit_depth;
1854
1892
image->depth=GetImageQuantumDepth(image,MagickFalse);
1855
image->interlace=ping_info->interlace_type != 0 ? PNGInterlace : NoInterlace;
1893
image->interlace=ping_interlace_method != 0 ? PNGInterlace : NoInterlace;
1856
1894
if (logging != MagickFalse)
1858
1896
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
1859
" PNG width: %lu, height: %lu",
1860
ping_info->width, ping_info->height);
1897
" PNG width: %.20g, height: %.20g",
1898
(double) ping_width, (double) ping_height);
1861
1899
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
1862
1900
" PNG color_type: %d, bit_depth: %d",
1863
ping_info->color_type, ping_info->bit_depth);
1901
ping_color_type, ping_bit_depth);
1864
1902
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
1865
1903
" PNG compression_method: %d",
1866
ping_info->compression_type);
1904
ping_compression_method);
1867
1905
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
1868
1906
" PNG interlace_method: %d, filter_method: %d",
1869
ping_info->interlace_type,ping_info->filter_type);
1907
ping_interlace_method,ping_filter_method);
1872
#if (PNG_LIBPNG_VER > 10008) && defined(PNG_READ_iCCP_SUPPORTED)
1873
if (ping_info->valid & PNG_INFO_iCCP)
1910
#ifdef PNG_READ_iCCP_SUPPORTED
1911
if (png_get_valid(ping,ping_info,PNG_INFO_iCCP))
1930
1969
" Reading PNG gAMA chunk: gamma: %f",file_gamma);
1933
if (mng_info->have_global_chrm != MagickFalse)
1934
image->chromaticity=mng_info->global_chrm;
1935
if (ping_info->valid & PNG_INFO_cHRM)
1972
if (!png_get_valid(ping,ping_info,PNG_INFO_cHRM))
1974
if (mng_info->have_global_chrm != MagickFalse)
1976
(void) png_set_cHRM(ping,ping_info,
1977
mng_info->global_chrm.white_point.x,
1978
mng_info->global_chrm.white_point.y,
1979
mng_info->global_chrm.red_primary.x,
1980
mng_info->global_chrm.red_primary.y,
1981
mng_info->global_chrm.green_primary.x,
1982
mng_info->global_chrm.green_primary.y,
1983
mng_info->global_chrm.blue_primary.x,
1984
mng_info->global_chrm.blue_primary.y);
1987
if (png_get_valid(ping,ping_info,PNG_INFO_cHRM))
1937
1989
(void) png_get_cHRM(ping,ping_info,
1938
1990
&image->chromaticity.white_point.x,
1950
2002
if (image->rendering_intent)
1952
image->gamma=0.45455f;
1953
image->chromaticity.red_primary.x=0.6400f;
1954
image->chromaticity.red_primary.y=0.3300f;
1955
image->chromaticity.green_primary.x=0.3000f;
1956
image->chromaticity.green_primary.y=0.6000f;
1957
image->chromaticity.blue_primary.x=0.1500f;
1958
image->chromaticity.blue_primary.y=0.0600f;
1959
image->chromaticity.white_point.x=0.3127f;
1960
image->chromaticity.white_point.y=0.3290f;
2004
png_set_sRGB(ping,ping_info,image->rendering_intent-1);
2005
png_set_gAMA(ping,ping_info,0.45455f);
2006
png_set_cHRM(ping,ping_info,
2007
0.6400f, 0.3300f, 0.3000f, 0.6000f,
2008
0.1500f, 0.0600f, 0.3127f, 0.3290f);
1962
if ((mng_info->have_global_gama != MagickFalse) || image->rendering_intent)
1963
ping_info->valid|=PNG_INFO_gAMA;
1964
if ((mng_info->have_global_chrm != MagickFalse) || image->rendering_intent)
1965
ping_info->valid|=PNG_INFO_cHRM;
1966
2010
#if defined(PNG_oFFs_SUPPORTED)
1967
if (ping_info->valid & PNG_INFO_oFFs)
2011
if (png_get_valid(ping,ping_info,PNG_INFO_oFFs))
1969
2013
image->page.x=png_get_x_offset_pixels(ping, ping_info);
1970
2014
image->page.y=png_get_y_offset_pixels(ping, ping_info);
1971
2015
if (logging != MagickFalse)
1972
2016
if (image->page.x || image->page.y)
1973
2017
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
1974
" Reading PNG oFFs chunk: x: %ld, y: %ld.",image->page.x,
2018
" Reading PNG oFFs chunk: x: %.20g, y: %.20g.",(double)
2019
image->page.x,(double) image->page.y);
1978
2022
#if defined(PNG_pHYs_SUPPORTED)
1979
if (ping_info->valid & PNG_INFO_pHYs)
2023
if (!png_get_valid(ping,ping_info,PNG_INFO_pHYs))
2025
if (mng_info->have_global_phys)
2027
png_set_pHYs(ping,ping_info,
2028
mng_info->global_x_pixels_per_unit,
2029
mng_info->global_y_pixels_per_unit,
2030
mng_info->global_phys_unit_type);
2034
if (png_get_valid(ping,ping_info,PNG_INFO_pHYs))
2001
2056
if (logging != MagickFalse)
2002
2057
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2003
" Reading PNG pHYs chunk: xres: %lu, yres: %lu, units: %d.",
2004
x_resolution, y_resolution, unit_type);
2008
if (mng_info->have_global_phys)
2010
image->x_resolution=(float) mng_info->global_x_pixels_per_unit;
2011
image->y_resolution=(float) mng_info->global_y_pixels_per_unit;
2012
if (mng_info->global_phys_unit_type == PNG_RESOLUTION_METER)
2014
image->units=PixelsPerCentimeterResolution;
2015
image->x_resolution=(double)
2016
mng_info->global_x_pixels_per_unit/100.0;
2017
image->y_resolution=(double)
2018
mng_info->global_y_pixels_per_unit/100.0;
2020
ping_info->valid|=PNG_INFO_pHYs;
2058
" Reading PNG pHYs chunk: xres: %.20g, yres: %.20g, units: %d.",
2059
(double) x_resolution,(double) y_resolution,unit_type);
2024
if (ping_info->valid & PNG_INFO_PLTE)
2062
if (png_get_valid(ping,ping_info,PNG_INFO_PLTE))
2093
2132
if (logging != MagickFalse)
2094
2133
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2095
2134
" Reading PNG bKGD chunk.");
2096
if (ping_info->bit_depth <= MAGICKCORE_QUANTUM_DEPTH)
2135
if (ping_bit_depth == MAGICKCORE_QUANTUM_DEPTH)
2098
image->background_color.red=ping_info->background.red;
2099
image->background_color.green=ping_info->background.green;
2100
image->background_color.blue=ping_info->background.blue;
2137
image->background_color.red=ping_background->red;
2138
image->background_color.green=ping_background->green;
2139
image->background_color.blue=ping_background->blue;
2141
else /* Scale background components to 16-bit */
2146
if (logging != MagickFalse)
2147
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2148
" raw ping_background=(%d,%d,%d).",ping_background->red,
2149
ping_background->green,ping_background->blue);
2152
if (ping_bit_depth == 1)
2154
else if (ping_bit_depth == 2)
2156
else if (ping_bit_depth == 4)
2158
if (ping_bit_depth <= 8)
2161
ping_background->red *= bkgd_scale;
2162
ping_background->green *= bkgd_scale;
2163
ping_background->blue *= bkgd_scale;
2165
if (logging != MagickFalse)
2167
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2168
" bkgd_scale=%d.",bkgd_scale);
2169
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2170
" ping_background=(%d,%d,%d).",ping_background->red,
2171
ping_background->green,ping_background->blue);
2104
2174
image->background_color.red=
2105
ScaleShortToQuantum(ping_info->background.red);
2175
ScaleShortToQuantum(ping_background->red);
2106
2176
image->background_color.green=
2107
ScaleShortToQuantum(ping_info->background.green);
2177
ScaleShortToQuantum(ping_background->green);
2108
2178
image->background_color.blue=
2109
ScaleShortToQuantum(ping_info->background.blue);
2179
ScaleShortToQuantum(ping_background->blue);
2181
if (logging != MagickFalse)
2182
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2183
" image->background_color=(%.20g,%.20g,%.20g).",
2184
(double) image->background_color.red,
2185
(double) image->background_color.green,
2186
(double) image->background_color.blue);
2125
2205
if (logging != MagickFalse)
2126
2206
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2127
2207
" Reading PNG tRNS chunk.");
2129
max_sample = (1 << ping_info->bit_depth) - 1;
2209
max_sample = (int) ((one << ping_bit_depth) - 1);
2131
if ((ping_info->color_type == PNG_COLOR_TYPE_GRAY &&
2132
(int)ping_info->trans_color.gray > max_sample) ||
2133
(ping_info->color_type == PNG_COLOR_TYPE_RGB &&
2134
((int)ping_info->trans_color.red > max_sample ||
2135
(int)ping_info->trans_color.green > max_sample ||
2136
(int)ping_info->trans_color.blue > max_sample)))
2211
if ((ping_color_type == PNG_COLOR_TYPE_GRAY &&
2212
(int)ping_trans_color->gray > max_sample) ||
2213
(ping_color_type == PNG_COLOR_TYPE_RGB &&
2214
((int)ping_trans_color->red > max_sample ||
2215
(int)ping_trans_color->green > max_sample ||
2216
(int)ping_trans_color->blue > max_sample)))
2138
2218
if (logging != MagickFalse)
2139
2219
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2140
2220
" Ignoring PNG tRNS chunk with out-of-range sample.");
2141
#if (PNG_LIBPNG_VER < 10007)
2142
ping_info->trans_alpha=(unsigned char *) RelinquishMagickMemory(
2143
ping_info->trans_alpha);
2144
ping_info->valid&=(~PNG_INFO_tRNS);
2146
2221
png_free_data(ping, ping_info, PNG_FREE_TRNS, 0);
2222
png_set_invalid(ping,ping_info,PNG_INFO_tRNS);
2148
2223
image->matte=MagickFalse;
2152
transparent_color.red= (Quantum)(ping_info->trans_color.red);
2153
transparent_color.green= (Quantum) (ping_info->trans_color.green);
2154
transparent_color.blue= (Quantum) (ping_info->trans_color.blue);
2155
transparent_color.opacity= (Quantum) (ping_info->trans_color.gray);
2156
if (ping_info->color_type == PNG_COLOR_TYPE_GRAY)
2227
transparent_color.red= (Quantum)(ping_trans_color->red);
2228
transparent_color.green= (Quantum) (ping_trans_color->green);
2229
transparent_color.blue= (Quantum) (ping_trans_color->blue);
2230
transparent_color.opacity= (Quantum) (ping_trans_color->gray);
2231
if (ping_color_type == PNG_COLOR_TYPE_GRAY)
2158
if (ping_info->bit_depth < 8)
2233
if (ping_bit_depth < 8)
2160
2235
transparent_color.opacity=(Quantum) (((
2161
ping_info->trans_color.gray)*255)/max_sample);
2236
ping_trans_color->gray)*255)/max_sample);
2163
2238
transparent_color.red=transparent_color.opacity;
2164
2239
transparent_color.green=transparent_color.opacity;
2169
2244
#if defined(PNG_READ_sBIT_SUPPORTED)
2170
2245
if (mng_info->have_global_sbit)
2172
if (!(ping_info->valid & PNG_INFO_sBIT))
2247
if (!png_get_valid(ping,ping_info,PNG_INFO_sBIT))
2173
2248
png_set_sBIT(ping,ping_info,&mng_info->global_sbit);
2176
2251
num_passes=png_set_interlace_handling(ping);
2177
2253
png_read_update_info(ping,ping_info);
2255
ping_rowbytes=png_get_rowbytes(ping,ping_info);
2179
2258
Initialize image structure.
2181
2260
mng_info->image_box.left=0;
2182
mng_info->image_box.right=(long) ping_info->width;
2261
mng_info->image_box.right=(ssize_t) ping_width;
2183
2262
mng_info->image_box.top=0;
2184
mng_info->image_box.bottom=(long) ping_info->height;
2263
mng_info->image_box.bottom=(ssize_t) ping_height;
2185
2264
if (mng_info->mng_type == 0)
2187
mng_info->mng_width=ping_info->width;
2188
mng_info->mng_height=ping_info->height;
2266
mng_info->mng_width=ping_width;
2267
mng_info->mng_height=ping_height;
2189
2268
mng_info->frame=mng_info->image_box;
2190
2269
mng_info->clip=mng_info->image_box;
2270
2353
if (image->delay != 0)
2271
2354
mng_info->scenes_found++;
2272
if ((image_info->number_scenes != 0) && (mng_info->scenes_found > (long)
2273
(image_info->first_scene+image_info->number_scenes)))
2355
if ((image->ping != MagickFalse) || (
2356
(image_info->number_scenes != 0) && (mng_info->scenes_found > (ssize_t)
2357
(image_info->first_scene+image_info->number_scenes))))
2275
2359
if (logging != MagickFalse)
2276
2360
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2277
" Skipping PNG image data for scene %ld",
2361
" Skipping PNG image data for scene %.20g",(double)
2278
2362
mng_info->scenes_found-1);
2279
2363
png_destroy_read_struct(&ping,&ping_info,&end_info);
2280
2364
#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
2281
(void) UnlockSemaphoreInfo(png_semaphore);
2365
UnlockSemaphoreInfo(png_semaphore);
2283
2367
if (logging != MagickFalse)
2284
2368
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2338
depth=(long) ping_info->bit_depth;
2425
depth=(ssize_t) ping_bit_depth;
2340
image->matte=(((int) ping_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) ||
2341
((int) ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ||
2342
(ping_info->valid & PNG_INFO_tRNS)) ? MagickTrue : MagickFalse;
2427
image->matte=(((int) ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA) ||
2428
((int) ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ||
2429
(png_get_valid(ping,ping_info,PNG_INFO_tRNS))) ?
2430
MagickTrue : MagickFalse;
2344
for (y=0; y < (long) image->rows; y++)
2432
for (y=0; y < (ssize_t) image->rows; y++)
2346
2434
if (num_passes > 1)
2347
row_offset=ping_info->rowbytes*y;
2435
row_offset=ping_rowbytes*y;
2350
2438
png_read_row(ping,png_pixels+row_offset,NULL);
2409
2497
*r++=OpaqueOpacity;
2412
else if (ping_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2413
for (x=(long) (4*image->columns); x != 0; x--)
2500
else if (ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2501
for (x=(ssize_t) (4*image->columns); x != 0; x--)
2418
else if (ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
2419
for (x=(long) (2*image->columns); x != 0; x--)
2506
else if (ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
2507
for (x=(ssize_t) (2*image->columns); x != 0; x--)
2425
if (depth == 8 && ping_info->color_type == PNG_COLOR_TYPE_GRAY)
2513
if (depth == 8 && ping_color_type == PNG_COLOR_TYPE_GRAY)
2426
2514
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
2427
2515
GrayQuantum,png_pixels+row_offset);
2428
if (ping_info->color_type == PNG_COLOR_TYPE_GRAY ||
2429
ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
2516
if (ping_color_type == PNG_COLOR_TYPE_GRAY ||
2517
ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
2431
2519
quantum_info->depth=8;
2432
2520
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
2433
2521
GrayAlphaQuantum,png_pixels+row_offset);
2435
else if (depth == 8 && ping_info->color_type == PNG_COLOR_TYPE_RGB)
2523
else if (depth == 8 && ping_color_type == PNG_COLOR_TYPE_RGB)
2436
2524
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
2437
2525
RGBQuantum,png_pixels+row_offset);
2438
else if (ping_info->color_type == PNG_COLOR_TYPE_RGB ||
2439
ping_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2526
else if (ping_color_type == PNG_COLOR_TYPE_RGB ||
2527
ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2441
2529
quantum_info->depth=8;
2442
2530
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
2443
2531
RGBAQuantum,png_pixels+row_offset);
2445
else if (ping_info->color_type == PNG_COLOR_TYPE_PALETTE)
2533
else if (ping_color_type == PNG_COLOR_TYPE_PALETTE)
2446
2534
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
2447
2535
IndexQuantum,png_pixels+row_offset);
2448
2536
#else /* (MAGICKCORE_QUANTUM_DEPTH != 8) */
2449
if ((int) ping_info->color_type == PNG_COLOR_TYPE_GRAY)
2537
if ((int) ping_color_type == PNG_COLOR_TYPE_GRAY)
2450
2538
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
2451
2539
GrayQuantum,png_pixels+row_offset,exception);
2452
else if ((int) ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
2540
else if ((int) ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
2453
2541
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
2454
2542
GrayAlphaQuantum,png_pixels+row_offset,exception);
2455
else if ((int) ping_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2543
else if ((int) ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2456
2544
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
2457
2545
RGBAQuantum,png_pixels+row_offset,exception);
2458
else if ((int) ping_info->color_type == PNG_COLOR_TYPE_PALETTE)
2546
else if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE)
2459
2547
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
2460
2548
IndexQuantum,png_pixels+row_offset,exception);
2462
2550
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
2463
2551
RGBQuantum,png_pixels+row_offset,exception);
2553
if ((image->previous == (Image *) NULL) && (num_passes == 1))
2555
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
2557
if (status == MagickFalse)
2465
2560
if (SyncAuthenticPixels(image,exception) == MagickFalse)
2468
if (image->previous == (Image *) NULL)
2563
if ((image->previous == (Image *) NULL) && (num_passes != 1))
2470
2565
status=SetImageProgress(image,LoadImageTag,pass,num_passes);
2471
2566
if (status == MagickFalse)
2485
2580
Convert grayscale image to PseudoClass pixel packets.
2487
image->matte=ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA ?
2582
image->matte=ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA ?
2488
2583
MagickTrue : MagickFalse;
2489
2584
quantum_scanline=(Quantum *) AcquireQuantumMemory(image->columns,
2490
2585
(image->matte ? 2 : 1)*sizeof(*quantum_scanline));
2491
2586
if (quantum_scanline == (Quantum *) NULL)
2492
2587
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
2493
for (y=0; y < (long) image->rows; y++)
2588
for (y=0; y < (ssize_t) image->rows; y++)
2495
2590
if (num_passes > 1)
2496
row_offset=ping_info->rowbytes*y;
2591
row_offset=ping_rowbytes*y;
2499
2594
png_read_row(ping,png_pixels+row_offset,NULL);
2500
2595
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
2501
2596
if (q == (PixelPacket *) NULL)
2503
indices=GetAuthenticIndexQueue(image);
2598
indexes=GetAuthenticIndexQueue(image);
2504
2599
p=png_pixels+row_offset;
2505
2600
r=quantum_scanline;
2506
switch (ping_info->bit_depth)
2601
switch (ping_bit_depth)
2513
for (x=(long) image->columns-7; x > 0; x-=8)
2608
for (x=(ssize_t) image->columns-7; x > 0; x-=8)
2515
2610
for (bit=7; bit >= 0; bit--)
2516
2611
*r++=(Quantum) ((*p) & (0x01 << bit) ? 0x01 : 0x00);
2650
2752
if (quantum_info != (QuantumInfo *) NULL)
2651
2753
quantum_info=DestroyQuantumInfo(quantum_info);
2652
2754
if (image->storage_class == PseudoClass)
2653
(void) SyncImage(image);
2760
image->matte=MagickFalse;
2761
(void) SyncImage(image);
2654
2764
png_read_end(ping,ping_info);
2656
2766
if (image_info->number_scenes != 0 && mng_info->scenes_found-1 <
2657
(long) image_info->first_scene && image->delay != 0)
2767
(ssize_t) image_info->first_scene && image->delay != 0)
2659
2769
png_destroy_read_struct(&ping,&ping_info,&end_info);
2660
2770
png_pixels=(unsigned char *) RelinquishMagickMemory(png_pixels);
2661
2771
image->colors=2;
2662
2772
(void) SetImageBackgroundColor(image);
2663
2773
#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
2664
(void) UnlockSemaphoreInfo(png_semaphore);
2774
UnlockSemaphoreInfo(png_semaphore);
2666
2776
if (logging != MagickFalse)
2667
2777
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2668
2778
" exit ReadOnePNGImage() early.");
2671
if (ping_info->valid & PNG_INFO_tRNS)
2781
if (png_get_valid(ping,ping_info,PNG_INFO_tRNS))
2679
2789
storage_class=image->storage_class;
2680
2790
image->matte=MagickTrue;
2681
for (y=0; y < (long) image->rows; y++)
2683
image->storage_class=storage_class;
2684
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
2685
if (q == (PixelPacket *) NULL)
2687
indices=GetAuthenticIndexQueue(image);
2792
#if 1 /* balfour fix */
2793
/* From imagemagick discourse server, 5 Feb 2010 */
2795
if (storage_class == PseudoClass)
2797
if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE)
2799
for (x=0; x < ping_num_trans; x++)
2801
image->colormap[x].opacity =
2802
ScaleCharToQuantum((unsigned char)(255-ping_trans_alpha[x]));
2805
else if (ping_color_type == PNG_COLOR_TYPE_GRAY)
2807
for (x=0; x < (int) image->colors; x++)
2809
if (image->colormap[x].red == transparent_color.opacity)
2811
image->colormap[x].opacity = (Quantum) TransparentOpacity;
2815
(void) SyncImage(image);
2820
for (y=0; y < (ssize_t) image->rows; y++)
2822
image->storage_class=storage_class;
2823
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
2824
if (q == (PixelPacket *) NULL)
2826
indexes=GetAuthenticIndexQueue(image);
2828
for (x=(ssize_t) image->columns-1; x >= 0; x--)
2830
if (ScaleQuantumToChar(q->red) == transparent_color.red &&
2831
ScaleQuantumToChar(q->green) == transparent_color.green &&
2832
ScaleQuantumToChar(q->blue) == transparent_color.blue)
2833
q->opacity=(Quantum) TransparentOpacity;
2835
SetOpacityPixelComponent(q,OpaqueOpacity);
2838
if (SyncAuthenticPixels(image,exception) == MagickFalse)
2843
#else /* not balfour */
2846
for (y=0; y < (ssize_t) image->rows; y++)
2848
image->storage_class=storage_class;
2849
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
2850
if (q == (PixelPacket *) NULL)
2852
indexes=GetAuthenticIndexQueue(image);
2689
2854
if (storage_class == PseudoClass)
2694
if ((int) ping_info->color_type == PNG_COLOR_TYPE_PALETTE)
2695
for (x=0; x < (long) image->columns; x++)
2859
if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE)
2860
for (x=0; x < (ssize_t) image->columns; x++)
2697
indexpacket=indices[x];
2698
if (indexpacket < ping_info->num_trans)
2862
indexpacket=indexes[x];
2863
if (indexpacket < ping_num_trans)
2699
2864
q->opacity=ScaleCharToQuantum((unsigned char)
2700
(255-ping_info->trans_alpha[(long) indexpacket]));
2865
(255-ping_trans_alpha[(ssize_t) indexpacket]));
2702
q->opacity=OpaqueOpacity;
2867
SetOpacityPixelComponent(q,OpaqueOpacity);
2705
else if (ping_info->color_type == PNG_COLOR_TYPE_GRAY)
2706
for (x=0; x < (long) image->columns; x++)
2870
else if (ping_color_type == PNG_COLOR_TYPE_GRAY)
2871
for (x=0; x < (ssize_t) image->columns; x++)
2708
indexpacket=indices[x];
2709
q->red=image->colormap[(long) indexpacket].red;
2873
indexpacket=indexes[x];
2874
q->red=image->colormap[(ssize_t) indexpacket].red;
2710
2875
q->green=q->red;
2711
2876
q->blue=q->red;
2712
2877
if (q->red == transparent_color.opacity)
2713
2878
q->opacity=(Quantum) TransparentOpacity;
2715
q->opacity=OpaqueOpacity;
2880
SetOpacityPixelComponent(q,OpaqueOpacity);
2720
for (x=(long) image->columns-1; x >= 0; x--)
2885
for (x=(ssize_t) image->columns-1; x >= 0; x--)
2722
2887
if (ScaleQuantumToChar(q->red) == transparent_color.red &&
2723
2888
ScaleQuantumToChar(q->green) == transparent_color.green &&
2724
2889
ScaleQuantumToChar(q->blue) == transparent_color.blue)
2725
2890
q->opacity=(Quantum) TransparentOpacity;
2727
q->opacity=OpaqueOpacity;
2892
SetOpacityPixelComponent(q,OpaqueOpacity);
2730
2895
if (SyncAuthenticPixels(image,exception) == MagickFalse)
2898
#endif /* not balfour */
2733
2899
image->storage_class=DirectClass;
2735
2901
#if (MAGICKCORE_QUANTUM_DEPTH == 8)
2825
2981
(void) ThrowMagickException(&image->exception,GetMagickModule(),
2826
2982
ResourceLimitError,"Cloning image for object buffer failed",
2827
2983
"`%s'",image->filename);
2828
png_get_IHDR(ping,ping_info,&width,&height,&bit_depth,&color_type,
2829
&interlace_method,&compression_method,&filter_method);
2830
if (width > 250000L || height > 250000L)
2984
if (ping_width > 250000L || ping_height > 250000L)
2831
2985
png_error(ping,"PNG Image dimensions are too large.");
2832
mng_info->ob[object_id]->width=width;
2833
mng_info->ob[object_id]->height=height;
2834
mng_info->ob[object_id]->color_type=color_type;
2835
mng_info->ob[object_id]->sample_depth=bit_depth;
2836
mng_info->ob[object_id]->interlace_method=interlace_method;
2837
mng_info->ob[object_id]->compression_method=compression_method;
2838
mng_info->ob[object_id]->filter_method=filter_method;
2839
if (ping_info->valid & PNG_INFO_PLTE)
2986
mng_info->ob[object_id]->width=ping_width;
2987
mng_info->ob[object_id]->height=ping_height;
2988
mng_info->ob[object_id]->color_type=ping_color_type;
2989
mng_info->ob[object_id]->sample_depth=ping_bit_depth;
2990
mng_info->ob[object_id]->interlace_method=ping_interlace_method;
2991
mng_info->ob[object_id]->compression_method=
2992
ping_compression_method;
2993
mng_info->ob[object_id]->filter_method=ping_filter_method;
2994
if (png_get_valid(ping,ping_info,PNG_INFO_PLTE))
3555
3710
jng_image=ReadImage(alpha_image_info,exception);
3556
3711
if (jng_image != (Image *) NULL)
3557
for (y=0; y < (long) image->rows; y++)
3712
for (y=0; y < (ssize_t) image->rows; y++)
3559
3714
s=GetVirtualPixels(jng_image,0,y,image->columns,1,
3560
3715
&image->exception);
3561
3716
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
3562
3717
if (image->matte != MagickFalse)
3563
for (x=(long) image->columns; x != 0; x--,q++,s++)
3718
for (x=(ssize_t) image->columns; x != 0; x--,q++,s++)
3564
3719
q->opacity=(Quantum) QuantumRange-s->red;
3566
for (x=(long) image->columns; x != 0; x--,q++,s++)
3721
for (x=(ssize_t) image->columns; x != 0; x--,q++,s++)
3568
3723
q->opacity=(Quantum) QuantumRange-s->red;
3569
3724
if (q->opacity != OpaqueOpacity)
3992
4150
if (memcmp(type,mng_MHDR,4) == 0)
3994
mng_info->mng_width=(unsigned long) ((p[0] << 24) | (p[1] << 16) |
4152
mng_info->mng_width=(size_t) ((p[0] << 24) | (p[1] << 16) |
3995
4153
(p[2] << 8) | p[3]);
3996
mng_info->mng_height=(unsigned long) ((p[4] << 24) | (p[5] << 16) |
4154
mng_info->mng_height=(size_t) ((p[4] << 24) | (p[5] << 16) |
3997
4155
(p[6] << 8) | p[7]);
3998
4156
if (logging != MagickFalse)
4000
4158
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
4001
" MNG width: %lu",mng_info->mng_width);
4159
" MNG width: %.20g",(double) mng_info->mng_width);
4002
4160
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
4003
" MNG height: %lu",mng_info->mng_height);
4161
" MNG height: %.20g",(double) mng_info->mng_height);
4006
mng_info->ticks_per_second=(unsigned long) mng_get_long(p);
4164
mng_info->ticks_per_second=(size_t) mng_get_long(p);
4007
4165
if (mng_info->ticks_per_second == 0)
4008
4166
default_frame_delay=0;
4040
4198
if ((mng_info->mng_width > 65535L) ||
4041
4199
(mng_info->mng_height > 65535L))
4042
4200
ThrowReaderException(ImageError,"WidthOrHeightExceedsLimit");
4043
(void) FormatMagickString(page_geometry,MaxTextExtent,"%lux%lu+0+0",
4044
mng_info->mng_width,mng_info->mng_height);
4201
(void) FormatMagickString(page_geometry,MaxTextExtent,
4202
"%.20gx%.20g+0+0",(double) mng_info->mng_width,(double)
4203
mng_info->mng_height);
4045
4204
mng_info->frame.left=0;
4046
mng_info->frame.right=(long) mng_info->mng_width;
4205
mng_info->frame.right=(ssize_t) mng_info->mng_width;
4047
4206
mng_info->frame.top=0;
4048
mng_info->frame.bottom=(long) mng_info->mng_height;
4207
mng_info->frame.bottom=(ssize_t) mng_info->mng_height;
4049
4208
mng_info->clip=default_fb=previous_fb=mng_info->frame;
4050
4209
for (i=0; i < MNG_MAX_OBJECTS; i++)
4051
4210
mng_info->object_clip[i]=mng_info->frame;
4122
4281
if (length > 11)
4124
mng_info->x_off[object_id]=(long) ((p[4] << 24) | (p[5] << 16) |
4283
mng_info->x_off[object_id]=(ssize_t) ((p[4] << 24) | (p[5] << 16) |
4125
4284
(p[6] << 8) | p[7]);
4126
mng_info->y_off[object_id]=(long) ((p[8] << 24) | (p[9] << 16) |
4285
mng_info->y_off[object_id]=(ssize_t) ((p[8] << 24) | (p[9] << 16) |
4127
4286
(p[10] << 8) | p[11]);
4128
4287
if (logging != MagickFalse)
4130
4289
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
4131
" x_off[%d]: %lu",object_id,mng_info->x_off[object_id]);
4290
" x_off[%d]: %.20g",object_id,(double)
4291
mng_info->x_off[object_id]);
4132
4292
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
4133
" y_off[%d]: %lu",object_id,mng_info->y_off[object_id]);
4293
" y_off[%d]: %.20g",object_id,(double)
4294
mng_info->y_off[object_id]);
4341
4502
p++; /* change_sync */
4342
4503
if (change_delay)
4344
frame_delay=(1UL*image->ticks_per_second*
4345
(mng_get_long(p))/mng_info->ticks_per_second);
4505
frame_delay=1UL*image->ticks_per_second*
4507
if (mng_info->ticks_per_second != 0)
4508
frame_delay/=mng_info->ticks_per_second;
4510
frame_delay=PNG_UINT_31_MAX;
4346
4511
if (change_delay == 2)
4347
4512
default_frame_delay=frame_delay;
4349
4514
if (logging != MagickFalse)
4350
4515
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
4351
" Framing_delay=%ld",frame_delay);
4516
" Framing_delay=%.20g",(double) frame_delay);
4353
4518
if (change_timeout)
4355
frame_timeout=(1UL*image->ticks_per_second*
4356
(mng_get_long(p))/mng_info->ticks_per_second);
4520
frame_timeout=1UL*image->ticks_per_second*
4522
if (mng_info->ticks_per_second != 0)
4523
frame_timeout/=mng_info->ticks_per_second;
4525
frame_timeout=PNG_UINT_31_MAX;
4357
4526
if (change_delay == 2)
4358
4527
default_frame_timeout=frame_timeout;
4360
4529
if (logging != MagickFalse)
4361
4530
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
4362
" Framing_timeout=%ld",frame_timeout);
4531
" Framing_timeout=%.20g",(double) frame_timeout);
4364
4533
if (change_clipping)
4427
4597
(void) SetImageBackgroundColor(image);
4428
4598
if (logging != MagickFalse)
4429
4599
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
4430
" Inserted background layer, L=%ld, R=%ld, T=%ld, B=%ld",
4431
mng_info->clip.left,mng_info->clip.right,
4432
mng_info->clip.top,mng_info->clip.bottom);
4600
" Inserted background layer, L=%.20g, R=%.20g T=%.20g, B=%.20g",
4601
(double) mng_info->clip.left,(double) mng_info->clip.right,
4602
(double) mng_info->clip.top,(double) mng_info->clip.bottom);
4435
4605
chunk=(unsigned char *) RelinquishMagickMemory(chunk);
4954
5126
(void) SetImageBackgroundColor(image);
4955
5127
if (logging != MagickFalse)
4956
5128
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
4957
" Inserted background layer, L=%ld, R=%ld, T=%ld, B=%ld",
4958
mng_info->clip.left,mng_info->clip.right,
4959
mng_info->clip.top,mng_info->clip.bottom);
5129
" Inserted background layer, L=%.20g, R=%.20g T=%.20g, B=%.20g",
5130
(double) mng_info->clip.left,(double) mng_info->clip.right,
5131
(double) mng_info->clip.top,(double) mng_info->clip.bottom);
4961
5133
#endif /* MNG_INSERT_LAYERS */
4962
5134
first_mng_object=MagickFalse;
5207
5379
n=GetAuthenticPixels(image,0,0,image->columns,1,exception);
5208
5380
(void) CopyMagickMemory(next,n,length);
5209
for (y=0; y < (long) image->rows; y++)
5381
for (y=0; y < (ssize_t) image->rows; y++)
5212
m=(long) mng_info->magn_mt;
5213
else if (magn_methy > 1 && y == (long) image->rows-2)
5214
m=(long) mng_info->magn_mb;
5215
else if (magn_methy <= 1 && y == (long) image->rows-1)
5216
m=(long) mng_info->magn_mb;
5217
else if (magn_methy > 1 && y == (long) image->rows-1)
5384
m=(ssize_t) mng_info->magn_mt;
5385
else if (magn_methy > 1 && y == (ssize_t) image->rows-2)
5386
m=(ssize_t) mng_info->magn_mb;
5387
else if (magn_methy <= 1 && y == (ssize_t) image->rows-1)
5388
m=(ssize_t) mng_info->magn_mb;
5389
else if (magn_methy > 1 && y == (ssize_t) image->rows-1)
5220
m=(long) mng_info->magn_my;
5392
m=(ssize_t) mng_info->magn_my;
5224
if (y < (long) image->rows-1)
5396
if (y < (ssize_t) image->rows-1)
5226
5398
n=GetAuthenticPixels(image,0,y+1,image->columns,1,
5260
5432
/* Interpolate */
5261
(*q).red=(QM) (((long) (2*i*((*n).red
5262
-(*pixels).red)+m))/((long) (m*2))
5433
(*q).red=(QM) (((ssize_t) (2*i*((*n).red
5434
-(*pixels).red)+m))/((ssize_t) (m*2))
5263
5435
+(*pixels).red);
5264
(*q).green=(QM) (((long) (2*i*((*n).green
5265
-(*pixels).green)+m))/((long) (m*2))
5436
(*q).green=(QM) (((ssize_t) (2*i*((*n).green
5437
-(*pixels).green)+m))/((ssize_t) (m*2))
5266
5438
+(*pixels).green);
5267
(*q).blue=(QM) (((long) (2*i*((*n).blue
5268
-(*pixels).blue)+m))/((long) (m*2))
5439
(*q).blue=(QM) (((ssize_t) (2*i*((*n).blue
5440
-(*pixels).blue)+m))/((ssize_t) (m*2))
5269
5441
+(*pixels).blue);
5270
5442
if (image->matte != MagickFalse)
5271
(*q).opacity=(QM) (((long)
5443
(*q).opacity=(QM) (((ssize_t)
5272
5444
(2*i*((*n).opacity
5273
5445
-(*pixels).opacity)+m))
5274
/((long) (m*2))+(*pixels).opacity);
5446
/((ssize_t) (m*2))+(*pixels).opacity);
5276
5448
if (magn_methy == 4)
5332
5504
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
5333
5505
pixels=q+(image->columns-length);
5335
for (x=(long) (image->columns-length);
5336
x < (long) image->columns; x++)
5507
for (x=(ssize_t) (image->columns-length);
5508
x < (ssize_t) image->columns; x++)
5338
if (x == (long) (image->columns-length))
5339
m=(long) mng_info->magn_ml;
5340
else if (magn_methx > 1 && x == (long) image->columns-2)
5341
m=(long) mng_info->magn_mr;
5342
else if (magn_methx <= 1 && x == (long) image->columns-1)
5343
m=(long) mng_info->magn_mr;
5344
else if (magn_methx > 1 && x == (long) image->columns-1)
5510
if (x == (ssize_t) (image->columns-length))
5511
m=(ssize_t) mng_info->magn_ml;
5512
else if (magn_methx > 1 && x == (ssize_t) image->columns-2)
5513
m=(ssize_t) mng_info->magn_mr;
5514
else if (magn_methx <= 1 && x == (ssize_t) image->columns-1)
5515
m=(ssize_t) mng_info->magn_mr;
5516
else if (magn_methx > 1 && x == (ssize_t) image->columns-1)
5347
m=(long) mng_info->magn_mx;
5519
m=(ssize_t) mng_info->magn_mx;
5348
5520
for (i=0; i < m; i++)
5350
5522
if (magn_methx <= 1)
5525
5697
const PixelPacket
5528
ok_to_reduce=(((((unsigned long) image->background_color.red >> 8) &
5700
ok_to_reduce=(((((size_t) image->background_color.red >> 8) &
5530
== ((unsigned long) image->background_color.red & 0xff)) &&
5531
((((unsigned long) image->background_color.green >> 8) & 0xff)
5532
== ((unsigned long) image->background_color.green & 0xff)) &&
5533
((((unsigned long) image->background_color.blue >> 8) & 0xff)
5534
== ((unsigned long) image->background_color.blue & 0xff)));
5702
== ((size_t) image->background_color.red & 0xff)) &&
5703
((((size_t) image->background_color.green >> 8) & 0xff)
5704
== ((size_t) image->background_color.green & 0xff)) &&
5705
((((size_t) image->background_color.blue >> 8) & 0xff)
5706
== ((size_t) image->background_color.blue & 0xff)));
5535
5707
if (ok_to_reduce && image->storage_class == PseudoClass)
5539
for (indx=0; indx < (long) image->colors; indx++)
5711
for (indx=0; indx < (ssize_t) image->colors; indx++)
5541
ok_to_reduce=(((((unsigned long) image->colormap[indx].red >>
5713
ok_to_reduce=(((((size_t) image->colormap[indx].red >>
5543
== ((unsigned long) image->colormap[indx].red & 0xff)) &&
5544
((((unsigned long) image->colormap[indx].green >> 8) & 0xff)
5545
== ((unsigned long) image->colormap[indx].green & 0xff)) &&
5546
((((unsigned long) image->colormap[indx].blue >> 8) & 0xff)
5547
== ((unsigned long) image->colormap[indx].blue & 0xff)));
5715
== ((size_t) image->colormap[indx].red & 0xff)) &&
5716
((((size_t) image->colormap[indx].green >> 8) & 0xff)
5717
== ((size_t) image->colormap[indx].green & 0xff)) &&
5718
((((size_t) image->colormap[indx].blue >> 8) & 0xff)
5719
== ((size_t) image->colormap[indx].blue & 0xff)));
5548
5720
if (ok_to_reduce == MagickFalse)
5552
5724
if ((ok_to_reduce != MagickFalse) &&
5553
5725
(image->storage_class != PseudoClass))
5561
for (y=0; y < (long) image->rows; y++)
5733
for (y=0; y < (ssize_t) image->rows; y++)
5563
5735
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
5564
5736
if (p == (const PixelPacket *) NULL)
5566
for (x=(long) image->columns-1; x >= 0; x--)
5738
for (x=(ssize_t) image->columns-1; x >= 0; x--)
5568
5740
ok_to_reduce=((
5569
(((unsigned long) p->red >> 8) & 0xff) ==
5570
((unsigned long) p->red & 0xff)) &&
5571
((((unsigned long) p->green >> 8) & 0xff) ==
5572
((unsigned long) p->green & 0xff)) &&
5573
((((unsigned long) p->blue >> 8) & 0xff) ==
5574
((unsigned long) p->blue & 0xff)) &&
5741
(((size_t) p->red >> 8) & 0xff) ==
5742
((size_t) p->red & 0xff)) &&
5743
((((size_t) p->green >> 8) & 0xff) ==
5744
((size_t) p->green & 0xff)) &&
5745
((((size_t) p->blue >> 8) & 0xff) ==
5746
((size_t) p->blue & 0xff)) &&
5575
5747
(((!image->matte ||
5576
(((unsigned long) p->opacity >> 8) & 0xff) ==
5577
((unsigned long) p->opacity & 0xff)))));
5748
(((size_t) p->opacity >> 8) & 0xff) ==
5749
((size_t) p->opacity & 0xff)))));
5578
5750
if (ok_to_reduce == 0)
5791
5964
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
5792
5965
" After coalesce:");
5793
5966
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
5794
" scene 0 delay=%lu dispose=%d",image->delay,(int) image->dispose);
5967
" scene 0 delay=%.20g dispose=%.20g",(double) image->delay,
5968
(double) image->dispose);
5795
5969
while (GetNextImageInList(image) != (Image *) NULL)
5797
image=GetNextImageInList(image);
5798
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
5799
" scene %d delay=%lu dispose=%d",++scene,
5800
image->delay,(int) image->dispose);
5971
image=GetNextImageInList(image);
5972
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
5973
" scene %.20g delay=%.20g dispose=%.20g",(double) scene++,
5974
(double) image->delay,(double) image->dispose);
5803
5977
image=GetFirstImageInList(image);
5804
5978
MngInfoFreeStruct(mng_info,&have_mng_structure);
5805
5979
have_mng_structure=MagickFalse;
6087
6260
% transparent region at the top and/or left.
6090
#if (PNG_LIBPNG_VER > 99 && PNG_LIBPNG_VER < 10007)
6091
/* This function became available in libpng version 1.0.6g. */
6093
png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
6096
png_free(png_ptr, png_ptr->zbuf); png_ptr->zbuf=NULL;
6097
png_ptr->zbuf_size=(png_size_t) size;
6098
png_ptr->zbuf=(png_bytep) png_malloc(png_ptr, size);
6099
if (png_ptr->zbuf == 0)
6100
png_error(png_ptr,"Unable to allocate zbuf");
6105
6264
png_write_raw_profile(const ImageInfo *image_info,png_struct *ping,
6106
6265
png_info *ping_info, unsigned char *profile_type, unsigned char
6107
6266
*profile_description, unsigned char *profile_data, png_uint_32 length)
6109
#if (PNG_LIBPNG_VER > 10005)
6127
6285
hex[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
6130
#if (PNG_LIBPNG_VER <= 10005)
6131
if (image_info->verbose)
6132
(void) printf("Not ");
6133
image_info=image_info;
6135
ping_info=ping_info;
6136
profile_type=profile_type;
6137
profile_description=profile_description;
6138
profile_data=profile_data;
6141
6287
if (LocaleNCompare((char *) profile_type+1, "ng-chunk-",9) == 0)
6144
6290
if (image_info->verbose)
6146
(void) printf("writing raw profile: type=%s, length=%lu\n",
6147
(char *) profile_type, length);
6292
(void) printf("writing raw profile: type=%s, length=%.20g\n",
6293
(char *) profile_type, (double) length);
6149
#if (PNG_LIBPNG_VER > 10005)
6150
6295
text=(png_textp) png_malloc(ping,(png_uint_32) sizeof(png_text));
6151
6296
description_length=(png_uint_32) strlen((const char *) profile_description);
6152
6297
allocated_length=(png_uint_32) (length*2 + (length >> 5) + 20
6380
6562
if (logging != MagickFalse)
6382
6564
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6383
" width=%lu",ping_info->width);
6384
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6385
" height=%lu",ping_info->height);
6386
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6387
" image_matte=%u",image->matte);
6388
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6389
" image_depth=%lu",image->depth);
6390
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6391
" requested PNG image_depth=%lu",image->depth);
6565
" width=%.20g",(double) ping_width);
6566
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6567
" height=%.20g",(double) ping_height);
6568
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6569
" image_matte=%.20g",(double) image->matte);
6570
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6571
" image_depth=%.20g",(double) image->depth);
6572
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6573
" requested PNG image_depth=%.20g",(double) image->depth);
6393
6575
save_image_depth=image_depth;
6394
ping_info->bit_depth=(png_byte) save_image_depth;
6576
ping_bit_depth=(png_byte) save_image_depth;
6395
6577
#if defined(PNG_pHYs_SUPPORTED)
6396
6578
if ((image->x_resolution != 0) && (image->y_resolution != 0) &&
6397
6579
(!mng_info->write_mng || !mng_info->equal_physs))
6505
6687
(void) SyncImage(image);
6506
6688
if (logging != MagickFalse)
6507
6689
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6508
" Colors quantized to %ld",number_colors);
6690
" Colors quantized to %.20g",(double) number_colors);
6511
ping_info->valid|=PNG_INFO_tRNS;
6693
png_set_invalid(ping,ping_info,PNG_INFO_tRNS);
6513
6695
Set image palette.
6515
ping_info->color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
6516
ping_info->valid|=PNG_INFO_PLTE;
6697
ping_color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
6517
6698
#if defined(PNG_SORT_PALETTE)
6518
6699
save_number_colors=image_colors;
6519
6700
if (CompressColormapTransFirst(image) == MagickFalse)
6520
6701
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
6521
number_colors=image_colors;
6702
number_colors=image->colors;
6522
6703
image_colors=save_number_colors;
6524
6705
palette=(png_color *) AcquireQuantumMemory(257,
6551
6733
palette[i].blue=ScaleQuantumToChar((Quantum) QuantumRange);
6553
6735
png_set_PLTE(ping,ping_info,palette,(int) number_colors);
6554
#if (PNG_LIBPNG_VER > 10008)
6555
6736
palette=(png_colorp) RelinquishMagickMemory(palette);
6557
image_depth=ping_info->bit_depth;
6558
ping_info->num_trans=0;
6737
image_depth=ping_bit_depth;
6565
6748
Identify which colormap entry is transparent.
6567
ping_info->trans_alpha=(unsigned char *) AcquireQuantumMemory(
6568
number_colors,sizeof(*ping_info->trans_alpha));
6569
if (ping_info->trans == (unsigned char *) NULL)
6570
ThrowWriterException(ResourceLimitError,
6571
"MemoryAllocationFailed");
6572
6750
assert(number_colors <= 256);
6573
for (i=0; i < (long) number_colors; i++)
6574
ping_info->trans_alpha[i]=255;
6751
for (i=0; i < (ssize_t) number_colors; i++)
6575
6753
exception=(&image->exception);
6576
for (y=0; y < (long) image->rows; y++)
6754
for (y=0; y < (ssize_t) image->rows; y++)
6578
6756
register const PixelPacket
6581
6759
p=GetAuthenticPixels(image,0,y,image->columns,1,exception);
6582
6760
if (p == (PixelPacket *) NULL)
6584
indices=GetAuthenticIndexQueue(image);
6585
for (x=0; x < (long) image->columns; x++)
6762
indexes=GetAuthenticIndexQueue(image);
6763
for (x=0; x < (ssize_t) image->columns; x++)
6587
6765
if (p->opacity != OpaqueOpacity)
6589
indices[x]=(IndexPacket) (number_colors-1);
6590
ping_info->trans_alpha[(long) indices[x]]=(png_byte) (255-
6591
ScaleQuantumToChar(p->opacity));
6767
indexes[x]=(IndexPacket) (number_colors-1);
6768
trans_alpha[(ssize_t) indexes[x]]=(png_byte) (255-
6769
ScaleQuantumToChar(GetOpacityPixelComponent(p)));
6595
6773
if (SyncAuthenticPixels(image,exception) == MagickFalse)
6598
for (i=0; i < (long) number_colors; i++)
6599
if (ping_info->trans_alpha[i] != 255)
6600
ping_info->num_trans=(unsigned short) (i+1);
6601
if (ping_info->num_trans == 0)
6602
ping_info->valid&=(~PNG_INFO_tRNS);
6603
if (!(ping_info->valid & PNG_INFO_tRNS))
6604
ping_info->num_trans=0;
6605
if (ping_info->num_trans == 0)
6606
ping_info->trans_alpha=(unsigned char *)
6607
RelinquishMagickMemory(ping_info->trans_alpha);
6776
for (i=0; i < (ssize_t) number_colors; i++)
6777
if (trans_alpha[i] != 255)
6778
ping_num_trans=(unsigned short) (i+1);
6780
if (ping_num_trans == 0)
6781
png_set_invalid(ping, ping_info, PNG_INFO_tRNS);
6782
if (!png_get_valid(ping, ping_info, PNG_INFO_tRNS))
6784
if (ping_num_trans != 0)
6786
for (i=0; i<256; i++)
6787
ping_trans_alpha[i]=(png_byte) trans_alpha[i];
6790
(void) png_set_tRNS(ping, ping_info,
6610
6796
Identify which colormap entry is the background color.
6612
for (i=0; i < (long) MagickMax(1L*number_colors-1L,1L); i++)
6613
if (IsPNGColorEqual(ping_info->background,image->colormap[i]))
6798
for (i=0; i < (ssize_t) MagickMax(1L*number_colors-1L,1L); i++)
6799
if (IsPNGColorEqual(ping_background,image->colormap[i]))
6615
ping_info->background.index=(png_byte) i;
6801
ping_background.index=(png_byte) i;
6617
6803
if (image_matte != MagickFalse)
6669
6855
image_info->type == GrayscaleMatteType) &&
6670
6856
image_matte == MagickTrue && ImageIsGray(image))
6672
ping_info->color_type=(png_byte) PNG_COLOR_TYPE_GRAY_ALPHA;
6858
ping_color_type=(png_byte) PNG_COLOR_TYPE_GRAY_ALPHA;
6673
6859
image_matte=MagickTrue;
6676
6862
if (logging != MagickFalse)
6677
6863
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6678
"Selected PNG colortype=%d",ping_info->color_type);
6864
"Selected PNG colortype=%d",ping_color_type);
6680
if (ping_info->bit_depth < 8)
6866
if (ping_bit_depth < 8)
6682
if (ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
6683
ping_info->color_type == PNG_COLOR_TYPE_RGB ||
6684
ping_info->color_type == PNG_COLOR_TYPE_RGBA)
6685
ping_info->bit_depth=8;
6868
if (ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
6869
ping_color_type == PNG_COLOR_TYPE_RGB ||
6870
ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
6688
if (ping_info->color_type == PNG_COLOR_TYPE_GRAY)
6874
if (ping_color_type == PNG_COLOR_TYPE_GRAY)
6690
6876
if (image->matte == MagickFalse && image->colors < 256)
6692
6878
if (ImageIsMonochrome(image))
6694
ping_info->bit_depth=1;
6695
if (ping_info->bit_depth < mng_info->write_png_depth)
6696
ping_info->bit_depth = mng_info->write_png_depth;
6881
if (ping_bit_depth < (int)mng_info->write_png_depth)
6882
ping_bit_depth = mng_info->write_png_depth;
6700
if (ping_info->color_type == PNG_COLOR_TYPE_PALETTE)
6886
if (ping_color_type == PNG_COLOR_TYPE_PALETTE)
6702
ping_info->bit_depth=1;
6703
while ((int) (1 << ping_info->bit_depth) < (long) image_colors)
6704
ping_info->bit_depth <<= 1;
6890
while ((int) (one << ping_bit_depth) < (ssize_t) image_colors)
6891
ping_bit_depth <<= 1;
6706
6893
if (logging != MagickFalse)
6708
6895
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6709
" Number of colors: %lu",image_colors);
6896
" Number of colors: %.20g",(double) image_colors);
6710
6897
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6711
" Tentative PNG bit depth: %d",ping_info->bit_depth);
6898
" Tentative PNG bit depth: %d",ping_bit_depth);
6713
6900
if (mng_info->write_png_depth)
6715
old_bit_depth=ping_info->bit_depth;
6716
if (ping_info->bit_depth < mng_info->write_png_depth)
6902
old_bit_depth=ping_bit_depth;
6903
if (ping_bit_depth < (int)mng_info->write_png_depth)
6718
ping_info->bit_depth = mng_info->write_png_depth;
6719
if (ping_info->bit_depth > 8)
6720
ping_info->bit_depth = 8;
6721
if (ping_info->bit_depth != old_bit_depth)
6905
ping_bit_depth = mng_info->write_png_depth;
6906
if (ping_bit_depth > 8)
6908
if (ping_bit_depth != (int) old_bit_depth)
6723
6910
if (logging != MagickFalse)
6724
6911
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6725
" Colors increased to %ld",image_colors);
6912
" Colors increased to %.20g",(double)
6731
image_depth=ping_info->bit_depth;
6919
image_depth=ping_bit_depth;
6732
6920
if (logging != MagickFalse)
6734
6922
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6735
" Tentative PNG color type: %d",ping_info->color_type);
6736
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6737
" image_info->type: %d",image_info->type);
6738
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6739
" image_depth: %lu",image_depth);
6740
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6741
" ping_info->bit_depth: %d",ping_info->bit_depth);
6923
" Tentative PNG color type: %.20g",(double) ping_color_type);
6924
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6925
" image_info->type: %.20g",(double) image_info->type);
6926
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6927
" image_depth: %.20g",(double) image_depth);
6928
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6929
" ping_bit_depth: %.20g",(double) ping_bit_depth);
6744
6932
if (matte && (mng_info->optimize || mng_info->IsPalette))
6749
6937
p=GetVirtualPixels(image,0,0,image->columns,1,&image->exception);
6750
ping_info->color_type=PNG_COLOR_TYPE_GRAY_ALPHA;
6751
for (y=0; y < (long) image->rows; y++)
6938
ping_color_type=PNG_COLOR_TYPE_GRAY_ALPHA;
6939
for (y=0; y < (ssize_t) image->rows; y++)
6753
6941
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
6754
6942
if (p == (const PixelPacket *) NULL)
6756
for (x=(long) image->columns-1; x >= 0; x--)
6944
for (x=(ssize_t) image->columns-1; x >= 0; x--)
6758
6946
if (IsGray(p) == MagickFalse)
6760
ping_info->color_type=(png_byte) PNG_COLOR_TYPE_RGB_ALPHA;
6948
ping_color_type=(png_byte) PNG_COLOR_TYPE_RGB_ALPHA;
6798
if (ping_info->bit_depth == 8)
6985
if (ping_bit_depth == 8)
6800
if (ping_info->bit_depth == 4)
6987
if (ping_bit_depth == 4)
6802
if (ping_info->bit_depth == 2)
6989
if (ping_bit_depth == 2)
6804
if (ping_info->bit_depth == 1)
6991
if (ping_bit_depth == 1)
6806
ping_info->valid|=PNG_INFO_tRNS;
6807
ping_info->trans_color.red=(png_uint_16)
6808
(ScaleQuantumToShort(p->red) & mask);
6809
ping_info->trans_color.green=(png_uint_16)
6810
(ScaleQuantumToShort(p->green) & mask);
6811
ping_info->trans_color.blue=(png_uint_16)
6812
(ScaleQuantumToShort(p->blue) & mask);
6813
ping_info->trans_color.gray=(png_uint_16)
6993
ping_trans_color.red=(png_uint_16)
6994
(ScaleQuantumToShort(GetRedPixelComponent(p)) & mask);
6995
ping_trans_color.green=(png_uint_16)
6996
(ScaleQuantumToShort(GetGreenPixelComponent(p)) & mask);
6997
ping_trans_color.blue=(png_uint_16)
6998
(ScaleQuantumToShort(GetBluePixelComponent(p)) & mask);
6999
ping_trans_color.gray=(png_uint_16)
6814
7000
(ScaleQuantumToShort(PixelIntensityToQuantum(p)) & mask);
6815
ping_info->trans_color.index=(png_byte)
6816
(ScaleQuantumToChar((Quantum) (QuantumRange-p->opacity)));
7001
ping_trans_color.index=(png_byte)
7002
(ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p))));
7003
(void) png_set_tRNS(ping, ping_info, NULL, 0,
6818
if (ping_info->valid & PNG_INFO_tRNS)
7006
if (png_get_valid(ping,ping_info,PNG_INFO_tRNS))
6821
7009
Determine if there is one and only one transparent color
6822
7010
and if so if it is fully transparent.
6824
for (y=0; y < (long) image->rows; y++)
7012
for (y=0; y < (ssize_t) image->rows; y++)
6826
7014
p=GetVirtualPixels(image,0,y,image->columns,1,
6827
7015
&image->exception);
6829
7017
if (p == (const PixelPacket *) NULL)
6831
for (x=(long) image->columns-1; x >= 0; x--)
7019
for (x=(ssize_t) image->columns-1; x >= 0; x--)
6833
7021
if (p->opacity != OpaqueOpacity)
6835
if (IsPNGColorEqual(ping_info->trans_color,*p) == 0)
7023
if (IsPNGColorEqual(ping_trans_color,*p) == 0)
6837
7025
break; /* Can't use RGB + tRNS for multiple
6838
7026
transparent colors. */
6859
ping_info->valid&=(~PNG_INFO_tRNS);
7047
png_set_invalid(ping,ping_info,PNG_INFO_tRNS);
6861
if (ping_info->valid & PNG_INFO_tRNS)
7049
if (png_get_valid(ping,ping_info,PNG_INFO_tRNS))
6863
ping_info->color_type &= 0x03; /* changes 4 or 6 to 0 or 2 */
7051
ping_color_type &= 0x03; /* changes 4 or 6 to 0 or 2 */
6864
7052
if (image_depth == 8)
6866
ping_info->trans_color.red&=0xff;
6867
ping_info->trans_color.green&=0xff;
6868
ping_info->trans_color.blue&=0xff;
6869
ping_info->trans_color.gray&=0xff;
7054
ping_trans_color.red&=0xff;
7055
ping_trans_color.green&=0xff;
7056
ping_trans_color.blue&=0xff;
7057
ping_trans_color.gray&=0xff;
6873
7061
matte=image_matte;
6874
if (ping_info->valid & PNG_INFO_tRNS)
7062
if (png_get_valid(ping,ping_info,PNG_INFO_tRNS))
6875
7063
image_matte=MagickFalse;
6876
7064
if ((mng_info->optimize || mng_info->IsPalette) &&
6877
7065
mng_info->write_png_colortype-1 != PNG_COLOR_TYPE_PALETTE &&
6878
7066
ImageIsGray(image) && (!image_matte || image_depth >= 8))
6880
7069
if (image_matte != MagickFalse)
6881
ping_info->color_type=PNG_COLOR_TYPE_GRAY_ALPHA;
7070
ping_color_type=PNG_COLOR_TYPE_GRAY_ALPHA;
6884
ping_info->color_type=PNG_COLOR_TYPE_GRAY;
7073
ping_color_type=PNG_COLOR_TYPE_GRAY;
6885
7074
if (save_image_depth == 16 && image_depth == 8)
6886
ping_info->trans_color.gray*=0x0101;
7075
ping_trans_color.gray*=0x0101;
6888
7077
if (image_depth > MAGICKCORE_QUANTUM_DEPTH)
6889
7078
image_depth=MAGICKCORE_QUANTUM_DEPTH;
6890
7079
if (image_colors == 0 || image_colors-1 > MaxColormapSize)
6891
image_colors=1 << image_depth;
7080
image_colors=one << image_depth;
6892
7081
if (image_depth > 8)
6893
ping_info->bit_depth=16;
6896
ping_info->bit_depth=8;
6897
if ((int) ping_info->color_type == PNG_COLOR_TYPE_PALETTE)
7086
if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE)
6899
7088
if(!mng_info->write_png_depth)
6901
ping_info->bit_depth=1;
6902
while ((int) (1 << ping_info->bit_depth)
6903
< (long) image_colors)
6904
ping_info->bit_depth <<= 1;
7091
while ((int) (one << ping_bit_depth)
7092
< (ssize_t) image_colors)
7093
ping_bit_depth <<= 1;
6907
else if (mng_info->optimize && ping_info->color_type ==
7096
else if (mng_info->optimize && ping_color_type ==
6908
7097
PNG_COLOR_TYPE_GRAY && image_colors < 17 &&
6909
7098
mng_info->IsPalette)
6930
7119
depth_1_ok=MagickFalse;
6932
7121
if (depth_1_ok && mng_info->write_png_depth <= 1)
6933
ping_info->bit_depth=1;
6934
7123
else if (depth_2_ok && mng_info->write_png_depth <= 2)
6935
ping_info->bit_depth=2;
6936
7125
else if (depth_4_ok && mng_info->write_png_depth <= 4)
6937
ping_info->bit_depth=4;
6940
image_depth=ping_info->bit_depth;
7129
image_depth=ping_bit_depth;
6943
7132
if (mng_info->IsPalette)
7137
number_colors=image_colors;
6945
7139
if (image_depth <= 8)
6950
number_colors=image_colors;
6952
ping_info->valid|=PNG_INFO_tRNS;
6954
7142
Set image palette.
6956
ping_info->color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
6957
ping_info->valid|=PNG_INFO_PLTE;
7144
ping_color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
6958
7145
if (mng_info->have_write_global_plte && !matte)
6960
png_set_PLTE(ping,ping_info,NULL,0);
6962
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
6963
" Setting up empty PLTE chunk");
7147
png_set_PLTE(ping,ping_info,NULL,0);
7149
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7150
" Setting up empty PLTE chunk");
6967
7154
#if defined(PNG_SORT_PALETTE)
6969
7156
save_number_colors;
6971
7158
if (mng_info->optimize)
7019
7209
register const IndexPacket
7023
7213
Identify which colormap entry is transparent.
7025
7215
assert(number_colors <= 256);
7026
for (i=0; i < (long) number_colors; i++)
7216
for (i=0; i < (ssize_t) number_colors; i++)
7028
7218
exception=(&image->exception);
7029
for (y=0; y < (long) image->rows; y++)
7219
for (y=0; y < (ssize_t) image->rows; y++)
7031
7221
p=GetVirtualPixels(image,0,y,image->columns,1,exception);
7032
7222
if (p == (const PixelPacket *) NULL)
7034
packet_indices=GetVirtualIndexQueue(image);
7035
for (x=0; x < (long) image->columns; x++)
7224
packet_indexes=GetVirtualIndexQueue(image);
7225
for (x=0; x < (ssize_t) image->columns; x++)
7037
7227
if (p->opacity != OpaqueOpacity)
7042
packet_index=packet_indices[x];
7043
assert((unsigned long) packet_index < number_colors);
7044
if (trans[(long) packet_index] != 256)
7232
packet_index=packet_indexes[x];
7233
assert((size_t) packet_index < number_colors);
7234
if (trans[(ssize_t) packet_index] != 256)
7046
if (trans[(long) packet_index] != (png_byte) (255-
7047
ScaleQuantumToChar(p->opacity)))
7236
if (trans[(ssize_t) packet_index] != (png_byte) (255-
7237
ScaleQuantumToChar(GetOpacityPixelComponent(p))))
7049
ping_info->color_type=(png_byte)
7239
ping_color_type=(png_byte)
7050
7240
PNG_COLOR_TYPE_RGB_ALPHA;
7054
trans[(long) packet_index]=(png_byte) (255-
7055
ScaleQuantumToChar(p->opacity));
7244
trans[(ssize_t) packet_index]=(png_byte) (255-
7245
ScaleQuantumToChar(GetOpacityPixelComponent(p)));
7059
if ((int) ping_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
7249
if ((int) ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
7061
ping_info->num_trans=0;
7062
ping_info->valid&=(~PNG_INFO_tRNS);
7063
ping_info->valid&=(~PNG_INFO_PLTE);
7252
png_set_invalid(ping,ping_info,PNG_INFO_tRNS);
7253
png_set_invalid(ping,ping_info,PNG_INFO_PLTE);
7064
7254
mng_info->IsPalette=MagickFalse;
7065
7255
(void) SyncImage(image);
7072
if ((ping_info->valid & PNG_INFO_tRNS))
7262
if (png_get_valid(ping,ping_info,PNG_INFO_tRNS))
7074
for (i=0; i < (long) number_colors; i++)
7264
for (i=0; i < (ssize_t) number_colors; i++)
7076
7266
if (trans[i] == 256)
7078
7268
if (trans[i] != 255)
7079
ping_info->num_trans=(unsigned short) (i+1);
7082
if (ping_info->num_trans == 0)
7083
ping_info->valid&=(~PNG_INFO_tRNS);
7084
if (!(ping_info->valid & PNG_INFO_tRNS))
7085
ping_info->num_trans=0;
7086
if (ping_info->num_trans != 0)
7088
ping_info->trans_alpha=(unsigned char *) AcquireQuantumMemory(
7089
number_colors,sizeof(*ping_info->trans_alpha));
7090
if (ping_info->trans_alpha == (unsigned char *) NULL)
7091
ThrowWriterException(ResourceLimitError,
7092
"MemoryAllocationFailed");
7093
for (i=0; i < (long) number_colors; i++)
7094
ping_info->trans_alpha[i]=(png_byte) trans[i];
7269
ping_num_trans=(unsigned short) (i+1);
7272
if (ping_num_trans == 0)
7273
png_set_invalid(ping,ping_info,PNG_INFO_tRNS);
7274
if (!png_get_valid(ping,ping_info,PNG_INFO_tRNS))
7276
if (ping_num_trans != 0)
7278
for (i=0; i < (ssize_t) number_colors; i++)
7279
ping_trans_alpha[i]=(png_byte) trans[i];
7099
Identify which colormap entry is the background color.
7101
for (i=0; i < (long) MagickMax(1L*number_colors-1L,1L); i++)
7102
if (IsPNGColorEqual(ping_info->background,image->colormap[i]))
7104
ping_info->background.index=(png_byte) i;
7140
7321
" Setting up bKGD chunk");
7141
7322
png_set_bKGD(ping,ping_info,&background);
7143
ping_info->trans_color.gray=(png_uint_16) (QuantumScale*(maxval*
7144
ping_info->trans_color.gray));
7324
ping_trans_color.gray=(png_uint_16) (QuantumScale*(maxval*
7325
ping_trans_color.gray));
7328
if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE)
7331
Identify which colormap entry is the background color.
7337
number_colors=image_colors;
7339
for (i=0; i < (ssize_t) MagickMax(1L*number_colors-1L,1L); i++)
7340
if (IsPNGColorEqual(ping_background,image->colormap[i]))
7343
ping_background.index=(png_byte) i;
7346
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7347
" Setting up bKGD chunk with index=%d",(int) i);
7349
png_set_bKGD(ping,ping_info,&ping_background);
7146
7352
if (logging != MagickFalse)
7147
7353
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7148
" PNG color type: %d",ping_info->color_type);
7354
" PNG color type: %d",ping_color_type);
7150
7356
Initialize compression level and filtering.
7152
7358
if (logging != MagickFalse)
7153
7359
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7154
7360
" Setting up deflate compression");
7155
#if (PNG_LIBPNG_VER > 99)
7156
7361
if (logging != MagickFalse)
7157
7362
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7158
7363
" Compression buffer size: 32768");
7159
7364
png_set_compression_buffer_size(ping,32768L);
7161
7365
if (logging != MagickFalse)
7162
7366
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7163
7367
" Compression mem level: 9");
7317
7521
if (mng_info->write_png_colortype-1 == PNG_COLOR_TYPE_GRAY)
7318
7522
if (ImageIsGray(image) == MagickFalse)
7320
ping_info->color_type = PNG_COLOR_TYPE_RGB;
7321
if (ping_info->bit_depth < 8)
7322
ping_info->bit_depth=8;
7524
ping_color_type = PNG_COLOR_TYPE_RGB;
7525
if (ping_bit_depth < 8)
7325
7529
if (mng_info->write_png_colortype-1 == PNG_COLOR_TYPE_GRAY_ALPHA)
7326
7530
if (ImageIsGray(image) == MagickFalse)
7327
ping_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
7531
ping_color_type = PNG_COLOR_TYPE_RGB_ALPHA;
7330
7534
if ((mng_info->write_png_depth &&
7331
mng_info->write_png_depth != ping_info->bit_depth) ||
7535
(int) mng_info->write_png_depth != ping_bit_depth) ||
7332
7536
(mng_info->write_png_colortype &&
7333
mng_info->write_png_colortype-1 != ping_info->color_type))
7537
((int) mng_info->write_png_colortype-1 != ping_color_type &&
7538
mng_info->write_png_colortype != 7 &&
7539
!(mng_info->write_png_colortype == 5 && ping_color_type == 0))))
7335
7541
if (logging != MagickFalse)
7358
7564
/* Add an opaque matte channel */
7359
7565
image->matte = MagickTrue;
7360
7566
(void) SetImageOpacity(image,0);
7567
if (logging != MagickFalse)
7568
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7569
" Added an opaque matte channel");
7572
if (image->matte == MagickTrue && ping_color_type < 4)
7574
if (ping_color_type == 3 && ping_num_trans == 0)
7576
png_set_invalid(ping,ping_info,PNG_INFO_tRNS);
7577
if (logging != MagickFalse)
7578
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7579
" Ignoring request to write tRNS chunk with num_trans==0");
7582
(void) png_set_tRNS(ping, ping_info,
7363
7588
if (logging != MagickFalse)
7364
7589
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7365
7590
" Writing PNG header chunks");
7592
png_set_IHDR(ping,ping_info,ping_width,ping_height,
7593
ping_bit_depth,ping_color_type,
7594
ping_interlace_method,ping_compression_method,
7595
ping_filter_method);
7367
7597
png_write_info_before_PLTE(ping, ping_info);
7368
7598
/* write any png-chunk-b profiles */
7369
7599
(void) png_write_chunk_from_profile(image,"PNG-chunk-b",(int) logging);
7374
7604
if (image->page.width || image->page.height)
7379
(void) WriteBlobMSBULong(image,9L); /* data length=8 */
7380
PNGType(chunk,mng_vpAg);
7381
LogPNGChunk((int) logging,mng_vpAg,9L);
7382
PNGLong(chunk+4,(png_uint_32) image->page.width);
7383
PNGLong(chunk+8,(png_uint_32) image->page.height);
7384
chunk[12]=0; /* unit = pixels */
7385
(void) WriteBlob(image,13,chunk);
7386
(void) WriteBlobMSBULong(image,crc32(0,chunk,13));
7609
(void) WriteBlobMSBULong(image,9L); /* data length=8 */
7610
PNGType(chunk,mng_vpAg);
7611
LogPNGChunk((int) logging,mng_vpAg,9L);
7612
PNGLong(chunk+4,(png_uint_32) image->page.width);
7613
PNGLong(chunk+8,(png_uint_32) image->page.height);
7614
chunk[12]=0; /* unit = pixels */
7615
(void) WriteBlob(image,13,chunk);
7616
(void) WriteBlobMSBULong(image,crc32(0,chunk,13));
7389
7619
#if (PNG_LIBPNG_VER == 10206)
7390
/* avoid libpng-1.2.6 bug by setting PNG_HAVE_IDAT flag */
7620
/* avoid libpng-1.2.6 bug by setting PNG_HAVE_IDAT flag */
7391
7621
#define PNG_HAVE_IDAT 0x04
7392
ping->mode |= PNG_HAVE_IDAT;
7622
ping->mode |= PNG_HAVE_IDAT;
7393
7623
#undef PNG_HAVE_IDAT
7398
7628
Allocate memory.
7400
7630
rowbytes=image->columns;
7401
if (image_depth <= 8)
7631
if (image_depth > 8)
7633
switch (ping_color_type)
7403
if (mng_info->write_png24 || (mng_info->write_png_depth == 8 &&
7404
mng_info->write_png_colortype-1 == PNG_COLOR_TYPE_RGB))
7635
case PNG_COLOR_TYPE_RGB:
7406
else if (mng_info->write_png32 || (mng_info->write_png_depth == 8 &&
7407
mng_info->write_png_colortype-1 == PNG_COLOR_TYPE_RGB_ALPHA))
7638
case PNG_COLOR_TYPE_GRAY_ALPHA:
7641
case PNG_COLOR_TYPE_RGBA:
7409
else if ((!mng_info->write_png8 ||
7410
mng_info->write_png_colortype-1 == PNG_COLOR_TYPE_GRAY ||
7411
mng_info->write_png_colortype-1 == PNG_COLOR_TYPE_GRAY_ALPHA )&&
7412
((mng_info->optimize || mng_info->IsPalette) && ImageIsGray(image)))
7413
rowbytes*=(image_matte ? 2 : 1);
7416
if (!mng_info->IsPalette)
7417
rowbytes*=(image_matte ? 4 : 3);
7422
if ((mng_info->optimize || mng_info->IsPalette) &&
7424
rowbytes*=(image_matte ? 4 : 2);
7426
rowbytes*=(image_matte ? 8 : 6);
7429
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7430
" Allocating %lu bytes of memory for pixels",rowbytes);
7649
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7650
" Writing PNG image data");
7651
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7652
" Allocating %.20g bytes of memory for pixels",(double) rowbytes);
7431
7654
png_pixels=(unsigned char *) AcquireQuantumMemory(rowbytes,
7432
7655
sizeof(*png_pixels));
7433
7656
if (png_pixels == (unsigned char *) NULL)
7539
7765
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
7540
7766
quantum_info,RedQuantum,png_pixels,&image->exception);
7767
if (logging && y == 0)
7768
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7769
" Writing GRAY PNG pixels (2)");
7542
7771
else /* PNG_COLOR_TYPE_GRAY_ALPHA */
7773
if (logging && y == 0)
7774
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7775
" Writing GRAY_ALPHA PNG pixels (2)");
7544
7776
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
7545
7777
quantum_info,GrayAlphaQuantum,png_pixels,&image->exception);
7779
if (logging && y == 0)
7780
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7781
" Writing row of pixels (2)");
7547
7782
png_write_row(ping,png_pixels);
7549
7784
if (image->previous == (Image *) NULL)
7573
7808
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
7574
7809
quantum_info,GrayQuantum,png_pixels,&image->exception);
7576
else if (ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
7577
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
7578
quantum_info,GrayAlphaQuantum,png_pixels,&image->exception);
7811
else if (ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
7813
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
7814
quantum_info,GrayAlphaQuantum,png_pixels,&image->exception);
7815
if (logging && y == 0)
7816
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7817
" Writing GRAY_ALPHA PNG pixels (3)");
7579
7819
else if (image_matte != MagickFalse)
7580
7820
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
7581
7821
quantum_info,RGBAQuantum,png_pixels,&image->exception);
7583
7823
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
7584
7824
quantum_info,RGBQuantum,png_pixels,&image->exception);
7825
if (logging && y == 0)
7826
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7827
" Writing row of pixels (3)");
7585
7828
png_write_row(ping,png_pixels);
7598
7841
quantum_info->depth=8;
7601
for (y=0; y < (long) image->rows; y++)
7844
for (y=0; y < (ssize_t) image->rows; y++)
7846
if (logging && y == 0)
7604
7847
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7605
7848
" pass %d, Image Is RGB, 16-bit GRAY, or GRAY_ALPHA",pass);
7606
7849
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
7607
7850
if (p == (const PixelPacket *) NULL)
7609
if (ping_info->color_type == PNG_COLOR_TYPE_GRAY)
7852
if (ping_color_type == PNG_COLOR_TYPE_GRAY)
7610
7853
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
7611
7854
quantum_info,GrayQuantum,png_pixels,&image->exception);
7612
else if (ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
7613
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
7614
quantum_info,GrayAlphaQuantum,png_pixels,&image->exception);
7855
else if (ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
7857
if (logging && y == 0)
7858
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7859
" Writing GRAY_ALPHA PNG pixels (4)");
7860
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
7861
quantum_info,GrayAlphaQuantum,png_pixels,&image->exception);
7616
7864
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
7617
7865
quantum_info,IndexQuantum,png_pixels,&image->exception);
7866
if (logging && y == 0)
7867
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7868
" Writing row of pixels (4)");
7618
7869
png_write_row(ping,png_pixels);
7632
7883
if (logging != MagickFalse)
7634
7885
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7635
" Writing PNG image data");
7636
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7637
" Width: %lu",ping_info->width);
7638
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7639
" Height: %lu",ping_info->height);
7886
" Wrote PNG image data");
7887
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7888
" Width: %.20g",(double) ping_width);
7889
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7890
" Height: %.20g",(double) ping_height);
7640
7891
if (mng_info->write_png_depth)
7642
7893
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7643
7894
" Defined PNG:bit-depth: %d",mng_info->write_png_depth);
7645
7896
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7646
" PNG bit-depth written: %d",ping_info->bit_depth);
7897
" PNG bit-depth written: %d",ping_bit_depth);
7647
7898
if (mng_info->write_png_colortype)
7649
7900
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7650
7901
" Defined PNG:color-type: %d",mng_info->write_png_colortype-1);
7652
7903
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7653
" PNG color-type written: %d",ping_info->color_type);
7904
" PNG color-type written: %d",ping_color_type);
7654
7905
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7655
" PNG Interlace method: %d",ping_info->interlace_type);
7906
" PNG Interlace method: %d",ping_interlace_method);
7658
7909
Generate text chunks.
7660
#if (PNG_LIBPNG_VER <= 10005)
7661
ping_info->num_text=0;
7663
7911
ResetImagePropertyIterator(image);
7664
7912
property=GetNextImageProperty(image);
7665
7913
while (property != (const char *) NULL)
7667
#if (PNG_LIBPNG_VER > 10005)
7672
7918
value=GetImageProperty(image,property);
7673
7919
if (value != (const char *) NULL)
7675
#if (PNG_LIBPNG_VER > 10005)
7676
7921
text=(png_textp) png_malloc(ping,(png_uint_32) sizeof(png_text));
7677
7922
text[0].key=(char *) property;
7678
7923
text[0].text=(char *) value;
7690
7935
png_set_text(ping,ping_info,text,1);
7691
7936
png_free(ping,text);
7693
/* Work directly with ping_info struct; png_set_text before libpng version
7694
* 1.0.5a is leaky */
7695
if (ping_info->num_text == 0)
7697
ping_info->text=(png_text *) AcquireQuantumMemory(256,
7698
sizeof(*ping_info->text));
7699
if (ping_info->text == (png_text *) NULL)
7700
(void) ThrowMagickException(&image->exception,GetMagickModule(),
7701
ResourceLimitError,"MemoryAllocationFailed","`%s'",
7704
i=ping_info->num_text++;
7706
(void) ThrowMagickException(&image->exception,GetMagickModule(),
7707
ResourceLimitError,"Cannot write more than 256 PNG text chunks",
7708
"`%s'",image->filename);
7709
ping_info->text[i].key=(char *) property;
7710
ping_info->text[i].text=(char *) value;
7711
ping_info->text[i].text_length=strlen(value);
7712
ping_info->text[i].compression=
7713
image_info->compression == NoCompression ||
7714
(image_info->compression == UndefinedCompression &&
7715
ping_info->text[i].text_length < 128) ? -1 : 0;
7716
if (logging != MagickFalse)
7718
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7719
" Setting up text chunk");
7720
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
7721
" keyword: %s",ping_info->text[i].key);
7725
7938
property=GetNextImageProperty(image);
7978
8177
if (mng_info->write_png8)
7980
mng_info->write_png_colortype = /* 3 */ 4;
7981
mng_info->write_png_depth = 8;
8179
mng_info->write_png_colortype = /* 3 */ 4;
8180
mng_info->write_png_depth = 8;
7983
8182
#if 0 /* this does not work */
7984
if (image->matte == MagickTrue)
7985
(void) SetImageType(image,PaletteMatteType);
7987
(void) SetImageType(image,PaletteType);
7988
(void) SyncImage(image);
8183
if (image->matte == MagickTrue)
8184
(void) SetImageType(image,PaletteMatteType);
8186
(void) SetImageType(image,PaletteType);
8187
(void) SyncImage(image);
7992
8191
if (mng_info->write_png24)
7994
mng_info->write_png_colortype = /* 2 */ 3;
7995
mng_info->write_png_depth = 8;
7997
if (image->matte == MagickTrue)
7998
(void) SetImageType(image,TrueColorMatteType);
8000
(void) SetImageType(image,TrueColorType);
8001
(void) SyncImage(image);
8193
mng_info->write_png_colortype = /* 2 */ 3;
8194
mng_info->write_png_depth = 8;
8196
if (image->matte == MagickTrue)
8197
(void) SetImageType(image,TrueColorMatteType);
8199
(void) SetImageType(image,TrueColorType);
8200
(void) SyncImage(image);
8004
8203
if (mng_info->write_png32)
8006
mng_info->write_png_colortype = /* 6 */ 7;
8007
mng_info->write_png_depth = 8;
8009
if (image->matte == MagickTrue)
8010
(void) SetImageType(image,TrueColorMatteType);
8012
(void) SetImageType(image,TrueColorType);
8013
(void) SyncImage(image);
8205
mng_info->write_png_colortype = /* 6 */ 7;
8206
mng_info->write_png_depth = 8;
8208
if (image->matte == MagickTrue)
8209
(void) SetImageType(image,TrueColorMatteType);
8211
(void) SetImageType(image,TrueColorType);
8212
(void) SyncImage(image);
8016
8215
value=GetImageOption(image_info,"png:bit-depth");
8017
8216
if (value != (char *) NULL)
8019
8218
if (LocaleCompare(value,"1") == 0)
8020
mng_info->write_png_depth = 1;
8219
mng_info->write_png_depth = 1;
8021
8220
else if (LocaleCompare(value,"2") == 0)
8022
mng_info->write_png_depth = 2;
8221
mng_info->write_png_depth = 2;
8023
8222
else if (LocaleCompare(value,"4") == 0)
8024
mng_info->write_png_depth = 4;
8223
mng_info->write_png_depth = 4;
8025
8224
else if (LocaleCompare(value,"8") == 0)
8026
mng_info->write_png_depth = 8;
8225
mng_info->write_png_depth = 8;
8027
8226
else if (LocaleCompare(value,"16") == 0)
8028
mng_info->write_png_depth = 16;
8227
mng_info->write_png_depth = 16;
8029
8228
if (logging != MagickFalse)
8030
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
8031
"png:bit-depth=%d was defined.\n",mng_info->write_png_depth);
8229
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
8230
"png:bit-depth=%d was defined.\n",mng_info->write_png_depth);
8033
8232
value=GetImageOption(image_info,"png:color-type");
8034
8233
if (value != (char *) NULL)
8036
8235
/* We must store colortype+1 because 0 is a valid colortype */
8037
8236
if (LocaleCompare(value,"0") == 0)
8038
mng_info->write_png_colortype = 1;
8237
mng_info->write_png_colortype = 1;
8039
8238
else if (LocaleCompare(value,"2") == 0)
8040
mng_info->write_png_colortype = 3;
8239
mng_info->write_png_colortype = 3;
8041
8240
else if (LocaleCompare(value,"3") == 0)
8042
mng_info->write_png_colortype = 4;
8241
mng_info->write_png_colortype = 4;
8043
8242
else if (LocaleCompare(value,"4") == 0)
8044
mng_info->write_png_colortype = 5;
8243
mng_info->write_png_colortype = 5;
8045
8244
else if (LocaleCompare(value,"6") == 0)
8046
mng_info->write_png_colortype = 7;
8245
mng_info->write_png_colortype = 7;
8047
8246
if (logging != MagickFalse)
8048
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
8049
"png:color-type=%d was defined.\n",mng_info->write_png_colortype-1);
8247
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
8248
"png:color-type=%d was defined.\n",mng_info->write_png_colortype-1);
8052
8251
status=WriteOnePNGImage(mng_info,image_info,image);
8331
8530
PNGType(chunk,mng_cHRM);
8332
8531
LogPNGChunk((int) logging,mng_cHRM,32L);
8333
8532
primary=image->chromaticity.white_point;
8334
PNGLong(chunk+4,(unsigned long) (100000*primary.x+0.5));
8335
PNGLong(chunk+8,(unsigned long) (100000*primary.y+0.5));
8533
PNGLong(chunk+4,(png_uint_32) (100000*primary.x+0.5));
8534
PNGLong(chunk+8,(png_uint_32) (100000*primary.y+0.5));
8336
8535
primary=image->chromaticity.red_primary;
8337
PNGLong(chunk+12,(unsigned long) (100000*primary.x+0.5));
8338
PNGLong(chunk+16,(unsigned long) (100000*primary.y+0.5));
8536
PNGLong(chunk+12,(png_uint_32) (100000*primary.x+0.5));
8537
PNGLong(chunk+16,(png_uint_32) (100000*primary.y+0.5));
8339
8538
primary=image->chromaticity.green_primary;
8340
PNGLong(chunk+20,(unsigned long) (100000*primary.x+0.5));
8341
PNGLong(chunk+24,(unsigned long) (100000*primary.y+0.5));
8539
PNGLong(chunk+20,(png_uint_32) (100000*primary.x+0.5));
8540
PNGLong(chunk+24,(png_uint_32) (100000*primary.y+0.5));
8342
8541
primary=image->chromaticity.blue_primary;
8343
PNGLong(chunk+28,(unsigned long) (100000*primary.x+0.5));
8344
PNGLong(chunk+32,(unsigned long) (100000*primary.y+0.5));
8542
PNGLong(chunk+28,(png_uint_32) (100000*primary.x+0.5));
8543
PNGLong(chunk+32,(png_uint_32) (100000*primary.y+0.5));
8345
8544
(void) WriteBlob(image,36,chunk);
8346
8545
(void) WriteBlobMSBULong(image,crc32(0,chunk,36));
8415
8614
if (jng_alpha_compression_method==0)
8423
8622
/* Write IDAT chunk header */
8424
8623
if (logging != MagickFalse)
8425
8624
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
8426
" Write IDAT chunks from blob, length=%lu.",
8427
(unsigned long) length);
8625
" Write IDAT chunks from blob, length=%.20g.",(double)
8429
8628
/* Copy IDAT chunks */
8432
for (i=8; i<(long) length; i+=len+12)
8631
for (i=8; i<(ssize_t) length; i+=len+12)
8434
8633
len=(*p<<24)|((*(p+1))<<16)|((*(p+2))<<8)|(*(p+3));
8436
8635
if (*(p)==73 && *(p+1)==68 && *(p+2)==65 && *(p+3)==84) /* IDAT */
8438
8637
/* Found an IDAT chunk. */
8439
(void) WriteBlobMSBULong(image,(unsigned long) len);
8440
LogPNGChunk((int) logging,mng_IDAT,(unsigned long) len);
8638
(void) WriteBlobMSBULong(image,(size_t) len);
8639
LogPNGChunk((int) logging,mng_IDAT,(size_t) len);
8441
8640
(void) WriteBlob(image,(size_t) len+4,p);
8442
8641
(void) WriteBlobMSBULong(image,
8443
8642
crc32(0,p,(uInt) len+4));
8512
8710
if (logging != MagickFalse)
8514
8712
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
8515
" Successfully read jpeg_image into a blob, length=%lu.",
8516
(unsigned long) length);
8713
" Successfully read jpeg_image into a blob, length=%.20g.",
8518
8716
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
8519
" Write JDAT chunk, length=%lu.",
8520
(unsigned long) length);
8717
" Write JDAT chunk, length=%.20g.",(double) length);
8522
8719
/* Write JDAT chunk(s) */
8523
(void) WriteBlobMSBULong(image,(unsigned long) length);
8720
(void) WriteBlobMSBULong(image,(size_t) length);
8524
8721
PNGType(chunk,mng_JDAT);
8525
8722
LogPNGChunk((int) logging,mng_JDAT,length);
8526
8723
(void) WriteBlob(image,4,chunk);
9115
9312
if (logging != MagickFalse)
9117
9314
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
9119
(png_uint_32) (mng_info->ticks_per_second*
9120
final_delay/MagickMax(image->ticks_per_second,1)));
9315
" TERM delay: %.20g",(double) (mng_info->ticks_per_second*
9316
final_delay/MagickMax(image->ticks_per_second,1)));
9121
9317
if (image->iterations == 0)
9122
9318
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
9123
" TERM iterations: %lu",PNG_UINT_31_MAX);
9319
" TERM iterations: %.20g",(double) PNG_UINT_31_MAX);
9125
9321
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
9126
" Image iterations: %lu",image->iterations);
9322
" Image iterations: %.20g",(double) image->iterations);
9128
9324
(void) WriteBlob(image,14,chunk);
9129
9325
(void) WriteBlobMSBULong(image,crc32(0,chunk,14));
9175
9371
PNGType(chunk,mng_cHRM);
9176
9372
LogPNGChunk((int) logging,mng_cHRM,32L);
9177
9373
primary=image->chromaticity.white_point;
9178
PNGLong(chunk+4,(unsigned long) (100000*primary.x+0.5));
9179
PNGLong(chunk+8,(unsigned long) (100000*primary.y+0.5));
9374
PNGLong(chunk+4,(png_uint_32) (100000*primary.x+0.5));
9375
PNGLong(chunk+8,(png_uint_32) (100000*primary.y+0.5));
9180
9376
primary=image->chromaticity.red_primary;
9181
PNGLong(chunk+12,(unsigned long) (100000*primary.x+0.5));
9182
PNGLong(chunk+16,(unsigned long) (100000*primary.y+0.5));
9377
PNGLong(chunk+12,(png_uint_32) (100000*primary.x+0.5));
9378
PNGLong(chunk+16,(png_uint_32) (100000*primary.y+0.5));
9183
9379
primary=image->chromaticity.green_primary;
9184
PNGLong(chunk+20,(unsigned long) (100000*primary.x+0.5));
9185
PNGLong(chunk+24,(unsigned long) (100000*primary.y+0.5));
9380
PNGLong(chunk+20,(png_uint_32) (100000*primary.x+0.5));
9381
PNGLong(chunk+24,(png_uint_32) (100000*primary.y+0.5));
9186
9382
primary=image->chromaticity.blue_primary;
9187
PNGLong(chunk+28,(unsigned long) (100000*primary.x+0.5));
9188
PNGLong(chunk+32,(unsigned long) (100000*primary.y+0.5));
9383
PNGLong(chunk+28,(png_uint_32) (100000*primary.x+0.5));
9384
PNGLong(chunk+32,(png_uint_32) (100000*primary.y+0.5));
9189
9385
(void) WriteBlob(image,36,chunk);
9190
9386
(void) WriteBlobMSBULong(image,crc32(0,chunk,36));
9191
9387
mng_info->have_write_global_chrm=MagickTrue;