Bug Summary

File:root/firefox-clang/media/libpng/pngrutil.c
Warning:line 1303, 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-09-01-224014-2642839-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/* png_inflate_claim: claim the zstream for some nefarious purpose that involves
409 * decompression. Returns Z_OK on success, else a zlib error code. It checks
410 * the owner but, in final release builds, just issues a warning if some other
411 * chunk apparently owns the stream. Prior to release it does a png_error.
412 */
413static int
414png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
415{
416 if (png_ptr->zowner != 0)
417 {
418 char msg[64];
419
420 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)))
;
421 /* So the message that results is "<chunk> using zstream"; this is an
422 * internal error, but is very useful for debugging. i18n requirements
423 * are minimal.
424 */
425 (void)png_safecatMOZ_PNG_safecat(msg, (sizeof msg), 4, " using zstream");
426#if PNG_RELEASE_BUILD(4 >= 3)
427 png_chunk_warningMOZ_PNG_chunk_warn(png_ptr, msg);
428 png_ptr->zowner = 0;
429#else
430 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, msg);
431#endif
432 }
433
434 /* Implementation note: unlike 'png_deflate_claim' this internal function
435 * does not take the size of the data as an argument. Some efficiency could
436 * be gained by using this when it is known *if* the zlib stream itself does
437 * not record the number; however, this is an illusion: the original writer
438 * of the PNG may have selected a lower window size, and we really must
439 * follow that because, for systems with limited capabilities, we
440 * would otherwise reject the application's attempts to use a smaller window
441 * size (zlib doesn't have an interface to say "this or lower"!).
442 *
443 * inflateReset2 was added to zlib 1.2.4; before this the window could not be
444 * reset, therefore it is necessary to always allocate the maximum window
445 * size with earlier zlibs just in case later compressed chunks need it.
446 */
447 {
448 int ret; /* zlib return code */
449#if ZLIB_VERNUM0x1320 >= 0x1240
450 int window_bits = 0;
451
452# if defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_MAXIMUM_INFLATE_WINDOW2)
453 if (((png_ptr->options >> PNG_MAXIMUM_INFLATE_WINDOW2) & 3) ==
454 PNG_OPTION_ON3)
455 {
456 window_bits = 15;
457 png_ptr->zstream_start = 0; /* fixed window size */
458 }
459
460 else
461 {
462 png_ptr->zstream_start = 1;
463 }
464# endif
465
466#endif /* ZLIB_VERNUM >= 0x1240 */
467
468 /* Set this for safety, just in case the previous owner left pointers to
469 * memory allocations.
470 */
471 png_ptr->zstream.next_in = NULL((void*)0);
472 png_ptr->zstream.avail_in = 0;
473 png_ptr->zstream.next_out = NULL((void*)0);
474 png_ptr->zstream.avail_out = 0;
475
476 if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED0x0002U) != 0)
477 {
478#if ZLIB_VERNUM0x1320 >= 0x1240
479 ret = inflateReset2MOZ_Z_inflateReset2(&png_ptr->zstream, window_bits);
480#else
481 ret = inflateResetMOZ_Z_inflateReset(&png_ptr->zstream);
482#endif
483 }
484
485 else
486 {
487#if ZLIB_VERNUM0x1320 >= 0x1240
488 ret = inflateInit2(&png_ptr->zstream, window_bits)MOZ_Z_inflateInit2_((&png_ptr->zstream), (window_bits)
, "1.3.2", (int)sizeof(z_stream))
;
489#else
490 ret = inflateInit(&png_ptr->zstream)MOZ_Z_inflateInit_((&png_ptr->zstream), "1.3.2", (int)
sizeof(z_stream))
;
491#endif
492
493 if (ret == Z_OK0)
494 png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED0x0002U;
495 }
496
497#ifdef PNG_DISABLE_ADLER32_CHECK_SUPPORTED
498 if (((png_ptr->options >> PNG_IGNORE_ADLER32) & 3) == PNG_OPTION_ON3)
499 /* Turn off validation of the ADLER32 checksum in IDAT chunks */
500 ret = inflateValidateMOZ_Z_inflateValidate(&png_ptr->zstream, 0);
501#endif
502
503 if (ret == Z_OK0)
504 png_ptr->zowner = owner;
505
506 else
507 png_zstream_errorMOZ_PNG_zstream_error(png_ptr, ret);
508
509 return ret;
510 }
511
512#ifdef window_bits
513# undef window_bits
514#endif
515}
516
517#if ZLIB_VERNUM0x1320 >= 0x1240
518/* Handle the start of the inflate stream if we called inflateInit2(strm,0);
519 * in this case some zlib versions skip validation of the CINFO field and, in
520 * certain circumstances, libpng may end up displaying an invalid image, in
521 * contrast to implementations that call zlib in the normal way (e.g. libpng
522 * 1.5).
523 */
524int /* PRIVATE */
525png_zlib_inflate(png_structrp png_ptr, int flush)
526{
527 if (png_ptr->zstream_start && png_ptr->zstream.avail_in > 0)
528 {
529 if ((*png_ptr->zstream.next_in >> 4) > 7)
530 {
531 png_ptr->zstream.msg = "invalid window size (libpng)";
532 return Z_DATA_ERROR(-3);
533 }
534
535 png_ptr->zstream_start = 0;
536 }
537
538 return inflateMOZ_Z_inflate(&png_ptr->zstream, flush);
539}
540#endif /* Zlib >= 1.2.4 */
541
542#ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED
543#if defined(PNG_READ_zTXt_SUPPORTED) || defined (PNG_READ_iTXt_SUPPORTED)
544/* png_inflate now returns zlib error codes including Z_OK and Z_STREAM_END to
545 * allow the caller to do multiple calls if required. If the 'finish' flag is
546 * set Z_FINISH will be passed to the final inflate() call and Z_STREAM_END must
547 * be returned or there has been a problem, otherwise Z_SYNC_FLUSH is used and
548 * Z_OK or Z_STREAM_END will be returned on success.
549 *
550 * The input and output sizes are updated to the actual amounts of data consumed
551 * or written, not the amount available (as in a z_stream). The data pointers
552 * are not changed, so the next input is (data+input_size) and the next
553 * available output is (output+output_size).
554 */
555static int
556png_inflateMOZ_PNG_inflate(png_structrp png_ptr, png_uint_32 owner, int finish,
557 /* INPUT: */ png_const_bytep input, png_uint_32p input_size_ptr,
558 /* OUTPUT: */ png_bytep output, png_alloc_size_t *output_size_ptr)
559{
560 if (png_ptr->zowner == owner) /* Else not claimed */
561 {
562 int ret;
563 png_alloc_size_t avail_out = *output_size_ptr;
564 png_uint_32 avail_in = *input_size_ptr;
565
566 /* zlib can't necessarily handle more than 65535 bytes at once (i.e. it
567 * can't even necessarily handle 65536 bytes) because the type uInt is
568 * "16 bits or more". Consequently it is necessary to chunk the input to
569 * zlib. This code uses ZLIB_IO_MAX, from pngpriv.h, as the maximum (the
570 * maximum value that can be stored in a uInt.) It is possible to set
571 * ZLIB_IO_MAX to a lower value in pngpriv.h and this may sometimes have
572 * a performance advantage, because it reduces the amount of data accessed
573 * at each step and that may give the OS more time to page it in.
574 */
575 png_ptr->zstream.next_in = PNGZ_INPUT_CAST(input)(input);
576 /* avail_in and avail_out are set below from 'size' */
577 png_ptr->zstream.avail_in = 0;
578 png_ptr->zstream.avail_out = 0;
579
580 /* Read directly into the output if it is available (this is set to
581 * a local buffer below if output is NULL).
582 */
583 if (output != NULL((void*)0))
584 png_ptr->zstream.next_out = output;
585
586 do
587 {
588 uInt avail;
589 Byte local_buffer[PNG_INFLATE_BUF_SIZE1024];
590
591 /* zlib INPUT BUFFER */
592 /* The setting of 'avail_in' used to be outside the loop; by setting it
593 * inside it is possible to chunk the input to zlib and simply rely on
594 * zlib to advance the 'next_in' pointer. This allows arbitrary
595 * amounts of data to be passed through zlib at the unavoidable cost of
596 * requiring a window save (memcpy of up to 32768 output bytes)
597 * every ZLIB_IO_MAX input bytes.
598 */
599 avail_in += png_ptr->zstream.avail_in; /* not consumed last time */
600
601 avail = ZLIB_IO_MAX((uInt)-1);
602
603 if (avail_in < avail)
604 avail = (uInt)avail_in; /* safe: < than ZLIB_IO_MAX */
605
606 avail_in -= avail;
607 png_ptr->zstream.avail_in = avail;
608
609 /* zlib OUTPUT BUFFER */
610 avail_out += png_ptr->zstream.avail_out; /* not written last time */
611
612 avail = ZLIB_IO_MAX((uInt)-1); /* maximum zlib can process */
613
614 if (output == NULL((void*)0))
615 {
616 /* Reset the output buffer each time round if output is NULL and
617 * make available the full buffer, up to 'remaining_space'
618 */
619 png_ptr->zstream.next_out = local_buffer;
620 if ((sizeof local_buffer) < avail)
621 avail = (sizeof local_buffer);
622 }
623
624 if (avail_out < avail)
625 avail = (uInt)avail_out; /* safe: < ZLIB_IO_MAX */
626
627 png_ptr->zstream.avail_out = avail;
628 avail_out -= avail;
629
630 /* zlib inflate call */
631 /* In fact 'avail_out' may be 0 at this point, that happens at the end
632 * of the read when the final LZ end code was not passed at the end of
633 * the previous chunk of input data. Tell zlib if we have reached the
634 * end of the output buffer.
635 */
636 ret = PNG_INFLATE(png_ptr, avail_out > 0 ? Z_NO_FLUSH :png_zlib_inflate(png_ptr, avail_out > 0 ? 0 : (finish ? 4 :
2))
637 (finish ? Z_FINISH : Z_SYNC_FLUSH))png_zlib_inflate(png_ptr, avail_out > 0 ? 0 : (finish ? 4 :
2))
;
638 } while (ret == Z_OK0);
639
640 /* For safety kill the local buffer pointer now */
641 if (output == NULL((void*)0))
642 png_ptr->zstream.next_out = NULL((void*)0);
643
644 /* Claw back the 'size' and 'remaining_space' byte counts. */
645 avail_in += png_ptr->zstream.avail_in;
646 avail_out += png_ptr->zstream.avail_out;
647
648 /* Update the input and output sizes; the updated values are the amount
649 * consumed or written, effectively the inverse of what zlib uses.
650 */
651 if (avail_out > 0)
652 *output_size_ptr -= avail_out;
653
654 if (avail_in > 0)
655 *input_size_ptr -= avail_in;
656
657 /* Ensure png_ptr->zstream.msg is set (even in the success case!) */
658 png_zstream_errorMOZ_PNG_zstream_error(png_ptr, ret);
659 return ret;
660 }
661
662 else
663 {
664 /* This is a bad internal error. The recovery assigns to the zstream msg
665 * pointer, which is not owned by the caller, but this is safe; it's only
666 * used on errors!
667 */
668 png_ptr->zstream.msg = PNGZ_MSG_CAST("zstream unclaimed")("zstream unclaimed");
669 return Z_STREAM_ERROR(-2);
670 }
671}
672
673/*
674 * Decompress trailing data in a chunk. The assumption is that read_buffer
675 * points at an allocated area holding the contents of a chunk with a
676 * trailing compressed part. What we get back is an allocated area
677 * holding the original prefix part and an uncompressed version of the
678 * trailing part (the malloc area passed in is freed).
679 */
680static int
681png_decompress_chunkMOZ_PNG_decomp_chunk(png_structrp png_ptr,
682 png_uint_32 chunklength, png_uint_32 prefix_size,
683 png_alloc_size_t *newlength /* must be initialized to the maximum! */,
684 int terminate /*add a '\0' to the end of the uncompressed data*/)
685{
686 /* TODO: implement different limits for different types of chunk.
687 *
688 * The caller supplies *newlength set to the maximum length of the
689 * uncompressed data, but this routine allocates space for the prefix and
690 * maybe a '\0' terminator too. We have to assume that 'prefix_size' is
691 * limited only by the maximum chunk size.
692 */
693 png_alloc_size_t limit = png_chunk_max(png_ptr)((png_ptr)->user_chunk_malloc_max);
694
695 if (limit >= prefix_size + (terminate != 0))
696 {
697 int ret;
698
699 limit -= prefix_size + (terminate != 0);
700
701 if (limit < *newlength)
702 *newlength = limit;
703
704 /* Now try to claim the stream. */
705 ret = png_inflate_claim(png_ptr, png_ptr->chunk_name);
706
707 if (ret == Z_OK0)
708 {
709 png_uint_32 lzsize = chunklength - prefix_size;
710
711 ret = png_inflateMOZ_PNG_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,
712 /* input: */ png_ptr->read_buffer + prefix_size, &lzsize,
713 /* output: */ NULL((void*)0), newlength);
714
715 if (ret == Z_STREAM_END1)
716 {
717 /* Use 'inflateReset' here, not 'inflateReset2' because this
718 * preserves the previously decided window size (otherwise it would
719 * be necessary to store the previous window size.) In practice
720 * this doesn't matter anyway, because png_inflate will call inflate
721 * with Z_FINISH in almost all cases, so the window will not be
722 * maintained.
723 */
724 if (inflateResetMOZ_Z_inflateReset(&png_ptr->zstream) == Z_OK0)
725 {
726 /* Because of the limit checks above we know that the new,
727 * expanded, size will fit in a size_t (let alone an
728 * png_alloc_size_t). Use png_malloc_base here to avoid an
729 * extra OOM message.
730 */
731 png_alloc_size_t new_size = *newlength;
732 png_alloc_size_t buffer_size = prefix_size + new_size +
733 (terminate != 0);
734 png_bytep text = png_voidcast(png_bytep, png_malloc_base(png_ptr,(MOZ_PNG_malloc_base(png_ptr, buffer_size))
735 buffer_size))(MOZ_PNG_malloc_base(png_ptr, buffer_size));
736
737 if (text != NULL((void*)0))
738 {
739 memset(text, 0, buffer_size);
740
741 ret = png_inflateMOZ_PNG_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,
742 png_ptr->read_buffer + prefix_size, &lzsize,
743 text + prefix_size, newlength);
744
745 if (ret == Z_STREAM_END1)
746 {
747 if (new_size == *newlength)
748 {
749 if (terminate != 0)
750 text[prefix_size + *newlength] = 0;
751
752 if (prefix_size > 0)
753 memcpy(text, png_ptr->read_buffer, prefix_size);
754
755 {
756 png_bytep old_ptr = png_ptr->read_buffer;
757
758 png_ptr->read_buffer = text;
759 png_ptr->read_buffer_size = buffer_size;
760 text = old_ptr; /* freed below */
761 }
762 }
763
764 else
765 {
766 /* The size changed on the second read, there can be no
767 * guarantee that anything is correct at this point.
768 * The 'msg' pointer has been set to "unexpected end of
769 * LZ stream", which is fine, but return an error code
770 * that the caller won't accept.
771 */
772 ret = PNG_UNEXPECTED_ZLIB_RETURN(-7);
773 }
774 }
775
776 else if (ret == Z_OK0)
777 ret = PNG_UNEXPECTED_ZLIB_RETURN(-7); /* for safety */
778
779 /* Free the text pointer (this is the old read_buffer on
780 * success)
781 */
782 png_freeMOZ_PNG_free(png_ptr, text);
783
784 /* This really is very benign, but it's still an error because
785 * the extra space may otherwise be used as a Trojan Horse.
786 */
787 if (ret == Z_STREAM_END1 &&
788 chunklength - prefix_size != lzsize)
789 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "extra compressed data");
790 }
791
792 else
793 {
794 /* Out of memory allocating the buffer */
795 ret = Z_MEM_ERROR(-4);
796 png_zstream_errorMOZ_PNG_zstream_error(png_ptr, Z_MEM_ERROR(-4));
797 }
798 }
799
800 else
801 {
802 /* inflateReset failed, store the error message */
803 png_zstream_errorMOZ_PNG_zstream_error(png_ptr, ret);
804 ret = PNG_UNEXPECTED_ZLIB_RETURN(-7);
805 }
806 }
807
808 else if (ret == Z_OK0)
809 ret = PNG_UNEXPECTED_ZLIB_RETURN(-7);
810
811 /* Release the claimed stream */
812 png_ptr->zowner = 0;
813 }
814
815 else /* the claim failed */ if (ret == Z_STREAM_END1) /* impossible! */
816 ret = PNG_UNEXPECTED_ZLIB_RETURN(-7);
817
818 return ret;
819 }
820
821 else
822 {
823 /* Application/configuration limits exceeded */
824 png_zstream_errorMOZ_PNG_zstream_error(png_ptr, Z_MEM_ERROR(-4));
825 return Z_MEM_ERROR(-4);
826 }
827}
828#endif /* READ_zTXt || READ_iTXt */
829#endif /* READ_COMPRESSED_TEXT */
830
831#ifdef PNG_READ_iCCP_SUPPORTED
832/* Perform a partial read and decompress, producing 'avail_out' bytes and
833 * reading from the current chunk as required.
834 */
835static int
836png_inflate_read(png_structrp png_ptr, png_bytep read_buffer, uInt read_size,
837 png_uint_32p chunk_bytes, png_bytep next_out, png_alloc_size_t *out_size,
838 int finish)
839{
840 if (png_ptr->zowner == png_ptr->chunk_name)
841 {
842 int ret;
843
844 /* next_in and avail_in must have been initialized by the caller. */
845 png_ptr->zstream.next_out = next_out;
846 png_ptr->zstream.avail_out = 0; /* set in the loop */
847
848 do
849 {
850 if (png_ptr->zstream.avail_in == 0)
851 {
852 if (read_size > *chunk_bytes)
853 read_size = (uInt)*chunk_bytes;
854 *chunk_bytes -= read_size;
855
856 if (read_size > 0)
857 png_crc_readMOZ_PNG_crc_read(png_ptr, read_buffer, read_size);
858
859 png_ptr->zstream.next_in = read_buffer;
860 png_ptr->zstream.avail_in = read_size;
861 }
862
863 if (png_ptr->zstream.avail_out == 0)
864 {
865 uInt avail = ZLIB_IO_MAX((uInt)-1);
866 if (avail > *out_size)
867 avail = (uInt)*out_size;
868 *out_size -= avail;
869
870 png_ptr->zstream.avail_out = avail;
871 }
872
873 /* Use Z_SYNC_FLUSH when there is no more chunk data to ensure that all
874 * the available output is produced; this allows reading of truncated
875 * streams.
876 */
877 ret = PNG_INFLATE(png_ptr, *chunk_bytes > 0 ?png_zlib_inflate(png_ptr, *chunk_bytes > 0 ? 0 : (finish ?
4 : 2))
878 Z_NO_FLUSH : (finish ? Z_FINISH : Z_SYNC_FLUSH))png_zlib_inflate(png_ptr, *chunk_bytes > 0 ? 0 : (finish ?
4 : 2))
;
879 }
880 while (ret == Z_OK0 && (*out_size > 0 || png_ptr->zstream.avail_out > 0));
881
882 *out_size += png_ptr->zstream.avail_out;
883 png_ptr->zstream.avail_out = 0; /* Should not be required, but is safe */
884
885 /* Ensure the error message pointer is always set: */
886 png_zstream_errorMOZ_PNG_zstream_error(png_ptr, ret);
887 return ret;
888 }
889
890 else
891 {
892 png_ptr->zstream.msg = PNGZ_MSG_CAST("zstream unclaimed")("zstream unclaimed");
893 return Z_STREAM_ERROR(-2);
894 }
895}
896#endif /* READ_iCCP */
897
898/* CHUNK HANDLING */
899/* Read and check the IDHR chunk */
900static png_handle_result_code
901png_handle_IHDRMOZ_PNG_handle_IHDR(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
902{
903 png_byte buf[13];
904 png_uint_32 width, height;
905 int bit_depth, color_type, compression_type, filter_type;
906 int interlace_type;
907
908 png_debug(1, "in png_handle_IHDR")((void)0);
909
910 /* Length and position are checked by the caller. */
911
912 png_ptr->mode |= PNG_HAVE_IHDR0x01;
913
914 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 13);
915 png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0);
916
917 width = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, buf);
918 height = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, buf + 4);
919 bit_depth = buf[8];
920 color_type = buf[9];
921 compression_type = buf[10];
922 filter_type = buf[11];
923 interlace_type = buf[12];
924
925#ifdef PNG_READ_APNG_SUPPORTED
926 png_ptr->first_frame_width = width;
927 png_ptr->first_frame_height = height;
928#endif
929
930 /* Set internal variables */
931 png_ptr->width = width;
932 png_ptr->height = height;
933 png_ptr->bit_depth = (png_byte)bit_depth;
934 png_ptr->interlaced = (png_byte)interlace_type;
935 png_ptr->color_type = (png_byte)color_type;
936#ifdef PNG_MNG_FEATURES_SUPPORTED
937 png_ptr->filter_type = (png_byte)filter_type;
938#endif
939 png_ptr->compression_type = (png_byte)compression_type;
940
941 /* Find number of channels */
942 switch (png_ptr->color_type)
943 {
944 default: /* invalid, png_set_IHDR calls png_error */
945 case PNG_COLOR_TYPE_GRAY0:
946 case PNG_COLOR_TYPE_PALETTE(2 | 1):
947 png_ptr->channels = 1;
948 break;
949
950 case PNG_COLOR_TYPE_RGB(2):
951 png_ptr->channels = 3;
952 break;
953
954 case PNG_COLOR_TYPE_GRAY_ALPHA(4):
955 png_ptr->channels = 2;
956 break;
957
958 case PNG_COLOR_TYPE_RGB_ALPHA(2 | 4):
959 png_ptr->channels = 4;
960 break;
961 }
962
963 /* Set up other useful info */
964 png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth * png_ptr->channels);
965 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) )
;
966 png_debug1(3, "bit_depth = %d", png_ptr->bit_depth)((void)0);
967 png_debug1(3, "channels = %d", png_ptr->channels)((void)0);
968 png_debug1(3, "rowbytes = %lu", (unsigned long)png_ptr->rowbytes)((void)0);
969
970 /* Rely on png_set_IHDR to completely validate the data and call png_error if
971 * it's wrong.
972 */
973 png_set_IHDRMOZ_PNG_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
974 color_type, interlace_type, compression_type, filter_type);
975
976 return handled_ok;
977 PNG_UNUSED(length)(void)length;
978}
979
980/* Read and check the palette */
981/* TODO: there are several obvious errors in this code when handling
982 * out-of-place chunks and there is much over-complexity caused by trying to
983 * patch up the problems.
984 */
985static png_handle_result_code
986png_handle_PLTEMOZ_PNG_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
987{
988 png_const_charp errmsg = NULL((void*)0);
989
990 png_debug(1, "in png_handle_PLTE")((void)0);
991
992 /* 1.6.47: consistency. This used to be especially treated as a critical
993 * error even in an image which is not colour mapped, there isn't a good
994 * justification for treating some errors here one way and others another so
995 * everything uses the same logic.
996 */
997 if ((png_ptr->mode & PNG_HAVE_PLTE0x02) != 0)
998 errmsg = "duplicate";
999
1000 else if ((png_ptr->mode & PNG_HAVE_IDAT0x04U) != 0)
1001 errmsg = "out of place";
1002
1003 else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR2) == 0)
1004 errmsg = "ignored in grayscale PNG";
1005
1006 else if (length > 3*PNG_MAX_PALETTE_LENGTH256 || (length % 3) != 0)
1007 errmsg = "invalid";
1008
1009 /* This drops PLTE in favour of tRNS or bKGD because both of those chunks
1010 * can have an effect on the rendering of the image whereas PLTE only matters
1011 * in the case of an 8-bit display with a decoder which controls the palette.
1012 *
1013 * The alternative here is to ignore the error and store the palette anyway;
1014 * destroying the tRNS will definitely cause problems.
1015 *
1016 * NOTE: the case of PNG_COLOR_TYPE_PALETTE need not be considered because
1017 * the png_handle_ routines for the three 'after PLTE' chunks tRNS, bKGD and
1018 * hIST all check for a preceding PLTE in these cases.
1019 */
1020 else if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE(2 | 1) &&
1021 (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)
))
1022 errmsg = "out of place";
1023
1024 else
1025 {
1026 /* If the palette has 256 or fewer entries but is too large for the bit
1027 * depth we don't issue an error to preserve the behavior of previous
1028 * libpng versions. We silently truncate the unused extra palette entries
1029 * here.
1030 */
1031 const unsigned max_palette_length =
1032 (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE(2 | 1)) ?
1033 1U << png_ptr->bit_depth : PNG_MAX_PALETTE_LENGTH256;
1034
1035 /* The cast is safe because 'length' is less than
1036 * 3*PNG_MAX_PALETTE_LENGTH
1037 */
1038 const unsigned num = (length > 3U*max_palette_length) ?
1039 max_palette_length : (unsigned)length / 3U;
1040
1041 unsigned i, j;
1042 png_byte buf[3*PNG_MAX_PALETTE_LENGTH256];
1043 png_color palette[PNG_MAX_PALETTE_LENGTH256];
1044
1045 /* Read the chunk into the buffer then read to the end of the chunk. */
1046 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, num*3U);
1047 png_crc_finish_critical(png_ptr, length - 3U*num,
1048 /* Handle as ancillary if PLTE is optional: */
1049 png_ptr->color_type != PNG_COLOR_TYPE_PALETTE(2 | 1));
1050
1051 for (i = 0U, j = 0U; i < num; i++)
1052 {
1053 palette[i].red = buf[j++];
1054 palette[i].green = buf[j++];
1055 palette[i].blue = buf[j++];
1056 }
1057
1058 /* A valid PLTE chunk has been read */
1059 png_ptr->mode |= PNG_HAVE_PLTE0x02;
1060
1061 png_set_PLTEMOZ_PNG_set_PLTE(png_ptr, info_ptr, palette, num);
1062 return handled_ok;
1063 }
1064
1065 /* Here on error: errmsg is non NULL. */
1066 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE(2 | 1))
1067 {
1068 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1069 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, errmsg);
1070 }
1071
1072 else /* not critical to this image */
1073 {
1074 png_crc_finish_critical(png_ptr, length, 1/*handle as ancillary*/);
1075 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, errmsg);
1076 }
1077
1078 /* Because PNG_UNUSED(errmsg) does not work if all the uses are compiled out
1079 * (this does happen).
1080 */
1081 return errmsg != NULL((void*)0) ? handled_error : handled_error;
1082}
1083
1084/* On read the IDAT chunk is always handled specially, even if marked for
1085 * unknown handling (this is allowed), so:
1086 */
1087#define png_handle_IDAT((void*)0) NULL((void*)0)
1088
1089static png_handle_result_code
1090png_handle_IENDMOZ_PNG_handle_IEND(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1091{
1092 png_debug(1, "in png_handle_IEND")((void)0);
1093
1094 png_ptr->mode |= (PNG_AFTER_IDAT0x08 | PNG_HAVE_IEND0x10U);
1095
1096 if (length != 0)
1097 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
1098
1099 png_crc_finish_critical(png_ptr, length, 1/*handle as ancillary*/);
1100
1101 return handled_ok;
1102 PNG_UNUSED(info_ptr)(void)info_ptr;
1103}
1104
1105#ifdef PNG_READ_gAMA_SUPPORTED
1106static png_handle_result_code
1107png_handle_gAMAMOZ_PNG_handle_gAMA(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1108{
1109 png_uint_32 ugamma;
1110 png_byte buf[4];
1111
1112 png_debug(1, "in png_handle_gAMA")((void)0);
1113
1114 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 4);
1115
1116 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
1117 return handled_error;
1118
1119 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))))
;
1120
1121 if (ugamma > PNG_UINT_31_MAX((png_uint_32)0x7fffffffL))
1122 {
1123 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
1124 return handled_error;
1125 }
1126
1127 png_set_gAMA_fixedMOZ_PNG_set_gAMA_fixed(png_ptr, info_ptr, (png_fixed_point)/*SAFE*/ugamma);
1128
1129#ifdef PNG_READ_GAMMA_SUPPORTED
1130 /* PNGv3: chunk precedence for gamma is cICP, [iCCP], sRGB, gAMA. gAMA is
1131 * at the end of the chain so simply check for an unset value.
1132 */
1133 if (png_ptr->chunk_gamma == 0)
1134 png_ptr->chunk_gamma = (png_fixed_point)/*SAFE*/ugamma;
1135#endif /*READ_GAMMA*/
1136
1137 return handled_ok;
1138 PNG_UNUSED(length)(void)length;
1139}
1140#else
1141# define png_handle_gAMAMOZ_PNG_handle_gAMA NULL((void*)0)
1142#endif
1143
1144#ifdef PNG_READ_sBIT_SUPPORTED
1145static png_handle_result_code /* PRIVATE */
1146png_handle_sBIT((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1147{
1148 unsigned int truelen, i;
1149 png_byte sample_depth;
1150 png_byte buf[4];
1151
1152 png_debug(1, "in png_handle_sBIT")((void)0);
1153
1154 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE(2 | 1))
1155 {
1156 truelen = 3;
1157 sample_depth = 8;
1158 }
1159
1160 else
1161 {
1162 truelen = png_ptr->channels;
1163 sample_depth = png_ptr->bit_depth;
1164 }
1165
1166 if (length != truelen)
1167 {
1168 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1169 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "bad length");
1170 return handled_error;
1171 }
1172
1173 buf[0] = buf[1] = buf[2] = buf[3] = sample_depth;
1174 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, truelen);
1175
1176 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
1177 return handled_error;
1178
1179 for (i=0; i<truelen; ++i)
1180 {
1181 if (buf[i] == 0 || buf[i] > sample_depth)
1182 {
1183 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
1184 return handled_error;
1185 }
1186 }
1187
1188 if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR2) != 0)
1189 {
1190 png_ptr->sig_bit.red = buf[0];
1191 png_ptr->sig_bit.green = buf[1];
1192 png_ptr->sig_bit.blue = buf[2];
1193 png_ptr->sig_bit.alpha = buf[3];
1194 }
1195
1196 else /* grayscale */
1197 {
1198 png_ptr->sig_bit.gray = buf[0];
1199 png_ptr->sig_bit.red = buf[0];
1200 png_ptr->sig_bit.green = buf[0];
1201 png_ptr->sig_bit.blue = buf[0];
1202 png_ptr->sig_bit.alpha = buf[1];
1203 }
1204
1205 png_set_sBITMOZ_PNG_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
1206 return handled_ok;
1207}
1208#else
1209# define png_handle_sBIT((void*)0) NULL((void*)0)
1210#endif
1211
1212#ifdef PNG_READ_cHRM_SUPPORTED
1213static png_int_32
1214png_get_int_32_checked(png_const_bytep buf, int *error)
1215{
1216 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))))
;
1217 if ((uval & 0x80000000) == 0) /* non-negative */
1218 return (png_int_32)uval;
1219
1220 uval = (uval ^ 0xffffffff) + 1; /* 2's complement: -x = ~x+1 */
1221 if ((uval & 0x80000000) == 0) /* no overflow */
1222 return -(png_int_32)uval;
1223
1224 /* This version of png_get_int_32 has a way of returning the error to the
1225 * caller, so:
1226 */
1227 *error = 1;
1228 return 0; /* Safe */
1229}
1230
1231static png_handle_result_code /* PRIVATE */
1232png_handle_cHRMMOZ_PNG_handle_cHRM(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1233{
1234 int error = 0;
1235 png_xy xy;
1236 png_byte buf[32];
1237
1238 png_debug(1, "in png_handle_cHRM")((void)0);
1239
1240 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 32);
1241
1242 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
1243 return handled_error;
1244
1245 xy.whitex = png_get_int_32_checked(buf + 0, &error);
1246 xy.whitey = png_get_int_32_checked(buf + 4, &error);
1247 xy.redx = png_get_int_32_checked(buf + 8, &error);
1248 xy.redy = png_get_int_32_checked(buf + 12, &error);
1249 xy.greenx = png_get_int_32_checked(buf + 16, &error);
1250 xy.greeny = png_get_int_32_checked(buf + 20, &error);
1251 xy.bluex = png_get_int_32_checked(buf + 24, &error);
1252 xy.bluey = png_get_int_32_checked(buf + 28, &error);
1253
1254 if (error)
1255 {
1256 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
1257 return handled_error;
1258 }
1259
1260 /* png_set_cHRM may complain about some of the values but this doesn't matter
1261 * because it was a cHRM and it did have vaguely (if, perhaps, ridiculous)
1262 * values. Ridiculosity will be checked if the values are used later.
1263 */
1264 png_set_cHRM_fixedMOZ_PNG_set_cHRM_fixed(png_ptr, info_ptr, xy.whitex, xy.whitey, xy.redx, xy.redy,
1265 xy.greenx, xy.greeny, xy.bluex, xy.bluey);
1266
1267 /* We only use 'chromaticities' for RGB to gray */
1268# ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1269 /* There is no need to check sRGB here, cICP is NYI and iCCP is not
1270 * supported so just check mDCV.
1271 */
1272 if (!png_has_chunk(png_ptr, mDCV)(((png_ptr)->chunks & (0x80000000U >> (31 - (PNG_INDEX_mDCV
)))) != 0)
)
1273 {
1274 png_ptr->chromaticities = xy;
1275 }
1276# endif /* READ_RGB_TO_GRAY */
1277
1278 return handled_ok;
1279 PNG_UNUSED(length)(void)length;
1280}
1281#else
1282# define png_handle_cHRMMOZ_PNG_handle_cHRM NULL((void*)0)
1283#endif
1284
1285#ifdef PNG_READ_sRGB_SUPPORTED
1286static png_handle_result_code /* PRIVATE */
1287png_handle_sRGBMOZ_PNG_handle_sRGB(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1288{
1289 png_byte intent;
1
'intent' declared without an initial value
1290
1291 png_debug(1, "in png_handle_sRGB")((void)0);
1292
1293 png_crc_readMOZ_PNG_crc_read(png_ptr, &intent, 1);
2
Calling 'MOZ_PNG_crc_read'
6
Returning from 'MOZ_PNG_crc_read'
1294
1295 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
7
Assuming the condition is false
8
Taking false branch
1296 return handled_error;
1297
1298 /* This checks the range of the "rendering intent" because it is specified in
1299 * the PNG spec itself; the "reserved" values will result in the chunk not
1300 * being accepted, just as they do with the various "reserved" values in
1301 * IHDR.
1302 */
1303 if (intent > 3/*PNGv3 spec*/)
9
The left operand of '>' is a garbage value
1304 {
1305 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
1306 return handled_error;
1307 }
1308
1309 png_set_sRGBMOZ_PNG_set_sRGB(png_ptr, info_ptr, intent);
1310 /* NOTE: png_struct::chromaticities is not set here because the RGB to gray
1311 * coefficients are known without a need for the chromaticities.
1312 */
1313
1314#ifdef PNG_READ_GAMMA_SUPPORTED
1315 /* PNGv3: chunk precedence for gamma is cICP, [iCCP], sRGB, gAMA. iCCP is
1316 * not supported by libpng so the only requirement is to check for cICP
1317 * setting the gamma (this is NYI, but this check is safe.)
1318 */
1319 if (!png_has_chunk(png_ptr, cICP)(((png_ptr)->chunks & (0x80000000U >> (31 - (PNG_INDEX_cICP
)))) != 0)
|| png_ptr->chunk_gamma == 0)
1320 png_ptr->chunk_gamma = PNG_GAMMA_sRGB_INVERSE45455;
1321#endif /*READ_GAMMA*/
1322
1323 return handled_ok;
1324 PNG_UNUSED(length)(void)length;
1325}
1326#else
1327# define png_handle_sRGBMOZ_PNG_handle_sRGB NULL((void*)0)
1328#endif /* READ_sRGB */
1329
1330#ifdef PNG_READ_iCCP_SUPPORTED
1331static png_handle_result_code /* PRIVATE */
1332png_handle_iCCPMOZ_PNG_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1333/* Note: this does not properly handle profiles that are > 64K under DOS */
1334{
1335 png_const_charp errmsg = NULL((void*)0); /* error message output, or no error */
1336 int finished = 0; /* crc checked */
1337
1338 png_debug(1, "in png_handle_iCCP")((void)0);
1339
1340 /* PNGv3: allow PNG files with both sRGB and iCCP because the PNG spec only
1341 * ever said that there "should" be only one, not "shall" and the PNGv3
1342 * colour chunk precedence rules give a handling for this case anyway.
1343 */
1344 {
1345 uInt read_length, keyword_length;
1346 char keyword[81];
1347
1348 /* Find the keyword; the keyword plus separator and compression method
1349 * bytes can be at most 81 characters long.
1350 */
1351 read_length = 81; /* maximum */
1352 if (read_length > length)
1353 read_length = (uInt)/*SAFE*/length;
1354
1355 png_crc_readMOZ_PNG_crc_read(png_ptr, (png_bytep)keyword, read_length);
1356 length -= read_length;
1357
1358 if (length < LZ77Min(2U+5U+4U))
1359 {
1360 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1361 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "too short");
1362 return handled_error;
1363 }
1364
1365 keyword_length = 0;
1366 while (keyword_length < 80 && keyword_length < read_length &&
1367 keyword[keyword_length] != 0)
1368 ++keyword_length;
1369
1370 /* TODO: make the keyword checking common */
1371 if (keyword_length >= 1 && keyword_length <= 79)
1372 {
1373 /* We only understand '0' compression - deflate - so if we get a
1374 * different value we can't safely decode the chunk.
1375 */
1376 if (keyword_length+1 < read_length &&
1377 keyword[keyword_length+1] == PNG_COMPRESSION_TYPE_BASE0)
1378 {
1379 read_length -= keyword_length+2;
1380
1381 if (png_inflate_claim(png_ptr, png_iCCP((((0xFFFFFFFFU)&(105)) << (24)) | (((0xFFFFFFFFU)&
(67)) << (16)) | (((0xFFFFFFFFU)&(67)) << (8)
) | (((0xFFFFFFFFU)&(80)) << (0)))
) == Z_OK0)
1382 {
1383 Byte profile_header[132]={0};
1384 Byte local_buffer[PNG_INFLATE_BUF_SIZE1024];
1385 png_alloc_size_t size = (sizeof profile_header);
1386
1387 png_ptr->zstream.next_in = (Bytef*)keyword + (keyword_length+2);
1388 png_ptr->zstream.avail_in = read_length;
1389 (void)png_inflate_read(png_ptr, local_buffer,
1390 (sizeof local_buffer), &length, profile_header, &size,
1391 0/*finish: don't, because the output is too small*/);
1392
1393 if (size == 0)
1394 {
1395 /* We have the ICC profile header; do the basic header checks.
1396 */
1397 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))
))
;
1398
1399 if (png_icc_check_lengthMOZ_PNG_icc_check_length(png_ptr, keyword, profile_length) !=
1400 0)
1401 {
1402 /* The length is apparently ok, so we can check the 132
1403 * byte header.
1404 */
1405 if (png_icc_check_headerMOZ_PNG_icc_check_header(png_ptr, keyword, profile_length,
1406 profile_header, png_ptr->color_type) != 0)
1407 {
1408 /* Now read the tag table; a variable size buffer is
1409 * needed at this point, allocate one for the whole
1410 * profile. The header check has already validated
1411 * that none of this stuff will overflow.
1412 */
1413 png_uint_32 tag_count =
1414 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))))
;
1415 png_bytep profile = png_read_buffer(png_ptr,
1416 profile_length);
1417
1418 if (profile != NULL((void*)0))
1419 {
1420 memcpy(profile, profile_header,
1421 (sizeof profile_header));
1422
1423 size = 12 * tag_count;
1424
1425 (void)png_inflate_read(png_ptr, local_buffer,
1426 (sizeof local_buffer), &length,
1427 profile + (sizeof profile_header), &size, 0);
1428
1429 /* Still expect a buffer error because we expect
1430 * there to be some tag data!
1431 */
1432 if (size == 0)
1433 {
1434 if (png_icc_check_tag_tableMOZ_PNG_icc_check_tags(png_ptr,
1435 keyword, profile_length, profile) != 0)
1436 {
1437 /* The profile has been validated for basic
1438 * security issues, so read the whole thing in.
1439 */
1440 size = profile_length - (sizeof profile_header)
1441 - 12 * tag_count;
1442
1443 (void)png_inflate_read(png_ptr, local_buffer,
1444 (sizeof local_buffer), &length,
1445 profile + (sizeof profile_header) +
1446 12 * tag_count, &size, 1/*finish*/);
1447
1448 if (length > 0 && !(png_ptr->flags &
1449 PNG_FLAG_BENIGN_ERRORS_WARN0x100000U))
1450 errmsg = "extra compressed data";
1451
1452 /* But otherwise allow extra data: */
1453 else if (size == 0)
1454 {
1455 if (length > 0)
1456 {
1457 /* This can be handled completely, so
1458 * keep going.
1459 */
1460 png_chunk_warningMOZ_PNG_chunk_warn(png_ptr,
1461 "extra compressed data");
1462 }
1463
1464 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1465 finished = 1;
1466
1467 /* Steal the profile for info_ptr. */
1468 if (info_ptr != NULL((void*)0))
1469 {
1470 png_free_dataMOZ_PNG_free_data(png_ptr, info_ptr,
1471 PNG_FREE_ICCP0x0010U, 0);
1472
1473 info_ptr->iccp_name = png_voidcast(char*,(MOZ_PNG_malloc_base(png_ptr, keyword_length+1))
1474 png_malloc_base(png_ptr,(MOZ_PNG_malloc_base(png_ptr, keyword_length+1))
1475 keyword_length+1))(MOZ_PNG_malloc_base(png_ptr, keyword_length+1));
1476 if (info_ptr->iccp_name != NULL((void*)0))
1477 {
1478 memcpy(info_ptr->iccp_name, keyword,
1479 keyword_length+1);
1480 info_ptr->iccp_proflen =
1481 profile_length;
1482 info_ptr->iccp_profile = profile;
1483 png_ptr->read_buffer = NULL((void*)0); /*steal*/
1484 info_ptr->free_me |= PNG_FREE_ICCP0x0010U;
1485 info_ptr->valid |= PNG_INFO_iCCP0x1000U;
1486 }
1487
1488 else
1489 errmsg = "out of memory";
1490 }
1491
1492 /* else the profile remains in the read
1493 * buffer which gets reused for subsequent
1494 * chunks.
1495 */
1496
1497 if (errmsg == NULL((void*)0))
1498 {
1499 png_ptr->zowner = 0;
1500 return handled_ok;
1501 }
1502 }
1503 if (errmsg == NULL((void*)0))
1504 errmsg = png_ptr->zstream.msg;
1505 }
1506 /* else png_icc_check_tag_table output an error */
1507 }
1508 else /* profile truncated */
1509 errmsg = png_ptr->zstream.msg;
1510 }
1511
1512 else
1513 errmsg = "out of memory";
1514 }
1515
1516 /* else png_icc_check_header output an error */
1517 }
1518
1519 /* else png_icc_check_length output an error */
1520 }
1521
1522 else /* profile truncated */
1523 errmsg = png_ptr->zstream.msg;
1524
1525 /* Release the stream */
1526 png_ptr->zowner = 0;
1527 }
1528
1529 else /* png_inflate_claim failed */
1530 errmsg = png_ptr->zstream.msg;
1531 }
1532
1533 else
1534 errmsg = "bad compression method"; /* or missing */
1535 }
1536
1537 else
1538 errmsg = "bad keyword";
1539 }
1540
1541 /* Failure: the reason is in 'errmsg' */
1542 if (finished == 0)
1543 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1544
1545 if (errmsg != NULL((void*)0)) /* else already output */
1546 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, errmsg);
1547
1548 return handled_error;
1549}
1550#else
1551# define png_handle_iCCPMOZ_PNG_handle_iCCP NULL((void*)0)
1552#endif /* READ_iCCP */
1553
1554#ifdef PNG_READ_sPLT_SUPPORTED
1555static png_handle_result_code /* PRIVATE */
1556png_handle_sPLT((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1557/* Note: this does not properly handle chunks that are > 64K under DOS */
1558{
1559 png_bytep buffer;
1560 png_bytep entry_start;
1561 png_sPLT_t new_palette;
1562 png_sPLT_entryp pp;
1563 png_uint_32 data_length;
1564 int entry_size, i;
1565 png_uint_32 skip = 0;
1566 png_uint_32 dl;
1567 size_t max_dl;
1568
1569 png_debug(1, "in png_handle_sPLT")((void)0);
1570
1571#ifdef PNG_USER_LIMITS_SUPPORTED
1572 if (png_ptr->user_chunk_cache_max != 0)
1573 {
1574 if (png_ptr->user_chunk_cache_max == 1)
1575 {
1576 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1577 return handled_error;
1578 }
1579
1580 if (--png_ptr->user_chunk_cache_max == 1)
1581 {
1582 png_warningMOZ_PNG_warning(png_ptr, "No space in chunk cache for sPLT");
1583 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1584 return handled_error;
1585 }
1586 }
1587#endif
1588
1589 buffer = png_read_buffer(png_ptr, length+1);
1590 if (buffer == NULL((void*)0))
1591 {
1592 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1593 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of memory");
1594 return handled_error;
1595 }
1596
1597
1598 /* WARNING: this may break if size_t is less than 32 bits; it is assumed
1599 * that the PNG_MAX_MALLOC_64K test is enabled in this case, but this is a
1600 * potential breakage point if the types in pngconf.h aren't exactly right.
1601 */
1602 png_crc_readMOZ_PNG_crc_read(png_ptr, buffer, length);
1603
1604 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, skip) != 0)
1605 return handled_error;
1606
1607 buffer[length] = 0;
1608
1609 for (entry_start = buffer; *entry_start; entry_start++)
1610 /* Empty loop to find end of name */ ;
1611
1612 ++entry_start;
1613
1614 /* A sample depth should follow the separator, and we should be on it */
1615 if (length < 2U || entry_start > buffer + (length - 2U))
1616 {
1617 png_warningMOZ_PNG_warning(png_ptr, "malformed sPLT chunk");
1618 return handled_error;
1619 }
1620
1621 new_palette.depth = *entry_start++;
1622 entry_size = (new_palette.depth == 8 ? 6 : 10);
1623 /* This must fit in a png_uint_32 because it is derived from the original
1624 * chunk data length.
1625 */
1626 data_length = length - (png_uint_32)(entry_start - buffer);
1627
1628 /* Integrity-check the data length */
1629 if ((data_length % (unsigned int)entry_size) != 0)
1630 {
1631 png_warningMOZ_PNG_warning(png_ptr, "sPLT chunk has bad length");
1632 return handled_error;
1633 }
1634
1635 dl = (png_uint_32)(data_length / (unsigned int)entry_size);
1636 max_dl = PNG_SIZE_MAX((size_t)(-1)) / (sizeof (png_sPLT_entry));
1637
1638 if (dl > max_dl)
1639 {
1640 png_warningMOZ_PNG_warning(png_ptr, "sPLT chunk too long");
1641 return handled_error;
1642 }
1643
1644 new_palette.nentries = (png_int_32)(data_length / (unsigned int)entry_size);
1645
1646 new_palette.entries = (png_sPLT_entryp)png_malloc_warnMOZ_PNG_malloc_warn(png_ptr,
1647 (png_alloc_size_t) new_palette.nentries * (sizeof (png_sPLT_entry)));
1648
1649 if (new_palette.entries == NULL((void*)0))
1650 {
1651 png_warningMOZ_PNG_warning(png_ptr, "sPLT chunk requires too much memory");
1652 return handled_error;
1653 }
1654
1655 for (i = 0; i < new_palette.nentries; i++)
1656 {
1657 pp = new_palette.entries + i;
1658
1659 if (new_palette.depth == 8)
1660 {
1661 pp->red = *entry_start++;
1662 pp->green = *entry_start++;
1663 pp->blue = *entry_start++;
1664 pp->alpha = *entry_start++;
1665 }
1666
1667 else
1668 {
1669 pp->red = png_get_uint_16(entry_start)((png_uint_16) (((unsigned int)(*(entry_start)) << 8) +
((unsigned int)(*((entry_start) + 1)))))
; entry_start += 2;
1670 pp->green = png_get_uint_16(entry_start)((png_uint_16) (((unsigned int)(*(entry_start)) << 8) +
((unsigned int)(*((entry_start) + 1)))))
; entry_start += 2;
1671 pp->blue = png_get_uint_16(entry_start)((png_uint_16) (((unsigned int)(*(entry_start)) << 8) +
((unsigned int)(*((entry_start) + 1)))))
; entry_start += 2;
1672 pp->alpha = png_get_uint_16(entry_start)((png_uint_16) (((unsigned int)(*(entry_start)) << 8) +
((unsigned int)(*((entry_start) + 1)))))
; entry_start += 2;
1673 }
1674
1675 pp->frequency = png_get_uint_16(entry_start)((png_uint_16) (((unsigned int)(*(entry_start)) << 8) +
((unsigned int)(*((entry_start) + 1)))))
; entry_start += 2;
1676 }
1677
1678 /* Discard all chunk data except the name and stash that */
1679 new_palette.name = (png_charp)buffer;
1680
1681 png_set_sPLTMOZ_PNG_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
1682
1683 png_freeMOZ_PNG_free(png_ptr, new_palette.entries);
1684 return handled_ok;
1685}
1686#else
1687# define png_handle_sPLT((void*)0) NULL((void*)0)
1688#endif /* READ_sPLT */
1689
1690#ifdef PNG_READ_tRNS_SUPPORTED
1691static png_handle_result_code /* PRIVATE */
1692png_handle_tRNSMOZ_PNG_handle_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1693{
1694 png_byte readbuf[PNG_MAX_PALETTE_LENGTH256];
1695
1696 png_debug(1, "in png_handle_tRNS")((void)0);
1697
1698 if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY0)
1699 {
1700 png_byte buf[2];
1701
1702 if (length != 2)
1703 {
1704 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1705 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
1706 return handled_error;
1707 }
1708
1709 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 2);
1710 png_ptr->num_trans = 1;
1711 png_ptr->trans_color.gray = png_get_uint_16(buf)((png_uint_16) (((unsigned int)(*(buf)) << 8) + ((unsigned
int)(*((buf) + 1)))))
;
1712 }
1713
1714 else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB(2))
1715 {
1716 png_byte buf[6];
1717
1718 if (length != 6)
1719 {
1720 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1721 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
1722 return handled_error;
1723 }
1724
1725 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, length);
1726 png_ptr->num_trans = 1;
1727 png_ptr->trans_color.red = png_get_uint_16(buf)((png_uint_16) (((unsigned int)(*(buf)) << 8) + ((unsigned
int)(*((buf) + 1)))))
;
1728 png_ptr->trans_color.green = png_get_uint_16(buf + 2)((png_uint_16) (((unsigned int)(*(buf + 2)) << 8) + ((unsigned
int)(*((buf + 2) + 1)))))
;
1729 png_ptr->trans_color.blue = png_get_uint_16(buf + 4)((png_uint_16) (((unsigned int)(*(buf + 4)) << 8) + ((unsigned
int)(*((buf + 4) + 1)))))
;
1730 }
1731
1732 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE(2 | 1))
1733 {
1734 if ((png_ptr->mode & PNG_HAVE_PLTE0x02) == 0)
1735 {
1736 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1737 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of place");
1738 return handled_error;
1739 }
1740
1741 if (length > (unsigned int) png_ptr->num_palette ||
1742 length > (unsigned int) PNG_MAX_PALETTE_LENGTH256 ||
1743 length == 0)
1744 {
1745 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1746 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
1747 return handled_error;
1748 }
1749
1750 png_crc_readMOZ_PNG_crc_read(png_ptr, readbuf, length);
1751 png_ptr->num_trans = (png_uint_16)length;
1752 }
1753
1754 else
1755 {
1756 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1757 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid with alpha channel");
1758 return handled_error;
1759 }
1760
1761 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
1762 {
1763 png_ptr->num_trans = 0;
1764 return handled_error;
1765 }
1766
1767 png_set_tRNSMOZ_PNG_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
1768 &(png_ptr->trans_color));
1769 return handled_ok;
1770}
1771#else
1772# define png_handle_tRNSMOZ_PNG_handle_tRNS NULL((void*)0)
1773#endif
1774
1775#ifdef PNG_READ_bKGD_SUPPORTED
1776static png_handle_result_code /* PRIVATE */
1777png_handle_bKGD((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1778{
1779 unsigned int truelen;
1780 png_byte buf[6];
1781 png_color_16 background;
1782
1783 png_debug(1, "in png_handle_bKGD")((void)0);
1784
1785 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE(2 | 1))
1786 {
1787 if ((png_ptr->mode & PNG_HAVE_PLTE0x02) == 0)
1788 {
1789 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1790 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of place");
1791 return handled_error;
1792 }
1793
1794 truelen = 1;
1795 }
1796
1797 else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR2) != 0)
1798 truelen = 6;
1799
1800 else
1801 truelen = 2;
1802
1803 if (length != truelen)
1804 {
1805 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
1806 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
1807 return handled_error;
1808 }
1809
1810 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, truelen);
1811
1812 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
1813 return handled_error;
1814
1815 /* We convert the index value into RGB components so that we can allow
1816 * arbitrary RGB values for background when we have transparency, and
1817 * so it is easy to determine the RGB values of the background color
1818 * from the info_ptr struct.
1819 */
1820 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE(2 | 1))
1821 {
1822 background.index = buf[0];
1823
1824 if (info_ptr != NULL((void*)0) && info_ptr->num_palette != 0)
1825 {
1826 if (buf[0] >= info_ptr->num_palette)
1827 {
1828 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid index");
1829 return handled_error;
1830 }
1831
1832 background.red = (png_uint_16)png_ptr->palette[buf[0]].red;
1833 background.green = (png_uint_16)png_ptr->palette[buf[0]].green;
1834 background.blue = (png_uint_16)png_ptr->palette[buf[0]].blue;
1835 }
1836
1837 else
1838 background.red = background.green = background.blue = 0;
1839
1840 background.gray = 0;
1841 }
1842
1843 else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR2) == 0) /* GRAY */
1844 {
1845 if (png_ptr->bit_depth <= 8)
1846 {
1847 if (buf[0] != 0 || buf[1] >= (unsigned int)(1 << png_ptr->bit_depth))
1848 {
1849 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid gray level");
1850 return handled_error;
1851 }
1852 }
1853
1854 background.index = 0;
1855 background.red =
1856 background.green =
1857 background.blue =
1858 background.gray = png_get_uint_16(buf)((png_uint_16) (((unsigned int)(*(buf)) << 8) + ((unsigned
int)(*((buf) + 1)))))
;
1859 }
1860
1861 else
1862 {
1863 if (png_ptr->bit_depth <= 8)
1864 {
1865 if (buf[0] != 0 || buf[2] != 0 || buf[4] != 0)
1866 {
1867 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid color");
1868 return handled_error;
1869 }
1870 }
1871
1872 background.index = 0;
1873 background.red = png_get_uint_16(buf)((png_uint_16) (((unsigned int)(*(buf)) << 8) + ((unsigned
int)(*((buf) + 1)))))
;
1874 background.green = png_get_uint_16(buf + 2)((png_uint_16) (((unsigned int)(*(buf + 2)) << 8) + ((unsigned
int)(*((buf + 2) + 1)))))
;
1875 background.blue = png_get_uint_16(buf + 4)((png_uint_16) (((unsigned int)(*(buf + 4)) << 8) + ((unsigned
int)(*((buf + 4) + 1)))))
;
1876 background.gray = 0;
1877 }
1878
1879 png_set_bKGDMOZ_PNG_set_bKGD(png_ptr, info_ptr, &background);
1880 return handled_ok;
1881}
1882#else
1883# define png_handle_bKGD((void*)0) NULL((void*)0)
1884#endif
1885
1886#ifdef PNG_READ_cICP_SUPPORTED
1887static png_handle_result_code /* PRIVATE */
1888png_handle_cICP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1889{
1890 png_byte buf[4];
1891
1892 png_debug(1, "in png_handle_cICP")((void)0);
1893
1894 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 4);
1895
1896 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
1897 return handled_error;
1898
1899 png_set_cICP(png_ptr, info_ptr, buf[0], buf[1], buf[2], buf[3]);
1900
1901 /* We only use 'chromaticities' for RGB to gray */
1902# ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1903 if (!png_has_chunk(png_ptr, mDCV)(((png_ptr)->chunks & (0x80000000U >> (31 - (PNG_INDEX_mDCV
)))) != 0)
)
1904 {
1905 /* TODO: png_ptr->chromaticities = chromaticities; */
1906 }
1907# endif /* READ_RGB_TO_GRAY */
1908
1909#ifdef PNG_READ_GAMMA_SUPPORTED
1910 /* PNGv3: chunk precedence for gamma is cICP, [iCCP], sRGB, gAMA. cICP is
1911 * at the head so simply set the gamma if it can be determined. If not
1912 * chunk_gamma remains unchanged; sRGB and gAMA handling check it for
1913 * being zero.
1914 */
1915 /* TODO: set png_struct::chunk_gamma when possible */
1916#endif /*READ_GAMMA*/
1917
1918 return handled_ok;
1919 PNG_UNUSED(length)(void)length;
1920}
1921#else
1922# define png_handle_cICP NULL((void*)0)
1923#endif
1924
1925#ifdef PNG_READ_cLLI_SUPPORTED
1926static png_handle_result_code /* PRIVATE */
1927png_handle_cLLI((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1928{
1929 png_byte buf[8];
1930
1931 png_debug(1, "in png_handle_cLLI")((void)0);
1932
1933 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 8);
1934
1935 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
1936 return handled_error;
1937
1938 /* The error checking happens here, this puts it in just one place: */
1939 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))))
,
1940 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))))
);
1941 return handled_ok;
1942 PNG_UNUSED(length)(void)length;
1943}
1944#else
1945# define png_handle_cLLI((void*)0) NULL((void*)0)
1946#endif
1947
1948#ifdef PNG_READ_mDCV_SUPPORTED
1949static png_handle_result_code /* PRIVATE */
1950png_handle_mDCV((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1951{
1952 png_xy chromaticities;
1953 png_byte buf[24];
1954
1955 png_debug(1, "in png_handle_mDCV")((void)0);
1956
1957 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 24);
1958
1959 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
1960 return handled_error;
1961
1962 /* The error checking happens here, this puts it in just one place. The
1963 * odd /50000 scaling factor makes it more difficult but the (x.y) values are
1964 * only two bytes so a <<1 is safe.
1965 *
1966 * WARNING: the PNG specification defines the cHRM chunk to **start** with
1967 * the white point (x,y). The W3C PNG v3 specification puts the white point
1968 * **after* R,G,B. The x,y values in mDCV are also scaled by 50,000 and
1969 * stored in just two bytes, whereas those in cHRM are scaled by 100,000 and
1970 * stored in four bytes. This is very, very confusing. These APIs remove
1971 * the confusion by copying the existing, well established, API.
1972 */
1973 chromaticities.redx = png_get_uint_16(buf+ 0U)((png_uint_16) (((unsigned int)(*(buf+ 0U)) << 8) + ((unsigned
int)(*((buf+ 0U) + 1)))))
<< 1; /* red x */
1974 chromaticities.redy = png_get_uint_16(buf+ 2U)((png_uint_16) (((unsigned int)(*(buf+ 2U)) << 8) + ((unsigned
int)(*((buf+ 2U) + 1)))))
<< 1; /* red y */
1975 chromaticities.greenx = png_get_uint_16(buf+ 4U)((png_uint_16) (((unsigned int)(*(buf+ 4U)) << 8) + ((unsigned
int)(*((buf+ 4U) + 1)))))
<< 1; /* green x */
1976 chromaticities.greeny = png_get_uint_16(buf+ 6U)((png_uint_16) (((unsigned int)(*(buf+ 6U)) << 8) + ((unsigned
int)(*((buf+ 6U) + 1)))))
<< 1; /* green y */
1977 chromaticities.bluex = png_get_uint_16(buf+ 8U)((png_uint_16) (((unsigned int)(*(buf+ 8U)) << 8) + ((unsigned
int)(*((buf+ 8U) + 1)))))
<< 1; /* blue x */
1978 chromaticities.bluey = png_get_uint_16(buf+10U)((png_uint_16) (((unsigned int)(*(buf+10U)) << 8) + ((unsigned
int)(*((buf+10U) + 1)))))
<< 1; /* blue y */
1979 chromaticities.whitex = png_get_uint_16(buf+12U)((png_uint_16) (((unsigned int)(*(buf+12U)) << 8) + ((unsigned
int)(*((buf+12U) + 1)))))
<< 1; /* white x */
1980 chromaticities.whitey = png_get_uint_16(buf+14U)((png_uint_16) (((unsigned int)(*(buf+14U)) << 8) + ((unsigned
int)(*((buf+14U) + 1)))))
<< 1; /* white y */
1981
1982 png_set_mDCV_fixed(png_ptr, info_ptr,
1983 chromaticities.whitex, chromaticities.whitey,
1984 chromaticities.redx, chromaticities.redy,
1985 chromaticities.greenx, chromaticities.greeny,
1986 chromaticities.bluex, chromaticities.bluey,
1987 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 */
1988 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 */
1989
1990 /* We only use 'chromaticities' for RGB to gray */
1991# ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1992 png_ptr->chromaticities = chromaticities;
1993# endif /* READ_RGB_TO_GRAY */
1994
1995 return handled_ok;
1996 PNG_UNUSED(length)(void)length;
1997}
1998#else
1999# define png_handle_mDCV((void*)0) NULL((void*)0)
2000#endif
2001
2002#ifdef PNG_READ_eXIf_SUPPORTED
2003static png_handle_result_code /* PRIVATE */
2004png_handle_eXIf(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2005{
2006 png_bytep buffer = NULL((void*)0);
2007
2008 png_debug(1, "in png_handle_eXIf")((void)0);
2009
2010 buffer = png_read_buffer(png_ptr, length);
2011
2012 if (buffer == NULL((void*)0))
2013 {
2014 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2015 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of memory");
2016 return handled_error;
2017 }
2018
2019 png_crc_readMOZ_PNG_crc_read(png_ptr, buffer, length);
2020
2021 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
2022 return handled_error;
2023
2024 /* PNGv3: the code used to check the byte order mark at the start for MM or
2025 * II, however PNGv3 states that the first 4 bytes should be checked.
2026 * The caller ensures that there are four bytes available.
2027 */
2028 {
2029 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))))
;
2030
2031 /* These numbers are copied from the PNGv3 spec: */
2032 if (header != 0x49492A00 && header != 0x4D4D002A)
2033 {
2034 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
2035 return handled_error;
2036 }
2037 }
2038
2039 png_set_eXIf_1(png_ptr, info_ptr, length, buffer);
2040 return handled_ok;
2041}
2042#else
2043# define png_handle_eXIf NULL((void*)0)
2044#endif
2045
2046#ifdef PNG_READ_hIST_SUPPORTED
2047static png_handle_result_code /* PRIVATE */
2048png_handle_hIST((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2049{
2050 unsigned int num, i;
2051 png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH256];
2052
2053 png_debug(1, "in png_handle_hIST")((void)0);
2054
2055 /* This cast is safe because the chunk definition limits the length to a
2056 * maximum of 1024 bytes.
2057 *
2058 * TODO: maybe use png_uint_32 anyway, not unsigned int, to reduce the
2059 * casts.
2060 */
2061 num = (unsigned int)length / 2 ;
2062
2063 if (length != num * 2 ||
2064 num != (unsigned int)png_ptr->num_palette ||
2065 num > (unsigned int)PNG_MAX_PALETTE_LENGTH256)
2066 {
2067 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2068 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
2069 return handled_error;
2070 }
2071
2072 for (i = 0; i < num; i++)
2073 {
2074 png_byte buf[2];
2075
2076 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 2);
2077 readbuf[i] = png_get_uint_16(buf)((png_uint_16) (((unsigned int)(*(buf)) << 8) + ((unsigned
int)(*((buf) + 1)))))
;
2078 }
2079
2080 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
2081 return handled_error;
2082
2083 png_set_hISTMOZ_PNG_set_hIST(png_ptr, info_ptr, readbuf);
2084 return handled_ok;
2085}
2086#else
2087# define png_handle_hIST((void*)0) NULL((void*)0)
2088#endif
2089
2090#ifdef PNG_READ_pHYs_SUPPORTED
2091static png_handle_result_code /* PRIVATE */
2092png_handle_pHYs((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2093{
2094 png_byte buf[9];
2095 png_uint_32 res_x, res_y;
2096 int unit_type;
2097
2098 png_debug(1, "in png_handle_pHYs")((void)0);
2099
2100 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 9);
2101
2102 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
2103 return handled_error;
2104
2105 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))))
;
2106 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))))
;
2107 unit_type = buf[8];
2108 png_set_pHYsMOZ_PNG_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
2109 return handled_ok;
2110 PNG_UNUSED(length)(void)length;
2111}
2112#else
2113# define png_handle_pHYs((void*)0) NULL((void*)0)
2114#endif
2115
2116#ifdef PNG_READ_oFFs_SUPPORTED
2117static png_handle_result_code /* PRIVATE */
2118png_handle_oFFs((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2119{
2120 png_byte buf[9];
2121 png_int_32 offset_x, offset_y;
2122 int unit_type;
2123
2124 png_debug(1, "in png_handle_oFFs")((void)0);
2125
2126 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 9);
2127
2128 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
2129 return handled_error;
2130
2131 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))))))
;
2132 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))))))
;
2133 unit_type = buf[8];
2134 png_set_oFFsMOZ_PNG_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
2135 return handled_ok;
2136 PNG_UNUSED(length)(void)length;
2137}
2138#else
2139# define png_handle_oFFs((void*)0) NULL((void*)0)
2140#endif
2141
2142#ifdef PNG_READ_pCAL_SUPPORTED
2143/* Read the pCAL chunk (described in the PNG Extensions document) */
2144static png_handle_result_code /* PRIVATE */
2145png_handle_pCAL((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2146{
2147 png_bytep buffer;
2148 png_bytep buf;
2149 png_bytep endptr;
2150 png_int_32 X0, X1;
2151 png_byte type;
2152 png_byte nparams;
2153 png_byte *units;
2154 png_charpp params;
2155 int i;
2156
2157 png_debug(1, "in png_handle_pCAL")((void)0);
2158 png_debug1(2, "Allocating and reading pCAL chunk data (%u bytes)",((void)0)
2159 length + 1)((void)0);
2160
2161 buffer = png_read_buffer(png_ptr, length+1);
2162
2163 if (buffer == NULL((void*)0))
2164 {
2165 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2166 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of memory");
2167 return handled_error;
2168 }
2169
2170 png_crc_readMOZ_PNG_crc_read(png_ptr, buffer, length);
2171
2172 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
2173 return handled_error;
2174
2175 buffer[length] = 0; /* Null terminate the last string */
2176
2177 png_debug(3, "Finding end of pCAL purpose string")((void)0);
2178 for (buf = buffer; *buf; buf++)
2179 /* Empty loop */ ;
2180
2181 endptr = buffer + length;
2182
2183 /* We need to have at least 12 bytes after the purpose string
2184 * in order to get the parameter information.
2185 */
2186 if (endptr - buf <= 12)
2187 {
2188 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid");
2189 return handled_error;
2190 }
2191
2192 png_debug(3, "Reading pCAL X0, X1, type, nparams, and units")((void)0);
2193 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))))))
;
2194 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))))))
;
2195 type = buf[9];
2196 nparams = buf[10];
2197 units = buf + 11;
2198
2199 png_debug(3, "Checking pCAL equation type and number of parameters")((void)0);
2200 /* Check that we have the right number of parameters for known
2201 * equation types.
2202 */
2203 if ((type == PNG_EQUATION_LINEAR0 && nparams != 2) ||
2204 (type == PNG_EQUATION_BASE_E1 && nparams != 3) ||
2205 (type == PNG_EQUATION_ARBITRARY2 && nparams != 3) ||
2206 (type == PNG_EQUATION_HYPERBOLIC3 && nparams != 4))
2207 {
2208 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid parameter count");
2209 return handled_error;
2210 }
2211
2212 else if (type >= PNG_EQUATION_LAST4)
2213 {
2214 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "unrecognized equation type");
2215 }
2216
2217 for (buf = units; *buf; buf++)
2218 /* Empty loop to move past the units string. */ ;
2219
2220 png_debug(3, "Allocating pCAL parameters array")((void)0);
2221
2222 params = png_voidcast(png_charpp, png_malloc_warn(png_ptr,(MOZ_PNG_malloc_warn(png_ptr, nparams * (sizeof (png_charp)))
)
2223 nparams * (sizeof (png_charp))))(MOZ_PNG_malloc_warn(png_ptr, nparams * (sizeof (png_charp)))
)
;
2224
2225 if (params == NULL((void*)0))
2226 {
2227 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of memory");
2228 return handled_error;
2229 }
2230
2231 /* Get pointers to the start of each parameter string. */
2232 for (i = 0; i < nparams; i++)
2233 {
2234 buf++; /* Skip the null string terminator from previous parameter. */
2235
2236 png_debug1(3, "Reading pCAL parameter %d", i)((void)0);
2237
2238 for (params[i] = (png_charp)buf; buf <= endptr && *buf != 0; buf++)
2239 /* Empty loop to move past each parameter string */ ;
2240
2241 /* Make sure we haven't run out of data yet */
2242 if (buf > endptr)
2243 {
2244 png_freeMOZ_PNG_free(png_ptr, params);
2245 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid data");
2246 return handled_error;
2247 }
2248 }
2249
2250 png_set_pCALMOZ_PNG_set_pCAL(png_ptr, info_ptr, (png_charp)buffer, X0, X1, type, nparams,
2251 (png_charp)units, params);
2252
2253 /* TODO: BUG: png_set_pCAL calls png_chunk_report which, in this case, calls
2254 * png_benign_error and that can error out.
2255 *
2256 * png_read_buffer needs to be allocated with space for both nparams and the
2257 * parameter strings. Not hard to do.
2258 */
2259 png_freeMOZ_PNG_free(png_ptr, params);
2260 return handled_ok;
2261}
2262#else
2263# define png_handle_pCAL((void*)0) NULL((void*)0)
2264#endif
2265
2266#ifdef PNG_READ_sCAL_SUPPORTED
2267/* Read the sCAL chunk */
2268static png_handle_result_code /* PRIVATE */
2269png_handle_sCAL((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2270{
2271 png_bytep buffer;
2272 size_t i;
2273 int state;
2274
2275 png_debug(1, "in png_handle_sCAL")((void)0);
2276 png_debug1(2, "Allocating and reading sCAL chunk data (%u bytes)",((void)0)
2277 length + 1)((void)0);
2278
2279 buffer = png_read_buffer(png_ptr, length+1);
2280
2281 if (buffer == NULL((void*)0))
2282 {
2283 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2284 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of memory");
2285 return handled_error;
2286 }
2287
2288 png_crc_readMOZ_PNG_crc_read(png_ptr, buffer, length);
2289 buffer[length] = 0; /* Null terminate the last string */
2290
2291 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
2292 return handled_error;
2293
2294 /* Validate the unit. */
2295 if (buffer[0] != 1 && buffer[0] != 2)
2296 {
2297 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "invalid unit");
2298 return handled_error;
2299 }
2300
2301 /* Validate the ASCII numbers, need two ASCII numbers separated by
2302 * a '\0' and they need to fit exactly in the chunk data.
2303 */
2304 i = 1;
2305 state = 0;
2306
2307 if (png_check_fp_numberMOZ_PNG_check_fp_number((png_const_charp)buffer, length, &state, &i) == 0 ||
2308 i >= length || buffer[i++] != 0)
2309 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "bad width format");
2310
2311 else if (PNG_FP_IS_POSITIVE(state) == 0)
2312 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "non-positive width");
2313
2314 else
2315 {
2316 size_t heighti = i;
2317
2318 state = 0;
2319 if (png_check_fp_numberMOZ_PNG_check_fp_number((png_const_charp)buffer, length,
2320 &state, &i) == 0 || i != length)
2321 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "bad height format");
2322
2323 else if (PNG_FP_IS_POSITIVE(state) == 0)
2324 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "non-positive height");
2325
2326 else
2327 {
2328 /* This is the (only) success case. */
2329 png_set_sCAL_sMOZ_PNG_set_sCAL_s(png_ptr, info_ptr, buffer[0],
2330 (png_charp)buffer+1, (png_charp)buffer+heighti);
2331 return handled_ok;
2332 }
2333 }
2334
2335 return handled_error;
2336}
2337#else
2338# define png_handle_sCAL((void*)0) NULL((void*)0)
2339#endif
2340
2341#ifdef PNG_READ_tIME_SUPPORTED
2342static png_handle_result_code /* PRIVATE */
2343png_handle_tIME((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2344{
2345 png_byte buf[7];
2346 png_time mod_time;
2347
2348 png_debug(1, "in png_handle_tIME")((void)0);
2349
2350 /* TODO: what is this doing here? It should be happened in pngread.c and
2351 * pngpread.c, although it could be moved to png_handle_chunk below and
2352 * thereby avoid some code duplication.
2353 */
2354 if ((png_ptr->mode & PNG_HAVE_IDAT0x04U) != 0)
2355 png_ptr->mode |= PNG_AFTER_IDAT0x08;
2356
2357 png_crc_readMOZ_PNG_crc_read(png_ptr, buf, 7);
2358
2359 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
2360 return handled_error;
2361
2362 mod_time.second = buf[6];
2363 mod_time.minute = buf[5];
2364 mod_time.hour = buf[4];
2365 mod_time.day = buf[3];
2366 mod_time.month = buf[2];
2367 mod_time.year = png_get_uint_16(buf)((png_uint_16) (((unsigned int)(*(buf)) << 8) + ((unsigned
int)(*((buf) + 1)))))
;
2368
2369 png_set_tIMEMOZ_PNG_set_tIME(png_ptr, info_ptr, &mod_time);
2370 return handled_ok;
2371 PNG_UNUSED(length)(void)length;
2372}
2373#else
2374# define png_handle_tIME((void*)0) NULL((void*)0)
2375#endif
2376
2377#ifdef PNG_READ_tEXt_SUPPORTED
2378/* Note: this does not properly handle chunks that are > 64K under DOS */
2379static png_handle_result_code /* PRIVATE */
2380png_handle_tEXt((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2381{
2382 png_text text_info;
2383 png_bytep buffer;
2384 png_charp key;
2385 png_charp text;
2386 png_uint_32 skip = 0;
2387
2388 png_debug(1, "in png_handle_tEXt")((void)0);
2389
2390#ifdef PNG_USER_LIMITS_SUPPORTED
2391 if (png_ptr->user_chunk_cache_max != 0)
2392 {
2393 if (png_ptr->user_chunk_cache_max == 1)
2394 {
2395 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2396 return handled_error;
2397 }
2398
2399 if (--png_ptr->user_chunk_cache_max == 1)
2400 {
2401 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2402 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "no space in chunk cache");
2403 return handled_error;
2404 }
2405 }
2406#endif
2407
2408 buffer = png_read_buffer(png_ptr, length+1);
2409
2410 if (buffer == NULL((void*)0))
2411 {
2412 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2413 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of memory");
2414 return handled_error;
2415 }
2416
2417 png_crc_readMOZ_PNG_crc_read(png_ptr, buffer, length);
2418
2419 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, skip) != 0)
2420 return handled_error;
2421
2422 key = (png_charp)buffer;
2423 key[length] = 0;
2424
2425 for (text = key; *text; text++)
2426 /* Empty loop to find end of key */ ;
2427
2428 if (text != key + length)
2429 text++;
2430
2431 text_info.compression = PNG_TEXT_COMPRESSION_NONE-1;
2432 text_info.key = key;
2433 text_info.lang = NULL((void*)0);
2434 text_info.lang_key = NULL((void*)0);
2435 text_info.itxt_length = 0;
2436 text_info.text = text;
2437 text_info.text_length = strlen(text);
2438
2439 if (png_set_text_2MOZ_PNG_set_text_2(png_ptr, info_ptr, &text_info, 1) == 0)
2440 return handled_ok;
2441
2442 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of memory");
2443 return handled_error;
2444}
2445#else
2446# define png_handle_tEXt((void*)0) NULL((void*)0)
2447#endif
2448
2449#ifdef PNG_READ_zTXt_SUPPORTED
2450/* Note: this does not correctly handle chunks that are > 64K under DOS */
2451static png_handle_result_code /* PRIVATE */
2452png_handle_zTXt((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2453{
2454 png_const_charp errmsg = NULL((void*)0);
2455 png_bytep buffer;
2456 png_uint_32 keyword_length;
2457
2458 png_debug(1, "in png_handle_zTXt")((void)0);
2459
2460#ifdef PNG_USER_LIMITS_SUPPORTED
2461 if (png_ptr->user_chunk_cache_max != 0)
2462 {
2463 if (png_ptr->user_chunk_cache_max == 1)
2464 {
2465 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2466 return handled_error;
2467 }
2468
2469 if (--png_ptr->user_chunk_cache_max == 1)
2470 {
2471 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2472 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "no space in chunk cache");
2473 return handled_error;
2474 }
2475 }
2476#endif
2477
2478 /* Note, "length" is sufficient here; we won't be adding
2479 * a null terminator later. The limit check in png_handle_chunk should be
2480 * sufficient.
2481 */
2482 buffer = png_read_buffer(png_ptr, length);
2483
2484 if (buffer == NULL((void*)0))
2485 {
2486 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2487 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of memory");
2488 return handled_error;
2489 }
2490
2491 png_crc_readMOZ_PNG_crc_read(png_ptr, buffer, length);
2492
2493 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
2494 return handled_error;
2495
2496 /* TODO: also check that the keyword contents match the spec! */
2497 for (keyword_length = 0;
2498 keyword_length < length && buffer[keyword_length] != 0;
2499 ++keyword_length)
2500 /* Empty loop to find end of name */ ;
2501
2502 if (keyword_length > 79 || keyword_length < 1)
2503 errmsg = "bad keyword";
2504
2505 /* zTXt must have some LZ data after the keyword, although it may expand to
2506 * zero bytes; we need a '\0' at the end of the keyword, the compression type
2507 * then the LZ data:
2508 */
2509 else if (keyword_length + 3 > length)
2510 errmsg = "truncated";
2511
2512 else if (buffer[keyword_length+1] != PNG_COMPRESSION_TYPE_BASE0)
2513 errmsg = "unknown compression type";
2514
2515 else
2516 {
2517 png_alloc_size_t uncompressed_length = PNG_SIZE_MAX((size_t)(-1));
2518
2519 /* TODO: at present png_decompress_chunk imposes a single application
2520 * level memory limit, this should be split to different values for iCCP
2521 * and text chunks.
2522 */
2523 if (png_decompress_chunkMOZ_PNG_decomp_chunk(png_ptr, length, keyword_length+2,
2524 &uncompressed_length, 1/*terminate*/) == Z_STREAM_END1)
2525 {
2526 png_text text;
2527
2528 if (png_ptr->read_buffer == NULL((void*)0))
2529 errmsg="Read failure in png_handle_zTXt";
2530 else
2531 {
2532 /* It worked; png_ptr->read_buffer now looks like a tEXt chunk
2533 * except for the extra compression type byte and the fact that
2534 * it isn't necessarily '\0' terminated.
2535 */
2536 buffer = png_ptr->read_buffer;
2537 buffer[uncompressed_length+(keyword_length+2)] = 0;
2538
2539 text.compression = PNG_TEXT_COMPRESSION_zTXt0;
2540 text.key = (png_charp)buffer;
2541 text.text = (png_charp)(buffer + keyword_length+2);
2542 text.text_length = uncompressed_length;
2543 text.itxt_length = 0;
2544 text.lang = NULL((void*)0);
2545 text.lang_key = NULL((void*)0);
2546
2547 if (png_set_text_2MOZ_PNG_set_text_2(png_ptr, info_ptr, &text, 1) == 0)
2548 return handled_ok;
2549
2550 errmsg = "out of memory";
2551 }
2552 }
2553
2554 else
2555 errmsg = png_ptr->zstream.msg;
2556 }
2557
2558 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, errmsg);
2559 return handled_error;
2560}
2561#else
2562# define png_handle_zTXt((void*)0) NULL((void*)0)
2563#endif
2564
2565#ifdef PNG_READ_iTXt_SUPPORTED
2566/* Note: this does not correctly handle chunks that are > 64K under DOS */
2567static png_handle_result_code /* PRIVATE */
2568png_handle_iTXt((void*)0)(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2569{
2570 png_const_charp errmsg = NULL((void*)0);
2571 png_bytep buffer;
2572 png_uint_32 prefix_length;
2573
2574 png_debug(1, "in png_handle_iTXt")((void)0);
2575
2576#ifdef PNG_USER_LIMITS_SUPPORTED
2577 if (png_ptr->user_chunk_cache_max != 0)
2578 {
2579 if (png_ptr->user_chunk_cache_max == 1)
2580 {
2581 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2582 return handled_error;
2583 }
2584
2585 if (--png_ptr->user_chunk_cache_max == 1)
2586 {
2587 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2588 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "no space in chunk cache");
2589 return handled_error;
2590 }
2591 }
2592#endif
2593
2594 buffer = png_read_buffer(png_ptr, length+1);
2595
2596 if (buffer == NULL((void*)0))
2597 {
2598 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2599 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "out of memory");
2600 return handled_error;
2601 }
2602
2603 png_crc_readMOZ_PNG_crc_read(png_ptr, buffer, length);
2604
2605 if (png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0) != 0)
2606 return handled_error;
2607
2608 /* First the keyword. */
2609 for (prefix_length=0;
2610 prefix_length < length && buffer[prefix_length] != 0;
2611 ++prefix_length)
2612 /* Empty loop */ ;
2613
2614 /* Perform a basic check on the keyword length here. */
2615 if (prefix_length > 79 || prefix_length < 1)
2616 errmsg = "bad keyword";
2617
2618 /* Expect keyword, compression flag, compression type, language, translated
2619 * keyword (both may be empty but are 0 terminated) then the text, which may
2620 * be empty.
2621 */
2622 else if (prefix_length + 5 > length)
2623 errmsg = "truncated";
2624
2625 else if (buffer[prefix_length+1] == 0 ||
2626 (buffer[prefix_length+1] == 1 &&
2627 buffer[prefix_length+2] == PNG_COMPRESSION_TYPE_BASE0))
2628 {
2629 int compressed = buffer[prefix_length+1] != 0;
2630 png_uint_32 language_offset, translated_keyword_offset;
2631 png_alloc_size_t uncompressed_length = 0;
2632
2633 /* Now the language tag */
2634 prefix_length += 3;
2635 language_offset = prefix_length;
2636
2637 for (; prefix_length < length && buffer[prefix_length] != 0;
2638 ++prefix_length)
2639 /* Empty loop */ ;
2640
2641 /* WARNING: the length may be invalid here, this is checked below. */
2642 translated_keyword_offset = ++prefix_length;
2643
2644 for (; prefix_length < length && buffer[prefix_length] != 0;
2645 ++prefix_length)
2646 /* Empty loop */ ;
2647
2648 /* prefix_length should now be at the trailing '\0' of the translated
2649 * keyword, but it may already be over the end. None of this arithmetic
2650 * can overflow because chunks are at most 2^31 bytes long, but on 16-bit
2651 * systems the available allocation may overflow.
2652 */
2653 ++prefix_length;
2654
2655 if (compressed == 0 && prefix_length <= length)
2656 uncompressed_length = length - prefix_length;
2657
2658 else if (compressed != 0 && prefix_length < length)
2659 {
2660 uncompressed_length = PNG_SIZE_MAX((size_t)(-1));
2661
2662 /* TODO: at present png_decompress_chunk imposes a single application
2663 * level memory limit, this should be split to different values for
2664 * iCCP and text chunks.
2665 */
2666 if (png_decompress_chunkMOZ_PNG_decomp_chunk(png_ptr, length, prefix_length,
2667 &uncompressed_length, 1/*terminate*/) == Z_STREAM_END1)
2668 buffer = png_ptr->read_buffer;
2669
2670 else
2671 errmsg = png_ptr->zstream.msg;
2672 }
2673
2674 else
2675 errmsg = "truncated";
2676
2677 if (errmsg == NULL((void*)0))
2678 {
2679 png_text text;
2680
2681 buffer[uncompressed_length+prefix_length] = 0;
2682
2683 if (compressed == 0)
2684 text.compression = PNG_ITXT_COMPRESSION_NONE1;
2685
2686 else
2687 text.compression = PNG_ITXT_COMPRESSION_zTXt2;
2688
2689 text.key = (png_charp)buffer;
2690 text.lang = (png_charp)buffer + language_offset;
2691 text.lang_key = (png_charp)buffer + translated_keyword_offset;
2692 text.text = (png_charp)buffer + prefix_length;
2693 text.text_length = 0;
2694 text.itxt_length = uncompressed_length;
2695
2696 if (png_set_text_2MOZ_PNG_set_text_2(png_ptr, info_ptr, &text, 1) == 0)
2697 return handled_ok;
2698
2699 errmsg = "out of memory";
2700 }
2701 }
2702
2703 else
2704 errmsg = "bad compression info";
2705
2706 if (errmsg != NULL((void*)0))
2707 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, errmsg);
2708 return handled_error;
2709}
2710#else
2711# define png_handle_iTXt((void*)0) NULL((void*)0)
2712#endif
2713
2714#ifdef PNG_READ_APNG_SUPPORTED
2715void /* PRIVATE */
2716png_handle_acTL((void*)0)(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
2717{
2718 png_byte data[8];
2719 png_uint_32 num_frames;
2720 png_uint_32 num_plays;
2721 png_uint_32 didSet;
2722
2723 png_debug(1, "in png_handle_acTL")((void)0);
2724
2725 if ((png_ptr->mode & PNG_HAVE_IHDR0x01) == 0)
2726 {
2727 png_error(png_ptr, "Missing IHDR before acTL");
2728 }
2729 else if ((png_ptr->mode & PNG_HAVE_IDAT0x04U) != 0)
2730 {
2731 png_warningMOZ_PNG_warning(png_ptr, "Invalid acTL after IDAT skipped");
2732 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2733 return;
2734 }
2735 else if ((png_ptr->mode & PNG_HAVE_acTL0x10000U) != 0)
2736 {
2737 png_warningMOZ_PNG_warning(png_ptr, "Duplicate acTL skipped");
2738 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2739 return;
2740 }
2741 else if (length != 8)
2742 {
2743 png_warningMOZ_PNG_warning(png_ptr, "acTL with invalid length skipped");
2744 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2745 return;
2746 }
2747
2748 png_crc_readMOZ_PNG_crc_read(png_ptr, data, 8);
2749 png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0);
2750
2751 num_frames = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, data);
2752 num_plays = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, data + 4);
2753
2754 /* the set function will do error checking on num_frames */
2755 didSet = png_set_acTLMOZ_APNG_set_acTL(png_ptr, info_ptr, num_frames, num_plays);
2756 if (didSet != 0)
2757 png_ptr->mode |= PNG_HAVE_acTL0x10000U;
2758}
2759
2760void /* PRIVATE */
2761png_handle_fcTL((void*)0)(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
2762{
2763 png_byte data[22];
2764 png_uint_32 width;
2765 png_uint_32 height;
2766 png_uint_32 x_offset;
2767 png_uint_32 y_offset;
2768 png_uint_16 delay_num;
2769 png_uint_16 delay_den;
2770 png_byte dispose_op;
2771 png_byte blend_op;
2772
2773 png_debug(1, "in png_handle_fcTL")((void)0);
2774
2775 png_ensure_sequence_numberMOZ_APNG_ensure_seqno(png_ptr, length);
2776
2777 if ((png_ptr->mode & PNG_HAVE_IHDR0x01) == 0)
2778 {
2779 png_error(png_ptr, "Missing IHDR before fcTL");
2780 }
2781 else if ((png_ptr->mode & PNG_HAVE_IDAT0x04U) != 0)
2782 {
2783 /* for any frames other then the first this message may be misleading,
2784 * but correct. PNG_HAVE_IDAT is unset before the frame head is read
2785 * i can't think of a better message */
2786 png_warningMOZ_PNG_warning(png_ptr, "Invalid fcTL after IDAT skipped");
2787 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length-4);
2788 return;
2789 }
2790 else if ((png_ptr->mode & PNG_HAVE_fcTL0x20000U) != 0)
2791 {
2792 png_warningMOZ_PNG_warning(png_ptr, "Duplicate fcTL within one frame skipped");
2793 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length-4);
2794 return;
2795 }
2796 else if (length != 26)
2797 {
2798 png_warningMOZ_PNG_warning(png_ptr, "fcTL with invalid length skipped");
2799 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length-4);
2800 return;
2801 }
2802
2803 png_crc_readMOZ_PNG_crc_read(png_ptr, data, 22);
2804 png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0);
2805
2806 width = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, data);
2807 height = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, data + 4);
2808 x_offset = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, data + 8);
2809 y_offset = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, data + 12);
2810 delay_num = png_get_uint_16(data + 16)((png_uint_16) (((unsigned int)(*(data + 16)) << 8) + (
(unsigned int)(*((data + 16) + 1)))))
;
2811 delay_den = png_get_uint_16(data + 18)((png_uint_16) (((unsigned int)(*(data + 18)) << 8) + (
(unsigned int)(*((data + 18) + 1)))))
;
2812 dispose_op = data[20];
2813 blend_op = data[21];
2814
2815 if (png_ptr->num_frames_read == 0 && (x_offset != 0 || y_offset != 0))
2816 {
2817 png_warningMOZ_PNG_warning(png_ptr, "fcTL for the first frame must have zero offset");
2818 return;
2819 }
2820
2821 if (info_ptr != NULL((void*)0))
2822 {
2823 if (png_ptr->num_frames_read == 0 &&
2824 (width != info_ptr->width || height != info_ptr->height))
2825 {
2826 png_warningMOZ_PNG_warning(png_ptr, "size in first frame's fcTL must match "
2827 "the size in IHDR");
2828 return;
2829 }
2830
2831 /* The set function will do more error checking */
2832 png_set_next_frame_fcTLMOZ_APNG_set_next_frame_fcTL(png_ptr, info_ptr, width, height,
2833 x_offset, y_offset, delay_num, delay_den,
2834 dispose_op, blend_op);
2835
2836 png_read_reinitMOZ_APNG_read_reinit(png_ptr, info_ptr);
2837
2838 png_ptr->mode |= PNG_HAVE_fcTL0x20000U;
2839 }
2840}
2841
2842void /* PRIVATE */
2843png_have_infoMOZ_APNG_have_info(png_structp png_ptr, png_infop info_ptr)
2844{
2845 if ((info_ptr->valid & PNG_INFO_acTL0x100000U) != 0 &&
2846 (info_ptr->valid & PNG_INFO_fcTL0x200000U) == 0)
2847 {
2848 png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN0x0001U;
2849 info_ptr->num_frames++;
2850 }
2851}
2852
2853void /* PRIVATE */
2854png_handle_fdAT((void*)0)(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
2855{
2856 png_ensure_sequence_numberMOZ_APNG_ensure_seqno(png_ptr, length);
2857
2858 /* This function is only called from png_read_end(), png_read_info(),
2859 * and png_push_read_chunk() which means that:
2860 * - the user doesn't want to read this frame
2861 * - or this is an out-of-place fdAT
2862 * in either case it is safe to ignore the chunk with a warning */
2863 png_warningMOZ_PNG_warning(png_ptr, "ignoring fdAT chunk");
2864 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length - 4);
2865 PNG_UNUSED(info_ptr)(void)info_ptr;
2866}
2867
2868void /* PRIVATE */
2869png_ensure_sequence_numberMOZ_APNG_ensure_seqno(png_structp png_ptr, png_uint_32 length)
2870{
2871 png_byte data[4];
2872 png_uint_32 sequence_number;
2873
2874 if (length < 4)
2875 png_error(png_ptr, "invalid fcTL or fdAT chunk found");
2876
2877 png_crc_readMOZ_PNG_crc_read(png_ptr, data, 4);
2878 sequence_number = png_get_uint_31MOZ_PNG_get_uint_31(png_ptr, data);
2879
2880 if (sequence_number != png_ptr->next_seq_num)
2881 png_error(png_ptr, "fcTL or fdAT chunk with out-of-order sequence "
2882 "number found");
2883
2884 png_ptr->next_seq_num++;
2885}
2886#endif /* READ_APNG */
2887
2888#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
2889/* Utility function for png_handle_unknown; set up png_ptr::unknown_chunk */
2890static int
2891png_cache_unknown_chunk(png_structrp png_ptr, png_uint_32 length)
2892{
2893 const png_alloc_size_t limit = png_chunk_max(png_ptr)((png_ptr)->user_chunk_malloc_max);
2894
2895 if (png_ptr->unknown_chunk.data != NULL((void*)0))
2896 {
2897 png_freeMOZ_PNG_free(png_ptr, png_ptr->unknown_chunk.data);
2898 png_ptr->unknown_chunk.data = NULL((void*)0);
2899 }
2900
2901 if (length <= limit)
2902 {
2903 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)
;
2904 /* The following is safe because of the PNG_SIZE_MAX init above */
2905 png_ptr->unknown_chunk.size = (size_t)length/*SAFE*/;
2906 /* 'mode' is a flag array, only the bottom four bits matter here */
2907 png_ptr->unknown_chunk.location = (png_byte)png_ptr->mode/*SAFE*/;
2908
2909 if (length == 0)
2910 png_ptr->unknown_chunk.data = NULL((void*)0);
2911
2912 else
2913 {
2914 /* Do a 'warn' here - it is handled below. */
2915 png_ptr->unknown_chunk.data = png_voidcast(png_bytep,(MOZ_PNG_malloc_warn(png_ptr, length))
2916 png_malloc_warn(png_ptr, length))(MOZ_PNG_malloc_warn(png_ptr, length));
2917 }
2918 }
2919
2920 if (png_ptr->unknown_chunk.data == NULL((void*)0) && length > 0)
2921 {
2922 /* This is benign because we clean up correctly */
2923 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
2924 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "unknown chunk exceeds memory limits");
2925 return 0;
2926 }
2927
2928 else
2929 {
2930 if (length > 0)
2931 png_crc_readMOZ_PNG_crc_read(png_ptr, png_ptr->unknown_chunk.data, length);
2932 png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0);
2933 return 1;
2934 }
2935}
2936#endif /* READ_UNKNOWN_CHUNKS */
2937
2938/* Handle an unknown, or known but disabled, chunk */
2939png_handle_result_code /*PRIVATE*/
2940png_handle_unknownMOZ_PNG_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
2941 png_uint_32 length, int keep)
2942{
2943 png_handle_result_code handled = handled_discarded; /* the default */
2944
2945 png_debug(1, "in png_handle_unknown")((void)0);
2946
2947#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
2948 /* NOTE: this code is based on the code in libpng-1.4.12 except for fixing
2949 * the bug which meant that setting a non-default behavior for a specific
2950 * chunk would be ignored (the default was always used unless a user
2951 * callback was installed).
2952 *
2953 * 'keep' is the value from the png_chunk_unknown_handling, the setting for
2954 * this specific chunk_name, if PNG_HANDLE_AS_UNKNOWN_SUPPORTED, if not it
2955 * will always be PNG_HANDLE_CHUNK_AS_DEFAULT and it needs to be set here.
2956 * This is just an optimization to avoid multiple calls to the lookup
2957 * function.
2958 */
2959# ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
2960# ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
2961 keep = png_chunk_unknown_handlingMOZ_PNG_chunk_unk_handling(png_ptr, png_ptr->chunk_name);
2962# endif
2963# endif
2964
2965 /* One of the following methods will read the chunk or skip it (at least one
2966 * of these is always defined because this is the only way to switch on
2967 * PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
2968 */
2969# ifdef PNG_READ_USER_CHUNKS_SUPPORTED
2970 /* The user callback takes precedence over the chunk keep value, but the
2971 * keep value is still required to validate a save of a critical chunk.
2972 */
2973 if (png_ptr->read_user_chunk_fn != NULL((void*)0))
2974 {
2975 if (png_cache_unknown_chunk(png_ptr, length) != 0)
2976 {
2977 /* Callback to user unknown chunk handler */
2978 int ret = (*(png_ptr->read_user_chunk_fn))(png_ptr,
2979 &png_ptr->unknown_chunk);
2980
2981 /* ret is:
2982 * negative: An error occurred; png_chunk_error will be called.
2983 * zero: The chunk was not handled, the chunk will be discarded
2984 * unless png_set_keep_unknown_chunks has been used to set
2985 * a 'keep' behavior for this particular chunk, in which
2986 * case that will be used. A critical chunk will cause an
2987 * error at this point unless it is to be saved.
2988 * positive: The chunk was handled, libpng will ignore/discard it.
2989 */
2990 if (ret < 0) /* handled_error */
2991 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, "error in user chunk");
2992
2993 else if (ret == 0)
2994 {
2995 /* If the keep value is 'default' or 'never' override it, but
2996 * still error out on critical chunks unless the keep value is
2997 * 'always' While this is weird it is the behavior in 1.4.12.
2998 * A possible improvement would be to obey the value set for the
2999 * chunk, but this would be an API change that would probably
3000 * damage some applications.
3001 *
3002 * The png_app_warning below catches the case that matters, where
3003 * the application has not set specific save or ignore for this
3004 * chunk or global save or ignore.
3005 */
3006 if (keep < PNG_HANDLE_CHUNK_IF_SAFE2)
3007 {
3008# ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
3009 if (png_ptr->unknown_default < PNG_HANDLE_CHUNK_IF_SAFE2)
3010 {
3011 png_chunk_warningMOZ_PNG_chunk_warn(png_ptr, "Saving unknown chunk:");
3012 png_app_warningMOZ_PNG_app_warn(png_ptr,
3013 "forcing save of an unhandled chunk;"
3014 " please call png_set_keep_unknown_chunks");
3015 /* with keep = PNG_HANDLE_CHUNK_IF_SAFE */
3016 }
3017# endif
3018 keep = PNG_HANDLE_CHUNK_IF_SAFE2;
3019 }
3020 }
3021
3022 else /* chunk was handled */
3023 {
3024 handled = handled_ok;
3025 /* Critical chunks can be safely discarded at this point. */
3026 keep = PNG_HANDLE_CHUNK_NEVER1;
3027 }
3028 }
3029
3030 else
3031 keep = PNG_HANDLE_CHUNK_NEVER1; /* insufficient memory */
3032 }
3033
3034 else
3035 /* Use the SAVE_UNKNOWN_CHUNKS code or skip the chunk */
3036# endif /* READ_USER_CHUNKS */
3037
3038# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
3039 {
3040 /* keep is currently just the per-chunk setting, if there was no
3041 * setting change it to the global default now (not that this may
3042 * still be AS_DEFAULT) then obtain the cache of the chunk if required,
3043 * if not simply skip the chunk.
3044 */
3045 if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT0)
3046 keep = png_ptr->unknown_default;
3047
3048 if (keep == PNG_HANDLE_CHUNK_ALWAYS3 ||
3049 (keep == PNG_HANDLE_CHUNK_IF_SAFE2 &&
3050 PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)(1 & ((png_ptr->chunk_name) >> 29))))
3051 {
3052 if (png_cache_unknown_chunk(png_ptr, length) == 0)
3053 keep = PNG_HANDLE_CHUNK_NEVER1;
3054 }
3055
3056 else
3057 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
3058 }
3059# else
3060# ifndef PNG_READ_USER_CHUNKS_SUPPORTED
3061# error no method to support READ_UNKNOWN_CHUNKS
3062# endif
3063
3064 {
3065 /* If here there is no read callback pointer set and no support is
3066 * compiled in to just save the unknown chunks, so simply skip this
3067 * chunk. If 'keep' is something other than AS_DEFAULT or NEVER then
3068 * the app has erroneously asked for unknown chunk saving when there
3069 * is no support.
3070 */
3071 if (keep > PNG_HANDLE_CHUNK_NEVER1)
3072 png_app_errorMOZ_PNG_app_err(png_ptr, "no unknown chunk support available");
3073
3074 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
3075 }
3076# endif
3077
3078# ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
3079 /* Now store the chunk in the chunk list if appropriate, and if the limits
3080 * permit it.
3081 */
3082 if (keep == PNG_HANDLE_CHUNK_ALWAYS3 ||
3083 (keep == PNG_HANDLE_CHUNK_IF_SAFE2 &&
3084 PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)(1 & ((png_ptr->chunk_name) >> 29))))
3085 {
3086# ifdef PNG_USER_LIMITS_SUPPORTED
3087 switch (png_ptr->user_chunk_cache_max)
3088 {
3089 case 2:
3090 png_ptr->user_chunk_cache_max = 1;
3091 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "no space in chunk cache");
3092 /* FALLTHROUGH */
3093 case 1:
3094 /* NOTE: prior to 1.6.0 this case resulted in an unknown critical
3095 * chunk being skipped, now there will be a hard error below.
3096 */
3097 break;
3098
3099 default: /* not at limit */
3100 --(png_ptr->user_chunk_cache_max);
3101 /* FALLTHROUGH */
3102 case 0: /* no limit */
3103# endif /* USER_LIMITS */
3104 /* Here when the limit isn't reached or when limits are compiled
3105 * out; store the chunk.
3106 */
3107 png_set_unknown_chunksMOZ_PNG_set_unknown_chunks(png_ptr, info_ptr,
3108 &png_ptr->unknown_chunk, 1);
3109 handled = handled_saved;
3110# ifdef PNG_USER_LIMITS_SUPPORTED
3111 break;
3112 }
3113# endif
3114 }
3115# else /* no store support: the chunk must be handled by the user callback */
3116 PNG_UNUSED(info_ptr)(void)info_ptr;
3117# endif
3118
3119 /* Regardless of the error handling below the cached data (if any) can be
3120 * freed now. Notice that the data is not freed if there is a png_error, but
3121 * it will be freed by destroy_read_struct.
3122 */
3123 if (png_ptr->unknown_chunk.data != NULL((void*)0))
3124 png_freeMOZ_PNG_free(png_ptr, png_ptr->unknown_chunk.data);
3125 png_ptr->unknown_chunk.data = NULL((void*)0);
3126
3127#else /* !PNG_READ_UNKNOWN_CHUNKS_SUPPORTED */
3128 /* There is no support to read an unknown chunk, so just skip it. */
3129 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
3130 PNG_UNUSED(info_ptr)(void)info_ptr;
3131 PNG_UNUSED(keep)(void)keep;
3132#endif /* !READ_UNKNOWN_CHUNKS */
3133
3134 /* Check for unhandled critical chunks */
3135 if (handled < handled_saved && PNG_CHUNK_CRITICAL(png_ptr->chunk_name)(!(1 & ((png_ptr->chunk_name) >> 29))))
3136 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, "unhandled critical chunk");
3137
3138 return handled;
3139}
3140
3141/* APNG handling: the minimal implementation of APNG handling in libpng 1.6
3142 * requires that those significant applications which already handle APNG not
3143 * get hosed. To do this ensure the code here will have to ensure than APNG
3144 * data by default (at least in 1.6) gets stored in the unknown chunk list.
3145 * Maybe this can be relaxed in a few years but at present it's just the only
3146 * safe way.
3147 *
3148 * ATM just cause unknown handling for all three chunks:
3149 */
3150#define png_handle_acTL((void*)0) NULL((void*)0)
3151#define png_handle_fcTL((void*)0) NULL((void*)0)
3152#define png_handle_fdAT((void*)0) NULL((void*)0)
3153
3154/*
3155 * 1.6.47: This is the new table driven interface to all the chunk handling.
3156 *
3157 * The table describes the PNG standard rules for **reading** known chunks -
3158 * every chunk which has an entry in PNG_KNOWN_CHUNKS. The table contains an
3159 * entry for each PNG_INDEX_cHNK describing the rules.
3160 *
3161 * In this initial version the only information in the entry is the
3162 * png_handle_cHNK function for the chunk in question. When chunk support is
3163 * compiled out the entry will be NULL.
3164 */
3165static const struct
3166{
3167 png_handle_result_code (*handler)(
3168 png_structrp, png_inforp, png_uint_32 length);
3169 /* A chunk-specific 'handler', NULL if the chunk is not supported in this
3170 * build.
3171 */
3172
3173 /* Crushing these values helps on modern 32-bit architectures because the
3174 * pointer and the following bit fields both end up requiring 32 bits.
3175 * Typically this will halve the table size. On 64-bit architectures the
3176 * table entries will typically be 8 bytes.
3177 */
3178 png_uint_32 max_length :12; /* Length min, max in bytes */
3179 png_uint_32 min_length :8;
3180 /* Length errors on critical chunks have special handling to preserve the
3181 * existing behaviour in libpng 1.6. Ancillary chunks are checked below
3182 * and produce a 'benign' error.
3183 */
3184 png_uint_32 pos_before :4; /* PNG_HAVE_ values chunk must precede */
3185 png_uint_32 pos_after :4; /* PNG_HAVE_ values chunk must follow */
3186 /* NOTE: PLTE, tRNS and bKGD require special handling which depends on
3187 * the colour type of the base image.
3188 */
3189 png_uint_32 multiple :1; /* Multiple occurrences permitted */
3190 /* This is enabled for PLTE because PLTE may, in practice, be optional */
3191}
3192read_chunks[PNG_INDEX_unknown] =
3193{
3194 /* Definitions as above but done indirectly by #define so that
3195 * PNG_KNOWN_CHUNKS can be used safely to build the table in order.
3196 *
3197 * Each CDcHNK definition lists the values for the parameters **after**
3198 * the first, 'handler', function. 'handler' is NULL when the chunk has no
3199 * compiled in support.
3200 */
3201# define NoCheck0x801U 0x801U /* Do not check the maximum length */
3202# define Limit0x802U 0x802U /* Limit to png_chunk_max bytes */
3203# define LKMin3U+(2U+5U+4U) 3U+LZ77Min(2U+5U+4U) /* Minimum length of keyword+LZ77 */
3204
3205#define hIHDR0x01 PNG_HAVE_IHDR0x01
3206#define hPLTE0x02 PNG_HAVE_PLTE0x02
3207#define hIDAT0x04U PNG_HAVE_IDAT0x04U
3208 /* For the two chunks, tRNS and bKGD which can occur in PNGs without a PLTE
3209 * but must occur after the PLTE use this and put the check in the handler
3210 * routine for colour mapped images were PLTE is required. Also put a check
3211 * in PLTE for other image types to drop the PLTE if tRNS or bKGD have been
3212 * seen.
3213 */
3214#define hCOL(0x02|0x04U) (PNG_HAVE_PLTE0x02|PNG_HAVE_IDAT0x04U)
3215 /* Used for the decoding chunks which must be before PLTE. */
3216#define aIDAT0x08 PNG_AFTER_IDAT0x08
3217
3218 /* Chunks from W3C PNG v3: */
3219 /* cHNK max_len, min, before, after, multiple */
3220# define CDIHDR13U, 13U, 0x01, 0, 0 13U, 13U, hIHDR0x01, 0, 0
3221# define CDPLTE0x801U, 0U, 0, 0x01, 1 NoCheck0x801U, 0U, 0, hIHDR0x01, 1
3222 /* PLTE errors are only critical for colour-map images, consequently the
3223 * handler does all the checks.
3224 */
3225# define CDIDAT0x801U, 0U, 0x08, 0x01, 1 NoCheck0x801U, 0U, aIDAT0x08, hIHDR0x01, 1
3226# define CDIEND0x801U, 0U, 0, 0x08, 0 NoCheck0x801U, 0U, 0, aIDAT0x08, 0
3227 /* Historically data was allowed in IEND */
3228# define CDtRNS256U, 0U, 0x04U, 0x01, 0 256U, 0U, hIDAT0x04U, hIHDR0x01, 0
3229# define CDcHRM32U, 32U, (0x02|0x04U), 0x01, 0 32U, 32U, hCOL(0x02|0x04U), hIHDR0x01, 0
3230# define CDgAMA4U, 4U, (0x02|0x04U), 0x01, 0 4U, 4U, hCOL(0x02|0x04U), hIHDR0x01, 0
3231# define CDiCCP0x801U, 3U+(2U+5U+4U), (0x02|0x04U), 0x01, 0 NoCheck0x801U, LKMin3U+(2U+5U+4U), hCOL(0x02|0x04U), hIHDR0x01, 0
3232# define CDsBIT4U, 1U, (0x02|0x04U), 0x01, 0 4U, 1U, hCOL(0x02|0x04U), hIHDR0x01, 0
3233# define CDsRGB1U, 1U, (0x02|0x04U), 0x01, 0 1U, 1U, hCOL(0x02|0x04U), hIHDR0x01, 0
3234# define CDcICP4U, 4U, (0x02|0x04U), 0x01, 0 4U, 4U, hCOL(0x02|0x04U), hIHDR0x01, 0
3235# define CDmDCV24U, 24U, (0x02|0x04U), 0x01, 0 24U, 24U, hCOL(0x02|0x04U), hIHDR0x01, 0
3236# define CDeXIf0x802U, 4U, 0, 0x01, 0 Limit0x802U, 4U, 0, hIHDR0x01, 0
3237# define CDcLLI8U, 8U, (0x02|0x04U), 0x01, 0 8U, 8U, hCOL(0x02|0x04U), hIHDR0x01, 0
3238# define CDtEXt0x801U, 2U, 0, 0x01, 1 NoCheck0x801U, 2U, 0, hIHDR0x01, 1
3239 /* Allocates 'length+1'; checked in the handler */
3240# define CDzTXt0x802U, 3U+(2U+5U+4U), 0, 0x01, 1 Limit0x802U, LKMin3U+(2U+5U+4U), 0, hIHDR0x01, 1
3241# define CDiTXt0x801U, 6U, 0, 0x01, 1 NoCheck0x801U, 6U, 0, hIHDR0x01, 1
3242 /* Allocates 'length+1'; checked in the handler */
3243# define CDbKGD6U, 1U, 0x04U, 0x01, 0 6U, 1U, hIDAT0x04U, hIHDR0x01, 0
3244# define CDhIST1024U, 0U, 0x02, 0x01, 0 1024U, 0U, hPLTE0x02, hIHDR0x01, 0
3245# define CDpHYs9U, 9U, 0x04U, 0x01, 0 9U, 9U, hIDAT0x04U, hIHDR0x01, 0
3246# define CDsPLT0x801U, 3U, 0x04U, 0x01, 1 NoCheck0x801U, 3U, hIDAT0x04U, hIHDR0x01, 1
3247 /* Allocates 'length+1'; checked in the handler */
3248# define CDtIME7U, 7U, 0, 0x01, 0 7U, 7U, 0, hIHDR0x01, 0
3249# define CDacTL8U, 8U, 0x04U, 0x01, 0 8U, 8U, hIDAT0x04U, hIHDR0x01, 0
3250# define CDfcTL25U, 26U, 0, 0x01, 1 25U, 26U, 0, hIHDR0x01, 1
3251# define CDfdAT0x802U, 4U, 0x04U, 0x01, 1 Limit0x802U, 4U, hIDAT0x04U, hIHDR0x01, 1
3252 /* Supported chunks from PNG extensions 1.5.0, NYI so limit */
3253# define CDoFFs9U, 9U, 0x04U, 0x01, 0 9U, 9U, hIDAT0x04U, hIHDR0x01, 0
3254# define CDpCAL0x801U, 14U, 0x04U, 0x01, 0 NoCheck0x801U, 14U, hIDAT0x04U, hIHDR0x01, 0
3255 /* Allocates 'length+1'; checked in the handler */
3256# define CDsCAL0x802U, 4U, 0x04U, 0x01, 0 Limit0x802U, 4U, hIDAT0x04U, hIHDR0x01, 0
3257 /* Allocates 'length+1'; checked in the handler */
3258
3259# define PNG_CHUNK(cHNK, index) { png_handle_ ## cHNK, CD ## cHNK },
3260 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)
3261# undef PNG_CHUNK
3262};
3263
3264
3265static png_index
3266png_chunk_index_from_name(png_uint_32 chunk_name)
3267{
3268 /* For chunk png_cHNK return PNG_INDEX_cHNK. Return PNG_INDEX_unknown if
3269 * chunk_name is not known. Notice that in a particular build "known" does
3270 * not necessarily mean "supported", although the inverse applies.
3271 */
3272 switch (chunk_name)
3273 {
3274# define PNG_CHUNK(cHNK, index)\
3275 case png_ ## cHNK: return PNG_INDEX_ ## cHNK; /* == index */
3276
3277 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)
3278
3279# undef PNG_CHUNK
3280
3281 default: return PNG_INDEX_unknown;
3282 }
3283}
3284
3285png_handle_result_code /*PRIVATE*/
3286png_handle_chunk(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
3287{
3288 /* CSE: these things don't change, these autos are just to save typing and
3289 * make the code more clear.
3290 */
3291 const png_uint_32 chunk_name = png_ptr->chunk_name;
3292 const png_index chunk_index = png_chunk_index_from_name(chunk_name);
3293
3294 png_handle_result_code handled = handled_error;
3295 png_const_charp errmsg = NULL((void*)0);
3296
3297 /* Is this a known chunk? If not there are no checks performed here;
3298 * png_handle_unknown does the correct checks. This means that the values
3299 * for known but unsupported chunks in the above table are not used here
3300 * however the chunks_seen fields in png_struct are still set.
3301 */
3302 if (chunk_index == PNG_INDEX_unknown ||
3303 read_chunks[chunk_index].handler == NULL((void*)0))
3304 {
3305 handled = png_handle_unknownMOZ_PNG_handle_unknown(
3306 png_ptr, info_ptr, length, PNG_HANDLE_CHUNK_AS_DEFAULT0);
3307 }
3308
3309 /* First check the position. The first check is historical; the stream must
3310 * start with IHDR and anything else causes libpng to give up immediately.
3311 */
3312 else if (chunk_index != PNG_INDEX_IHDR &&
3313 (png_ptr->mode & PNG_HAVE_IHDR0x01) == 0)
3314 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, "missing IHDR"); /* NORETURN */
3315
3316 /* Before all the pos_before chunks, after all the pos_after chunks. */
3317 else if (((png_ptr->mode & read_chunks[chunk_index].pos_before) != 0) ||
3318 ((png_ptr->mode & read_chunks[chunk_index].pos_after) !=
3319 read_chunks[chunk_index].pos_after))
3320 {
3321 errmsg = "out of place";
3322 }
3323
3324 /* Now check for duplicates: duplicated critical chunks also produce a
3325 * full error.
3326 */
3327 else if (read_chunks[chunk_index].multiple == 0 &&
3328 png_file_has_chunk(png_ptr, chunk_index)(((png_ptr)->chunks & (0x80000000U >> (31 - (chunk_index
)))) != 0)
)
3329 {
3330 errmsg = "duplicate";
3331 }
3332
3333 else if (length < read_chunks[chunk_index].min_length)
3334 errmsg = "too short";
3335 else
3336 {
3337 /* NOTE: apart from IHDR the critical chunks (PLTE, IDAT and IEND) are set
3338 * up above not to do any length checks.
3339 *
3340 * The png_chunk_max check ensures that the variable length chunks are
3341 * always checked at this point for being within the system allocation
3342 * limits.
3343 */
3344 unsigned max_length = read_chunks[chunk_index].max_length;
3345
3346 switch (max_length)
3347 {
3348 case Limit0x802U:
3349 /* png_read_chunk_header has already png_error'ed chunks with a
3350 * length exceeding the 31-bit PNG limit, so just check the memory
3351 * limit:
3352 */
3353 if (length <= png_chunk_max(png_ptr)((png_ptr)->user_chunk_malloc_max))
3354 goto MeetsLimit;
3355
3356 errmsg = "length exceeds libpng limit";
3357 break;
3358
3359 default:
3360 if (length <= max_length)
3361 goto MeetsLimit;
3362
3363 errmsg = "too long";
3364 break;
3365
3366 case NoCheck0x801U:
3367 MeetsLimit:
3368 handled = read_chunks[chunk_index].handler(
3369 png_ptr, info_ptr, length);
3370 break;
3371 }
3372 }
3373
3374 /* If there was an error or the chunk was simply skipped it is not counted as
3375 * 'seen'.
3376 */
3377 if (errmsg != NULL((void*)0))
3378 {
3379 if (PNG_CHUNK_CRITICAL(chunk_name)(!(1 & ((chunk_name) >> 29)))) /* stop immediately */
3380 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, errmsg);
3381 else /* ancillary chunk */
3382 {
3383 /* The chunk data is skipped: */
3384 png_crc_finishMOZ_PNG_crc_finish(png_ptr, length);
3385 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, errmsg);
3386 }
3387 }
3388
3389 else if (handled >= handled_saved)
3390 {
3391 if (chunk_index != PNG_INDEX_unknown)
3392 png_file_add_chunk(png_ptr, chunk_index)((void)((png_ptr)->chunks |= (0x80000000U >> (31 - (
chunk_index)))))
;
3393 }
3394
3395 return handled;
3396}
3397
3398/* Combines the row recently read in with the existing pixels in the row. This
3399 * routine takes care of alpha and transparency if requested. This routine also
3400 * handles the two methods of progressive display of interlaced images,
3401 * depending on the 'display' value; if 'display' is true then the whole row
3402 * (dp) is filled from the start by replicating the available pixels. If
3403 * 'display' is false only those pixels present in the pass are filled in.
3404 */
3405void /* PRIVATE */
3406png_combine_rowMOZ_PNG_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
3407{
3408 unsigned int pixel_depth = png_ptr->transformed_pixel_depth;
3409 png_const_bytep sp = png_ptr->row_buf + 1;
3410 png_alloc_size_t row_width = png_ptr->width;
3411 unsigned int pass = png_ptr->pass;
3412 png_bytep end_ptr = 0;
3413 png_byte end_byte = 0;
3414 unsigned int end_mask;
3415
3416 png_debug(1, "in png_combine_row")((void)0);
3417
3418 /* Added in 1.5.6: it should not be possible to enter this routine until at
3419 * least one row has been read from the PNG data and transformed.
3420 */
3421 if (pixel_depth == 0)
3422 png_error(png_ptr, "internal row logic error");
3423
3424 /* Added in 1.5.4: the pixel depth should match the information returned by
3425 * any call to png_read_update_info at this point. Do not continue if we got
3426 * this wrong.
3427 */
3428 if (png_ptr->info_rowbytes != 0 && png_ptr->info_rowbytes !=
3429 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) )
)
3430 png_error(png_ptr, "internal row size calculation error");
3431
3432 /* Don't expect this to ever happen: */
3433 if (row_width == 0)
3434 png_error(png_ptr, "internal row width error");
3435
3436 /* Preserve the last byte in cases where only part of it will be overwritten,
3437 * the multiply below may overflow, we don't care because ANSI-C guarantees
3438 * we get the low bits.
3439 */
3440 end_mask = (pixel_depth * row_width) & 7;
3441 if (end_mask != 0)
3442 {
3443 /* end_ptr == NULL is a flag to say do nothing */
3444 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;
3445 end_byte = *end_ptr;
3446# ifdef PNG_READ_PACKSWAP_SUPPORTED
3447 if ((png_ptr->transformations & PNG_PACKSWAP0x10000U) != 0)
3448 /* little-endian byte */
3449 end_mask = (unsigned int)(0xff << end_mask);
3450
3451 else /* big-endian byte */
3452# endif
3453 end_mask = 0xff >> end_mask;
3454 /* end_mask is now the bits to *keep* from the destination row */
3455 }
3456
3457 /* For non-interlaced images this reduces to a memcpy(). A memcpy()
3458 * will also happen if interlacing isn't supported or if the application
3459 * does not call png_set_interlace_handling(). In the latter cases the
3460 * caller just gets a sequence of the unexpanded rows from each interlace
3461 * pass.
3462 */
3463#ifdef PNG_READ_INTERLACING_SUPPORTED
3464 if (png_ptr->interlaced != 0 &&
3465 (png_ptr->transformations & PNG_INTERLACE0x0002U) != 0 &&
3466 pass < 6 && (display == 0 ||
3467 /* The following copies everything for 'display' on passes 0, 2 and 4. */
3468 (display == 1 && (pass & 1) != 0)))
3469 {
3470 /* Narrow images may have no bits in a pass; the caller should handle
3471 * this, but this test is cheap:
3472 */
3473 if (row_width <= PNG_PASS_START_COL(pass)(((1& (pass))<<(3-(((pass)+1)>>1)))&7))
3474 return;
3475
3476 if (pixel_depth < 8)
3477 {
3478 /* For pixel depths up to 4 bpp the 8-pixel mask can be expanded to fit
3479 * into 32 bits, then a single loop over the bytes using the four byte
3480 * values in the 32-bit mask can be used. For the 'display' option the
3481 * expanded mask may also not require any masking within a byte. To
3482 * make this work the PACKSWAP option must be taken into account - it
3483 * simply requires the pixels to be reversed in each byte.
3484 *
3485 * The 'regular' case requires a mask for each of the first 6 passes,
3486 * the 'display' case does a copy for the even passes in the range
3487 * 0..6. This has already been handled in the test above.
3488 *
3489 * The masks are arranged as four bytes with the first byte to use in
3490 * the lowest bits (little-endian) regardless of the order (PACKSWAP or
3491 * not) of the pixels in each byte.
3492 *
3493 * NOTE: the whole of this logic depends on the caller of this function
3494 * only calling it on rows appropriate to the pass. This function only
3495 * understands the 'x' logic; the 'y' logic is handled by the caller.
3496 *
3497 * The following defines allow generation of compile time constant bit
3498 * masks for each pixel depth and each possibility of swapped or not
3499 * swapped bytes. Pass 'p' is in the range 0..6; 'x', a pixel index,
3500 * is in the range 0..7; and the result is 1 if the pixel is to be
3501 * copied in the pass, 0 if not. 'S' is for the sparkle method, 'B'
3502 * for the block method.
3503 *
3504 * With some compilers a compile time expression of the general form:
3505 *
3506 * (shift >= 32) ? (a >> (shift-32)) : (b >> shift)
3507 *
3508 * Produces warnings with values of 'shift' in the range 33 to 63
3509 * because the right hand side of the ?: expression is evaluated by
3510 * the compiler even though it isn't used. Microsoft Visual C (various
3511 * versions) and the Intel C compiler are known to do this. To avoid
3512 * this the following macros are used in 1.5.6. This is a temporary
3513 * solution to avoid destabilizing the code during the release process.
3514 */
3515# if PNG_USE_COMPILE_TIME_MASKS1
3516# define PNG_LSR(x,s)((x)>>((s) & 0x1f)) ((x)>>((s) & 0x1f))
3517# define PNG_LSL(x,s)((x)<<((s) & 0x1f)) ((x)<<((s) & 0x1f))
3518# else
3519# define PNG_LSR(x,s)((x)>>((s) & 0x1f)) ((x)>>(s))
3520# define PNG_LSL(x,s)((x)<<((s) & 0x1f)) ((x)<<(s))
3521# endif
3522# 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)) :\
3523 PNG_LSR(0xaa55ff00,(7-(p))*8+(7-(x)))((0xaa55ff00)>>(((7-(p))*8+(7-(x))) & 0x1f))) & 1)
3524# 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)) :\
3525 PNG_LSR(0xff55ff00,(7-(p))*8+(7-(x)))((0xff55ff00)>>(((7-(p))*8+(7-(x))) & 0x1f))) & 1)
3526
3527 /* Return a mask for pass 'p' pixel 'x' at depth 'd'. The mask is
3528 * little endian - the first pixel is at bit 0 - however the extra
3529 * parameter 's' can be set to cause the mask position to be swapped
3530 * within each byte, to match the PNG format. This is done by XOR of
3531 * the shift with 7, 6 or 4 for bit depths 1, 2 and 4.
3532 */
3533# define PIXEL_MASK(p,x,d,s)(((((((1U)<<(((d)) & 0x1f)))-1))<<(((((x)*(d)
)^((s)?8-(d):0))) & 0x1f)))
\
3534 (PNG_LSL(((PNG_LSL(1U,(d)))-1),(((x)*(d))^((s)?8-(d):0)))((((((1U)<<(((d)) & 0x1f)))-1))<<(((((x)*(d))
^((s)?8-(d):0))) & 0x1f))
)
3535
3536 /* Hence generate the appropriate 'block' or 'sparkle' pixel copy mask.
3537 */
3538# 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)
3539# 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)
3540
3541 /* Combine 8 of these to get the full mask. For the 1-bpp and 2-bpp
3542 * cases the result needs replicating, for the 4-bpp case the above
3543 * generates a full 32 bits.
3544 */
3545# define MASK_EXPAND(m,d)((m)*((d)==1?0x01010101:((d)==2?0x00010001:1))) ((m)*((d)==1?0x01010101:((d)==2?0x00010001:1)))
3546
3547# 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)))
3548 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)))
3549 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)))
3550
3551# 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)))
3552 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)))
3553 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)))
3554
3555#if PNG_USE_COMPILE_TIME_MASKS1
3556 /* Utility macros to construct all the masks for a depth/swap
3557 * combination. The 's' parameter says whether the format is PNG
3558 * (big endian bytes) or not. Only the three odd-numbered passes are
3559 * required for the display/block algorithm.
3560 */
3561# 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)))
,\
3562 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)))
}
3563
3564# 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)))
}
3565
3566# define DEPTH_INDEX(d)((d)==1?0:((d)==2?1:2)) ((d)==1?0:((d)==2?1:2))
3567
3568 /* Hence the pre-compiled masks indexed by PACKSWAP (or not), depth and
3569 * then pass:
3570 */
3571 static const png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] =
3572 {
3573 /* Little-endian byte masks for PACKSWAP */
3574 { 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))) }
},
3575 /* Normal (big-endian byte) masks - PNG format */
3576 { 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))) }
}
3577 };
3578
3579 /* display_mask has only three entries for the odd passes, so index by
3580 * pass>>1.
3581 */
3582 static const png_uint_32 display_mask[2][3][3] =
3583 {
3584 /* Little-endian byte masks for PACKSWAP */
3585 { 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))) }
},
3586 /* Normal (big-endian byte) masks - PNG format */
3587 { 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))) }
}
3588 };
3589
3590# 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])
\
3591 ((display)?display_mask[png][DEPTH_INDEX(depth)((depth)==1?0:((depth)==2?1:2))][pass>>1]:\
3592 row_mask[png][DEPTH_INDEX(depth)((depth)==1?0:((depth)==2?1:2))][pass])
3593
3594#else /* !PNG_USE_COMPILE_TIME_MASKS */
3595 /* This is the runtime alternative: it seems unlikely that this will
3596 * ever be either smaller or faster than the compile time approach.
3597 */
3598# 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])
\
3599 ((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)))
)
3600#endif /* !USE_COMPILE_TIME_MASKS */
3601
3602 /* Use the appropriate mask to copy the required bits. In some cases
3603 * the byte mask will be 0 or 0xff; optimize these cases. row_width is
3604 * the number of pixels, but the code copies bytes, so it is necessary
3605 * to special case the end.
3606 */
3607 png_uint_32 pixels_per_byte = 8 / pixel_depth;
3608 png_uint_32 mask;
3609
3610# ifdef PNG_READ_PACKSWAP_SUPPORTED
3611 if ((png_ptr->transformations & PNG_PACKSWAP0x10000U) != 0)
3612 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])
;
3613
3614 else
3615# endif
3616 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])
;
3617
3618 for (;;)
3619 {
3620 png_uint_32 m;
3621
3622 /* It doesn't matter in the following if png_uint_32 has more than
3623 * 32 bits because the high bits always match those in m<<24; it is,
3624 * however, essential to use OR here, not +, because of this.
3625 */
3626 m = mask;
3627 mask = (m >> 8) | (m << 24); /* rotate right to good compilers */
3628 m &= 0xff;
3629
3630 if (m != 0) /* something to copy */
3631 {
3632 if (m != 0xff)
3633 *dp = (png_byte)((*dp & ~m) | (*sp & m));
3634 else
3635 *dp = *sp;
3636 }
3637
3638 /* NOTE: this may overwrite the last byte with garbage if the image
3639 * is not an exact number of bytes wide; libpng has always done
3640 * this.
3641 */
3642 if (row_width <= pixels_per_byte)
3643 break; /* May need to restore part of the last byte */
3644
3645 row_width -= pixels_per_byte;
3646 ++dp;
3647 ++sp;
3648 }
3649 }
3650
3651 else /* pixel_depth >= 8 */
3652 {
3653 unsigned int bytes_to_copy, bytes_to_jump;
3654
3655 /* Validate the depth - it must be a multiple of 8 */
3656 if (pixel_depth & 7)
3657 png_error(png_ptr, "invalid user transform pixel depth");
3658
3659 pixel_depth >>= 3; /* now in bytes */
3660 row_width *= pixel_depth;
3661
3662 /* Regardless of pass number the Adam 7 interlace always results in a
3663 * fixed number of pixels to copy then to skip. There may be a
3664 * different number of pixels to skip at the start though.
3665 */
3666 {
3667 unsigned int offset = PNG_PASS_START_COL(pass)(((1& (pass))<<(3-(((pass)+1)>>1)))&7) * pixel_depth;
3668
3669 row_width -= offset;
3670 dp += offset;
3671 sp += offset;
3672 }
3673
3674 /* Work out the bytes to copy. */
3675 if (display != 0)
3676 {
3677 /* When doing the 'block' algorithm the pixel in the pass gets
3678 * replicated to adjacent pixels. This is why the even (0,2,4,6)
3679 * passes are skipped above - the entire expanded row is copied.
3680 */
3681 bytes_to_copy = (1<<((6-pass)>>1)) * pixel_depth;
3682
3683 /* But don't allow this number to exceed the actual row width. */
3684 if (bytes_to_copy > row_width)
3685 bytes_to_copy = (unsigned int)/*SAFE*/row_width;
3686 }
3687
3688 else /* normal row; Adam7 only ever gives us one pixel to copy. */
3689 bytes_to_copy = pixel_depth;
3690
3691 /* In Adam7 there is a constant offset between where the pixels go. */
3692 bytes_to_jump = PNG_PASS_COL_OFFSET(pass)(1<<((7-(pass))>>1)) * pixel_depth;
3693
3694 /* And simply copy these bytes. Some optimization is possible here,
3695 * depending on the value of 'bytes_to_copy'. Special case the low
3696 * byte counts, which we know to be frequent.
3697 *
3698 * Notice that these cases all 'return' rather than 'break' - this
3699 * avoids an unnecessary test on whether to restore the last byte
3700 * below.
3701 */
3702 switch (bytes_to_copy)
3703 {
3704 case 1:
3705 for (;;)
3706 {
3707 *dp = *sp;
3708
3709 if (row_width <= bytes_to_jump)
3710 return;
3711
3712 dp += bytes_to_jump;
3713 sp += bytes_to_jump;
3714 row_width -= bytes_to_jump;
3715 }
3716
3717 case 2:
3718 /* There is a possibility of a partial copy at the end here; this
3719 * slows the code down somewhat.
3720 */
3721 do
3722 {
3723 dp[0] = sp[0]; dp[1] = sp[1];
3724
3725 if (row_width <= bytes_to_jump)
3726 return;
3727
3728 sp += bytes_to_jump;
3729 dp += bytes_to_jump;
3730 row_width -= bytes_to_jump;
3731 }
3732 while (row_width > 1);
3733
3734 /* And there can only be one byte left at this point: */
3735 *dp = *sp;
3736 return;
3737
3738 case 3:
3739 /* This can only be the RGB case, so each copy is exactly one
3740 * pixel and it is not necessary to check for a partial copy.
3741 */
3742 for (;;)
3743 {
3744 dp[0] = sp[0]; dp[1] = sp[1]; dp[2] = sp[2];
3745
3746 if (row_width <= bytes_to_jump)
3747 return;
3748
3749 sp += bytes_to_jump;
3750 dp += bytes_to_jump;
3751 row_width -= bytes_to_jump;
3752 }
3753
3754 default:
3755#if PNG_ALIGN_TYPE3 != PNG_ALIGN_NONE0
3756 /* Check for double byte alignment and, if possible, use a
3757 * 16-bit copy. Don't attempt this for narrow images - ones that
3758 * are less than an interlace panel wide. Don't attempt it for
3759 * wide bytes_to_copy either - use the memcpy there.
3760 */
3761 if (bytes_to_copy < 16 /*else use memcpy*/ &&
3762 png_isaligned(dp, png_uint_16)(((png_uint_16)(size_t)((const void*)(dp)) & (png_uint_16
)((sizeof(png_uint_16))-1)) == 0)
&&
3763 png_isaligned(sp, png_uint_16)(((png_uint_16)(size_t)((const void*)(sp)) & (png_uint_16
)((sizeof(png_uint_16))-1)) == 0)
&&
3764 bytes_to_copy % (sizeof (png_uint_16)) == 0 &&
3765 bytes_to_jump % (sizeof (png_uint_16)) == 0)
3766 {
3767 /* Everything is aligned for png_uint_16 copies, but try for
3768 * png_uint_32 first.
3769 */
3770 if (png_isaligned(dp, png_uint_32)(((png_uint_32)(size_t)((const void*)(dp)) & (png_uint_32
)((sizeof(png_uint_32))-1)) == 0)
&&
3771 png_isaligned(sp, png_uint_32)(((png_uint_32)(size_t)((const void*)(sp)) & (png_uint_32
)((sizeof(png_uint_32))-1)) == 0)
&&
3772 bytes_to_copy % (sizeof (png_uint_32)) == 0 &&
3773 bytes_to_jump % (sizeof (png_uint_32)) == 0)
3774 {
3775 png_uint_32p dp32 = png_aligncast(png_uint_32p,dp)((void*)(dp));
3776 png_const_uint_32p sp32 = png_aligncastconst(((const void*)(sp))
3777 png_const_uint_32p, sp)((const void*)(sp));
3778 size_t skip = (bytes_to_jump-bytes_to_copy) /
3779 (sizeof (png_uint_32));
3780
3781 do
3782 {
3783 size_t c = bytes_to_copy;
3784 do
3785 {
3786 *dp32++ = *sp32++;
3787 c -= (sizeof (png_uint_32));
3788 }
3789 while (c > 0);
3790
3791 if (row_width <= bytes_to_jump)
3792 return;
3793
3794 dp32 += skip;
3795 sp32 += skip;
3796 row_width -= bytes_to_jump;
3797 }
3798 while (bytes_to_copy <= row_width);
3799
3800 /* Get to here when the row_width truncates the final copy.
3801 * There will be 1-3 bytes left to copy, so don't try the
3802 * 16-bit loop below.
3803 */
3804 dp = (png_bytep)dp32;
3805 sp = (png_const_bytep)sp32;
3806 do
3807 *dp++ = *sp++;
3808 while (--row_width > 0);
3809 return;
3810 }
3811
3812 /* Else do it in 16-bit quantities, but only if the size is
3813 * not too large.
3814 */
3815 else
3816 {
3817 png_uint_16p dp16 = png_aligncast(png_uint_16p, dp)((void*)(dp));
3818 png_const_uint_16p sp16 = png_aligncastconst(((const void*)(sp))
3819 png_const_uint_16p, sp)((const void*)(sp));
3820 size_t skip = (bytes_to_jump-bytes_to_copy) /
3821 (sizeof (png_uint_16));
3822
3823 do
3824 {
3825 size_t c = bytes_to_copy;
3826 do
3827 {
3828 *dp16++ = *sp16++;
3829 c -= (sizeof (png_uint_16));
3830 }
3831 while (c > 0);
3832
3833 if (row_width <= bytes_to_jump)
3834 return;
3835
3836 dp16 += skip;
3837 sp16 += skip;
3838 row_width -= bytes_to_jump;
3839 }
3840 while (bytes_to_copy <= row_width);
3841
3842 /* End of row - 1 byte left, bytes_to_copy > row_width: */
3843 dp = (png_bytep)dp16;
3844 sp = (png_const_bytep)sp16;
3845 do
3846 *dp++ = *sp++;
3847 while (--row_width > 0);
3848 return;
3849 }
3850 }
3851#endif /* ALIGN_TYPE code */
3852
3853 /* The true default - use a memcpy: */
3854 for (;;)
3855 {
3856 memcpy(dp, sp, bytes_to_copy);
3857
3858 if (row_width <= bytes_to_jump)
3859 return;
3860
3861 sp += bytes_to_jump;
3862 dp += bytes_to_jump;
3863 row_width -= bytes_to_jump;
3864 if (bytes_to_copy > row_width)
3865 bytes_to_copy = (unsigned int)/*SAFE*/row_width;
3866 }
3867 }
3868
3869 /* NOT REACHED*/
3870 } /* pixel_depth >= 8 */
3871
3872 /* Here if pixel_depth < 8 to check 'end_ptr' below. */
3873 }
3874 else
3875#endif /* READ_INTERLACING */
3876
3877 /* If here then the switch above wasn't used so just memcpy the whole row
3878 * from the temporary row buffer (notice that this overwrites the end of the
3879 * destination row if it is a partial byte.)
3880 */
3881 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) )
);
3882
3883 /* Restore the overwritten bits from the last byte if necessary. */
3884 if (end_ptr != NULL((void*)0))
3885 *end_ptr = (png_byte)((end_byte & end_mask) | (*end_ptr & ~end_mask));
3886}
3887
3888#ifdef PNG_READ_INTERLACING_SUPPORTED
3889void /* PRIVATE */
3890png_do_read_interlaceMOZ_PNG_do_read_int(png_row_infop row_info, png_bytep row, int pass,
3891 png_uint_32 transformations /* Because these may affect the byte layout */)
3892{
3893 png_debug(1, "in png_do_read_interlace")((void)0);
3894 if (row != NULL((void*)0) && row_info != NULL((void*)0))
3895 {
3896 png_uint_32 final_width;
3897
3898 final_width = row_info->width * png_pass_inc[pass];
3899
3900 switch (row_info->pixel_depth)
3901 {
3902 case 1:
3903 {
3904 png_bytep sp = row + (size_t)((row_info->width - 1) >> 3);
3905 png_bytep dp = row + (size_t)((final_width - 1) >> 3);
3906 unsigned int sshift, dshift;
3907 unsigned int s_start, s_end;
3908 int s_inc;
3909 int jstop = (int)png_pass_inc[pass];
3910 png_byte v;
3911 png_uint_32 i;
3912 int j;
3913
3914#ifdef PNG_READ_PACKSWAP_SUPPORTED
3915 if ((transformations & PNG_PACKSWAP0x10000U) != 0)
3916 {
3917 sshift = ((row_info->width + 7) & 0x07);
3918 dshift = ((final_width + 7) & 0x07);
3919 s_start = 7;
3920 s_end = 0;
3921 s_inc = -1;
3922 }
3923
3924 else
3925#endif
3926 {
3927 sshift = 7 - ((row_info->width + 7) & 0x07);
3928 dshift = 7 - ((final_width + 7) & 0x07);
3929 s_start = 0;
3930 s_end = 7;
3931 s_inc = 1;
3932 }
3933
3934 for (i = 0; i < row_info->width; i++)
3935 {
3936 v = (png_byte)((*sp >> sshift) & 0x01);
3937 for (j = 0; j < jstop; j++)
3938 {
3939 unsigned int tmp = *dp & (0x7f7f >> (7 - dshift));
3940 tmp |= (unsigned int)(v << dshift);
3941 *dp = (png_byte)(tmp & 0xff);
3942
3943 if (dshift == s_end)
3944 {
3945 dshift = s_start;
3946 dp--;
3947 }
3948
3949 else
3950 dshift = (unsigned int)((int)dshift + s_inc);
3951 }
3952
3953 if (sshift == s_end)
3954 {
3955 sshift = s_start;
3956 sp--;
3957 }
3958
3959 else
3960 sshift = (unsigned int)((int)sshift + s_inc);
3961 }
3962 break;
3963 }
3964
3965 case 2:
3966 {
3967 png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
3968 png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
3969 unsigned int sshift, dshift;
3970 unsigned int s_start, s_end;
3971 int s_inc;
3972 int jstop = (int)png_pass_inc[pass];
3973 png_uint_32 i;
3974
3975#ifdef PNG_READ_PACKSWAP_SUPPORTED
3976 if ((transformations & PNG_PACKSWAP0x10000U) != 0)
3977 {
3978 sshift = (((row_info->width + 3) & 0x03) << 1);
3979 dshift = (((final_width + 3) & 0x03) << 1);
3980 s_start = 6;
3981 s_end = 0;
3982 s_inc = -2;
3983 }
3984
3985 else
3986#endif
3987 {
3988 sshift = ((3 - ((row_info->width + 3) & 0x03)) << 1);
3989 dshift = ((3 - ((final_width + 3) & 0x03)) << 1);
3990 s_start = 0;
3991 s_end = 6;
3992 s_inc = 2;
3993 }
3994
3995 for (i = 0; i < row_info->width; i++)
3996 {
3997 png_byte v;
3998 int j;
3999
4000 v = (png_byte)((*sp >> sshift) & 0x03);
4001 for (j = 0; j < jstop; j++)
4002 {
4003 unsigned int tmp = *dp & (0x3f3f >> (6 - dshift));
4004 tmp |= (unsigned int)(v << dshift);
4005 *dp = (png_byte)(tmp & 0xff);
4006
4007 if (dshift == s_end)
4008 {
4009 dshift = s_start;
4010 dp--;
4011 }
4012
4013 else
4014 dshift = (unsigned int)((int)dshift + s_inc);
4015 }
4016
4017 if (sshift == s_end)
4018 {
4019 sshift = s_start;
4020 sp--;
4021 }
4022
4023 else
4024 sshift = (unsigned int)((int)sshift + s_inc);
4025 }
4026 break;
4027 }
4028
4029 case 4:
4030 {
4031 png_bytep sp = row + (size_t)((row_info->width - 1) >> 1);
4032 png_bytep dp = row + (size_t)((final_width - 1) >> 1);
4033 unsigned int sshift, dshift;
4034 unsigned int s_start, s_end;
4035 int s_inc;
4036 png_uint_32 i;
4037 int jstop = (int)png_pass_inc[pass];
4038
4039#ifdef PNG_READ_PACKSWAP_SUPPORTED
4040 if ((transformations & PNG_PACKSWAP0x10000U) != 0)
4041 {
4042 sshift = (((row_info->width + 1) & 0x01) << 2);
4043 dshift = (((final_width + 1) & 0x01) << 2);
4044 s_start = 4;
4045 s_end = 0;
4046 s_inc = -4;
4047 }
4048
4049 else
4050#endif
4051 {
4052 sshift = ((1 - ((row_info->width + 1) & 0x01)) << 2);
4053 dshift = ((1 - ((final_width + 1) & 0x01)) << 2);
4054 s_start = 0;
4055 s_end = 4;
4056 s_inc = 4;
4057 }
4058
4059 for (i = 0; i < row_info->width; i++)
4060 {
4061 png_byte v = (png_byte)((*sp >> sshift) & 0x0f);
4062 int j;
4063
4064 for (j = 0; j < jstop; j++)
4065 {
4066 unsigned int tmp = *dp & (0xf0f >> (4 - dshift));
4067 tmp |= (unsigned int)(v << dshift);
4068 *dp = (png_byte)(tmp & 0xff);
4069
4070 if (dshift == s_end)
4071 {
4072 dshift = s_start;
4073 dp--;
4074 }
4075
4076 else
4077 dshift = (unsigned int)((int)dshift + s_inc);
4078 }
4079
4080 if (sshift == s_end)
4081 {
4082 sshift = s_start;
4083 sp--;
4084 }
4085
4086 else
4087 sshift = (unsigned int)((int)sshift + s_inc);
4088 }
4089 break;
4090 }
4091
4092 default:
4093 {
4094 size_t pixel_bytes = (row_info->pixel_depth >> 3);
4095
4096 png_bytep sp = row + (size_t)(row_info->width - 1)
4097 * pixel_bytes;
4098
4099 png_bytep dp = row + (size_t)(final_width - 1) * pixel_bytes;
4100
4101 int jstop = (int)png_pass_inc[pass];
4102 png_uint_32 i;
4103
4104 for (i = 0; i < row_info->width; i++)
4105 {
4106 png_byte v[8]; /* SAFE; pixel_depth does not exceed 64 */
4107 int j;
4108
4109 memcpy(v, sp, pixel_bytes);
4110
4111 for (j = 0; j < jstop; j++)
4112 {
4113 memcpy(dp, v, pixel_bytes);
4114 dp -= pixel_bytes;
4115 }
4116
4117 sp -= pixel_bytes;
4118 }
4119 break;
4120 }
4121 }
4122
4123 row_info->width = final_width;
4124 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) )
;
4125 }
4126#ifndef PNG_READ_PACKSWAP_SUPPORTED
4127 PNG_UNUSED(transformations)(void)transformations; /* Silence compiler warning */
4128#endif
4129}
4130#endif /* READ_INTERLACING */
4131
4132static void
4133png_read_filter_row_subMOZ_PNG_read_filt_row_s(png_row_infop row_info, png_bytep row,
4134 png_const_bytep prev_row)
4135{
4136 size_t i;
4137 size_t istop = row_info->rowbytes;
4138 unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
4139 png_bytep rp = row + bpp;
4140
4141 PNG_UNUSED(prev_row)(void)prev_row;
4142
4143 for (i = bpp; i < istop; i++)
4144 {
4145 *rp = (png_byte)(((int)(*rp) + (int)(*(rp-bpp))) & 0xff);
4146 rp++;
4147 }
4148}
4149
4150static void
4151png_read_filter_row_upMOZ_PNG_read_filt_row_up(png_row_infop row_info, png_bytep row,
4152 png_const_bytep prev_row)
4153{
4154 size_t i;
4155 size_t istop = row_info->rowbytes;
4156 png_bytep rp = row;
4157 png_const_bytep pp = prev_row;
4158
4159 for (i = 0; i < istop; i++)
4160 {
4161 *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
4162 rp++;
4163 }
4164}
4165
4166static void
4167png_read_filter_row_avgMOZ_PNG_read_filt_row_a(png_row_infop row_info, png_bytep row,
4168 png_const_bytep prev_row)
4169{
4170 size_t i;
4171 png_bytep rp = row;
4172 png_const_bytep pp = prev_row;
4173 unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
4174 size_t istop = row_info->rowbytes - bpp;
4175
4176 for (i = 0; i < bpp; i++)
4177 {
4178 *rp = (png_byte)(((int)(*rp) +
4179 ((int)(*pp++) / 2 )) & 0xff);
4180
4181 rp++;
4182 }
4183
4184 for (i = 0; i < istop; i++)
4185 {
4186 *rp = (png_byte)(((int)(*rp) +
4187 (int)(*pp++ + *(rp-bpp)) / 2 ) & 0xff);
4188
4189 rp++;
4190 }
4191}
4192
4193static void
4194png_read_filter_row_paeth_1byte_pixelMOZ_PNG_read_filt_row_p_1b_px(png_row_infop row_info, png_bytep row,
4195 png_const_bytep prev_row)
4196{
4197 png_bytep rp_end = row + row_info->rowbytes;
4198 int a, c;
4199
4200 /* First pixel/byte */
4201 c = *prev_row++;
4202 a = *row + c;
4203 *row++ = (png_byte)a;
4204
4205 /* Remainder */
4206 while (row < rp_end)
4207 {
4208 int b, pa, pb, pc, p;
4209
4210 a &= 0xff; /* From previous iteration or start */
4211 b = *prev_row++;
4212
4213 p = b - c;
4214 pc = a - c;
4215
4216#ifdef PNG_USE_ABS
4217 pa = abs(p);
4218 pb = abs(pc);
4219 pc = abs(p + pc);
4220#else
4221 pa = p < 0 ? -p : p;
4222 pb = pc < 0 ? -pc : pc;
4223 pc = (p + pc) < 0 ? -(p + pc) : p + pc;
4224#endif
4225
4226 /* Find the best predictor, the least of pa, pb, pc favoring the earlier
4227 * ones in the case of a tie.
4228 */
4229 if (pb < pa)
4230 {
4231 pa = pb; a = b;
4232 }
4233 if (pc < pa) a = c;
4234
4235 /* Calculate the current pixel in a, and move the previous row pixel to c
4236 * for the next time round the loop
4237 */
4238 c = b;
4239 a += *row;
4240 *row++ = (png_byte)a;
4241 }
4242}
4243
4244static void
4245png_read_filter_row_paeth_multibyte_pixelMOZ_PNG_read_filt_row_p_mb_px(png_row_infop row_info, png_bytep row,
4246 png_const_bytep prev_row)
4247{
4248 unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
4249 png_bytep rp_end = row + bpp;
4250
4251 /* Process the first pixel in the row completely (this is the same as 'up'
4252 * because there is only one candidate predictor for the first row).
4253 */
4254 while (row < rp_end)
4255 {
4256 int a = *row + *prev_row++;
4257 *row++ = (png_byte)a;
4258 }
4259
4260 /* Remainder */
4261 rp_end = rp_end + (row_info->rowbytes - bpp);
4262
4263 while (row < rp_end)
4264 {
4265 int a, b, c, pa, pb, pc, p;
4266
4267 c = *(prev_row - bpp);
4268 a = *(row - bpp);
4269 b = *prev_row++;
4270
4271 p = b - c;
4272 pc = a - c;
4273
4274#ifdef PNG_USE_ABS
4275 pa = abs(p);
4276 pb = abs(pc);
4277 pc = abs(p + pc);
4278#else
4279 pa = p < 0 ? -p : p;
4280 pb = pc < 0 ? -pc : pc;
4281 pc = (p + pc) < 0 ? -(p + pc) : p + pc;
4282#endif
4283
4284 if (pb < pa)
4285 {
4286 pa = pb; a = b;
4287 }
4288 if (pc < pa) a = c;
4289
4290 a += *row;
4291 *row++ = (png_byte)a;
4292 }
4293}
4294
4295static void
4296png_init_filter_functionsMOZ_PNG_init_filt_func(png_structrp pp)
4297 /* This function is called once for every PNG image (except for PNG images
4298 * that only use PNG_FILTER_VALUE_NONE for all rows) to set the
4299 * implementations required to reverse the filtering of PNG rows. Reversing
4300 * the filter is the first transformation performed on the row data. It is
4301 * performed in place, therefore an implementation can be selected based on
4302 * the image pixel format. If the implementation depends on image width then
4303 * take care to ensure that it works correctly if the image is interlaced -
4304 * interlacing causes the actual row width to vary.
4305 */
4306{
4307 unsigned int bpp = (pp->pixel_depth + 7) >> 3;
4308
4309 pp->read_filter[PNG_FILTER_VALUE_SUB1-1] = png_read_filter_row_subMOZ_PNG_read_filt_row_s;
4310 pp->read_filter[PNG_FILTER_VALUE_UP2-1] = png_read_filter_row_upMOZ_PNG_read_filt_row_up;
4311 pp->read_filter[PNG_FILTER_VALUE_AVG3-1] = png_read_filter_row_avgMOZ_PNG_read_filt_row_a;
4312 if (bpp == 1)
4313 pp->read_filter[PNG_FILTER_VALUE_PAETH4-1] =
4314 png_read_filter_row_paeth_1byte_pixelMOZ_PNG_read_filt_row_p_1b_px;
4315 else
4316 pp->read_filter[PNG_FILTER_VALUE_PAETH4-1] =
4317 png_read_filter_row_paeth_multibyte_pixelMOZ_PNG_read_filt_row_p_mb_px;
4318
4319#ifdef PNG_FILTER_OPTIMIZATIONSMOZ_PNG_init_filt_func_sse2
4320 /* To use this define PNG_FILTER_OPTIMIZATIONS as the name of a function to
4321 * call to install hardware optimizations for the above functions; simply
4322 * replace whatever elements of the pp->read_filter[] array with a hardware
4323 * specific (or, for that matter, generic) optimization.
4324 *
4325 * To see an example of this examine what configure.ac does when
4326 * --enable-arm-neon is specified on the command line.
4327 */
4328 PNG_FILTER_OPTIMIZATIONSMOZ_PNG_init_filt_func_sse2(pp, bpp);
4329#endif
4330}
4331
4332void /* PRIVATE */
4333png_read_filter_rowMOZ_PNG_read_filt_row(png_structrp pp, png_row_infop row_info, png_bytep row,
4334 png_const_bytep prev_row, int filter)
4335{
4336 /* OPTIMIZATION: DO NOT MODIFY THIS FUNCTION, instead #define
4337 * PNG_FILTER_OPTIMIZATIONS to a function that overrides the generic
4338 * implementations. See png_init_filter_functions above.
4339 */
4340 if (filter > PNG_FILTER_VALUE_NONE0 && filter < PNG_FILTER_VALUE_LAST5)
4341 {
4342 if (pp->read_filter[0] == NULL((void*)0))
4343 png_init_filter_functionsMOZ_PNG_init_filt_func(pp);
4344
4345 pp->read_filter[filter-1](row_info, row, prev_row);
4346 }
4347}
4348
4349#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
4350void /* PRIVATE */
4351png_read_IDAT_data(png_structrp png_ptr, png_bytep output,
4352 png_alloc_size_t avail_out)
4353{
4354 /* Loop reading IDATs and decompressing the result into output[avail_out] */
4355 png_ptr->zstream.next_out = output;
4356 png_ptr->zstream.avail_out = 0; /* safety: set below */
4357
4358 if (output == NULL((void*)0))
4359 avail_out = 0;
4360
4361 do
4362 {
4363 int ret;
4364 png_byte tmpbuf[PNG_INFLATE_BUF_SIZE1024];
4365
4366 if (png_ptr->zstream.avail_in == 0)
4367 {
4368 uInt avail_in;
4369 png_bytep buffer;
4370
4371#ifdef PNG_READ_APNG_SUPPORTED
4372 png_uint_32 bytes_to_skip = 0;
4373
4374 while (png_ptr->idat_size == 0 || bytes_to_skip != 0)
4375 {
4376 png_crc_finishMOZ_PNG_crc_finish(png_ptr, bytes_to_skip);
4377 bytes_to_skip = 0;
4378
4379 png_ptr->idat_size = png_read_chunk_headerMOZ_PNG_read_chunk_header(png_ptr);
4380 if (png_ptr->num_frames_read == 0)
4381 {
4382 if (png_ptr->chunk_name != png_IDAT((((0xFFFFFFFFU)&(73)) << (24)) | (((0xFFFFFFFFU)&
(68)) << (16)) | (((0xFFFFFFFFU)&(65)) << (8)
) | (((0xFFFFFFFFU)&(84)) << (0)))
)
4383 png_error(png_ptr, "Not enough image data");
4384 }
4385 else
4386 {
4387 if (png_ptr->chunk_name == png_IEND((((0xFFFFFFFFU)&(73)) << (24)) | (((0xFFFFFFFFU)&
(69)) << (16)) | (((0xFFFFFFFFU)&(78)) << (8)
) | (((0xFFFFFFFFU)&(68)) << (0)))
)
4388 png_error(png_ptr, "Not enough image data");
4389 if (png_ptr->chunk_name != png_fdAT((((0xFFFFFFFFU)&(102)) << (24)) | (((0xFFFFFFFFU)&
(100)) << (16)) | (((0xFFFFFFFFU)&(65)) << (8
)) | (((0xFFFFFFFFU)&(84)) << (0)))
)
4390 {
4391 png_warningMOZ_PNG_warning(png_ptr, "Skipped (ignored) a chunk "
4392 "between APNG chunks");
4393 bytes_to_skip = png_ptr->idat_size;
4394 continue;
4395 }
4396
4397 png_ensure_sequence_numberMOZ_APNG_ensure_seqno(png_ptr, png_ptr->idat_size);
4398
4399 png_ptr->idat_size -= 4;
4400 }
4401 }
4402#else
4403 while (png_ptr->idat_size == 0)
4404 {
4405 png_crc_finishMOZ_PNG_crc_finish(png_ptr, 0);
4406
4407 png_ptr->idat_size = png_read_chunk_headerMOZ_PNG_read_chunk_header(png_ptr);
4408 /* This is an error even in the 'check' case because the code just
4409 * consumed a non-IDAT header.
4410 */
4411 if (png_ptr->chunk_name != png_IDAT((((0xFFFFFFFFU)&(73)) << (24)) | (((0xFFFFFFFFU)&
(68)) << (16)) | (((0xFFFFFFFFU)&(65)) << (8)
) | (((0xFFFFFFFFU)&(84)) << (0)))
)
4412 png_error(png_ptr, "Not enough image data");
4413 }
4414#endif /* READ_APNG */
4415
4416 avail_in = png_ptr->IDAT_read_size;
4417
4418 if (avail_in > png_chunk_max(png_ptr)((png_ptr)->user_chunk_malloc_max))
4419 avail_in = (uInt)/*SAFE*/png_chunk_max(png_ptr)((png_ptr)->user_chunk_malloc_max);
4420
4421 if (avail_in > png_ptr->idat_size)
4422 avail_in = (uInt)png_ptr->idat_size;
4423
4424 /* A PNG with a gradually increasing IDAT size will defeat this attempt
4425 * to minimize memory usage by causing lots of re-allocs, but
4426 * realistically doing IDAT_read_size re-allocs is not likely to be a
4427 * big problem.
4428 *
4429 * An error here corresponds to the system being out of memory.
4430 */
4431 buffer = png_read_buffer(png_ptr, avail_in);
4432
4433 if (buffer == NULL((void*)0))
4434 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, "out of memory");
4435
4436 png_crc_readMOZ_PNG_crc_read(png_ptr, buffer, avail_in);
4437 png_ptr->idat_size -= avail_in;
4438
4439 png_ptr->zstream.next_in = buffer;
4440 png_ptr->zstream.avail_in = avail_in;
4441 }
4442
4443 /* And set up the output side. */
4444 if (output != NULL((void*)0)) /* standard read */
4445 {
4446 uInt out = ZLIB_IO_MAX((uInt)-1);
4447
4448 if (out > avail_out)
4449 out = (uInt)avail_out;
4450
4451 avail_out -= out;
4452 png_ptr->zstream.avail_out = out;
4453 }
4454
4455 else /* after last row, checking for end */
4456 {
4457 png_ptr->zstream.next_out = tmpbuf;
4458 png_ptr->zstream.avail_out = (sizeof tmpbuf);
4459 }
4460
4461 /* Use NO_FLUSH; this gives zlib the maximum opportunity to optimize the
4462 * process. If the LZ stream is truncated the sequential reader will
4463 * terminally damage the stream, above, by reading the chunk header of the
4464 * following chunk (it then exits with png_error).
4465 *
4466 * TODO: deal more elegantly with truncated IDAT lists.
4467 */
4468 ret = PNG_INFLATE(png_ptr, Z_NO_FLUSH)png_zlib_inflate(png_ptr, 0);
4469
4470 /* Take the unconsumed output back. */
4471 if (output != NULL((void*)0))
4472 avail_out += png_ptr->zstream.avail_out;
4473
4474 else /* avail_out counts the extra bytes */
4475 avail_out += (sizeof tmpbuf) - png_ptr->zstream.avail_out;
4476
4477 png_ptr->zstream.avail_out = 0;
4478
4479 if (ret == Z_STREAM_END1)
4480 {
4481 /* Do this for safety; we won't read any more into this row. */
4482 png_ptr->zstream.next_out = NULL((void*)0);
4483
4484 png_ptr->mode |= PNG_AFTER_IDAT0x08;
4485 png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED0x0008U;
4486#ifdef PNG_READ_APNG_SUPPORTED
4487 png_ptr->num_frames_read++;
4488#endif
4489
4490 if (png_ptr->zstream.avail_in > 0 || png_ptr->idat_size > 0)
4491 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "Extra compressed data");
4492 break;
4493 }
4494
4495 if (ret != Z_OK0)
4496 {
4497 png_zstream_errorMOZ_PNG_zstream_error(png_ptr, ret);
4498
4499 if (output != NULL((void*)0))
4500 png_chunk_errorMOZ_PNG_chunk_err(png_ptr, png_ptr->zstream.msg);
4501
4502 else /* checking */
4503 {
4504 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, png_ptr->zstream.msg);
4505 return;
4506 }
4507 }
4508 } while (avail_out > 0);
4509
4510 if (avail_out > 0)
4511 {
4512 /* The stream ended before the image; this is the same as too few IDATs so
4513 * should be handled the same way.
4514 */
4515 if (output != NULL((void*)0))
4516 png_error(png_ptr, "Not enough image data");
4517
4518 else /* the deflate stream contained extra data */
4519 png_chunk_benign_errorMOZ_PNG_chunk_benign_err(png_ptr, "Too much image data");
4520 }
4521}
4522
4523void /* PRIVATE */
4524png_read_finish_IDAT(png_structrp png_ptr)
4525{
4526 /* We don't need any more data and the stream should have ended, however the
4527 * LZ end code may actually not have been processed. In this case we must
4528 * read it otherwise stray unread IDAT data or, more likely, an IDAT chunk
4529 * may still remain to be consumed.
4530 */
4531 if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED0x0008U) == 0)
4532 {
4533 /* The NULL causes png_read_IDAT_data to swallow any remaining bytes in
4534 * the compressed stream, but the stream may be damaged too, so even after
4535 * this call we may need to terminate the zstream ownership.
4536 */
4537 png_read_IDAT_data(png_ptr, NULL((void*)0), 0);
4538 png_ptr->zstream.next_out = NULL((void*)0); /* safety */
4539
4540 /* Now clear everything out for safety; the following may not have been
4541 * done.
4542 */
4543 if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED0x0008U) == 0)
4544 {
4545 png_ptr->mode |= PNG_AFTER_IDAT0x08;
4546 png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED0x0008U;
4547 }
4548 }
4549
4550 /* If the zstream has not been released do it now *and* terminate the reading
4551 * of the final IDAT chunk.
4552 */
4553 if (png_ptr->zowner == png_IDAT((((0xFFFFFFFFU)&(73)) << (24)) | (((0xFFFFFFFFU)&
(68)) << (16)) | (((0xFFFFFFFFU)&(65)) << (8)
) | (((0xFFFFFFFFU)&(84)) << (0)))
)
4554 {
4555 /* Always do this; the pointers otherwise point into the read buffer. */
4556 png_ptr->zstream.next_in = NULL((void*)0);
4557 png_ptr->zstream.avail_in = 0;
4558
4559 /* Now we no longer own the zstream. */
4560 png_ptr->zowner = 0;
4561
4562 /* The slightly weird semantics of the sequential IDAT reading is that we
4563 * are always in or at the end of an IDAT chunk, so we always need to do a
4564 * crc_finish here. If idat_size is non-zero we also need to read the
4565 * spurious bytes at the end of the chunk now.
4566 */
4567 (void)png_crc_finishMOZ_PNG_crc_finish(png_ptr, png_ptr->idat_size);
4568 }
4569}
4570
4571void /* PRIVATE */
4572png_read_finish_rowMOZ_PNG_read_finish_row(png_structrp png_ptr)
4573{
4574 png_debug(1, "in png_read_finish_row")((void)0);
4575 png_ptr->row_number++;
4576 if (png_ptr->row_number < png_ptr->num_rows)
4577 return;
4578
4579 if (png_ptr->interlaced != 0)
4580 {
4581 png_ptr->row_number = 0;
4582
4583 /* TO DO: don't do this if prev_row isn't needed (requires
4584 * read-ahead of the next row's filter byte.
4585 */
4586 memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
4587
4588 do
4589 {
4590 png_ptr->pass++;
4591
4592 if (png_ptr->pass >= 7)
4593 break;
4594
4595 png_ptr->iwidth = (png_ptr->width +
4596 png_pass_inc[png_ptr->pass] - 1 -
4597 png_pass_start[png_ptr->pass]) /
4598 png_pass_inc[png_ptr->pass];
4599
4600 if ((png_ptr->transformations & PNG_INTERLACE0x0002U) == 0)
4601 {
4602 png_ptr->num_rows = (png_ptr->height +
4603 png_pass_yinc[png_ptr->pass] - 1 -
4604 png_pass_ystart[png_ptr->pass]) /
4605 png_pass_yinc[png_ptr->pass];
4606 }
4607
4608 else /* if (png_ptr->transformations & PNG_INTERLACE) */
4609 break; /* libpng deinterlacing sees every row */
4610
4611 } while (png_ptr->num_rows == 0 || png_ptr->iwidth == 0);
4612
4613 if (png_ptr->pass < 7)
4614 return;
4615 }
4616
4617 /* Here after at the end of the last row of the last pass. */
4618 png_read_finish_IDAT(png_ptr);
4619}
4620#endif /* SEQUENTIAL_READ */
4621
4622void /* PRIVATE */
4623png_read_start_rowMOZ_PNG_read_start_row(png_structrp png_ptr)
4624{
4625 unsigned int max_pixel_depth;
4626 size_t row_bytes;
4627
4628 png_debug(1, "in png_read_start_row")((void)0);
4629
4630#ifdef PNG_READ_TRANSFORMS_SUPPORTED
4631 png_init_read_transformationsMOZ_PNG_init_read_transf(png_ptr);
4632#endif
4633 if (png_ptr->interlaced != 0)
4634 {
4635 if ((png_ptr->transformations & PNG_INTERLACE0x0002U) == 0)
4636 png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
4637 png_pass_ystart[0]) / png_pass_yinc[0];
4638
4639 else
4640 png_ptr->num_rows = png_ptr->height;
4641
4642 png_ptr->iwidth = (png_ptr->width +
4643 png_pass_inc[png_ptr->pass] - 1 -
4644 png_pass_start[png_ptr->pass]) /
4645 png_pass_inc[png_ptr->pass];
4646 }
4647
4648 else
4649 {
4650 png_ptr->num_rows = png_ptr->height;
4651 png_ptr->iwidth = png_ptr->width;
4652 }
4653
4654 max_pixel_depth = (unsigned int)png_ptr->pixel_depth;
4655
4656 /* WARNING: * png_read_transform_info (pngrtran.c) performs a simpler set of
4657 * calculations to calculate the final pixel depth, then
4658 * png_do_read_transforms actually does the transforms. This means that the
4659 * code which effectively calculates this value is actually repeated in three
4660 * separate places. They must all match. Innocent changes to the order of
4661 * transformations can and will break libpng in a way that causes memory
4662 * overwrites.
4663 *
4664 * TODO: fix this.
4665 */
4666#ifdef PNG_READ_PACK_SUPPORTED
4667 if ((png_ptr->transformations & PNG_PACK0x0004U) != 0 && png_ptr->bit_depth < 8)
4668 max_pixel_depth = 8;
4669#endif
4670
4671#ifdef PNG_READ_EXPAND_SUPPORTED
4672 if ((png_ptr->transformations & PNG_EXPAND0x1000U) != 0)
4673 {
4674 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE(2 | 1))
4675 {
4676 if (png_ptr->num_trans != 0)
4677 max_pixel_depth = 32;
4678
4679 else
4680 max_pixel_depth = 24;
4681 }
4682
4683 else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY0)
4684 {
4685 if (max_pixel_depth < 8)
4686 max_pixel_depth = 8;
4687
4688 if (png_ptr->num_trans != 0)
4689 max_pixel_depth *= 2;
4690 }
4691
4692 else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB(2))
4693 {
4694 if (png_ptr->num_trans != 0)
4695 {
4696 max_pixel_depth *= 4;
4697 max_pixel_depth /= 3;
4698 }
4699 }
4700 }
4701#endif
4702
4703#ifdef PNG_READ_EXPAND_16_SUPPORTED
4704 if ((png_ptr->transformations & PNG_EXPAND_160x0200U) != 0)
4705 {
4706# ifdef PNG_READ_EXPAND_SUPPORTED
4707 /* In fact it is an error if it isn't supported, but checking is
4708 * the safe way.
4709 */
4710 if ((png_ptr->transformations & PNG_EXPAND0x1000U) != 0)
4711 {
4712 if (png_ptr->bit_depth < 16)
4713 max_pixel_depth *= 2;
4714 }
4715 else
4716# endif
4717 png_ptr->transformations &= ~PNG_EXPAND_160x0200U;
4718 }
4719#endif
4720
4721#ifdef PNG_READ_FILLER_SUPPORTED
4722 if ((png_ptr->transformations & (PNG_FILLER0x8000U)) != 0)
4723 {
4724 if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY0)
4725 {
4726 if (max_pixel_depth <= 8)
4727 max_pixel_depth = 16;
4728
4729 else
4730 max_pixel_depth = 32;
4731 }
4732
4733 else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB(2) ||
4734 png_ptr->color_type == PNG_COLOR_TYPE_PALETTE(2 | 1))
4735 {
4736 if (max_pixel_depth <= 32)
4737 max_pixel_depth = 32;
4738
4739 else
4740 max_pixel_depth = 64;
4741 }
4742 }
4743#endif
4744
4745#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
4746 if ((png_ptr->transformations & PNG_GRAY_TO_RGB0x4000U) != 0)
4747 {
4748 if (
4749#ifdef PNG_READ_EXPAND_SUPPORTED
4750 (png_ptr->num_trans != 0 &&
4751 (png_ptr->transformations & PNG_EXPAND0x1000U) != 0) ||
4752#endif
4753#ifdef PNG_READ_FILLER_SUPPORTED
4754 (png_ptr->transformations & (PNG_FILLER0x8000U)) != 0 ||
4755#endif
4756 png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA(4))
4757 {
4758 if (max_pixel_depth <= 16)
4759 max_pixel_depth = 32;
4760
4761 else
4762 max_pixel_depth = 64;
4763 }
4764
4765 else
4766 {
4767 if (max_pixel_depth <= 8)
4768 {
4769 if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA(2 | 4))
4770 max_pixel_depth = 32;
4771
4772 else
4773 max_pixel_depth = 24;
4774 }
4775
4776 else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA(2 | 4))
4777 max_pixel_depth = 64;
4778
4779 else
4780 max_pixel_depth = 48;
4781 }
4782 }
4783#endif
4784
4785#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
4786defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
4787 if ((png_ptr->transformations & PNG_USER_TRANSFORM0x100000U) != 0)
4788 {
4789 unsigned int user_pixel_depth = png_ptr->user_transform_depth *
4790 png_ptr->user_transform_channels;
4791
4792 if (user_pixel_depth > max_pixel_depth)
4793 max_pixel_depth = user_pixel_depth;
4794 }
4795#endif
4796
4797 /* This value is stored in png_struct and double checked in the row read
4798 * code.
4799 */
4800 png_ptr->maximum_pixel_depth = (png_byte)max_pixel_depth;
4801 png_ptr->transformed_pixel_depth = 0; /* calculated on demand */
4802
4803 /* Align the width on the next larger 8 pixels. Mainly used
4804 * for interlacing
4805 */
4806 row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
4807 /* Calculate the maximum bytes needed, adding a byte and a pixel
4808 * for safety's sake
4809 */
4810 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) )
+
4811 1 + ((max_pixel_depth + 7) >> 3U);
4812
4813#ifdef PNG_MAX_MALLOC_64K
4814 if (row_bytes > (png_uint_32)65536L)
4815 png_error(png_ptr, "This image requires a row greater than 64KB");
4816#endif
4817
4818 if (row_bytes + 48 > png_ptr->old_big_row_buf_size)
4819 {
4820 png_freeMOZ_PNG_free(png_ptr, png_ptr->big_row_buf);
4821 png_freeMOZ_PNG_free(png_ptr, png_ptr->big_prev_row);
4822
4823 if (png_ptr->interlaced != 0)
4824 png_ptr->big_row_buf = (png_bytep)png_callocMOZ_PNG_calloc(png_ptr,
4825 row_bytes + 48);
4826
4827 else
4828 png_ptr->big_row_buf = (png_bytep)png_mallocMOZ_PNG_malloc(png_ptr, row_bytes + 48);
4829
4830 png_ptr->big_prev_row = (png_bytep)png_mallocMOZ_PNG_malloc(png_ptr, row_bytes + 48);
4831
4832#ifdef PNG_ALIGNED_MEMORY_SUPPORTED
4833 /* Use 16-byte aligned memory for row_buf with at least 16 bytes
4834 * of padding before and after row_buf; treat prev_row similarly.
4835 * NOTE: the alignment is to the start of the pixels, one beyond the start
4836 * of the buffer, because of the filter byte. Prior to libpng 1.5.6 this
4837 * was incorrect; the filter byte was aligned, which had the exact
4838 * opposite effect of that intended.
4839 */
4840 {
4841 png_bytep temp = png_ptr->big_row_buf + 32;
4842 size_t extra = (size_t)temp & 0x0f;
4843 png_ptr->row_buf = temp - extra - 1/*filter byte*/;
4844
4845 temp = png_ptr->big_prev_row + 32;
4846 extra = (size_t)temp & 0x0f;
4847 png_ptr->prev_row = temp - extra - 1/*filter byte*/;
4848 }
4849#else
4850 /* Use 31 bytes of padding before and 17 bytes after row_buf. */
4851 png_ptr->row_buf = png_ptr->big_row_buf + 31;
4852 png_ptr->prev_row = png_ptr->big_prev_row + 31;
4853#endif
4854 png_ptr->old_big_row_buf_size = row_bytes + 48;
4855 }
4856
4857#ifdef PNG_MAX_MALLOC_64K
4858 if (png_ptr->rowbytes > 65535)
4859 png_error(png_ptr, "This image requires a row greater than 64KB");
4860
4861#endif
4862 if (png_ptr->rowbytes > (PNG_SIZE_MAX((size_t)(-1)) - 1))
4863 png_error(png_ptr, "Row has too many bytes to allocate in memory");
4864
4865 memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
4866
4867 png_debug1(3, "width = %u,", png_ptr->width)((void)0);
4868 png_debug1(3, "height = %u,", png_ptr->height)((void)0);
4869 png_debug1(3, "iwidth = %u,", png_ptr->iwidth)((void)0);
4870 png_debug1(3, "num_rows = %u,", png_ptr->num_rows)((void)0);
4871 png_debug1(3, "rowbytes = %lu,", (unsigned long)png_ptr->rowbytes)((void)0);
4872 png_debug1(3, "irowbytes = %lu",((void)0)
4873 (unsigned long)PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1)((void)0);
4874
4875 /* The sequential reader needs a buffer for IDAT, but the progressive reader
4876 * does not, so free the read buffer now regardless; the sequential reader
4877 * reallocates it on demand.
4878 */
4879 if (png_ptr->read_buffer != NULL((void*)0))
4880 {
4881 png_bytep buffer = png_ptr->read_buffer;
4882
4883 png_ptr->read_buffer_size = 0;
4884 png_ptr->read_buffer = NULL((void*)0);
4885 png_freeMOZ_PNG_free(png_ptr, buffer);
4886 }
4887
4888 /* Finally claim the zstream for the inflate of the IDAT data, use the bits
4889 * value from the stream (note that this will result in a fatal error if the
4890 * IDAT stream has a bogus deflate header window_bits value, but this should
4891 * not be happening any longer!)
4892 */
4893 if (png_inflate_claim(png_ptr, png_IDAT((((0xFFFFFFFFU)&(73)) << (24)) | (((0xFFFFFFFFU)&
(68)) << (16)) | (((0xFFFFFFFFU)&(65)) << (8)
) | (((0xFFFFFFFFU)&(84)) << (0)))
) != Z_OK0)
4894 png_error(png_ptr, png_ptr->zstream.msg);
4895
4896 png_ptr->flags |= PNG_FLAG_ROW_INIT0x0040U;
4897}
4898
4899#ifdef PNG_READ_APNG_SUPPORTED
4900/* This function is to be called after the main IDAT set has been read and
4901 * before a new IDAT is read. It resets some parts of png_ptr
4902 * to make them usable by the read functions again */
4903void /* PRIVATE */
4904png_read_resetMOZ_APNG_read_reset(png_structp png_ptr)
4905{
4906 png_ptr->mode &= ~PNG_HAVE_IDAT0x04U;
4907 png_ptr->mode &= ~PNG_AFTER_IDAT0x08;
4908 png_ptr->row_number = 0;
4909 png_ptr->pass = 0;
4910}
4911
4912void /* PRIVATE */
4913png_read_reinitMOZ_APNG_read_reinit(png_structp png_ptr, png_infop info_ptr)
4914{
4915 png_ptr->width = info_ptr->next_frame_width;
4916 png_ptr->height = info_ptr->next_frame_height;
4917 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) )
;
4918 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) )
4919 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) )
;
4920 if (png_ptr->prev_row != NULL((void*)0))
4921 memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
4922}
4923
4924#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
4925/* same as png_read_reset() but for the progressive reader */
4926void /* PRIVATE */
4927png_progressive_read_resetMOZ_APNG_prog_read_reset(png_structp png_ptr)
4928{
4929#ifdef PNG_READ_INTERLACING_SUPPORTED
4930 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
4931
4932 /* Start of interlace block */
4933 static PNG_CONSTconst png_byte png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
4934
4935 /* Offset to next interlace block */
4936 static PNG_CONSTconst png_byte png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
4937
4938 /* Start of interlace block in the y direction */
4939 static PNG_CONSTconst png_byte png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
4940
4941 /* Offset to next interlace block in the y direction */
4942 static PNG_CONSTconst png_byte png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
4943
4944 if (png_ptr->interlaced != 0)
4945 {
4946 if ((png_ptr->transformations & PNG_INTERLACE0x0002U) == 0)
4947 png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
4948 png_pass_ystart[0]) / png_pass_yinc[0];
4949 else
4950 png_ptr->num_rows = png_ptr->height;
4951
4952 png_ptr->iwidth = (png_ptr->width +
4953 png_pass_inc[png_ptr->pass] - 1 -
4954 png_pass_start[png_ptr->pass]) /
4955 png_pass_inc[png_ptr->pass];
4956 }
4957 else
4958#endif /* READ_INTERLACING */
4959 {
4960 png_ptr->num_rows = png_ptr->height;
4961 png_ptr->iwidth = png_ptr->width;
4962 }
4963 png_ptr->flags &= ~PNG_FLAG_ZSTREAM_ENDED0x0008U;
4964 if (inflateResetMOZ_Z_inflateReset(&(png_ptr->zstream)) != Z_OK0)
4965 png_error(png_ptr, "inflateReset failed");
4966 png_ptr->zstream.avail_in = 0;
4967 png_ptr->zstream.next_in = 0;
4968 png_ptr->zstream.next_out = png_ptr->row_buf;
4969 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) )
4970 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;
4971}
4972#endif /* PROGRESSIVE_READ */
4973#endif /* READ_APNG */
4974#endif /* READ */