+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
127#ifndef STBI_INCLUDE_STB_IMAGE_H
+
128#define STBI_INCLUDE_STB_IMAGE_H
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
372#define STBI_VERSION 1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
392#ifdef STB_IMAGE_STATIC
+
393#define STBIDEF static
+
+
395#define STBIDEF extern
+
+
+
+
+
+
+
+
+
+
+
+
+
+
409 int (*read)(
void *
user,
char * data,
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
436#ifdef STBI_WINDOWS_UTF8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
459#ifndef STBI_NO_LINEAR
+
+
+
+
+
+
+
+
+
+
+
+
+
472STBIDEF
void stbi_hdr_to_ldr_gamma(
float gamma);
+
473STBIDEF
void stbi_hdr_to_ldr_scale(
float scale);
+
+
+
476#ifndef STBI_NO_LINEAR
+
477STBIDEF
void stbi_ldr_to_hdr_gamma(
float gamma);
+
478STBIDEF
void stbi_ldr_to_hdr_scale(
float scale);
+
+
+
+
+
+
+
485STBIDEF
int stbi_is_hdr(
char const *
filename);
+
486STBIDEF
int stbi_is_hdr_from_file(
FILE *
f);
+
+
+
+
+
491STBIDEF
const char * stbi_failure_reason(
void);
+
+
+
+
+
+
+
+
+
+
+
+
503STBIDEF
int stbi_info(
char const *
filename,
int *
x,
int *
y,
int *
comp);
+
504STBIDEF
int stbi_info_from_file(
FILE *
f,
int *
x,
int *
y,
int *
comp);
+
505STBIDEF
int stbi_is_16_bit(
char const *
filename);
+
506STBIDEF
int stbi_is_16_bit_from_file(
FILE *
f);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
533STBIDEF
char * stbi_zlib_decode_malloc(
const char *
buffer,
int len,
int *
outlen);
+
+
+
536STBIDEF
char * stbi_zlib_decode_noheader_malloc(
const char *
buffer,
int len,
int *
outlen);
+
+
+
+
+
+
+
+
+
+
+
548#ifdef STB_IMAGE_IMPLEMENTATION
+
+
550#if defined(STBI_ONLY_JPEG) || defined(STBI_ONLY_PNG) || defined(STBI_ONLY_BMP) || defined(STBI_ONLY_TGA) || \
+
551 defined(STBI_ONLY_GIF) || defined(STBI_ONLY_PSD) || defined(STBI_ONLY_HDR) || defined(STBI_ONLY_PIC) || \
+
552 defined(STBI_ONLY_PNM) || defined(STBI_ONLY_ZLIB)
+
553#ifndef STBI_ONLY_JPEG
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
582#if defined(STBI_NO_PNG) && !defined(STBI_SUPPORT_ZLIB) && !defined(STBI_NO_ZLIB)
+
+
+
+
+
+
+
+
+
+
592#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR)
+
+
+
+
+
+
+
+
+
+
602#define STBI_ASSERT(x) assert(x)
+
+
+
+
606#define STBI_EXTERN extern "C"
+
+
608#define STBI_EXTERN extern
+
+
+
+
+
613#define stbi_inline inline
+
+
+
+
+
618#define stbi_inline __forceinline
+
+
+
621#ifndef STBI_NO_THREAD_LOCALS
+
622#if defined(__cplusplus) && __cplusplus >= 201103L
+
623#define STBI_THREAD_LOCAL thread_local
+
624#elif defined(__GNUC__) && __GNUC__ < 5
+
625#define STBI_THREAD_LOCAL __thread
+
626#elif defined(_MSC_VER)
+
627#define STBI_THREAD_LOCAL __declspec(thread)
+
628#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
+
629#define STBI_THREAD_LOCAL _Thread_local
+
+
+
632#ifndef STBI_THREAD_LOCAL
+
+
634#define STBI_THREAD_LOCAL __thread
+
+
+
+
+
639#if defined(_MSC_VER) || defined(__SYMBIAN32__)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
656#define STBI_NOTUSED(v) (void)(v)
+
+
658#define STBI_NOTUSED(v) (void)sizeof(v)
+
+
+
+
662#define STBI_HAS_LROTL
+
+
+
+
666#define stbi_lrot(x, y) _lrotl(x, y)
+
+
668#define stbi_lrot(x, y) (((x) << (y)) | ((x) >> (-(y)&31)))
+
+
+
671#if defined(STBI_MALLOC) && defined(STBI_FREE) && (defined(STBI_REALLOC) || defined(STBI_REALLOC_SIZED))
+
+
673#elif !defined(STBI_MALLOC) && !defined(STBI_FREE) && !defined(STBI_REALLOC) && !defined(STBI_REALLOC_SIZED)
+
+
+
676#error "Must define all or none of STBI_MALLOC, STBI_FREE, and STBI_REALLOC (or STBI_REALLOC_SIZED)."
+
+
+
+
680#define STBI_MALLOC(sz) malloc(sz)
+
681#define STBI_REALLOC(p, newsz) realloc(p, newsz)
+
682#define STBI_FREE(p) free(p)
+
+
+
685#ifndef STBI_REALLOC_SIZED
+
686#define STBI_REALLOC_SIZED(p, oldsz, newsz) STBI_REALLOC(p, newsz)
+
+
+
+
690#if defined(__x86_64__) || defined(_M_X64)
+
691#define STBI__X64_TARGET
+
692#elif defined(__i386) || defined(_M_IX86)
+
693#define STBI__X86_TARGET
+
+
+
696#if defined(__GNUC__) && defined(STBI__X86_TARGET) && !defined(__SSE2__) && !defined(STBI_NO_SIMD)
+
+
+
+
+
+
+
+
+
+
+
707#if defined(__MINGW32__) && defined(STBI__X86_TARGET) && !defined(STBI_MINGW_ENABLE_SSE2) && !defined(STBI_NO_SIMD)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
722#if !defined(STBI_NO_SIMD) && (defined(STBI__X86_TARGET) || defined(STBI__X64_TARGET))
+
+
724#include <emmintrin.h>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
747#define STBI_SIMD_ALIGN(type, name) __declspec(align(16)) type name
+
+
749#if !defined(STBI_NO_JPEG) && defined(STBI_SSE2)
+
+
+
752 return ((
info3 >> 26) & 1) != 0;
+
+
+
+
+
757#define STBI_SIMD_ALIGN(type, name) type name __attribute__((aligned(16)))
+
+
759#if !defined(STBI_NO_JPEG) && defined(STBI_SSE2)
+
+
+
+
+
+
+
+
+
+
+
+
+
772#if defined(STBI_NO_SIMD) && defined(STBI_NEON)
+
+
+
+
+
+
+
779#define STBI_SIMD_ALIGN(type, name) __declspec(align(16)) type name
+
+
781#define STBI_SIMD_ALIGN(type, name) type name __attribute__((aligned(16)))
+
+
+
+
785#ifndef STBI_SIMD_ALIGN
+
786#define STBI_SIMD_ALIGN(type, name) type name
+
+
+
789#ifndef STBI_MAX_DIMENSIONS
+
790#define STBI_MAX_DIMENSIONS (1 << 24)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
820 s->read_from_callbacks = 0;
+
821 s->callback_already_read = 0;
+
+
+
+
+
+
+
+
829 s->io_user_data =
user;
+
830 s->buflen =
sizeof(
s->buffer_start);
+
831 s->read_from_callbacks = 1;
+
832 s->callback_already_read = 0;
+
833 s->img_buffer =
s->img_buffer_original =
s->buffer_start;
+
+
835 s->img_buffer_original_end =
s->img_buffer_end;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
869 s->img_buffer =
s->img_buffer_original;
+
870 s->img_buffer_end =
s->img_buffer_original_end;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
940#ifdef STBI_THREAD_LOCAL
+
+
+
+
+
+
+
947#ifndef STBI_NO_FAILURE_STRINGS
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
989#if !defined(STBI_NO_JPEG) || !defined(STBI_NO_PNG) || !defined(STBI_NO_TGA) || !defined(STBI_NO_HDR)
+
+
+
+
+
+
+
+
+
+
+
+
+
1002#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM)
+
+
+
+
+
+
+
1009#if !defined(STBI_NO_JPEG) || !defined(STBI_NO_PNG) || !defined(STBI_NO_TGA) || !defined(STBI_NO_HDR)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1024#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM)
+
+
+
+
+
+
+
+
+
+
1034 if ((
a >= 0) != (
b >= 0))
+
+
+
+
+
+
+
+
+
1043 if (
b == 0 ||
b == -1)
+
+
1045 if ((
a >= 0) == (
b >= 0))
+
+
+
+
+
+
+
+
+
+
+
1056#ifdef STBI_NO_FAILURE_STRINGS
+
1057#define stbi__err(x, y) 0
+
1058#elif defined(STBI_FAILURE_USERMSG)
+
1059#define stbi__err(x, y) stbi__err(y)
+
+
1061#define stbi__err(x, y) stbi__err(x)
+
+
+
1064#define stbi__errpf(x, y) ((float *)(size_t)(stbi__err(x, y) ? NULL : NULL))
+
1065#define stbi__errpuc(x, y) ((unsigned char *)(size_t)(stbi__err(x, y) ? NULL : NULL))
+
+
+
+
1069#ifndef STBI_NO_LINEAR
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1083#ifndef STBI_THREAD_LOCAL
+
1084#define stbi__vertically_flip_on_load stbi__vertically_flip_on_load_global
+
+
+
+
+
+
+
+
+
1093#define stbi__vertically_flip_on_load \
+
1094 (stbi__vertically_flip_on_load_set ? stbi__vertically_flip_on_load_local : stbi__vertically_flip_on_load_global)
+
+
+
+
+
1099 ri->bits_per_channel = 8;
+
+
1101 ri->num_channels = 0;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1153 return stbi__errpuc(
"unknown image type",
"Image not of any known type, or corrupt");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1194 for (row = 0; row < (
h >> 1); row++) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1234 if (
ri.bits_per_channel != 8) {
+
+
1236 ri.bits_per_channel = 8;
+
+
+
+
+
+
+
+
+
+
1246 return (
unsigned char *)
result;
+
+
+
+
+
+
+
+
+
+
+
+
+
1259 if (
ri.bits_per_channel != 16) {
+
+
1261 ri.bits_per_channel = 16;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1275#if !defined(STBI_NO_HDR) && !defined(STBI_NO_LINEAR)
+
+
+
+
+
+
+
+
+
1284#ifndef STBI_NO_STDIO
+
+
1286#if defined(_WIN32) && defined(STBI_WINDOWS_UTF8)
+
+
+
+
+
+
+
+
1294#if defined(_WIN32) && defined(STBI_WINDOWS_UTF8)
+
+
+
+
+
+
+
+
1302#if defined(_WIN32) && defined(STBI_WINDOWS_UTF8)
+
+
+
+
+
+
+
+
+
1311#if defined(_MSC_VER) && _MSC_VER >= 1400
+
+
+
+
+
+
+
1318#elif defined(_MSC_VER) && _MSC_VER >= 1400
+
+
+
+
+
+
+
+
+
+
+
+
+
1331 return stbi__errpuc(
"can't fopen",
"Unable to open file");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1416#ifndef STBI_NO_LINEAR
+
+
1418 unsigned char * data;
+
+
+
+
+
+
+
+
+
+
+
+
+
1431 return stbi__errpf(
"unknown image type",
"Image not of any known type, or corrupt");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1447#ifndef STBI_NO_STDIO
+
+
+
+
+
1452 return stbi__errpf(
"can't fopen",
"Unable to open file");
+
+
+
+
+
+
1458STBIDEF
float * stbi_loadf_from_file(
FILE *
f,
int *
x,
int *
y,
int *
comp,
int req_comp) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1483#ifndef STBI_NO_STDIO
+
1484STBIDEF
int stbi_is_hdr(
char const *
filename) {
+
+
+
+
1488 result = stbi_is_hdr_from_file(
f);
+
+
+
+
+
+
1494STBIDEF
int stbi_is_hdr_from_file(
FILE *
f) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1522#ifndef STBI_NO_LINEAR
+
+
+
+
1526STBIDEF
void stbi_ldr_to_hdr_scale(
float scale) {
stbi__l2h_scale = scale; }
+
+
+
+
+
+
1532STBIDEF
void stbi_hdr_to_ldr_scale(
float scale) {
stbi__h2l_scale_i = 1 / scale; }
+
+
+
+
+
+
+
+
+
1542 int n = (
s->io.read)(
s->io_user_data, (
char *)
s->buffer_start,
s->buflen);
+
1543 s->callback_already_read += (
int)(
s->img_buffer -
s->img_buffer_original);
+
+
+
+
1547 s->read_from_callbacks = 0;
+
1548 s->img_buffer =
s->buffer_start;
+
1549 s->img_buffer_end =
s->buffer_start + 1;
+
+
+
1552 s->img_buffer =
s->buffer_start;
+
1553 s->img_buffer_end =
s->buffer_start + n;
+
+
+
+
+
1558 if (
s->img_buffer <
s->img_buffer_end)
+
1559 return *
s->img_buffer++;
+
1560 if (
s->read_from_callbacks) {
+
+
1562 return *
s->img_buffer++;
+
+
+
+
+
1567#if defined(STBI_NO_JPEG) && defined(STBI_NO_HDR) && defined(STBI_NO_PIC) && defined(STBI_NO_PNM)
+
+
+
+
+
1572 if (!(
s->io.eof)(
s->io_user_data))
+
+
+
+
1576 if (
s->read_from_callbacks == 0)
+
+
+
+
1580 return s->img_buffer >=
s->img_buffer_end;
+
+
+
+
1584#if defined(STBI_NO_JPEG) && defined(STBI_NO_PNG) && defined(STBI_NO_BMP) && defined(STBI_NO_PSD) && defined(STBI_NO_TGA) && \
+
1585 defined(STBI_NO_GIF) && defined(STBI_NO_PIC)
+
+
+
+
+
+
+
1592 s->img_buffer =
s->img_buffer_end;
+
+
+
+
1596 int blen = (
int)(
s->img_buffer_end -
s->img_buffer);
+
+
1598 s->img_buffer =
s->img_buffer_end;
+
1599 (
s->io.skip)(
s->io_user_data, n -
blen);
+
+
+
+
+
+
+
+
1607#if defined(STBI_NO_PNG) && defined(STBI_NO_TGA) && defined(STBI_NO_HDR) && defined(STBI_NO_PNM)
+
+
+
+
+
1612 int blen = (
int)(
s->img_buffer_end -
s->img_buffer);
+
+
+
+
+
+
+
+
1620 s->img_buffer =
s->img_buffer_end;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1634#if defined(STBI_NO_JPEG) && defined(STBI_NO_PNG) && defined(STBI_NO_PSD) && defined(STBI_NO_PIC)
+
+
+
+
+
+
+
+
+
1643#if defined(STBI_NO_PNG) && defined(STBI_NO_PSD) && defined(STBI_NO_PIC)
+
+
+
+
+
+
+
+
+
1652#if defined(STBI_NO_BMP) && defined(STBI_NO_TGA) && defined(STBI_NO_GIF)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1669#define STBI__BYTECAST(x) ((stbi_uc)((x)&255))
+
+
1671#if defined(STBI_NO_JPEG) && defined(STBI_NO_PNG) && defined(STBI_NO_BMP) && defined(STBI_NO_PSD) && defined(STBI_NO_TGA) && \
+
1672 defined(STBI_NO_GIF) && defined(STBI_NO_PIC) && defined(STBI_NO_PNM)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1689#if defined(STBI_NO_PNG) && defined(STBI_NO_BMP) && defined(STBI_NO_PSD) && defined(STBI_NO_TGA) && defined(STBI_NO_GIF) && \
+
1690 defined(STBI_NO_PIC) && defined(STBI_NO_PNM)
+
+
+
+
+
1695 unsigned char *
good;
+
+
+
+
+
+
+
+
+
+
+
+
1707 for (
j = 0;
j < (
int)
y; ++
j) {
+
+
+
+
1711#define STBI__COMBO(a, b) ((a)*8 + (b))
+
1712#define STBI__CASE(a, b) \
+
1713 case STBI__COMBO(a, b): \
+
1714 for (i = x - 1; i >= 0; --i, src += a, dest += b)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1770 return stbi__errpuc(
"unsupported",
"Unsupported format conversion");
+
+
+
+
+
+
+
+
+
+
1780#if defined(STBI_NO_PNG) && defined(STBI_NO_PSD)
+
+
+
+
+
+
1786#if defined(STBI_NO_PNG) && defined(STBI_NO_PSD)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1803 for (
j = 0;
j < (
int)
y; ++
j) {
+
+
+
+
1807#define STBI__COMBO(a, b) ((a)*8 + (b))
+
1808#define STBI__CASE(a, b) \
+
1809 case STBI__COMBO(a, b): \
+
1810 for (i = x - 1; i >= 0; --i, src += a, dest += b)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1876#ifndef STBI_NO_LINEAR
+
+
+
+
+
+
+
1883 if (output ==
NULL) {
+
+
+
+
+
+
+
+
+
1892 for (
i = 0;
i <
x *
y; ++
i) {
+
1893 for (k = 0; k < n; ++k) {
+
+
+
+
+
1898 for (
i = 0;
i <
x *
y; ++
i) {
+
1899 output[
i *
comp + n] = data[
i *
comp + n] / 255.0f;
+
+
+
+
+
+
+
+
+
1908#define stbi__float2int(x) ((int)(x))
+
+
+
+
+
+
+
1915 if (output ==
NULL) {
+
+
+
+
+
+
+
+
+
1924 for (
i = 0;
i <
x *
y; ++
i) {
+
1925 for (k = 0; k < n; ++k) {
+
+
+
+
+
+
+
+
+
1934 float z = data[
i *
comp + k] * 255 + 0.5f;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2040 for (
i = 0;
i < 16; ++
i) {
+
+
+
+
2044 return stbi__err(
"bad size list",
"Corrupt JPEG");
+
+
+
+
+
+
+
+
2052 for (
j = 1;
j <= 16; ++
j) {
+
+
+
2055 if (
h->size[k] ==
j) {
+
2056 while (
h->size[k] ==
j)
+
+
2058 if (
code - 1 >= (1u <<
j))
+
2059 return stbi__err(
"bad code lengths",
"Corrupt JPEG");
+
+
+
2062 h->maxcode[
j] =
code << (16 -
j);
+
+
+
2065 h->maxcode[
j] = 0xffffffff;
+
+
+
+
2069 for (
i = 0;
i < k; ++
i) {
+
+
+
+
+
2074 for (
j = 0;
j < m; ++
j) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2091 int run = (
rs >> 4) & 15;
+
+
+
+
+
+
+
+
+
+
+
2102 if (k >= -128 && k <= 127)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2117 j->marker = (
unsigned char)
c;
+
+
+
+
+
2122 j->code_buffer |=
b << (24 -
j->code_bits);
+
+
2124 }
while (
j->code_bits <= 24);
+
+
+
+
+
2129 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535};
+
+
+
+
+
+
+
2136 if (
j->code_bits < 16)
+
+
+
+
+
+
+
+
+
2145 if (
s >
j->code_bits)
+
+
2147 j->code_buffer <<=
s;
+
+
2149 return h->values[k];
+
+
+
+
+
+
+
+
+
2158 temp =
j->code_buffer >> 16;
+
+
+
+
+
+
+
+
+
+
2168 if (k >
j->code_bits)
+
+
+
+
2172 c = ((
j->code_buffer >> (32 - k)) &
stbi__bmask[k]) +
h->delta[k];
+
+
+
+
+
+
+
2179 j->code_buffer <<= k;
+
2180 return h->values[
c];
+
+
+
+
2184static const int stbi__jbias[16] = {0, -1, -3, -7, -15, -31, -63, -127, -255, -511, -1023, -2047, -4095, -8191, -16383, -32767};
+
+
+
+
+
+
+
2191 if (
j->code_bits < n)
+
+
2193 if (
j->code_bits < n)
+
+
+
2196 sgn =
j->code_buffer >> 31;
+
+
+
+
+
+
+
+
+
+
+
2207 if (
j->code_bits < n)
+
+
2209 if (
j->code_bits < n)
+
+
+
+
+
+
+
+
+
+
+
2220 if (
j->code_bits < 1)
+
+
2222 if (
j->code_bits < 1)
+
+
+
2225 j->code_buffer <<= 1;
+
+
2227 return k & 0x80000000;
+
+
+
+
+
+
2233 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, 35,
+
2234 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51, 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63,
+
+
2236 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63};
+
+
+
+
+
+
+
+
2244 if (
j->code_bits < 16)
+
+
+
+
2248 return stbi__err(
"bad huffman code",
"Corrupt JPEG");
+
+
+
2251 memset(data, 0, 64 *
sizeof(data[0]));
+
+
+
+
2255 return stbi__err(
"bad delta",
"Corrupt JPEG");
+
2256 dc =
j->img_comp[
b].dc_pred +
diff;
+
2257 j->img_comp[
b].dc_pred =
dc;
+
+
2259 return stbi__err(
"can't merge dc and ac",
"Corrupt JPEG");
+
+
+
+
+
+
+
+
2267 if (
j->code_bits < 16)
+
+
+
+
+
+
+
2274 if (
s >
j->code_bits)
+
2275 return stbi__err(
"bad huffman code",
"Combined length longer than code bits available");
+
2276 j->code_buffer <<=
s;
+
+
+
+
+
+
+
+
2284 return stbi__err(
"bad huffman code",
"Corrupt JPEG");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2305 if (
j->spec_end != 0)
+
2306 return stbi__err(
"can't merge dc and ac",
"Corrupt JPEG");
+
+
2308 if (
j->code_bits < 16)
+
+
+
2311 if (
j->succ_high == 0) {
+
+
2313 memset(data, 0, 64 *
sizeof(data[0]));
+
+
+
2316 return stbi__err(
"can't merge dc and ac",
"Corrupt JPEG");
+
+
+
+
2320 return stbi__err(
"bad delta",
"Corrupt JPEG");
+
2321 dc =
j->img_comp[
b].dc_pred +
diff;
+
2322 j->img_comp[
b].dc_pred =
dc;
+
+
2324 return stbi__err(
"can't merge dc and ac",
"Corrupt JPEG");
+
2325 data[0] = (
short)(
dc * (1 <<
j->succ_low));
+
+
+
+
2329 data[0] += (
short)(1 <<
j->succ_low);
+
+
+
+
+
+
+
+
+
2338 if (
j->spec_start == 0)
+
2339 return stbi__err(
"can't merge dc and ac",
"Corrupt JPEG");
+
+
2341 if (
j->succ_high == 0) {
+
+
+
+
+
+
+
+
+
+
+
+
2353 if (
j->code_bits < 16)
+
+
+
+
+
+
+
2360 if (
s >
j->code_bits)
+
2361 return stbi__err(
"bad huffman code",
"Combined length longer than code bits available");
+
2362 j->code_buffer <<=
s;
+
+
+
+
+
+
+
2369 return stbi__err(
"bad huffman code",
"Corrupt JPEG");
+
+
+
+
+
2374 j->eob_run = (1 <<
r);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2395 for (k =
j->spec_start; k <=
j->spec_end; ++k) {
+
+
+
+
2399 if ((*p &
bit) == 0) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2413 return stbi__err(
"bad huffman code",
"Corrupt JPEG");
+
+
+
+
+
2418 j->eob_run = (1 <<
r) - 1;
+
+
+
+
+
+
+
+
+
+
+
2429 return stbi__err(
"bad huffman code",
"Corrupt JPEG");
+
+
+
+
+
+
+
+
+
+
+
+
+
2442 if ((*p &
bit) == 0) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2465 if ((
unsigned int)
x > 255) {
+
+
+
+
+
+
+
+
+
2474#define stbi__f2f(x) ((int)(((x)*4096 + 0.5)))
+
2475#define stbi__fsh(x) ((x)*4096)
+
+
+
2478#define STBI__IDCT_1D(s0, s1, s2, s3, s4, s5, s6, s7) \
+
2479 int t0, t1, t2, t3, p1, p2, p3, p4, p5, x0, x1, x2, x3; \
+
+
+
2482 p1 = (p2 + p3) * stbi__f2f(0.5411961f); \
+
2483 t2 = p1 + p3 * stbi__f2f(-1.847759065f); \
+
2484 t3 = p1 + p2 * stbi__f2f(0.765366865f); \
+
+
+
2487 t0 = stbi__fsh(p2 + p3); \
+
2488 t1 = stbi__fsh(p2 - p3); \
+
+
+
+
+
+
+
+
+
+
+
+
+
2501 p5 = (p3 + p4) * stbi__f2f(1.175875602f); \
+
2502 t0 = t0 * stbi__f2f(0.298631336f); \
+
2503 t1 = t1 * stbi__f2f(2.053119869f); \
+
2504 t2 = t2 * stbi__f2f(3.072711026f); \
+
2505 t3 = t3 * stbi__f2f(1.501321110f); \
+
2506 p1 = p5 + p1 * stbi__f2f(-0.899976223f); \
+
2507 p2 = p5 + p2 * stbi__f2f(-2.562915447f); \
+
2508 p3 = p3 * stbi__f2f(-1.961570560f); \
+
2509 p4 = p4 * stbi__f2f(-0.390180644f); \
+
+
+
+
+
+
+
+
+
+
+
+
2521 for (
i = 0;
i < 8; ++
i, ++
d, ++
v) {
+
+
2523 if (
d[8] == 0 &&
d[16] == 0 &&
d[24] == 0 &&
d[32] == 0 &&
d[40] == 0 &&
d[48] == 0 &&
d[56] == 0) {
+
+
+
+
+
+
2529 v[0] =
v[8] =
v[16] =
v[24] =
v[32] =
v[40] =
v[48] =
v[56] =
dcterm;
+
+
+
+
+
+
+
+
+
2538 v[0] = (
x0 +
t3) >> 10;
+
2539 v[56] = (
x0 -
t3) >> 10;
+
2540 v[8] = (
x1 +
t2) >> 10;
+
2541 v[48] = (
x1 -
t2) >> 10;
+
2542 v[16] = (
x2 +
t1) >> 10;
+
2543 v[40] = (
x2 -
t1) >> 10;
+
2544 v[24] = (
x3 +
t0) >> 10;
+
2545 v[32] = (
x3 -
t0) >> 10;
+
+
+
+
+
+
+
+
+
+
+
+
+
2558 x0 += 65536 + (128 << 17);
+
2559 x1 += 65536 + (128 << 17);
+
2560 x2 += 65536 + (128 << 17);
+
2561 x3 += 65536 + (128 << 17);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2585#define dct_const(x, y) _mm_setr_epi16((x), (y), (x), (y), (x), (y), (x), (y))
+
+
+
+
2589#define dct_rot(out0, out1, x, y, c0, c1) \
+
2590 __m128i c0##lo = _mm_unpacklo_epi16((x), (y)); \
+
2591 __m128i c0##hi = _mm_unpackhi_epi16((x), (y)); \
+
2592 __m128i out0##_l = _mm_madd_epi16(c0##lo, c0); \
+
2593 __m128i out0##_h = _mm_madd_epi16(c0##hi, c0); \
+
2594 __m128i out1##_l = _mm_madd_epi16(c0##lo, c1); \
+
2595 __m128i out1##_h = _mm_madd_epi16(c0##hi, c1)
+
+
+
2598#define dct_widen(out, in) \
+
2599 __m128i out##_l = _mm_srai_epi32(_mm_unpacklo_epi16(_mm_setzero_si128(), (in)), 4); \
+
2600 __m128i out##_h = _mm_srai_epi32(_mm_unpackhi_epi16(_mm_setzero_si128(), (in)), 4)
+
+
+
2603#define dct_wadd(out, a, b) \
+
2604 __m128i out##_l = _mm_add_epi32(a##_l, b##_l); \
+
2605 __m128i out##_h = _mm_add_epi32(a##_h, b##_h)
+
+
+
2608#define dct_wsub(out, a, b) \
+
2609 __m128i out##_l = _mm_sub_epi32(a##_l, b##_l); \
+
2610 __m128i out##_h = _mm_sub_epi32(a##_h, b##_h)
+
+
+
2613#define dct_bfly32o(out0, out1, a, b, bias, s) \
+
+
2615 __m128i abiased_l = _mm_add_epi32(a##_l, bias); \
+
2616 __m128i abiased_h = _mm_add_epi32(a##_h, bias); \
+
2617 dct_wadd(sum, abiased, b); \
+
2618 dct_wsub(dif, abiased, b); \
+
2619 out0 = _mm_packs_epi32(_mm_srai_epi32(sum_l, s), _mm_srai_epi32(sum_h, s)); \
+
2620 out1 = _mm_packs_epi32(_mm_srai_epi32(dif_l, s), _mm_srai_epi32(dif_h, s)); \
+
+
+
+
2624#define dct_interleave8(a, b) \
+
+
2626 a = _mm_unpacklo_epi8(a, b); \
+
2627 b = _mm_unpackhi_epi8(tmp, b)
+
+
+
2630#define dct_interleave16(a, b) \
+
+
2632 a = _mm_unpacklo_epi16(a, b); \
+
2633 b = _mm_unpackhi_epi16(tmp, b)
+
+
2635#define dct_pass(bias, shift) \
+
+
+
2638 dct_rot(t2e, t3e, row2, row6, rot0_0, rot0_1); \
+
2639 __m128i sum04 = _mm_add_epi16(row0, row4); \
+
2640 __m128i dif04 = _mm_sub_epi16(row0, row4); \
+
2641 dct_widen(t0e, sum04); \
+
2642 dct_widen(t1e, dif04); \
+
2643 dct_wadd(x0, t0e, t3e); \
+
2644 dct_wsub(x3, t0e, t3e); \
+
2645 dct_wadd(x1, t1e, t2e); \
+
2646 dct_wsub(x2, t1e, t2e); \
+
+
2648 dct_rot(y0o, y2o, row7, row3, rot2_0, rot2_1); \
+
2649 dct_rot(y1o, y3o, row5, row1, rot3_0, rot3_1); \
+
2650 __m128i sum17 = _mm_add_epi16(row1, row7); \
+
2651 __m128i sum35 = _mm_add_epi16(row3, row5); \
+
2652 dct_rot(y4o, y5o, sum17, sum35, rot1_0, rot1_1); \
+
2653 dct_wadd(x4, y0o, y4o); \
+
2654 dct_wadd(x5, y1o, y5o); \
+
2655 dct_wadd(x6, y2o, y5o); \
+
2656 dct_wadd(x7, y3o, y4o); \
+
2657 dct_bfly32o(row0, row7, x0, x7, bias, shift); \
+
2658 dct_bfly32o(row1, row6, x1, x6, bias, shift); \
+
2659 dct_bfly32o(row2, row5, x2, x5, bias, shift); \
+
2660 dct_bfly32o(row3, row4, x3, x4, bias, shift); \
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2755#undef dct_interleave8
+
2756#undef dct_interleave16
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2782#define dct_long_mul(out, inq, coeff) \
+
2783 int32x4_t out##_l = vmull_s16(vget_low_s16(inq), coeff); \
+
2784 int32x4_t out##_h = vmull_s16(vget_high_s16(inq), coeff)
+
+
2786#define dct_long_mac(out, acc, inq, coeff) \
+
2787 int32x4_t out##_l = vmlal_s16(acc##_l, vget_low_s16(inq), coeff); \
+
2788 int32x4_t out##_h = vmlal_s16(acc##_h, vget_high_s16(inq), coeff)
+
+
2790#define dct_widen(out, inq) \
+
2791 int32x4_t out##_l = vshll_n_s16(vget_low_s16(inq), 12); \
+
2792 int32x4_t out##_h = vshll_n_s16(vget_high_s16(inq), 12)
+
+
+
2795#define dct_wadd(out, a, b) \
+
2796 int32x4_t out##_l = vaddq_s32(a##_l, b##_l); \
+
2797 int32x4_t out##_h = vaddq_s32(a##_h, b##_h)
+
+
+
2800#define dct_wsub(out, a, b) \
+
2801 int32x4_t out##_l = vsubq_s32(a##_l, b##_l); \
+
2802 int32x4_t out##_h = vsubq_s32(a##_h, b##_h)
+
+
+
2805#define dct_bfly32o(out0, out1, a, b, shiftop, s) \
+
+
2807 dct_wadd(sum, a, b); \
+
2808 dct_wsub(dif, a, b); \
+
2809 out0 = vcombine_s16(shiftop(sum_l, s), shiftop(sum_h, s)); \
+
2810 out1 = vcombine_s16(shiftop(dif_l, s), shiftop(dif_h, s)); \
+
+
+
2813#define dct_pass(shiftop, shift) \
+
+
+
2816 int16x8_t sum26 = vaddq_s16(row2, row6); \
+
2817 dct_long_mul(p1e, sum26, rot0_0); \
+
2818 dct_long_mac(t2e, p1e, row6, rot0_1); \
+
2819 dct_long_mac(t3e, p1e, row2, rot0_2); \
+
2820 int16x8_t sum04 = vaddq_s16(row0, row4); \
+
2821 int16x8_t dif04 = vsubq_s16(row0, row4); \
+
2822 dct_widen(t0e, sum04); \
+
2823 dct_widen(t1e, dif04); \
+
2824 dct_wadd(x0, t0e, t3e); \
+
2825 dct_wsub(x3, t0e, t3e); \
+
2826 dct_wadd(x1, t1e, t2e); \
+
2827 dct_wsub(x2, t1e, t2e); \
+
+
2829 int16x8_t sum15 = vaddq_s16(row1, row5); \
+
2830 int16x8_t sum17 = vaddq_s16(row1, row7); \
+
2831 int16x8_t sum35 = vaddq_s16(row3, row5); \
+
2832 int16x8_t sum37 = vaddq_s16(row3, row7); \
+
2833 int16x8_t sumodd = vaddq_s16(sum17, sum35); \
+
2834 dct_long_mul(p5o, sumodd, rot1_0); \
+
2835 dct_long_mac(p1o, p5o, sum17, rot1_1); \
+
2836 dct_long_mac(p2o, p5o, sum35, rot1_2); \
+
2837 dct_long_mul(p3o, sum37, rot2_0); \
+
2838 dct_long_mul(p4o, sum15, rot2_1); \
+
2839 dct_wadd(sump13o, p1o, p3o); \
+
2840 dct_wadd(sump24o, p2o, p4o); \
+
2841 dct_wadd(sump23o, p2o, p3o); \
+
2842 dct_wadd(sump14o, p1o, p4o); \
+
2843 dct_long_mac(x4, sump13o, row7, rot3_0); \
+
2844 dct_long_mac(x5, sump24o, row5, rot3_1); \
+
2845 dct_long_mac(x6, sump23o, row3, rot3_2); \
+
2846 dct_long_mac(x7, sump14o, row1, rot3_3); \
+
2847 dct_bfly32o(row0, row7, x0, x7, shiftop, shift); \
+
2848 dct_bfly32o(row1, row6, x1, x6, shiftop, shift); \
+
2849 dct_bfly32o(row2, row5, x2, x5, shiftop, shift); \
+
2850 dct_bfly32o(row3, row4, x3, x4, shiftop, shift); \
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2873#define dct_trn16(x, y) \
+
+
2875 int16x8x2_t t = vtrnq_s16(x, y); \
+
+
+
+
2879#define dct_trn32(x, y) \
+
+
2881 int32x4x2_t t = vtrnq_s32(vreinterpretq_s32_s16(x), vreinterpretq_s32_s16(y)); \
+
2882 x = vreinterpretq_s16_s32(t.val[0]); \
+
2883 y = vreinterpretq_s16_s32(t.val[1]); \
+
+
2885#define dct_trn64(x, y) \
+
+
+
+
2889 x = vcombine_s16(vget_low_s16(x0), vget_low_s16(y0)); \
+
2890 y = vcombine_s16(vget_high_s16(x0), vget_high_s16(y0)); \
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2934#define dct_trn8_8(x, y) \
+
+
2936 uint8x8x2_t t = vtrn_u8(x, y); \
+
+
+
+
2940#define dct_trn8_16(x, y) \
+
+
2942 uint16x4x2_t t = vtrn_u16(vreinterpret_u16_u8(x), vreinterpret_u16_u8(y)); \
+
2943 x = vreinterpret_u8_u16(t.val[0]); \
+
2944 y = vreinterpret_u8_u16(t.val[1]); \
+
+
2946#define dct_trn8_32(x, y) \
+
+
2948 uint32x2x2_t t = vtrn_u32(vreinterpret_u32_u8(x), vreinterpret_u32_u8(y)); \
+
2949 x = vreinterpret_u8_u32(t.val[0]); \
+
2950 y = vreinterpret_u8_u32(t.val[1]); \
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3007#define STBI__MARKER_none 0xff
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3028#define STBI__RESTART(x) ((x) >= 0xd0 && (x) <= 0xd7)
+
+
+
+
+
+
+
+
3036 j->img_comp[0].dc_pred =
j->img_comp[1].dc_pred =
j->img_comp[2].dc_pred =
j->img_comp[3].dc_pred = 0;
+
+
3038 j->todo =
j->restart_interval ?
j->restart_interval : 0x7fffffff;
+
+
+
+
+
+
+
+
3046 if (!
z->progressive) {
+
3047 if (
z->scan_n == 1) {
+
+
+
3050 int n =
z->order[0];
+
+
+
+
+
3055 int w = (
z->img_comp[n].x + 7) >> 3;
+
3056 int h = (
z->img_comp[n].y + 7) >> 3;
+
3057 for (
j = 0;
j <
h; ++
j) {
+
3058 for (
i = 0;
i <
w; ++
i) {
+
3059 int ha =
z->img_comp[n].ha;
+
+
3061 z->dequant[
z->img_comp[n].tq]))
+
+
3063 z->idct_block_kernel(
z->img_comp[n].data +
z->img_comp[n].w2 *
j * 8 +
i * 8,
z->img_comp[n].w2, data);
+
+
3065 if (--
z->todo <= 0) {
+
3066 if (
z->code_bits < 24)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3080 for (
j = 0;
j <
z->img_mcu_y; ++
j) {
+
3081 for (
i = 0;
i <
z->img_mcu_x; ++
i) {
+
+
3083 for (k = 0; k <
z->scan_n; ++k) {
+
3084 int n =
z->order[k];
+
+
+
3087 for (
y = 0;
y <
z->img_comp[n].v; ++
y) {
+
3088 for (
x = 0;
x <
z->img_comp[n].h; ++
x) {
+
3089 int x2 = (
i *
z->img_comp[n].h +
x) * 8;
+
3090 int y2 = (
j *
z->img_comp[n].v +
y) * 8;
+
3091 int ha =
z->img_comp[n].ha;
+
+
3093 z->fast_ac[
ha], n,
z->dequant[
z->img_comp[n].tq]))
+
+
3095 z->idct_block_kernel(
z->img_comp[n].data +
z->img_comp[n].w2 *
y2 +
x2,
z->img_comp[n].w2,
+
+
+
+
+
+
+
3102 if (--
z->todo <= 0) {
+
3103 if (
z->code_bits < 24)
+
+
+
+
+
+
+
+
+
+
+
3114 if (
z->scan_n == 1) {
+
+
3116 int n =
z->order[0];
+
+
+
+
+
3121 int w = (
z->img_comp[n].x + 7) >> 3;
+
3122 int h = (
z->img_comp[n].y + 7) >> 3;
+
3123 for (
j = 0;
j <
h; ++
j) {
+
3124 for (
i = 0;
i <
w; ++
i) {
+
3125 short * data =
z->img_comp[n].coeff + 64 * (
i +
j *
z->img_comp[n].coeff_w);
+
3126 if (
z->spec_start == 0) {
+
+
+
+
3130 int ha =
z->img_comp[n].ha;
+
+
+
+
+
3135 if (--
z->todo <= 0) {
+
3136 if (
z->code_bits < 24)
+
+
+
+
+
+
+
+
+
+
+
3147 for (
j = 0;
j <
z->img_mcu_y; ++
j) {
+
3148 for (
i = 0;
i <
z->img_mcu_x; ++
i) {
+
+
3150 for (k = 0; k <
z->scan_n; ++k) {
+
3151 int n =
z->order[k];
+
+
+
3154 for (
y = 0;
y <
z->img_comp[n].v; ++
y) {
+
3155 for (
x = 0;
x <
z->img_comp[n].h; ++
x) {
+
3156 int x2 = (
i *
z->img_comp[n].h +
x);
+
3157 int y2 = (
j *
z->img_comp[n].v +
y);
+
3158 short * data =
z->img_comp[n].coeff + 64 * (
x2 +
y2 *
z->img_comp[n].coeff_w);
+
+
+
+
+
+
+
+
3166 if (--
z->todo <= 0) {
+
3167 if (
z->code_bits < 24)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3182 for (
i = 0;
i < 64; ++
i)
+
+
+
+
+
3187 if (
z->progressive) {
+
+
+
3190 for (n = 0; n <
z->s->img_n; ++n) {
+
3191 int w = (
z->img_comp[n].x + 7) >> 3;
+
3192 int h = (
z->img_comp[n].y + 7) >> 3;
+
3193 for (
j = 0;
j <
h; ++
j) {
+
3194 for (
i = 0;
i <
w; ++
i) {
+
3195 short * data =
z->img_comp[n].coeff + 64 * (
i +
j *
z->img_comp[n].coeff_w);
+
+
3197 z->idct_block_kernel(
z->img_comp[n].data +
z->img_comp[n].w2 *
j * 8 +
i * 8,
z->img_comp[n].w2, data);
+
+
+
+
+
+
+
+
+
+
+
3208 return stbi__err(
"expected marker",
"Corrupt JPEG");
+
+
+
+
3212 return stbi__err(
"bad DRI len",
"Corrupt JPEG");
+
+
+
+
+
+
+
+
3220 int p = q >> 4,
sixteen = (p != 0);
+
+
3222 if (p != 0 && p != 1)
+
3223 return stbi__err(
"bad DQT type",
"Corrupt JPEG");
+
+
3225 return stbi__err(
"bad DQT table",
"Corrupt JPEG");
+
+
3227 for (
i = 0;
i < 64; ++
i)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3241 if (
tc > 1 ||
th > 3)
+
3242 return stbi__err(
"bad DHT header",
"Corrupt JPEG");
+
3243 for (
i = 0;
i < 16; ++
i) {
+
+
+
+
+
3248 return stbi__err(
"bad DHT header",
"Corrupt JPEG");
+
+
+
+
+
3253 v =
z->huff_dc[
th].values;
+
+
+
+
3257 v =
z->huff_ac[
th].values;
+
+
3259 for (
i = 0;
i < n; ++
i)
+
+
+
+
+
+
+
+
+
+
3269 if ((m >= 0xE0 && m <= 0xEF) || m == 0xFE) {
+
+
+
+
3273 return stbi__err(
"bad COM len",
"Corrupt JPEG");
+
+
3275 return stbi__err(
"bad APP len",
"Corrupt JPEG");
+
+
+
+
3279 if (m == 0xE0 &&
L >= 5) {
+
3280 static const unsigned char tag[5] = {
'J',
'F',
'I',
'F',
'\0'};
+
+
+
3283 for (
i = 0;
i < 5; ++
i)
+
+
+
+
+
+
3289 }
else if (m == 0xEE &&
L >= 12) {
+
3290 static const unsigned char tag[6] = {
'A',
'd',
'o',
'b',
'e',
'\0'};
+
+
+
3293 for (
i = 0;
i < 6; ++
i)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3310 return stbi__err(
"unknown marker",
"Corrupt JPEG");
+
+
+
+
+
+
+
+
3318 if (
z->scan_n < 1 ||
z->scan_n > 4 ||
z->scan_n > (
int)
z->s->img_n)
+
3319 return stbi__err(
"bad SOS component count",
"Corrupt JPEG");
+
3320 if (
Ls != 6 + 2 *
z->scan_n)
+
3321 return stbi__err(
"bad SOS len",
"Corrupt JPEG");
+
3322 for (
i = 0;
i <
z->scan_n; ++
i) {
+
+
+
+
3326 if (
z->img_comp[
which].id ==
id)
+
+
3328 if (
which ==
z->s->img_n)
+
+
3330 z->img_comp[
which].hd = q >> 4;
+
3331 if (
z->img_comp[
which].hd > 3)
+
3332 return stbi__err(
"bad DC huff",
"Corrupt JPEG");
+
3333 z->img_comp[
which].ha = q & 15;
+
3334 if (
z->img_comp[
which].ha > 3)
+
3335 return stbi__err(
"bad AC huff",
"Corrupt JPEG");
+
+
+
+
+
+
+
+
+
3344 z->succ_high = (
aa >> 4);
+
3345 z->succ_low = (
aa & 15);
+
3346 if (
z->progressive) {
+
3347 if (
z->spec_start > 63 ||
z->spec_end > 63 ||
z->spec_start >
z->spec_end ||
z->succ_high > 13 ||
z->succ_low > 13)
+
3348 return stbi__err(
"bad SOS",
"Corrupt JPEG");
+
+
3350 if (
z->spec_start != 0)
+
3351 return stbi__err(
"bad SOS",
"Corrupt JPEG");
+
3352 if (
z->succ_high != 0 ||
z->succ_low != 0)
+
3353 return stbi__err(
"bad SOS",
"Corrupt JPEG");
+
+
+
+
+
+
+
+
+
+
+
3364 if (
z->img_comp[
i].raw_data) {
+
+
3366 z->img_comp[
i].raw_data =
NULL;
+
3367 z->img_comp[
i].data =
NULL;
+
+
3369 if (
z->img_comp[
i].raw_coeff) {
+
+
3371 z->img_comp[
i].raw_coeff = 0;
+
3372 z->img_comp[
i].coeff = 0;
+
+
3374 if (
z->img_comp[
i].linebuf) {
+
+
3376 z->img_comp[
i].linebuf =
NULL;
+
+
+
+
+
+
+
+
+
+
+
3387 return stbi__err(
"bad SOF len",
"Corrupt JPEG");
+
+
+
3390 return stbi__err(
"only 8-bit",
"JPEG format not supported: 8-bit only");
+
+
+
+
3394 "JPEG format not supported: delayed height");
+
+
+
3397 return stbi__err(
"0 width",
"Corrupt JPEG");
+
+
3399 return stbi__err(
"too large",
"Very large image (corrupt?)");
+
+
3401 return stbi__err(
"too large",
"Very large image (corrupt?)");
+
+
3403 if (
c != 3 &&
c != 1 &&
c != 4)
+
3404 return stbi__err(
"bad component count",
"Corrupt JPEG");
+
+
3406 for (
i = 0;
i <
c; ++
i) {
+
3407 z->img_comp[
i].data =
NULL;
+
3408 z->img_comp[
i].linebuf =
NULL;
+
+
+
3411 if (
Lf != 8 + 3 *
s->img_n)
+
3412 return stbi__err(
"bad SOF len",
"Corrupt JPEG");
+
+
+
3415 for (
i = 0;
i <
s->img_n; ++
i) {
+
3416 static const unsigned char rgb[3] = {
'R',
'G',
'B'};
+
+
3418 if (
s->img_n == 3 &&
z->img_comp[
i].id ==
rgb[
i])
+
+
+
3421 z->img_comp[
i].h = (q >> 4);
+
3422 if (!
z->img_comp[
i].h ||
z->img_comp[
i].h > 4)
+
3423 return stbi__err(
"bad H",
"Corrupt JPEG");
+
3424 z->img_comp[
i].v = q & 15;
+
3425 if (!
z->img_comp[
i].v ||
z->img_comp[
i].v > 4)
+
3426 return stbi__err(
"bad V",
"Corrupt JPEG");
+
+
3428 if (
z->img_comp[
i].tq > 3)
+
3429 return stbi__err(
"bad TQ",
"Corrupt JPEG");
+
+
+
+
+
+
+
3436 return stbi__err(
"too large",
"Image too large to decode");
+
+
3438 for (
i = 0;
i <
s->img_n; ++
i) {
+
+
+
+
+
+
+
+
+
3447 for (
i = 0;
i <
s->img_n; ++
i) {
+
3448 if (
h_max %
z->img_comp[
i].h != 0)
+
3449 return stbi__err(
"bad H",
"Corrupt JPEG");
+
3450 if (
v_max %
z->img_comp[
i].v != 0)
+
3451 return stbi__err(
"bad V",
"Corrupt JPEG");
+
+
+
+
+
+
3457 z->img_mcu_w =
h_max * 8;
+
3458 z->img_mcu_h =
v_max * 8;
+
+
3460 z->img_mcu_x = (
s->img_x +
z->img_mcu_w - 1) /
z->img_mcu_w;
+
3461 z->img_mcu_y = (
s->img_y +
z->img_mcu_h - 1) /
z->img_mcu_h;
+
+
3463 for (
i = 0;
i <
s->img_n; ++
i) {
+
+
+
+
+
+
+
+
+
+
+
3474 z->img_comp[
i].w2 =
z->img_mcu_x *
z->img_comp[
i].h * 8;
+
3475 z->img_comp[
i].h2 =
z->img_mcu_y *
z->img_comp[
i].v * 8;
+
3476 z->img_comp[
i].coeff = 0;
+
3477 z->img_comp[
i].raw_coeff = 0;
+
3478 z->img_comp[
i].linebuf =
NULL;
+
+
3480 if (
z->img_comp[
i].raw_data ==
NULL)
+
+
+
3483 z->img_comp[
i].data = (
stbi_uc *)(((
size_t)
z->img_comp[
i].raw_data + 15) & ~15);
+
3484 if (
z->progressive) {
+
+
3486 z->img_comp[
i].coeff_w =
z->img_comp[
i].w2 / 8;
+
3487 z->img_comp[
i].coeff_h =
z->img_comp[
i].h2 / 8;
+
+
3489 if (
z->img_comp[
i].raw_coeff ==
NULL)
+
+
3491 z->img_comp[
i].coeff = (
short *)(((
size_t)
z->img_comp[
i].raw_coeff + 15) & ~15);
+
+
+
+
+
+
+
+
3499#define stbi__DNL(x) ((x) == 0xdc)
+
3500#define stbi__SOI(x) ((x) == 0xd8)
+
3501#define stbi__EOI(x) ((x) == 0xd9)
+
3502#define stbi__SOF(x) ((x) == 0xc0 || (x) == 0xc1 || (x) == 0xc2)
+
3503#define stbi__SOS(x) ((x) == 0xda)
+
+
3505#define stbi__SOF_progressive(x) ((x) == 0xc2)
+
+
+
+
+
3510 z->app14_color_transform = -1;
+
+
+
+
3514 return stbi__err(
"no SOI",
"Corrupt JPEG");
+
+
+
+
+
+
+
+
+
+
+
3525 return stbi__err(
"no SOF",
"Corrupt JPEG");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3544 if (
x != 0x00 &&
x != 0xff) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3560 for (m = 0; m < 4; m++) {
+
3561 j->img_comp[m].raw_data =
NULL;
+
3562 j->img_comp[m].raw_coeff =
NULL;
+
+
3564 j->restart_interval = 0;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3585 return stbi__err(
"bad DNL len",
"Corrupt JPEG");
+
3586 if (
NL !=
j->s->img_y)
+
3587 return stbi__err(
"bad DNL height",
"Corrupt JPEG");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3604#define stbi__div4(x) ((stbi_uc)((x) >> 2))
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3618 for (
i = 0;
i <
w; ++
i)
+
+
+
+
+
+
+
+
+
+
+
+
3630 out[0] =
out[1] = input[0];
+
+
+
+
+
+
3636 for (
i = 1;
i <
w - 1; ++
i) {
+
3637 int n = 3 * input[
i] + 2;
+
+
+
+
+
3642 out[
i * 2 + 1] = input[
w - 1];
+
+
+
+
+
+
+
+
3650#define stbi__div16(x) ((stbi_uc)((x) >> 4))
+
+
+
+
+
+
+
+
+
+
+
+
3662 for (
i = 1;
i <
w; ++
i) {
+
+
+
+
+
+
+
+
+
+
+
+
+
3675#if defined(STBI_SSE2) || defined(STBI_NEON)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3689 for (;
i < ((
w - 1) & ~7);
i += 8) {
+
3690#if defined(STBI_SSE2)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3733#elif defined(STBI_NEON)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3777 for (++
i;
i <
w; ++
i) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3795 for (
i = 0;
i <
w; ++
i)
+
3796 for (
j = 0;
j <
hs; ++
j)
+
+
+
+
+
+
+
3803#define stbi__float2fixed(x) (((int)((x)*4096.0f + 0.5f)) << 8)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3818 if ((
unsigned)
r > 255) {
+
+
+
+
+
+
3824 if ((
unsigned)
g > 255) {
+
+
+
+
+
+
3830 if ((
unsigned)
b > 255) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3844#if defined(STBI_SSE2) || defined(STBI_NEON)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3863 for (;
i + 7 <
count;
i += 8) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3920 for (;
i + 7 <
count;
i += 8) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
3967 if ((
unsigned)
r > 255) {
+
+
+
+
+
+
3973 if ((
unsigned)
g > 255) {
+
+
+
+
+
+
3979 if ((
unsigned)
b > 255) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4029 unsigned int t =
x *
y + 128;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4050 is_rgb =
z->s->img_n == 3 && (
z->rgb == 3 || (
z->app14_color_transform == 0 && !
z->jfif));
+
+
4052 if (
z->s->img_n == 3 && n < 3 && !
is_rgb)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4079 if (!
z->img_comp[k].linebuf) {
+
+
+
+
+
4084 r->hs =
z->img_h_max /
z->img_comp[k].h;
+
4085 r->vs =
z->img_v_max /
z->img_comp[k].v;
+
4086 r->ystep =
r->vs >> 1;
+
4087 r->w_lores = (
z->s->img_x +
r->hs - 1) /
r->hs;
+
+
4089 r->line0 =
r->line1 =
z->img_comp[k].data;
+
+
4091 if (
r->hs == 1 &&
r->vs == 1)
+
+
4093 else if (
r->hs == 1 &&
r->vs == 2)
+
+
4095 else if (
r->hs == 2 &&
r->vs == 1)
+
+
4097 else if (
r->hs == 2 &&
r->vs == 2)
+
4098 r->resample =
z->resample_row_hv_2_kernel;
+
+
+
+
+
+
+
+
+
+
+
+
+
4111 for (
j = 0;
j <
z->s->img_y; ++
j) {
+
+
+
+
4115 int y_bot =
r->ystep >= (
r->vs >> 1);
+
+
+
4118 if (++
r->ystep >=
r->vs) {
+
+
4120 r->line0 =
r->line1;
+
4121 if (++
r->ypos <
z->img_comp[k].y)
+
4122 r->line1 +=
z->img_comp[k].w2;
+
+
+
+
+
4127 if (
z->s->img_n == 3) {
+
+
4129 for (
i = 0;
i <
z->s->img_x; ++
i) {
+
+
+
+
+
+
+
+
+
+
4139 }
else if (
z->s->img_n == 4) {
+
4140 if (
z->app14_color_transform == 0) {
+
4141 for (
i = 0;
i <
z->s->img_x; ++
i) {
+
+
+
+
+
+
+
+
4149 }
else if (
z->app14_color_transform == 2) {
+
+
4151 for (
i = 0;
i <
z->s->img_x; ++
i) {
+
+
+
+
+
+
+
+
+
+
+
4162 for (
i = 0;
i <
z->s->img_x; ++
i) {
+
+
+
+
+
+
+
+
4170 for (
i = 0;
i <
z->s->img_x; ++
i)
+
+
+
4173 for (
i = 0;
i <
z->s->img_x; ++
i,
out += 2) {
+
+
+
+
+
4178 }
else if (
z->s->img_n == 4 &&
z->app14_color_transform == 0) {
+
4179 for (
i = 0;
i <
z->s->img_x; ++
i) {
+
+
+
+
+
+
+
+
+
4188 }
else if (
z->s->img_n == 4 &&
z->app14_color_transform == 2) {
+
4189 for (
i = 0;
i <
z->s->img_x; ++
i) {
+
+
+
+
+
+
+
+
4197 for (
i = 0;
i <
z->s->img_x; ++
i)
+
+
+
4200 for (
i = 0;
i <
z->s->img_x; ++
i) {
+
+
+
+
+
+
+
+
+
+
+
4211 *
comp =
z->s->img_n >= 3 ? 3 : 1;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4234 return stbi__err(
"outofmem",
"Out of memory");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4254 *
comp =
j->s->img_n >= 3 ? 3 : 1;
+
+
+
+
+
+
+
+
4262 return stbi__err(
"outofmem",
"Out of memory");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4281#define STBI__ZFAST_BITS 9
+
4282#define STBI__ZFAST_MASK ((1 << STBI__ZFAST_BITS) - 1)
+
4283#define STBI__ZNSYMS 288
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4297 n = ((n & 0xAAAA) >> 1) | ((n & 0x5555) << 1);
+
4298 n = ((n & 0xCCCC) >> 2) | ((n & 0x3333) << 2);
+
4299 n = ((n & 0xF0F0) >> 4) | ((n & 0x0F0F) << 4);
+
4300 n = ((n & 0xFF00) >> 8) | ((n & 0x00FF) << 8);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4317 memset(
z->fast, 0,
sizeof(
z->fast));
+
4318 for (
i = 0;
i <
num; ++
i)
+
+
+
4321 for (
i = 1;
i < 16; ++
i)
+
+
4323 return stbi__err(
"bad sizes",
"Corrupt PNG");
+
+
4325 for (
i = 1;
i < 16; ++
i) {
+
+
+
+
+
+
4331 if (
code - 1 >= (1 <<
i))
+
4332 return stbi__err(
"bad codelengths",
"Corrupt PNG");
+
4333 z->maxcode[
i] =
code << (16 -
i);
+
+
+
+
4337 z->maxcode[16] = 0x10000;
+
4338 for (
i = 0;
i <
num; ++
i) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4383 if (
z->code_buffer >= (1U <<
z->num_bits)) {
+
4384 z->zbuffer =
z->zbuffer_end;
+
+
+
+
+
4389 }
while (
z->num_bits <= 24);
+
+
+
+
+
4394 if (
z->num_bits < n)
+
+
4396 k =
z->code_buffer & ((1 << n) - 1);
+
4397 z->code_buffer >>= n;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4413 b = (k >> (16 -
s)) -
z->firstcode[
s] +
z->firstsymbol[
s];
+
+
+
4416 if (
z->size[
b] !=
s)
+
+
4418 a->code_buffer >>=
s;
+
+
+
+
+
+
+
4425 if (
a->num_bits < 16) {
+
+
+
+
+
+
+
+
+
4434 a->code_buffer >>=
s;
+
+
+
+
+
+
+
+
+
+
+
+
4446 if (!
z->z_expandable)
+
4447 return stbi__err(
"output buffer limit",
"Corrupt PNG");
+
4448 cur = (
unsigned int)(
z->zout -
z->zout_start);
+
+
+
4451 return stbi__err(
"outofmem",
"Out of memory");
+
+
+
4454 return stbi__err(
"outofmem",
"Out of memory");
+
+
+
+
+
+
4460 return stbi__err(
"outofmem",
"Out of memory");
+
+
+
+
+
+
+
4467static const int stbi__zlength_base[31] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
+
4468 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
+
+
4470static const int stbi__zlength_extra[31] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
+
4471 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0};
+
+
4473static const int stbi__zdist_base[32] = {1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33,
+
4474 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537,
+
4475 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0};
+
+
4477static const int stbi__zdist_extra[32] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6,
+
4478 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13};
+
+
+
4481 char *
zout =
a->zout;
+
+
+
+
+
4486 return stbi__err(
"bad huffman code",
"Corrupt PNG");
+
4487 if (
zout >=
a->zout_end) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4515 return stbi__err(
"bad dist",
"Corrupt PNG");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4541 static const stbi_uc length_dezigzag[19] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4564 return stbi__err(
"bad codelengths",
"Corrupt PNG");
+
+
+
+
+
+
+
+
4572 return stbi__err(
"bad codelengths",
"Corrupt PNG");
+
+
4574 }
else if (
c == 17) {
+
+
4576 }
else if (
c == 18) {
+
+
+
4579 return stbi__err(
"bad codelengths",
"Corrupt PNG");
+
+
+
4582 return stbi__err(
"bad codelengths",
"Corrupt PNG");
+
+
+
+
+
+
4588 return stbi__err(
"bad codelengths",
"Corrupt PNG");
+
+
+
+
+
+
+
+
+
+
+
4599 if (
a->num_bits & 7)
+
+
+
+
4603 while (
a->num_bits > 0) {
+
+
4605 a->code_buffer >>= 8;
+
+
+
4608 if (
a->num_bits < 0)
+
4609 return stbi__err(
"zlib corrupt",
"Corrupt PNG");
+
+
+
+
+
+
+
4616 return stbi__err(
"zlib corrupt",
"Corrupt PNG");
+
4617 if (
a->zbuffer +
len >
a->zbuffer_end)
+
4618 return stbi__err(
"read past buffer",
"Corrupt PNG");
+
4619 if (
a->zout +
len >
a->zout_end)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4634 return stbi__err(
"bad zlib header",
"Corrupt PNG");
+
4635 if ((
cmf * 256 +
flg) % 31 != 0)
+
4636 return stbi__err(
"bad zlib header",
"Corrupt PNG");
+
+
4638 return stbi__err(
"no preset dict",
"Corrupt PNG");
+
+
4640 return stbi__err(
"bad compression",
"Corrupt PNG");
+
+
+
+
+
+
4646 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+
4647 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+
4648 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+
4649 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+
4650 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+
4651 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+
4652 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+
4653 9, 9, 9, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8};
+
4654static const stbi_uc stbi__zdefault_distance[32] = {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+
4655 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4682 }
else if (
type == 3) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4703 a->zout_start =
obuf;
+
+
+
4706 a->z_expandable =
exp;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4721 return a.zout_start;
+
+
+
+
+
+
+
4728STBIDEF
char * stbi_zlib_decode_malloc(
char const *
buffer,
int len,
int *
outlen) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4743 return a.zout_start;
+
+
+
+
+
+
+
+
+
+
+
+
4755 return (
int)(
a.zout -
a.zout_start);
+
+
+
+
+
4760STBIDEF
char * stbi_zlib_decode_noheader_malloc(
char const *
buffer,
int len,
int *
outlen) {
+
+
+
+
+
+
+
+
+
+
4770 return a.zout_start;
+
+
+
+
+
+
+
+
+
+
+
+
4782 return (
int)(
a.zout -
a.zout_start);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4812 static const stbi_uc png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
+
+
4814 for (
i = 0;
i < 8; ++
i)
+
+
4816 return stbi__err(
"bad png sig",
"Not a PNG");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4870 return stbi__err(
"outofmem",
"Out of memory");
+
+
+
4873 return stbi__err(
"too large",
"Corrupt PNG");
+
+
+
+
+
+
+
+
4881 return stbi__err(
"not enough pixels",
"Corrupt PNG");
+
+
4883 for (
j = 0;
j <
y; ++
j) {
+
+
+
+
+
+
4889 return stbi__err(
"invalid filter",
"Corrupt PNG");
+
+
+
+
4893 return stbi__err(
"invalid width",
"Corrupt PNG");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4937 }
else if (
depth == 16) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4954#define STBI__CASE(f) \
+
+
4956 for (k = 0; k < nk; ++k)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
4981#define STBI__CASE(f) \
+
+
4983 for (i = x - 1; i >= 1; --i, cur[filter_bytes] = 255, raw += filter_bytes, cur += output_bytes, prior += output_bytes) \
+
4984 for (k = 0; k < filter_bytes; ++k)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5020 for (
j = 0;
j <
y; ++
j) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5035 for (k =
x *
img_n; k >= 2; k -= 2, ++
in) {
+
5036 *
cur++ = scale * ((*
in >> 4));
+
5037 *
cur++ = scale * ((*in) & 0x0f);
+
+
+
5040 *
cur++ = scale * ((*
in >> 4));
+
5041 }
else if (
depth == 2) {
+
5042 for (k =
x *
img_n; k >= 4; k -= 4, ++
in) {
+
5043 *
cur++ = scale * ((*
in >> 6));
+
5044 *
cur++ = scale * ((*
in >> 4) & 0x03);
+
5045 *
cur++ = scale * ((*
in >> 2) & 0x03);
+
5046 *
cur++ = scale * ((*in) & 0x03);
+
+
+
5049 *
cur++ = scale * ((*
in >> 6));
+
+
5051 *
cur++ = scale * ((*
in >> 4) & 0x03);
+
+
5053 *
cur++ = scale * ((*
in >> 2) & 0x03);
+
5054 }
else if (
depth == 1) {
+
5055 for (k =
x *
img_n; k >= 8; k -= 8, ++
in) {
+
5056 *
cur++ = scale * ((*
in >> 7));
+
5057 *
cur++ = scale * ((*
in >> 6) & 0x01);
+
5058 *
cur++ = scale * ((*
in >> 5) & 0x01);
+
5059 *
cur++ = scale * ((*
in >> 4) & 0x01);
+
5060 *
cur++ = scale * ((*
in >> 3) & 0x01);
+
5061 *
cur++ = scale * ((*
in >> 2) & 0x01);
+
5062 *
cur++ = scale * ((*
in >> 1) & 0x01);
+
5063 *
cur++ = scale * ((*in) & 0x01);
+
+
+
5066 *
cur++ = scale * ((*
in >> 7));
+
+
5068 *
cur++ = scale * ((*
in >> 6) & 0x01);
+
+
5070 *
cur++ = scale * ((*
in >> 5) & 0x01);
+
+
5072 *
cur++ = scale * ((*
in >> 4) & 0x01);
+
+
5074 *
cur++ = scale * ((*
in >> 3) & 0x01);
+
+
5076 *
cur++ = scale * ((*
in >> 2) & 0x01);
+
+
5078 *
cur++ = scale * ((*
in >> 1) & 0x01);
+
+
+
+
+
+
+
5085 for (q =
x - 1; q >= 0; --q) {
+
5086 cur[q * 2 + 1] = 255;
+
+
+
+
+
5091 for (q =
x - 1; q >= 0; --q) {
+
5092 cur[q * 4 + 3] = 255;
+
5093 cur[q * 4 + 2] =
cur[q * 3 + 2];
+
5094 cur[q * 4 + 1] =
cur[q * 3 + 1];
+
5095 cur[q * 4 + 0] =
cur[q * 3 + 0];
+
+
+
+
+
5100 }
else if (
depth == 16) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5128 return stbi__err(
"outofmem",
"Out of memory");
+
5129 for (p = 0; p < 7; ++p) {
+
5130 int xorig[] = {0, 4, 0, 2, 0, 1, 0};
+
5131 int yorig[] = {0, 0, 4, 0, 2, 0, 1};
+
5132 int xspc[] = {8, 8, 4, 4, 2, 2, 1};
+
5133 int yspc[] = {8, 8, 8, 4, 4, 2, 2};
+
+
+
+
+
+
+
+
+
+
+
5144 for (
j = 0;
j <
y; ++
j) {
+
5145 for (
i = 0;
i <
x; ++
i) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5173 p[1] = (p[0] ==
tc[0] ? 0 : 255);
+
+
+
+
+
5178 if (p[0] ==
tc[0] && p[1] ==
tc[1] && p[2] ==
tc[2])
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5197 p[1] = (p[0] ==
tc[0] ? 0 : 65535);
+
+
+
+
+
5202 if (p[0] ==
tc[0] && p[1] ==
tc[1] && p[2] ==
tc[2])
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5216 return stbi__err(
"outofmem",
"Out of memory");
+
+
+
+
+
+
+
5223 int n =
orig[
i] * 4;
+
+
+
+
+
+
+
+
5231 int n =
orig[
i] * 4;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5258#ifndef STBI_THREAD_LOCAL
+
5259#define stbi__unpremultiply_on_load stbi__unpremultiply_on_load_global
+
5260#define stbi__de_iphone_flag stbi__de_iphone_flag_global
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5275#define stbi__unpremultiply_on_load \
+
5276 (stbi__unpremultiply_on_load_set ? stbi__unpremultiply_on_load_local : stbi__unpremultiply_on_load_global)
+
5277#define stbi__de_iphone_flag (stbi__de_iphone_flag_set ? stbi__de_iphone_flag_local : stbi__de_iphone_flag_global)
+
+
+
+
+
+
+
+
5285 if (
s->img_out_n == 3) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5301 p[0] = (p[2] * 255 +
half) /
a;
+
5302 p[1] = (p[1] * 255 +
half) /
a;
+
5303 p[2] = (
t * 255 +
half) /
a;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5322#define STBI__PNG_TYPE(a, b, c, d) (((unsigned)(a) << 24) + ((unsigned)(b) << 16) + ((unsigned)(c) << 8) + (unsigned)(d))
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5352 return stbi__err(
"multiple IHDR",
"Corrupt PNG");
+
+
+
5355 return stbi__err(
"bad IHDR len",
"Corrupt PNG");
+
+
+
+
5359 return stbi__err(
"too large",
"Very large image (corrupt?)");
+
+
5361 return stbi__err(
"too large",
"Very large image (corrupt?)");
+
+
5363 if (
z->depth != 1 &&
z->depth != 2 &&
z->depth != 4 &&
z->depth != 8 &&
z->depth != 16)
+
5364 return stbi__err(
"1/2/4/8/16-bit only",
"PNG not supported: 1/2/4/8/16-bit only");
+
+
+
5367 return stbi__err(
"bad ctype",
"Corrupt PNG");
+
5368 if (
color == 3 &&
z->depth == 16)
+
5369 return stbi__err(
"bad ctype",
"Corrupt PNG");
+
+
+
+
5373 return stbi__err(
"bad ctype",
"Corrupt PNG");
+
+
+
5376 return stbi__err(
"bad comp method",
"Corrupt PNG");
+
+
+
5379 return stbi__err(
"bad filter method",
"Corrupt PNG");
+
+
+
5382 return stbi__err(
"bad interlace method",
"Corrupt PNG");
+
5383 if (!
s->img_x || !
s->img_y)
+
5384 return stbi__err(
"0-pixel image",
"Corrupt PNG");
+
+
5386 s->img_n = (
color & 2 ? 3 : 1) + (
color & 4 ? 1 : 0);
+
5387 if ((1 << 30) /
s->img_x /
s->img_n <
s->img_y)
+
5388 return stbi__err(
"too large",
"Image too large to decode");
+
+
+
+
+
5393 if ((1 << 30) /
s->img_x / 4 <
s->img_y)
+
5394 return stbi__err(
"too large",
"Corrupt PNG");
+
+
+
+
+
+
+
+
5402 return stbi__err(
"first not IHDR",
"Corrupt PNG");
+
5403 if (
c.length > 256 * 3)
+
5404 return stbi__err(
"invalid PLTE",
"Corrupt PNG");
+
+
+
5407 return stbi__err(
"invalid PLTE",
"Corrupt PNG");
+
+
+
+
+
+
+
+
+
+
+
+
5419 return stbi__err(
"first not IHDR",
"Corrupt PNG");
+
+
5421 return stbi__err(
"tRNS after IDAT",
"Corrupt PNG");
+
+
+
+
+
+
+
5428 return stbi__err(
"tRNS before PLTE",
"Corrupt PNG");
+
+
5430 return stbi__err(
"bad tRNS len",
"Corrupt PNG");
+
+
5432 for (
i = 0;
i <
c.length; ++
i)
+
+
+
5435 if (!(
s->img_n & 1))
+
5436 return stbi__err(
"tRNS with alpha",
"Corrupt PNG");
+
+
5438 return stbi__err(
"bad tRNS len",
"Corrupt PNG");
+
+
+
+
+
+
+
5445 if (
z->depth == 16) {
+
5446 for (k = 0; k <
s->img_n; ++k)
+
+
+
5449 for (k = 0; k <
s->img_n; ++k)
+
+
+
+
+
+
+
+
+
+
5459 return stbi__err(
"first not IHDR",
"Corrupt PNG");
+
+
5461 return stbi__err(
"no PLTE",
"Corrupt PNG");
+
+
+
+
+
+
+
5468 if (
c.length > (1u << 30))
+
5469 return stbi__err(
"IDAT size limit",
"IDAT section larger than 2^30 bytes");
+
+
+
+
+
+
+
+
+
+
+
+
+
5482 return stbi__err(
"outofmem",
"Out of memory");
+
+
+
+
5486 return stbi__err(
"outofdata",
"Corrupt PNG");
+
+
+
+
+
+
+
+
5494 return stbi__err(
"first not IHDR",
"Corrupt PNG");
+
+
+
5497 if (
z->idata ==
NULL)
+
5498 return stbi__err(
"no IDAT",
"Corrupt PNG");
+
+
5500 bpl = (
s->img_x *
z->depth + 7) / 8;
+
+
5502 z->expanded = (
stbi_uc *)stbi_zlib_decode_malloc_guesssize_headerflag((
char *)
z->idata,
ioff,
raw_len,
+
+
5504 if (
z->expanded ==
NULL)
+
+
+
+
+
5509 s->img_out_n =
s->img_n + 1;
+
+
5511 s->img_out_n =
s->img_n;
+
+
+
+
5515 if (
z->depth == 16) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5547 return stbi__err(
"first not IHDR",
"Corrupt PNG");
+
5548 if ((
c.type & (1 << 29)) == 0) {
+
5549#ifndef STBI_NO_FAILURE_STRINGS
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5573 ri->bits_per_channel = 8;
+
5574 else if (p->depth == 16)
+
5575 ri->bits_per_channel = 16;
+
+
5577 return stbi__errpuc(
"bad bits_per_channel",
"PNG not supported: unsupported color depth");
+
+
+
+
5581 if (
ri->bits_per_channel == 8)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5627 *
comp = p->s->img_n;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5642 if (p.depth != 16) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5665 r = (
sz == 12 ||
sz == 40 ||
sz == 56 ||
sz == 108 ||
sz == 124);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5703 a = (
a & 0x55555555) + ((
a >> 1) & 0x55555555);
+
5704 a = (
a & 0x33333333) + ((
a >> 2) & 0x33333333);
+
5705 a = (
a + (
a >> 4)) & 0x0f0f0f0f;
+
+
5707 a = (
a + (
a >> 16));
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5727 0, 0, 0, 1, 0, 2, 4, 6, 0,
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5751 if (
info->bpp == 16) {
+
5752 info->mr = 31u << 10;
+
5753 info->mg = 31u << 5;
+
5754 info->mb = 31u << 0;
+
5755 }
else if (
info->bpp == 32) {
+
5756 info->mr = 0xffu << 16;
+
5757 info->mg = 0xffu << 8;
+
5758 info->mb = 0xffu << 0;
+
5759 info->ma = 0xffu << 24;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5780 info->extra_read = 14;
+
+
5782 if (
info->offset < 0)
+
+
+
+
5786 return stbi__errpuc(
"unknown BMP",
"BMP type not supported: unknown");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5800 return stbi__errpuc(
"BMP RLE",
"BMP type not supported: RLE");
+
+
+
5803 "BMP type not supported: unsupported compression");
+
+
+
+
+
+
+
+
5811 if (
hsz == 40 ||
hsz == 56) {
+
+
+
+
+
+
+
5818 if (
info->bpp == 16 ||
info->bpp == 32) {
+
+
+
+
+
+
+
5825 info->extra_read += 12;
+
+
+
+
+
+
+
+
+
+
+
+
5837 if (
hsz != 108 &&
hsz != 124)
+
+
+
+
+
+
+
+
+
5846 for (
i = 0;
i < 12; ++
i)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5873 s->img_y =
abs((
int)
s->img_y);
+
+
+
5876 return stbi__errpuc(
"too large",
"Very large image (corrupt?)");
+
+
5878 return stbi__errpuc(
"too large",
"Very large image (corrupt?)");
+
+
+
+
+
+
+
+
5886 if (
info.hsz == 12) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5913 if (
info.bpp == 24 &&
ma == 0xff000000)
+
+
+
5916 s->img_n =
ma ? 4 : 3;
+
+
+
+
+
+
+
+
+
+
+
+
+
5929 if (
info.bpp < 16) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5945 width = (
s->img_x + 7) >> 3;
+
5946 else if (
info.bpp == 4)
+
5947 width = (
s->img_x + 1) >> 1;
+
5948 else if (
info.bpp == 8)
+
+
+
+
+
+
+
5955 if (
info.bpp == 1) {
+
5956 for (
j = 0;
j < (
int)
s->img_y; ++
j) {
+
+
5958 for (
i = 0;
i < (
int)
s->img_x; ++
i) {
+
+
+
+
+
+
+
5965 if (
i + 1 == (
int)
s->img_x)
+
+
+
+
+
+
+
+
+
+
5975 for (
j = 0;
j < (
int)
s->img_y; ++
j) {
+
5976 for (
i = 0;
i < (
int)
s->img_x;
i += 2) {
+
+
5978 if (
info.bpp == 4) {
+
+
+
+
+
+
+
+
+
5987 if (
i + 1 == (
int)
s->img_x)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6006 else if (
info.bpp == 16)
+
+
+
+
+
6011 if (
info.bpp == 24) {
+
+
6013 }
else if (
info.bpp == 32) {
+
6014 if (
mb == 0xff &&
mg == 0xff00 &&
mr == 0x00ff0000 &&
ma == 0xff000000)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6036 for (
j = 0;
j < (
int)
s->img_y; ++
j) {
+
+
6038 for (
i = 0;
i < (
int)
s->img_x; ++
i) {
+
+
+
+
+
+
+
+
+
+
+
+
+
6051 for (
i = 0;
i < (
int)
s->img_x; ++
i) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6069 for (
i = 4 *
s->img_x *
s->img_y - 1;
i >= 0;
i -= 4)
+
+
+
+
+
6074 for (
j = 0;
j < (
int)
s->img_y >> 1; ++
j) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6112 return STBI_grey_alpha;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6143 if ((
sz != 8) && (
sz != 15) && (
sz != 16) && (
sz != 24) && (
sz != 32)) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6202 if (
sz != 1 &&
sz != 9)
+
+
+
+
6206 if ((
sz != 8) && (
sz != 15) && (
sz != 16) && (
sz != 24) && (
sz != 32))
+
+
+
+
6210 if ((
sz != 2) && (
sz != 3) && (
sz != 10) && (
sz != 11))
+
+
+
+
+
+
+
+
+
+
+
6221 if ((
sz != 8) && (
sz != 15) && (
sz != 16) && (
sz != 24) && (
sz != 32))
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6280 return stbi__errpuc(
"too large",
"Very large image (corrupt?)");
+
+
6282 return stbi__errpuc(
"too large",
"Very large image (corrupt?)");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6298 return stbi__errpuc(
"bad format",
"Can't find out TGA pixelformat");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6463 }
else if (
len < 128) {
+
+
+
+
+
+
+
+
+
+
+
6474 }
else if (
len > 128) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6509 return stbi__errpuc(
"wrong version",
"Unsupported version of PSD image");
+
+
+
+
+
+
+
+
6517 return stbi__errpuc(
"wrong channel count",
"Unsupported number of channels in PSD image");
+
+
+
+
+
+
+
6524 return stbi__errpuc(
"too large",
"Very large image (corrupt?)");
+
+
6526 return stbi__errpuc(
"too large",
"Very large image (corrupt?)");
+
+
+
+
+
6531 return stbi__errpuc(
"unsupported bit depth",
"PSD bit depth is not 8 or 16 bit");
+
+
+
+
+
+
+
+
+
+
+
+
+
6544 return stbi__errpuc(
"wrong color format",
"PSD is not in RGB color format");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6561 return stbi__errpuc(
"bad compression",
"PSD has an unknown compression format");
+
+
+
+
+
+
+
+
+
+
6571 ri->bits_per_channel = 16;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6604 *p = (
channel == 3 ? 255 : 0);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6633 if (
ri->bits_per_channel == 16) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6653 if (
ri->bits_per_channel == 16) {
+
6654 for (
i = 0;
i <
w *
h; ++
i) {
+
+
+
6657 float a =
pixel[3] / 65535.0f;
+
6658 float ra = 1.0f /
a;
+
6659 float inv_a = 65535.0f * (1 -
ra);
+
+
+
+
+
+
+
6666 for (
i = 0;
i <
w *
h; ++
i) {
+
+
+
6669 float a =
pixel[3] / 255.0f;
+
6670 float ra = 1.0f /
a;
+
6671 float inv_a = 255.0f * (1 -
ra);
+
+
+
+
+
+
+
+
+
+
+
6682 if (
ri->bits_per_channel == 16)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6709 for (
i = 0;
i < 4; ++
i)
+
+
+
+
+
+
+
+
+
+
+
+
+
6722 for (
i = 0;
i < 84; ++
i)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6779 return stbi__errpuc(
"bad file",
"file too short (reading packets)");
+
+
6781 return stbi__errpuc(
"bad format",
"packet isn't 8bpp");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6795 return stbi__errpuc(
"bad format",
"packet has bad compression type");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6815 return stbi__errpuc(
"bad file",
"file too short (pure read count)");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6834 return stbi__errpuc(
"bad file",
"file too short (mixed read count)");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6879 for (
i = 0;
i < 92; ++
i)
+
+
+
+
+
+
+
6886 return stbi__errpuc(
"too large",
"Very large image (corrupt?)");
+
+
6888 return stbi__errpuc(
"too large",
"Very large image (corrupt?)");
+
+
+
6891 return stbi__errpuc(
"bad file",
"file too short (pic header)");
+
+
6893 return stbi__errpuc(
"too large",
"PIC image too large to decode");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6959 if (
sz !=
'9' &&
sz !=
'7')
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
6985 return stbi__err(
"not GIF",
"Corrupt GIF");
+
+
+
+
6989 return stbi__err(
"not GIF",
"Corrupt GIF");
+
+
6991 return stbi__err(
"not GIF",
"Corrupt GIF");
+
+
+
+
+
+
+
+
6999 g->transparent = -1;
+
+
+
7002 return stbi__err(
"too large",
"Very large image (corrupt?)");
+
+
7004 return stbi__err(
"too large",
"Very large image (corrupt?)");
+
+
+
+
+
+
+
+
7012 if (
g->flags & 0x80)
+
+
+
+
+
+
+
+
+
7021 return stbi__err(
"outofmem",
"Out of memory");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7041 if (
g->codes[
code].prefix >= 0)
+
+
+
7044 if (
g->cur_y >=
g->max_y)
+
+
+
7047 idx =
g->cur_x +
g->cur_y;
+
+
7049 g->history[idx / 4] = 1;
+
+
7051 c = &
g->color_table[
g->codes[
code].suffix * 4];
+
+
+
+
+
+
+
+
+
7060 if (
g->cur_x >=
g->max_x) {
+
7061 g->cur_x =
g->start_x;
+
7062 g->cur_y +=
g->step;
+
+
7064 while (
g->cur_y >=
g->max_y &&
g->parse > 0) {
+
7065 g->step = (1 <<
g->parse) *
g->line_size;
+
7066 g->cur_y =
g->start_y + (
g->step >> 1);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7137 p->first =
g->codes[
oldcode].first;
+
+
+
7140 return stbi__errpuc(
"illegal code in raster",
"Corrupt GIF");
+
+
+
+
+
+
+
+
+
+
+
7151 return stbi__errpuc(
"illegal code in raster",
"Corrupt GIF");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7172 return stbi__errpuc(
"too large",
"GIF image is too large");
+
+
+
+
+
7177 if (!
g->out || !
g->background || !
g->history)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7198 if (
g->history[
pi]) {
+
+
+
+
+
+
+
7205 if (
g->history[
pi]) {
+
+
+
+
+
+
+
+
+
+
+
+
7217 memcpy(
g->background,
g->out, 4 *
g->w *
g->h);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7235 if (((
x +
w) > (
g->w)) || ((
y +
h) > (
g->h)))
+
7236 return stbi__errpuc(
"bad Image Descriptor",
"Corrupt GIF");
+
+
7238 g->line_size =
g->w * 4;
+
+
7240 g->start_y =
y *
g->line_size;
+
7241 g->max_x =
g->start_x +
w * 4;
+
7242 g->max_y =
g->start_y +
h *
g->line_size;
+
7243 g->cur_x =
g->start_x;
+
7244 g->cur_y =
g->start_y;
+
+
+
+
+
+
+
7251 g->cur_y =
g->max_y;
+
+
+
+
7255 if (
g->lflags & 0x40) {
+
7256 g->step = 8 *
g->line_size;
+
+
+
7259 g->step =
g->line_size;
+
+
+
+
7263 if (
g->lflags & 0x80) {
+
+
+
7266 }
else if (
g->flags & 0x80) {
+
+
+
7269 return stbi__errpuc(
"missing color table",
"Corrupt GIF");
+
+
+
+
+
+
+
+
+
+
+
7280 if (
g->history[
pi] == 0) {
+
7281 g->pal[
g->bgindex][3] =
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7302 if (
g->transparent >= 0) {
+
7303 g->pal[
g->transparent][3] = 255;
+
+
7305 if (
g->eflags & 0x01) {
+
+
7307 if (
g->transparent >= 0) {
+
7308 g->pal[
g->transparent][3] = 0;
+
+
+
+
+
7313 g->transparent = -1;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7411 (*delays)[layers - 1U] =
g.delay;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7428 return stbi__errpuc(
"not GIF",
"Image was not as a gif type.");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7487#define STBI__HDR_BUFLEN 1024
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7510 if (input[3] != 0) {
+
+
+
+
+
7515 output[0] = (input[0] + input[1] + input[2]) *
f1 / 3;
+
+
7517 output[0] = input[0] *
f1;
+
7518 output[1] = input[1] *
f1;
+
7519 output[2] = input[2] *
f1;
+
+
+
+
+
+
+
+
+
+
+
7530 output[0] = output[1] = output[2] = 0;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7557 return stbi__errpf(
"not HDR",
"Corrupt HDR image");
+
+
+
+
+
+
+
+
+
+
+
+
7569 return stbi__errpf(
"unsupported format",
"Unsupported HDR format");
+
+
+
+
+
+
7575 return stbi__errpf(
"unsupported data layout",
"Unsupported HDR format");
+
+
+
7578 while (*
token ==
' ')
+
+
+
7581 return stbi__errpf(
"unsupported data layout",
"Unsupported HDR format");
+
+
+
+
+
7586 return stbi__errpf(
"too large",
"Very large image (corrupt?)");
+
+
7588 return stbi__errpf(
"too large",
"Very large image (corrupt?)");
+
+
+
+
+
+
+
+
+
+
+
7599 return stbi__errpf(
"too large",
"HDR image is too large");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7626 if (
c1 != 2 ||
c2 != 2 || (
len & 0x80)) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7645 return stbi__errpf(
"invalid decoded scanline length",
"corrupt HDR");
+
+
+
+
+
+
+
+
+
+
7655 for (k = 0; k < 4; ++k) {
+
+
+
+
+
+
+
+
+
+
+
+
7667 return stbi__errpf(
"corrupt",
"bad RLE data in HDR");
+
+
+
+
+
+
+
+
+
7676 return stbi__errpf(
"corrupt",
"bad RLE data in HDR");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7730 while (*
token ==
' ')
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7759 if (
info.bpp == 24 &&
info.ma == 0xff000000)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7858 if ((*
x) != 0 && (1 << 28) / (*
x) < (*
y)) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7911 if (p !=
'P' || (
t !=
'5' &&
t !=
'6')) {
+
+
+
+
+
+
+
+
+
+
+
7922 ri->bits_per_channel =
stbi__pnm_info(
s, (
int *)&
s->img_x, (
int *)&
s->img_y, (
int *)&
s->img_n);
+
7923 if (
ri->bits_per_channel == 0)
+
+
+
+
7927 return stbi__errpuc(
"too large",
"Very large image (corrupt?)");
+
+
7929 return stbi__errpuc(
"too large",
"Very large image (corrupt?)");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7948 if (
ri->bits_per_channel == 16) {
+
+
+
+
+
+
+
+
+
+
+
7959static int stbi__pnm_isspace(
char c) {
return c ==
' ' ||
c ==
'\t' ||
c ==
'\n' ||
c ==
'\v' ||
c ==
'\f' ||
c ==
'\r'; }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
7982 if ((
value > 214748364) || (
value == 214748364 && *
c >
'7'))
+
7983 return stbi__err(
"integer parse overflow",
"Parsing an integer in the PPM header overflowed a 32-bit int");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
8005 if (p !=
'P' || (
t !=
'5' &&
t !=
'6')) {
+
+
+
+
+
8010 *
comp = (
t ==
'6') ? 3 : 1;
+
+
+
+
+
+
+
8017 return stbi__err(
"invalid width",
"PPM image header had zero or overflowing width");
+
+
+
+
+
8022 return stbi__err(
"invalid width",
"PPM image header had zero or overflowing width");
+
+
+
+
+
8027 return stbi__err(
"max value > 65535",
"PPM image supports only 8-bit and 16-bit images");
+
8028 else if (
maxv > 255)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
8087 return stbi__err(
"unknown image type",
"Image not of any known type, or corrupt");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
8108#ifndef STBI_NO_STDIO
+
8109STBIDEF
int stbi_info(
char const *
filename,
int *
x,
int *
y,
int *
comp) {
+
+
+
+
8113 return stbi__err(
"can't fopen",
"Unable to open file");
+
+
+
+
+
+
8119STBIDEF
int stbi_info_from_file(
FILE *
f,
int *
x,
int *
y,
int *
comp) {
+
+
+
+
+
+
+
+
+
+
8129STBIDEF
int stbi_is_16_bit(
char const *
filename) {
+
+
+
+
8133 return stbi__err(
"can't fopen",
"Unable to open file");
+
8134 result = stbi_is_16_bit_from_file(
f);
+
+
+
+
+
8139STBIDEF
int stbi_is_16_bit_from_file(
FILE *
f) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Definition stb_image.h:408
+