Bug Summary

File:root/firefox-clang/media/libpng/pngrutil.c
Warning:line 1310, column 15
The left operand of '>' is a garbage value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name pngrutil.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/media/libpng -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/media/libpng -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D MOZ_PNG_USE_INTEL_SSE -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D MOZ_SUPPORT_LEAKCHECKING -D STATIC_EXPORTABLE_JS_API -I /root/firefox-clang/media/libpng -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/media/libpng -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=tautological-type-limit-compare -Wno-range-loop-analysis -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-unknown-warning-option -Wno-character-conversion -std=gnu89 -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-10-17-231001-351276-1 -x c /root/firefox-clang/media/libpng/pngrutil.c
1/* pngrutil.c - utilities to read a PNG file
2 *
3 * Copyright (c) 2018-2025 Cosmin Truta
4 * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
5 * Copyright (c) 1996-1997 Andreas Dilger
6 * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
7 *
8 * This code is released under the libpng license.
9 * For conditions of distribution and use, see the disclaimer
10 * and license in png.h
11 *
12 * This file contains routines that are only called from within
13 * libpng itself during the course of reading an image.
14 */
15
16#include "pngpriv.h"
17
18#ifdef PNG_READ_SUPPORTED
19
20/* The minimum 'zlib' stream is assumed to be just the 2 byte header, 5 bytes
21 * minimum 'deflate' stream, and the 4 byte checksum.
22 */
23#define LZ77Min(2U+5U+4U) (2U+5U+4U)
24
25#ifdef PNG_READ_INTERLACING_SUPPORTED
26/* Arrays to facilitate interlacing - use pass (0 - 6) as index. */
27
28/* Start of interlace block */
29static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
30/* Offset to next interlace block */
31static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
32/* Start of interlace block in the y direction */
33static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
34/* Offset to next interlace block in the y direction */
35static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
36
37/* TODO: Move these arrays to a common utility module to avoid duplication. */
38#endif
39
40png_uint_32 PNGAPI
41png_get_uint_31MOZ_PNG_get_uint_31(png_const_structrp png_ptr, png_const_bytep buf)
42{
43 png_uint_32 uval = png_get_uint_32(buf)(((png_uint_32)(*(buf)) << 24) + ((png_uint_32)(*((buf)
+ 1)) << 16) + ((png_uint_32)(*((buf) + 2)) << 8
) + ((png_uint_32)(*((buf) + 3))))
;
44
45 if (uval > PNG_UINT_31_MAX((png_uint_32)0x7fffffffL))
46 png_error(png_ptr, "PNG unsigned integer out of range");
47
48 return uval;
49}
50
51#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED
52/* NOTE: the read macros will obscure these definitions, so that if
53 * PNG_USE_READ_MACROS is set the library will not use them internally,
54 * but the APIs will still be available externally.
55 *
56 * The parentheses around "PNGAPI function_name" in the following three
57 * functions are necessary because they allow the macros to co-exist with
58 * these (unused but exported) functions.
59 */
60
61/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */
62png_uint_32 (PNGAPI
63png_get_uint_32)(png_const_bytep buf)
64{
65 png_uint_32 uval =
66 ((png_uint_32)(*(buf )) << 24) +
67 ((png_uint_32)(*(buf + 1)) << 16) +
68 ((png_uint_32)(*(buf + 2)) << 8) +
69 ((png_uint_32)(*(buf + 3)) ) ;
70
71 return uval;
72}
73
74/* Grab a signed 32-bit integer from a buffer in big-endian format. The
75 * data is stored in the PNG file in two's complement format and there
76 * is no guarantee that a 'png_int_32' is exactly 32 bits, therefore
77 * the following code does a two's complement to native conversion.
78 */
79png_int_32 (PNGAPI
80png_get_int_32)(png_const_bytep buf)
81{
82 png_uint_32 uval = png_get_uint_32(buf)(((png_uint_32)(*(buf)) << 24) + ((png_uint_32)(*((buf)
+ 1)) << 16) + ((png_uint_32)(*((buf) + 2)) << 8
) + ((png_uint_32)(*((buf) + 3))))
;
83 if ((uval & 0x80000000) == 0) /* non-negative */
84 return (png_int_32)uval;
85
86 uval = (uval ^ 0xffffffff) + 1; /* 2's complement: -x = ~x+1 */
87 if ((uval & 0x80000000) == 0) /* no overflow */
88 return -(png_int_32)uval;
89 /* The following has to be safe; this function only gets called on PNG data
90 * and if we get here that data is invalid. 0 is the most safe value and
91 * if not then an attacker would surely just generate a PNG with 0 instead.
92 */
93 return 0;
94}
95
96/* Grab an unsigned 16-bit integer from a buffer in big-endian format. */
97png_uint_16 (PNGAPI
98png_get_uint_16)(png_const_bytep buf)
99{
100 /* ANSI-C requires an int value to accommodate at least 16 bits so this
101 * works and allows the compiler not to worry about possible narrowing
102 * on 32-bit systems. (Pre-ANSI systems did not make integers smaller
103 * than 16 bits either.)
104 */
105 unsigned int val =
106 ((unsigned int)(*buf) << 8) +
107 ((unsigned int)(*(buf + 1)));
108
109 return (png_uint_16)val;
110}
111
112#endif /* READ_INT_FUNCTIONS */
113
114/* Read and check the PNG file signature */
115void /* PRIVATE */
116png_read_sigMOZ_PNG_read_sig(png_structrp png_ptr, png_inforp info_ptr)
117{
118 size_t num_checked, num_to_check;
119
120 /* Exit if the user application does not expect a signature. */
121 if (png_ptr->sig_bytes >= 8)
122 return;
123
124 num_checked = png_ptr->sig_bytes;
125 num_to_check = 8 - num_checked;
126
127#ifdef PNG_IO_STATE_SUPPORTED
128 png_ptr->io_state = PNG_IO_READING | PNG_IO_SIGNATURE;
129#endif
130
131 /* The signature must be serialized in a single I/O call. */
132 png_read_dataMOZ_PNG_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
133 png_ptr->sig_bytes = 8;
134
135 if (png_sig_cmpMOZ_PNG_sig_cmp(info_ptr->signature, num_checked, num_to_check) != 0)
136 {
137 if (num_checked < 4 &&
138 png_sig_cmpMOZ_PNG_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4) != 0)
139 png_error(png_ptr, "Not a PNG file");
140 else
141 png_error(png_ptr, "PNG file corrupted by ASCII conversion");
142 }
143 if (num_checked < 3)
144 png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE0x1000U;
145}
146
147/* This function is called to verify that a chunk name is valid.
148 * Do this using the bit-whacking approach from contrib/tools/pngfix.c
149 *
150 * Copied from libpng 1.7.
151 */
152static int
153check_chunk_name(png_uint_32 name)
154{
155 png_uint_32 t;
156
157 /* Remove bit 5 from all but the reserved byte; this means
158 * every 8-bit unit must be in the range 65-90 to be valid.
159 * So bit 5 must be zero, bit 6 must be set and bit 7 zero.
160 */
161 name &= ~PNG_U32(32,32,0,32)((((0xFFFFFFFFU)&(32)) << (24)) | (((0xFFFFFFFFU)&
(32)) << (16)) | (((0xFFFFFFFFU)&(0)) << (8))
| (((0xFFFFFFFFU)&(32)) << (0)))
;
162 t = (name & ~0x1f1f1f1fU) ^ 0x40404040U;
163
164 /* Subtract 65 for each 8-bit quantity, this must not
165 * overflow and each byte must then be in the range 0-25.
166 */
167 name -= PNG_U32(65,65,65,65)((((0xFFFFFFFFU)&(65)) << (24)) | (((0xFFFFFFFFU)&
(65)) << (16)) | (((0xFFFFFFFFU)&(65)) << (8)
) | (((0xFFFFFFFFU)&(65)) << (0)))
;
168 t |= name;
169
170 /* Subtract 26, handling the overflow which should set the
171 * top three bits of each byte.
172 */
173 name -= PNG_U32(25,25,25,26)((((0xFFFFFFFFU)&(25)) << (24)) | (((0xFFFFFFFFU)&
(25)) << (16)) | (((0xFFFFFFFFU)&(25)) << (8)
) | (((0xFFFFFFFFU)&(26)) << (0)))
;
174 t |= ~name;
175
176 return (t & 0xe0e0e0e0U) == 0U;
177}
178
179/* Read the chunk header (length + type name).
180 * Put the type name into png_ptr->chunk_name, and return the length.
181 */
182png_uint_32 /* PRIVATE */
183png_read_chunk_headerMOZ_PNG_read_chunk_header(png_structrp png_ptr)
184{
185 png_byte buf[8];
186 png_uint_32 chunk_name, length;
187
188#ifdef PNG_IO_STATE_SUPPORTED
189 png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_HDR;
190#endif
191
192 /* Read the length and the chunk name. png_struct::chunk_name is immediately
193 * updated even if they are detectably wrong. This aids error message
194 * handling by allowing png_chunk_error to be used.
195 */
196 png_read_dataMOZ_PNG_read_data(png_ptr, buf, 8);
197 length = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, buf);
198 png_ptr->chunk_name = chunk_name = PNG_CHUNK_FROM_STRING(buf+4)((((0xFFFFFFFFU)&(0xff & (buf+4)[0])) << (24)) |
(((0xFFFFFFFFU)&(0xff & (buf+4)[1])) << (16)) |
(((0xFFFFFFFFU)&(0xff & (buf+4)[2])) << (8)) |
(((0xFFFFFFFFU)&(0xff & (buf+4)[3])) << (0)))
;
199
200 /* Reset the crc and run it over the chunk name. */
201 png_reset_crcMOZ_PNG_reset_crc(png_ptr);
202 png_calculate_crcMOZ_PNG_calc_crc(png_ptr, buf + 4, 4);
203
204 png_debug2(0, "Reading chunk typeid = 0x%lx, length = %lu",((void)0)
205 (unsigned long)png_ptr->chunk_name, (unsigned long)length)((void)0);
206
207 /* Sanity check the length (first by <= 0x80) and the chunk name. An error
208 * here indicates a broken stream and libpng has no recovery from this.
209 */
210 if (buf[0] >= 0x80U)
211 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, "bad header (invalid length)");
212
213 /* Check to see if chunk name is valid. */
214 if (!check_chunk_name(chunk_name))
215 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, "bad header (invalid type)");
216
217#ifdef PNG_IO_STATE_SUPPORTED
218 png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_DATA;
219#endif
220
221 return length;
222}
223
224/* Read data, and (optionally) run it through the CRC. */
225void /* PRIVATE */
226png_crc_readMOZ_PNG_crc_read(png_structrp png_ptr, png_bytep buf, png_uint_32 length)
227{
228 if (png_ptr == NULL((void*)0))
3
Assuming 'png_ptr' is equal to NULL
4
Taking true branch
229 return;
5
Returning without writing to '*buf'
230
231 png_read_dataMOZ_PNG_read_data(png_ptr, buf, length);
232 png_calculate_crcMOZ_PNG_calc_crc(png_ptr, buf, length);
233}
234
235/* Compare the CRC stored in the PNG file with that calculated by libpng from
236 * the data it has read thus far.
237 */
238static int
239png_crc_errorMOZ_PNG_crc_error(png_structrp png_ptr, int handle_as_ancillary)
240{
241 png_byte crc_bytes[4];
242 png_uint_32 crc;
243 int need_crc = 1;
244
245 /* There are four flags two for ancillary and two for critical chunks. The
246 * default setting of these flags is all zero.
247 *
248 * PNG_FLAG_CRC_ANCILLARY_USE
249 * PNG_FLAG_CRC_ANCILLARY_NOWARN
250 * USE+NOWARN: no CRC calculation (implemented here), else;
251 * NOWARN: png_chunk_error on error (implemented in png_crc_finish)
252 * else: png_chunk_warning on error (implemented in png_crc_finish)
253 * This is the default.
254 *
255 * I.e. NOWARN without USE produces png_chunk_error. The default setting
256 * where neither are set does the same thing.
257 *
258 * PNG_FLAG_CRC_CRITICAL_USE
259 * PNG_FLAG_CRC_CRITICAL_IGNORE
260 * IGNORE: no CRC calculation (implemented here), else;
261 * USE: png_chunk_warning on error (implemented in png_crc_finish)
262 * else: png_chunk_error on error (implemented in png_crc_finish)
263 * This is the default.
264 *
265 * This arose because of original mis-implementation and has persisted for
266 * compatibility reasons.
267 *
268 * TODO: the flag names are internal so maybe this can be changed to
269 * something comprehensible.
270 */
271 if (handle_as_ancillary || PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)(1 & ((png_ptr->chunk_name) >> 29)) != 0)
272 {
273 if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK(0x0100U | 0x0200U)) ==
274 (PNG_FLAG_CRC_ANCILLARY_USE0x0100U | PNG_FLAG_CRC_ANCILLARY_NOWARN0x0200U))
275 need_crc = 0;
276 }
277
278 else /* critical */
279 {
280 if ((png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE0x0800U) != 0)
281 need_crc = 0;
282 }
283
284#ifdef PNG_IO_STATE_SUPPORTED
285 png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_CRC;
286#endif
287
288 /* The chunk CRC must be serialized in a single I/O call. */
289 png_read_dataMOZ_PNG_read_data(png_ptr, crc_bytes, 4);
290
291 if (need_crc != 0)
292 {
293 crc = png_get_uint_32(crc_bytes)(((png_uint_32)(*(crc_bytes)) << 24) + ((png_uint_32)(*
((crc_bytes) + 1)) << 16) + ((png_uint_32)(*((crc_bytes
) + 2)) << 8) + ((png_uint_32)(*((crc_bytes) + 3))))
;
294 return crc != png_ptr->crc;
295 }
296
297 else
298 return 0;
299}
300
301/* Optionally skip data and then check the CRC. Depending on whether we
302 * are reading an ancillary or critical chunk, and how the program has set
303 * things up, we may calculate the CRC on the data and print a message.
304 * Returns '1' if there was a CRC error, '0' otherwise.
305 *
306 * There is one public version which is used in most places and another which
307 * takes the value for the 'critical' flag to check. This allows PLTE and IEND
308 * handling code to ignore the CRC error and removes some confusing code
309 * duplication.
310 */
311static int
312png_crc_finish_critical(png_structrp png_ptr, png_uint_32 skip,
313 int handle_as_ancillary)
314{
315 /* The size of the local buffer for inflate is a good guess as to a
316 * reasonable size to use for buffering reads from the application.
317 */
318 while (skip > 0)
319 {
320 png_uint_32 len;
321 png_byte tmpbuf[PNG_INFLATE_BUF_SIZE1024];
322
323 len = (sizeof tmpbuf);
324 if (len > skip)
325 len = skip;
326 skip -= len;
327
328 png_crc_readMOZ_PNG_crc_read(png_ptr, tmpbuf, len);
329 }
330
331 /* If 'handle_as_ancillary' has been requested and this is a critical chunk
332 * but PNG_FLAG_CRC_CRITICAL_IGNORE was set then png_read_crc did not, in
333 * fact, calculate the CRC so the ANCILLARY settings should not be used
334 * instead.
335 */
336 if (handle_as_ancillary &&
337 (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE0x0800U) != 0)
338 handle_as_ancillary = 0;
339
340 /* TODO: this might be more comprehensible if png_crc_error was inlined here.
341 */
342 if (png_crc_errorMOZ_PNG_crc_error(png_ptr, handle_as_ancillary) != 0)
343 {
344 /* See above for the explanation of how the flags work. */
345 if (handle_as_ancillary || PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)(1 & ((png_ptr->chunk_name) >> 29)) != 0 ?
346 (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN0x0200U) == 0 :
347 (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE0x0400U) != 0)
348 png_chunk_warningMOZ_PNG_chunk_warn(png_ptr, "CRC error");
349
350 else
351 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, "CRC error");
352
353 return 1;
354 }
355
356 return 0;
357}
358
359int /* PRIVATE */
360png_crc_finishMOZ_PNG_crc_finish(png_structrp png_ptr, png_uint_32 skip)
361{
362 return png_crc_finish_critical(png_ptr, skip, 0/*critical handling*/);
363}
364
365#if defined(PNG_READ_iCCP_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) ||\
366 defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_READ_sCAL_SUPPORTED) ||\
367 defined(PNG_READ_sPLT_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) ||\
368 defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_eXIf_SUPPORTED) ||\
369 defined(PNG_SEQUENTIAL_READ_SUPPORTED)
370/* Manage the read buffer; this simply reallocates the buffer if it is not small
371 * enough (or if it is not allocated). The routine returns a pointer to the
372 * buffer; if an error occurs and 'warn' is set the routine returns NULL, else
373 * it will call png_error on failure.
374 */
375static png_bytep
376png_read_buffer(png_structrp png_ptr, png_alloc_size_t new_size)
377{
378 png_bytep buffer = png_ptr->read_buffer;
379
380 if (new_size > png_chunk_max(png_ptr)((png_ptr)->user_chunk_malloc_max)) return NULL((void*)0);
381
382 if (buffer != NULL((void*)0) && new_size > png_ptr->read_buffer_size)
383 {
384 png_ptr->read_buffer = NULL((void*)0);
385 png_ptr->read_buffer_size = 0;
386 png_freeMOZ_PNG_free(png_ptr, buffer);
387 buffer = NULL((void*)0);
388 }
389
390 if (buffer == NULL((void*)0))
391 {
392 buffer = png_voidcast(png_bytep, png_malloc_base(png_ptr, new_size))(MOZ_PNG_malloc_base(png_ptr, new_size));
393
394 if (buffer != NULL((void*)0))
395 {
396# ifndef PNG_NO_MEMZERO /* for detecting UIM bugs **only** */
397 memset(buffer, 0, new_size); /* just in case */
398# endif
399 png_ptr->read_buffer = buffer;
400 png_ptr->read_buffer_size = new_size;
401 }
402 }
403
404 return buffer;
405}
406#endif /* READ_iCCP|iTXt|pCAL|sCAL|sPLT|tEXt|zTXt|eXIf|SEQUENTIAL_READ */
407
408/* Detach the zstream from the input and output buffers left by
409 * the current or a previous owner, and possibly deallocated since.
410 */
411static void
412png_inflate_detach_buffers(png_structrp png_ptr)
413{
414 png_ptr->zstream.next_in = NULL((void*)0);
415 png_ptr->zstream.avail_in = 0;
416 png_ptr->zstream.next_out = NULL((void*)0);
417 png_ptr->zstream.avail_out = 0;
418}
419
420/* png_inflate_claim: claim the zstream for some nefarious purpose that involves
421 * decompression. Returns Z_OK on success, else a zlib error code. It checks
422 * the owner but, in final release builds, just issues a warning if some other
423 * chunk apparently owns the stream. Prior to release it does a png_error.
424 */
425static int
426png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
427{
428 if (png_ptr->zowner != 0)
429 {
430 char msg[64];
431
432 PNG_STRING_FROM_CHUNK(msg, png_ptr->zowner)(void)(((char*)(msg))[0]=(char)(((png_ptr->zowner)>>
24) & 0xff), ((char*)(msg))[1]=(char)(((png_ptr->zowner
)>>16) & 0xff), ((char*)(msg))[2]=(char)(((png_ptr->
zowner)>>8) & 0xff), ((char*)(msg))[3]=(char)((png_ptr
->zowner & 0xff)))
;
433 /* So the message that results is "<chunk> using zstream"; this is an
434 * internal error, but is very useful for debugging. i18n requirements
435 * are minimal.
436 */
437 (void)png_safecatMOZ_PNG_safecat(msg, (sizeof msg), 4, " using zstream");
438#if PNG_RELEASE_BUILD(4 >= 3)
439 png_chunk_warningMOZ_PNG_chunk_warn(png_ptr, msg);
440 png_ptr->zowner = 0;
441#else
442 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, msg);
443#endif
444 }
445
446 /* Implementation note: unlike 'png_deflate_claim' this internal function
447 * does not take the size of the data as an argument. Some efficiency could
448 * be gained by using this when it is known *if* the zlib stream itself does
449 * not record the number; however, this is an illusion: the original writer
450 * of the PNG may have selected a lower window size, and we really must
451 * follow that because, for systems with limited capabilities, we
452 * would otherwise reject the application's attempts to use a smaller window
453 * size (zlib doesn't have an interface to say "this or lower"!).
454 *
455 * inflateReset2 was added to zlib 1.2.4; before this the window could not be
456 * reset, therefore it is necessary to always allocate the maximum window
457 * size with earlier zlibs just in case later compressed chunks need it.
458 */
459 {
460 int ret; /* zlib return code */
461#if ZLIB_VERNUM0x1320 >= 0x1240
462 int window_bits = 0;
463
464# if defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_MAXIMUM_INFLATE_WINDOW2)
465 if (((png_ptr->options >> PNG_MAXIMUM_INFLATE_WINDOW2) & 3) ==
466 PNG_OPTION_ON3)
467 {
468 window_bits = 15;
469 png_ptr->zstream_start = 0; /* fixed window size */
470 }
471
472 else
473 {
474 png_ptr->zstream_start = 1;
475 }
476# endif
477
478#endif /* ZLIB_VERNUM >= 0x1240 */
479
480 png_inflate_detach_buffers(png_ptr);
481
482 if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED0x0002U) != 0)
483 {
484#if ZLIB_VERNUM0x1320 >= 0x1240
485 ret = inflateReset2MOZ_Z_inflateReset2(&png_ptr->zstream, window_bits);
486#else
487 ret = inflateResetMOZ_Z_inflateReset(&png_ptr->zstream);
488#endif
489 }
490
491 else
492 {
493#if ZLIB_VERNUM0x1320 >= 0x1240
494 ret = inflateInit2(&png_ptr->zstream, window_bits)MOZ_Z_inflateInit2_((&png_ptr->zstream), (window_bits)
, "1.3.2", (int)sizeof(z_stream))
;
495#else
496 ret = inflateInit(&png_ptr->zstream)MOZ_Z_inflateInit_((&png_ptr->zstream), "1.3.2", (int)
sizeof(z_stream))
;
497#endif
498
499 if (ret == Z_OK0)
500 png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED0x0002U;
501 }
502
503#ifdef PNG_DISABLE_ADLER32_CHECK_SUPPORTED
504 if (((png_ptr->options >> PNG_IGNORE_ADLER32) & 3) == PNG_OPTION_ON3)
505 /* Turn off validation of the ADLER32 checksum in IDAT chunks */
506 ret = inflateValidateMOZ_Z_inflateValidate(&png_ptr->zstream, 0);
507#endif
508
509 if (ret == Z_OK0)
510 png_ptr->zowner = owner;
511
512 else
513 png_zstream_errorMOZ_PNG_zstream_error(png_ptr, ret);
514
515 return ret;
516 }
517
518#ifdef window_bits
519# undef window_bits
520#endif
521}
522
523#if ZLIB_VERNUM0x1320 >= 0x1240
524/* Handle the start of the inflate stream if we called inflateInit2(strm,0);
525 * in this case some zlib versions skip validation of the CINFO field and, in
526 * certain circumstances, libpng may end up displaying an invalid image, in
527 * contrast to implementations that call zlib in the normal way (e.g. libpng
528 * 1.5).
529 */
530int /* PRIVATE */
531png_zlib_inflate(png_structrp png_ptr, int flush)
532{
533 if (png_ptr->zstream_start && png_ptr->zstream.avail_in > 0)
534 {
535 if ((*png_ptr->zstream.next_in >> 4) > 7)
536 {
537 png_ptr->zstream.msg = "invalid window size (libpng)";
538 return Z_DATA_ERROR(-3);
539 }
540
541 png_ptr->zstream_start = 0;
542 }
543
544 return inflateMOZ_Z_inflate(&png_ptr->zstream, flush);
545}
546#endif /* Zlib >= 1.2.4 */
547
548#ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED
549#if defined(PNG_READ_zTXt_SUPPORTED) || defined (PNG_READ_iTXt_SUPPORTED)
550/* png_inflate now returns zlib error codes including Z_OK and Z_STREAM_END to
551 * allow the caller to do multiple calls if required. If the 'finish' flag is
552 * set Z_FINISH will be passed to the final inflate() call and Z_STREAM_END must
553 * be returned or there has been a problem, otherwise Z_SYNC_FLUSH is used and
554 * Z_OK or Z_STREAM_END will be returned on success.
555 *
556 * The input and output sizes are updated to the actual amounts of data consumed
557 * or written, not the amount available (as in a z_stream). The data pointers
558 * are not changed, so the next input is (data+input_size) and the next
559 * available output is (output+output_size).
560 */
561static int
562png_inflateMOZ_PNG_inflate(png_structrp png_ptr, png_uint_32 owner, int finish,
563 /* INPUT: */ png_const_bytep input, png_uint_32p input_size_ptr,
564 /* OUTPUT: */ png_bytep output, png_alloc_size_t *output_size_ptr)
565{
566 if (png_ptr->zowner == owner) /* Else not claimed */
567 {
568 int ret;
569 png_alloc_size_t avail_out = *output_size_ptr;
570 png_uint_32 avail_in = *input_size_ptr;
571
572 /* zlib can't necessarily handle more than 65535 bytes at once (i.e. it
573 * can't even necessarily handle 65536 bytes) because the type uInt is
574 * "16 bits or more". Consequently it is necessary to chunk the input to
575 * zlib. This code uses ZLIB_IO_MAX, from pngpriv.h, as the maximum (the
576 * maximum value that can be stored in a uInt.) It is possible to set
577 * ZLIB_IO_MAX to a lower value in pngpriv.h and this may sometimes have
578 * a performance advantage, because it reduces the amount of data accessed
579 * at each step and that may give the OS more time to page it in.
580 */
581 png_ptr->zstream.next_in = PNGZ_INPUT_CAST(input)(input);
582 /* avail_in and avail_out are set below from 'size' */
583 png_ptr->zstream.avail_in = 0;
584 png_ptr->zstream.avail_out = 0;
585
586 /* Read directly into the output if it is available (this is set to
587 * a local buffer below if output is NULL).
588 */
589 if (output != NULL((void*)0))
590 png_ptr->zstream.next_out = output;
591
592 do
593 {
594 uInt avail;
595 Byte local_buffer[PNG_INFLATE_BUF_SIZE1024];
596
597 /* zlib INPUT BUFFER */
598 /* The setting of 'avail_in' used to be outside the loop; by setting it
599 * inside it is possible to chunk the input to zlib and simply rely on
600 * zlib to advance the 'next_in' pointer. This allows arbitrary
601 * amounts of data to be passed through zlib at the unavoidable cost of
602 * requiring a window save (memcpy of up to 32768 output bytes)
603 * every ZLIB_IO_MAX input bytes.
604 */
605 avail_in += png_ptr->zstream.avail_in; /* not consumed last time */
606
607 avail = ZLIB_IO_MAX((uInt)-1);
608
609 if (avail_in < avail)
610 avail = (uInt)avail_in; /* safe: < than ZLIB_IO_MAX */
611
612 avail_in -= avail;
613 png_ptr->zstream.avail_in = avail;
614
615 /* zlib OUTPUT BUFFER */
616 avail_out += png_ptr->zstream.avail_out; /* not written last time */
617
618 avail = ZLIB_IO_MAX((uInt)-1); /* maximum zlib can process */
619
620 if (output == NULL((void*)0))
621 {
622 /* Reset the output buffer each time round if output is NULL and
623 * make available the full buffer, up to 'remaining_space'
624 */
625 png_ptr->zstream.next_out = local_buffer;
626 if ((sizeof local_buffer) < avail)
627 avail = (sizeof local_buffer);
628 }
629
630 if (avail_out < avail)
631 avail = (uInt)avail_out; /* safe: < ZLIB_IO_MAX */
632
633 png_ptr->zstream.avail_out = avail;
634 avail_out -= avail;
635
636 /* zlib inflate call */
637 /* In fact 'avail_out' may be 0 at this point, that happens at the end
638 * of the read when the final LZ end code was not passed at the end of
639 * the previous chunk of input data. Tell zlib if we have reached the
640 * end of the output buffer.
641 */
642 ret = PNG_INFLATE(png_ptr, avail_out > 0 ? Z_NO_FLUSH :png_zlib_inflate(png_ptr, avail_out > 0 ? 0 : (finish ? 4 :
2))
643 (finish ? Z_FINISH : Z_SYNC_FLUSH))png_zlib_inflate(png_ptr, avail_out > 0 ? 0 : (finish ? 4 :
2))
;
644 } while (ret == Z_OK0);
645
646 /* For safety kill the local buffer pointer now */
647 if (output == NULL((void*)0))
648 png_ptr->zstream.next_out = NULL((void*)0);
649
650 /* Claw back the 'size' and 'remaining_space' byte counts. */
651 avail_in += png_ptr->zstream.avail_in;
652 avail_out += png_ptr->zstream.avail_out;
653
654 /* Update the input and output sizes; the updated values are the amount
655 * consumed or written, effectively the inverse of what zlib uses.
656 */
657 if (avail_out > 0)
658 *output_size_ptr -= avail_out;
659
660 if (avail_in > 0)
661 *input_size_ptr -= avail_in;
662
663 /* Ensure png_ptr->zstream.msg is set (even in the success case!) */
664 png_zstream_errorMOZ_PNG_zstream_error(png_ptr, ret);
665 return ret;
666 }
667
668 else
669 {
670 /* This is a bad internal error. The recovery assigns to the zstream msg
671 * pointer, which is not owned by the caller, but this is safe; it's only
672 * used on errors!
673 */
674 png_ptr->zstream.msg = PNGZ_MSG_CAST("zstream unclaimed")("zstream unclaimed");
675 return Z_STREAM_ERROR(-2);
676 }
677}
678
679/*
680 * Decompress trailing data in a chunk. The assumption is that read_buffer
681 * points at an allocated area holding the contents of a chunk with a
682 * trailing compressed part. What we get back is an allocated area
683 * holding the original prefix part and an uncompressed version of the
684 * trailing part (the malloc area passed in is freed).
685 */
686static int
687png_decompress_chunkMOZ_PNG_decomp_chunk(png_structrp png_ptr,
688 png_uint_32 chunklength, png_uint_32 prefix_size,
689 png_alloc_size_t *newlength /* must be initialized to the maximum! */,
690 int terminate /*add a '\0' to the end of the uncompressed data*/)
691{
692 /* TODO: implement different limits for different types of chunk.
693 *
694 * The caller supplies *newlength set to the maximum length of the
695 * uncompressed data, but this routine allocates space for the prefix and
696 * maybe a '\0' terminator too. We have to assume that 'prefix_size' is
697 * limited only by the maximum chunk size.
698 */
699 png_alloc_size_t limit = png_chunk_max(png_ptr)((png_ptr)->user_chunk_malloc_max);
700
701 if (limit >= prefix_size + (terminate != 0))
702 {
703 int ret;
704
705 limit -= prefix_size + (terminate != 0);
706
707 if (limit < *newlength)
708 *newlength = limit;
709
710 /* Now try to claim the stream. */
711 ret = png_inflate_claim(png_ptr, png_ptr->chunk_name);
712
713 if (ret == Z_OK0)
714 {
715 png_uint_32 lzsize = chunklength - prefix_size;
716
717 ret = png_inflateMOZ_PNG_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,
718 /* input: */ png_ptr->read_buffer + prefix_size, &lzsize,
719 /* output: */ NULL((void*)0), newlength);
720
721 if (ret == Z_STREAM_END1)
722 {
723 /* Use 'inflateReset' here, not 'inflateReset2' because this
724 * preserves the previously decided window size (otherwise it would
725 * be necessary to store the previous window size.) In practice
726 * this doesn't matter anyway, because png_inflate will call inflate
727 * with Z_FINISH in almost all cases, so the window will not be
728 * maintained.
729 */
730 if (inflateResetMOZ_Z_inflateReset(&png_ptr->zstream) == Z_OK0)
731 {
732 /* Because of the limit checks above we know that the new,
733 * expanded, size will fit in a size_t (let alone an
734 * png_alloc_size_t). Use png_malloc_base here to avoid an
735 * extra OOM message.
736 */
737 png_alloc_size_t new_size = *newlength;
738 png_alloc_size_t buffer_size = prefix_size + new_size +
739 (terminate != 0);
740 png_bytep text = png_voidcast(png_bytep, png_malloc_base(png_ptr,(MOZ_PNG_malloc_base(png_ptr, buffer_size))
741 buffer_size))(MOZ_PNG_malloc_base(png_ptr, buffer_size));
742
743 if (text != NULL((void*)0))
744 {
745 memset(text, 0, buffer_size);
746
747 ret = png_inflateMOZ_PNG_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,
748 png_ptr->read_buffer + prefix_size, &lzsize,
749 text + prefix_size, newlength);
750
751 if (ret == Z_STREAM_END1)
752 {
753 if (new_size == *newlength)
754 {
755 if (terminate != 0)
756 text[prefix_size + *newlength] = 0;
757
758 if (prefix_size > 0)
759 memcpy(text, png_ptr->read_buffer, prefix_size);
760
761 {
762 png_bytep old_ptr = png_ptr->read_buffer;
763
764 png_ptr->read_buffer = text;
765 png_ptr->read_buffer_size = buffer_size;
766 text = old_ptr; /* freed below */
767 }
768 }
769
770 else
771 {
772 /* The size changed on the second read, there can be no
773 * guarantee that anything is correct at this point.
774 * The 'msg' pointer has been set to "unexpected end of
775 * LZ stream", which is fine, but return an error code
776 * that the caller won't accept.
777 */
778 ret = PNG_UNEXPECTED_ZLIB_RETURN(-7);
779 }
780 }
781
782 else if (ret == Z_OK0)
783 ret = PNG_UNEXPECTED_ZLIB_RETURN(-7); /* for safety */
784
785 /* Free the text pointer (this is the old read_buffer on
786 * success)
787 */
788 png_freeMOZ_PNG_free(png_ptr, text);
789
790 /* This really is very benign, but it's still an error because
791 * the extra space may otherwise be used as a Trojan Horse.
792 */
793 if (ret == Z_STREAM_END1 &&
794 chunklength - prefix_size != lzsize)
795 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "extra compressed data");
796 }
797
798 else
799 {
800 /* Out of memory allocating the buffer */
801 ret = Z_MEM_ERROR(-4);
802 png_zstream_errorMOZ_PNG_zstream_error(png_ptr, Z_MEM_ERROR(-4));
803 }
804 }
805
806 else
807 {
808 /* inflateReset failed, store the error message */
809 png_zstream_errorMOZ_PNG_zstream_error(png_ptr, ret);
810 ret = PNG_UNEXPECTED_ZLIB_RETURN(-7);
811 }
812 }
813
814 else if (ret == Z_OK0)
815 ret = PNG_UNEXPECTED_ZLIB_RETURN(-7);
816
817 /* Release the claimed stream. */
818 png_inflate_detach_buffers(png_ptr);
819 png_ptr->zowner = 0;
820 }
821
822 else /* the claim failed */ if (ret == Z_STREAM_END1) /* impossible! */
823 ret = PNG_UNEXPECTED_ZLIB_RETURN(-7);
824
825 return ret;
826 }
827
828 else
829 {
830 /* Application/configuration limits exceeded */
831 png_zstream_errorMOZ_PNG_zstream_error(png_ptr, Z_MEM_ERROR(-4));
832 return Z_MEM_ERROR(-4);
833 }
834}
835#endif /* READ_zTXt || READ_iTXt */
836#endif /* READ_COMPRESSED_TEXT */
837
838#ifdef PNG_READ_iCCP_SUPPORTED
839/* Perform a partial read and decompress, producing 'avail_out' bytes and
840 * reading from the current chunk as required.
841 */
842static int
843png_inflate_read(png_structrp png_ptr, png_bytep read_buffer, uInt read_size,
844 png_uint_32p chunk_bytes, png_bytep next_out, png_alloc_size_t *out_size,
845 int finish)
846{
847 if (png_ptr->zowner == png_ptr->chunk_name)
848 {
849 int ret;
850
851 /* next_in and avail_in must have been initialized by the caller. */
852 png_ptr->zstream.next_out = next_out;
853 png_ptr->zstream.avail_out = 0; /* set in the loop */
854
855 do
856 {
857 if (png_ptr->zstream.avail_in == 0)
858 {
859 if (read_size > *chunk_bytes)
860 read_size = (uInt)*chunk_bytes;
861 *chunk_bytes -= read_size;
862
863 if (read_size > 0)
864 png_crc_readMOZ_PNG_crc_read(png_ptr, read_buffer, read_size);
865
866 png_ptr->zstream.next_in = read_buffer;
867 png_ptr->zstream.avail_in = read_size;
868 }
869
870 if (png_ptr->zstream.avail_out == 0)
871 {
872 uInt avail = ZLIB_IO_MAX((uInt)-1);
873 if (avail > *out_size)
874 avail = (uInt)*out_size;
875 *out_size -= avail;
876
877 png_ptr->zstream.avail_out = avail;
878 }
879
880 /* Use Z_SYNC_FLUSH when there is no more chunk data to ensure that all
881 * the available output is produced; this allows reading of truncated
882 * streams.
883 */
884 ret = PNG_INFLATE(png_ptr, *chunk_bytes > 0 ?png_zlib_inflate(png_ptr, *chunk_bytes > 0 ? 0 : (finish ?
4 : 2))
885 Z_NO_FLUSH : (finish ? Z_FINISH : Z_SYNC_FLUSH))png_zlib_inflate(png_ptr, *chunk_bytes > 0 ? 0 : (finish ?
4 : 2))
;
886 }
887 while (ret == Z_OK0 && (*out_size > 0 || png_ptr->zstream.avail_out > 0));
888
889 *out_size += png_ptr->zstream.avail_out;
890 png_ptr->zstream.avail_out = 0; /* Should not be required, but is safe */
891
892 /* Ensure the error message pointer is always set: */
893 png_zstream_errorMOZ_PNG_zstream_error(png_ptr, ret);
894 return ret;
895 }
896
897 else
898 {
899 png_ptr->zstream.msg = PNGZ_MSG_CAST("zstream unclaimed")("zstream unclaimed");
900 return Z_STREAM_ERROR(-2);
901 }
902}
903#endif /* READ_iCCP */
904
905/* CHUNK HANDLING */
906/* Read and check the IDHR chunk */
907static png_handle_result_code
908png_handle_IHDRMOZ_PNG_handle_IHDR(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
909{
910 png_byte buf[13];
911 png_uint_32 width, height;
912 int bit_depth, color_type, compression_type, filter_type;
913 int interlace_type;
914
915 png_debug(1, "in png_handle_IHDR")((void)0);
916
917 /* Length and position are checked by the caller. */
918
919 png_ptr->mode |= PNG_HAVE_IHDR0x01;
920
921 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 13);
922 png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0);
923
924 width = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, buf);
925 height = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, buf + 4);
926 bit_depth = buf[8];
927 color_type = buf[9];
928 compression_type = buf[10];
929 filter_type = buf[11];
930 interlace_type = buf[12];
931
932#ifdef PNG_READ_APNG_SUPPORTED
933 png_ptr->first_frame_width = width;
934 png_ptr->first_frame_height = height;
935#endif
936
937 /* Set internal variables */
938 png_ptr->width = width;
939 png_ptr->height = height;
940 png_ptr->bit_depth = (png_byte)bit_depth;
941 png_ptr->interlaced = (png_byte)interlace_type;
942 png_ptr->color_type = (png_byte)color_type;
943#ifdef PNG_MNG_FEATURES_SUPPORTED
944 png_ptr->filter_type = (png_byte)filter_type;
945#endif
946 png_ptr->compression_type = (png_byte)compression_type;
947
948 /* Find number of channels */
949 switch (png_ptr->color_type)
950 {
951 default: /* invalid, png_set_IHDR calls png_error */
952 case PNG_COLOR_TYPE_GRAY0:
953 case PNG_COLOR_TYPE_PALETTE(2 | 1):
954 png_ptr->channels = 1;
955 break;
956
957 case PNG_COLOR_TYPE_RGB(2):
958 png_ptr->channels = 3;
959 break;
960
961 case PNG_COLOR_TYPE_GRAY_ALPHA(4):
962 png_ptr->channels = 2;
963 break;
964
965 case PNG_COLOR_TYPE_RGB_ALPHA(2 | 4):
966 png_ptr->channels = 4;
967 break;
968 }
969
970 /* Set up other useful info */
971 png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth * png_ptr->channels);
972 png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width)((png_ptr->pixel_depth) >= 8 ? ((size_t)(png_ptr->width
) * (((size_t)(png_ptr->pixel_depth)) >> 3)) : (( ((
size_t)(png_ptr->width) * ((size_t)(png_ptr->pixel_depth
))) + 7) >> 3) )
;
973 png_debug1(3, "bit_depth = %d", png_ptr->bit_depth)((void)0);
974 png_debug1(3, "channels = %d", png_ptr->channels)((void)0);
975 png_debug1(3, "rowbytes = %lu", (unsigned long)png_ptr->rowbytes)((void)0);
976
977 /* Rely on png_set_IHDR to completely validate the data and call png_error if
978 * it's wrong.
979 */
980 png_set_IHDRMOZ_PNG_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
981 color_type, interlace_type, compression_type, filter_type);
982
983 return handled_ok;
984 PNG_UNUSED(length)(void)length;
985}
986
987/* Read and check the palette */
988/* TODO: there are several obvious errors in this code when handling
989 * out-of-place chunks and there is much over-complexity caused by trying to
990 * patch up the problems.
991 */
992static png_handle_result_code
993png_handle_PLTEMOZ_PNG_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
994{
995 png_const_charp errmsg = NULL((void*)0);
996
997 png_debug(1, "in png_handle_PLTE")((void)0);
998
999 /* 1.6.47: consistency. This used to be especially treated as a critical
1000 * error even in an image which is not colour mapped, there isn't a good
1001 * justification for treating some errors here one way and others another so
1002 * everything uses the same logic.
1003 */
1004 if ((png_ptr->mode & PNG_HAVE_PLTE0x02) != 0)
1005 errmsg = "duplicate";
1006
1007 else if ((png_ptr->mode & PNG_HAVE_IDAT0x04U) != 0)
1008 errmsg = "out of place";
1009
1010 else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR2) == 0)
1011 errmsg = "ignored in grayscale PNG";
1012
1013 else if (length > 3*PNG_MAX_PALETTE_LENGTH256 || (length % 3) != 0)
1014 errmsg = "invalid";
1015
1016 /* This drops PLTE in favour of tRNS or bKGD because both of those chunks
1017 * can have an effect on the rendering of the image whereas PLTE only matters
1018 * in the case of an 8-bit display with a decoder which controls the palette.
1019 *
1020 * The alternative here is to ignore the error and store the palette anyway;
1021 * destroying the tRNS will definitely cause problems.
1022 *
1023 * NOTE: the case of PNG_COLOR_TYPE_PALETTE need not be considered because
1024 * the png_handle_ routines for the three 'after PLTE' chunks tRNS, bKGD and
1025 * hIST all check for a preceding PLTE in these cases.
1026 */
1027 else if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE(2 | 1) &&
1028 (png_has_chunk(png_ptr, tRNS)(((png_ptr)->chunks & (0x80000000U >> (31 - (PNG_INDEX_tRNS
)))) != 0)
|| png_has_chunk(png_ptr, bKGD)(((png_ptr)->chunks & (0x80000000U >> (31 - (PNG_INDEX_bKGD
)))) != 0)
))
1029 errmsg = "out of place";
1030
1031 else
1032 {
1033 /* If the palette has 256 or fewer entries but is too large for the bit
1034 * depth we don't issue an error to preserve the behavior of previous
1035 * libpng versions. We silently truncate the unused extra palette entries
1036 * here.
1037 */
1038 const unsigned max_palette_length =
1039 (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE(2 | 1)) ?
1040 1U << png_ptr->bit_depth : PNG_MAX_PALETTE_LENGTH256;
1041
1042 /* The cast is safe because 'length' is less than
1043 * 3*PNG_MAX_PALETTE_LENGTH
1044 */
1045 const unsigned num = (length > 3U*max_palette_length) ?
1046 max_palette_length : (unsigned)length / 3U;
1047
1048 unsigned i, j;
1049 png_byte buf[3*PNG_MAX_PALETTE_LENGTH256];
1050 png_color palette[PNG_MAX_PALETTE_LENGTH256];
1051
1052 /* Read the chunk into the buffer then read to the end of the chunk. */
1053 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, num*3U);
1054 png_crc_finish_critical(png_ptr, length - 3U*num,
1055 /* Handle as ancillary if PLTE is optional: */
1056 png_ptr->color_type != PNG_COLOR_TYPE_PALETTE(2 | 1));
1057
1058 for (i = 0U, j = 0U; i < num; i++)
1059 {
1060 palette[i].red = buf[j++];
1061 palette[i].green = buf[j++];
1062 palette[i].blue = buf[j++];
1063 }
1064
1065 /* A valid PLTE chunk has been read */
1066 png_ptr->mode |= PNG_HAVE_PLTE0x02;
1067
1068 png_set_PLTEMOZ_PNG_set_PLTE(png_ptr, info_ptr, palette, num);
1069 return handled_ok;
1070 }
1071
1072 /* Here on error: errmsg is non NULL. */
1073 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE(2 | 1))
1074 {
1075 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1076 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, errmsg);
1077 }
1078
1079 else /* not critical to this image */
1080 {
1081 png_crc_finish_critical(png_ptr, length, 1/*handle as ancillary*/);
1082 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, errmsg);
1083 }
1084
1085 /* Because PNG_UNUSED(errmsg) does not work if all the uses are compiled out
1086 * (this does happen).
1087 */
1088 return errmsg != NULL((void*)0) ? handled_error : handled_error;
1089}
1090
1091/* On read the IDAT chunk is always handled specially, even if marked for
1092 * unknown handling (this is allowed), so:
1093 */
1094#define png_handle_IDAT((void*)0) NULL((void*)0)
1095
1096static png_handle_result_code
1097png_handle_IENDMOZ_PNG_handle_IEND(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1098{
1099 png_debug(1, "in png_handle_IEND")((void)0);
1100
1101 png_ptr->mode |= (PNG_AFTER_IDAT0x08 | PNG_HAVE_IEND0x10U);
1102
1103 if (length != 0)
1104 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
1105
1106 png_crc_finish_critical(png_ptr, length, 1/*handle as ancillary*/);
1107
1108 return handled_ok;
1109 PNG_UNUSED(info_ptr)(void)info_ptr;
1110}
1111
1112#ifdef PNG_READ_gAMA_SUPPORTED
1113static png_handle_result_code
1114png_handle_gAMAMOZ_PNG_handle_gAMA(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1115{
1116 png_uint_32 ugamma;
1117 png_byte buf[4];
1118
1119 png_debug(1, "in png_handle_gAMA")((void)0);
1120
1121 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 4);
1122
1123 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
1124 return handled_error;
1125
1126 ugamma = png_get_uint_32(buf)(((png_uint_32)(*(buf)) << 24) + ((png_uint_32)(*((buf)
+ 1)) << 16) + ((png_uint_32)(*((buf) + 2)) << 8
) + ((png_uint_32)(*((buf) + 3))))
;
1127
1128 if (ugamma > PNG_UINT_31_MAX((png_uint_32)0x7fffffffL))
1129 {
1130 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
1131 return handled_error;
1132 }
1133
1134 png_set_gAMA_fixedMOZ_PNG_set_gAMA_fixed(png_ptr, info_ptr, (png_fixed_point)/*SAFE*/ugamma);
1135
1136#ifdef PNG_READ_GAMMA_SUPPORTED
1137 /* PNGv3: chunk precedence for gamma is cICP, [iCCP], sRGB, gAMA. gAMA is
1138 * at the end of the chain so simply check for an unset value.
1139 */
1140 if (png_ptr->chunk_gamma == 0)
1141 png_ptr->chunk_gamma = (png_fixed_point)/*SAFE*/ugamma;
1142#endif /*READ_GAMMA*/
1143
1144 return handled_ok;
1145 PNG_UNUSED(length)(void)length;
1146}
1147#else
1148# define png_handle_gAMAMOZ_PNG_handle_gAMA NULL((void*)0)
1149#endif
1150
1151#ifdef PNG_READ_sBIT_SUPPORTED
1152static png_handle_result_code /* PRIVATE */
1153png_handle_sBIT((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1154{
1155 unsigned int truelen, i;
1156 png_byte sample_depth;
1157 png_byte buf[4];
1158
1159 png_debug(1, "in png_handle_sBIT")((void)0);
1160
1161 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE(2 | 1))
1162 {
1163 truelen = 3;
1164 sample_depth = 8;
1165 }
1166
1167 else
1168 {
1169 truelen = png_ptr->channels;
1170 sample_depth = png_ptr->bit_depth;
1171 }
1172
1173 if (length != truelen)
1174 {
1175 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1176 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "bad length");
1177 return handled_error;
1178 }
1179
1180 buf[0] = buf[1] = buf[2] = buf[3] = sample_depth;
1181 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, truelen);
1182
1183 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
1184 return handled_error;
1185
1186 for (i=0; i<truelen; ++i)
1187 {
1188 if (buf[i] == 0 || buf[i] > sample_depth)
1189 {
1190 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
1191 return handled_error;
1192 }
1193 }
1194
1195 if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR2) != 0)
1196 {
1197 png_ptr->sig_bit.red = buf[0];
1198 png_ptr->sig_bit.green = buf[1];
1199 png_ptr->sig_bit.blue = buf[2];
1200 png_ptr->sig_bit.alpha = buf[3];
1201 }
1202
1203 else /* grayscale */
1204 {
1205 png_ptr->sig_bit.gray = buf[0];
1206 png_ptr->sig_bit.red = buf[0];
1207 png_ptr->sig_bit.green = buf[0];
1208 png_ptr->sig_bit.blue = buf[0];
1209 png_ptr->sig_bit.alpha = buf[1];
1210 }
1211
1212 png_set_sBITMOZ_PNG_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
1213 return handled_ok;
1214}
1215#else
1216# define png_handle_sBIT((void*)0) NULL((void*)0)
1217#endif
1218
1219#ifdef PNG_READ_cHRM_SUPPORTED
1220static png_int_32
1221png_get_int_32_checked(png_const_bytep buf, int *error)
1222{
1223 png_uint_32 uval = png_get_uint_32(buf)(((png_uint_32)(*(buf)) << 24) + ((png_uint_32)(*((buf)
+ 1)) << 16) + ((png_uint_32)(*((buf) + 2)) << 8
) + ((png_uint_32)(*((buf) + 3))))
;
1224 if ((uval & 0x80000000) == 0) /* non-negative */
1225 return (png_int_32)uval;
1226
1227 uval = (uval ^ 0xffffffff) + 1; /* 2's complement: -x = ~x+1 */
1228 if ((uval & 0x80000000) == 0) /* no overflow */
1229 return -(png_int_32)uval;
1230
1231 /* This version of png_get_int_32 has a way of returning the error to the
1232 * caller, so:
1233 */
1234 *error = 1;
1235 return 0; /* Safe */
1236}
1237
1238static png_handle_result_code /* PRIVATE */
1239png_handle_cHRMMOZ_PNG_handle_cHRM(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1240{
1241 int error = 0;
1242 png_xy xy;
1243 png_byte buf[32];
1244
1245 png_debug(1, "in png_handle_cHRM")((void)0);
1246
1247 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 32);
1248
1249 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
1250 return handled_error;
1251
1252 xy.whitex = png_get_int_32_checked(buf + 0, &error);
1253 xy.whitey = png_get_int_32_checked(buf + 4, &error);
1254 xy.redx = png_get_int_32_checked(buf + 8, &error);
1255 xy.redy = png_get_int_32_checked(buf + 12, &error);
1256 xy.greenx = png_get_int_32_checked(buf + 16, &error);
1257 xy.greeny = png_get_int_32_checked(buf + 20, &error);
1258 xy.bluex = png_get_int_32_checked(buf + 24, &error);
1259 xy.bluey = png_get_int_32_checked(buf + 28, &error);
1260
1261 if (error)
1262 {
1263 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
1264 return handled_error;
1265 }
1266
1267 /* png_set_cHRM may complain about some of the values but this doesn't matter
1268 * because it was a cHRM and it did have vaguely (if, perhaps, ridiculous)
1269 * values. Ridiculosity will be checked if the values are used later.
1270 */
1271 png_set_cHRM_fixedMOZ_PNG_set_cHRM_fixed(png_ptr, info_ptr, xy.whitex, xy.whitey, xy.redx, xy.redy,
1272 xy.greenx, xy.greeny, xy.bluex, xy.bluey);
1273
1274 /* We only use 'chromaticities' for RGB to gray */
1275# ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1276 /* There is no need to check sRGB here, cICP is NYI and iCCP is not
1277 * supported so just check mDCV.
1278 */
1279 if (!png_has_chunk(png_ptr, mDCV)(((png_ptr)->chunks & (0x80000000U >> (31 - (PNG_INDEX_mDCV
)))) != 0)
)
1280 {
1281 png_ptr->chromaticities = xy;
1282 }
1283# endif /* READ_RGB_TO_GRAY */
1284
1285 return handled_ok;
1286 PNG_UNUSED(length)(void)length;
1287}
1288#else
1289# define png_handle_cHRMMOZ_PNG_handle_cHRM NULL((void*)0)
1290#endif
1291
1292#ifdef PNG_READ_sRGB_SUPPORTED
1293static png_handle_result_code /* PRIVATE */
1294png_handle_sRGBMOZ_PNG_handle_sRGB(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1295{
1296 png_byte intent;
1
'intent' declared without an initial value
1297
1298 png_debug(1, "in png_handle_sRGB")((void)0);
1299
1300 png_crc_readMOZ_PNG_crc_read(png_ptr, &intent, 1);
2
Calling 'MOZ_PNG_crc_read'
6
Returning from 'MOZ_PNG_crc_read'
1301
1302 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
7
Assuming the condition is false
8
Taking false branch
1303 return handled_error;
1304
1305 /* This checks the range of the "rendering intent" because it is specified in
1306 * the PNG spec itself; the "reserved" values will result in the chunk not
1307 * being accepted, just as they do with the various "reserved" values in
1308 * IHDR.
1309 */
1310 if (intent > 3/*PNGv3 spec*/)
9
The left operand of '>' is a garbage value
1311 {
1312 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
1313 return handled_error;
1314 }
1315
1316 png_set_sRGBMOZ_PNG_set_sRGB(png_ptr, info_ptr, intent);
1317 /* NOTE: png_struct::chromaticities is not set here because the RGB to gray
1318 * coefficients are known without a need for the chromaticities.
1319 */
1320
1321#ifdef PNG_READ_GAMMA_SUPPORTED
1322 /* PNGv3: chunk precedence for gamma is cICP, [iCCP], sRGB, gAMA. iCCP is
1323 * not supported by libpng so the only requirement is to check for cICP
1324 * setting the gamma (this is NYI, but this check is safe.)
1325 */
1326 if (!png_has_chunk(png_ptr, cICP)(((png_ptr)->chunks & (0x80000000U >> (31 - (PNG_INDEX_cICP
)))) != 0)
|| png_ptr->chunk_gamma == 0)
1327 png_ptr->chunk_gamma = PNG_GAMMA_sRGB_INVERSE45455;
1328#endif /*READ_GAMMA*/
1329
1330 return handled_ok;
1331 PNG_UNUSED(length)(void)length;
1332}
1333#else
1334# define png_handle_sRGBMOZ_PNG_handle_sRGB NULL((void*)0)
1335#endif /* READ_sRGB */
1336
1337#ifdef PNG_READ_iCCP_SUPPORTED
1338static png_handle_result_code /* PRIVATE */
1339png_handle_iCCPMOZ_PNG_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1340/* Note: this does not properly handle profiles that are > 64K under DOS */
1341{
1342 png_const_charp errmsg = NULL((void*)0); /* error message output, or no error */
1343 int finished = 0; /* crc checked */
1344
1345 png_debug(1, "in png_handle_iCCP")((void)0);
1346
1347 /* PNGv3: allow PNG files with both sRGB and iCCP because the PNG spec only
1348 * ever said that there "should" be only one, not "shall" and the PNGv3
1349 * colour chunk precedence rules give a handling for this case anyway.
1350 */
1351 {
1352 uInt read_length, keyword_length;
1353 char keyword[81];
1354
1355 /* Find the keyword; the keyword plus separator and compression method
1356 * bytes can be at most 81 characters long.
1357 */
1358 read_length = 81; /* maximum */
1359 if (read_length > length)
1360 read_length = (uInt)/*SAFE*/length;
1361
1362 png_crc_readMOZ_PNG_crc_read(png_ptr, (png_bytep)keyword, read_length);
1363 length -= read_length;
1364
1365 if (length < LZ77Min(2U+5U+4U))
1366 {
1367 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1368 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "too short");
1369 return handled_error;
1370 }
1371
1372 keyword_length = 0;
1373 while (keyword_length < 80 && keyword_length < read_length &&
1374 keyword[keyword_length] != 0)
1375 ++keyword_length;
1376
1377 /* TODO: make the keyword checking common */
1378 if (keyword_length >= 1 && keyword_length <= 79)
1379 {
1380 /* We only understand '0' compression - deflate - so if we get a
1381 * different value we can't safely decode the chunk.
1382 */
1383 if (keyword_length+1 < read_length &&
1384 keyword[keyword_length+1] == PNG_COMPRESSION_TYPE_BASE0)
1385 {
1386 read_length -= keyword_length+2;
1387
1388 if (png_inflate_claim(png_ptr, png_iCCP((((0xFFFFFFFFU)&(105)) << (24)) | (((0xFFFFFFFFU)&
(67)) << (16)) | (((0xFFFFFFFFU)&(67)) << (8)
) | (((0xFFFFFFFFU)&(80)) << (0)))
) == Z_OK0)
1389 {
1390 Byte profile_header[132]={0};
1391 Byte local_buffer[PNG_INFLATE_BUF_SIZE1024];
1392 png_alloc_size_t size = (sizeof profile_header);
1393
1394 png_ptr->zstream.next_in = (Bytef*)keyword + (keyword_length+2);
1395 png_ptr->zstream.avail_in = read_length;
1396 (void)png_inflate_read(png_ptr, local_buffer,
1397 (sizeof local_buffer), &length, profile_header, &size,
1398 0/*finish: don't, because the output is too small*/);
1399
1400 if (size == 0)
1401 {
1402 /* We have the ICC profile header; do the basic header checks.
1403 */
1404 png_uint_32 profile_length = png_get_uint_32(profile_header)(((png_uint_32)(*(profile_header)) << 24) + ((png_uint_32
)(*((profile_header) + 1)) << 16) + ((png_uint_32)(*((profile_header
) + 2)) << 8) + ((png_uint_32)(*((profile_header) + 3))
))
;
1405
1406 if (png_icc_check_lengthMOZ_PNG_icc_check_length(png_ptr, keyword, profile_length) !=
1407 0)
1408 {
1409 /* The length is apparently ok, so we can check the 132
1410 * byte header.
1411 */
1412 if (png_icc_check_headerMOZ_PNG_icc_check_header(png_ptr, keyword, profile_length,
1413 profile_header, png_ptr->color_type) != 0)
1414 {
1415 /* Now read the tag table; a variable size buffer is
1416 * needed at this point, allocate one for the whole
1417 * profile. The header check has already validated
1418 * that none of this stuff will overflow.
1419 */
1420 png_uint_32 tag_count =
1421 png_get_uint_32(profile_header + 128)(((png_uint_32)(*(profile_header + 128)) << 24) + ((png_uint_32
)(*((profile_header + 128) + 1)) << 16) + ((png_uint_32
)(*((profile_header + 128) + 2)) << 8) + ((png_uint_32)
(*((profile_header + 128) + 3))))
;
1422 png_bytep profile = png_read_buffer(png_ptr,
1423 profile_length);
1424
1425 if (profile != NULL((void*)0))
1426 {
1427 memcpy(profile, profile_header,
1428 (sizeof profile_header));
1429
1430 size = 12 * tag_count;
1431
1432 (void)png_inflate_read(png_ptr, local_buffer,
1433 (sizeof local_buffer), &length,
1434 profile + (sizeof profile_header), &size, 0);
1435
1436 /* Still expect a buffer error because we expect
1437 * there to be some tag data!
1438 */
1439 if (size == 0)
1440 {
1441 if (png_icc_check_tag_tableMOZ_PNG_icc_check_tags(png_ptr,
1442 keyword, profile_length, profile) != 0)
1443 {
1444 /* The profile has been validated for basic
1445 * security issues, so read the whole thing in.
1446 */
1447 size = profile_length - (sizeof profile_header)
1448 - 12 * tag_count;
1449
1450 (void)png_inflate_read(png_ptr, local_buffer,
1451 (sizeof local_buffer), &length,
1452 profile + (sizeof profile_header) +
1453 12 * tag_count, &size, 1/*finish*/);
1454
1455 if (length > 0 && !(png_ptr->flags &
1456 PNG_FLAG_BENIGN_ERRORS_WARN0x100000U))
1457 errmsg = "extra compressed data";
1458
1459 /* But otherwise allow extra data: */
1460 else if (size == 0)
1461 {
1462 if (length > 0)
1463 {
1464 /* This can be handled completely, so
1465 * keep going.
1466 */
1467 png_chunk_warningMOZ_PNG_chunk_warn(png_ptr,
1468 "extra compressed data");
1469 }
1470
1471 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1472 finished = 1;
1473
1474 /* Steal the profile for info_ptr. */
1475 if (info_ptr != NULL((void*)0))
1476 {
1477 png_free_dataMOZ_PNG_free_data(png_ptr, info_ptr,
1478 PNG_FREE_ICCP0x0010U, 0);
1479
1480 info_ptr->iccp_name = png_voidcast(char*,(MOZ_PNG_malloc_base(png_ptr, keyword_length+1))
1481 png_malloc_base(png_ptr,(MOZ_PNG_malloc_base(png_ptr, keyword_length+1))
1482 keyword_length+1))(MOZ_PNG_malloc_base(png_ptr, keyword_length+1));
1483 if (info_ptr->iccp_name != NULL((void*)0))
1484 {
1485 memcpy(info_ptr->iccp_name, keyword,
1486 keyword_length+1);
1487 info_ptr->iccp_proflen =
1488 profile_length;
1489 info_ptr->iccp_profile = profile;
1490 png_ptr->read_buffer = NULL((void*)0); /*steal*/
1491 info_ptr->free_me |= PNG_FREE_ICCP0x0010U;
1492 info_ptr->valid |= PNG_INFO_iCCP0x1000U;
1493 }
1494
1495 else
1496 errmsg = "out of memory";
1497 }
1498
1499 /* else the profile remains in the read
1500 * buffer which gets reused for subsequent
1501 * chunks.
1502 */
1503
1504 if (errmsg == NULL((void*)0))
1505 {
1506 png_inflate_detach_buffers(png_ptr);
1507 png_ptr->zowner = 0;
1508 return handled_ok;
1509 }
1510 }
1511 if (errmsg == NULL((void*)0))
1512 errmsg = png_ptr->zstream.msg;
1513 }
1514 /* else png_icc_check_tag_table output an error */
1515 }
1516 else /* profile truncated */
1517 errmsg = png_ptr->zstream.msg;
1518 }
1519
1520 else
1521 errmsg = "out of memory";
1522 }
1523
1524 /* else png_icc_check_header output an error */
1525 }
1526
1527 /* else png_icc_check_length output an error */
1528 }
1529
1530 else /* profile truncated */
1531 errmsg = png_ptr->zstream.msg;
1532
1533 /* Release the claimed stream. */
1534 png_inflate_detach_buffers(png_ptr);
1535 png_ptr->zowner = 0;
1536 }
1537
1538 else /* png_inflate_claim failed */
1539 errmsg = png_ptr->zstream.msg;
1540 }
1541
1542 else
1543 errmsg = "bad compression method"; /* or missing */
1544 }
1545
1546 else
1547 errmsg = "bad keyword";
1548 }
1549
1550 /* Failure: the reason is in 'errmsg' */
1551 if (finished == 0)
1552 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1553
1554 if (errmsg != NULL((void*)0)) /* else already output */
1555 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, errmsg);
1556
1557 return handled_error;
1558}
1559#else
1560# define png_handle_iCCPMOZ_PNG_handle_iCCP NULL((void*)0)
1561#endif /* READ_iCCP */
1562
1563#ifdef PNG_READ_sPLT_SUPPORTED
1564static png_handle_result_code /* PRIVATE */
1565png_handle_sPLT((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1566/* Note: this does not properly handle chunks that are > 64K under DOS */
1567{
1568 png_bytep buffer;
1569 png_bytep entry_start;
1570 png_sPLT_t new_palette;
1571 png_sPLT_entryp pp;
1572 png_uint_32 data_length;
1573 int entry_size, i;
1574 png_uint_32 skip = 0;
1575 png_uint_32 dl;
1576 size_t max_dl;
1577
1578 png_debug(1, "in png_handle_sPLT")((void)0);
1579
1580#ifdef PNG_USER_LIMITS_SUPPORTED
1581 if (png_ptr->user_chunk_cache_max != 0)
1582 {
1583 if (png_ptr->user_chunk_cache_max == 1)
1584 {
1585 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1586 return handled_error;
1587 }
1588
1589 if (--png_ptr->user_chunk_cache_max == 1)
1590 {
1591 png_warningMOZ_PNG_warning(png_ptr, "No space in chunk cache for sPLT");
1592 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1593 return handled_error;
1594 }
1595 }
1596#endif
1597
1598 buffer = png_read_buffer(png_ptr, length+1);
1599 if (buffer == NULL((void*)0))
1600 {
1601 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1602 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of memory");
1603 return handled_error;
1604 }
1605
1606
1607 /* WARNING: this may break if size_t is less than 32 bits; it is assumed
1608 * that the PNG_MAX_MALLOC_64K test is enabled in this case, but this is a
1609 * potential breakage point if the types in pngconf.h aren't exactly right.
1610 */
1611 png_crc_readMOZ_PNG_crc_read(png_ptr, buffer, length);
1612
1613 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, skip) != 0)
1614 return handled_error;
1615
1616 buffer[length] = 0;
1617
1618 for (entry_start = buffer; *entry_start; entry_start++)
1619 /* Empty loop to find end of name */ ;
1620
1621 ++entry_start;
1622
1623 /* A sample depth should follow the separator, and we should be on it */
1624 if (length < 2U || entry_start > buffer + (length - 2U))
1625 {
1626 png_warningMOZ_PNG_warning(png_ptr, "malformed sPLT chunk");
1627 return handled_error;
1628 }
1629
1630 new_palette.depth = *entry_start++;
1631 entry_size = (new_palette.depth == 8 ? 6 : 10);
1632 /* This must fit in a png_uint_32 because it is derived from the original
1633 * chunk data length.
1634 */
1635 data_length = length - (png_uint_32)(entry_start - buffer);
1636
1637 /* Integrity-check the data length */
1638 if ((data_length % (unsigned int)entry_size) != 0)
1639 {
1640 png_warningMOZ_PNG_warning(png_ptr, "sPLT chunk has bad length");
1641 return handled_error;
1642 }
1643
1644 dl = (png_uint_32)(data_length / (unsigned int)entry_size);
1645 max_dl = PNG_SIZE_MAX((size_t)(-1)) / (sizeof (png_sPLT_entry));
1646
1647 if (dl > max_dl)
1648 {
1649 png_warningMOZ_PNG_warning(png_ptr, "sPLT chunk too long");
1650 return handled_error;
1651 }
1652
1653 new_palette.nentries = (png_int_32)(data_length / (unsigned int)entry_size);
1654
1655 new_palette.entries = (png_sPLT_entryp)png_malloc_warnMOZ_PNG_malloc_warn(png_ptr,
1656 (png_alloc_size_t) new_palette.nentries * (sizeof (png_sPLT_entry)));
1657
1658 if (new_palette.entries == NULL((void*)0))
1659 {
1660 png_warningMOZ_PNG_warning(png_ptr, "sPLT chunk requires too much memory");
1661 return handled_error;
1662 }
1663
1664 for (i = 0; i < new_palette.nentries; i++)
1665 {
1666 pp = new_palette.entries + i;
1667
1668 if (new_palette.depth == 8)
1669 {
1670 pp->red = *entry_start++;
1671 pp->green = *entry_start++;
1672 pp->blue = *entry_start++;
1673 pp->alpha = *entry_start++;
1674 }
1675
1676 else
1677 {
1678 pp->red = png_get_uint_16(entry_start)((png_uint_16) (((unsigned int)(*(entry_start)) << 8) +
((unsigned int)(*((entry_start) + 1)))))
; entry_start += 2;
1679 pp->green = png_get_uint_16(entry_start)((png_uint_16) (((unsigned int)(*(entry_start)) << 8) +
((unsigned int)(*((entry_start) + 1)))))
; entry_start += 2;
1680 pp->blue = png_get_uint_16(entry_start)((png_uint_16) (((unsigned int)(*(entry_start)) << 8) +
((unsigned int)(*((entry_start) + 1)))))
; entry_start += 2;
1681 pp->alpha = png_get_uint_16(entry_start)((png_uint_16) (((unsigned int)(*(entry_start)) << 8) +
((unsigned int)(*((entry_start) + 1)))))
; entry_start += 2;
1682 }
1683
1684 pp->frequency = png_get_uint_16(entry_start)((png_uint_16) (((unsigned int)(*(entry_start)) << 8) +
((unsigned int)(*((entry_start) + 1)))))
; entry_start += 2;
1685 }
1686
1687 /* Discard all chunk data except the name and stash that */
1688 new_palette.name = (png_charp)buffer;
1689
1690 png_set_sPLTMOZ_PNG_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
1691
1692 png_freeMOZ_PNG_free(png_ptr, new_palette.entries);
1693 return handled_ok;
1694}
1695#else
1696# define png_handle_sPLT((void*)0) NULL((void*)0)
1697#endif /* READ_sPLT */
1698
1699#ifdef PNG_READ_tRNS_SUPPORTED
1700static png_handle_result_code /* PRIVATE */
1701png_handle_tRNSMOZ_PNG_handle_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1702{
1703 png_byte readbuf[PNG_MAX_PALETTE_LENGTH256];
1704
1705 png_debug(1, "in png_handle_tRNS")((void)0);
1706
1707 if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY0)
1708 {
1709 png_byte buf[2];
1710
1711 if (length != 2)
1712 {
1713 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1714 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
1715 return handled_error;
1716 }
1717
1718 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 2);
1719 png_ptr->num_trans = 1;
1720 png_ptr->trans_color.gray = png_get_uint_16(buf)((png_uint_16) (((unsigned int)(*(buf)) << 8) + ((unsigned
int)(*((buf) + 1)))))
;
1721 }
1722
1723 else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB(2))
1724 {
1725 png_byte buf[6];
1726
1727 if (length != 6)
1728 {
1729 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1730 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
1731 return handled_error;
1732 }
1733
1734 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, length);
1735 png_ptr->num_trans = 1;
1736 png_ptr->trans_color.red = png_get_uint_16(buf)((png_uint_16) (((unsigned int)(*(buf)) << 8) + ((unsigned
int)(*((buf) + 1)))))
;
1737 png_ptr->trans_color.green = png_get_uint_16(buf + 2)((png_uint_16) (((unsigned int)(*(buf + 2)) << 8) + ((unsigned
int)(*((buf + 2) + 1)))))
;
1738 png_ptr->trans_color.blue = png_get_uint_16(buf + 4)((png_uint_16) (((unsigned int)(*(buf + 4)) << 8) + ((unsigned
int)(*((buf + 4) + 1)))))
;
1739 }
1740
1741 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE(2 | 1))
1742 {
1743 if ((png_ptr->mode & PNG_HAVE_PLTE0x02) == 0)
1744 {
1745 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1746 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of place");
1747 return handled_error;
1748 }
1749
1750 if (length > (unsigned int) png_ptr->num_palette ||
1751 length > (unsigned int) PNG_MAX_PALETTE_LENGTH256 ||
1752 length == 0)
1753 {
1754 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1755 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
1756 return handled_error;
1757 }
1758
1759 png_crc_readMOZ_PNG_crc_read(png_ptr, readbuf, length);
1760 png_ptr->num_trans = (png_uint_16)length;
1761 }
1762
1763 else
1764 {
1765 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1766 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid with alpha channel");
1767 return handled_error;
1768 }
1769
1770 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
1771 {
1772 png_ptr->num_trans = 0;
1773 return handled_error;
1774 }
1775
1776 png_set_tRNSMOZ_PNG_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
1777 &(png_ptr->trans_color));
1778 return handled_ok;
1779}
1780#else
1781# define png_handle_tRNSMOZ_PNG_handle_tRNS NULL((void*)0)
1782#endif
1783
1784#ifdef PNG_READ_bKGD_SUPPORTED
1785static png_handle_result_code /* PRIVATE */
1786png_handle_bKGD((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1787{
1788 unsigned int truelen;
1789 png_byte buf[6];
1790 png_color_16 background;
1791
1792 png_debug(1, "in png_handle_bKGD")((void)0);
1793
1794 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE(2 | 1))
1795 {
1796 if ((png_ptr->mode & PNG_HAVE_PLTE0x02) == 0)
1797 {
1798 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1799 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of place");
1800 return handled_error;
1801 }
1802
1803 truelen = 1;
1804 }
1805
1806 else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR2) != 0)
1807 truelen = 6;
1808
1809 else
1810 truelen = 2;
1811
1812 if (length != truelen)
1813 {
1814 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1815 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
1816 return handled_error;
1817 }
1818
1819 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, truelen);
1820
1821 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
1822 return handled_error;
1823
1824 /* We convert the index value into RGB components so that we can allow
1825 * arbitrary RGB values for background when we have transparency, and
1826 * so it is easy to determine the RGB values of the background color
1827 * from the info_ptr struct.
1828 */
1829 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE(2 | 1))
1830 {
1831 background.index = buf[0];
1832
1833 if (info_ptr != NULL((void*)0) && info_ptr->num_palette != 0)
1834 {
1835 if (buf[0] >= info_ptr->num_palette)
1836 {
1837 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid index");
1838 return handled_error;
1839 }
1840
1841 background.red = (png_uint_16)png_ptr->palette[buf[0]].red;
1842 background.green = (png_uint_16)png_ptr->palette[buf[0]].green;
1843 background.blue = (png_uint_16)png_ptr->palette[buf[0]].blue;
1844 }
1845
1846 else
1847 background.red = background.green = background.blue = 0;
1848
1849 background.gray = 0;
1850 }
1851
1852 else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR2) == 0) /* GRAY */
1853 {
1854 if (png_ptr->bit_depth <= 8)
1855 {
1856 if (buf[0] != 0 || buf[1] >= (unsigned int)(1 << png_ptr->bit_depth))
1857 {
1858 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid gray level");
1859 return handled_error;
1860 }
1861 }
1862
1863 background.index = 0;
1864 background.red =
1865 background.green =
1866 background.blue =
1867 background.gray = png_get_uint_16(buf)((png_uint_16) (((unsigned int)(*(buf)) << 8) + ((unsigned
int)(*((buf) + 1)))))
;
1868 }
1869
1870 else
1871 {
1872 if (png_ptr->bit_depth <= 8)
1873 {
1874 if (buf[0] != 0 || buf[2] != 0 || buf[4] != 0)
1875 {
1876 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid color");
1877 return handled_error;
1878 }
1879 }
1880
1881 background.index = 0;
1882 background.red = png_get_uint_16(buf)((png_uint_16) (((unsigned int)(*(buf)) << 8) + ((unsigned
int)(*((buf) + 1)))))
;
1883 background.green = png_get_uint_16(buf + 2)((png_uint_16) (((unsigned int)(*(buf + 2)) << 8) + ((unsigned
int)(*((buf + 2) + 1)))))
;
1884 background.blue = png_get_uint_16(buf + 4)((png_uint_16) (((unsigned int)(*(buf + 4)) << 8) + ((unsigned
int)(*((buf + 4) + 1)))))
;
1885 background.gray = 0;
1886 }
1887
1888 png_set_bKGDMOZ_PNG_set_bKGD(png_ptr, info_ptr, &background);
1889 return handled_ok;
1890}
1891#else
1892# define png_handle_bKGD((void*)0) NULL((void*)0)
1893#endif
1894
1895#ifdef PNG_READ_cICP_SUPPORTED
1896static png_handle_result_code /* PRIVATE */
1897png_handle_cICP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1898{
1899 png_byte buf[4];
1900
1901 png_debug(1, "in png_handle_cICP")((void)0);
1902
1903 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 4);
1904
1905 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
1906 return handled_error;
1907
1908 png_set_cICP(png_ptr, info_ptr, buf[0], buf[1], buf[2], buf[3]);
1909
1910 /* We only use 'chromaticities' for RGB to gray */
1911# ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1912 if (!png_has_chunk(png_ptr, mDCV)(((png_ptr)->chunks & (0x80000000U >> (31 - (PNG_INDEX_mDCV
)))) != 0)
)
1913 {
1914 /* TODO: png_ptr->chromaticities = chromaticities; */
1915 }
1916# endif /* READ_RGB_TO_GRAY */
1917
1918#ifdef PNG_READ_GAMMA_SUPPORTED
1919 /* PNGv3: chunk precedence for gamma is cICP, [iCCP], sRGB, gAMA. cICP is
1920 * at the head so simply set the gamma if it can be determined. If not
1921 * chunk_gamma remains unchanged; sRGB and gAMA handling check it for
1922 * being zero.
1923 */
1924 /* TODO: set png_struct::chunk_gamma when possible */
1925#endif /*READ_GAMMA*/
1926
1927 return handled_ok;
1928 PNG_UNUSED(length)(void)length;
1929}
1930#else
1931# define png_handle_cICP NULL((void*)0)
1932#endif
1933
1934#ifdef PNG_READ_cLLI_SUPPORTED
1935static png_handle_result_code /* PRIVATE */
1936png_handle_cLLI((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1937{
1938 png_byte buf[8];
1939
1940 png_debug(1, "in png_handle_cLLI")((void)0);
1941
1942 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 8);
1943
1944 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
1945 return handled_error;
1946
1947 /* The error checking happens here, this puts it in just one place: */
1948 png_set_cLLI_fixed(png_ptr, info_ptr, png_get_uint_32(buf)(((png_uint_32)(*(buf)) << 24) + ((png_uint_32)(*((buf)
+ 1)) << 16) + ((png_uint_32)(*((buf) + 2)) << 8
) + ((png_uint_32)(*((buf) + 3))))
,
1949 png_get_uint_32(buf+4)(((png_uint_32)(*(buf+4)) << 24) + ((png_uint_32)(*((buf
+4) + 1)) << 16) + ((png_uint_32)(*((buf+4) + 2)) <<
8) + ((png_uint_32)(*((buf+4) + 3))))
);
1950 return handled_ok;
1951 PNG_UNUSED(length)(void)length;
1952}
1953#else
1954# define png_handle_cLLI((void*)0) NULL((void*)0)
1955#endif
1956
1957#ifdef PNG_READ_mDCV_SUPPORTED
1958static png_handle_result_code /* PRIVATE */
1959png_handle_mDCV((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1960{
1961 png_xy chromaticities;
1962 png_byte buf[24];
1963
1964 png_debug(1, "in png_handle_mDCV")((void)0);
1965
1966 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 24);
1967
1968 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
1969 return handled_error;
1970
1971 /* The error checking happens here, this puts it in just one place. The
1972 * odd /50000 scaling factor makes it more difficult but the (x.y) values are
1973 * only two bytes so a <<1 is safe.
1974 *
1975 * WARNING: the PNG specification defines the cHRM chunk to **start** with
1976 * the white point (x,y). The W3C PNG v3 specification puts the white point
1977 * **after* R,G,B. The x,y values in mDCV are also scaled by 50,000 and
1978 * stored in just two bytes, whereas those in cHRM are scaled by 100,000 and
1979 * stored in four bytes. This is very, very confusing. These APIs remove
1980 * the confusion by copying the existing, well established, API.
1981 */
1982 chromaticities.redx = png_get_uint_16(buf+ 0U)((png_uint_16) (((unsigned int)(*(buf+ 0U)) << 8) + ((unsigned
int)(*((buf+ 0U) + 1)))))
<< 1; /* red x */
1983 chromaticities.redy = png_get_uint_16(buf+ 2U)((png_uint_16) (((unsigned int)(*(buf+ 2U)) << 8) + ((unsigned
int)(*((buf+ 2U) + 1)))))
<< 1; /* red y */
1984 chromaticities.greenx = png_get_uint_16(buf+ 4U)((png_uint_16) (((unsigned int)(*(buf+ 4U)) << 8) + ((unsigned
int)(*((buf+ 4U) + 1)))))
<< 1; /* green x */
1985 chromaticities.greeny = png_get_uint_16(buf+ 6U)((png_uint_16) (((unsigned int)(*(buf+ 6U)) << 8) + ((unsigned
int)(*((buf+ 6U) + 1)))))
<< 1; /* green y */
1986 chromaticities.bluex = png_get_uint_16(buf+ 8U)((png_uint_16) (((unsigned int)(*(buf+ 8U)) << 8) + ((unsigned
int)(*((buf+ 8U) + 1)))))
<< 1; /* blue x */
1987 chromaticities.bluey = png_get_uint_16(buf+10U)((png_uint_16) (((unsigned int)(*(buf+10U)) << 8) + ((unsigned
int)(*((buf+10U) + 1)))))
<< 1; /* blue y */
1988 chromaticities.whitex = png_get_uint_16(buf+12U)((png_uint_16) (((unsigned int)(*(buf+12U)) << 8) + ((unsigned
int)(*((buf+12U) + 1)))))
<< 1; /* white x */
1989 chromaticities.whitey = png_get_uint_16(buf+14U)((png_uint_16) (((unsigned int)(*(buf+14U)) << 8) + ((unsigned
int)(*((buf+14U) + 1)))))
<< 1; /* white y */
1990
1991 png_set_mDCV_fixed(png_ptr, info_ptr,
1992 chromaticities.whitex, chromaticities.whitey,
1993 chromaticities.redx, chromaticities.redy,
1994 chromaticities.greenx, chromaticities.greeny,
1995 chromaticities.bluex, chromaticities.bluey,
1996 png_get_uint_32(buf+16U)(((png_uint_32)(*(buf+16U)) << 24) + ((png_uint_32)(*((
buf+16U) + 1)) << 16) + ((png_uint_32)(*((buf+16U) + 2)
) << 8) + ((png_uint_32)(*((buf+16U) + 3))))
, /* peak luminance */
1997 png_get_uint_32(buf+20U)(((png_uint_32)(*(buf+20U)) << 24) + ((png_uint_32)(*((
buf+20U) + 1)) << 16) + ((png_uint_32)(*((buf+20U) + 2)
) << 8) + ((png_uint_32)(*((buf+20U) + 3))))
);/* minimum perceivable luminance */
1998
1999 /* We only use 'chromaticities' for RGB to gray */
2000# ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
2001 png_ptr->chromaticities = chromaticities;
2002# endif /* READ_RGB_TO_GRAY */
2003
2004 return handled_ok;
2005 PNG_UNUSED(length)(void)length;
2006}
2007#else
2008# define png_handle_mDCV((void*)0) NULL((void*)0)
2009#endif
2010
2011#ifdef PNG_READ_eXIf_SUPPORTED
2012static png_handle_result_code /* PRIVATE */
2013png_handle_eXIf(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2014{
2015 png_bytep buffer = NULL((void*)0);
2016
2017 png_debug(1, "in png_handle_eXIf")((void)0);
2018
2019 buffer = png_read_buffer(png_ptr, length);
2020
2021 if (buffer == NULL((void*)0))
2022 {
2023 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2024 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of memory");
2025 return handled_error;
2026 }
2027
2028 png_crc_readMOZ_PNG_crc_read(png_ptr, buffer, length);
2029
2030 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
2031 return handled_error;
2032
2033 /* PNGv3: the code used to check the byte order mark at the start for MM or
2034 * II, however PNGv3 states that the first 4 bytes should be checked.
2035 * The caller ensures that there are four bytes available.
2036 */
2037 {
2038 png_uint_32 header = png_get_uint_32(buffer)(((png_uint_32)(*(buffer)) << 24) + ((png_uint_32)(*((buffer
) + 1)) << 16) + ((png_uint_32)(*((buffer) + 2)) <<
8) + ((png_uint_32)(*((buffer) + 3))))
;
2039
2040 /* These numbers are copied from the PNGv3 spec: */
2041 if (header != 0x49492A00 && header != 0x4D4D002A)
2042 {
2043 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
2044 return handled_error;
2045 }
2046 }
2047
2048 png_set_eXIf_1(png_ptr, info_ptr, length, buffer);
2049 return handled_ok;
2050}
2051#else
2052# define png_handle_eXIf NULL((void*)0)
2053#endif
2054
2055#ifdef PNG_READ_hIST_SUPPORTED
2056static png_handle_result_code /* PRIVATE */
2057png_handle_hIST((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2058{
2059 unsigned int num, i;
2060 png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH256];
2061
2062 png_debug(1, "in png_handle_hIST")((void)0);
2063
2064 /* This cast is safe because the chunk definition limits the length to a
2065 * maximum of 1024 bytes.
2066 *
2067 * TODO: maybe use png_uint_32 anyway, not unsigned int, to reduce the
2068 * casts.
2069 */
2070 num = (unsigned int)length / 2 ;
2071
2072 if (length != num * 2 ||
2073 num != (unsigned int)png_ptr->num_palette ||
2074 num > (unsigned int)PNG_MAX_PALETTE_LENGTH256)
2075 {
2076 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2077 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
2078 return handled_error;
2079 }
2080
2081 for (i = 0; i < num; i++)
2082 {
2083 png_byte buf[2];
2084
2085 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 2);
2086 readbuf[i] = png_get_uint_16(buf)((png_uint_16) (((unsigned int)(*(buf)) << 8) + ((unsigned
int)(*((buf) + 1)))))
;
2087 }
2088
2089 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
2090 return handled_error;
2091
2092 png_set_hISTMOZ_PNG_set_hIST(png_ptr, info_ptr, readbuf);
2093 return handled_ok;
2094}
2095#else
2096# define png_handle_hIST((void*)0) NULL((void*)0)
2097#endif
2098
2099#ifdef PNG_READ_pHYs_SUPPORTED
2100static png_handle_result_code /* PRIVATE */
2101png_handle_pHYs((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2102{
2103 png_byte buf[9];
2104 png_uint_32 res_x, res_y;
2105 int unit_type;
2106
2107 png_debug(1, "in png_handle_pHYs")((void)0);
2108
2109 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 9);
2110
2111 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
2112 return handled_error;
2113
2114 res_x = png_get_uint_32(buf)(((png_uint_32)(*(buf)) << 24) + ((png_uint_32)(*((buf)
+ 1)) << 16) + ((png_uint_32)(*((buf) + 2)) << 8
) + ((png_uint_32)(*((buf) + 3))))
;
2115 res_y = png_get_uint_32(buf + 4)(((png_uint_32)(*(buf + 4)) << 24) + ((png_uint_32)(*((
buf + 4) + 1)) << 16) + ((png_uint_32)(*((buf + 4) + 2)
) << 8) + ((png_uint_32)(*((buf + 4) + 3))))
;
2116 unit_type = buf[8];
2117 png_set_pHYsMOZ_PNG_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
2118 return handled_ok;
2119 PNG_UNUSED(length)(void)length;
2120}
2121#else
2122# define png_handle_pHYs((void*)0) NULL((void*)0)
2123#endif
2124
2125#ifdef PNG_READ_oFFs_SUPPORTED
2126static png_handle_result_code /* PRIVATE */
2127png_handle_oFFs((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2128{
2129 png_byte buf[9];
2130 png_int_32 offset_x, offset_y;
2131 int unit_type;
2132
2133 png_debug(1, "in png_handle_oFFs")((void)0);
2134
2135 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 9);
2136
2137 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
2138 return handled_error;
2139
2140 offset_x = png_get_int_32(buf)((png_int_32)((*(buf) & 0x80) ? -((png_int_32)((((((png_uint_32
)(*(buf)) << 24) + ((png_uint_32)(*((buf) + 1)) <<
16) + ((png_uint_32)(*((buf) + 2)) << 8) + ((png_uint_32
)(*((buf) + 3))))^0xffffffffU)+1U)&0x7fffffffU)) : (png_int_32
)(((png_uint_32)(*(buf)) << 24) + ((png_uint_32)(*((buf
) + 1)) << 16) + ((png_uint_32)(*((buf) + 2)) << 8
) + ((png_uint_32)(*((buf) + 3))))))
;
2141 offset_y = png_get_int_32(buf + 4)((png_int_32)((*(buf + 4) & 0x80) ? -((png_int_32)((((((png_uint_32
)(*(buf + 4)) << 24) + ((png_uint_32)(*((buf + 4) + 1))
<< 16) + ((png_uint_32)(*((buf + 4) + 2)) << 8) +
((png_uint_32)(*((buf + 4) + 3))))^0xffffffffU)+1U)&0x7fffffffU
)) : (png_int_32)(((png_uint_32)(*(buf + 4)) << 24) + (
(png_uint_32)(*((buf + 4) + 1)) << 16) + ((png_uint_32)
(*((buf + 4) + 2)) << 8) + ((png_uint_32)(*((buf + 4) +
3))))))
;
2142 unit_type = buf[8];
2143 png_set_oFFsMOZ_PNG_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
2144 return handled_ok;
2145 PNG_UNUSED(length)(void)length;
2146}
2147#else
2148# define png_handle_oFFs((void*)0) NULL((void*)0)
2149#endif
2150
2151#ifdef PNG_READ_pCAL_SUPPORTED
2152/* Read the pCAL chunk (described in the PNG Extensions document) */
2153static png_handle_result_code /* PRIVATE */
2154png_handle_pCAL((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2155{
2156 png_bytep buffer;
2157 png_bytep buf;
2158 png_bytep endptr;
2159 png_int_32 X0, X1;
2160 png_byte type;
2161 png_byte nparams;
2162 png_byte *units;
2163 png_charpp params;
2164 int i;
2165
2166 png_debug(1, "in png_handle_pCAL")((void)0);
2167 png_debug1(2, "Allocating and reading pCAL chunk data (%u bytes)",((void)0)
2168 length + 1)((void)0);
2169
2170 buffer = png_read_buffer(png_ptr, length+1);
2171
2172 if (buffer == NULL((void*)0))
2173 {
2174 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2175 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of memory");
2176 return handled_error;
2177 }
2178
2179 png_crc_readMOZ_PNG_crc_read(png_ptr, buffer, length);
2180
2181 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
2182 return handled_error;
2183
2184 buffer[length] = 0; /* Null terminate the last string */
2185
2186 png_debug(3, "Finding end of pCAL purpose string")((void)0);
2187 for (buf = buffer; *buf; buf++)
2188 /* Empty loop */ ;
2189
2190 endptr = buffer + length;
2191
2192 /* We need to have at least 12 bytes after the purpose string
2193 * in order to get the parameter information.
2194 */
2195 if (endptr - buf <= 12)
2196 {
2197 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
2198 return handled_error;
2199 }
2200
2201 png_debug(3, "Reading pCAL X0, X1, type, nparams, and units")((void)0);
2202 X0 = png_get_int_32((png_bytep)buf+1)((png_int_32)((*((png_bytep)buf+1) & 0x80) ? -((png_int_32
)((((((png_uint_32)(*((png_bytep)buf+1)) << 24) + ((png_uint_32
)(*(((png_bytep)buf+1) + 1)) << 16) + ((png_uint_32)(*(
((png_bytep)buf+1) + 2)) << 8) + ((png_uint_32)(*(((png_bytep
)buf+1) + 3))))^0xffffffffU)+1U)&0x7fffffffU)) : (png_int_32
)(((png_uint_32)(*((png_bytep)buf+1)) << 24) + ((png_uint_32
)(*(((png_bytep)buf+1) + 1)) << 16) + ((png_uint_32)(*(
((png_bytep)buf+1) + 2)) << 8) + ((png_uint_32)(*(((png_bytep
)buf+1) + 3))))))
;
2203 X1 = png_get_int_32((png_bytep)buf+5)((png_int_32)((*((png_bytep)buf+5) & 0x80) ? -((png_int_32
)((((((png_uint_32)(*((png_bytep)buf+5)) << 24) + ((png_uint_32
)(*(((png_bytep)buf+5) + 1)) << 16) + ((png_uint_32)(*(
((png_bytep)buf+5) + 2)) << 8) + ((png_uint_32)(*(((png_bytep
)buf+5) + 3))))^0xffffffffU)+1U)&0x7fffffffU)) : (png_int_32
)(((png_uint_32)(*((png_bytep)buf+5)) << 24) + ((png_uint_32
)(*(((png_bytep)buf+5) + 1)) << 16) + ((png_uint_32)(*(
((png_bytep)buf+5) + 2)) << 8) + ((png_uint_32)(*(((png_bytep
)buf+5) + 3))))))
;
2204 type = buf[9];
2205 nparams = buf[10];
2206 units = buf + 11;
2207
2208 png_debug(3, "Checking pCAL equation type and number of parameters")((void)0);
2209 /* Check that we have the right number of parameters for known
2210 * equation types.
2211 */
2212 if ((type == PNG_EQUATION_LINEAR0 && nparams != 2) ||
2213 (type == PNG_EQUATION_BASE_E1 && nparams != 3) ||
2214 (type == PNG_EQUATION_ARBITRARY2 && nparams != 3) ||
2215 (type == PNG_EQUATION_HYPERBOLIC3 && nparams != 4))
2216 {
2217 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid parameter count");
2218 return handled_error;
2219 }
2220
2221 else if (type >= PNG_EQUATION_LAST4)
2222 {
2223 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "unrecognized equation type");
2224 }
2225
2226 for (buf = units; *buf; buf++)
2227 /* Empty loop to move past the units string. */ ;
2228
2229 png_debug(3, "Allocating pCAL parameters array")((void)0);
2230
2231 params = png_voidcast(png_charpp, png_malloc_warn(png_ptr,(MOZ_PNG_malloc_warn(png_ptr, nparams * (sizeof (png_charp)))
)
2232 nparams * (sizeof (png_charp))))(MOZ_PNG_malloc_warn(png_ptr, nparams * (sizeof (png_charp)))
)
;
2233
2234 if (params == NULL((void*)0))
2235 {
2236 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of memory");
2237 return handled_error;
2238 }
2239
2240 /* Get pointers to the start of each parameter string. */
2241 for (i = 0; i < nparams; i++)
2242 {
2243 buf++; /* Skip the null string terminator from previous parameter. */
2244
2245 png_debug1(3, "Reading pCAL parameter %d", i)((void)0);
2246
2247 for (params[i] = (png_charp)buf; buf <= endptr && *buf != 0; buf++)
2248 /* Empty loop to move past each parameter string */ ;
2249
2250 /* Make sure we haven't run out of data yet */
2251 if (buf > endptr)
2252 {
2253 png_freeMOZ_PNG_free(png_ptr, params);
2254 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid data");
2255 return handled_error;
2256 }
2257 }
2258
2259 png_set_pCALMOZ_PNG_set_pCAL(png_ptr, info_ptr, (png_charp)buffer, X0, X1, type, nparams,
2260 (png_charp)units, params);
2261
2262 /* TODO: BUG: png_set_pCAL calls png_chunk_report which, in this case, calls
2263 * png_benign_error and that can error out.
2264 *
2265 * png_read_buffer needs to be allocated with space for both nparams and the
2266 * parameter strings. Not hard to do.
2267 */
2268 png_freeMOZ_PNG_free(png_ptr, params);
2269 return handled_ok;
2270}
2271#else
2272# define png_handle_pCAL((void*)0) NULL((void*)0)
2273#endif
2274
2275#ifdef PNG_READ_sCAL_SUPPORTED
2276/* Read the sCAL chunk */
2277static png_handle_result_code /* PRIVATE */
2278png_handle_sCAL((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2279{
2280 png_bytep buffer;
2281 size_t i;
2282 int state;
2283
2284 png_debug(1, "in png_handle_sCAL")((void)0);
2285 png_debug1(2, "Allocating and reading sCAL chunk data (%u bytes)",((void)0)
2286 length + 1)((void)0);
2287
2288 buffer = png_read_buffer(png_ptr, length+1);
2289
2290 if (buffer == NULL((void*)0))
2291 {
2292 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2293 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of memory");
2294 return handled_error;
2295 }
2296
2297 png_crc_readMOZ_PNG_crc_read(png_ptr, buffer, length);
2298 buffer[length] = 0; /* Null terminate the last string */
2299
2300 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
2301 return handled_error;
2302
2303 /* Validate the unit. */
2304 if (buffer[0] != 1 && buffer[0] != 2)
2305 {
2306 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid unit");
2307 return handled_error;
2308 }
2309
2310 /* Validate the ASCII numbers, need two ASCII numbers separated by
2311 * a '\0' and they need to fit exactly in the chunk data.
2312 */
2313 i = 1;
2314 state = 0;
2315
2316 if (png_check_fp_numberMOZ_PNG_check_fp_number((png_const_charp)buffer, length, &state, &i) == 0 ||
2317 i >= length || buffer[i++] != 0)
2318 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "bad width format");
2319
2320 else if (PNG_FP_IS_POSITIVE(state) == 0)
2321 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "non-positive width");
2322
2323 else
2324 {
2325 size_t heighti = i;
2326
2327 state = 0;
2328 if (png_check_fp_numberMOZ_PNG_check_fp_number((png_const_charp)buffer, length,
2329 &state, &i) == 0 || i != length)
2330 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "bad height format");
2331
2332 else if (PNG_FP_IS_POSITIVE(state) == 0)
2333 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "non-positive height");
2334
2335 else
2336 {
2337 /* This is the (only) success case. */
2338 png_set_sCAL_sMOZ_PNG_set_sCAL_s(png_ptr, info_ptr, buffer[0],
2339 (png_charp)buffer+1, (png_charp)buffer+heighti);
2340 return handled_ok;
2341 }
2342 }
2343
2344 return handled_error;
2345}
2346#else
2347# define png_handle_sCAL((void*)0) NULL((void*)0)
2348#endif
2349
2350#ifdef PNG_READ_tIME_SUPPORTED
2351static png_handle_result_code /* PRIVATE */
2352png_handle_tIME((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2353{
2354 png_byte buf[7];
2355 png_time mod_time;
2356
2357 png_debug(1, "in png_handle_tIME")((void)0);
2358
2359 /* TODO: what is this doing here? It should be happened in pngread.c and
2360 * pngpread.c, although it could be moved to png_handle_chunk below and
2361 * thereby avoid some code duplication.
2362 */
2363 if ((png_ptr->mode & PNG_HAVE_IDAT0x04U) != 0)
2364 png_ptr->mode |= PNG_AFTER_IDAT0x08;
2365
2366 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 7);
2367
2368 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
2369 return handled_error;
2370
2371 mod_time.second = buf[6];
2372 mod_time.minute = buf[5];
2373 mod_time.hour = buf[4];
2374 mod_time.day = buf[3];
2375 mod_time.month = buf[2];
2376 mod_time.year = png_get_uint_16(buf)((png_uint_16) (((unsigned int)(*(buf)) << 8) + ((unsigned
int)(*((buf) + 1)))))
;
2377
2378 png_set_tIMEMOZ_PNG_set_tIME(png_ptr, info_ptr, &mod_time);
2379 return handled_ok;
2380 PNG_UNUSED(length)(void)length;
2381}
2382#else
2383# define png_handle_tIME((void*)0) NULL((void*)0)
2384#endif
2385
2386#ifdef PNG_READ_tEXt_SUPPORTED
2387/* Note: this does not properly handle chunks that are > 64K under DOS */
2388static png_handle_result_code /* PRIVATE */
2389png_handle_tEXt((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2390{
2391 png_text text_info;
2392 png_bytep buffer;
2393 png_charp key;
2394 png_charp text;
2395 png_uint_32 skip = 0;
2396
2397 png_debug(1, "in png_handle_tEXt")((void)0);
2398
2399#ifdef PNG_USER_LIMITS_SUPPORTED
2400 if (png_ptr->user_chunk_cache_max != 0)
2401 {
2402 if (png_ptr->user_chunk_cache_max == 1)
2403 {
2404 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2405 return handled_error;
2406 }
2407
2408 if (--png_ptr->user_chunk_cache_max == 1)
2409 {
2410 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2411 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "no space in chunk cache");
2412 return handled_error;
2413 }
2414 }
2415#endif
2416
2417 buffer = png_read_buffer(png_ptr, length+1);
2418
2419 if (buffer == NULL((void*)0))
2420 {
2421 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2422 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of memory");
2423 return handled_error;
2424 }
2425
2426 png_crc_readMOZ_PNG_crc_read(png_ptr, buffer, length);
2427
2428 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, skip) != 0)
2429 return handled_error;
2430
2431 key = (png_charp)buffer;
2432 key[length] = 0;
2433
2434 for (text = key; *text; text++)
2435 /* Empty loop to find end of key */ ;
2436
2437 if (text != key + length)
2438 text++;
2439
2440 text_info.compression = PNG_TEXT_COMPRESSION_NONE-1;
2441 text_info.key = key;
2442 text_info.lang = NULL((void*)0);
2443 text_info.lang_key = NULL((void*)0);
2444 text_info.itxt_length = 0;
2445 text_info.text = text;
2446 text_info.text_length = strlen(text);
2447
2448 if (png_set_text_2MOZ_PNG_set_text_2(png_ptr, info_ptr, &text_info, 1) == 0)
2449 return handled_ok;
2450
2451 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of memory");
2452 return handled_error;
2453}
2454#else
2455# define png_handle_tEXt((void*)0) NULL((void*)0)
2456#endif
2457
2458#ifdef PNG_READ_zTXt_SUPPORTED
2459/* Note: this does not correctly handle chunks that are > 64K under DOS */
2460static png_handle_result_code /* PRIVATE */
2461png_handle_zTXt((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2462{
2463 png_const_charp errmsg = NULL((void*)0);
2464 png_bytep buffer;
2465 png_uint_32 keyword_length;
2466
2467 png_debug(1, "in png_handle_zTXt")((void)0);
2468
2469#ifdef PNG_USER_LIMITS_SUPPORTED
2470 if (png_ptr->user_chunk_cache_max != 0)
2471 {
2472 if (png_ptr->user_chunk_cache_max == 1)
2473 {
2474 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2475 return handled_error;
2476 }
2477
2478 if (--png_ptr->user_chunk_cache_max == 1)
2479 {
2480 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2481 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "no space in chunk cache");
2482 return handled_error;
2483 }
2484 }
2485#endif
2486
2487 /* Note, "length" is sufficient here; we won't be adding
2488 * a null terminator later. The limit check in png_handle_chunk should be
2489 * sufficient.
2490 */
2491 buffer = png_read_buffer(png_ptr, length);
2492
2493 if (buffer == NULL((void*)0))
2494 {
2495 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2496 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of memory");
2497 return handled_error;
2498 }
2499
2500 png_crc_readMOZ_PNG_crc_read(png_ptr, buffer, length);
2501
2502 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
2503 return handled_error;
2504
2505 /* TODO: also check that the keyword contents match the spec! */
2506 for (keyword_length = 0;
2507 keyword_length < length && buffer[keyword_length] != 0;
2508 ++keyword_length)
2509 /* Empty loop to find end of name */ ;
2510
2511 if (keyword_length > 79 || keyword_length < 1)
2512 errmsg = "bad keyword";
2513
2514 /* zTXt must have some LZ data after the keyword, although it may expand to
2515 * zero bytes; we need a '\0' at the end of the keyword, the compression type
2516 * then the LZ data:
2517 */
2518 else if (keyword_length + 3 > length)
2519 errmsg = "truncated";
2520
2521 else if (buffer[keyword_length+1] != PNG_COMPRESSION_TYPE_BASE0)
2522 errmsg = "unknown compression type";
2523
2524 else
2525 {
2526 png_alloc_size_t uncompressed_length = PNG_SIZE_MAX((size_t)(-1));
2527
2528 /* TODO: at present png_decompress_chunk imposes a single application
2529 * level memory limit, this should be split to different values for iCCP
2530 * and text chunks.
2531 */
2532 if (png_decompress_chunkMOZ_PNG_decomp_chunk(png_ptr, length, keyword_length+2,
2533 &uncompressed_length, 1/*terminate*/) == Z_STREAM_END1)
2534 {
2535 png_text text;
2536
2537 if (png_ptr->read_buffer == NULL((void*)0))
2538 errmsg="Read failure in png_handle_zTXt";
2539 else
2540 {
2541 /* It worked; png_ptr->read_buffer now looks like a tEXt chunk
2542 * except for the extra compression type byte and the fact that
2543 * it isn't necessarily '\0' terminated.
2544 */
2545 buffer = png_ptr->read_buffer;
2546 buffer[uncompressed_length+(keyword_length+2)] = 0;
2547
2548 text.compression = PNG_TEXT_COMPRESSION_zTXt0;
2549 text.key = (png_charp)buffer;
2550 text.text = (png_charp)(buffer + keyword_length+2);
2551 text.text_length = uncompressed_length;
2552 text.itxt_length = 0;
2553 text.lang = NULL((void*)0);
2554 text.lang_key = NULL((void*)0);
2555
2556 if (png_set_text_2MOZ_PNG_set_text_2(png_ptr, info_ptr, &text, 1) == 0)
2557 return handled_ok;
2558
2559 errmsg = "out of memory";
2560 }
2561 }
2562
2563 else
2564 errmsg = png_ptr->zstream.msg;
2565 }
2566
2567 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, errmsg);
2568 return handled_error;
2569}
2570#else
2571# define png_handle_zTXt((void*)0) NULL((void*)0)
2572#endif
2573
2574#ifdef PNG_READ_iTXt_SUPPORTED
2575/* Note: this does not correctly handle chunks that are > 64K under DOS */
2576static png_handle_result_code /* PRIVATE */
2577png_handle_iTXt((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2578{
2579 png_const_charp errmsg = NULL((void*)0);
2580 png_bytep buffer;
2581 png_uint_32 prefix_length;
2582
2583 png_debug(1, "in png_handle_iTXt")((void)0);
2584
2585#ifdef PNG_USER_LIMITS_SUPPORTED
2586 if (png_ptr->user_chunk_cache_max != 0)
2587 {
2588 if (png_ptr->user_chunk_cache_max == 1)
2589 {
2590 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2591 return handled_error;
2592 }
2593
2594 if (--png_ptr->user_chunk_cache_max == 1)
2595 {
2596 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2597 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "no space in chunk cache");
2598 return handled_error;
2599 }
2600 }
2601#endif
2602
2603 buffer = png_read_buffer(png_ptr, length+1);
2604
2605 if (buffer == NULL((void*)0))
2606 {
2607 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2608 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of memory");
2609 return handled_error;
2610 }
2611
2612 png_crc_readMOZ_PNG_crc_read(png_ptr, buffer, length);
2613
2614 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
2615 return handled_error;
2616
2617 /* First the keyword. */
2618 for (prefix_length=0;
2619 prefix_length < length && buffer[prefix_length] != 0;
2620 ++prefix_length)
2621 /* Empty loop */ ;
2622
2623 /* Perform a basic check on the keyword length here. */
2624 if (prefix_length > 79 || prefix_length < 1)
2625 errmsg = "bad keyword";
2626
2627 /* Expect keyword, compression flag, compression type, language, translated
2628 * keyword (both may be empty but are 0 terminated) then the text, which may
2629 * be empty.
2630 */
2631 else if (prefix_length + 5 > length)
2632 errmsg = "truncated";
2633
2634 else if (buffer[prefix_length+1] == 0 ||
2635 (buffer[prefix_length+1] == 1 &&
2636 buffer[prefix_length+2] == PNG_COMPRESSION_TYPE_BASE0))
2637 {
2638 int compressed = buffer[prefix_length+1] != 0;
2639 png_uint_32 language_offset, translated_keyword_offset;
2640 png_alloc_size_t uncompressed_length = 0;
2641
2642 /* Now the language tag */
2643 prefix_length += 3;
2644 language_offset = prefix_length;
2645
2646 for (; prefix_length < length && buffer[prefix_length] != 0;
2647 ++prefix_length)
2648 /* Empty loop */ ;
2649
2650 /* WARNING: the length may be invalid here, this is checked below. */
2651 translated_keyword_offset = ++prefix_length;
2652
2653 for (; prefix_length < length && buffer[prefix_length] != 0;
2654 ++prefix_length)
2655 /* Empty loop */ ;
2656
2657 /* prefix_length should now be at the trailing '\0' of the translated
2658 * keyword, but it may already be over the end. None of this arithmetic
2659 * can overflow because chunks are at most 2^31 bytes long, but on 16-bit
2660 * systems the available allocation may overflow.
2661 */
2662 ++prefix_length;
2663
2664 if (compressed == 0 && prefix_length <= length)
2665 uncompressed_length = length - prefix_length;
2666
2667 else if (compressed != 0 && prefix_length < length)
2668 {
2669 uncompressed_length = PNG_SIZE_MAX((size_t)(-1));
2670
2671 /* TODO: at present png_decompress_chunk imposes a single application
2672 * level memory limit, this should be split to different values for
2673 * iCCP and text chunks.
2674 */
2675 if (png_decompress_chunkMOZ_PNG_decomp_chunk(png_ptr, length, prefix_length,
2676 &uncompressed_length, 1/*terminate*/) == Z_STREAM_END1)
2677 buffer = png_ptr->read_buffer;
2678
2679 else
2680 errmsg = png_ptr->zstream.msg;
2681 }
2682
2683 else
2684 errmsg = "truncated";
2685
2686 if (errmsg == NULL((void*)0))
2687 {
2688 png_text text;
2689
2690 buffer[uncompressed_length+prefix_length] = 0;
2691
2692 if (compressed == 0)
2693 text.compression = PNG_ITXT_COMPRESSION_NONE1;
2694
2695 else
2696 text.compression = PNG_ITXT_COMPRESSION_zTXt2;
2697
2698 text.key = (png_charp)buffer;
2699 text.lang = (png_charp)buffer + language_offset;
2700 text.lang_key = (png_charp)buffer + translated_keyword_offset;
2701 text.text = (png_charp)buffer + prefix_length;
2702 text.text_length = 0;
2703 text.itxt_length = uncompressed_length;
2704
2705 if (png_set_text_2MOZ_PNG_set_text_2(png_ptr, info_ptr, &text, 1) == 0)
2706 return handled_ok;
2707
2708 errmsg = "out of memory";
2709 }
2710 }
2711
2712 else
2713 errmsg = "bad compression info";
2714
2715 if (errmsg != NULL((void*)0))
2716 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, errmsg);
2717 return handled_error;
2718}
2719#else
2720# define png_handle_iTXt((void*)0) NULL((void*)0)
2721#endif
2722
2723#ifdef PNG_READ_APNG_SUPPORTED
2724void /* PRIVATE */
2725png_handle_acTL((void*)0)(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
2726{
2727 png_byte data[8];
2728 png_uint_32 num_frames;
2729 png_uint_32 num_plays;
2730 png_uint_32 didSet;
2731
2732 png_debug(1, "in png_handle_acTL")((void)0);
2733
2734 if ((png_ptr->mode & PNG_HAVE_IHDR0x01) == 0)
2735 {
2736 png_error(png_ptr, "Missing IHDR before acTL");
2737 }
2738 else if ((png_ptr->mode & PNG_HAVE_IDAT0x04U) != 0)
2739 {
2740 png_warningMOZ_PNG_warning(png_ptr, "Invalid acTL after IDAT skipped");
2741 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2742 return;
2743 }
2744 else if ((png_ptr->mode & PNG_HAVE_acTL0x10000U) != 0)
2745 {
2746 png_warningMOZ_PNG_warning(png_ptr, "Duplicate acTL skipped");
2747 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2748 return;
2749 }
2750 else if (length != 8)
2751 {
2752 png_warningMOZ_PNG_warning(png_ptr, "acTL with invalid length skipped");
2753 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2754 return;
2755 }
2756
2757 png_crc_readMOZ_PNG_crc_read(png_ptr, data, 8);
2758 png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0);
2759
2760 num_frames = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, data);
2761 num_plays = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, data + 4);
2762
2763 /* the set function will do error checking on num_frames */
2764 didSet = png_set_acTLMOZ_APNG_set_acTL(png_ptr, info_ptr, num_frames, num_plays);
2765 if (didSet != 0)
2766 png_ptr->mode |= PNG_HAVE_acTL0x10000U;
2767}
2768
2769void /* PRIVATE */
2770png_handle_fcTL((void*)0)(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
2771{
2772 png_byte data[22];
2773 png_uint_32 width;
2774 png_uint_32 height;
2775 png_uint_32 x_offset;
2776 png_uint_32 y_offset;
2777 png_uint_16 delay_num;
2778 png_uint_16 delay_den;
2779 png_byte dispose_op;
2780 png_byte blend_op;
2781
2782 png_debug(1, "in png_handle_fcTL")((void)0);
2783
2784 png_ensure_sequence_numberMOZ_APNG_ensure_seqno(png_ptr, length);
2785
2786 if ((png_ptr->mode & PNG_HAVE_IHDR0x01) == 0)
2787 {
2788 png_error(png_ptr, "Missing IHDR before fcTL");
2789 }
2790 else if ((png_ptr->mode & PNG_HAVE_IDAT0x04U) != 0)
2791 {
2792 /* for any frames other then the first this message may be misleading,
2793 * but correct. PNG_HAVE_IDAT is unset before the frame head is read
2794 * i can't think of a better message */
2795 png_warningMOZ_PNG_warning(png_ptr, "Invalid fcTL after IDAT skipped");
2796 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length-4);
2797 return;
2798 }
2799 else if ((png_ptr->mode & PNG_HAVE_fcTL0x20000U) != 0)
2800 {
2801 png_warningMOZ_PNG_warning(png_ptr, "Duplicate fcTL within one frame skipped");
2802 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length-4);
2803 return;
2804 }
2805 else if (length != 26)
2806 {
2807 png_warningMOZ_PNG_warning(png_ptr, "fcTL with invalid length skipped");
2808 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length-4);
2809 return;
2810 }
2811
2812 png_crc_readMOZ_PNG_crc_read(png_ptr, data, 22);
2813 png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0);
2814
2815 width = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, data);
2816 height = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, data + 4);
2817 x_offset = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, data + 8);
2818 y_offset = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, data + 12);
2819 delay_num = png_get_uint_16(data + 16)((png_uint_16) (((unsigned int)(*(data + 16)) << 8) + (
(unsigned int)(*((data + 16) + 1)))))
;
2820 delay_den = png_get_uint_16(data + 18)((png_uint_16) (((unsigned int)(*(data + 18)) << 8) + (
(unsigned int)(*((data + 18) + 1)))))
;
2821 dispose_op = data[20];
2822 blend_op = data[21];
2823
2824 if (png_ptr->num_frames_read == 0 && (x_offset != 0 || y_offset != 0))
2825 {
2826 png_warningMOZ_PNG_warning(png_ptr, "fcTL for the first frame must have zero offset");
2827 return;
2828 }
2829
2830 if (info_ptr != NULL((void*)0))
2831 {
2832 if (png_ptr->num_frames_read == 0 &&
2833 (width != info_ptr->width || height != info_ptr->height))
2834 {
2835 png_warningMOZ_PNG_warning(png_ptr, "size in first frame's fcTL must match "
2836 "the size in IHDR");
2837 return;
2838 }
2839
2840 /* The set function will do more error checking */
2841 png_set_next_frame_fcTLMOZ_APNG_set_next_frame_fcTL(png_ptr, info_ptr, width, height,
2842 x_offset, y_offset, delay_num, delay_den,
2843 dispose_op, blend_op);
2844
2845 png_read_reinitMOZ_APNG_read_reinit(png_ptr, info_ptr);
2846
2847 png_ptr->mode |= PNG_HAVE_fcTL0x20000U;
2848 }
2849}
2850
2851void /* PRIVATE */
2852png_have_infoMOZ_APNG_have_info(png_structp png_ptr, png_infop info_ptr)
2853{
2854 if ((info_ptr->valid & PNG_INFO_acTL0x100000U) != 0 &&
2855 (info_ptr->valid & PNG_INFO_fcTL0x200000U) == 0)
2856 {
2857 png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN0x0001U;
2858 info_ptr->num_frames++;
2859 }
2860}
2861
2862void /* PRIVATE */
2863png_handle_fdAT((void*)0)(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
2864{
2865 png_ensure_sequence_numberMOZ_APNG_ensure_seqno(png_ptr, length);
2866
2867 /* This function is only called from png_read_end(), png_read_info(),
2868 * and png_push_read_chunk() which means that:
2869 * - the user doesn't want to read this frame
2870 * - or this is an out-of-place fdAT
2871 * in either case it is safe to ignore the chunk with a warning */
2872 png_warningMOZ_PNG_warning(png_ptr, "ignoring fdAT chunk");
2873 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length - 4);
2874 PNG_UNUSED(info_ptr)(void)info_ptr;
2875}
2876
2877void /* PRIVATE */
2878png_ensure_sequence_numberMOZ_APNG_ensure_seqno(png_structp png_ptr, png_uint_32 length)
2879{
2880 png_byte data[4];
2881 png_uint_32 sequence_number;
2882
2883 if (length < 4)
2884 png_error(png_ptr, "invalid fcTL or fdAT chunk found");
2885
2886 png_crc_readMOZ_PNG_crc_read(png_ptr, data, 4);
2887 sequence_number = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, data);
2888
2889 if (sequence_number != png_ptr->next_seq_num)
2890 png_error(png_ptr, "fcTL or fdAT chunk with out-of-order sequence "
2891 "number found");
2892
2893 png_ptr->next_seq_num++;
2894}
2895#endif /* READ_APNG */
2896
2897#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
2898/* Utility function for png_handle_unknown; set up png_ptr::unknown_chunk */
2899static int
2900png_cache_unknown_chunk(png_structrp png_ptr, png_uint_32 length)
2901{
2902 const png_alloc_size_t limit = png_chunk_max(png_ptr)((png_ptr)->user_chunk_malloc_max);
2903
2904 if (png_ptr->unknown_chunk.data != NULL((void*)0))
2905 {
2906 png_freeMOZ_PNG_free(png_ptr, png_ptr->unknown_chunk.data);
2907 png_ptr->unknown_chunk.data = NULL((void*)0);
2908 }
2909
2910 if (length <= limit)
2911 {
2912 PNG_CSTRING_FROM_CHUNK(png_ptr->unknown_chunk.name, png_ptr->chunk_name)(void)((void)(((char*)(png_ptr->unknown_chunk.name))[0]=(char
)(((png_ptr->chunk_name)>>24) & 0xff), ((char*)(
png_ptr->unknown_chunk.name))[1]=(char)(((png_ptr->chunk_name
)>>16) & 0xff), ((char*)(png_ptr->unknown_chunk.
name))[2]=(char)(((png_ptr->chunk_name)>>8) & 0xff
), ((char*)(png_ptr->unknown_chunk.name))[3]=(char)((png_ptr
->chunk_name & 0xff))), ((char*)(png_ptr->unknown_chunk
.name))[4] = 0)
;
2913 /* The following is safe because of the PNG_SIZE_MAX init above */
2914 png_ptr->unknown_chunk.size = (size_t)length/*SAFE*/;
2915 /* 'mode' is a flag array, only the bottom four bits matter here */
2916 png_ptr->unknown_chunk.location = (png_byte)png_ptr->mode/*SAFE*/;
2917
2918 if (length == 0)
2919 png_ptr->unknown_chunk.data = NULL((void*)0);
2920
2921 else
2922 {
2923 /* Do a 'warn' here - it is handled below. */
2924 png_ptr->unknown_chunk.data = png_voidcast(png_bytep,(MOZ_PNG_malloc_warn(png_ptr, length))
2925 png_malloc_warn(png_ptr, length))(MOZ_PNG_malloc_warn(png_ptr, length));
2926 }
2927 }
2928
2929 if (png_ptr->unknown_chunk.data == NULL((void*)0) && length > 0)
2930 {
2931 /* This is benign because we clean up correctly */
2932 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2933 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "unknown chunk exceeds memory limits");
2934 return 0;
2935 }
2936
2937 else
2938 {
2939 if (length > 0)
2940 png_crc_readMOZ_PNG_crc_read(png_ptr, png_ptr->unknown_chunk.data, length);
2941 png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0);
2942 return 1;
2943 }
2944}
2945#endif /* READ_UNKNOWN_CHUNKS */
2946
2947/* Handle an unknown, or known but disabled, chunk */
2948png_handle_result_code /*PRIVATE*/
2949png_handle_unknownMOZ_PNG_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
2950 png_uint_32 length, int keep)
2951{
2952 png_handle_result_code handled = handled_discarded; /* the default */
2953
2954 png_debug(1, "in png_handle_unknown")((void)0);
2955
2956#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
2957 /* NOTE: this code is based on the code in libpng-1.4.12 except for fixing
2958 * the bug which meant that setting a non-default behavior for a specific
2959 * chunk would be ignored (the default was always used unless a user
2960 * callback was installed).
2961 *
2962 * 'keep' is the value from the png_chunk_unknown_handling, the setting for
2963 * this specific chunk_name, if PNG_HANDLE_AS_UNKNOWN_SUPPORTED, if not it
2964 * will always be PNG_HANDLE_CHUNK_AS_DEFAULT and it needs to be set here.
2965 * This is just an optimization to avoid multiple calls to the lookup
2966 * function.
2967 */
2968# ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
2969# ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
2970 keep = png_chunk_unknown_handlingMOZ_PNG_chunk_unk_handling(png_ptr, png_ptr->chunk_name);
2971# endif
2972# endif
2973
2974 /* One of the following methods will read the chunk or skip it (at least one
2975 * of these is always defined because this is the only way to switch on
2976 * PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
2977 */
2978# ifdef PNG_READ_USER_CHUNKS_SUPPORTED
2979 /* The user callback takes precedence over the chunk keep value, but the
2980 * keep value is still required to validate a save of a critical chunk.
2981 */
2982 if (png_ptr->read_user_chunk_fn != NULL((void*)0))
2983 {
2984 if (png_cache_unknown_chunk(png_ptr, length) != 0)
2985 {
2986 /* Callback to user unknown chunk handler */
2987 int ret = (*(png_ptr->read_user_chunk_fn))(png_ptr,
2988 &png_ptr->unknown_chunk);
2989
2990 /* ret is:
2991 * negative: An error occurred; png_chunk_error will be called.
2992 * zero: The chunk was not handled, the chunk will be discarded
2993 * unless png_set_keep_unknown_chunks has been used to set
2994 * a 'keep' behavior for this particular chunk, in which
2995 * case that will be used. A critical chunk will cause an
2996 * error at this point unless it is to be saved.
2997 * positive: The chunk was handled, libpng will ignore/discard it.
2998 */
2999 if (ret < 0) /* handled_error */
3000 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, "error in user chunk");
3001
3002 else if (ret == 0)
3003 {
3004 /* If the keep value is 'default' or 'never' override it, but
3005 * still error out on critical chunks unless the keep value is
3006 * 'always' While this is weird it is the behavior in 1.4.12.
3007 * A possible improvement would be to obey the value set for the
3008 * chunk, but this would be an API change that would probably
3009 * damage some applications.
3010 *
3011 * The png_app_warning below catches the case that matters, where
3012 * the application has not set specific save or ignore for this
3013 * chunk or global save or ignore.
3014 */
3015 if (keep < PNG_HANDLE_CHUNK_IF_SAFE2)
3016 {
3017# ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
3018 if (png_ptr->unknown_default < PNG_HANDLE_CHUNK_IF_SAFE2)
3019 {
3020 png_chunk_warningMOZ_PNG_chunk_warn(png_ptr, "Saving unknown chunk:");
3021 png_app_warningMOZ_PNG_app_warn(png_ptr,
3022 "forcing save of an unhandled chunk;"
3023 " please call png_set_keep_unknown_chunks");
3024 /* with keep = PNG_HANDLE_CHUNK_IF_SAFE */
3025 }
3026# endif
3027 keep = PNG_HANDLE_CHUNK_IF_SAFE2;
3028 }
3029 }
3030
3031 else /* chunk was handled */
3032 {
3033 handled = handled_ok;
3034 /* Critical chunks can be safely discarded at this point. */
3035 keep = PNG_HANDLE_CHUNK_NEVER1;
3036 }
3037 }
3038
3039 else
3040 keep = PNG_HANDLE_CHUNK_NEVER1; /* insufficient memory */
3041 }
3042
3043 else
3044 /* Use the SAVE_UNKNOWN_CHUNKS code or skip the chunk */
3045# endif /* READ_USER_CHUNKS */
3046
3047# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
3048 {
3049 /* keep is currently just the per-chunk setting, if there was no
3050 * setting change it to the global default now (not that this may
3051 * still be AS_DEFAULT) then obtain the cache of the chunk if required,
3052 * if not simply skip the chunk.
3053 */
3054 if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT0)
3055 keep = png_ptr->unknown_default;
3056
3057 if (keep == PNG_HANDLE_CHUNK_ALWAYS3 ||
3058 (keep == PNG_HANDLE_CHUNK_IF_SAFE2 &&
3059 PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)(1 & ((png_ptr->chunk_name) >> 29))))
3060 {
3061 if (png_cache_unknown_chunk(png_ptr, length) == 0)
3062 keep = PNG_HANDLE_CHUNK_NEVER1;
3063 }
3064
3065 else
3066 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
3067 }
3068# else
3069# ifndef PNG_READ_USER_CHUNKS_SUPPORTED
3070# error no method to support READ_UNKNOWN_CHUNKS
3071# endif
3072
3073 {
3074 /* If here there is no read callback pointer set and no support is
3075 * compiled in to just save the unknown chunks, so simply skip this
3076 * chunk. If 'keep' is something other than AS_DEFAULT or NEVER then
3077 * the app has erroneously asked for unknown chunk saving when there
3078 * is no support.
3079 */
3080 if (keep > PNG_HANDLE_CHUNK_NEVER1)
3081 png_app_errorMOZ_PNG_app_err(png_ptr, "no unknown chunk support available");
3082
3083 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
3084 }
3085# endif
3086
3087# ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
3088 /* Now store the chunk in the chunk list if appropriate, and if the limits
3089 * permit it.
3090 */
3091 if (keep == PNG_HANDLE_CHUNK_ALWAYS3 ||
3092 (keep == PNG_HANDLE_CHUNK_IF_SAFE2 &&
3093 PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)(1 & ((png_ptr->chunk_name) >> 29))))
3094 {
3095# ifdef PNG_USER_LIMITS_SUPPORTED
3096 switch (png_ptr->user_chunk_cache_max)
3097 {
3098 case 2:
3099 png_ptr->user_chunk_cache_max = 1;
3100 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "no space in chunk cache");
3101 /* FALLTHROUGH */
3102 case 1:
3103 /* NOTE: prior to 1.6.0 this case resulted in an unknown critical
3104 * chunk being skipped, now there will be a hard error below.
3105 */
3106 break;
3107
3108 default: /* not at limit */
3109 --(png_ptr->user_chunk_cache_max);
3110 /* FALLTHROUGH */
3111 case 0: /* no limit */
3112# endif /* USER_LIMITS */
3113 /* Here when the limit isn't reached or when limits are compiled
3114 * out; store the chunk.
3115 */
3116 png_set_unknown_chunksMOZ_PNG_set_unknown_chunks(png_ptr, info_ptr,
3117 &png_ptr->unknown_chunk, 1);
3118 handled = handled_saved;
3119# ifdef PNG_USER_LIMITS_SUPPORTED
3120 break;
3121 }
3122# endif
3123 }
3124# else /* no store support: the chunk must be handled by the user callback */
3125 PNG_UNUSED(info_ptr)(void)info_ptr;
3126# endif
3127
3128 /* Regardless of the error handling below the cached data (if any) can be
3129 * freed now. Notice that the data is not freed if there is a png_error, but
3130 * it will be freed by destroy_read_struct.
3131 */
3132 if (png_ptr->unknown_chunk.data != NULL((void*)0))
3133 png_freeMOZ_PNG_free(png_ptr, png_ptr->unknown_chunk.data);
3134 png_ptr->unknown_chunk.data = NULL((void*)0);
3135
3136#else /* !PNG_READ_UNKNOWN_CHUNKS_SUPPORTED */
3137 /* There is no support to read an unknown chunk, so just skip it. */
3138 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
3139 PNG_UNUSED(info_ptr)(void)info_ptr;
3140 PNG_UNUSED(keep)(void)keep;
3141#endif /* !READ_UNKNOWN_CHUNKS */
3142
3143 /* Check for unhandled critical chunks */
3144 if (handled < handled_saved && PNG_CHUNK_CRITICAL(png_ptr->chunk_name)(!(1 & ((png_ptr->chunk_name) >> 29))))
3145 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, "unhandled critical chunk");
3146
3147 return handled;
3148}
3149
3150/* APNG handling: the minimal implementation of APNG handling in libpng 1.6
3151 * requires that those significant applications which already handle APNG not
3152 * get hosed. To do this ensure the code here will have to ensure than APNG
3153 * data by default (at least in 1.6) gets stored in the unknown chunk list.
3154 * Maybe this can be relaxed in a few years but at present it's just the only
3155 * safe way.
3156 *
3157 * ATM just cause unknown handling for all three chunks:
3158 */
3159#define png_handle_acTL((void*)0) NULL((void*)0)
3160#define png_handle_fcTL((void*)0) NULL((void*)0)
3161#define png_handle_fdAT((void*)0) NULL((void*)0)
3162
3163/*
3164 * 1.6.47: This is the new table driven interface to all the chunk handling.
3165 *
3166 * The table describes the PNG standard rules for **reading** known chunks -
3167 * every chunk which has an entry in PNG_KNOWN_CHUNKS. The table contains an
3168 * entry for each PNG_INDEX_cHNK describing the rules.
3169 *
3170 * In this initial version the only information in the entry is the
3171 * png_handle_cHNK function for the chunk in question. When chunk support is
3172 * compiled out the entry will be NULL.
3173 */
3174static const struct
3175{
3176 png_handle_result_code (*handler)(
3177 png_structrp, png_inforp, png_uint_32 length);
3178 /* A chunk-specific 'handler', NULL if the chunk is not supported in this
3179 * build.
3180 */
3181
3182 /* Crushing these values helps on modern 32-bit architectures because the
3183 * pointer and the following bit fields both end up requiring 32 bits.
3184 * Typically this will halve the table size. On 64-bit architectures the
3185 * table entries will typically be 8 bytes.
3186 */
3187 png_uint_32 max_length :12; /* Length min, max in bytes */
3188 png_uint_32 min_length :8;
3189 /* Length errors on critical chunks have special handling to preserve the
3190 * existing behaviour in libpng 1.6. Ancillary chunks are checked below
3191 * and produce a 'benign' error.
3192 */
3193 png_uint_32 pos_before :4; /* PNG_HAVE_ values chunk must precede */
3194 png_uint_32 pos_after :4; /* PNG_HAVE_ values chunk must follow */
3195 /* NOTE: PLTE, tRNS and bKGD require special handling which depends on
3196 * the colour type of the base image.
3197 */
3198 png_uint_32 multiple :1; /* Multiple occurrences permitted */
3199 /* This is enabled for PLTE because PLTE may, in practice, be optional */
3200}
3201read_chunks[PNG_INDEX_unknown] =
3202{
3203 /* Definitions as above but done indirectly by #define so that
3204 * PNG_KNOWN_CHUNKS can be used safely to build the table in order.
3205 *
3206 * Each CDcHNK definition lists the values for the parameters **after**
3207 * the first, 'handler', function. 'handler' is NULL when the chunk has no
3208 * compiled in support.
3209 */
3210# define NoCheck0x801U 0x801U /* Do not check the maximum length */
3211# define Limit0x802U 0x802U /* Limit to png_chunk_max bytes */
3212# define LKMin3U+(2U+5U+4U) 3U+LZ77Min(2U+5U+4U) /* Minimum length of keyword+LZ77 */
3213
3214#define hIHDR0x01 PNG_HAVE_IHDR0x01
3215#define hPLTE0x02 PNG_HAVE_PLTE0x02
3216#define hIDAT0x04U PNG_HAVE_IDAT0x04U
3217 /* For the two chunks, tRNS and bKGD which can occur in PNGs without a PLTE
3218 * but must occur after the PLTE use this and put the check in the handler
3219 * routine for colour mapped images were PLTE is required. Also put a check
3220 * in PLTE for other image types to drop the PLTE if tRNS or bKGD have been
3221 * seen.
3222 */
3223#define hCOL(0x02|0x04U) (PNG_HAVE_PLTE0x02|PNG_HAVE_IDAT0x04U)
3224 /* Used for the decoding chunks which must be before PLTE. */
3225#define aIDAT0x08 PNG_AFTER_IDAT0x08
3226
3227 /* Chunks from W3C PNG v3: */
3228 /* cHNK max_len, min, before, after, multiple */
3229# define CDIHDR13U, 13U, 0x01, 0, 0 13U, 13U, hIHDR0x01, 0, 0
3230# define CDPLTE0x801U, 0U, 0, 0x01, 1 NoCheck0x801U, 0U, 0, hIHDR0x01, 1
3231 /* PLTE errors are only critical for colour-map images, consequently the
3232 * handler does all the checks.
3233 */
3234# define CDIDAT0x801U, 0U, 0x08, 0x01, 1 NoCheck0x801U, 0U, aIDAT0x08, hIHDR0x01, 1
3235# define CDIEND0x801U, 0U, 0, 0x08, 0 NoCheck0x801U, 0U, 0, aIDAT0x08, 0
3236 /* Historically data was allowed in IEND */
3237# define CDtRNS256U, 0U, 0x04U, 0x01, 0 256U, 0U, hIDAT0x04U, hIHDR0x01, 0
3238# define CDcHRM32U, 32U, (0x02|0x04U), 0x01, 0 32U, 32U, hCOL(0x02|0x04U), hIHDR0x01, 0
3239# define CDgAMA4U, 4U, (0x02|0x04U), 0x01, 0 4U, 4U, hCOL(0x02|0x04U), hIHDR0x01, 0
3240# define CDiCCP0x801U, 3U+(2U+5U+4U), (0x02|0x04U), 0x01, 0 NoCheck0x801U, LKMin3U+(2U+5U+4U), hCOL(0x02|0x04U), hIHDR0x01, 0
3241# define CDsBIT4U, 1U, (0x02|0x04U), 0x01, 0 4U, 1U, hCOL(0x02|0x04U), hIHDR0x01, 0
3242# define CDsRGB1U, 1U, (0x02|0x04U), 0x01, 0 1U, 1U, hCOL(0x02|0x04U), hIHDR0x01, 0
3243# define CDcICP4U, 4U, (0x02|0x04U), 0x01, 0 4U, 4U, hCOL(0x02|0x04U), hIHDR0x01, 0
3244# define CDmDCV24U, 24U, (0x02|0x04U), 0x01, 0 24U, 24U, hCOL(0x02|0x04U), hIHDR0x01, 0
3245# define CDeXIf0x802U, 4U, 0, 0x01, 0 Limit0x802U, 4U, 0, hIHDR0x01, 0
3246# define CDcLLI8U, 8U, (0x02|0x04U), 0x01, 0 8U, 8U, hCOL(0x02|0x04U), hIHDR0x01, 0
3247# define CDtEXt0x801U, 2U, 0, 0x01, 1 NoCheck0x801U, 2U, 0, hIHDR0x01, 1
3248 /* Allocates 'length+1'; checked in the handler */
3249# define CDzTXt0x802U, 3U+(2U+5U+4U), 0, 0x01, 1 Limit0x802U, LKMin3U+(2U+5U+4U), 0, hIHDR0x01, 1
3250# define CDiTXt0x801U, 6U, 0, 0x01, 1 NoCheck0x801U, 6U, 0, hIHDR0x01, 1
3251 /* Allocates 'length+1'; checked in the handler */
3252# define CDbKGD6U, 1U, 0x04U, 0x01, 0 6U, 1U, hIDAT0x04U, hIHDR0x01, 0
3253# define CDhIST1024U, 0U, 0x04U, 0x02, 0 1024U, 0U, hIDAT0x04U, hPLTE0x02, 0
3254# define CDpHYs9U, 9U, 0x04U, 0x01, 0 9U, 9U, hIDAT0x04U, hIHDR0x01, 0
3255# define CDsPLT0x801U, 3U, 0x04U, 0x01, 1 NoCheck0x801U, 3U, hIDAT0x04U, hIHDR0x01, 1
3256 /* Allocates 'length+1'; checked in the handler */
3257# define CDtIME7U, 7U, 0, 0x01, 0 7U, 7U, 0, hIHDR0x01, 0
3258# define CDacTL8U, 8U, 0x04U, 0x01, 0 8U, 8U, hIDAT0x04U, hIHDR0x01, 0
3259# define CDfcTL25U, 26U, 0, 0x01, 1 25U, 26U, 0, hIHDR0x01, 1
3260# define CDfdAT0x802U, 4U, 0x04U, 0x01, 1 Limit0x802U, 4U, hIDAT0x04U, hIHDR0x01, 1
3261 /* Supported chunks from PNG extensions 1.5.0, NYI so limit */
3262# define CDoFFs9U, 9U, 0x04U, 0x01, 0 9U, 9U, hIDAT0x04U, hIHDR0x01, 0
3263# define CDpCAL0x801U, 14U, 0x04U, 0x01, 0 NoCheck0x801U, 14U, hIDAT0x04U, hIHDR0x01, 0
3264 /* Allocates 'length+1'; checked in the handler */
3265# define CDsCAL0x802U, 4U, 0x04U, 0x01, 0 Limit0x802U, 4U, hIDAT0x04U, hIHDR0x01, 0
3266 /* Allocates 'length+1'; checked in the handler */
3267
3268# define PNG_CHUNK(cHNK, index) { png_handle_ ## cHNK, CD ## cHNK },
3269 PNG_KNOWN_CHUNKSPNG_CHUNK(IHDR, 0) PNG_CHUNK(PLTE, 1) PNG_CHUNK(IDAT, 2) PNG_CHUNK
(IEND, 3) PNG_CHUNK(acTL, 4) PNG_CHUNK(bKGD, 5) PNG_CHUNK(cHRM
, 6) PNG_CHUNK(cICP, 7) PNG_CHUNK(cLLI, 8) PNG_CHUNK(eXIf, 9)
PNG_CHUNK(fcTL, 10) PNG_CHUNK(fdAT, 11) PNG_CHUNK(gAMA, 12) PNG_CHUNK
(hIST, 13) PNG_CHUNK(iCCP, 14) PNG_CHUNK(iTXt, 15) PNG_CHUNK(
mDCV, 16) PNG_CHUNK(oFFs, 17) PNG_CHUNK(pCAL, 18) PNG_CHUNK(pHYs
, 19) PNG_CHUNK(sBIT, 20) PNG_CHUNK(sCAL, 21) PNG_CHUNK(sPLT,
22) PNG_CHUNK(sRGB, 23) PNG_CHUNK(tEXt, 24) PNG_CHUNK(tIME, 25
) PNG_CHUNK(tRNS, 26) PNG_CHUNK(zTXt, 27)
3270# undef PNG_CHUNK
3271};
3272
3273
3274static png_index
3275png_chunk_index_from_name(png_uint_32 chunk_name)
3276{
3277 /* For chunk png_cHNK return PNG_INDEX_cHNK. Return PNG_INDEX_unknown if
3278 * chunk_name is not known. Notice that in a particular build "known" does
3279 * not necessarily mean "supported", although the inverse applies.
3280 */
3281 switch (chunk_name)
3282 {
3283# define PNG_CHUNK(cHNK, index)\
3284 case png_ ## cHNK: return PNG_INDEX_ ## cHNK; /* == index */
3285
3286 PNG_KNOWN_CHUNKSPNG_CHUNK(IHDR, 0) PNG_CHUNK(PLTE, 1) PNG_CHUNK(IDAT, 2) PNG_CHUNK
(IEND, 3) PNG_CHUNK(acTL, 4) PNG_CHUNK(bKGD, 5) PNG_CHUNK(cHRM
, 6) PNG_CHUNK(cICP, 7) PNG_CHUNK(cLLI, 8) PNG_CHUNK(eXIf, 9)
PNG_CHUNK(fcTL, 10) PNG_CHUNK(fdAT, 11) PNG_CHUNK(gAMA, 12) PNG_CHUNK
(hIST, 13) PNG_CHUNK(iCCP, 14) PNG_CHUNK(iTXt, 15) PNG_CHUNK(
mDCV, 16) PNG_CHUNK(oFFs, 17) PNG_CHUNK(pCAL, 18) PNG_CHUNK(pHYs
, 19) PNG_CHUNK(sBIT, 20) PNG_CHUNK(sCAL, 21) PNG_CHUNK(sPLT,
22) PNG_CHUNK(sRGB, 23) PNG_CHUNK(tEXt, 24) PNG_CHUNK(tIME, 25
) PNG_CHUNK(tRNS, 26) PNG_CHUNK(zTXt, 27)
3287
3288# undef PNG_CHUNK
3289
3290 default: return PNG_INDEX_unknown;
3291 }
3292}
3293
3294png_handle_result_code /*PRIVATE*/
3295png_handle_chunk(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
3296{
3297 /* CSE: these things don't change, these autos are just to save typing and
3298 * make the code more clear.
3299 */
3300 const png_uint_32 chunk_name = png_ptr->chunk_name;
3301 const png_index chunk_index = png_chunk_index_from_name(chunk_name);
3302
3303 png_handle_result_code handled = handled_error;
3304 png_const_charp errmsg = NULL((void*)0);
3305
3306 /* Is this a known chunk? If not there are no checks performed here;
3307 * png_handle_unknown does the correct checks. This means that the values
3308 * for known but unsupported chunks in the above table are not used here
3309 * however the chunks_seen fields in png_struct are still set.
3310 */
3311 if (chunk_index == PNG_INDEX_unknown ||
3312 read_chunks[chunk_index].handler == NULL((void*)0))
3313 {
3314 handled = png_handle_unknownMOZ_PNG_handle_unknown(
3315 png_ptr, info_ptr, length, PNG_HANDLE_CHUNK_AS_DEFAULT0);
3316 }
3317
3318 /* First check the position. The first check is historical; the stream must
3319 * start with IHDR and anything else causes libpng to give up immediately.
3320 */
3321 else if (chunk_index != PNG_INDEX_IHDR &&
3322 (png_ptr->mode & PNG_HAVE_IHDR0x01) == 0)
3323 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, "missing IHDR"); /* NORETURN */
3324
3325 /* Before all the pos_before chunks, after all the pos_after chunks. */
3326 else if (((png_ptr->mode & read_chunks[chunk_index].pos_before) != 0) ||
3327 ((png_ptr->mode & read_chunks[chunk_index].pos_after) !=
3328 read_chunks[chunk_index].pos_after))
3329 {
3330 errmsg = "out of place";
3331 }
3332
3333 /* Now check for duplicates: duplicated critical chunks also produce a
3334 * full error.
3335 */
3336 else if (read_chunks[chunk_index].multiple == 0 &&
3337 png_file_has_chunk(png_ptr, chunk_index)(((png_ptr)->chunks & (0x80000000U >> (31 - (chunk_index
)))) != 0)
)
3338 {
3339 errmsg = "duplicate";
3340 }
3341
3342 else if (length < read_chunks[chunk_index].min_length)
3343 errmsg = "too short";
3344 else
3345 {
3346 /* NOTE: apart from IHDR the critical chunks (PLTE, IDAT and IEND) are set
3347 * up above not to do any length checks.
3348 *
3349 * The png_chunk_max check ensures that the variable length chunks are
3350 * always checked at this point for being within the system allocation
3351 * limits.
3352 */
3353 unsigned max_length = read_chunks[chunk_index].max_length;
3354
3355 switch (max_length)
3356 {
3357 case Limit0x802U:
3358 /* png_read_chunk_header has already png_error'ed chunks with a
3359 * length exceeding the 31-bit PNG limit, so just check the memory
3360 * limit:
3361 */
3362 if (length <= png_chunk_max(png_ptr)((png_ptr)->user_chunk_malloc_max))
3363 goto MeetsLimit;
3364
3365 errmsg = "length exceeds libpng limit";
3366 break;
3367
3368 default:
3369 if (length <= max_length)
3370 goto MeetsLimit;
3371
3372 errmsg = "too long";
3373 break;
3374
3375 case NoCheck0x801U:
3376 MeetsLimit:
3377 handled = read_chunks[chunk_index].handler(
3378 png_ptr, info_ptr, length);
3379 break;
3380 }
3381 }
3382
3383 /* If there was an error or the chunk was simply skipped it is not counted as
3384 * 'seen'.
3385 */
3386 if (errmsg != NULL((void*)0))
3387 {
3388 if (PNG_CHUNK_CRITICAL(chunk_name)(!(1 & ((chunk_name) >> 29)))) /* stop immediately */
3389 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, errmsg);
3390 else /* ancillary chunk */
3391 {
3392 /* The chunk data is skipped: */
3393 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
3394 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, errmsg);
3395 }
3396 }
3397
3398 else if (handled >= handled_saved)
3399 {
3400 if (chunk_index != PNG_INDEX_unknown)
3401 png_file_add_chunk(png_ptr, chunk_index)((void)((png_ptr)->chunks |= (0x80000000U >> (31 - (
chunk_index)))))
;
3402 }
3403
3404 return handled;
3405}
3406
3407/* Combines the row recently read in with the existing pixels in the row. This
3408 * routine takes care of alpha and transparency if requested. This routine also
3409 * handles the two methods of progressive display of interlaced images,
3410 * depending on the 'display' value; if 'display' is true then the whole row
3411 * (dp) is filled from the start by replicating the available pixels. If
3412 * 'display' is false only those pixels present in the pass are filled in.
3413 */
3414void /* PRIVATE */
3415png_combine_rowMOZ_PNG_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
3416{
3417 unsigned int pixel_depth = png_ptr->transformed_pixel_depth;
3418 png_const_bytep sp = png_ptr->row_buf + 1;
3419 png_alloc_size_t row_width = png_ptr->width;
3420 unsigned int pass = png_ptr->pass;
3421 png_bytep end_ptr = 0;
3422 png_byte end_byte = 0;
3423 unsigned int end_mask;
3424
3425 png_debug(1, "in png_combine_row")((void)0);
3426
3427 /* Added in 1.5.6: it should not be possible to enter this routine until at
3428 * least one row has been read from the PNG data and transformed.
3429 */
3430 if (pixel_depth == 0)
3431 png_error(png_ptr, "internal row logic error");
3432
3433 /* Added in 1.5.4: the pixel depth should match the information returned by
3434 * any call to png_read_update_info at this point. Do not continue if we got
3435 * this wrong.
3436 */
3437 if (png_ptr->info_rowbytes != 0 && png_ptr->info_rowbytes !=
3438 PNG_ROWBYTES(pixel_depth, row_width)((pixel_depth) >= 8 ? ((size_t)(row_width) * (((size_t)(pixel_depth
)) >> 3)) : (( ((size_t)(row_width) * ((size_t)(pixel_depth
))) + 7) >> 3) )
)
3439 png_error(png_ptr, "internal row size calculation error");
3440
3441 /* Don't expect this to ever happen: */
3442 if (row_width == 0)
3443 png_error(png_ptr, "internal row width error");
3444
3445 /* Preserve the last byte in cases where only part of it will be overwritten,
3446 * the multiply below may overflow, we don't care because ANSI-C guarantees
3447 * we get the low bits.
3448 */
3449 end_mask = (pixel_depth * row_width) & 7;
3450 if (end_mask != 0)
3451 {
3452 /* end_ptr == NULL is a flag to say do nothing */
3453 end_ptr = dp + PNG_ROWBYTES(pixel_depth, row_width)((pixel_depth) >= 8 ? ((size_t)(row_width) * (((size_t)(pixel_depth
)) >> 3)) : (( ((size_t)(row_width) * ((size_t)(pixel_depth
))) + 7) >> 3) )
- 1;
3454 end_byte = *end_ptr;
3455# ifdef PNG_READ_PACKSWAP_SUPPORTED
3456 if ((png_ptr->transformations & PNG_PACKSWAP0x10000U) != 0)
3457 /* little-endian byte */
3458 end_mask = (unsigned int)(0xff << end_mask);
3459
3460 else /* big-endian byte */
3461# endif
3462 end_mask = 0xff >> end_mask;
3463 /* end_mask is now the bits to *keep* from the destination row */
3464 }
3465
3466 /* For non-interlaced images this reduces to a memcpy(). A memcpy()
3467 * will also happen if interlacing isn't supported or if the application
3468 * does not call png_set_interlace_handling(). In the latter cases the
3469 * caller just gets a sequence of the unexpanded rows from each interlace
3470 * pass.
3471 */
3472#ifdef PNG_READ_INTERLACING_SUPPORTED
3473 if (png_ptr->interlaced != 0 &&
3474 (png_ptr->transformations & PNG_INTERLACE0x0002U) != 0 &&
3475 pass < 6 && (display == 0 ||
3476 /* The following copies everything for 'display' on passes 0, 2 and 4. */
3477 (display == 1 && (pass & 1) != 0)))
3478 {
3479 /* Narrow images may have no bits in a pass; the caller should handle
3480 * this, but this test is cheap:
3481 */
3482 if (row_width <= PNG_PASS_START_COL(pass)(((1& (pass))<<(3-(((pass)+1)>>1)))&7))
3483 return;
3484
3485 if (pixel_depth < 8)
3486 {
3487 /* For pixel depths up to 4 bpp the 8-pixel mask can be expanded to fit
3488 * into 32 bits, then a single loop over the bytes using the four byte
3489 * values in the 32-bit mask can be used. For the 'display' option the
3490 * expanded mask may also not require any masking within a byte. To
3491 * make this work the PACKSWAP option must be taken into account - it
3492 * simply requires the pixels to be reversed in each byte.
3493 *
3494 * The 'regular' case requires a mask for each of the first 6 passes,
3495 * the 'display' case does a copy for the even passes in the range
3496 * 0..6. This has already been handled in the test above.
3497 *
3498 * The masks are arranged as four bytes with the first byte to use in
3499 * the lowest bits (little-endian) regardless of the order (PACKSWAP or
3500 * not) of the pixels in each byte.
3501 *
3502 * NOTE: the whole of this logic depends on the caller of this function
3503 * only calling it on rows appropriate to the pass. This function only
3504 * understands the 'x' logic; the 'y' logic is handled by the caller.
3505 *
3506 * The following defines allow generation of compile time constant bit
3507 * masks for each pixel depth and each possibility of swapped or not
3508 * swapped bytes. Pass 'p' is in the range 0..6; 'x', a pixel index,
3509 * is in the range 0..7; and the result is 1 if the pixel is to be
3510 * copied in the pass, 0 if not. 'S' is for the sparkle method, 'B'
3511 * for the block method.
3512 *
3513 * With some compilers a compile time expression of the general form:
3514 *
3515 * (shift >= 32) ? (a >> (shift-32)) : (b >> shift)
3516 *
3517 * Produces warnings with values of 'shift' in the range 33 to 63
3518 * because the right hand side of the ?: expression is evaluated by
3519 * the compiler even though it isn't used. Microsoft Visual C (various
3520 * versions) and the Intel C compiler are known to do this. To avoid
3521 * this the following macros are used in 1.5.6. This is a temporary
3522 * solution to avoid destabilizing the code during the release process.
3523 */
3524# if PNG_USE_COMPILE_TIME_MASKS1
3525# define PNG_LSR(x,s)((x)>>((s) & 0x1f)) ((x)>>((s) & 0x1f))
3526# define PNG_LSL(x,s)((x)<<((s) & 0x1f)) ((x)<<((s) & 0x1f))
3527# else
3528# define PNG_LSR(x,s)((x)>>((s) & 0x1f)) ((x)>>(s))
3529# define PNG_LSL(x,s)((x)<<((s) & 0x1f)) ((x)<<(s))
3530# endif
3531# define S_COPY(p,x)(((p)<4 ? ((0x80088822)>>(((3-(p))*8+(7-(x))) & 0x1f
)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(x))) & 0x1f))) &
1)
(((p)<4 ? PNG_LSR(0x80088822,(3-(p))*8+(7-(x)))((0x80088822)>>(((3-(p))*8+(7-(x))) & 0x1f)) :\
3532 PNG_LSR(0xaa55ff00,(7-(p))*8+(7-(x)))((0xaa55ff00)>>(((7-(p))*8+(7-(x))) & 0x1f))) & 1)
3533# define B_COPY(p,x)(((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+(7-(x))) & 0x1f
)) : ((0xff55ff00)>>(((7-(p))*8+(7-(x))) & 0x1f))) &
1)
(((p)<4 ? PNG_LSR(0xff0fff33,(3-(p))*8+(7-(x)))((0xff0fff33)>>(((3-(p))*8+(7-(x))) & 0x1f)) :\
3534 PNG_LSR(0xff55ff00,(7-(p))*8+(7-(x)))((0xff55ff00)>>(((7-(p))*8+(7-(x))) & 0x1f))) & 1)
3535
3536 /* Return a mask for pass 'p' pixel 'x' at depth 'd'. The mask is
3537 * little endian - the first pixel is at bit 0 - however the extra
3538 * parameter 's' can be set to cause the mask position to be swapped
3539 * within each byte, to match the PNG format. This is done by XOR of
3540 * the shift with 7, 6 or 4 for bit depths 1, 2 and 4.
3541 */
3542# define PIXEL_MASK(p,x,d,s)(((((((1U)<<(((d)) & 0x1f)))-1))<<(((((x)*(d)
)^((s)?8-(d):0))) & 0x1f)))
\
3543 (PNG_LSL(((PNG_LSL(1U,(d)))-1),(((x)*(d))^((s)?8-(d):0)))((((((1U)<<(((d)) & 0x1f)))-1))<<(((((x)*(d))
^((s)?8-(d):0))) & 0x1f))
)
3544
3545 /* Hence generate the appropriate 'block' or 'sparkle' pixel copy mask.
3546 */
3547# define S_MASKx(p,x,d,s)((((p)<4 ? ((0x80088822)>>(((3-(p))*8+(7-(x))) &
0x1f)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(x))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((x)*(d))^((s)?8-(d):0))) & 0x1f))):0)
(S_COPY(p,x)(((p)<4 ? ((0x80088822)>>(((3-(p))*8+(7-(x))) & 0x1f
)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(x))) & 0x1f))) &
1)
?PIXEL_MASK(p,x,d,s)(((((((1U)<<(((d)) & 0x1f)))-1))<<(((((x)*(d)
)^((s)?8-(d):0))) & 0x1f)))
:0)
3548# define B_MASKx(p,x,d,s)((((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+(7-(x))) &
0x1f)) : ((0xff55ff00)>>(((7-(p))*8+(7-(x))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((x)*(d))^((s)?8-(d):0))) & 0x1f))):0)
(B_COPY(p,x)(((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+(7-(x))) & 0x1f
)) : ((0xff55ff00)>>(((7-(p))*8+(7-(x))) & 0x1f))) &
1)
?PIXEL_MASK(p,x,d,s)(((((((1U)<<(((d)) & 0x1f)))-1))<<(((((x)*(d)
)^((s)?8-(d):0))) & 0x1f)))
:0)
3549
3550 /* Combine 8 of these to get the full mask. For the 1-bpp and 2-bpp
3551 * cases the result needs replicating, for the 4-bpp case the above
3552 * generates a full 32 bits.
3553 */
3554# define MASK_EXPAND(m,d)((m)*((d)==1?0x01010101:((d)==2?0x00010001:1))) ((m)*((d)==1?0x01010101:((d)==2?0x00010001:1)))
3555
3556# define S_MASK(p,d,s)((((((p)<4 ? ((0x80088822)>>(((3-(p))*8+(7-(0))) &
0x1f)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((p)<4 ?
((0x80088822)>>(((3-(p))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(p))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((p)<4 ? ((0x80088822)>>
(((3-(p))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(p))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((p)<4 ? ((0x80088822)>>(((3-(p))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((p)<4 ? ((0x80088822)>>(((3-(p))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((p)<4 ?
((0x80088822)>>(((3-(p))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(p))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((p)<4 ? ((0x80088822)>>
(((3-(p))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(p))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((p)<4 ? ((0x80088822)>>(((3-(p))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1)))
MASK_EXPAND(S_MASKx(p,0,d,s) + S_MASKx(p,1,d,s) +\((((((p)<4 ? ((0x80088822)>>(((3-(p))*8+(7-(0))) &
0x1f)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((p)<4 ?
((0x80088822)>>(((3-(p))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(p))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((p)<4 ? ((0x80088822)>>
(((3-(p))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(p))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((p)<4 ? ((0x80088822)>>(((3-(p))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((p)<4 ? ((0x80088822)>>(((3-(p))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((p)<4 ?
((0x80088822)>>(((3-(p))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(p))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((p)<4 ? ((0x80088822)>>
(((3-(p))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(p))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((p)<4 ? ((0x80088822)>>(((3-(p))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1)))
3557 S_MASKx(p,2,d,s) + S_MASKx(p,3,d,s) + S_MASKx(p,4,d,s) +\((((((p)<4 ? ((0x80088822)>>(((3-(p))*8+(7-(0))) &
0x1f)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((p)<4 ?
((0x80088822)>>(((3-(p))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(p))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((p)<4 ? ((0x80088822)>>
(((3-(p))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(p))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((p)<4 ? ((0x80088822)>>(((3-(p))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((p)<4 ? ((0x80088822)>>(((3-(p))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((p)<4 ?
((0x80088822)>>(((3-(p))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(p))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((p)<4 ? ((0x80088822)>>
(((3-(p))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(p))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((p)<4 ? ((0x80088822)>>(((3-(p))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1)))
3558 S_MASKx(p,5,d,s) + S_MASKx(p,6,d,s) + S_MASKx(p,7,d,s), d)((((((p)<4 ? ((0x80088822)>>(((3-(p))*8+(7-(0))) &
0x1f)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((p)<4 ?
((0x80088822)>>(((3-(p))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(p))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((p)<4 ? ((0x80088822)>>
(((3-(p))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(p))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((p)<4 ? ((0x80088822)>>(((3-(p))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((p)<4 ? ((0x80088822)>>(((3-(p))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((p)<4 ?
((0x80088822)>>(((3-(p))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(p))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((p)<4 ? ((0x80088822)>>
(((3-(p))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(p))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((p)<4 ? ((0x80088822)>>(((3-(p))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(p))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1)))
3559
3560# define B_MASK(p,d,s)((((((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+(7-(0))) &
0x1f)) : ((0xff55ff00)>>(((7-(p))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((p)<4 ?
((0xff0fff33)>>(((3-(p))*8+(7-(1))) & 0x1f)) : ((0xff55ff00
)>>(((7-(p))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((p)<4 ? ((0xff0fff33)>>
(((3-(p))*8+(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7
-(p))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+
(7-(3))) & 0x1f)) : ((0xff55ff00)>>(((7-(p))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+(7-(4))) &
0x1f)) : ((0xff55ff00)>>(((7-(p))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((p)<4 ?
((0xff0fff33)>>(((3-(p))*8+(7-(5))) & 0x1f)) : ((0xff55ff00
)>>(((7-(p))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((p)<4 ? ((0xff0fff33)>>
(((3-(p))*8+(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7
-(p))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+
(7-(7))) & 0x1f)) : ((0xff55ff00)>>(((7-(p))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1)))
MASK_EXPAND(B_MASKx(p,0,d,s) + B_MASKx(p,1,d,s) +\((((((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+(7-(0))) &
0x1f)) : ((0xff55ff00)>>(((7-(p))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((p)<4 ?
((0xff0fff33)>>(((3-(p))*8+(7-(1))) & 0x1f)) : ((0xff55ff00
)>>(((7-(p))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((p)<4 ? ((0xff0fff33)>>
(((3-(p))*8+(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7
-(p))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+
(7-(3))) & 0x1f)) : ((0xff55ff00)>>(((7-(p))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+(7-(4))) &
0x1f)) : ((0xff55ff00)>>(((7-(p))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((p)<4 ?
((0xff0fff33)>>(((3-(p))*8+(7-(5))) & 0x1f)) : ((0xff55ff00
)>>(((7-(p))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((p)<4 ? ((0xff0fff33)>>
(((3-(p))*8+(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7
-(p))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+
(7-(7))) & 0x1f)) : ((0xff55ff00)>>(((7-(p))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1)))
3561 B_MASKx(p,2,d,s) + B_MASKx(p,3,d,s) + B_MASKx(p,4,d,s) +\((((((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+(7-(0))) &
0x1f)) : ((0xff55ff00)>>(((7-(p))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((p)<4 ?
((0xff0fff33)>>(((3-(p))*8+(7-(1))) & 0x1f)) : ((0xff55ff00
)>>(((7-(p))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((p)<4 ? ((0xff0fff33)>>
(((3-(p))*8+(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7
-(p))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+
(7-(3))) & 0x1f)) : ((0xff55ff00)>>(((7-(p))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+(7-(4))) &
0x1f)) : ((0xff55ff00)>>(((7-(p))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((p)<4 ?
((0xff0fff33)>>(((3-(p))*8+(7-(5))) & 0x1f)) : ((0xff55ff00
)>>(((7-(p))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((p)<4 ? ((0xff0fff33)>>
(((3-(p))*8+(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7
-(p))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+
(7-(7))) & 0x1f)) : ((0xff55ff00)>>(((7-(p))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1)))
3562 B_MASKx(p,5,d,s) + B_MASKx(p,6,d,s) + B_MASKx(p,7,d,s), d)((((((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+(7-(0))) &
0x1f)) : ((0xff55ff00)>>(((7-(p))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((p)<4 ?
((0xff0fff33)>>(((3-(p))*8+(7-(1))) & 0x1f)) : ((0xff55ff00
)>>(((7-(p))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((p)<4 ? ((0xff0fff33)>>
(((3-(p))*8+(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7
-(p))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+
(7-(3))) & 0x1f)) : ((0xff55ff00)>>(((7-(p))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+(7-(4))) &
0x1f)) : ((0xff55ff00)>>(((7-(p))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((p)<4 ?
((0xff0fff33)>>(((3-(p))*8+(7-(5))) & 0x1f)) : ((0xff55ff00
)>>(((7-(p))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((p)<4 ? ((0xff0fff33)>>
(((3-(p))*8+(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7
-(p))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((p)<4 ? ((0xff0fff33)>>(((3-(p))*8+
(7-(7))) & 0x1f)) : ((0xff55ff00)>>(((7-(p))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1)))
3563
3564#if PNG_USE_COMPILE_TIME_MASKS1
3565 /* Utility macros to construct all the masks for a depth/swap
3566 * combination. The 's' parameter says whether the format is PNG
3567 * (big endian bytes) or not. Only the three odd-numbered passes are
3568 * required for the display/block algorithm.
3569 */
3570# define S_MASKS(d,s){ ((((((0)<4 ? ((0x80088822)>>(((3-(0))*8+(7-(0))) &
0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((0)<4 ?
((0x80088822)>>(((3-(0))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(0))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((0)<4 ? ((0x80088822)>>
(((3-(0))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(0))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((0)<4 ? ((0x80088822)>>(((3-(0))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((0)<4 ? ((0x80088822)>>(((3-(0))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((0)<4 ?
((0x80088822)>>(((3-(0))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(0))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((0)<4 ? ((0x80088822)>>
(((3-(0))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(0))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((0)<4 ? ((0x80088822)>>(((3-(0))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1))), ((((((1)<4 ? (
(0x80088822)>>(((3-(1))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(1))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((0)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((1)<4 ? ((0x80088822)>>
(((3-(1))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(1))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((1)<4 ? ((0x80088822)>>(((3-(1))*8+
(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((2)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((1)<4 ? ((0x80088822)>>(((3-(1))*8+(7-(3))) &
0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((1)<4 ?
((0x80088822)>>(((3-(1))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(1))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((4)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((1)<4 ? ((0x80088822)>>
(((3-(1))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(1))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((1)<4 ? ((0x80088822)>>(((3-(1))*8+
(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((6)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((1)<4 ? ((0x80088822)>>(((3-(1))*8+(7-(7))) &
0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))*((d)==1?0x01010101
:((d)==2?0x00010001:1))), ((((((2)<4 ? ((0x80088822)>>
(((3-(2))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(2))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((0)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((2)<4 ? ((0x80088822)>>(((3-(2))*8+
(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((1)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((2)<4 ? ((0x80088822)>>(((3-(2))*8+(7-(2))) &
0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((2)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((2)<4 ?
((0x80088822)>>(((3-(2))*8+(7-(3))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(2))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((3)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((2)<4 ? ((0x80088822)>>
(((3-(2))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(2))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((4)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((2)<4 ? ((0x80088822)>>(((3-(2))*8+
(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((5)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((2)<4 ? ((0x80088822)>>(((3-(2))*8+(7-(6))) &
0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((6)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((2)<4 ?
((0x80088822)>>(((3-(2))*8+(7-(7))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(2))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((7)*(d))^((s)?8-
(d):0))) & 0x1f))):0))*((d)==1?0x01010101:((d)==2?0x00010001
:1))), ((((((3)<4 ? ((0x80088822)>>(((3-(3))*8+(7-(0
))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(0))) &
0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((3)<4 ?
((0x80088822)>>(((3-(3))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(3))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((3)<4 ? ((0x80088822)>>
(((3-(3))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(3))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((3)<4 ? ((0x80088822)>>(((3-(3))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((3)<4 ? ((0x80088822)>>(((3-(3))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((3)<4 ?
((0x80088822)>>(((3-(3))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(3))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((3)<4 ? ((0x80088822)>>
(((3-(3))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(3))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((3)<4 ? ((0x80088822)>>(((3-(3))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1))), ((((((4)<4 ? (
(0x80088822)>>(((3-(4))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(4))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((0)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((4)<4 ? ((0x80088822)>>
(((3-(4))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(4))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((4)<4 ? ((0x80088822)>>(((3-(4))*8+
(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((2)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((4)<4 ? ((0x80088822)>>(((3-(4))*8+(7-(3))) &
0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((4)<4 ?
((0x80088822)>>(((3-(4))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(4))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((4)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((4)<4 ? ((0x80088822)>>
(((3-(4))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(4))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((4)<4 ? ((0x80088822)>>(((3-(4))*8+
(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((6)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((4)<4 ? ((0x80088822)>>(((3-(4))*8+(7-(7))) &
0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))*((d)==1?0x01010101
:((d)==2?0x00010001:1))), ((((((5)<4 ? ((0x80088822)>>
(((3-(5))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(5))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((0)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((5)<4 ? ((0x80088822)>>(((3-(5))*8+
(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((1)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((5)<4 ? ((0x80088822)>>(((3-(5))*8+(7-(2))) &
0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((2)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((5)<4 ?
((0x80088822)>>(((3-(5))*8+(7-(3))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(5))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((3)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((5)<4 ? ((0x80088822)>>
(((3-(5))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(5))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((4)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((5)<4 ? ((0x80088822)>>(((3-(5))*8+
(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((5)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((5)<4 ? ((0x80088822)>>(((3-(5))*8+(7-(6))) &
0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((6)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((5)<4 ?
((0x80088822)>>(((3-(5))*8+(7-(7))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(5))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((7)*(d))^((s)?8-
(d):0))) & 0x1f))):0))*((d)==1?0x01010101:((d)==2?0x00010001
:1))) }
{ S_MASK(0,d,s)((((((0)<4 ? ((0x80088822)>>(((3-(0))*8+(7-(0))) &
0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((0)<4 ?
((0x80088822)>>(((3-(0))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(0))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((0)<4 ? ((0x80088822)>>
(((3-(0))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(0))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((0)<4 ? ((0x80088822)>>(((3-(0))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((0)<4 ? ((0x80088822)>>(((3-(0))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((0)<4 ?
((0x80088822)>>(((3-(0))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(0))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((0)<4 ? ((0x80088822)>>
(((3-(0))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(0))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((0)<4 ? ((0x80088822)>>(((3-(0))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1)))
, S_MASK(1,d,s)((((((1)<4 ? ((0x80088822)>>(((3-(1))*8+(7-(0))) &
0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((1)<4 ?
((0x80088822)>>(((3-(1))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(1))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((1)<4 ? ((0x80088822)>>
(((3-(1))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(1))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((1)<4 ? ((0x80088822)>>(((3-(1))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((1)<4 ? ((0x80088822)>>(((3-(1))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((1)<4 ?
((0x80088822)>>(((3-(1))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(1))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((1)<4 ? ((0x80088822)>>
(((3-(1))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(1))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((1)<4 ? ((0x80088822)>>(((3-(1))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1)))
, S_MASK(2,d,s)((((((2)<4 ? ((0x80088822)>>(((3-(2))*8+(7-(0))) &
0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((2)<4 ?
((0x80088822)>>(((3-(2))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(2))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((2)<4 ? ((0x80088822)>>
(((3-(2))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(2))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((2)<4 ? ((0x80088822)>>(((3-(2))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((2)<4 ? ((0x80088822)>>(((3-(2))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((2)<4 ?
((0x80088822)>>(((3-(2))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(2))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((2)<4 ? ((0x80088822)>>
(((3-(2))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(2))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((2)<4 ? ((0x80088822)>>(((3-(2))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1)))
,\
3571 S_MASK(3,d,s)((((((3)<4 ? ((0x80088822)>>(((3-(3))*8+(7-(0))) &
0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((3)<4 ?
((0x80088822)>>(((3-(3))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(3))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((3)<4 ? ((0x80088822)>>
(((3-(3))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(3))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((3)<4 ? ((0x80088822)>>(((3-(3))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((3)<4 ? ((0x80088822)>>(((3-(3))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((3)<4 ?
((0x80088822)>>(((3-(3))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(3))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((3)<4 ? ((0x80088822)>>
(((3-(3))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(3))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((3)<4 ? ((0x80088822)>>(((3-(3))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1)))
, S_MASK(4,d,s)((((((4)<4 ? ((0x80088822)>>(((3-(4))*8+(7-(0))) &
0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((4)<4 ?
((0x80088822)>>(((3-(4))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(4))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((4)<4 ? ((0x80088822)>>
(((3-(4))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(4))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((4)<4 ? ((0x80088822)>>(((3-(4))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((4)<4 ? ((0x80088822)>>(((3-(4))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((4)<4 ?
((0x80088822)>>(((3-(4))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(4))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((4)<4 ? ((0x80088822)>>
(((3-(4))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(4))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((4)<4 ? ((0x80088822)>>(((3-(4))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1)))
, S_MASK(5,d,s)((((((5)<4 ? ((0x80088822)>>(((3-(5))*8+(7-(0))) &
0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((5)<4 ?
((0x80088822)>>(((3-(5))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(5))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((5)<4 ? ((0x80088822)>>
(((3-(5))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(5))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((5)<4 ? ((0x80088822)>>(((3-(5))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((5)<4 ? ((0x80088822)>>(((3-(5))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((5)<4 ?
((0x80088822)>>(((3-(5))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(5))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((5)<4 ? ((0x80088822)>>
(((3-(5))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(5))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((5)<4 ? ((0x80088822)>>(((3-(5))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1)))
}
3572
3573# define B_MASKS(d,s){ ((((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+(7-(0))) &
0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((1)<4 ?
((0xff0fff33)>>(((3-(1))*8+(7-(1))) & 0x1f)) : ((0xff55ff00
)>>(((7-(1))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>
(((3-(1))*8+(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7
-(1))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+
(7-(3))) & 0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+(7-(4))) &
0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((1)<4 ?
((0xff0fff33)>>(((3-(1))*8+(7-(5))) & 0x1f)) : ((0xff55ff00
)>>(((7-(1))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>
(((3-(1))*8+(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7
-(1))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+
(7-(7))) & 0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1))), ((((((3)<4 ? (
(0xff0fff33)>>(((3-(3))*8+(7-(0))) & 0x1f)) : ((0xff55ff00
)>>(((7-(3))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((0)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>
(((3-(3))*8+(7-(1))) & 0x1f)) : ((0xff55ff00)>>(((7
-(3))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+
(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((2)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+(7-(3))) &
0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((3)<4 ?
((0xff0fff33)>>(((3-(3))*8+(7-(4))) & 0x1f)) : ((0xff55ff00
)>>(((7-(3))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((4)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>
(((3-(3))*8+(7-(5))) & 0x1f)) : ((0xff55ff00)>>(((7
-(3))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+
(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((6)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+(7-(7))) &
0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))*((d)==1?0x01010101
:((d)==2?0x00010001:1))), ((((((5)<4 ? ((0xff0fff33)>>
(((3-(5))*8+(7-(0))) & 0x1f)) : ((0xff55ff00)>>(((7
-(5))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((0)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+
(7-(1))) & 0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((1)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+(7-(2))) &
0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((2)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((5)<4 ?
((0xff0fff33)>>(((3-(5))*8+(7-(3))) & 0x1f)) : ((0xff55ff00
)>>(((7-(5))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((3)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>
(((3-(5))*8+(7-(4))) & 0x1f)) : ((0xff55ff00)>>(((7
-(5))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((4)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+
(7-(5))) & 0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((5)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+(7-(6))) &
0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((6)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((5)<4 ?
((0xff0fff33)>>(((3-(5))*8+(7-(7))) & 0x1f)) : ((0xff55ff00
)>>(((7-(5))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((7)*(d))^((s)?8-
(d):0))) & 0x1f))):0))*((d)==1?0x01010101:((d)==2?0x00010001
:1))) }
{ B_MASK(1,d,s)((((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+(7-(0))) &
0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((1)<4 ?
((0xff0fff33)>>(((3-(1))*8+(7-(1))) & 0x1f)) : ((0xff55ff00
)>>(((7-(1))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>
(((3-(1))*8+(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7
-(1))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+
(7-(3))) & 0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+(7-(4))) &
0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((1)<4 ?
((0xff0fff33)>>(((3-(1))*8+(7-(5))) & 0x1f)) : ((0xff55ff00
)>>(((7-(1))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>
(((3-(1))*8+(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7
-(1))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+
(7-(7))) & 0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1)))
, B_MASK(3,d,s)((((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+(7-(0))) &
0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((3)<4 ?
((0xff0fff33)>>(((3-(3))*8+(7-(1))) & 0x1f)) : ((0xff55ff00
)>>(((7-(3))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>
(((3-(3))*8+(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7
-(3))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+
(7-(3))) & 0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+(7-(4))) &
0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((3)<4 ?
((0xff0fff33)>>(((3-(3))*8+(7-(5))) & 0x1f)) : ((0xff55ff00
)>>(((7-(3))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>
(((3-(3))*8+(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7
-(3))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+
(7-(7))) & 0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1)))
, B_MASK(5,d,s)((((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+(7-(0))) &
0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((0)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((5)<4 ?
((0xff0fff33)>>(((3-(5))*8+(7-(1))) & 0x1f)) : ((0xff55ff00
)>>(((7-(5))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((1)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>
(((3-(5))*8+(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7
-(5))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((2)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+
(7-(3))) & 0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((3)*(d))^((s)?8-(d):0))) & 0x1f))):0) +
((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+(7-(4))) &
0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((d)) & 0x1f)))-1))<<
(((((4)*(d))^((s)?8-(d):0))) & 0x1f))):0) + ((((5)<4 ?
((0xff0fff33)>>(((3-(5))*8+(7-(5))) & 0x1f)) : ((0xff55ff00
)>>(((7-(5))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((d)) & 0x1f)))-1))<<(((((5)*(d))^((s)?8-
(d):0))) & 0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>
(((3-(5))*8+(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7
-(5))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
d)) & 0x1f)))-1))<<(((((6)*(d))^((s)?8-(d):0))) &
0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+
(7-(7))) & 0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((d)) & 0x1f
)))-1))<<(((((7)*(d))^((s)?8-(d):0))) & 0x1f))):0))
*((d)==1?0x01010101:((d)==2?0x00010001:1)))
}
3574
3575# define DEPTH_INDEX(d)((d)==1?0:((d)==2?1:2)) ((d)==1?0:((d)==2?1:2))
3576
3577 /* Hence the pre-compiled masks indexed by PACKSWAP (or not), depth and
3578 * then pass:
3579 */
3580 static const png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] =
3581 {
3582 /* Little-endian byte masks for PACKSWAP */
3583 { S_MASKS(1,0){ ((((((0)<4 ? ((0x80088822)>>(((3-(0))*8+(7-(0))) &
0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((0)*(1))^((0)?8-(1):0))) & 0x1f))):0) + ((((0)<4 ?
((0x80088822)>>(((3-(0))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(0))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((1)*(1))^((0)?8-
(1):0))) & 0x1f))):0) + ((((0)<4 ? ((0x80088822)>>
(((3-(0))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(0))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((2)*(1))^((0)?8-(1):0))) &
0x1f))):0) + ((((0)<4 ? ((0x80088822)>>(((3-(0))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((3)*(1))^((0)?8-(1):0))) & 0x1f))):0) +
((((0)<4 ? ((0x80088822)>>(((3-(0))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((4)*(1))^((0)?8-(1):0))) & 0x1f))):0) + ((((0)<4 ?
((0x80088822)>>(((3-(0))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(0))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((5)*(1))^((0)?8-
(1):0))) & 0x1f))):0) + ((((0)<4 ? ((0x80088822)>>
(((3-(0))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(0))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((6)*(1))^((0)?8-(1):0))) &
0x1f))):0) + ((((0)<4 ? ((0x80088822)>>(((3-(0))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((7)*(1))^((0)?8-(1):0))) & 0x1f))):0))
*((1)==1?0x01010101:((1)==2?0x00010001:1))), ((((((1)<4 ? (
(0x80088822)>>(((3-(1))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(1))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((0)*(1))^((0)?8-
(1):0))) & 0x1f))):0) + ((((1)<4 ? ((0x80088822)>>
(((3-(1))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(1))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((1)*(1))^((0)?8-(1):0))) &
0x1f))):0) + ((((1)<4 ? ((0x80088822)>>(((3-(1))*8+
(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((2)*(1))^((0)?8-(1):0))) & 0x1f))):0) +
((((1)<4 ? ((0x80088822)>>(((3-(1))*8+(7-(3))) &
0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((3)*(1))^((0)?8-(1):0))) & 0x1f))):0) + ((((1)<4 ?
((0x80088822)>>(((3-(1))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(1))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((4)*(1))^((0)?8-
(1):0))) & 0x1f))):0) + ((((1)<4 ? ((0x80088822)>>
(((3-(1))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(1))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((5)*(1))^((0)?8-(1):0))) &
0x1f))):0) + ((((1)<4 ? ((0x80088822)>>(((3-(1))*8+
(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((6)*(1))^((0)?8-(1):0))) & 0x1f))):0) +
((((1)<4 ? ((0x80088822)>>(((3-(1))*8+(7-(7))) &
0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((7)*(1))^((0)?8-(1):0))) & 0x1f))):0))*((1)==1?0x01010101
:((1)==2?0x00010001:1))), ((((((2)<4 ? ((0x80088822)>>
(((3-(2))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(2))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((0)*(1))^((0)?8-(1):0))) &
0x1f))):0) + ((((2)<4 ? ((0x80088822)>>(((3-(2))*8+
(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((1)*(1))^((0)?8-(1):0))) & 0x1f))):0) +
((((2)<4 ? ((0x80088822)>>(((3-(2))*8+(7-(2))) &
0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((2)*(1))^((0)?8-(1):0))) & 0x1f))):0) + ((((2)<4 ?
((0x80088822)>>(((3-(2))*8+(7-(3))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(2))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((3)*(1))^((0)?8-
(1):0))) & 0x1f))):0) + ((((2)<4 ? ((0x80088822)>>
(((3-(2))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(2))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((4)*(1))^((0)?8-(1):0))) &
0x1f))):0) + ((((2)<4 ? ((0x80088822)>>(((3-(2))*8+
(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((5)*(1))^((0)?8-(1):0))) & 0x1f))):0) +
((((2)<4 ? ((0x80088822)>>(((3-(2))*8+(7-(6))) &
0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((6)*(1))^((0)?8-(1):0))) & 0x1f))):0) + ((((2)<4 ?
((0x80088822)>>(((3-(2))*8+(7-(7))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(2))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((7)*(1))^((0)?8-
(1):0))) & 0x1f))):0))*((1)==1?0x01010101:((1)==2?0x00010001
:1))), ((((((3)<4 ? ((0x80088822)>>(((3-(3))*8+(7-(0
))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(0))) &
0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((0)*(1))^((0)?8-(1):0))) & 0x1f))):0) + ((((3)<4 ?
((0x80088822)>>(((3-(3))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(3))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((1)*(1))^((0)?8-
(1):0))) & 0x1f))):0) + ((((3)<4 ? ((0x80088822)>>
(((3-(3))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(3))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((2)*(1))^((0)?8-(1):0))) &
0x1f))):0) + ((((3)<4 ? ((0x80088822)>>(((3-(3))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((3)*(1))^((0)?8-(1):0))) & 0x1f))):0) +
((((3)<4 ? ((0x80088822)>>(((3-(3))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((4)*(1))^((0)?8-(1):0))) & 0x1f))):0) + ((((3)<4 ?
((0x80088822)>>(((3-(3))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(3))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((5)*(1))^((0)?8-
(1):0))) & 0x1f))):0) + ((((3)<4 ? ((0x80088822)>>
(((3-(3))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(3))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((6)*(1))^((0)?8-(1):0))) &
0x1f))):0) + ((((3)<4 ? ((0x80088822)>>(((3-(3))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((7)*(1))^((0)?8-(1):0))) & 0x1f))):0))
*((1)==1?0x01010101:((1)==2?0x00010001:1))), ((((((4)<4 ? (
(0x80088822)>>(((3-(4))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(4))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((0)*(1))^((0)?8-
(1):0))) & 0x1f))):0) + ((((4)<4 ? ((0x80088822)>>
(((3-(4))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(4))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((1)*(1))^((0)?8-(1):0))) &
0x1f))):0) + ((((4)<4 ? ((0x80088822)>>(((3-(4))*8+
(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((2)*(1))^((0)?8-(1):0))) & 0x1f))):0) +
((((4)<4 ? ((0x80088822)>>(((3-(4))*8+(7-(3))) &
0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((3)*(1))^((0)?8-(1):0))) & 0x1f))):0) + ((((4)<4 ?
((0x80088822)>>(((3-(4))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(4))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((4)*(1))^((0)?8-
(1):0))) & 0x1f))):0) + ((((4)<4 ? ((0x80088822)>>
(((3-(4))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(4))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((5)*(1))^((0)?8-(1):0))) &
0x1f))):0) + ((((4)<4 ? ((0x80088822)>>(((3-(4))*8+
(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((6)*(1))^((0)?8-(1):0))) & 0x1f))):0) +
((((4)<4 ? ((0x80088822)>>(((3-(4))*8+(7-(7))) &
0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((7)*(1))^((0)?8-(1):0))) & 0x1f))):0))*((1)==1?0x01010101
:((1)==2?0x00010001:1))), ((((((5)<4 ? ((0x80088822)>>
(((3-(5))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(5))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((0)*(1))^((0)?8-(1):0))) &
0x1f))):0) + ((((5)<4 ? ((0x80088822)>>(((3-(5))*8+
(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((1)*(1))^((0)?8-(1):0))) & 0x1f))):0) +
((((5)<4 ? ((0x80088822)>>(((3-(5))*8+(7-(2))) &
0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((2)*(1))^((0)?8-(1):0))) & 0x1f))):0) + ((((5)<4 ?
((0x80088822)>>(((3-(5))*8+(7-(3))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(5))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((3)*(1))^((0)?8-
(1):0))) & 0x1f))):0) + ((((5)<4 ? ((0x80088822)>>
(((3-(5))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(5))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((4)*(1))^((0)?8-(1):0))) &
0x1f))):0) + ((((5)<4 ? ((0x80088822)>>(((3-(5))*8+
(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((5)*(1))^((0)?8-(1):0))) & 0x1f))):0) +
((((5)<4 ? ((0x80088822)>>(((3-(5))*8+(7-(6))) &
0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((6)*(1))^((0)?8-(1):0))) & 0x1f))):0) + ((((5)<4 ?
((0x80088822)>>(((3-(5))*8+(7-(7))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(5))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((7)*(1))^((0)?8-
(1):0))) & 0x1f))):0))*((1)==1?0x01010101:((1)==2?0x00010001
:1))) }
, S_MASKS(2,0){ ((((((0)<4 ? ((0x80088822)>>(((3-(0))*8+(7-(0))) &
0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((0)*(2))^((0)?8-(2):0))) & 0x1f))):0) + ((((0)<4 ?
((0x80088822)>>(((3-(0))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(0))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((1)*(2))^((0)?8-
(2):0))) & 0x1f))):0) + ((((0)<4 ? ((0x80088822)>>
(((3-(0))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(0))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((2)*(2))^((0)?8-(2):0))) &
0x1f))):0) + ((((0)<4 ? ((0x80088822)>>(((3-(0))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((3)*(2))^((0)?8-(2):0))) & 0x1f))):0) +
((((0)<4 ? ((0x80088822)>>(((3-(0))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((4)*(2))^((0)?8-(2):0))) & 0x1f))):0) + ((((0)<4 ?
((0x80088822)>>(((3-(0))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(0))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((5)*(2))^((0)?8-
(2):0))) & 0x1f))):0) + ((((0)<4 ? ((0x80088822)>>
(((3-(0))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(0))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((6)*(2))^((0)?8-(2):0))) &
0x1f))):0) + ((((0)<4 ? ((0x80088822)>>(((3-(0))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((7)*(2))^((0)?8-(2):0))) & 0x1f))):0))
*((2)==1?0x01010101:((2)==2?0x00010001:1))), ((((((1)<4 ? (
(0x80088822)>>(((3-(1))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(1))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((0)*(2))^((0)?8-
(2):0))) & 0x1f))):0) + ((((1)<4 ? ((0x80088822)>>
(((3-(1))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(1))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((1)*(2))^((0)?8-(2):0))) &
0x1f))):0) + ((((1)<4 ? ((0x80088822)>>(((3-(1))*8+
(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((2)*(2))^((0)?8-(2):0))) & 0x1f))):0) +
((((1)<4 ? ((0x80088822)>>(((3-(1))*8+(7-(3))) &
0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((3)*(2))^((0)?8-(2):0))) & 0x1f))):0) + ((((1)<4 ?
((0x80088822)>>(((3-(1))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(1))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((4)*(2))^((0)?8-
(2):0))) & 0x1f))):0) + ((((1)<4 ? ((0x80088822)>>
(((3-(1))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(1))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((5)*(2))^((0)?8-(2):0))) &
0x1f))):0) + ((((1)<4 ? ((0x80088822)>>(((3-(1))*8+
(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((6)*(2))^((0)?8-(2):0))) & 0x1f))):0) +
((((1)<4 ? ((0x80088822)>>(((3-(1))*8+(7-(7))) &
0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((7)*(2))^((0)?8-(2):0))) & 0x1f))):0))*((2)==1?0x01010101
:((2)==2?0x00010001:1))), ((((((2)<4 ? ((0x80088822)>>
(((3-(2))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(2))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((0)*(2))^((0)?8-(2):0))) &
0x1f))):0) + ((((2)<4 ? ((0x80088822)>>(((3-(2))*8+
(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((1)*(2))^((0)?8-(2):0))) & 0x1f))):0) +
((((2)<4 ? ((0x80088822)>>(((3-(2))*8+(7-(2))) &
0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((2)*(2))^((0)?8-(2):0))) & 0x1f))):0) + ((((2)<4 ?
((0x80088822)>>(((3-(2))*8+(7-(3))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(2))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((3)*(2))^((0)?8-
(2):0))) & 0x1f))):0) + ((((2)<4 ? ((0x80088822)>>
(((3-(2))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(2))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((4)*(2))^((0)?8-(2):0))) &
0x1f))):0) + ((((2)<4 ? ((0x80088822)>>(((3-(2))*8+
(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((5)*(2))^((0)?8-(2):0))) & 0x1f))):0) +
((((2)<4 ? ((0x80088822)>>(((3-(2))*8+(7-(6))) &
0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((6)*(2))^((0)?8-(2):0))) & 0x1f))):0) + ((((2)<4 ?
((0x80088822)>>(((3-(2))*8+(7-(7))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(2))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((7)*(2))^((0)?8-
(2):0))) & 0x1f))):0))*((2)==1?0x01010101:((2)==2?0x00010001
:1))), ((((((3)<4 ? ((0x80088822)>>(((3-(3))*8+(7-(0
))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(0))) &
0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((0)*(2))^((0)?8-(2):0))) & 0x1f))):0) + ((((3)<4 ?
((0x80088822)>>(((3-(3))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(3))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((1)*(2))^((0)?8-
(2):0))) & 0x1f))):0) + ((((3)<4 ? ((0x80088822)>>
(((3-(3))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(3))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((2)*(2))^((0)?8-(2):0))) &
0x1f))):0) + ((((3)<4 ? ((0x80088822)>>(((3-(3))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((3)*(2))^((0)?8-(2):0))) & 0x1f))):0) +
((((3)<4 ? ((0x80088822)>>(((3-(3))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((4)*(2))^((0)?8-(2):0))) & 0x1f))):0) + ((((3)<4 ?
((0x80088822)>>(((3-(3))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(3))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((5)*(2))^((0)?8-
(2):0))) & 0x1f))):0) + ((((3)<4 ? ((0x80088822)>>
(((3-(3))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(3))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((6)*(2))^((0)?8-(2):0))) &
0x1f))):0) + ((((3)<4 ? ((0x80088822)>>(((3-(3))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((7)*(2))^((0)?8-(2):0))) & 0x1f))):0))
*((2)==1?0x01010101:((2)==2?0x00010001:1))), ((((((4)<4 ? (
(0x80088822)>>(((3-(4))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(4))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((0)*(2))^((0)?8-
(2):0))) & 0x1f))):0) + ((((4)<4 ? ((0x80088822)>>
(((3-(4))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(4))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((1)*(2))^((0)?8-(2):0))) &
0x1f))):0) + ((((4)<4 ? ((0x80088822)>>(((3-(4))*8+
(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((2)*(2))^((0)?8-(2):0))) & 0x1f))):0) +
((((4)<4 ? ((0x80088822)>>(((3-(4))*8+(7-(3))) &
0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((3)*(2))^((0)?8-(2):0))) & 0x1f))):0) + ((((4)<4 ?
((0x80088822)>>(((3-(4))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(4))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((4)*(2))^((0)?8-
(2):0))) & 0x1f))):0) + ((((4)<4 ? ((0x80088822)>>
(((3-(4))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(4))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((5)*(2))^((0)?8-(2):0))) &
0x1f))):0) + ((((4)<4 ? ((0x80088822)>>(((3-(4))*8+
(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((6)*(2))^((0)?8-(2):0))) & 0x1f))):0) +
((((4)<4 ? ((0x80088822)>>(((3-(4))*8+(7-(7))) &
0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((7)*(2))^((0)?8-(2):0))) & 0x1f))):0))*((2)==1?0x01010101
:((2)==2?0x00010001:1))), ((((((5)<4 ? ((0x80088822)>>
(((3-(5))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(5))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((0)*(2))^((0)?8-(2):0))) &
0x1f))):0) + ((((5)<4 ? ((0x80088822)>>(((3-(5))*8+
(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((1)*(2))^((0)?8-(2):0))) & 0x1f))):0) +
((((5)<4 ? ((0x80088822)>>(((3-(5))*8+(7-(2))) &
0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((2)*(2))^((0)?8-(2):0))) & 0x1f))):0) + ((((5)<4 ?
((0x80088822)>>(((3-(5))*8+(7-(3))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(5))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((3)*(2))^((0)?8-
(2):0))) & 0x1f))):0) + ((((5)<4 ? ((0x80088822)>>
(((3-(5))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(5))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((4)*(2))^((0)?8-(2):0))) &
0x1f))):0) + ((((5)<4 ? ((0x80088822)>>(((3-(5))*8+
(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((5)*(2))^((0)?8-(2):0))) & 0x1f))):0) +
((((5)<4 ? ((0x80088822)>>(((3-(5))*8+(7-(6))) &
0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((6)*(2))^((0)?8-(2):0))) & 0x1f))):0) + ((((5)<4 ?
((0x80088822)>>(((3-(5))*8+(7-(7))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(5))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((7)*(2))^((0)?8-
(2):0))) & 0x1f))):0))*((2)==1?0x01010101:((2)==2?0x00010001
:1))) }
, S_MASKS(4,0){ ((((((0)<4 ? ((0x80088822)>>(((3-(0))*8+(7-(0))) &
0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((0)*(4))^((0)?8-(4):0))) & 0x1f))):0) + ((((0)<4 ?
((0x80088822)>>(((3-(0))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(0))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((1)*(4))^((0)?8-
(4):0))) & 0x1f))):0) + ((((0)<4 ? ((0x80088822)>>
(((3-(0))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(0))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((2)*(4))^((0)?8-(4):0))) &
0x1f))):0) + ((((0)<4 ? ((0x80088822)>>(((3-(0))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((3)*(4))^((0)?8-(4):0))) & 0x1f))):0) +
((((0)<4 ? ((0x80088822)>>(((3-(0))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((4)*(4))^((0)?8-(4):0))) & 0x1f))):0) + ((((0)<4 ?
((0x80088822)>>(((3-(0))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(0))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((5)*(4))^((0)?8-
(4):0))) & 0x1f))):0) + ((((0)<4 ? ((0x80088822)>>
(((3-(0))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(0))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((6)*(4))^((0)?8-(4):0))) &
0x1f))):0) + ((((0)<4 ? ((0x80088822)>>(((3-(0))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((7)*(4))^((0)?8-(4):0))) & 0x1f))):0))
*((4)==1?0x01010101:((4)==2?0x00010001:1))), ((((((1)<4 ? (
(0x80088822)>>(((3-(1))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(1))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((0)*(4))^((0)?8-
(4):0))) & 0x1f))):0) + ((((1)<4 ? ((0x80088822)>>
(((3-(1))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(1))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((1)*(4))^((0)?8-(4):0))) &
0x1f))):0) + ((((1)<4 ? ((0x80088822)>>(((3-(1))*8+
(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((2)*(4))^((0)?8-(4):0))) & 0x1f))):0) +
((((1)<4 ? ((0x80088822)>>(((3-(1))*8+(7-(3))) &
0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((3)*(4))^((0)?8-(4):0))) & 0x1f))):0) + ((((1)<4 ?
((0x80088822)>>(((3-(1))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(1))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((4)*(4))^((0)?8-
(4):0))) & 0x1f))):0) + ((((1)<4 ? ((0x80088822)>>
(((3-(1))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(1))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((5)*(4))^((0)?8-(4):0))) &
0x1f))):0) + ((((1)<4 ? ((0x80088822)>>(((3-(1))*8+
(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((6)*(4))^((0)?8-(4):0))) & 0x1f))):0) +
((((1)<4 ? ((0x80088822)>>(((3-(1))*8+(7-(7))) &
0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((7)*(4))^((0)?8-(4):0))) & 0x1f))):0))*((4)==1?0x01010101
:((4)==2?0x00010001:1))), ((((((2)<4 ? ((0x80088822)>>
(((3-(2))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(2))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((0)*(4))^((0)?8-(4):0))) &
0x1f))):0) + ((((2)<4 ? ((0x80088822)>>(((3-(2))*8+
(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((1)*(4))^((0)?8-(4):0))) & 0x1f))):0) +
((((2)<4 ? ((0x80088822)>>(((3-(2))*8+(7-(2))) &
0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((2)*(4))^((0)?8-(4):0))) & 0x1f))):0) + ((((2)<4 ?
((0x80088822)>>(((3-(2))*8+(7-(3))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(2))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((3)*(4))^((0)?8-
(4):0))) & 0x1f))):0) + ((((2)<4 ? ((0x80088822)>>
(((3-(2))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(2))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((4)*(4))^((0)?8-(4):0))) &
0x1f))):0) + ((((2)<4 ? ((0x80088822)>>(((3-(2))*8+
(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((5)*(4))^((0)?8-(4):0))) & 0x1f))):0) +
((((2)<4 ? ((0x80088822)>>(((3-(2))*8+(7-(6))) &
0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((6)*(4))^((0)?8-(4):0))) & 0x1f))):0) + ((((2)<4 ?
((0x80088822)>>(((3-(2))*8+(7-(7))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(2))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((7)*(4))^((0)?8-
(4):0))) & 0x1f))):0))*((4)==1?0x01010101:((4)==2?0x00010001
:1))), ((((((3)<4 ? ((0x80088822)>>(((3-(3))*8+(7-(0
))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(0))) &
0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((0)*(4))^((0)?8-(4):0))) & 0x1f))):0) + ((((3)<4 ?
((0x80088822)>>(((3-(3))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(3))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((1)*(4))^((0)?8-
(4):0))) & 0x1f))):0) + ((((3)<4 ? ((0x80088822)>>
(((3-(3))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(3))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((2)*(4))^((0)?8-(4):0))) &
0x1f))):0) + ((((3)<4 ? ((0x80088822)>>(((3-(3))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((3)*(4))^((0)?8-(4):0))) & 0x1f))):0) +
((((3)<4 ? ((0x80088822)>>(((3-(3))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((4)*(4))^((0)?8-(4):0))) & 0x1f))):0) + ((((3)<4 ?
((0x80088822)>>(((3-(3))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(3))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((5)*(4))^((0)?8-
(4):0))) & 0x1f))):0) + ((((3)<4 ? ((0x80088822)>>
(((3-(3))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(3))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((6)*(4))^((0)?8-(4):0))) &
0x1f))):0) + ((((3)<4 ? ((0x80088822)>>(((3-(3))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((7)*(4))^((0)?8-(4):0))) & 0x1f))):0))
*((4)==1?0x01010101:((4)==2?0x00010001:1))), ((((((4)<4 ? (
(0x80088822)>>(((3-(4))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(4))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((0)*(4))^((0)?8-
(4):0))) & 0x1f))):0) + ((((4)<4 ? ((0x80088822)>>
(((3-(4))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(4))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((1)*(4))^((0)?8-(4):0))) &
0x1f))):0) + ((((4)<4 ? ((0x80088822)>>(((3-(4))*8+
(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((2)*(4))^((0)?8-(4):0))) & 0x1f))):0) +
((((4)<4 ? ((0x80088822)>>(((3-(4))*8+(7-(3))) &
0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((3)*(4))^((0)?8-(4):0))) & 0x1f))):0) + ((((4)<4 ?
((0x80088822)>>(((3-(4))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(4))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((4)*(4))^((0)?8-
(4):0))) & 0x1f))):0) + ((((4)<4 ? ((0x80088822)>>
(((3-(4))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(4))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((5)*(4))^((0)?8-(4):0))) &
0x1f))):0) + ((((4)<4 ? ((0x80088822)>>(((3-(4))*8+
(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((6)*(4))^((0)?8-(4):0))) & 0x1f))):0) +
((((4)<4 ? ((0x80088822)>>(((3-(4))*8+(7-(7))) &
0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((7)*(4))^((0)?8-(4):0))) & 0x1f))):0))*((4)==1?0x01010101
:((4)==2?0x00010001:1))), ((((((5)<4 ? ((0x80088822)>>
(((3-(5))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(5))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((0)*(4))^((0)?8-(4):0))) &
0x1f))):0) + ((((5)<4 ? ((0x80088822)>>(((3-(5))*8+
(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((1)*(4))^((0)?8-(4):0))) & 0x1f))):0) +
((((5)<4 ? ((0x80088822)>>(((3-(5))*8+(7-(2))) &
0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((2)*(4))^((0)?8-(4):0))) & 0x1f))):0) + ((((5)<4 ?
((0x80088822)>>(((3-(5))*8+(7-(3))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(5))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((3)*(4))^((0)?8-
(4):0))) & 0x1f))):0) + ((((5)<4 ? ((0x80088822)>>
(((3-(5))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(5))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((4)*(4))^((0)?8-(4):0))) &
0x1f))):0) + ((((5)<4 ? ((0x80088822)>>(((3-(5))*8+
(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((5)*(4))^((0)?8-(4):0))) & 0x1f))):0) +
((((5)<4 ? ((0x80088822)>>(((3-(5))*8+(7-(6))) &
0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((6)*(4))^((0)?8-(4):0))) & 0x1f))):0) + ((((5)<4 ?
((0x80088822)>>(((3-(5))*8+(7-(7))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(5))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((7)*(4))^((0)?8-
(4):0))) & 0x1f))):0))*((4)==1?0x01010101:((4)==2?0x00010001
:1))) }
},
3584 /* Normal (big-endian byte) masks - PNG format */
3585 { S_MASKS(1,1){ ((((((0)<4 ? ((0x80088822)>>(((3-(0))*8+(7-(0))) &
0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((0)*(1))^((1)?8-(1):0))) & 0x1f))):0) + ((((0)<4 ?
((0x80088822)>>(((3-(0))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(0))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((1)*(1))^((1)?8-
(1):0))) & 0x1f))):0) + ((((0)<4 ? ((0x80088822)>>
(((3-(0))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(0))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((2)*(1))^((1)?8-(1):0))) &
0x1f))):0) + ((((0)<4 ? ((0x80088822)>>(((3-(0))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((3)*(1))^((1)?8-(1):0))) & 0x1f))):0) +
((((0)<4 ? ((0x80088822)>>(((3-(0))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((4)*(1))^((1)?8-(1):0))) & 0x1f))):0) + ((((0)<4 ?
((0x80088822)>>(((3-(0))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(0))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((5)*(1))^((1)?8-
(1):0))) & 0x1f))):0) + ((((0)<4 ? ((0x80088822)>>
(((3-(0))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(0))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((6)*(1))^((1)?8-(1):0))) &
0x1f))):0) + ((((0)<4 ? ((0x80088822)>>(((3-(0))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((7)*(1))^((1)?8-(1):0))) & 0x1f))):0))
*((1)==1?0x01010101:((1)==2?0x00010001:1))), ((((((1)<4 ? (
(0x80088822)>>(((3-(1))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(1))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((0)*(1))^((1)?8-
(1):0))) & 0x1f))):0) + ((((1)<4 ? ((0x80088822)>>
(((3-(1))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(1))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((1)*(1))^((1)?8-(1):0))) &
0x1f))):0) + ((((1)<4 ? ((0x80088822)>>(((3-(1))*8+
(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((2)*(1))^((1)?8-(1):0))) & 0x1f))):0) +
((((1)<4 ? ((0x80088822)>>(((3-(1))*8+(7-(3))) &
0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((3)*(1))^((1)?8-(1):0))) & 0x1f))):0) + ((((1)<4 ?
((0x80088822)>>(((3-(1))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(1))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((4)*(1))^((1)?8-
(1):0))) & 0x1f))):0) + ((((1)<4 ? ((0x80088822)>>
(((3-(1))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(1))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((5)*(1))^((1)?8-(1):0))) &
0x1f))):0) + ((((1)<4 ? ((0x80088822)>>(((3-(1))*8+
(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((6)*(1))^((1)?8-(1):0))) & 0x1f))):0) +
((((1)<4 ? ((0x80088822)>>(((3-(1))*8+(7-(7))) &
0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((7)*(1))^((1)?8-(1):0))) & 0x1f))):0))*((1)==1?0x01010101
:((1)==2?0x00010001:1))), ((((((2)<4 ? ((0x80088822)>>
(((3-(2))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(2))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((0)*(1))^((1)?8-(1):0))) &
0x1f))):0) + ((((2)<4 ? ((0x80088822)>>(((3-(2))*8+
(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((1)*(1))^((1)?8-(1):0))) & 0x1f))):0) +
((((2)<4 ? ((0x80088822)>>(((3-(2))*8+(7-(2))) &
0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((2)*(1))^((1)?8-(1):0))) & 0x1f))):0) + ((((2)<4 ?
((0x80088822)>>(((3-(2))*8+(7-(3))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(2))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((3)*(1))^((1)?8-
(1):0))) & 0x1f))):0) + ((((2)<4 ? ((0x80088822)>>
(((3-(2))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(2))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((4)*(1))^((1)?8-(1):0))) &
0x1f))):0) + ((((2)<4 ? ((0x80088822)>>(((3-(2))*8+
(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((5)*(1))^((1)?8-(1):0))) & 0x1f))):0) +
((((2)<4 ? ((0x80088822)>>(((3-(2))*8+(7-(6))) &
0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((6)*(1))^((1)?8-(1):0))) & 0x1f))):0) + ((((2)<4 ?
((0x80088822)>>(((3-(2))*8+(7-(7))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(2))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((7)*(1))^((1)?8-
(1):0))) & 0x1f))):0))*((1)==1?0x01010101:((1)==2?0x00010001
:1))), ((((((3)<4 ? ((0x80088822)>>(((3-(3))*8+(7-(0
))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(0))) &
0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((0)*(1))^((1)?8-(1):0))) & 0x1f))):0) + ((((3)<4 ?
((0x80088822)>>(((3-(3))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(3))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((1)*(1))^((1)?8-
(1):0))) & 0x1f))):0) + ((((3)<4 ? ((0x80088822)>>
(((3-(3))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(3))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((2)*(1))^((1)?8-(1):0))) &
0x1f))):0) + ((((3)<4 ? ((0x80088822)>>(((3-(3))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((3)*(1))^((1)?8-(1):0))) & 0x1f))):0) +
((((3)<4 ? ((0x80088822)>>(((3-(3))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((4)*(1))^((1)?8-(1):0))) & 0x1f))):0) + ((((3)<4 ?
((0x80088822)>>(((3-(3))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(3))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((5)*(1))^((1)?8-
(1):0))) & 0x1f))):0) + ((((3)<4 ? ((0x80088822)>>
(((3-(3))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(3))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((6)*(1))^((1)?8-(1):0))) &
0x1f))):0) + ((((3)<4 ? ((0x80088822)>>(((3-(3))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((7)*(1))^((1)?8-(1):0))) & 0x1f))):0))
*((1)==1?0x01010101:((1)==2?0x00010001:1))), ((((((4)<4 ? (
(0x80088822)>>(((3-(4))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(4))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((0)*(1))^((1)?8-
(1):0))) & 0x1f))):0) + ((((4)<4 ? ((0x80088822)>>
(((3-(4))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(4))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((1)*(1))^((1)?8-(1):0))) &
0x1f))):0) + ((((4)<4 ? ((0x80088822)>>(((3-(4))*8+
(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((2)*(1))^((1)?8-(1):0))) & 0x1f))):0) +
((((4)<4 ? ((0x80088822)>>(((3-(4))*8+(7-(3))) &
0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((3)*(1))^((1)?8-(1):0))) & 0x1f))):0) + ((((4)<4 ?
((0x80088822)>>(((3-(4))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(4))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((4)*(1))^((1)?8-
(1):0))) & 0x1f))):0) + ((((4)<4 ? ((0x80088822)>>
(((3-(4))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(4))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((5)*(1))^((1)?8-(1):0))) &
0x1f))):0) + ((((4)<4 ? ((0x80088822)>>(((3-(4))*8+
(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((6)*(1))^((1)?8-(1):0))) & 0x1f))):0) +
((((4)<4 ? ((0x80088822)>>(((3-(4))*8+(7-(7))) &
0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((7)*(1))^((1)?8-(1):0))) & 0x1f))):0))*((1)==1?0x01010101
:((1)==2?0x00010001:1))), ((((((5)<4 ? ((0x80088822)>>
(((3-(5))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(5))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((0)*(1))^((1)?8-(1):0))) &
0x1f))):0) + ((((5)<4 ? ((0x80088822)>>(((3-(5))*8+
(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((1)*(1))^((1)?8-(1):0))) & 0x1f))):0) +
((((5)<4 ? ((0x80088822)>>(((3-(5))*8+(7-(2))) &
0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((2)*(1))^((1)?8-(1):0))) & 0x1f))):0) + ((((5)<4 ?
((0x80088822)>>(((3-(5))*8+(7-(3))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(5))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((3)*(1))^((1)?8-
(1):0))) & 0x1f))):0) + ((((5)<4 ? ((0x80088822)>>
(((3-(5))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(5))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((4)*(1))^((1)?8-(1):0))) &
0x1f))):0) + ((((5)<4 ? ((0x80088822)>>(((3-(5))*8+
(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((5)*(1))^((1)?8-(1):0))) & 0x1f))):0) +
((((5)<4 ? ((0x80088822)>>(((3-(5))*8+(7-(6))) &
0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((6)*(1))^((1)?8-(1):0))) & 0x1f))):0) + ((((5)<4 ?
((0x80088822)>>(((3-(5))*8+(7-(7))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(5))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((7)*(1))^((1)?8-
(1):0))) & 0x1f))):0))*((1)==1?0x01010101:((1)==2?0x00010001
:1))) }
, S_MASKS(2,1){ ((((((0)<4 ? ((0x80088822)>>(((3-(0))*8+(7-(0))) &
0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((0)*(2))^((1)?8-(2):0))) & 0x1f))):0) + ((((0)<4 ?
((0x80088822)>>(((3-(0))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(0))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((1)*(2))^((1)?8-
(2):0))) & 0x1f))):0) + ((((0)<4 ? ((0x80088822)>>
(((3-(0))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(0))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((2)*(2))^((1)?8-(2):0))) &
0x1f))):0) + ((((0)<4 ? ((0x80088822)>>(((3-(0))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((3)*(2))^((1)?8-(2):0))) & 0x1f))):0) +
((((0)<4 ? ((0x80088822)>>(((3-(0))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((4)*(2))^((1)?8-(2):0))) & 0x1f))):0) + ((((0)<4 ?
((0x80088822)>>(((3-(0))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(0))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((5)*(2))^((1)?8-
(2):0))) & 0x1f))):0) + ((((0)<4 ? ((0x80088822)>>
(((3-(0))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(0))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((6)*(2))^((1)?8-(2):0))) &
0x1f))):0) + ((((0)<4 ? ((0x80088822)>>(((3-(0))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((7)*(2))^((1)?8-(2):0))) & 0x1f))):0))
*((2)==1?0x01010101:((2)==2?0x00010001:1))), ((((((1)<4 ? (
(0x80088822)>>(((3-(1))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(1))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((0)*(2))^((1)?8-
(2):0))) & 0x1f))):0) + ((((1)<4 ? ((0x80088822)>>
(((3-(1))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(1))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((1)*(2))^((1)?8-(2):0))) &
0x1f))):0) + ((((1)<4 ? ((0x80088822)>>(((3-(1))*8+
(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((2)*(2))^((1)?8-(2):0))) & 0x1f))):0) +
((((1)<4 ? ((0x80088822)>>(((3-(1))*8+(7-(3))) &
0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((3)*(2))^((1)?8-(2):0))) & 0x1f))):0) + ((((1)<4 ?
((0x80088822)>>(((3-(1))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(1))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((4)*(2))^((1)?8-
(2):0))) & 0x1f))):0) + ((((1)<4 ? ((0x80088822)>>
(((3-(1))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(1))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((5)*(2))^((1)?8-(2):0))) &
0x1f))):0) + ((((1)<4 ? ((0x80088822)>>(((3-(1))*8+
(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((6)*(2))^((1)?8-(2):0))) & 0x1f))):0) +
((((1)<4 ? ((0x80088822)>>(((3-(1))*8+(7-(7))) &
0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((7)*(2))^((1)?8-(2):0))) & 0x1f))):0))*((2)==1?0x01010101
:((2)==2?0x00010001:1))), ((((((2)<4 ? ((0x80088822)>>
(((3-(2))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(2))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((0)*(2))^((1)?8-(2):0))) &
0x1f))):0) + ((((2)<4 ? ((0x80088822)>>(((3-(2))*8+
(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((1)*(2))^((1)?8-(2):0))) & 0x1f))):0) +
((((2)<4 ? ((0x80088822)>>(((3-(2))*8+(7-(2))) &
0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((2)*(2))^((1)?8-(2):0))) & 0x1f))):0) + ((((2)<4 ?
((0x80088822)>>(((3-(2))*8+(7-(3))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(2))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((3)*(2))^((1)?8-
(2):0))) & 0x1f))):0) + ((((2)<4 ? ((0x80088822)>>
(((3-(2))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(2))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((4)*(2))^((1)?8-(2):0))) &
0x1f))):0) + ((((2)<4 ? ((0x80088822)>>(((3-(2))*8+
(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((5)*(2))^((1)?8-(2):0))) & 0x1f))):0) +
((((2)<4 ? ((0x80088822)>>(((3-(2))*8+(7-(6))) &
0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((6)*(2))^((1)?8-(2):0))) & 0x1f))):0) + ((((2)<4 ?
((0x80088822)>>(((3-(2))*8+(7-(7))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(2))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((7)*(2))^((1)?8-
(2):0))) & 0x1f))):0))*((2)==1?0x01010101:((2)==2?0x00010001
:1))), ((((((3)<4 ? ((0x80088822)>>(((3-(3))*8+(7-(0
))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(0))) &
0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((0)*(2))^((1)?8-(2):0))) & 0x1f))):0) + ((((3)<4 ?
((0x80088822)>>(((3-(3))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(3))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((1)*(2))^((1)?8-
(2):0))) & 0x1f))):0) + ((((3)<4 ? ((0x80088822)>>
(((3-(3))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(3))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((2)*(2))^((1)?8-(2):0))) &
0x1f))):0) + ((((3)<4 ? ((0x80088822)>>(((3-(3))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((3)*(2))^((1)?8-(2):0))) & 0x1f))):0) +
((((3)<4 ? ((0x80088822)>>(((3-(3))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((4)*(2))^((1)?8-(2):0))) & 0x1f))):0) + ((((3)<4 ?
((0x80088822)>>(((3-(3))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(3))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((5)*(2))^((1)?8-
(2):0))) & 0x1f))):0) + ((((3)<4 ? ((0x80088822)>>
(((3-(3))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(3))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((6)*(2))^((1)?8-(2):0))) &
0x1f))):0) + ((((3)<4 ? ((0x80088822)>>(((3-(3))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((7)*(2))^((1)?8-(2):0))) & 0x1f))):0))
*((2)==1?0x01010101:((2)==2?0x00010001:1))), ((((((4)<4 ? (
(0x80088822)>>(((3-(4))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(4))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((0)*(2))^((1)?8-
(2):0))) & 0x1f))):0) + ((((4)<4 ? ((0x80088822)>>
(((3-(4))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(4))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((1)*(2))^((1)?8-(2):0))) &
0x1f))):0) + ((((4)<4 ? ((0x80088822)>>(((3-(4))*8+
(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((2)*(2))^((1)?8-(2):0))) & 0x1f))):0) +
((((4)<4 ? ((0x80088822)>>(((3-(4))*8+(7-(3))) &
0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((3)*(2))^((1)?8-(2):0))) & 0x1f))):0) + ((((4)<4 ?
((0x80088822)>>(((3-(4))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(4))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((4)*(2))^((1)?8-
(2):0))) & 0x1f))):0) + ((((4)<4 ? ((0x80088822)>>
(((3-(4))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(4))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((5)*(2))^((1)?8-(2):0))) &
0x1f))):0) + ((((4)<4 ? ((0x80088822)>>(((3-(4))*8+
(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((6)*(2))^((1)?8-(2):0))) & 0x1f))):0) +
((((4)<4 ? ((0x80088822)>>(((3-(4))*8+(7-(7))) &
0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((7)*(2))^((1)?8-(2):0))) & 0x1f))):0))*((2)==1?0x01010101
:((2)==2?0x00010001:1))), ((((((5)<4 ? ((0x80088822)>>
(((3-(5))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(5))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((0)*(2))^((1)?8-(2):0))) &
0x1f))):0) + ((((5)<4 ? ((0x80088822)>>(((3-(5))*8+
(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((1)*(2))^((1)?8-(2):0))) & 0x1f))):0) +
((((5)<4 ? ((0x80088822)>>(((3-(5))*8+(7-(2))) &
0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((2)*(2))^((1)?8-(2):0))) & 0x1f))):0) + ((((5)<4 ?
((0x80088822)>>(((3-(5))*8+(7-(3))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(5))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((3)*(2))^((1)?8-
(2):0))) & 0x1f))):0) + ((((5)<4 ? ((0x80088822)>>
(((3-(5))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(5))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((4)*(2))^((1)?8-(2):0))) &
0x1f))):0) + ((((5)<4 ? ((0x80088822)>>(((3-(5))*8+
(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((5)*(2))^((1)?8-(2):0))) & 0x1f))):0) +
((((5)<4 ? ((0x80088822)>>(((3-(5))*8+(7-(6))) &
0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((6)*(2))^((1)?8-(2):0))) & 0x1f))):0) + ((((5)<4 ?
((0x80088822)>>(((3-(5))*8+(7-(7))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(5))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((7)*(2))^((1)?8-
(2):0))) & 0x1f))):0))*((2)==1?0x01010101:((2)==2?0x00010001
:1))) }
, S_MASKS(4,1){ ((((((0)<4 ? ((0x80088822)>>(((3-(0))*8+(7-(0))) &
0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((0)*(4))^((1)?8-(4):0))) & 0x1f))):0) + ((((0)<4 ?
((0x80088822)>>(((3-(0))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(0))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((1)*(4))^((1)?8-
(4):0))) & 0x1f))):0) + ((((0)<4 ? ((0x80088822)>>
(((3-(0))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(0))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((2)*(4))^((1)?8-(4):0))) &
0x1f))):0) + ((((0)<4 ? ((0x80088822)>>(((3-(0))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((3)*(4))^((1)?8-(4):0))) & 0x1f))):0) +
((((0)<4 ? ((0x80088822)>>(((3-(0))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((4)*(4))^((1)?8-(4):0))) & 0x1f))):0) + ((((0)<4 ?
((0x80088822)>>(((3-(0))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(0))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((5)*(4))^((1)?8-
(4):0))) & 0x1f))):0) + ((((0)<4 ? ((0x80088822)>>
(((3-(0))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(0))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((6)*(4))^((1)?8-(4):0))) &
0x1f))):0) + ((((0)<4 ? ((0x80088822)>>(((3-(0))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(0))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((7)*(4))^((1)?8-(4):0))) & 0x1f))):0))
*((4)==1?0x01010101:((4)==2?0x00010001:1))), ((((((1)<4 ? (
(0x80088822)>>(((3-(1))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(1))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((0)*(4))^((1)?8-
(4):0))) & 0x1f))):0) + ((((1)<4 ? ((0x80088822)>>
(((3-(1))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(1))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((1)*(4))^((1)?8-(4):0))) &
0x1f))):0) + ((((1)<4 ? ((0x80088822)>>(((3-(1))*8+
(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((2)*(4))^((1)?8-(4):0))) & 0x1f))):0) +
((((1)<4 ? ((0x80088822)>>(((3-(1))*8+(7-(3))) &
0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((3)*(4))^((1)?8-(4):0))) & 0x1f))):0) + ((((1)<4 ?
((0x80088822)>>(((3-(1))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(1))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((4)*(4))^((1)?8-
(4):0))) & 0x1f))):0) + ((((1)<4 ? ((0x80088822)>>
(((3-(1))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(1))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((5)*(4))^((1)?8-(4):0))) &
0x1f))):0) + ((((1)<4 ? ((0x80088822)>>(((3-(1))*8+
(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((6)*(4))^((1)?8-(4):0))) & 0x1f))):0) +
((((1)<4 ? ((0x80088822)>>(((3-(1))*8+(7-(7))) &
0x1f)) : ((0xaa55ff00)>>(((7-(1))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((7)*(4))^((1)?8-(4):0))) & 0x1f))):0))*((4)==1?0x01010101
:((4)==2?0x00010001:1))), ((((((2)<4 ? ((0x80088822)>>
(((3-(2))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(2))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((0)*(4))^((1)?8-(4):0))) &
0x1f))):0) + ((((2)<4 ? ((0x80088822)>>(((3-(2))*8+
(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((1)*(4))^((1)?8-(4):0))) & 0x1f))):0) +
((((2)<4 ? ((0x80088822)>>(((3-(2))*8+(7-(2))) &
0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((2)*(4))^((1)?8-(4):0))) & 0x1f))):0) + ((((2)<4 ?
((0x80088822)>>(((3-(2))*8+(7-(3))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(2))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((3)*(4))^((1)?8-
(4):0))) & 0x1f))):0) + ((((2)<4 ? ((0x80088822)>>
(((3-(2))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(2))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((4)*(4))^((1)?8-(4):0))) &
0x1f))):0) + ((((2)<4 ? ((0x80088822)>>(((3-(2))*8+
(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((5)*(4))^((1)?8-(4):0))) & 0x1f))):0) +
((((2)<4 ? ((0x80088822)>>(((3-(2))*8+(7-(6))) &
0x1f)) : ((0xaa55ff00)>>(((7-(2))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((6)*(4))^((1)?8-(4):0))) & 0x1f))):0) + ((((2)<4 ?
((0x80088822)>>(((3-(2))*8+(7-(7))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(2))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((7)*(4))^((1)?8-
(4):0))) & 0x1f))):0))*((4)==1?0x01010101:((4)==2?0x00010001
:1))), ((((((3)<4 ? ((0x80088822)>>(((3-(3))*8+(7-(0
))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(0))) &
0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((0)*(4))^((1)?8-(4):0))) & 0x1f))):0) + ((((3)<4 ?
((0x80088822)>>(((3-(3))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(3))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((1)*(4))^((1)?8-
(4):0))) & 0x1f))):0) + ((((3)<4 ? ((0x80088822)>>
(((3-(3))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(3))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((2)*(4))^((1)?8-(4):0))) &
0x1f))):0) + ((((3)<4 ? ((0x80088822)>>(((3-(3))*8+
(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((3)*(4))^((1)?8-(4):0))) & 0x1f))):0) +
((((3)<4 ? ((0x80088822)>>(((3-(3))*8+(7-(4))) &
0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((4)*(4))^((1)?8-(4):0))) & 0x1f))):0) + ((((3)<4 ?
((0x80088822)>>(((3-(3))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(3))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((5)*(4))^((1)?8-
(4):0))) & 0x1f))):0) + ((((3)<4 ? ((0x80088822)>>
(((3-(3))*8+(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(3))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((6)*(4))^((1)?8-(4):0))) &
0x1f))):0) + ((((3)<4 ? ((0x80088822)>>(((3-(3))*8+
(7-(7))) & 0x1f)) : ((0xaa55ff00)>>(((7-(3))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((7)*(4))^((1)?8-(4):0))) & 0x1f))):0))
*((4)==1?0x01010101:((4)==2?0x00010001:1))), ((((((4)<4 ? (
(0x80088822)>>(((3-(4))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(4))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((0)*(4))^((1)?8-
(4):0))) & 0x1f))):0) + ((((4)<4 ? ((0x80088822)>>
(((3-(4))*8+(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(4))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((1)*(4))^((1)?8-(4):0))) &
0x1f))):0) + ((((4)<4 ? ((0x80088822)>>(((3-(4))*8+
(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((2)*(4))^((1)?8-(4):0))) & 0x1f))):0) +
((((4)<4 ? ((0x80088822)>>(((3-(4))*8+(7-(3))) &
0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((3)*(4))^((1)?8-(4):0))) & 0x1f))):0) + ((((4)<4 ?
((0x80088822)>>(((3-(4))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(4))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((4)*(4))^((1)?8-
(4):0))) & 0x1f))):0) + ((((4)<4 ? ((0x80088822)>>
(((3-(4))*8+(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(4))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((5)*(4))^((1)?8-(4):0))) &
0x1f))):0) + ((((4)<4 ? ((0x80088822)>>(((3-(4))*8+
(7-(6))) & 0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((6)*(4))^((1)?8-(4):0))) & 0x1f))):0) +
((((4)<4 ? ((0x80088822)>>(((3-(4))*8+(7-(7))) &
0x1f)) : ((0xaa55ff00)>>(((7-(4))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((7)*(4))^((1)?8-(4):0))) & 0x1f))):0))*((4)==1?0x01010101
:((4)==2?0x00010001:1))), ((((((5)<4 ? ((0x80088822)>>
(((3-(5))*8+(7-(0))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(5))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((0)*(4))^((1)?8-(4):0))) &
0x1f))):0) + ((((5)<4 ? ((0x80088822)>>(((3-(5))*8+
(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((1)*(4))^((1)?8-(4):0))) & 0x1f))):0) +
((((5)<4 ? ((0x80088822)>>(((3-(5))*8+(7-(2))) &
0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((2)*(4))^((1)?8-(4):0))) & 0x1f))):0) + ((((5)<4 ?
((0x80088822)>>(((3-(5))*8+(7-(3))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(5))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((3)*(4))^((1)?8-
(4):0))) & 0x1f))):0) + ((((5)<4 ? ((0x80088822)>>
(((3-(5))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00)>>(((7
-(5))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((4)*(4))^((1)?8-(4):0))) &
0x1f))):0) + ((((5)<4 ? ((0x80088822)>>(((3-(5))*8+
(7-(5))) & 0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((5)*(4))^((1)?8-(4):0))) & 0x1f))):0) +
((((5)<4 ? ((0x80088822)>>(((3-(5))*8+(7-(6))) &
0x1f)) : ((0xaa55ff00)>>(((7-(5))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((6)*(4))^((1)?8-(4):0))) & 0x1f))):0) + ((((5)<4 ?
((0x80088822)>>(((3-(5))*8+(7-(7))) & 0x1f)) : ((0xaa55ff00
)>>(((7-(5))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((7)*(4))^((1)?8-
(4):0))) & 0x1f))):0))*((4)==1?0x01010101:((4)==2?0x00010001
:1))) }
}
3586 };
3587
3588 /* display_mask has only three entries for the odd passes, so index by
3589 * pass>>1.
3590 */
3591 static const png_uint_32 display_mask[2][3][3] =
3592 {
3593 /* Little-endian byte masks for PACKSWAP */
3594 { B_MASKS(1,0){ ((((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+(7-(0))) &
0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((0)*(1))^((0)?8-(1):0))) & 0x1f))):0) + ((((1)<4 ?
((0xff0fff33)>>(((3-(1))*8+(7-(1))) & 0x1f)) : ((0xff55ff00
)>>(((7-(1))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((1)*(1))^((0)?8-
(1):0))) & 0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>
(((3-(1))*8+(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7
-(1))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((2)*(1))^((0)?8-(1):0))) &
0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+
(7-(3))) & 0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((3)*(1))^((0)?8-(1):0))) & 0x1f))):0) +
((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+(7-(4))) &
0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((4)*(1))^((0)?8-(1):0))) & 0x1f))):0) + ((((1)<4 ?
((0xff0fff33)>>(((3-(1))*8+(7-(5))) & 0x1f)) : ((0xff55ff00
)>>(((7-(1))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((5)*(1))^((0)?8-
(1):0))) & 0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>
(((3-(1))*8+(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7
-(1))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((6)*(1))^((0)?8-(1):0))) &
0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+
(7-(7))) & 0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((7)*(1))^((0)?8-(1):0))) & 0x1f))):0))
*((1)==1?0x01010101:((1)==2?0x00010001:1))), ((((((3)<4 ? (
(0xff0fff33)>>(((3-(3))*8+(7-(0))) & 0x1f)) : ((0xff55ff00
)>>(((7-(3))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((0)*(1))^((0)?8-
(1):0))) & 0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>
(((3-(3))*8+(7-(1))) & 0x1f)) : ((0xff55ff00)>>(((7
-(3))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((1)*(1))^((0)?8-(1):0))) &
0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+
(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((2)*(1))^((0)?8-(1):0))) & 0x1f))):0) +
((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+(7-(3))) &
0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((3)*(1))^((0)?8-(1):0))) & 0x1f))):0) + ((((3)<4 ?
((0xff0fff33)>>(((3-(3))*8+(7-(4))) & 0x1f)) : ((0xff55ff00
)>>(((7-(3))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((4)*(1))^((0)?8-
(1):0))) & 0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>
(((3-(3))*8+(7-(5))) & 0x1f)) : ((0xff55ff00)>>(((7
-(3))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((5)*(1))^((0)?8-(1):0))) &
0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+
(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((6)*(1))^((0)?8-(1):0))) & 0x1f))):0) +
((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+(7-(7))) &
0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((7)*(1))^((0)?8-(1):0))) & 0x1f))):0))*((1)==1?0x01010101
:((1)==2?0x00010001:1))), ((((((5)<4 ? ((0xff0fff33)>>
(((3-(5))*8+(7-(0))) & 0x1f)) : ((0xff55ff00)>>(((7
-(5))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((0)*(1))^((0)?8-(1):0))) &
0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+
(7-(1))) & 0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((1)*(1))^((0)?8-(1):0))) & 0x1f))):0) +
((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+(7-(2))) &
0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((2)*(1))^((0)?8-(1):0))) & 0x1f))):0) + ((((5)<4 ?
((0xff0fff33)>>(((3-(5))*8+(7-(3))) & 0x1f)) : ((0xff55ff00
)>>(((7-(5))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((3)*(1))^((0)?8-
(1):0))) & 0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>
(((3-(5))*8+(7-(4))) & 0x1f)) : ((0xff55ff00)>>(((7
-(5))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((4)*(1))^((0)?8-(1):0))) &
0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+
(7-(5))) & 0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((5)*(1))^((0)?8-(1):0))) & 0x1f))):0) +
((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+(7-(6))) &
0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((6)*(1))^((0)?8-(1):0))) & 0x1f))):0) + ((((5)<4 ?
((0xff0fff33)>>(((3-(5))*8+(7-(7))) & 0x1f)) : ((0xff55ff00
)>>(((7-(5))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((7)*(1))^((0)?8-
(1):0))) & 0x1f))):0))*((1)==1?0x01010101:((1)==2?0x00010001
:1))) }
, B_MASKS(2,0){ ((((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+(7-(0))) &
0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((0)*(2))^((0)?8-(2):0))) & 0x1f))):0) + ((((1)<4 ?
((0xff0fff33)>>(((3-(1))*8+(7-(1))) & 0x1f)) : ((0xff55ff00
)>>(((7-(1))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((1)*(2))^((0)?8-
(2):0))) & 0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>
(((3-(1))*8+(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7
-(1))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((2)*(2))^((0)?8-(2):0))) &
0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+
(7-(3))) & 0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((3)*(2))^((0)?8-(2):0))) & 0x1f))):0) +
((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+(7-(4))) &
0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((4)*(2))^((0)?8-(2):0))) & 0x1f))):0) + ((((1)<4 ?
((0xff0fff33)>>(((3-(1))*8+(7-(5))) & 0x1f)) : ((0xff55ff00
)>>(((7-(1))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((5)*(2))^((0)?8-
(2):0))) & 0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>
(((3-(1))*8+(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7
-(1))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((6)*(2))^((0)?8-(2):0))) &
0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+
(7-(7))) & 0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((7)*(2))^((0)?8-(2):0))) & 0x1f))):0))
*((2)==1?0x01010101:((2)==2?0x00010001:1))), ((((((3)<4 ? (
(0xff0fff33)>>(((3-(3))*8+(7-(0))) & 0x1f)) : ((0xff55ff00
)>>(((7-(3))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((0)*(2))^((0)?8-
(2):0))) & 0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>
(((3-(3))*8+(7-(1))) & 0x1f)) : ((0xff55ff00)>>(((7
-(3))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((1)*(2))^((0)?8-(2):0))) &
0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+
(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((2)*(2))^((0)?8-(2):0))) & 0x1f))):0) +
((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+(7-(3))) &
0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((3)*(2))^((0)?8-(2):0))) & 0x1f))):0) + ((((3)<4 ?
((0xff0fff33)>>(((3-(3))*8+(7-(4))) & 0x1f)) : ((0xff55ff00
)>>(((7-(3))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((4)*(2))^((0)?8-
(2):0))) & 0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>
(((3-(3))*8+(7-(5))) & 0x1f)) : ((0xff55ff00)>>(((7
-(3))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((5)*(2))^((0)?8-(2):0))) &
0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+
(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((6)*(2))^((0)?8-(2):0))) & 0x1f))):0) +
((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+(7-(7))) &
0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((7)*(2))^((0)?8-(2):0))) & 0x1f))):0))*((2)==1?0x01010101
:((2)==2?0x00010001:1))), ((((((5)<4 ? ((0xff0fff33)>>
(((3-(5))*8+(7-(0))) & 0x1f)) : ((0xff55ff00)>>(((7
-(5))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((0)*(2))^((0)?8-(2):0))) &
0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+
(7-(1))) & 0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((1)*(2))^((0)?8-(2):0))) & 0x1f))):0) +
((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+(7-(2))) &
0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((2)*(2))^((0)?8-(2):0))) & 0x1f))):0) + ((((5)<4 ?
((0xff0fff33)>>(((3-(5))*8+(7-(3))) & 0x1f)) : ((0xff55ff00
)>>(((7-(5))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((3)*(2))^((0)?8-
(2):0))) & 0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>
(((3-(5))*8+(7-(4))) & 0x1f)) : ((0xff55ff00)>>(((7
-(5))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((4)*(2))^((0)?8-(2):0))) &
0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+
(7-(5))) & 0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((5)*(2))^((0)?8-(2):0))) & 0x1f))):0) +
((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+(7-(6))) &
0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((6)*(2))^((0)?8-(2):0))) & 0x1f))):0) + ((((5)<4 ?
((0xff0fff33)>>(((3-(5))*8+(7-(7))) & 0x1f)) : ((0xff55ff00
)>>(((7-(5))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((7)*(2))^((0)?8-
(2):0))) & 0x1f))):0))*((2)==1?0x01010101:((2)==2?0x00010001
:1))) }
, B_MASKS(4,0){ ((((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+(7-(0))) &
0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((0)*(4))^((0)?8-(4):0))) & 0x1f))):0) + ((((1)<4 ?
((0xff0fff33)>>(((3-(1))*8+(7-(1))) & 0x1f)) : ((0xff55ff00
)>>(((7-(1))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((1)*(4))^((0)?8-
(4):0))) & 0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>
(((3-(1))*8+(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7
-(1))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((2)*(4))^((0)?8-(4):0))) &
0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+
(7-(3))) & 0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((3)*(4))^((0)?8-(4):0))) & 0x1f))):0) +
((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+(7-(4))) &
0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((4)*(4))^((0)?8-(4):0))) & 0x1f))):0) + ((((1)<4 ?
((0xff0fff33)>>(((3-(1))*8+(7-(5))) & 0x1f)) : ((0xff55ff00
)>>(((7-(1))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((5)*(4))^((0)?8-
(4):0))) & 0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>
(((3-(1))*8+(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7
-(1))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((6)*(4))^((0)?8-(4):0))) &
0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+
(7-(7))) & 0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((7)*(4))^((0)?8-(4):0))) & 0x1f))):0))
*((4)==1?0x01010101:((4)==2?0x00010001:1))), ((((((3)<4 ? (
(0xff0fff33)>>(((3-(3))*8+(7-(0))) & 0x1f)) : ((0xff55ff00
)>>(((7-(3))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((0)*(4))^((0)?8-
(4):0))) & 0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>
(((3-(3))*8+(7-(1))) & 0x1f)) : ((0xff55ff00)>>(((7
-(3))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((1)*(4))^((0)?8-(4):0))) &
0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+
(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((2)*(4))^((0)?8-(4):0))) & 0x1f))):0) +
((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+(7-(3))) &
0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((3)*(4))^((0)?8-(4):0))) & 0x1f))):0) + ((((3)<4 ?
((0xff0fff33)>>(((3-(3))*8+(7-(4))) & 0x1f)) : ((0xff55ff00
)>>(((7-(3))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((4)*(4))^((0)?8-
(4):0))) & 0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>
(((3-(3))*8+(7-(5))) & 0x1f)) : ((0xff55ff00)>>(((7
-(3))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((5)*(4))^((0)?8-(4):0))) &
0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+
(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((6)*(4))^((0)?8-(4):0))) & 0x1f))):0) +
((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+(7-(7))) &
0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((7)*(4))^((0)?8-(4):0))) & 0x1f))):0))*((4)==1?0x01010101
:((4)==2?0x00010001:1))), ((((((5)<4 ? ((0xff0fff33)>>
(((3-(5))*8+(7-(0))) & 0x1f)) : ((0xff55ff00)>>(((7
-(5))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((0)*(4))^((0)?8-(4):0))) &
0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+
(7-(1))) & 0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((1)*(4))^((0)?8-(4):0))) & 0x1f))):0) +
((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+(7-(2))) &
0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((2)*(4))^((0)?8-(4):0))) & 0x1f))):0) + ((((5)<4 ?
((0xff0fff33)>>(((3-(5))*8+(7-(3))) & 0x1f)) : ((0xff55ff00
)>>(((7-(5))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((3)*(4))^((0)?8-
(4):0))) & 0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>
(((3-(5))*8+(7-(4))) & 0x1f)) : ((0xff55ff00)>>(((7
-(5))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((4)*(4))^((0)?8-(4):0))) &
0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+
(7-(5))) & 0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((5)*(4))^((0)?8-(4):0))) & 0x1f))):0) +
((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+(7-(6))) &
0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((6)*(4))^((0)?8-(4):0))) & 0x1f))):0) + ((((5)<4 ?
((0xff0fff33)>>(((3-(5))*8+(7-(7))) & 0x1f)) : ((0xff55ff00
)>>(((7-(5))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((7)*(4))^((0)?8-
(4):0))) & 0x1f))):0))*((4)==1?0x01010101:((4)==2?0x00010001
:1))) }
},
3595 /* Normal (big-endian byte) masks - PNG format */
3596 { B_MASKS(1,1){ ((((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+(7-(0))) &
0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((0)*(1))^((1)?8-(1):0))) & 0x1f))):0) + ((((1)<4 ?
((0xff0fff33)>>(((3-(1))*8+(7-(1))) & 0x1f)) : ((0xff55ff00
)>>(((7-(1))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((1)*(1))^((1)?8-
(1):0))) & 0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>
(((3-(1))*8+(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7
-(1))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((2)*(1))^((1)?8-(1):0))) &
0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+
(7-(3))) & 0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((3)*(1))^((1)?8-(1):0))) & 0x1f))):0) +
((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+(7-(4))) &
0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((4)*(1))^((1)?8-(1):0))) & 0x1f))):0) + ((((1)<4 ?
((0xff0fff33)>>(((3-(1))*8+(7-(5))) & 0x1f)) : ((0xff55ff00
)>>(((7-(1))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((5)*(1))^((1)?8-
(1):0))) & 0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>
(((3-(1))*8+(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7
-(1))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((6)*(1))^((1)?8-(1):0))) &
0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+
(7-(7))) & 0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((7)*(1))^((1)?8-(1):0))) & 0x1f))):0))
*((1)==1?0x01010101:((1)==2?0x00010001:1))), ((((((3)<4 ? (
(0xff0fff33)>>(((3-(3))*8+(7-(0))) & 0x1f)) : ((0xff55ff00
)>>(((7-(3))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((0)*(1))^((1)?8-
(1):0))) & 0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>
(((3-(3))*8+(7-(1))) & 0x1f)) : ((0xff55ff00)>>(((7
-(3))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((1)*(1))^((1)?8-(1):0))) &
0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+
(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((2)*(1))^((1)?8-(1):0))) & 0x1f))):0) +
((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+(7-(3))) &
0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((3)*(1))^((1)?8-(1):0))) & 0x1f))):0) + ((((3)<4 ?
((0xff0fff33)>>(((3-(3))*8+(7-(4))) & 0x1f)) : ((0xff55ff00
)>>(((7-(3))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((4)*(1))^((1)?8-
(1):0))) & 0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>
(((3-(3))*8+(7-(5))) & 0x1f)) : ((0xff55ff00)>>(((7
-(3))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((5)*(1))^((1)?8-(1):0))) &
0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+
(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((6)*(1))^((1)?8-(1):0))) & 0x1f))):0) +
((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+(7-(7))) &
0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((7)*(1))^((1)?8-(1):0))) & 0x1f))):0))*((1)==1?0x01010101
:((1)==2?0x00010001:1))), ((((((5)<4 ? ((0xff0fff33)>>
(((3-(5))*8+(7-(0))) & 0x1f)) : ((0xff55ff00)>>(((7
-(5))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((0)*(1))^((1)?8-(1):0))) &
0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+
(7-(1))) & 0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((1)*(1))^((1)?8-(1):0))) & 0x1f))):0) +
((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+(7-(2))) &
0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((2)*(1))^((1)?8-(1):0))) & 0x1f))):0) + ((((5)<4 ?
((0xff0fff33)>>(((3-(5))*8+(7-(3))) & 0x1f)) : ((0xff55ff00
)>>(((7-(5))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((3)*(1))^((1)?8-
(1):0))) & 0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>
(((3-(5))*8+(7-(4))) & 0x1f)) : ((0xff55ff00)>>(((7
-(5))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
1)) & 0x1f)))-1))<<(((((4)*(1))^((1)?8-(1):0))) &
0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+
(7-(5))) & 0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((1)) & 0x1f
)))-1))<<(((((5)*(1))^((1)?8-(1):0))) & 0x1f))):0) +
((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+(7-(6))) &
0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((1)) & 0x1f)))-1))<<
(((((6)*(1))^((1)?8-(1):0))) & 0x1f))):0) + ((((5)<4 ?
((0xff0fff33)>>(((3-(5))*8+(7-(7))) & 0x1f)) : ((0xff55ff00
)>>(((7-(5))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((1)) & 0x1f)))-1))<<(((((7)*(1))^((1)?8-
(1):0))) & 0x1f))):0))*((1)==1?0x01010101:((1)==2?0x00010001
:1))) }
, B_MASKS(2,1){ ((((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+(7-(0))) &
0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((0)*(2))^((1)?8-(2):0))) & 0x1f))):0) + ((((1)<4 ?
((0xff0fff33)>>(((3-(1))*8+(7-(1))) & 0x1f)) : ((0xff55ff00
)>>(((7-(1))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((1)*(2))^((1)?8-
(2):0))) & 0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>
(((3-(1))*8+(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7
-(1))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((2)*(2))^((1)?8-(2):0))) &
0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+
(7-(3))) & 0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((3)*(2))^((1)?8-(2):0))) & 0x1f))):0) +
((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+(7-(4))) &
0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((4)*(2))^((1)?8-(2):0))) & 0x1f))):0) + ((((1)<4 ?
((0xff0fff33)>>(((3-(1))*8+(7-(5))) & 0x1f)) : ((0xff55ff00
)>>(((7-(1))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((5)*(2))^((1)?8-
(2):0))) & 0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>
(((3-(1))*8+(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7
-(1))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((6)*(2))^((1)?8-(2):0))) &
0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+
(7-(7))) & 0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((7)*(2))^((1)?8-(2):0))) & 0x1f))):0))
*((2)==1?0x01010101:((2)==2?0x00010001:1))), ((((((3)<4 ? (
(0xff0fff33)>>(((3-(3))*8+(7-(0))) & 0x1f)) : ((0xff55ff00
)>>(((7-(3))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((0)*(2))^((1)?8-
(2):0))) & 0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>
(((3-(3))*8+(7-(1))) & 0x1f)) : ((0xff55ff00)>>(((7
-(3))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((1)*(2))^((1)?8-(2):0))) &
0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+
(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((2)*(2))^((1)?8-(2):0))) & 0x1f))):0) +
((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+(7-(3))) &
0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((3)*(2))^((1)?8-(2):0))) & 0x1f))):0) + ((((3)<4 ?
((0xff0fff33)>>(((3-(3))*8+(7-(4))) & 0x1f)) : ((0xff55ff00
)>>(((7-(3))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((4)*(2))^((1)?8-
(2):0))) & 0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>
(((3-(3))*8+(7-(5))) & 0x1f)) : ((0xff55ff00)>>(((7
-(3))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((5)*(2))^((1)?8-(2):0))) &
0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+
(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((6)*(2))^((1)?8-(2):0))) & 0x1f))):0) +
((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+(7-(7))) &
0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((7)*(2))^((1)?8-(2):0))) & 0x1f))):0))*((2)==1?0x01010101
:((2)==2?0x00010001:1))), ((((((5)<4 ? ((0xff0fff33)>>
(((3-(5))*8+(7-(0))) & 0x1f)) : ((0xff55ff00)>>(((7
-(5))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((0)*(2))^((1)?8-(2):0))) &
0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+
(7-(1))) & 0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((1)*(2))^((1)?8-(2):0))) & 0x1f))):0) +
((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+(7-(2))) &
0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((2)*(2))^((1)?8-(2):0))) & 0x1f))):0) + ((((5)<4 ?
((0xff0fff33)>>(((3-(5))*8+(7-(3))) & 0x1f)) : ((0xff55ff00
)>>(((7-(5))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((3)*(2))^((1)?8-
(2):0))) & 0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>
(((3-(5))*8+(7-(4))) & 0x1f)) : ((0xff55ff00)>>(((7
-(5))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
2)) & 0x1f)))-1))<<(((((4)*(2))^((1)?8-(2):0))) &
0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+
(7-(5))) & 0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((2)) & 0x1f
)))-1))<<(((((5)*(2))^((1)?8-(2):0))) & 0x1f))):0) +
((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+(7-(6))) &
0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((2)) & 0x1f)))-1))<<
(((((6)*(2))^((1)?8-(2):0))) & 0x1f))):0) + ((((5)<4 ?
((0xff0fff33)>>(((3-(5))*8+(7-(7))) & 0x1f)) : ((0xff55ff00
)>>(((7-(5))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((2)) & 0x1f)))-1))<<(((((7)*(2))^((1)?8-
(2):0))) & 0x1f))):0))*((2)==1?0x01010101:((2)==2?0x00010001
:1))) }
, B_MASKS(4,1){ ((((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+(7-(0))) &
0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(0))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((0)*(4))^((1)?8-(4):0))) & 0x1f))):0) + ((((1)<4 ?
((0xff0fff33)>>(((3-(1))*8+(7-(1))) & 0x1f)) : ((0xff55ff00
)>>(((7-(1))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((1)*(4))^((1)?8-
(4):0))) & 0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>
(((3-(1))*8+(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7
-(1))*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((2)*(4))^((1)?8-(4):0))) &
0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+
(7-(3))) & 0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(
3))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((3)*(4))^((1)?8-(4):0))) & 0x1f))):0) +
((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+(7-(4))) &
0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(4))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((4)*(4))^((1)?8-(4):0))) & 0x1f))):0) + ((((1)<4 ?
((0xff0fff33)>>(((3-(1))*8+(7-(5))) & 0x1f)) : ((0xff55ff00
)>>(((7-(1))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((5)*(4))^((1)?8-
(4):0))) & 0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>
(((3-(1))*8+(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7
-(1))*8+(7-(6))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((6)*(4))^((1)?8-(4):0))) &
0x1f))):0) + ((((1)<4 ? ((0xff0fff33)>>(((3-(1))*8+
(7-(7))) & 0x1f)) : ((0xff55ff00)>>(((7-(1))*8+(7-(
7))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((7)*(4))^((1)?8-(4):0))) & 0x1f))):0))
*((4)==1?0x01010101:((4)==2?0x00010001:1))), ((((((3)<4 ? (
(0xff0fff33)>>(((3-(3))*8+(7-(0))) & 0x1f)) : ((0xff55ff00
)>>(((7-(3))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((0)*(4))^((1)?8-
(4):0))) & 0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>
(((3-(3))*8+(7-(1))) & 0x1f)) : ((0xff55ff00)>>(((7
-(3))*8+(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((1)*(4))^((1)?8-(4):0))) &
0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+
(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(
2))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((2)*(4))^((1)?8-(4):0))) & 0x1f))):0) +
((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+(7-(3))) &
0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(3))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((3)*(4))^((1)?8-(4):0))) & 0x1f))):0) + ((((3)<4 ?
((0xff0fff33)>>(((3-(3))*8+(7-(4))) & 0x1f)) : ((0xff55ff00
)>>(((7-(3))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((4)*(4))^((1)?8-
(4):0))) & 0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>
(((3-(3))*8+(7-(5))) & 0x1f)) : ((0xff55ff00)>>(((7
-(3))*8+(7-(5))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((5)*(4))^((1)?8-(4):0))) &
0x1f))):0) + ((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+
(7-(6))) & 0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(
6))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((6)*(4))^((1)?8-(4):0))) & 0x1f))):0) +
((((3)<4 ? ((0xff0fff33)>>(((3-(3))*8+(7-(7))) &
0x1f)) : ((0xff55ff00)>>(((7-(3))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((7)*(4))^((1)?8-(4):0))) & 0x1f))):0))*((4)==1?0x01010101
:((4)==2?0x00010001:1))), ((((((5)<4 ? ((0xff0fff33)>>
(((3-(5))*8+(7-(0))) & 0x1f)) : ((0xff55ff00)>>(((7
-(5))*8+(7-(0))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((0)*(4))^((1)?8-(4):0))) &
0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+
(7-(1))) & 0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(
1))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((1)*(4))^((1)?8-(4):0))) & 0x1f))):0) +
((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+(7-(2))) &
0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(2))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((2)*(4))^((1)?8-(4):0))) & 0x1f))):0) + ((((5)<4 ?
((0xff0fff33)>>(((3-(5))*8+(7-(3))) & 0x1f)) : ((0xff55ff00
)>>(((7-(5))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((3)*(4))^((1)?8-
(4):0))) & 0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>
(((3-(5))*8+(7-(4))) & 0x1f)) : ((0xff55ff00)>>(((7
-(5))*8+(7-(4))) & 0x1f))) & 1)?(((((((1U)<<(((
4)) & 0x1f)))-1))<<(((((4)*(4))^((1)?8-(4):0))) &
0x1f))):0) + ((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+
(7-(5))) & 0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(
5))) & 0x1f))) & 1)?(((((((1U)<<(((4)) & 0x1f
)))-1))<<(((((5)*(4))^((1)?8-(4):0))) & 0x1f))):0) +
((((5)<4 ? ((0xff0fff33)>>(((3-(5))*8+(7-(6))) &
0x1f)) : ((0xff55ff00)>>(((7-(5))*8+(7-(6))) & 0x1f
))) & 1)?(((((((1U)<<(((4)) & 0x1f)))-1))<<
(((((6)*(4))^((1)?8-(4):0))) & 0x1f))):0) + ((((5)<4 ?
((0xff0fff33)>>(((3-(5))*8+(7-(7))) & 0x1f)) : ((0xff55ff00
)>>(((7-(5))*8+(7-(7))) & 0x1f))) & 1)?(((((((1U
)<<(((4)) & 0x1f)))-1))<<(((((7)*(4))^((1)?8-
(4):0))) & 0x1f))):0))*((4)==1?0x01010101:((4)==2?0x00010001
:1))) }
}
3597 };
3598
3599# define MASK(pass,depth,display,png)((display)?display_mask[png][((depth)==1?0:((depth)==2?1:2))]
[pass>>1]: row_mask[png][((depth)==1?0:((depth)==2?1:2)
)][pass])
\
3600 ((display)?display_mask[png][DEPTH_INDEX(depth)((depth)==1?0:((depth)==2?1:2))][pass>>1]:\
3601 row_mask[png][DEPTH_INDEX(depth)((depth)==1?0:((depth)==2?1:2))][pass])
3602
3603#else /* !PNG_USE_COMPILE_TIME_MASKS */
3604 /* This is the runtime alternative: it seems unlikely that this will
3605 * ever be either smaller or faster than the compile time approach.
3606 */
3607# define MASK(pass,depth,display,png)((display)?display_mask[png][((depth)==1?0:((depth)==2?1:2))]
[pass>>1]: row_mask[png][((depth)==1?0:((depth)==2?1:2)
)][pass])
\
3608 ((display)?B_MASK(pass,depth,png)((((((pass)<4 ? ((0xff0fff33)>>(((3-(pass))*8+(7-(0)
)) & 0x1f)) : ((0xff55ff00)>>(((7-(pass))*8+(7-(0))
) & 0x1f))) & 1)?(((((((1U)<<(((depth)) & 0x1f
)))-1))<<(((((0)*(depth))^((png)?8-(depth):0))) & 0x1f
))):0) + ((((pass)<4 ? ((0xff0fff33)>>(((3-(pass))*8
+(7-(1))) & 0x1f)) : ((0xff55ff00)>>(((7-(pass))*8+
(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((depth)) &
0x1f)))-1))<<(((((1)*(depth))^((png)?8-(depth):0))) &
0x1f))):0) + ((((pass)<4 ? ((0xff0fff33)>>(((3-(pass
))*8+(7-(2))) & 0x1f)) : ((0xff55ff00)>>(((7-(pass)
)*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((depth
)) & 0x1f)))-1))<<(((((2)*(depth))^((png)?8-(depth)
:0))) & 0x1f))):0) + ((((pass)<4 ? ((0xff0fff33)>>
(((3-(pass))*8+(7-(3))) & 0x1f)) : ((0xff55ff00)>>(
((7-(pass))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U)<<
(((depth)) & 0x1f)))-1))<<(((((3)*(depth))^((png)?8
-(depth):0))) & 0x1f))):0) + ((((pass)<4 ? ((0xff0fff33
)>>(((3-(pass))*8+(7-(4))) & 0x1f)) : ((0xff55ff00)
>>(((7-(pass))*8+(7-(4))) & 0x1f))) & 1)?((((((
(1U)<<(((depth)) & 0x1f)))-1))<<(((((4)*(depth
))^((png)?8-(depth):0))) & 0x1f))):0) + ((((pass)<4 ? (
(0xff0fff33)>>(((3-(pass))*8+(7-(5))) & 0x1f)) : ((
0xff55ff00)>>(((7-(pass))*8+(7-(5))) & 0x1f))) &
1)?(((((((1U)<<(((depth)) & 0x1f)))-1))<<(((
((5)*(depth))^((png)?8-(depth):0))) & 0x1f))):0) + ((((pass
)<4 ? ((0xff0fff33)>>(((3-(pass))*8+(7-(6))) & 0x1f
)) : ((0xff55ff00)>>(((7-(pass))*8+(7-(6))) & 0x1f)
)) & 1)?(((((((1U)<<(((depth)) & 0x1f)))-1))<<
(((((6)*(depth))^((png)?8-(depth):0))) & 0x1f))):0) + (((
(pass)<4 ? ((0xff0fff33)>>(((3-(pass))*8+(7-(7))) &
0x1f)) : ((0xff55ff00)>>(((7-(pass))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((depth)) & 0x1f)))-1))<<
(((((7)*(depth))^((png)?8-(depth):0))) & 0x1f))):0))*((depth
)==1?0x01010101:((depth)==2?0x00010001:1)))
:S_MASK(pass,depth,png)((((((pass)<4 ? ((0x80088822)>>(((3-(pass))*8+(7-(0)
)) & 0x1f)) : ((0xaa55ff00)>>(((7-(pass))*8+(7-(0))
) & 0x1f))) & 1)?(((((((1U)<<(((depth)) & 0x1f
)))-1))<<(((((0)*(depth))^((png)?8-(depth):0))) & 0x1f
))):0) + ((((pass)<4 ? ((0x80088822)>>(((3-(pass))*8
+(7-(1))) & 0x1f)) : ((0xaa55ff00)>>(((7-(pass))*8+
(7-(1))) & 0x1f))) & 1)?(((((((1U)<<(((depth)) &
0x1f)))-1))<<(((((1)*(depth))^((png)?8-(depth):0))) &
0x1f))):0) + ((((pass)<4 ? ((0x80088822)>>(((3-(pass
))*8+(7-(2))) & 0x1f)) : ((0xaa55ff00)>>(((7-(pass)
)*8+(7-(2))) & 0x1f))) & 1)?(((((((1U)<<(((depth
)) & 0x1f)))-1))<<(((((2)*(depth))^((png)?8-(depth)
:0))) & 0x1f))):0) + ((((pass)<4 ? ((0x80088822)>>
(((3-(pass))*8+(7-(3))) & 0x1f)) : ((0xaa55ff00)>>(
((7-(pass))*8+(7-(3))) & 0x1f))) & 1)?(((((((1U)<<
(((depth)) & 0x1f)))-1))<<(((((3)*(depth))^((png)?8
-(depth):0))) & 0x1f))):0) + ((((pass)<4 ? ((0x80088822
)>>(((3-(pass))*8+(7-(4))) & 0x1f)) : ((0xaa55ff00)
>>(((7-(pass))*8+(7-(4))) & 0x1f))) & 1)?((((((
(1U)<<(((depth)) & 0x1f)))-1))<<(((((4)*(depth
))^((png)?8-(depth):0))) & 0x1f))):0) + ((((pass)<4 ? (
(0x80088822)>>(((3-(pass))*8+(7-(5))) & 0x1f)) : ((
0xaa55ff00)>>(((7-(pass))*8+(7-(5))) & 0x1f))) &
1)?(((((((1U)<<(((depth)) & 0x1f)))-1))<<(((
((5)*(depth))^((png)?8-(depth):0))) & 0x1f))):0) + ((((pass
)<4 ? ((0x80088822)>>(((3-(pass))*8+(7-(6))) & 0x1f
)) : ((0xaa55ff00)>>(((7-(pass))*8+(7-(6))) & 0x1f)
)) & 1)?(((((((1U)<<(((depth)) & 0x1f)))-1))<<
(((((6)*(depth))^((png)?8-(depth):0))) & 0x1f))):0) + (((
(pass)<4 ? ((0x80088822)>>(((3-(pass))*8+(7-(7))) &
0x1f)) : ((0xaa55ff00)>>(((7-(pass))*8+(7-(7))) & 0x1f
))) & 1)?(((((((1U)<<(((depth)) & 0x1f)))-1))<<
(((((7)*(depth))^((png)?8-(depth):0))) & 0x1f))):0))*((depth
)==1?0x01010101:((depth)==2?0x00010001:1)))
)
3609#endif /* !USE_COMPILE_TIME_MASKS */
3610
3611 /* Use the appropriate mask to copy the required bits. In some cases
3612 * the byte mask will be 0 or 0xff; optimize these cases. row_width is
3613 * the number of pixels, but the code copies bytes, so it is necessary
3614 * to special case the end.
3615 */
3616 png_uint_32 pixels_per_byte = 8 / pixel_depth;
3617 png_uint_32 mask;
3618
3619# ifdef PNG_READ_PACKSWAP_SUPPORTED
3620 if ((png_ptr->transformations & PNG_PACKSWAP0x10000U) != 0)
3621 mask = MASK(pass, pixel_depth, display, 0)((display)?display_mask[0][((pixel_depth)==1?0:((pixel_depth)
==2?1:2))][pass>>1]: row_mask[0][((pixel_depth)==1?0:((
pixel_depth)==2?1:2))][pass])
;
3622
3623 else
3624# endif
3625 mask = MASK(pass, pixel_depth, display, 1)((display)?display_mask[1][((pixel_depth)==1?0:((pixel_depth)
==2?1:2))][pass>>1]: row_mask[1][((pixel_depth)==1?0:((
pixel_depth)==2?1:2))][pass])
;
3626
3627 for (;;)
3628 {
3629 png_uint_32 m;
3630
3631 /* It doesn't matter in the following if png_uint_32 has more than
3632 * 32 bits because the high bits always match those in m<<24; it is,
3633 * however, essential to use OR here, not +, because of this.
3634 */
3635 m = mask;
3636 mask = (m >> 8) | (m << 24); /* rotate right to good compilers */
3637 m &= 0xff;
3638
3639 if (m != 0) /* something to copy */
3640 {
3641 if (m != 0xff)
3642 *dp = (png_byte)((*dp & ~m) | (*sp & m));
3643 else
3644 *dp = *sp;
3645 }
3646
3647 /* NOTE: this may overwrite the last byte with garbage if the image
3648 * is not an exact number of bytes wide; libpng has always done
3649 * this.
3650 */
3651 if (row_width <= pixels_per_byte)
3652 break; /* May need to restore part of the last byte */
3653
3654 row_width -= pixels_per_byte;
3655 ++dp;
3656 ++sp;
3657 }
3658 }
3659
3660 else /* pixel_depth >= 8 */
3661 {
3662 unsigned int bytes_to_copy, bytes_to_jump;
3663
3664 /* Validate the depth - it must be a multiple of 8 */
3665 if (pixel_depth & 7)
3666 png_error(png_ptr, "invalid user transform pixel depth");
3667
3668 pixel_depth >>= 3; /* now in bytes */
3669 row_width *= pixel_depth;
3670
3671 /* Regardless of pass number the Adam 7 interlace always results in a
3672 * fixed number of pixels to copy then to skip. There may be a
3673 * different number of pixels to skip at the start though.
3674 */
3675 {
3676 unsigned int offset = PNG_PASS_START_COL(pass)(((1& (pass))<<(3-(((pass)+1)>>1)))&7) * pixel_depth;
3677
3678 row_width -= offset;
3679 dp += offset;
3680 sp += offset;
3681 }
3682
3683 /* Work out the bytes to copy. */
3684 if (display != 0)
3685 {
3686 /* When doing the 'block' algorithm the pixel in the pass gets
3687 * replicated to adjacent pixels. This is why the even (0,2,4,6)
3688 * passes are skipped above - the entire expanded row is copied.
3689 */
3690 bytes_to_copy = (1<<((6-pass)>>1)) * pixel_depth;
3691
3692 /* But don't allow this number to exceed the actual row width. */
3693 if (bytes_to_copy > row_width)
3694 bytes_to_copy = (unsigned int)/*SAFE*/row_width;
3695 }
3696
3697 else /* normal row; Adam7 only ever gives us one pixel to copy. */
3698 bytes_to_copy = pixel_depth;
3699
3700 /* In Adam7 there is a constant offset between where the pixels go. */
3701 bytes_to_jump = PNG_PASS_COL_OFFSET(pass)(1<<((7-(pass))>>1)) * pixel_depth;
3702
3703 /* And simply copy these bytes. Some optimization is possible here,
3704 * depending on the value of 'bytes_to_copy'. Special case the low
3705 * byte counts, which we know to be frequent.
3706 *
3707 * Notice that these cases all 'return' rather than 'break' - this
3708 * avoids an unnecessary test on whether to restore the last byte
3709 * below.
3710 */
3711 switch (bytes_to_copy)
3712 {
3713 case 1:
3714 for (;;)
3715 {
3716 *dp = *sp;
3717
3718 if (row_width <= bytes_to_jump)
3719 return;
3720
3721 dp += bytes_to_jump;
3722 sp += bytes_to_jump;
3723 row_width -= bytes_to_jump;
3724 }
3725
3726 case 2:
3727 /* There is a possibility of a partial copy at the end here; this
3728 * slows the code down somewhat.
3729 */
3730 do
3731 {
3732 dp[0] = sp[0]; dp[1] = sp[1];
3733
3734 if (row_width <= bytes_to_jump)
3735 return;
3736
3737 sp += bytes_to_jump;
3738 dp += bytes_to_jump;
3739 row_width -= bytes_to_jump;
3740 }
3741 while (row_width > 1);
3742
3743 /* And there can only be one byte left at this point: */
3744 *dp = *sp;
3745 return;
3746
3747 case 3:
3748 /* This can only be the RGB case, so each copy is exactly one
3749 * pixel and it is not necessary to check for a partial copy.
3750 */
3751 for (;;)
3752 {
3753 dp[0] = sp[0]; dp[1] = sp[1]; dp[2] = sp[2];
3754
3755 if (row_width <= bytes_to_jump)
3756 return;
3757
3758 sp += bytes_to_jump;
3759 dp += bytes_to_jump;
3760 row_width -= bytes_to_jump;
3761 }
3762
3763 default:
3764#if PNG_ALIGN_TYPE3 != PNG_ALIGN_NONE0
3765 /* Check for double byte alignment and, if possible, use a
3766 * 16-bit copy. Don't attempt this for narrow images - ones that
3767 * are less than an interlace panel wide. Don't attempt it for
3768 * wide bytes_to_copy either - use the memcpy there.
3769 */
3770 if (bytes_to_copy < 16 /*else use memcpy*/ &&
3771 png_isaligned(dp, png_uint_16)(((png_uint_16)(size_t)((const void*)(dp)) & (png_uint_16
)((sizeof(png_uint_16))-1)) == 0)
&&
3772 png_isaligned(sp, png_uint_16)(((png_uint_16)(size_t)((const void*)(sp)) & (png_uint_16
)((sizeof(png_uint_16))-1)) == 0)
&&
3773 bytes_to_copy % (sizeof (png_uint_16)) == 0 &&
3774 bytes_to_jump % (sizeof (png_uint_16)) == 0)
3775 {
3776 /* Everything is aligned for png_uint_16 copies, but try for
3777 * png_uint_32 first.
3778 */
3779 if (png_isaligned(dp, png_uint_32)(((png_uint_32)(size_t)((const void*)(dp)) & (png_uint_32
)((sizeof(png_uint_32))-1)) == 0)
&&
3780 png_isaligned(sp, png_uint_32)(((png_uint_32)(size_t)((const void*)(sp)) & (png_uint_32
)((sizeof(png_uint_32))-1)) == 0)
&&
3781 bytes_to_copy % (sizeof (png_uint_32)) == 0 &&
3782 bytes_to_jump % (sizeof (png_uint_32)) == 0)
3783 {
3784 png_uint_32p dp32 = png_aligncast(png_uint_32p,dp)((void*)(dp));
3785 png_const_uint_32p sp32 = png_aligncastconst(((const void*)(sp))
3786 png_const_uint_32p, sp)((const void*)(sp));
3787 size_t skip = (bytes_to_jump-bytes_to_copy) /
3788 (sizeof (png_uint_32));
3789
3790 do
3791 {
3792 size_t c = bytes_to_copy;
3793 do
3794 {
3795 *dp32++ = *sp32++;
3796 c -= (sizeof (png_uint_32));
3797 }
3798 while (c > 0);
3799
3800 if (row_width <= bytes_to_jump)
3801 return;
3802
3803 dp32 += skip;
3804 sp32 += skip;
3805 row_width -= bytes_to_jump;
3806 }
3807 while (bytes_to_copy <= row_width);
3808
3809 /* Get to here when the row_width truncates the final copy.
3810 * There will be 1-3 bytes left to copy, so don't try the
3811 * 16-bit loop below.
3812 */
3813 dp = (png_bytep)dp32;
3814 sp = (png_const_bytep)sp32;
3815 do
3816 *dp++ = *sp++;
3817 while (--row_width > 0);
3818 return;
3819 }
3820
3821 /* Else do it in 16-bit quantities, but only if the size is
3822 * not too large.
3823 */
3824 else
3825 {
3826 png_uint_16p dp16 = png_aligncast(png_uint_16p, dp)((void*)(dp));
3827 png_const_uint_16p sp16 = png_aligncastconst(((const void*)(sp))
3828 png_const_uint_16p, sp)((const void*)(sp));
3829 size_t skip = (bytes_to_jump-bytes_to_copy) /
3830 (sizeof (png_uint_16));
3831
3832 do
3833 {
3834 size_t c = bytes_to_copy;
3835 do
3836 {
3837 *dp16++ = *sp16++;
3838 c -= (sizeof (png_uint_16));
3839 }
3840 while (c > 0);
3841
3842 if (row_width <= bytes_to_jump)
3843 return;
3844
3845 dp16 += skip;
3846 sp16 += skip;
3847 row_width -= bytes_to_jump;
3848 }
3849 while (bytes_to_copy <= row_width);
3850
3851 /* End of row - 1 byte left, bytes_to_copy > row_width: */
3852 dp = (png_bytep)dp16;
3853 sp = (png_const_bytep)sp16;
3854 do
3855 *dp++ = *sp++;
3856 while (--row_width > 0);
3857 return;
3858 }
3859 }
3860#endif /* ALIGN_TYPE code */
3861
3862 /* The true default - use a memcpy: */
3863 for (;;)
3864 {
3865 memcpy(dp, sp, bytes_to_copy);
3866
3867 if (row_width <= bytes_to_jump)
3868 return;
3869
3870 sp += bytes_to_jump;
3871 dp += bytes_to_jump;
3872 row_width -= bytes_to_jump;
3873 if (bytes_to_copy > row_width)
3874 bytes_to_copy = (unsigned int)/*SAFE*/row_width;
3875 }
3876 }
3877
3878 /* NOT REACHED*/
3879 } /* pixel_depth >= 8 */
3880
3881 /* Here if pixel_depth < 8 to check 'end_ptr' below. */
3882 }
3883 else
3884#endif /* READ_INTERLACING */
3885
3886 /* If here then the switch above wasn't used so just memcpy the whole row
3887 * from the temporary row buffer (notice that this overwrites the end of the
3888 * destination row if it is a partial byte.)
3889 */
3890 memcpy(dp, sp, PNG_ROWBYTES(pixel_depth, row_width)((pixel_depth) >= 8 ? ((size_t)(row_width) * (((size_t)(pixel_depth
)) >> 3)) : (( ((size_t)(row_width) * ((size_t)(pixel_depth
))) + 7) >> 3) )
);
3891
3892 /* Restore the overwritten bits from the last byte if necessary. */
3893 if (end_ptr != NULL((void*)0))
3894 *end_ptr = (png_byte)((end_byte & end_mask) | (*end_ptr & ~end_mask));
3895}
3896
3897#ifdef PNG_READ_INTERLACING_SUPPORTED
3898void /* PRIVATE */
3899png_do_read_interlaceMOZ_PNG_do_read_int(png_row_infop row_info, png_bytep row, int pass,
3900 png_uint_32 transformations /* Because these may affect the byte layout */)
3901{
3902 png_debug(1, "in png_do_read_interlace")((void)0);
3903 if (row != NULL((void*)0) && row_info != NULL((void*)0))
3904 {
3905 png_uint_32 final_width;
3906
3907 final_width = row_info->width * png_pass_inc[pass];
3908
3909 switch (row_info->pixel_depth)
3910 {
3911 case 1:
3912 {
3913 png_bytep sp = row + (size_t)((row_info->width - 1) >> 3);
3914 png_bytep dp = row + (size_t)((final_width - 1) >> 3);
3915 unsigned int sshift, dshift;
3916 unsigned int s_start, s_end;
3917 int s_inc;
3918 int jstop = (int)png_pass_inc[pass];
3919 png_byte v;
3920 png_uint_32 i;
3921 int j;
3922
3923#ifdef PNG_READ_PACKSWAP_SUPPORTED
3924 if ((transformations & PNG_PACKSWAP0x10000U) != 0)
3925 {
3926 sshift = ((row_info->width + 7) & 0x07);
3927 dshift = ((final_width + 7) & 0x07);
3928 s_start = 7;
3929 s_end = 0;
3930 s_inc = -1;
3931 }
3932
3933 else
3934#endif
3935 {
3936 sshift = 7 - ((row_info->width + 7) & 0x07);
3937 dshift = 7 - ((final_width + 7) & 0x07);
3938 s_start = 0;
3939 s_end = 7;
3940 s_inc = 1;
3941 }
3942
3943 for (i = 0; i < row_info->width; i++)
3944 {
3945 v = (png_byte)((*sp >> sshift) & 0x01);
3946 for (j = 0; j < jstop; j++)
3947 {
3948 unsigned int tmp = *dp & (0x7f7f >> (7 - dshift));
3949 tmp |= (unsigned int)(v << dshift);
3950 *dp = (png_byte)(tmp & 0xff);
3951
3952 if (dshift == s_end)
3953 {
3954 dshift = s_start;
3955 dp--;
3956 }
3957
3958 else
3959 dshift = (unsigned int)((int)dshift + s_inc);
3960 }
3961
3962 if (sshift == s_end)
3963 {
3964 sshift = s_start;
3965 sp--;
3966 }
3967
3968 else
3969 sshift = (unsigned int)((int)sshift + s_inc);
3970 }
3971 break;
3972 }
3973
3974 case 2:
3975 {
3976 png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
3977 png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
3978 unsigned int sshift, dshift;
3979 unsigned int s_start, s_end;
3980 int s_inc;
3981 int jstop = (int)png_pass_inc[pass];
3982 png_uint_32 i;
3983
3984#ifdef PNG_READ_PACKSWAP_SUPPORTED
3985 if ((transformations & PNG_PACKSWAP0x10000U) != 0)
3986 {
3987 sshift = (((row_info->width + 3) & 0x03) << 1);
3988 dshift = (((final_width + 3) & 0x03) << 1);
3989 s_start = 6;
3990 s_end = 0;
3991 s_inc = -2;
3992 }
3993
3994 else
3995#endif
3996 {
3997 sshift = ((3 - ((row_info->width + 3) & 0x03)) << 1);
3998 dshift = ((3 - ((final_width + 3) & 0x03)) << 1);
3999 s_start = 0;
4000 s_end = 6;
4001 s_inc = 2;
4002 }
4003
4004 for (i = 0; i < row_info->width; i++)
4005 {
4006 png_byte v;
4007 int j;
4008
4009 v = (png_byte)((*sp >> sshift) & 0x03);
4010 for (j = 0; j < jstop; j++)
4011 {
4012 unsigned int tmp = *dp & (0x3f3f >> (6 - dshift));
4013 tmp |= (unsigned int)(v << dshift);
4014 *dp = (png_byte)(tmp & 0xff);
4015
4016 if (dshift == s_end)
4017 {
4018 dshift = s_start;
4019 dp--;
4020 }
4021
4022 else
4023 dshift = (unsigned int)((int)dshift + s_inc);
4024 }
4025
4026 if (sshift == s_end)
4027 {
4028 sshift = s_start;
4029 sp--;
4030 }
4031
4032 else
4033 sshift = (unsigned int)((int)sshift + s_inc);
4034 }
4035 break;
4036 }
4037
4038 case 4:
4039 {
4040 png_bytep sp = row + (size_t)((row_info->width - 1) >> 1);
4041 png_bytep dp = row + (size_t)((final_width - 1) >> 1);
4042 unsigned int sshift, dshift;
4043 unsigned int s_start, s_end;
4044 int s_inc;
4045 png_uint_32 i;
4046 int jstop = (int)png_pass_inc[pass];
4047
4048#ifdef PNG_READ_PACKSWAP_SUPPORTED
4049 if ((transformations & PNG_PACKSWAP0x10000U) != 0)
4050 {
4051 sshift = (((row_info->width + 1) & 0x01) << 2);
4052 dshift = (((final_width + 1) & 0x01) << 2);
4053 s_start = 4;
4054 s_end = 0;
4055 s_inc = -4;
4056 }
4057
4058 else
4059#endif
4060 {
4061 sshift = ((1 - ((row_info->width + 1) & 0x01)) << 2);
4062 dshift = ((1 - ((final_width + 1) & 0x01)) << 2);
4063 s_start = 0;
4064 s_end = 4;
4065 s_inc = 4;
4066 }
4067
4068 for (i = 0; i < row_info->width; i++)
4069 {
4070 png_byte v = (png_byte)((*sp >> sshift) & 0x0f);
4071 int j;
4072
4073 for (j = 0; j < jstop; j++)
4074 {
4075 unsigned int tmp = *dp & (0xf0f >> (4 - dshift));
4076 tmp |= (unsigned int)(v << dshift);
4077 *dp = (png_byte)(tmp & 0xff);
4078
4079 if (dshift == s_end)
4080 {
4081 dshift = s_start;
4082 dp--;
4083 }
4084
4085 else
4086 dshift = (unsigned int)((int)dshift + s_inc);
4087 }
4088
4089 if (sshift == s_end)
4090 {
4091 sshift = s_start;
4092 sp--;
4093 }
4094
4095 else
4096 sshift = (unsigned int)((int)sshift + s_inc);
4097 }
4098 break;
4099 }
4100
4101 default:
4102 {
4103 size_t pixel_bytes = (row_info->pixel_depth >> 3);
4104
4105 png_bytep sp = row + (size_t)(row_info->width - 1)
4106 * pixel_bytes;
4107
4108 png_bytep dp = row + (size_t)(final_width - 1) * pixel_bytes;
4109
4110 int jstop = (int)png_pass_inc[pass];
4111 png_uint_32 i;
4112
4113 for (i = 0; i < row_info->width; i++)
4114 {
4115 png_byte v[8]; /* SAFE; pixel_depth does not exceed 64 */
4116 int j;
4117
4118 memcpy(v, sp, pixel_bytes);
4119
4120 for (j = 0; j < jstop; j++)
4121 {
4122 memcpy(dp, v, pixel_bytes);
4123 dp -= pixel_bytes;
4124 }
4125
4126 sp -= pixel_bytes;
4127 }
4128 break;
4129 }
4130 }
4131
4132 row_info->width = final_width;
4133 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width)((row_info->pixel_depth) >= 8 ? ((size_t)(final_width) *
(((size_t)(row_info->pixel_depth)) >> 3)) : (( ((size_t
)(final_width) * ((size_t)(row_info->pixel_depth))) + 7) >>
3) )
;
4134 }
4135#ifndef PNG_READ_PACKSWAP_SUPPORTED
4136 PNG_UNUSED(transformations)(void)transformations; /* Silence compiler warning */
4137#endif
4138}
4139#endif /* READ_INTERLACING */
4140
4141static void
4142png_read_filter_row_subMOZ_PNG_read_filt_row_s(png_row_infop row_info, png_bytep row,
4143 png_const_bytep prev_row)
4144{
4145 size_t i;
4146 size_t istop = row_info->rowbytes;
4147 unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
4148 png_bytep rp = row + bpp;
4149
4150 PNG_UNUSED(prev_row)(void)prev_row;
4151
4152 for (i = bpp; i < istop; i++)
4153 {
4154 *rp = (png_byte)(((int)(*rp) + (int)(*(rp-bpp))) & 0xff);
4155 rp++;
4156 }
4157}
4158
4159static void
4160png_read_filter_row_upMOZ_PNG_read_filt_row_up(png_row_infop row_info, png_bytep row,
4161 png_const_bytep prev_row)
4162{
4163 size_t i;
4164 size_t istop = row_info->rowbytes;
4165 png_bytep rp = row;
4166 png_const_bytep pp = prev_row;
4167
4168 for (i = 0; i < istop; i++)
4169 {
4170 *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
4171 rp++;
4172 }
4173}
4174
4175static void
4176png_read_filter_row_avgMOZ_PNG_read_filt_row_a(png_row_infop row_info, png_bytep row,
4177 png_const_bytep prev_row)
4178{
4179 size_t i;
4180 png_bytep rp = row;
4181 png_const_bytep pp = prev_row;
4182 unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
4183 size_t istop = row_info->rowbytes - bpp;
4184
4185 for (i = 0; i < bpp; i++)
4186 {
4187 *rp = (png_byte)(((int)(*rp) +
4188 ((int)(*pp++) / 2 )) & 0xff);
4189
4190 rp++;
4191 }
4192
4193 for (i = 0; i < istop; i++)
4194 {
4195 *rp = (png_byte)(((int)(*rp) +
4196 (int)(*pp++ + *(rp-bpp)) / 2 ) & 0xff);
4197
4198 rp++;
4199 }
4200}
4201
4202static void
4203png_read_filter_row_paeth_1byte_pixelMOZ_PNG_read_filt_row_p_1b_px(png_row_infop row_info, png_bytep row,
4204 png_const_bytep prev_row)
4205{
4206 png_bytep rp_end = row + row_info->rowbytes;
4207 int a, c;
4208
4209 /* First pixel/byte */
4210 c = *prev_row++;
4211 a = *row + c;
4212 *row++ = (png_byte)a;
4213
4214 /* Remainder */
4215 while (row < rp_end)
4216 {
4217 int b, pa, pb, pc, p;
4218
4219 a &= 0xff; /* From previous iteration or start */
4220 b = *prev_row++;
4221
4222 p = b - c;
4223 pc = a - c;
4224
4225#ifdef PNG_USE_ABS
4226 pa = abs(p);
4227 pb = abs(pc);
4228 pc = abs(p + pc);
4229#else
4230 pa = p < 0 ? -p : p;
4231 pb = pc < 0 ? -pc : pc;
4232 pc = (p + pc) < 0 ? -(p + pc) : p + pc;
4233#endif
4234
4235 /* Find the best predictor, the least of pa, pb, pc favoring the earlier
4236 * ones in the case of a tie.
4237 */
4238 if (pb < pa)
4239 {
4240 pa = pb; a = b;
4241 }
4242 if (pc < pa) a = c;
4243
4244 /* Calculate the current pixel in a, and move the previous row pixel to c
4245 * for the next time round the loop
4246 */
4247 c = b;
4248 a += *row;
4249 *row++ = (png_byte)a;
4250 }
4251}
4252
4253static void
4254png_read_filter_row_paeth_multibyte_pixelMOZ_PNG_read_filt_row_p_mb_px(png_row_infop row_info, png_bytep row,
4255 png_const_bytep prev_row)
4256{
4257 unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
4258 png_bytep rp_end = row + bpp;
4259
4260 /* Process the first pixel in the row completely (this is the same as 'up'
4261 * because there is only one candidate predictor for the first row).
4262 */
4263 while (row < rp_end)
4264 {
4265 int a = *row + *prev_row++;
4266 *row++ = (png_byte)a;
4267 }
4268
4269 /* Remainder */
4270 rp_end = rp_end + (row_info->rowbytes - bpp);
4271
4272 while (row < rp_end)
4273 {
4274 int a, b, c, pa, pb, pc, p;
4275
4276 c = *(prev_row - bpp);
4277 a = *(row - bpp);
4278 b = *prev_row++;
4279
4280 p = b - c;
4281 pc = a - c;
4282
4283#ifdef PNG_USE_ABS
4284 pa = abs(p);
4285 pb = abs(pc);
4286 pc = abs(p + pc);
4287#else
4288 pa = p < 0 ? -p : p;
4289 pb = pc < 0 ? -pc : pc;
4290 pc = (p + pc) < 0 ? -(p + pc) : p + pc;
4291#endif
4292
4293 if (pb < pa)
4294 {
4295 pa = pb; a = b;
4296 }
4297 if (pc < pa) a = c;
4298
4299 a += *row;
4300 *row++ = (png_byte)a;
4301 }
4302}
4303
4304static void
4305png_init_filter_functionsMOZ_PNG_init_filt_func(png_structrp pp)
4306 /* This function is called once for every PNG image (except for PNG images
4307 * that only use PNG_FILTER_VALUE_NONE for all rows) to set the
4308 * implementations required to reverse the filtering of PNG rows. Reversing
4309 * the filter is the first transformation performed on the row data. It is
4310 * performed in place, therefore an implementation can be selected based on
4311 * the image pixel format. If the implementation depends on image width then
4312 * take care to ensure that it works correctly if the image is interlaced -
4313 * interlacing causes the actual row width to vary.
4314 */
4315{
4316 unsigned int bpp = (pp->pixel_depth + 7) >> 3;
4317
4318 pp->read_filter[PNG_FILTER_VALUE_SUB1-1] = png_read_filter_row_subMOZ_PNG_read_filt_row_s;
4319 pp->read_filter[PNG_FILTER_VALUE_UP2-1] = png_read_filter_row_upMOZ_PNG_read_filt_row_up;
4320 pp->read_filter[PNG_FILTER_VALUE_AVG3-1] = png_read_filter_row_avgMOZ_PNG_read_filt_row_a;
4321 if (bpp == 1)
4322 pp->read_filter[PNG_FILTER_VALUE_PAETH4-1] =
4323 png_read_filter_row_paeth_1byte_pixelMOZ_PNG_read_filt_row_p_1b_px;
4324 else
4325 pp->read_filter[PNG_FILTER_VALUE_PAETH4-1] =
4326 png_read_filter_row_paeth_multibyte_pixelMOZ_PNG_read_filt_row_p_mb_px;
4327
4328#ifdef PNG_FILTER_OPTIMIZATIONSMOZ_PNG_init_filt_func_sse2
4329 /* To use this define PNG_FILTER_OPTIMIZATIONS as the name of a function to
4330 * call to install hardware optimizations for the above functions; simply
4331 * replace whatever elements of the pp->read_filter[] array with a hardware
4332 * specific (or, for that matter, generic) optimization.
4333 *
4334 * To see an example of this examine what configure.ac does when
4335 * --enable-arm-neon is specified on the command line.
4336 */
4337 PNG_FILTER_OPTIMIZATIONSMOZ_PNG_init_filt_func_sse2(pp, bpp);
4338#endif
4339}
4340
4341void /* PRIVATE */
4342png_read_filter_rowMOZ_PNG_read_filt_row(png_structrp pp, png_row_infop row_info, png_bytep row,
4343 png_const_bytep prev_row, int filter)
4344{
4345 /* OPTIMIZATION: DO NOT MODIFY THIS FUNCTION, instead #define
4346 * PNG_FILTER_OPTIMIZATIONS to a function that overrides the generic
4347 * implementations. See png_init_filter_functions above.
4348 */
4349 if (filter > PNG_FILTER_VALUE_NONE0 && filter < PNG_FILTER_VALUE_LAST5)
4350 {
4351 if (pp->read_filter[0] == NULL((void*)0))
4352 png_init_filter_functionsMOZ_PNG_init_filt_func(pp);
4353
4354 pp->read_filter[filter-1](row_info, row, prev_row);
4355 }
4356}
4357
4358#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
4359void /* PRIVATE */
4360png_read_IDAT_data(png_structrp png_ptr, png_bytep output,
4361 png_alloc_size_t avail_out)
4362{
4363 /* Loop reading IDATs and decompressing the result into output[avail_out] */
4364 png_ptr->zstream.next_out = output;
4365 png_ptr->zstream.avail_out = 0; /* safety: set below */
4366
4367 if (output == NULL((void*)0))
4368 avail_out = 0;
4369
4370 do
4371 {
4372 int ret;
4373 png_byte tmpbuf[PNG_INFLATE_BUF_SIZE1024];
4374
4375 if (png_ptr->zstream.avail_in == 0)
4376 {
4377 uInt avail_in;
4378 png_bytep buffer;
4379
4380#ifdef PNG_READ_APNG_SUPPORTED
4381 png_uint_32 bytes_to_skip = 0;
4382
4383 while (png_ptr->idat_size == 0 || bytes_to_skip != 0)
4384 {
4385 png_crc_finishMOZ_PNG_crc_finish(png_ptr, bytes_to_skip);
4386 bytes_to_skip = 0;
4387
4388 png_ptr->idat_size = png_read_chunk_headerMOZ_PNG_read_chunk_header(png_ptr);
4389 if (png_ptr->num_frames_read == 0)
4390 {
4391 if (png_ptr->chunk_name != png_IDAT((((0xFFFFFFFFU)&(73)) << (24)) | (((0xFFFFFFFFU)&
(68)) << (16)) | (((0xFFFFFFFFU)&(65)) << (8)
) | (((0xFFFFFFFFU)&(84)) << (0)))
)
4392 png_error(png_ptr, "Not enough image data");
4393 }
4394 else
4395 {
4396 if (png_ptr->chunk_name == png_IEND((((0xFFFFFFFFU)&(73)) << (24)) | (((0xFFFFFFFFU)&
(69)) << (16)) | (((0xFFFFFFFFU)&(78)) << (8)
) | (((0xFFFFFFFFU)&(68)) << (0)))
)
4397 png_error(png_ptr, "Not enough image data");
4398 if (png_ptr->chunk_name != png_fdAT((((0xFFFFFFFFU)&(102)) << (24)) | (((0xFFFFFFFFU)&
(100)) << (16)) | (((0xFFFFFFFFU)&(65)) << (8
)) | (((0xFFFFFFFFU)&(84)) << (0)))
)
4399 {
4400 png_warningMOZ_PNG_warning(png_ptr, "Skipped (ignored) a chunk "
4401 "between APNG chunks");
4402 bytes_to_skip = png_ptr->idat_size;
4403 continue;
4404 }
4405
4406 png_ensure_sequence_numberMOZ_APNG_ensure_seqno(png_ptr, png_ptr->idat_size);
4407
4408 png_ptr->idat_size -= 4;
4409 }
4410 }
4411#else
4412 while (png_ptr->idat_size == 0)
4413 {
4414 png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0);
4415
4416 png_ptr->idat_size = png_read_chunk_headerMOZ_PNG_read_chunk_header(png_ptr);
4417 /* This is an error even in the 'check' case because the code just
4418 * consumed a non-IDAT header.
4419 */
4420 if (png_ptr->chunk_name != png_IDAT((((0xFFFFFFFFU)&(73)) << (24)) | (((0xFFFFFFFFU)&
(68)) << (16)) | (((0xFFFFFFFFU)&(65)) << (8)
) | (((0xFFFFFFFFU)&(84)) << (0)))
)
4421 png_error(png_ptr, "Not enough image data");
4422 }
4423#endif /* READ_APNG */
4424
4425 avail_in = png_ptr->IDAT_read_size;
4426
4427 if (avail_in > png_chunk_max(png_ptr)((png_ptr)->user_chunk_malloc_max))
4428 avail_in = (uInt)/*SAFE*/png_chunk_max(png_ptr)((png_ptr)->user_chunk_malloc_max);
4429
4430 if (avail_in > png_ptr->idat_size)
4431 avail_in = (uInt)png_ptr->idat_size;
4432
4433 /* A PNG with a gradually increasing IDAT size will defeat this attempt
4434 * to minimize memory usage by causing lots of re-allocs, but
4435 * realistically doing IDAT_read_size re-allocs is not likely to be a
4436 * big problem.
4437 *
4438 * An error here corresponds to the system being out of memory.
4439 */
4440 buffer = png_read_buffer(png_ptr, avail_in);
4441
4442 if (buffer == NULL((void*)0))
4443 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, "out of memory");
4444
4445 png_crc_readMOZ_PNG_crc_read(png_ptr, buffer, avail_in);
4446 png_ptr->idat_size -= avail_in;
4447
4448 png_ptr->zstream.next_in = buffer;
4449 png_ptr->zstream.avail_in = avail_in;
4450 }
4451
4452 /* And set up the output side. */
4453 if (output != NULL((void*)0)) /* standard read */
4454 {
4455 uInt out = ZLIB_IO_MAX((uInt)-1);
4456
4457 if (out > avail_out)
4458 out = (uInt)avail_out;
4459
4460 avail_out -= out;
4461 png_ptr->zstream.avail_out = out;
4462 }
4463
4464 else /* after last row, checking for end */
4465 {
4466 png_ptr->zstream.next_out = tmpbuf;
4467 png_ptr->zstream.avail_out = (sizeof tmpbuf);
4468 }
4469
4470 /* Use NO_FLUSH; this gives zlib the maximum opportunity to optimize the
4471 * process. If the LZ stream is truncated the sequential reader will
4472 * terminally damage the stream, above, by reading the chunk header of the
4473 * following chunk (it then exits with png_error).
4474 *
4475 * TODO: deal more elegantly with truncated IDAT lists.
4476 */
4477 ret = PNG_INFLATE(png_ptr, Z_NO_FLUSH)png_zlib_inflate(png_ptr, 0);
4478
4479 /* Take the unconsumed output back. */
4480 if (output != NULL((void*)0))
4481 avail_out += png_ptr->zstream.avail_out;
4482
4483 else /* avail_out counts the extra bytes */
4484 avail_out += (sizeof tmpbuf) - png_ptr->zstream.avail_out;
4485
4486 png_ptr->zstream.avail_out = 0;
4487
4488 if (ret == Z_STREAM_END1)
4489 {
4490 /* Do this for safety; we won't read any more into this row. */
4491 png_ptr->zstream.next_out = NULL((void*)0);
4492
4493 png_ptr->mode |= PNG_AFTER_IDAT0x08;
4494 png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED0x0008U;
4495#ifdef PNG_READ_APNG_SUPPORTED
4496 png_ptr->num_frames_read++;
4497#endif
4498
4499 if (png_ptr->zstream.avail_in > 0 || png_ptr->idat_size > 0)
4500 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "Extra compressed data");
4501 break;
4502 }
4503
4504 if (ret != Z_OK0)
4505 {
4506 png_zstream_errorMOZ_PNG_zstream_error(png_ptr, ret);
4507
4508 if (output != NULL((void*)0))
4509 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, png_ptr->zstream.msg);
4510
4511 else /* checking */
4512 {
4513 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, png_ptr->zstream.msg);
4514 return;
4515 }
4516 }
4517 } while (avail_out > 0);
4518
4519 if (avail_out > 0)
4520 {
4521 /* The stream ended before the image; this is the same as too few IDATs so
4522 * should be handled the same way.
4523 */
4524 if (output != NULL((void*)0))
4525 png_error(png_ptr, "Not enough image data");
4526
4527 else /* the deflate stream contained extra data */
4528 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "Too much image data");
4529 }
4530}
4531
4532void /* PRIVATE */
4533png_read_finish_IDAT(png_structrp png_ptr)
4534{
4535 /* We don't need any more data and the stream should have ended, however the
4536 * LZ end code may actually not have been processed. In this case we must
4537 * read it otherwise stray unread IDAT data or, more likely, an IDAT chunk
4538 * may still remain to be consumed.
4539 */
4540 if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED0x0008U) == 0)
4541 {
4542 /* The NULL causes png_read_IDAT_data to swallow any remaining bytes in
4543 * the compressed stream, but the stream may be damaged too, so even after
4544 * this call we may need to terminate the zstream ownership.
4545 */
4546 png_read_IDAT_data(png_ptr, NULL((void*)0), 0);
4547 png_ptr->zstream.next_out = NULL((void*)0); /* safety */
4548
4549 /* Now clear everything out for safety; the following may not have been
4550 * done.
4551 */
4552 if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED0x0008U) == 0)
4553 {
4554 png_ptr->mode |= PNG_AFTER_IDAT0x08;
4555 png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED0x0008U;
4556 }
4557 }
4558
4559 /* If the zstream has not been released do it now *and* terminate the reading
4560 * of the final IDAT chunk.
4561 */
4562 if (png_ptr->zowner == png_IDAT((((0xFFFFFFFFU)&(73)) << (24)) | (((0xFFFFFFFFU)&
(68)) << (16)) | (((0xFFFFFFFFU)&(65)) << (8)
) | (((0xFFFFFFFFU)&(84)) << (0)))
)
4563 {
4564 png_inflate_detach_buffers(png_ptr);
4565 png_ptr->zowner = 0;
4566
4567 /* The slightly weird semantics of the sequential IDAT reading is that we
4568 * are always in or at the end of an IDAT chunk, so we always need to do a
4569 * crc_finish here. If idat_size is non-zero we also need to read the
4570 * spurious bytes at the end of the chunk now.
4571 */
4572 (void)png_crc_finishMOZ_PNG_crc_finish(png_ptr, png_ptr->idat_size);
4573 }
4574}
4575
4576void /* PRIVATE */
4577png_read_finish_rowMOZ_PNG_read_finish_row(png_structrp png_ptr)
4578{
4579 png_debug(1, "in png_read_finish_row")((void)0);
4580 png_ptr->row_number++;
4581 if (png_ptr->row_number < png_ptr->num_rows)
4582 return;
4583
4584 if (png_ptr->interlaced != 0)
4585 {
4586 png_ptr->row_number = 0;
4587
4588 /* TO DO: don't do this if prev_row isn't needed (requires
4589 * read-ahead of the next row's filter byte.
4590 */
4591 memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
4592
4593 do
4594 {
4595 png_ptr->pass++;
4596
4597 if (png_ptr->pass >= 7)
4598 break;
4599
4600 png_ptr->iwidth = (png_ptr->width +
4601 png_pass_inc[png_ptr->pass] - 1 -
4602 png_pass_start[png_ptr->pass]) /
4603 png_pass_inc[png_ptr->pass];
4604
4605 if ((png_ptr->transformations & PNG_INTERLACE0x0002U) == 0)
4606 {
4607 png_ptr->num_rows = (png_ptr->height +
4608 png_pass_yinc[png_ptr->pass] - 1 -
4609 png_pass_ystart[png_ptr->pass]) /
4610 png_pass_yinc[png_ptr->pass];
4611 }
4612
4613 else /* if (png_ptr->transformations & PNG_INTERLACE) */
4614 break; /* libpng deinterlacing sees every row */
4615
4616 } while (png_ptr->num_rows == 0 || png_ptr->iwidth == 0);
4617
4618 if (png_ptr->pass < 7)
4619 return;
4620 }
4621
4622 /* Here after at the end of the last row of the last pass. */
4623 png_read_finish_IDAT(png_ptr);
4624}
4625#endif /* SEQUENTIAL_READ */
4626
4627void /* PRIVATE */
4628png_read_start_rowMOZ_PNG_read_start_row(png_structrp png_ptr)
4629{
4630 unsigned int max_pixel_depth;
4631 size_t row_bytes;
4632
4633 png_debug(1, "in png_read_start_row")((void)0);
4634
4635#ifdef PNG_READ_TRANSFORMS_SUPPORTED
4636 png_init_read_transformationsMOZ_PNG_init_read_transf(png_ptr);
4637#endif
4638 if (png_ptr->interlaced != 0)
4639 {
4640 if ((png_ptr->transformations & PNG_INTERLACE0x0002U) == 0)
4641 png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
4642 png_pass_ystart[0]) / png_pass_yinc[0];
4643
4644 else
4645 png_ptr->num_rows = png_ptr->height;
4646
4647 png_ptr->iwidth = (png_ptr->width +
4648 png_pass_inc[png_ptr->pass] - 1 -
4649 png_pass_start[png_ptr->pass]) /
4650 png_pass_inc[png_ptr->pass];
4651 }
4652
4653 else
4654 {
4655 png_ptr->num_rows = png_ptr->height;
4656 png_ptr->iwidth = png_ptr->width;
4657 }
4658
4659 max_pixel_depth = (unsigned int)png_ptr->pixel_depth;
4660
4661 /* WARNING: * png_read_transform_info (pngrtran.c) performs a simpler set of
4662 * calculations to calculate the final pixel depth, then
4663 * png_do_read_transforms actually does the transforms. This means that the
4664 * code which effectively calculates this value is actually repeated in three
4665 * separate places. They must all match. Innocent changes to the order of
4666 * transformations can and will break libpng in a way that causes memory
4667 * overwrites.
4668 *
4669 * TODO: fix this.
4670 */
4671#ifdef PNG_READ_PACK_SUPPORTED
4672 if ((png_ptr->transformations & PNG_PACK0x0004U) != 0 && png_ptr->bit_depth < 8)
4673 max_pixel_depth = 8;
4674#endif
4675
4676#ifdef PNG_READ_EXPAND_SUPPORTED
4677 if ((png_ptr->transformations & PNG_EXPAND0x1000U) != 0)
4678 {
4679 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE(2 | 1))
4680 {
4681 if (png_ptr->num_trans != 0)
4682 max_pixel_depth = 32;
4683
4684 else
4685 max_pixel_depth = 24;
4686 }
4687
4688 else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY0)
4689 {
4690 if (max_pixel_depth < 8)
4691 max_pixel_depth = 8;
4692
4693 if (png_ptr->num_trans != 0)
4694 max_pixel_depth *= 2;
4695 }
4696
4697 else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB(2))
4698 {
4699 if (png_ptr->num_trans != 0)
4700 {
4701 max_pixel_depth *= 4;
4702 max_pixel_depth /= 3;
4703 }
4704 }
4705 }
4706#endif
4707
4708#ifdef PNG_READ_EXPAND_16_SUPPORTED
4709 if ((png_ptr->transformations & PNG_EXPAND_160x0200U) != 0)
4710 {
4711# ifdef PNG_READ_EXPAND_SUPPORTED
4712 /* In fact it is an error if it isn't supported, but checking is
4713 * the safe way.
4714 */
4715 if ((png_ptr->transformations & PNG_EXPAND0x1000U) != 0)
4716 {
4717 if (png_ptr->bit_depth < 16)
4718 max_pixel_depth *= 2;
4719 }
4720 else
4721# endif
4722 png_ptr->transformations &= ~PNG_EXPAND_160x0200U;
4723 }
4724#endif
4725
4726#ifdef PNG_READ_FILLER_SUPPORTED
4727 if ((png_ptr->transformations & (PNG_FILLER0x8000U)) != 0)
4728 {
4729 if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY0)
4730 {
4731 if (max_pixel_depth <= 8)
4732 max_pixel_depth = 16;
4733
4734 else
4735 max_pixel_depth = 32;
4736 }
4737
4738 else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB(2) ||
4739 png_ptr->color_type == PNG_COLOR_TYPE_PALETTE(2 | 1))
4740 {
4741 if (max_pixel_depth <= 32)
4742 max_pixel_depth = 32;
4743
4744 else
4745 max_pixel_depth = 64;
4746 }
4747 }
4748#endif
4749
4750#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
4751 if ((png_ptr->transformations & PNG_GRAY_TO_RGB0x4000U) != 0)
4752 {
4753 if (
4754#ifdef PNG_READ_EXPAND_SUPPORTED
4755 (png_ptr->num_trans != 0 &&
4756 (png_ptr->transformations & PNG_EXPAND0x1000U) != 0) ||
4757#endif
4758#ifdef PNG_READ_FILLER_SUPPORTED
4759 (png_ptr->transformations & (PNG_FILLER0x8000U)) != 0 ||
4760#endif
4761 png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA(4))
4762 {
4763 if (max_pixel_depth <= 16)
4764 max_pixel_depth = 32;
4765
4766 else
4767 max_pixel_depth = 64;
4768 }
4769
4770 else
4771 {
4772 if (max_pixel_depth <= 8)
4773 {
4774 if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA(2 | 4))
4775 max_pixel_depth = 32;
4776
4777 else
4778 max_pixel_depth = 24;
4779 }
4780
4781 else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA(2 | 4))
4782 max_pixel_depth = 64;
4783
4784 else
4785 max_pixel_depth = 48;
4786 }
4787 }
4788#endif
4789
4790#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
4791defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
4792 if ((png_ptr->transformations & PNG_USER_TRANSFORM0x100000U) != 0)
4793 {
4794 unsigned int user_pixel_depth = png_ptr->user_transform_depth *
4795 png_ptr->user_transform_channels;
4796
4797 if (user_pixel_depth > max_pixel_depth)
4798 max_pixel_depth = user_pixel_depth;
4799 }
4800#endif
4801
4802 /* This value is stored in png_struct and double checked in the row read
4803 * code.
4804 */
4805 png_ptr->maximum_pixel_depth = (png_byte)max_pixel_depth;
4806 png_ptr->transformed_pixel_depth = 0; /* calculated on demand */
4807
4808 /* Align the width on the next larger 8 pixels. Mainly used
4809 * for interlacing
4810 */
4811 row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
4812 /* Calculate the maximum bytes needed, adding a byte and a pixel
4813 * for safety's sake
4814 */
4815 row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes)((max_pixel_depth) >= 8 ? ((size_t)(row_bytes) * (((size_t
)(max_pixel_depth)) >> 3)) : (( ((size_t)(row_bytes) * (
(size_t)(max_pixel_depth))) + 7) >> 3) )
+
4816 1 + ((max_pixel_depth + 7) >> 3U);
4817
4818#ifdef PNG_MAX_MALLOC_64K
4819 if (row_bytes > (png_uint_32)65536L)
4820 png_error(png_ptr, "This image requires a row greater than 64KB");
4821#endif
4822
4823 if (row_bytes + 48 > png_ptr->old_big_row_buf_size)
4824 {
4825 png_freeMOZ_PNG_free(png_ptr, png_ptr->big_row_buf);
4826 png_freeMOZ_PNG_free(png_ptr, png_ptr->big_prev_row);
4827 png_ptr->big_row_buf = png_ptr->big_prev_row = NULL((void*)0);
4828
4829 if (png_ptr->interlaced != 0)
4830 png_ptr->big_row_buf = (png_bytep)png_callocMOZ_PNG_calloc(png_ptr,
4831 row_bytes + 48);
4832
4833 else
4834 png_ptr->big_row_buf = (png_bytep)png_mallocMOZ_PNG_malloc(png_ptr, row_bytes + 48);
4835
4836 png_ptr->big_prev_row = (png_bytep)png_mallocMOZ_PNG_malloc(png_ptr, row_bytes + 48);
4837
4838#ifdef PNG_ALIGNED_MEMORY_SUPPORTED
4839 /* Use 16-byte aligned memory for row_buf with at least 16 bytes
4840 * of padding before and after row_buf; treat prev_row similarly.
4841 * NOTE: the alignment is to the start of the pixels, one beyond the start
4842 * of the buffer, because of the filter byte. Prior to libpng 1.5.6 this
4843 * was incorrect; the filter byte was aligned, which had the exact
4844 * opposite effect of that intended.
4845 */
4846 {
4847 png_bytep temp = png_ptr->big_row_buf + 32;
4848 size_t extra = (size_t)temp & 0x0f;
4849 png_ptr->row_buf = temp - extra - 1/*filter byte*/;
4850
4851 temp = png_ptr->big_prev_row + 32;
4852 extra = (size_t)temp & 0x0f;
4853 png_ptr->prev_row = temp - extra - 1/*filter byte*/;
4854 }
4855#else
4856 /* Use 31 bytes of padding before and 17 bytes after row_buf. */
4857 png_ptr->row_buf = png_ptr->big_row_buf + 31;
4858 png_ptr->prev_row = png_ptr->big_prev_row + 31;
4859#endif
4860 png_ptr->old_big_row_buf_size = row_bytes + 48;
4861 }
4862
4863#ifdef PNG_MAX_MALLOC_64K
4864 if (png_ptr->rowbytes > 65535)
4865 png_error(png_ptr, "This image requires a row greater than 64KB");
4866
4867#endif
4868 if (png_ptr->rowbytes > (PNG_SIZE_MAX((size_t)(-1)) - 1))
4869 png_error(png_ptr, "Row has too many bytes to allocate in memory");
4870
4871 memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
4872
4873 png_debug1(3, "width = %u,", png_ptr->width)((void)0);
4874 png_debug1(3, "height = %u,", png_ptr->height)((void)0);
4875 png_debug1(3, "iwidth = %u,", png_ptr->iwidth)((void)0);
4876 png_debug1(3, "num_rows = %u,", png_ptr->num_rows)((void)0);
4877 png_debug1(3, "rowbytes = %lu,", (unsigned long)png_ptr->rowbytes)((void)0);
4878 png_debug1(3, "irowbytes = %lu",((void)0)
4879 (unsigned long)PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1)((void)0);
4880
4881 /* The sequential reader needs a buffer for IDAT, but the progressive reader
4882 * does not, so free the read buffer now regardless; the sequential reader
4883 * reallocates it on demand.
4884 */
4885 if (png_ptr->read_buffer != NULL((void*)0))
4886 {
4887 png_bytep buffer = png_ptr->read_buffer;
4888
4889 png_ptr->read_buffer_size = 0;
4890 png_ptr->read_buffer = NULL((void*)0);
4891 png_freeMOZ_PNG_free(png_ptr, buffer);
4892 }
4893
4894 /* Finally claim the zstream for the inflate of the IDAT data, use the bits
4895 * value from the stream (note that this will result in a fatal error if the
4896 * IDAT stream has a bogus deflate header window_bits value, but this should
4897 * not be happening any longer!)
4898 */
4899 if (png_inflate_claim(png_ptr, png_IDAT((((0xFFFFFFFFU)&(73)) << (24)) | (((0xFFFFFFFFU)&
(68)) << (16)) | (((0xFFFFFFFFU)&(65)) << (8)
) | (((0xFFFFFFFFU)&(84)) << (0)))
) != Z_OK0)
4900 png_error(png_ptr, png_ptr->zstream.msg);
4901
4902 png_ptr->flags |= PNG_FLAG_ROW_INIT0x0040U;
4903}
4904
4905#ifdef PNG_READ_APNG_SUPPORTED
4906/* This function is to be called after the main IDAT set has been read and
4907 * before a new IDAT is read. It resets some parts of png_ptr
4908 * to make them usable by the read functions again */
4909void /* PRIVATE */
4910png_read_resetMOZ_APNG_read_reset(png_structp png_ptr)
4911{
4912 png_ptr->mode &= ~PNG_HAVE_IDAT0x04U;
4913 png_ptr->mode &= ~PNG_AFTER_IDAT0x08;
4914 png_ptr->row_number = 0;
4915 png_ptr->pass = 0;
4916}
4917
4918void /* PRIVATE */
4919png_read_reinitMOZ_APNG_read_reinit(png_structp png_ptr, png_infop info_ptr)
4920{
4921 png_ptr->width = info_ptr->next_frame_width;
4922 png_ptr->height = info_ptr->next_frame_height;
4923 png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width)((png_ptr->pixel_depth) >= 8 ? ((size_t)(png_ptr->width
) * (((size_t)(png_ptr->pixel_depth)) >> 3)) : (( ((
size_t)(png_ptr->width) * ((size_t)(png_ptr->pixel_depth
))) + 7) >> 3) )
;
4924 png_ptr->info_rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,((info_ptr->pixel_depth) >= 8 ? ((size_t)(png_ptr->width
) * (((size_t)(info_ptr->pixel_depth)) >> 3)) : (( (
(size_t)(png_ptr->width) * ((size_t)(info_ptr->pixel_depth
))) + 7) >> 3) )
4925 png_ptr->width)((info_ptr->pixel_depth) >= 8 ? ((size_t)(png_ptr->width
) * (((size_t)(info_ptr->pixel_depth)) >> 3)) : (( (
(size_t)(png_ptr->width) * ((size_t)(info_ptr->pixel_depth
))) + 7) >> 3) )
;
4926 if (png_ptr->prev_row != NULL((void*)0))
4927 memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
4928}
4929
4930#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
4931/* same as png_read_reset() but for the progressive reader */
4932void /* PRIVATE */
4933png_progressive_read_resetMOZ_APNG_prog_read_reset(png_structp png_ptr)
4934{
4935#ifdef PNG_READ_INTERLACING_SUPPORTED
4936 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
4937
4938 /* Start of interlace block */
4939 static PNG_CONSTconst png_byte png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
4940
4941 /* Offset to next interlace block */
4942 static PNG_CONSTconst png_byte png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
4943
4944 /* Start of interlace block in the y direction */
4945 static PNG_CONSTconst png_byte png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
4946
4947 /* Offset to next interlace block in the y direction */
4948 static PNG_CONSTconst png_byte png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
4949
4950 if (png_ptr->interlaced != 0)
4951 {
4952 if ((png_ptr->transformations & PNG_INTERLACE0x0002U) == 0)
4953 png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
4954 png_pass_ystart[0]) / png_pass_yinc[0];
4955 else
4956 png_ptr->num_rows = png_ptr->height;
4957
4958 png_ptr->iwidth = (png_ptr->width +
4959 png_pass_inc[png_ptr->pass] - 1 -
4960 png_pass_start[png_ptr->pass]) /
4961 png_pass_inc[png_ptr->pass];
4962 }
4963 else
4964#endif /* READ_INTERLACING */
4965 {
4966 png_ptr->num_rows = png_ptr->height;
4967 png_ptr->iwidth = png_ptr->width;
4968 }
4969 png_ptr->flags &= ~PNG_FLAG_ZSTREAM_ENDED0x0008U;
4970 if (inflateResetMOZ_Z_inflateReset(&(png_ptr->zstream)) != Z_OK0)
4971 png_error(png_ptr, "inflateReset failed");
4972 png_ptr->zstream.avail_in = 0;
4973 png_ptr->zstream.next_in = 0;
4974 png_ptr->zstream.next_out = png_ptr->row_buf;
4975 png_ptr->zstream.avail_out = (uInt)PNG_ROWBYTES(png_ptr->pixel_depth,((png_ptr->pixel_depth) >= 8 ? ((size_t)(png_ptr->iwidth
) * (((size_t)(png_ptr->pixel_depth)) >> 3)) : (( ((
size_t)(png_ptr->iwidth) * ((size_t)(png_ptr->pixel_depth
))) + 7) >> 3) )
4976 png_ptr->iwidth)((png_ptr->pixel_depth) >= 8 ? ((size_t)(png_ptr->iwidth
) * (((size_t)(png_ptr->pixel_depth)) >> 3)) : (( ((
size_t)(png_ptr->iwidth) * ((size_t)(png_ptr->pixel_depth
))) + 7) >> 3) )
+ 1;
4977}
4978#endif /* PROGRESSIVE_READ */
4979#endif /* READ_APNG */
4980#endif /* READ */