29JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4390 4611 4365 4267 4616 2544 2545 6297)
33#if JUCE_INCLUDE_ZLIB_CODE
38 #include <juce_core/zip/zlib/zlib.h>
41 #include JUCE_ZLIB_INCLUDE_PATH
45#if ! defined (jmp_buf) || ! defined (longjmp)
49namespace pnglibNamespace
51 using namespace zlibNamespace;
53#if JUCE_INCLUDE_PNGLIB_CODE || ! defined (JUCE_INCLUDE_PNGLIB_CODE)
61 JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE (
"-Wcomma",
63 "-Wimplicit-fallthrough",
64 "-Wmaybe-uninitialized",
65 "-Wnull-pointer-subtraction",
67 "-Wtautological-constant-out-of-range-compare",
68 "-Wzero-as-null-pointer-constant")
76 #define PNG_ARM_NEON_SUPPORTED
83 #define PNG_16BIT_SUPPORTED
84 #define PNG_ALIGNED_MEMORY_SUPPORTED
85 #define PNG_BENIGN_ERRORS_SUPPORTED
86 #define PNG_BENIGN_READ_ERRORS_SUPPORTED
87 #define PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
88 #define PNG_COLORSPACE_SUPPORTED
89 #define PNG_CONSOLE_IO_SUPPORTED
90 #define PNG_EASY_ACCESS_SUPPORTED
91 #define PNG_FIXED_POINT_SUPPORTED
92 #define PNG_FLOATING_ARITHMETIC_SUPPORTED
93 #define PNG_FLOATING_POINT_SUPPORTED
94 #define PNG_FORMAT_AFIRST_SUPPORTED
95 #define PNG_FORMAT_BGR_SUPPORTED
96 #define PNG_GAMMA_SUPPORTED
97 #define PNG_GET_PALETTE_MAX_SUPPORTED
98 #define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
99 #define PNG_INCH_CONVERSIONS_SUPPORTED
100 #define PNG_INFO_IMAGE_SUPPORTED
101 #define PNG_IO_STATE_SUPPORTED
102 #define PNG_POINTER_INDEXING_SUPPORTED
103 #define PNG_PROGRESSIVE_READ_SUPPORTED
104 #define PNG_READ_16BIT_SUPPORTED
105 #define PNG_READ_ALPHA_MODE_SUPPORTED
106 #define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
107 #define PNG_READ_BACKGROUND_SUPPORTED
108 #define PNG_READ_BGR_SUPPORTED
109 #define PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
110 #define PNG_READ_COMPOSITE_NODIV_SUPPORTED
111 #define PNG_READ_COMPRESSED_TEXT_SUPPORTED
112 #define PNG_READ_EXPAND_16_SUPPORTED
113 #define PNG_READ_EXPAND_SUPPORTED
114 #define PNG_READ_FILLER_SUPPORTED
115 #define PNG_READ_GAMMA_SUPPORTED
116 #define PNG_READ_GET_PALETTE_MAX_SUPPORTED
117 #define PNG_READ_GRAY_TO_RGB_SUPPORTED
118 #define PNG_READ_INTERLACING_SUPPORTED
119 #define PNG_READ_INT_FUNCTIONS_SUPPORTED
120 #define PNG_READ_INVERT_ALPHA_SUPPORTED
121 #define PNG_READ_INVERT_SUPPORTED
122 #define PNG_READ_OPT_PLTE_SUPPORTED
123 #define PNG_READ_PACKSWAP_SUPPORTED
124 #define PNG_READ_PACK_SUPPORTED
125 #define PNG_READ_QUANTIZE_SUPPORTED
126 #define PNG_READ_RGB_TO_GRAY_SUPPORTED
127 #define PNG_READ_SCALE_16_TO_8_SUPPORTED
128 #define PNG_READ_SHIFT_SUPPORTED
129 #define PNG_READ_STRIP_16_TO_8_SUPPORTED
130 #define PNG_READ_STRIP_ALPHA_SUPPORTED
131 #define PNG_READ_SUPPORTED
132 #define PNG_READ_SWAP_ALPHA_SUPPORTED
133 #define PNG_READ_SWAP_SUPPORTED
134 #define PNG_READ_TEXT_SUPPORTED
135 #define PNG_READ_TRANSFORMS_SUPPORTED
136 #define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
137 #define PNG_READ_USER_CHUNKS_SUPPORTED
138 #define PNG_READ_USER_TRANSFORM_SUPPORTED
139 #define PNG_READ_bKGD_SUPPORTED
140 #define PNG_READ_cHRM_SUPPORTED
141 #define PNG_READ_gAMA_SUPPORTED
142 #define PNG_READ_hIST_SUPPORTED
143 #define PNG_READ_iCCP_SUPPORTED
144 #define PNG_READ_iTXt_SUPPORTED
145 #define PNG_READ_oFFs_SUPPORTED
146 #define PNG_READ_pCAL_SUPPORTED
147 #define PNG_READ_pHYs_SUPPORTED
148 #define PNG_READ_sBIT_SUPPORTED
149 #define PNG_READ_sCAL_SUPPORTED
150 #define PNG_READ_sPLT_SUPPORTED
151 #define PNG_READ_sRGB_SUPPORTED
152 #define PNG_READ_tEXt_SUPPORTED
153 #define PNG_READ_tIME_SUPPORTED
154 #define PNG_READ_tRNS_SUPPORTED
155 #define PNG_READ_zTXt_SUPPORTED
156 #define PNG_SAVE_INT_32_SUPPORTED
157 #define PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
158 #define PNG_SEQUENTIAL_READ_SUPPORTED
159 #define PNG_SET_CHUNK_CACHE_LIMIT_SUPPORTED
160 #define PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
161 #define PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
162 #define PNG_SET_USER_LIMITS_SUPPORTED
163 #define PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED
164 #define PNG_SIMPLIFIED_READ_BGR_SUPPORTED
165 #define PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
166 #define PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED
167 #define PNG_STDIO_SUPPORTED
168 #define PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
169 #define PNG_TEXT_SUPPORTED
170 #define PNG_TIME_RFC1123_SUPPORTED
171 #define PNG_UNKNOWN_CHUNKS_SUPPORTED
172 #define PNG_USER_CHUNKS_SUPPORTED
173 #define PNG_USER_LIMITS_SUPPORTED
174 #define PNG_USER_TRANSFORM_INFO_SUPPORTED
175 #define PNG_USER_TRANSFORM_PTR_SUPPORTED
176 #define PNG_WARNINGS_SUPPORTED
177 #define PNG_WRITE_16BIT_SUPPORTED
178 #define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
179 #define PNG_WRITE_BGR_SUPPORTED
180 #define PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED
181 #define PNG_WRITE_COMPRESSED_TEXT_SUPPORTED
182 #define PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
183 #define PNG_WRITE_FILLER_SUPPORTED
184 #define PNG_WRITE_FILTER_SUPPORTED
185 #define PNG_WRITE_FLUSH_SUPPORTED
186 #define PNG_WRITE_GET_PALETTE_MAX_SUPPORTED
187 #define PNG_WRITE_INTERLACING_SUPPORTED
188 #define PNG_WRITE_INT_FUNCTIONS_SUPPORTED
189 #define PNG_WRITE_INVERT_ALPHA_SUPPORTED
190 #define PNG_WRITE_INVERT_SUPPORTED
191 #define PNG_WRITE_OPTIMIZE_CMF_SUPPORTED
192 #define PNG_WRITE_PACKSWAP_SUPPORTED
193 #define PNG_WRITE_PACK_SUPPORTED
194 #define PNG_WRITE_SHIFT_SUPPORTED
195 #define PNG_WRITE_SUPPORTED
196 #define PNG_WRITE_SWAP_ALPHA_SUPPORTED
197 #define PNG_WRITE_SWAP_SUPPORTED
198 #define PNG_WRITE_TEXT_SUPPORTED
199 #define PNG_WRITE_TRANSFORMS_SUPPORTED
200 #define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
201 #define PNG_WRITE_USER_TRANSFORM_SUPPORTED
202 #define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
203 #define PNG_WRITE_bKGD_SUPPORTED
204 #define PNG_WRITE_cHRM_SUPPORTED
205 #define PNG_WRITE_gAMA_SUPPORTED
206 #define PNG_WRITE_hIST_SUPPORTED
207 #define PNG_WRITE_iCCP_SUPPORTED
208 #define PNG_WRITE_iTXt_SUPPORTED
209 #define PNG_WRITE_oFFs_SUPPORTED
210 #define PNG_WRITE_pCAL_SUPPORTED
211 #define PNG_WRITE_pHYs_SUPPORTED
212 #define PNG_WRITE_sBIT_SUPPORTED
213 #define PNG_WRITE_sCAL_SUPPORTED
214 #define PNG_WRITE_sPLT_SUPPORTED
215 #define PNG_WRITE_sRGB_SUPPORTED
216 #define PNG_WRITE_tEXt_SUPPORTED
217 #define PNG_WRITE_tIME_SUPPORTED
218 #define PNG_WRITE_tRNS_SUPPORTED
219 #define PNG_WRITE_zTXt_SUPPORTED
220 #define PNG_bKGD_SUPPORTED
221 #define PNG_cHRM_SUPPORTED
222 #define PNG_gAMA_SUPPORTED
223 #define PNG_hIST_SUPPORTED
224 #define PNG_iCCP_SUPPORTED
225 #define PNG_iTXt_SUPPORTED
226 #define PNG_oFFs_SUPPORTED
227 #define PNG_pCAL_SUPPORTED
228 #define PNG_pHYs_SUPPORTED
229 #define PNG_sBIT_SUPPORTED
230 #define PNG_sCAL_SUPPORTED
231 #define PNG_sPLT_SUPPORTED
232 #define PNG_sRGB_SUPPORTED
233 #define PNG_tEXt_SUPPORTED
234 #define PNG_tIME_SUPPORTED
235 #define PNG_tRNS_SUPPORTED
236 #define PNG_zTXt_SUPPORTED
238 #define PNG_STRING_COPYRIGHT "";
239 #define PNG_STRING_NEWLINE "\n"
240 #define PNG_LITERAL_SHARP 0x23
241 #define PNG_LITERAL_LEFT_SQUARE_BRACKET 0x5b
242 #define PNG_LITERAL_RIGHT_SQUARE_BRACKET 0x5d
244 #define PNG_API_RULE 0
245 #define PNG_CALLOC_SUPPORTED
246 #define PNG_COST_SHIFT 3
247 #define PNG_DEFAULT_READ_MACROS 1
248 #define PNG_GAMMA_THRESHOLD_FIXED 5000
249 #define PNG_IDAT_READ_SIZE PNG_ZBUF_SIZE
250 #define PNG_INFLATE_BUF_SIZE 1024
251 #define PNG_MAX_GAMMA_8 11
252 #define PNG_QUANTIZE_BLUE_BITS 5
253 #define PNG_QUANTIZE_GREEN_BITS 5
254 #define PNG_QUANTIZE_RED_BITS 5
255 #define PNG_TEXT_Z_DEFAULT_COMPRESSION (-1)
256 #define PNG_TEXT_Z_DEFAULT_STRATEGY 0
257 #define PNG_WEIGHT_SHIFT 8
258 #define PNG_ZBUF_SIZE 8192
259 #define PNG_Z_DEFAULT_COMPRESSION (-1)
260 #define PNG_Z_DEFAULT_NOFILTER_STRATEGY 0
261 #define PNG_Z_DEFAULT_STRATEGY 1
262 #define PNG_sCAL_PRECISION 5
263 #define PNG_sRGB_PROFILE_CHECKS 2
265 #define PNG_LINKAGE_API
266 #define PNG_LINKAGE_FUNCTION
268 #define PNG_ARM_NEON_OPT 0
270 #if ! defined (PNG_USER_WIDTH_MAX)
271 #define PNG_USER_WIDTH_MAX 1000000
274 #if ! defined (PNG_USER_HEIGHT_MAX)
275 #define PNG_USER_HEIGHT_MAX 1000000
278 #define png_debug(a, b)
279 #define png_debug1(a, b, c)
280 #define png_debug2(a, b, c, d)
282 #include "pnglib/png.h"
283 #include "pnglib/pngconf.h"
285 #define PNG_NO_EXTERN
286 #include "pnglib/png.c"
287 #include "pnglib/pngerror.c"
288 #include "pnglib/pngget.c"
289 #include "pnglib/pngmem.c"
290 #include "pnglib/pngread.c"
291 #include "pnglib/pngpread.c"
292 #include "pnglib/pngrio.c"
311 #include "pnglib/pngrtran.c"
312 #include "pnglib/pngrutil.c"
313 #include "pnglib/pngset.c"
314 #include "pnglib/pngtrans.c"
315 #include "pnglib/pngwio.c"
316 #include "pnglib/pngwrite.c"
317 #include "pnglib/pngwtran.c"
318 #include "pnglib/pngwutil.c"
320 JUCE_END_IGNORE_WARNINGS_GCC_LIKE
335JUCE_END_IGNORE_WARNINGS_MSVC
340 using namespace pnglibNamespace;
344 static_cast<OutputStream*
> (
png_get_io_ptr (png))->write (data, length);
347 #if ! JUCE_USING_COREIMAGE_LOADER
350 static_cast<InputStream*
> (
png_get_io_ptr (png))->read (data, (
int) length);
357 #ifdef PNG_SETJMP_SUPPORTED
360 longjmp (*(jmp_buf*) p->error_ptr, 1);
366 JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4611)
418 JUCE_END_IGNORE_WARNINGS_MSVC
425 image.getProperties()->set (
"originalImageHadAlpha", image.hasAlphaChannel());
428 const Image::BitmapData destData (image, Image::BitmapData::writeOnly);
430 for (
int y = 0; y < (
int) height; ++y)
432 const uint8* src = rows[y];
433 uint8* dest = destData.getLinePointer (y);
437 for (
int i = (
int) width; --i >= 0;)
439 ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
440 ((PixelARGB*) dest)->premultiply();
441 dest += destData.pixelStride;
447 for (
int i = (
int) width; --i >= 0;)
449 ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
450 dest += destData.pixelStride;
471 const size_t lineStride = width * 4;
472 HeapBlock<uint8> tempBuffer (height * lineStride);
475 for (
size_t y = 0; y < height; ++y)
476 rows[y] = (
png_bytep) (tempBuffer + lineStride * y);
485 (
int) width, (
int) height, rows);
491 static Image readImage (InputStream& in)
511PNGImageFormat::PNGImageFormat() {}
512PNGImageFormat::~PNGImageFormat() {}
528#if JUCE_USING_COREIMAGE_LOADER
534 #if JUCE_USING_COREIMAGE_LOADER
537 return PNGHelpers::readImage (in);
543 using namespace pnglibNamespace;
544 auto width = image.getWidth();
545 auto height = image.getHeight();
586 for (
int y = 0; y < height; ++y)
591 if (image.hasAlphaChannel())
593 for (
int i = width; --i >= 0;)
599 *
dst++ = p.getGreen();
600 *
dst++ = p.getBlue();
601 *
dst++ = p.getAlpha();
607 for (
int i = width; --i >= 0;)
Represents a local file or directory.
bool hasFileExtension(StringRef extensionToTest) const
Checks whether the file has a given extension.
Very simple container class to hold a pointer to some data on the heap.
Retrieves a section of an image as raw pixel data, so it can be read or written to.
int pixelStride
The number of bytes between each pixel.
uint8 * getLinePointer(int y) const noexcept
Returns a pointer to the start of a line in the image.
Holds a fixed-size bitmap.
@ ARGB
< each pixel is a 4-byte ARGB premultiplied colour value.
The base class for streams that write data to some kind of destination.
Represents a 32-bit INTERNAL pixel with premultiplied alpha, and can perform compositing operations w...
forcedinline void unpremultiply() noexcept
Unpremultiplies the pixel's RGB values.
Represents a 24-bit RGB pixel, and can perform compositing operations on it.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
unsigned char uint8
A platform-independent 8-bit unsigned integer type.