aboutsummaryrefslogtreecommitdiff
path: root/mwe/resource-manager
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-15 20:39:07 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-15 20:39:07 +0100
commite8cd950b8ebd152d76d588d4fedc7f4c239b0835 (patch)
tree7919d13a79d52f1365bc19bf1b435a6264ee5512 /mwe/resource-manager
parent5bee4515c1089ce3499bc3b74780db94f0c02306 (diff)
parent9f6475e7b0698c414138e2a8140b47f01ce9c5d1 (diff)
merge `master` into `loek/cleanup`
Diffstat (limited to 'mwe/resource-manager')
-rw-r--r--mwe/resource-manager/TextureMap.cpp10
-rw-r--r--mwe/resource-manager/main.cpp5
-rw-r--r--mwe/resource-manager/map_layer.cpp41
-rw-r--r--mwe/resource-manager/resource_converter.cpp3
-rw-r--r--mwe/resource-manager/spritesheet.cpp4
-rw-r--r--mwe/resource-manager/stb_image.h1501
-rw-r--r--mwe/resource-manager/tiledMap.cpp6
7 files changed, 598 insertions, 972 deletions
diff --git a/mwe/resource-manager/TextureMap.cpp b/mwe/resource-manager/TextureMap.cpp
index d82975c..284f8a8 100644
--- a/mwe/resource-manager/TextureMap.cpp
+++ b/mwe/resource-manager/TextureMap.cpp
@@ -15,8 +15,7 @@ TextureMap::~TextureMap() {
}
//public
-bool TextureMap::loadFromFile(const std::string & path,
- SDL_Renderer * renderer) {
+bool TextureMap::loadFromFile(const std::string & path, SDL_Renderer * renderer) {
assert(renderer != nullptr);
assert(!path.empty());
@@ -34,12 +33,11 @@ bool TextureMap::loadFromFile(const std::string & path,
constexpr std::int32_t bmask = 0x00ff0000;
const std::int32_t amask = c == 4 ? 0xff000000 : 0;
- auto * surface = SDL_CreateRGBSurfaceFrom(data, x, y, c * 8, pitch,
- rmask, gmask, bmask, amask);
+ auto * surface
+ = SDL_CreateRGBSurfaceFrom(data, x, y, c * 8, pitch, rmask, gmask, bmask, amask);
if (!surface) {
- std::cerr << "Unable to create texture surface: " << SDL_GetError()
- << "\n";
+ std::cerr << "Unable to create texture surface: " << SDL_GetError() << "\n";
stbi_image_free(data);
return false;
}
diff --git a/mwe/resource-manager/main.cpp b/mwe/resource-manager/main.cpp
index b6416f6..1910af8 100644
--- a/mwe/resource-manager/main.cpp
+++ b/mwe/resource-manager/main.cpp
@@ -23,9 +23,8 @@ int main() {
SDL_Event event;
- SDL_Window * window
- = SDL_CreateWindow("Tessting resources", SDL_WINDOWPOS_UNDEFINED,
- SDL_WINDOWPOS_UNDEFINED, 640, 480, 0);
+ SDL_Window * window = SDL_CreateWindow("Tessting resources", SDL_WINDOWPOS_UNDEFINED,
+ SDL_WINDOWPOS_UNDEFINED, 640, 480, 0);
SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, 0);
diff --git a/mwe/resource-manager/map_layer.cpp b/mwe/resource-manager/map_layer.cpp
index 6339707..17792a6 100644
--- a/mwe/resource-manager/map_layer.cpp
+++ b/mwe/resource-manager/map_layer.cpp
@@ -20,8 +20,7 @@ bool MapLayer::create(const tmx::Map & map, std::uint32_t layerIndex,
const auto & tileSets = map.getTilesets();
const auto tintColour = layer.getTintColour();
- const SDL_Colour vertColour
- = {tintColour.r, tintColour.g, tintColour.b, tintColour.a};
+ const SDL_Colour vertColour = {tintColour.r, tintColour.g, tintColour.b, tintColour.a};
for (auto i = 0u; i < tileSets.size(); ++i) {
//check tile ID to see if it falls within the current tile set
@@ -40,8 +39,7 @@ bool MapLayer::create(const tmx::Map & map, std::uint32_t layerIndex,
for (auto x = 0u; x < mapSize.x; ++x) {
const auto idx = y * mapSize.x + x;
if (idx < tileIDs.size() && tileIDs[idx].ID >= ts.getFirstGID()
- && tileIDs[idx].ID
- < (ts.getFirstGID() + ts.getTileCount())) {
+ && tileIDs[idx].ID < (ts.getFirstGID() + ts.getTileCount())) {
//tex coords
auto idIndex = (tileIDs[idx].ID - ts.getFirstGID());
float u = static_cast<float>(idIndex % tileCountX);
@@ -55,36 +53,24 @@ bool MapLayer::create(const tmx::Map & map, std::uint32_t layerIndex,
v /= textures[i]->getSize().y;
//vert pos
- const float tilePosX
- = static_cast<float>(x) * mapTileSize.x;
- const float tilePosY
- = (static_cast<float>(y) * mapTileSize.y);
+ const float tilePosX = static_cast<float>(x) * mapTileSize.x;
+ const float tilePosY = (static_cast<float>(y) * mapTileSize.y);
//push back to vert array
- SDL_Vertex vert
- = {{tilePosX, tilePosY}, vertColour, {u, v}};
+ SDL_Vertex vert = {{tilePosX, tilePosY}, vertColour, {u, v}};
verts.emplace_back(vert);
- vert = {{tilePosX + mapTileSize.x, tilePosY},
- vertColour,
- {u + uNorm, v}};
+ vert = {{tilePosX + mapTileSize.x, tilePosY}, vertColour, {u + uNorm, v}};
verts.emplace_back(vert);
- vert = {{tilePosX, tilePosY + mapTileSize.y},
- vertColour,
- {u, v + vNorm}};
+ vert = {{tilePosX, tilePosY + mapTileSize.y}, vertColour, {u, v + vNorm}};
verts.emplace_back(vert);
- vert = {{tilePosX, tilePosY + mapTileSize.y},
- vertColour,
- {u, v + vNorm}};
+ vert = {{tilePosX, tilePosY + mapTileSize.y}, vertColour, {u, v + vNorm}};
verts.emplace_back(vert);
- vert = {{tilePosX + mapTileSize.x, tilePosY},
- vertColour,
- {u + uNorm, v}};
+ vert = {{tilePosX + mapTileSize.x, tilePosY}, vertColour, {u + uNorm, v}};
verts.emplace_back(vert);
- vert
- = {{tilePosX + mapTileSize.x, tilePosY + mapTileSize.y},
- vertColour,
- {u + uNorm, v + vNorm}};
+ vert = {{tilePosX + mapTileSize.x, tilePosY + mapTileSize.y},
+ vertColour,
+ {u + uNorm, v + vNorm}};
verts.emplace_back(vert);
}
}
@@ -104,7 +90,6 @@ void MapLayer::draw(SDL_Renderer * renderer) const {
assert(renderer);
for (const auto & s : m_subsets) {
SDL_RenderGeometry(renderer, s.texture, s.vertexData.data(),
- static_cast<std::int32_t>(s.vertexData.size()),
- nullptr, 0);
+ static_cast<std::int32_t>(s.vertexData.size()), nullptr, 0);
}
}
diff --git a/mwe/resource-manager/resource_converter.cpp b/mwe/resource-manager/resource_converter.cpp
index 0477dc2..632f630 100644
--- a/mwe/resource-manager/resource_converter.cpp
+++ b/mwe/resource-manager/resource_converter.cpp
@@ -17,8 +17,7 @@ SDL_Surface * ResourceConverter::FromStringToImage(const Texture & resource) {
const std::string & content = resource.getContent();
SDL_RWops * rw = SDL_RWFromConstMem(content.data(), content.size());
if (!rw) {
- std::cerr << "Failed to create SDL_RWops: " << SDL_GetError()
- << std::endl;
+ std::cerr << "Failed to create SDL_RWops: " << SDL_GetError() << std::endl;
return nullptr;
}
diff --git a/mwe/resource-manager/spritesheet.cpp b/mwe/resource-manager/spritesheet.cpp
index a5881e5..9739e01 100644
--- a/mwe/resource-manager/spritesheet.cpp
+++ b/mwe/resource-manager/spritesheet.cpp
@@ -4,8 +4,6 @@
#include <string>
-SpriteSheet::SpriteSheet(const std::string & content) {
- this->m_content = content;
-}
+SpriteSheet::SpriteSheet(const std::string & content) { this->m_content = content; }
SpriteSheet::~SpriteSheet() {}
diff --git a/mwe/resource-manager/stb_image.h b/mwe/resource-manager/stb_image.h
index ce0cc10..3462f3a 100644
--- a/mwe/resource-manager/stb_image.h
+++ b/mwe/resource-manager/stb_image.h
@@ -410,9 +410,8 @@ typedef struct {
int (*read)(
void * user, char * data,
int size); // fill 'data' with 'size' bytes. return number of bytes actually read
- void (*skip)(
- void * user,
- int n); // skip the next 'n' bytes, or 'unget' the last -n bytes if negative
+ void (*skip)(void * user,
+ int n); // skip the next 'n' bytes, or 'unget' the last -n bytes if negative
int (*eof)(void * user); // returns nonzero if we are at end of file/data
} stbi_io_callbacks;
@@ -421,33 +420,28 @@ typedef struct {
// 8-bits-per-channel interface
//
-STBIDEF stbi_uc * stbi_load_from_memory(stbi_uc const * buffer, int len,
- int * x, int * y,
- int * channels_in_file,
- int desired_channels);
-STBIDEF stbi_uc * stbi_load_from_callbacks(stbi_io_callbacks const * clbk,
- void * user, int * x, int * y,
- int * channels_in_file,
+STBIDEF stbi_uc * stbi_load_from_memory(stbi_uc const * buffer, int len, int * x, int * y,
+ int * channels_in_file, int desired_channels);
+STBIDEF stbi_uc * stbi_load_from_callbacks(stbi_io_callbacks const * clbk, void * user,
+ int * x, int * y, int * channels_in_file,
int desired_channels);
#ifndef STBI_NO_STDIO
-STBIDEF stbi_uc * stbi_load(char const * filename, int * x, int * y,
- int * channels_in_file, int desired_channels);
-STBIDEF stbi_uc * stbi_load_from_file(FILE * f, int * x, int * y,
- int * channels_in_file,
+STBIDEF stbi_uc * stbi_load(char const * filename, int * x, int * y, int * channels_in_file,
+ int desired_channels);
+STBIDEF stbi_uc * stbi_load_from_file(FILE * f, int * x, int * y, int * channels_in_file,
int desired_channels);
// for stbi_load_from_file, file pointer is left pointing immediately after image
#endif
#ifndef STBI_NO_GIF
-STBIDEF stbi_uc * stbi_load_gif_from_memory(stbi_uc const * buffer, int len,
- int ** delays, int * x, int * y,
- int * z, int * comp, int req_comp);
+STBIDEF stbi_uc * stbi_load_gif_from_memory(stbi_uc const * buffer, int len, int ** delays,
+ int * x, int * y, int * z, int * comp,
+ int req_comp);
#endif
#ifdef STBI_WINDOWS_UTF8
-STBIDEF int stbi_convert_wchar_to_utf8(char * buffer, size_t bufferlen,
- const wchar_t * input);
+STBIDEF int stbi_convert_wchar_to_utf8(char * buffer, size_t bufferlen, const wchar_t * input);
#endif
////////////////////////////////////
@@ -455,20 +449,16 @@ STBIDEF int stbi_convert_wchar_to_utf8(char * buffer, size_t bufferlen,
// 16-bits-per-channel interface
//
-STBIDEF stbi_us * stbi_load_16_from_memory(stbi_uc const * buffer, int len,
- int * x, int * y,
- int * channels_in_file,
- int desired_channels);
-STBIDEF stbi_us * stbi_load_16_from_callbacks(stbi_io_callbacks const * clbk,
- void * user, int * x, int * y,
- int * channels_in_file,
+STBIDEF stbi_us * stbi_load_16_from_memory(stbi_uc const * buffer, int len, int * x, int * y,
+ int * channels_in_file, int desired_channels);
+STBIDEF stbi_us * stbi_load_16_from_callbacks(stbi_io_callbacks const * clbk, void * user,
+ int * x, int * y, int * channels_in_file,
int desired_channels);
#ifndef STBI_NO_STDIO
-STBIDEF stbi_us * stbi_load_16(char const * filename, int * x, int * y,
- int * channels_in_file, int desired_channels);
-STBIDEF stbi_us * stbi_load_from_file_16(FILE * f, int * x, int * y,
- int * channels_in_file,
+STBIDEF stbi_us * stbi_load_16(char const * filename, int * x, int * y, int * channels_in_file,
+ int desired_channels);
+STBIDEF stbi_us * stbi_load_from_file_16(FILE * f, int * x, int * y, int * channels_in_file,
int desired_channels);
#endif
@@ -477,19 +467,16 @@ STBIDEF stbi_us * stbi_load_from_file_16(FILE * f, int * x, int * y,
// float-per-channel interface
//
#ifndef STBI_NO_LINEAR
-STBIDEF float * stbi_loadf_from_memory(stbi_uc const * buffer, int len, int * x,
- int * y, int * channels_in_file,
- int desired_channels);
-STBIDEF float * stbi_loadf_from_callbacks(stbi_io_callbacks const * clbk,
- void * user, int * x, int * y,
- int * channels_in_file,
+STBIDEF float * stbi_loadf_from_memory(stbi_uc const * buffer, int len, int * x, int * y,
+ int * channels_in_file, int desired_channels);
+STBIDEF float * stbi_loadf_from_callbacks(stbi_io_callbacks const * clbk, void * user, int * x,
+ int * y, int * channels_in_file,
int desired_channels);
#ifndef STBI_NO_STDIO
-STBIDEF float * stbi_loadf(char const * filename, int * x, int * y,
- int * channels_in_file, int desired_channels);
-STBIDEF float * stbi_loadf_from_file(FILE * f, int * x, int * y,
- int * channels_in_file,
+STBIDEF float * stbi_loadf(char const * filename, int * x, int * y, int * channels_in_file,
+ int desired_channels);
+STBIDEF float * stbi_loadf_from_file(FILE * f, int * x, int * y, int * channels_in_file,
int desired_channels);
#endif
#endif
@@ -505,8 +492,7 @@ STBIDEF void stbi_ldr_to_hdr_scale(float scale);
#endif // STBI_NO_LINEAR
// stbi_is_hdr is always defined, but always returns false if STBI_NO_HDR
-STBIDEF int stbi_is_hdr_from_callbacks(stbi_io_callbacks const * clbk,
- void * user);
+STBIDEF int stbi_is_hdr_from_callbacks(stbi_io_callbacks const * clbk, void * user);
STBIDEF int stbi_is_hdr_from_memory(stbi_uc const * buffer, int len);
#ifndef STBI_NO_STDIO
STBIDEF int stbi_is_hdr(char const * filename);
@@ -521,13 +507,12 @@ STBIDEF const char * stbi_failure_reason(void);
STBIDEF void stbi_image_free(void * retval_from_stbi_load);
// get image dimensions & components without fully decoding
-STBIDEF int stbi_info_from_memory(stbi_uc const * buffer, int len, int * x,
- int * y, int * comp);
-STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const * clbk,
- void * user, int * x, int * y, int * comp);
+STBIDEF int stbi_info_from_memory(stbi_uc const * buffer, int len, int * x, int * y,
+ int * comp);
+STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const * clbk, void * user, int * x,
+ int * y, int * comp);
STBIDEF int stbi_is_16_bit_from_memory(stbi_uc const * buffer, int len);
-STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const * clbk,
- void * user);
+STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const * clbk, void * user);
#ifndef STBI_NO_STDIO
STBIDEF int stbi_info(char const * filename, int * x, int * y, int * comp);
@@ -539,8 +524,7 @@ STBIDEF int stbi_is_16_bit_from_file(FILE * f);
// for image formats that explicitly notate that they have premultiplied alpha,
// we just return the colors as stored in the file. set this flag to force
// unpremultiplication. results are undefined if the unpremultiply overflow.
-STBIDEF void
-stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply);
+STBIDEF void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply);
// indicate whether we should process iphone images back to canonical format,
// or just pass them through "as-is"
@@ -552,32 +536,23 @@ STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip);
// as above, but only applies to images loaded on the thread that calls the function
// this function is only available if your compiler supports thread-local variables;
// calling it will fail to link if your compiler doesn't
-STBIDEF void
-stbi_set_unpremultiply_on_load_thread(int flag_true_if_should_unpremultiply);
-STBIDEF void
-stbi_convert_iphone_png_to_rgb_thread(int flag_true_if_should_convert);
-STBIDEF void
-stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_flip);
+STBIDEF void stbi_set_unpremultiply_on_load_thread(int flag_true_if_should_unpremultiply);
+STBIDEF void stbi_convert_iphone_png_to_rgb_thread(int flag_true_if_should_convert);
+STBIDEF void stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_flip);
// ZLIB client - used by PNG, available for other purposes
STBIDEF char * stbi_zlib_decode_malloc_guesssize(const char * buffer, int len,
- int initial_size,
- int * outlen);
-STBIDEF char * stbi_zlib_decode_malloc_guesssize_headerflag(const char * buffer,
- int len,
- int initial_size,
- int * outlen,
+ int initial_size, int * outlen);
+STBIDEF char * stbi_zlib_decode_malloc_guesssize_headerflag(const char * buffer, int len,
+ int initial_size, int * outlen,
int parse_header);
-STBIDEF char * stbi_zlib_decode_malloc(const char * buffer, int len,
- int * outlen);
-STBIDEF int stbi_zlib_decode_buffer(char * obuffer, int olen,
- const char * ibuffer, int ilen);
+STBIDEF char * stbi_zlib_decode_malloc(const char * buffer, int len, int * outlen);
+STBIDEF int stbi_zlib_decode_buffer(char * obuffer, int olen, const char * ibuffer, int ilen);
-STBIDEF char * stbi_zlib_decode_noheader_malloc(const char * buffer, int len,
- int * outlen);
-STBIDEF int stbi_zlib_decode_noheader_buffer(char * obuffer, int olen,
- const char * ibuffer, int ilen);
+STBIDEF char * stbi_zlib_decode_noheader_malloc(const char * buffer, int len, int * outlen);
+STBIDEF int stbi_zlib_decode_noheader_buffer(char * obuffer, int olen, const char * ibuffer,
+ int ilen);
#ifdef __cplusplus
}
@@ -590,11 +565,10 @@ STBIDEF int stbi_zlib_decode_noheader_buffer(char * obuffer, int olen,
#ifdef STB_IMAGE_IMPLEMENTATION
-#if defined(STBI_ONLY_JPEG) || defined(STBI_ONLY_PNG) \
- || defined(STBI_ONLY_BMP) || defined(STBI_ONLY_TGA) \
- || defined(STBI_ONLY_GIF) || defined(STBI_ONLY_PSD) \
- || defined(STBI_ONLY_HDR) || defined(STBI_ONLY_PIC) \
- || defined(STBI_ONLY_PNM) || defined(STBI_ONLY_ZLIB)
+#if defined(STBI_ONLY_JPEG) || defined(STBI_ONLY_PNG) || defined(STBI_ONLY_BMP) \
+ || defined(STBI_ONLY_TGA) || defined(STBI_ONLY_GIF) || defined(STBI_ONLY_PSD) \
+ || defined(STBI_ONLY_HDR) || defined(STBI_ONLY_PIC) || defined(STBI_ONLY_PNM) \
+ || defined(STBI_ONLY_ZLIB)
#ifndef STBI_ONLY_JPEG
#define STBI_NO_JPEG
#endif
@@ -624,8 +598,7 @@ STBIDEF int stbi_zlib_decode_noheader_buffer(char * obuffer, int olen,
#endif
#endif
-#if defined(STBI_NO_PNG) && !defined(STBI_SUPPORT_ZLIB) \
- && !defined(STBI_NO_ZLIB)
+#if defined(STBI_NO_PNG) && !defined(STBI_SUPPORT_ZLIB) && !defined(STBI_NO_ZLIB)
#define STBI_NO_ZLIB
#endif
@@ -671,8 +644,7 @@ STBIDEF int stbi_zlib_decode_noheader_buffer(char * obuffer, int olen,
#define STBI_THREAD_LOCAL __thread
#elif defined(_MSC_VER)
#define STBI_THREAD_LOCAL __declspec(thread)
-#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \
- && !defined(__STDC_NO_THREADS__)
+#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
#define STBI_THREAD_LOCAL _Thread_local
#endif
@@ -755,8 +727,8 @@ typedef unsigned char validate_uint32[sizeof(stbi__uint32) == 4 ? 1 : -1];
#define STBI_NO_SIMD
#endif
-#if defined(__MINGW32__) && defined(STBI__X86_TARGET) \
- && !defined(STBI_MINGW_ENABLE_SSE2) && !defined(STBI_NO_SIMD)
+#if defined(__MINGW32__) && defined(STBI__X86_TARGET) && !defined(STBI_MINGW_ENABLE_SSE2) \
+ && !defined(STBI_NO_SIMD)
// Note that __MINGW32__ doesn't actually mean 32-bit, so we have to avoid STBI__X64_TARGET
//
// 32-bit MinGW wants ESP to be 16-byte aligned, but this is not in the
@@ -771,8 +743,7 @@ typedef unsigned char validate_uint32[sizeof(stbi__uint32) == 4 ? 1 : -1];
#define STBI_NO_SIMD
#endif
-#if !defined(STBI_NO_SIMD) \
- && (defined(STBI__X86_TARGET) || defined(STBI__X64_TARGET))
+#if !defined(STBI_NO_SIMD) && (defined(STBI__X86_TARGET) || defined(STBI__X64_TARGET))
#define STBI_SSE2
#include <emmintrin.h>
@@ -868,8 +839,7 @@ typedef struct {
static void stbi__refill_buffer(stbi__context * s);
// initialize a memory-decode context
-static void stbi__start_mem(stbi__context * s, stbi_uc const * buffer,
- int len) {
+static void stbi__start_mem(stbi__context * s, stbi_uc const * buffer, int len) {
s->io.read = NULL;
s->read_from_callbacks = 0;
s->callback_already_read = 0;
@@ -878,8 +848,7 @@ static void stbi__start_mem(stbi__context * s, stbi_uc const * buffer,
}
// initialize a callback-based context
-static void stbi__start_callbacks(stbi__context * s, stbi_io_callbacks * c,
- void * user) {
+static void stbi__start_callbacks(stbi__context * s, stbi_io_callbacks * c, void * user) {
s->io = *c;
s->io_user_data = user;
s->buflen = sizeof(s->buffer_start);
@@ -941,68 +910,68 @@ typedef struct {
#ifndef STBI_NO_JPEG
static int stbi__jpeg_test(stbi__context * s);
-static void * stbi__jpeg_load(stbi__context * s, int * x, int * y, int * comp,
- int req_comp, stbi__result_info * ri);
+static void * stbi__jpeg_load(stbi__context * s, int * x, int * y, int * comp, int req_comp,
+ stbi__result_info * ri);
static int stbi__jpeg_info(stbi__context * s, int * x, int * y, int * comp);
#endif
#ifndef STBI_NO_PNG
static int stbi__png_test(stbi__context * s);
-static void * stbi__png_load(stbi__context * s, int * x, int * y, int * comp,
- int req_comp, stbi__result_info * ri);
+static void * stbi__png_load(stbi__context * s, int * x, int * y, int * comp, int req_comp,
+ stbi__result_info * ri);
static int stbi__png_info(stbi__context * s, int * x, int * y, int * comp);
static int stbi__png_is16(stbi__context * s);
#endif
#ifndef STBI_NO_BMP
static int stbi__bmp_test(stbi__context * s);
-static void * stbi__bmp_load(stbi__context * s, int * x, int * y, int * comp,
- int req_comp, stbi__result_info * ri);
+static void * stbi__bmp_load(stbi__context * s, int * x, int * y, int * comp, int req_comp,
+ stbi__result_info * ri);
static int stbi__bmp_info(stbi__context * s, int * x, int * y, int * comp);
#endif
#ifndef STBI_NO_TGA
static int stbi__tga_test(stbi__context * s);
-static void * stbi__tga_load(stbi__context * s, int * x, int * y, int * comp,
- int req_comp, stbi__result_info * ri);
+static void * stbi__tga_load(stbi__context * s, int * x, int * y, int * comp, int req_comp,
+ stbi__result_info * ri);
static int stbi__tga_info(stbi__context * s, int * x, int * y, int * comp);
#endif
#ifndef STBI_NO_PSD
static int stbi__psd_test(stbi__context * s);
-static void * stbi__psd_load(stbi__context * s, int * x, int * y, int * comp,
- int req_comp, stbi__result_info * ri, int bpc);
+static void * stbi__psd_load(stbi__context * s, int * x, int * y, int * comp, int req_comp,
+ stbi__result_info * ri, int bpc);
static int stbi__psd_info(stbi__context * s, int * x, int * y, int * comp);
static int stbi__psd_is16(stbi__context * s);
#endif
#ifndef STBI_NO_HDR
static int stbi__hdr_test(stbi__context * s);
-static float * stbi__hdr_load(stbi__context * s, int * x, int * y, int * comp,
- int req_comp, stbi__result_info * ri);
+static float * stbi__hdr_load(stbi__context * s, int * x, int * y, int * comp, int req_comp,
+ stbi__result_info * ri);
static int stbi__hdr_info(stbi__context * s, int * x, int * y, int * comp);
#endif
#ifndef STBI_NO_PIC
static int stbi__pic_test(stbi__context * s);
-static void * stbi__pic_load(stbi__context * s, int * x, int * y, int * comp,
- int req_comp, stbi__result_info * ri);
+static void * stbi__pic_load(stbi__context * s, int * x, int * y, int * comp, int req_comp,
+ stbi__result_info * ri);
static int stbi__pic_info(stbi__context * s, int * x, int * y, int * comp);
#endif
#ifndef STBI_NO_GIF
static int stbi__gif_test(stbi__context * s);
-static void * stbi__gif_load(stbi__context * s, int * x, int * y, int * comp,
- int req_comp, stbi__result_info * ri);
-static void * stbi__load_gif_main(stbi__context * s, int ** delays, int * x,
- int * y, int * z, int * comp, int req_comp);
+static void * stbi__gif_load(stbi__context * s, int * x, int * y, int * comp, int req_comp,
+ stbi__result_info * ri);
+static void * stbi__load_gif_main(stbi__context * s, int ** delays, int * x, int * y, int * z,
+ int * comp, int req_comp);
static int stbi__gif_info(stbi__context * s, int * x, int * y, int * comp);
#endif
#ifndef STBI_NO_PNM
static int stbi__pnm_test(stbi__context * s);
-static void * stbi__pnm_load(stbi__context * s, int * x, int * y, int * comp,
- int req_comp, stbi__result_info * ri);
+static void * stbi__pnm_load(stbi__context * s, int * x, int * y, int * comp, int req_comp,
+ stbi__result_info * ri);
static int stbi__pnm_info(stbi__context * s, int * x, int * y, int * comp);
static int stbi__pnm_is16(stbi__context * s);
#endif
@@ -1013,9 +982,7 @@ static
#endif
const char * stbi__g_failure_reason;
-STBIDEF const char * stbi_failure_reason(void) {
- return stbi__g_failure_reason;
-}
+STBIDEF const char * stbi_failure_reason(void) { return stbi__g_failure_reason; }
#ifndef STBI_NO_FAILURE_STRINGS
static int stbi__err(const char * str) {
@@ -1074,8 +1041,7 @@ static int stbi__mad3sizes_valid(int a, int b, int c, int add) {
#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM)
static int stbi__mad4sizes_valid(int a, int b, int c, int d, int add) {
return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a * b, c)
- && stbi__mul2sizes_valid(a * b * c, d)
- && stbi__addsizes_valid(a * b * c * d, add);
+ && stbi__mul2sizes_valid(a * b * c, d) && stbi__addsizes_valid(a * b * c * d, add);
}
#endif
@@ -1102,8 +1068,7 @@ static void * stbi__malloc_mad4(int a, int b, int c, int d, int add) {
// returns 1 if the sum of two signed ints is valid (between -2^31 and 2^31-1 inclusive), 0 on overflow.
static int stbi__addints_valid(int a, int b) {
- if ((a >= 0) != (b >= 0))
- return 1; // a and b have different signs, so no overflow
+ if ((a >= 0) != (b >= 0)) return 1; // a and b have different signs, so no overflow
if (a < 0 && b < 0)
return a
>= INT_MIN
@@ -1116,9 +1081,7 @@ static int stbi__mul2shorts_valid(int a, int b) {
if (b == 0 || b == -1)
return 1; // multiplication by 0 is always 0; check for -1 so SHRT_MIN/b doesn't overflow
if ((a >= 0) == (b >= 0))
- return a
- <= SHRT_MAX
- / b; // product is positive, so similar to mul2sizes_valid
+ return a <= SHRT_MAX / b; // product is positive, so similar to mul2sizes_valid
if (b < 0) return a <= SHRT_MIN / b; // same as a * b >= SHRT_MIN
return a >= SHRT_MIN / b;
}
@@ -1136,8 +1099,7 @@ static int stbi__mul2shorts_valid(int a, int b) {
#endif
#define stbi__errpf(x, y) ((float *) (size_t) (stbi__err(x, y) ? NULL : NULL))
-#define stbi__errpuc(x, y) \
- ((unsigned char *) (size_t) (stbi__err(x, y) ? NULL : NULL))
+#define stbi__errpuc(x, y) ((unsigned char *) (size_t) (stbi__err(x, y) ? NULL : NULL))
STBIDEF void stbi_image_free(void * retval_from_stbi_load) {
STBI_FREE(retval_from_stbi_load);
@@ -1163,8 +1125,7 @@ STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip) {
static STBI_THREAD_LOCAL int stbi__vertically_flip_on_load_local,
stbi__vertically_flip_on_load_set;
-STBIDEF void
-stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_flip) {
+STBIDEF void stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_flip) {
stbi__vertically_flip_on_load_local = flag_true_if_should_flip;
stbi__vertically_flip_on_load_set = 1;
}
@@ -1174,12 +1135,11 @@ stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_flip) {
: stbi__vertically_flip_on_load_global)
#endif // STBI_THREAD_LOCAL
-static void * stbi__load_main(stbi__context * s, int * x, int * y, int * comp,
- int req_comp, stbi__result_info * ri, int bpc) {
+static void * stbi__load_main(stbi__context * s, int * x, int * y, int * comp, int req_comp,
+ stbi__result_info * ri, int bpc) {
memset(ri, 0,
sizeof(*ri)); // make sure it's initialized if we add new fields
- ri->bits_per_channel
- = 8; // default is 8 so most paths don't have to be changed
+ ri->bits_per_channel = 8; // default is 8 so most paths don't have to be changed
ri->channel_order
= STBI_ORDER_RGB; // all current input & output are this, but this is here so we can add BGR order
ri->num_channels = 0;
@@ -1196,8 +1156,7 @@ static void * stbi__load_main(stbi__context * s, int * x, int * y, int * comp,
if (stbi__gif_test(s)) return stbi__gif_load(s, x, y, comp, req_comp, ri);
#endif
#ifndef STBI_NO_PSD
- if (stbi__psd_test(s))
- return stbi__psd_load(s, x, y, comp, req_comp, ri, bpc);
+ if (stbi__psd_test(s)) return stbi__psd_load(s, x, y, comp, req_comp, ri, bpc);
#else
STBI_NOTUSED(bpc);
#endif
@@ -1227,12 +1186,10 @@ static void * stbi__load_main(stbi__context * s, int * x, int * y, int * comp,
if (stbi__tga_test(s)) return stbi__tga_load(s, x, y, comp, req_comp, ri);
#endif
- return stbi__errpuc("unknown image type",
- "Image not of any known type, or corrupt");
+ return stbi__errpuc("unknown image type", "Image not of any known type, or corrupt");
}
-static stbi_uc * stbi__convert_16_to_8(stbi__uint16 * orig, int w, int h,
- int channels) {
+static stbi_uc * stbi__convert_16_to_8(stbi__uint16 * orig, int w, int h, int channels) {
int i;
int img_len = w * h * channels;
stbi_uc * reduced;
@@ -1249,15 +1206,13 @@ static stbi_uc * stbi__convert_16_to_8(stbi__uint16 * orig, int w, int h,
return reduced;
}
-static stbi__uint16 * stbi__convert_8_to_16(stbi_uc * orig, int w, int h,
- int channels) {
+static stbi__uint16 * stbi__convert_8_to_16(stbi_uc * orig, int w, int h, int channels) {
int i;
int img_len = w * h * channels;
stbi__uint16 * enlarged;
enlarged = (stbi__uint16 *) stbi__malloc(img_len * 2);
- if (enlarged == NULL)
- return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory");
+ if (enlarged == NULL) return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory");
for (i = 0; i < img_len; ++i)
enlarged[i]
@@ -1269,8 +1224,7 @@ static stbi__uint16 * stbi__convert_8_to_16(stbi_uc * orig, int w, int h,
return enlarged;
}
-static void stbi__vertical_flip(void * image, int w, int h,
- int bytes_per_pixel) {
+static void stbi__vertical_flip(void * image, int w, int h, int bytes_per_pixel) {
int row;
size_t bytes_per_row = (size_t) w * bytes_per_pixel;
stbi_uc temp[2048];
@@ -1282,8 +1236,7 @@ static void stbi__vertical_flip(void * image, int w, int h,
// swap row0 with row1
size_t bytes_left = bytes_per_row;
while (bytes_left) {
- size_t bytes_copy
- = (bytes_left < sizeof(temp)) ? bytes_left : sizeof(temp);
+ size_t bytes_copy = (bytes_left < sizeof(temp)) ? bytes_left : sizeof(temp);
memcpy(temp, row0, bytes_copy);
memcpy(row0, row1, bytes_copy);
memcpy(row1, temp, bytes_copy);
@@ -1308,10 +1261,8 @@ static void stbi__vertical_flip_slices(void * image, int w, int h, int z,
}
#endif
-static unsigned char * stbi__load_and_postprocess_8bit(stbi__context * s,
- int * x, int * y,
- int * comp,
- int req_comp) {
+static unsigned char * stbi__load_and_postprocess_8bit(stbi__context * s, int * x, int * y,
+ int * comp, int req_comp) {
stbi__result_info ri;
void * result = stbi__load_main(s, x, y, comp, req_comp, &ri, 8);
@@ -1336,10 +1287,8 @@ static unsigned char * stbi__load_and_postprocess_8bit(stbi__context * s,
return (unsigned char *) result;
}
-static stbi__uint16 * stbi__load_and_postprocess_16bit(stbi__context * s,
- int * x, int * y,
- int * comp,
- int req_comp) {
+static stbi__uint16 * stbi__load_and_postprocess_16bit(stbi__context * s, int * x, int * y,
+ int * comp, int req_comp) {
stbi__result_info ri;
void * result = stbi__load_main(s, x, y, comp, req_comp, &ri, 16);
@@ -1366,8 +1315,8 @@ static stbi__uint16 * stbi__load_and_postprocess_16bit(stbi__context * s,
}
#if !defined(STBI_NO_HDR) && !defined(STBI_NO_LINEAR)
-static void stbi__float_postprocess(float * result, int * x, int * y,
- int * comp, int req_comp) {
+static void stbi__float_postprocess(float * result, int * x, int * y, int * comp,
+ int req_comp) {
if (stbi__vertically_flip_on_load && result != NULL) {
int channels = req_comp ? req_comp : *comp;
stbi__vertical_flip(result, *x, *y, channels * sizeof(float));
@@ -1378,19 +1327,20 @@ static void stbi__float_postprocess(float * result, int * x, int * y,
#ifndef STBI_NO_STDIO
#if defined(_WIN32) && defined(STBI_WINDOWS_UTF8)
-STBI_EXTERN __declspec(dllimport) int __stdcall MultiByteToWideChar(
- unsigned int cp, unsigned long flags, const char * str, int cbmb,
- wchar_t * widestr, int cchwide);
+STBI_EXTERN
+__declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int cp, unsigned long flags,
+ const char * str, int cbmb,
+ wchar_t * widestr, int cchwide);
STBI_EXTERN __declspec(dllimport) int __stdcall WideCharToMultiByte(
- unsigned int cp, unsigned long flags, const wchar_t * widestr, int cchwide,
- char * str, int cbmb, const char * defchar, int * used_default);
+ unsigned int cp, unsigned long flags, const wchar_t * widestr, int cchwide, char * str,
+ int cbmb, const char * defchar, int * used_default);
#endif
#if defined(_WIN32) && defined(STBI_WINDOWS_UTF8)
STBIDEF int stbi_convert_wchar_to_utf8(char * buffer, size_t bufferlen,
const wchar_t * input) {
- return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer,
- (int) bufferlen, NULL, NULL);
+ return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer, (int) bufferlen, NULL,
+ NULL);
}
#endif
@@ -1433,8 +1383,7 @@ STBIDEF stbi_uc * stbi_load(char const * filename, int * x, int * y, int * comp,
return result;
}
-STBIDEF stbi_uc * stbi_load_from_file(FILE * f, int * x, int * y, int * comp,
- int req_comp) {
+STBIDEF stbi_uc * stbi_load_from_file(FILE * f, int * x, int * y, int * comp, int req_comp) {
unsigned char * result;
stbi__context s;
stbi__start_file(&s, f);
@@ -1446,8 +1395,8 @@ STBIDEF stbi_uc * stbi_load_from_file(FILE * f, int * x, int * y, int * comp,
return result;
}
-STBIDEF stbi__uint16 * stbi_load_from_file_16(FILE * f, int * x, int * y,
- int * comp, int req_comp) {
+STBIDEF stbi__uint16 * stbi_load_from_file_16(FILE * f, int * x, int * y, int * comp,
+ int req_comp) {
stbi__uint16 * result;
stbi__context s;
stbi__start_file(&s, f);
@@ -1459,12 +1408,11 @@ STBIDEF stbi__uint16 * stbi_load_from_file_16(FILE * f, int * x, int * y,
return result;
}
-STBIDEF stbi_us * stbi_load_16(char const * filename, int * x, int * y,
- int * comp, int req_comp) {
+STBIDEF stbi_us * stbi_load_16(char const * filename, int * x, int * y, int * comp,
+ int req_comp) {
FILE * f = stbi__fopen(filename, "rb");
stbi__uint16 * result;
- if (!f)
- return (stbi_us *) stbi__errpuc("can't fopen", "Unable to open file");
+ if (!f) return (stbi_us *) stbi__errpuc("can't fopen", "Unable to open file");
result = stbi_load_from_file_16(f, x, y, comp, req_comp);
fclose(f);
return result;
@@ -1472,52 +1420,44 @@ STBIDEF stbi_us * stbi_load_16(char const * filename, int * x, int * y,
#endif //!STBI_NO_STDIO
-STBIDEF stbi_us * stbi_load_16_from_memory(stbi_uc const * buffer, int len,
- int * x, int * y,
- int * channels_in_file,
- int desired_channels) {
+STBIDEF stbi_us * stbi_load_16_from_memory(stbi_uc const * buffer, int len, int * x, int * y,
+ int * channels_in_file, int desired_channels) {
stbi__context s;
stbi__start_mem(&s, buffer, len);
- return stbi__load_and_postprocess_16bit(&s, x, y, channels_in_file,
- desired_channels);
+ return stbi__load_and_postprocess_16bit(&s, x, y, channels_in_file, desired_channels);
}
-STBIDEF stbi_us * stbi_load_16_from_callbacks(stbi_io_callbacks const * clbk,
- void * user, int * x, int * y,
- int * channels_in_file,
+STBIDEF stbi_us * stbi_load_16_from_callbacks(stbi_io_callbacks const * clbk, void * user,
+ int * x, int * y, int * channels_in_file,
int desired_channels) {
stbi__context s;
stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user);
- return stbi__load_and_postprocess_16bit(&s, x, y, channels_in_file,
- desired_channels);
+ return stbi__load_and_postprocess_16bit(&s, x, y, channels_in_file, desired_channels);
}
-STBIDEF stbi_uc * stbi_load_from_memory(stbi_uc const * buffer, int len,
- int * x, int * y, int * comp,
- int req_comp) {
+STBIDEF stbi_uc * stbi_load_from_memory(stbi_uc const * buffer, int len, int * x, int * y,
+ int * comp, int req_comp) {
stbi__context s;
stbi__start_mem(&s, buffer, len);
return stbi__load_and_postprocess_8bit(&s, x, y, comp, req_comp);
}
-STBIDEF stbi_uc * stbi_load_from_callbacks(stbi_io_callbacks const * clbk,
- void * user, int * x, int * y,
- int * comp, int req_comp) {
+STBIDEF stbi_uc * stbi_load_from_callbacks(stbi_io_callbacks const * clbk, void * user,
+ int * x, int * y, int * comp, int req_comp) {
stbi__context s;
stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user);
return stbi__load_and_postprocess_8bit(&s, x, y, comp, req_comp);
}
#ifndef STBI_NO_GIF
-STBIDEF stbi_uc * stbi_load_gif_from_memory(stbi_uc const * buffer, int len,
- int ** delays, int * x, int * y,
- int * z, int * comp, int req_comp) {
+STBIDEF stbi_uc * stbi_load_gif_from_memory(stbi_uc const * buffer, int len, int ** delays,
+ int * x, int * y, int * z, int * comp,
+ int req_comp) {
unsigned char * result;
stbi__context s;
stbi__start_mem(&s, buffer, len);
- result = (unsigned char *) stbi__load_gif_main(&s, delays, x, y, z, comp,
- req_comp);
+ result = (unsigned char *) stbi__load_gif_main(&s, delays, x, y, z, comp, req_comp);
if (stbi__vertically_flip_on_load) {
stbi__vertical_flip_slices(result, *x, *y, *z, *comp);
}
@@ -1539,30 +1479,26 @@ static float * stbi__loadf_main(stbi__context * s, int * x, int * y, int * comp,
}
#endif
data = stbi__load_and_postprocess_8bit(s, x, y, comp, req_comp);
- if (data)
- return stbi__ldr_to_hdr(data, *x, *y, req_comp ? req_comp : *comp);
- return stbi__errpf("unknown image type",
- "Image not of any known type, or corrupt");
+ if (data) return stbi__ldr_to_hdr(data, *x, *y, req_comp ? req_comp : *comp);
+ return stbi__errpf("unknown image type", "Image not of any known type, or corrupt");
}
-STBIDEF float * stbi_loadf_from_memory(stbi_uc const * buffer, int len, int * x,
- int * y, int * comp, int req_comp) {
+STBIDEF float * stbi_loadf_from_memory(stbi_uc const * buffer, int len, int * x, int * y,
+ int * comp, int req_comp) {
stbi__context s;
stbi__start_mem(&s, buffer, len);
return stbi__loadf_main(&s, x, y, comp, req_comp);
}
-STBIDEF float * stbi_loadf_from_callbacks(stbi_io_callbacks const * clbk,
- void * user, int * x, int * y,
- int * comp, int req_comp) {
+STBIDEF float * stbi_loadf_from_callbacks(stbi_io_callbacks const * clbk, void * user, int * x,
+ int * y, int * comp, int req_comp) {
stbi__context s;
stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user);
return stbi__loadf_main(&s, x, y, comp, req_comp);
}
#ifndef STBI_NO_STDIO
-STBIDEF float * stbi_loadf(char const * filename, int * x, int * y, int * comp,
- int req_comp) {
+STBIDEF float * stbi_loadf(char const * filename, int * x, int * y, int * comp, int req_comp) {
float * result;
FILE * f = stbi__fopen(filename, "rb");
if (!f) return stbi__errpf("can't fopen", "Unable to open file");
@@ -1571,8 +1507,7 @@ STBIDEF float * stbi_loadf(char const * filename, int * x, int * y, int * comp,
return result;
}
-STBIDEF float * stbi_loadf_from_file(FILE * f, int * x, int * y, int * comp,
- int req_comp) {
+STBIDEF float * stbi_loadf_from_file(FILE * f, int * x, int * y, int * comp, int req_comp) {
stbi__context s;
stbi__start_file(&s, f);
return stbi__loadf_main(&s, x, y, comp, req_comp);
@@ -1624,8 +1559,7 @@ STBIDEF int stbi_is_hdr_from_file(FILE * f) {
}
#endif // !STBI_NO_STDIO
-STBIDEF int stbi_is_hdr_from_callbacks(stbi_io_callbacks const * clbk,
- void * user) {
+STBIDEF int stbi_is_hdr_from_callbacks(stbi_io_callbacks const * clbk, void * user) {
#ifndef STBI_NO_HDR
stbi__context s;
stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user);
@@ -1646,12 +1580,8 @@ STBIDEF void stbi_ldr_to_hdr_scale(float scale) { stbi__l2h_scale = scale; }
static float stbi__h2l_gamma_i = 1.0f / 2.2f, stbi__h2l_scale_i = 1.0f;
-STBIDEF void stbi_hdr_to_ldr_gamma(float gamma) {
- stbi__h2l_gamma_i = 1 / gamma;
-}
-STBIDEF void stbi_hdr_to_ldr_scale(float scale) {
- stbi__h2l_scale_i = 1 / scale;
-}
+STBIDEF void stbi_hdr_to_ldr_gamma(float gamma) { stbi__h2l_gamma_i = 1 / gamma; }
+STBIDEF void stbi_hdr_to_ldr_scale(float scale) { stbi__h2l_scale_i = 1 / scale; }
//////////////////////////////////////////////////////////////////////////////
//
@@ -1736,8 +1666,7 @@ static int stbi__getn(stbi__context * s, stbi_uc * buffer, int n) {
memcpy(buffer, s->img_buffer, blen);
- count = (s->io.read)(s->io_user_data, (char *) buffer + blen,
- n - blen);
+ count = (s->io.read)(s->io_user_data, (char *) buffer + blen, n - blen);
res = (count == (n - blen));
s->img_buffer = s->img_buffer_end;
return res;
@@ -1788,8 +1717,7 @@ static stbi__uint32 stbi__get32le(stbi__context * s) {
}
#endif
-#define STBI__BYTECAST(x) \
- ((stbi_uc) ((x) & 255)) // truncate int to byte without warnings
+#define STBI__BYTECAST(x) ((stbi_uc) ((x) & 255)) // truncate int to byte without warnings
#if defined(STBI_NO_JPEG) && defined(STBI_NO_PNG) && defined(STBI_NO_BMP) \
&& defined(STBI_NO_PSD) && defined(STBI_NO_TGA) && defined(STBI_NO_GIF) \
@@ -1817,9 +1745,8 @@ static stbi_uc stbi__compute_y(int r, int g, int b) {
&& defined(STBI_NO_PNM)
// nothing
#else
-static unsigned char * stbi__convert_format(unsigned char * data, int img_n,
- int req_comp, unsigned int x,
- unsigned int y) {
+static unsigned char * stbi__convert_format(unsigned char * data, int img_n, int req_comp,
+ unsigned int x, unsigned int y) {
int i, j;
unsigned char * good;
@@ -1871,18 +1798,14 @@ static unsigned char * stbi__convert_format(unsigned char * data, int img_n,
dest[3] = 255;
}
break;
- STBI__CASE(3, 1) {
- dest[0] = stbi__compute_y(src[0], src[1], src[2]);
- }
+ STBI__CASE(3, 1) { dest[0] = stbi__compute_y(src[0], src[1], src[2]); }
break;
STBI__CASE(3, 2) {
dest[0] = stbi__compute_y(src[0], src[1], src[2]);
dest[1] = 255;
}
break;
- STBI__CASE(4, 1) {
- dest[0] = stbi__compute_y(src[0], src[1], src[2]);
- }
+ STBI__CASE(4, 1) { dest[0] = stbi__compute_y(src[0], src[1], src[2]); }
break;
STBI__CASE(4, 2) {
dest[0] = stbi__compute_y(src[0], src[1], src[2]);
@@ -1899,8 +1822,7 @@ static unsigned char * stbi__convert_format(unsigned char * data, int img_n,
STBI_ASSERT(0);
STBI_FREE(data);
STBI_FREE(good);
- return stbi__errpuc("unsupported",
- "Unsupported format conversion");
+ return stbi__errpuc("unsupported", "Unsupported format conversion");
}
#undef STBI__CASE
}
@@ -1921,9 +1843,8 @@ static stbi__uint16 stbi__compute_y_16(int r, int g, int b) {
#if defined(STBI_NO_PNG) && defined(STBI_NO_PSD)
// nothing
#else
-static stbi__uint16 * stbi__convert_format16(stbi__uint16 * data, int img_n,
- int req_comp, unsigned int x,
- unsigned int y) {
+static stbi__uint16 * stbi__convert_format16(stbi__uint16 * data, int img_n, int req_comp,
+ unsigned int x, unsigned int y) {
int i, j;
stbi__uint16 * good;
@@ -1975,18 +1896,14 @@ static stbi__uint16 * stbi__convert_format16(stbi__uint16 * data, int img_n,
dest[3] = 0xffff;
}
break;
- STBI__CASE(3, 1) {
- dest[0] = stbi__compute_y_16(src[0], src[1], src[2]);
- }
+ STBI__CASE(3, 1) { dest[0] = stbi__compute_y_16(src[0], src[1], src[2]); }
break;
STBI__CASE(3, 2) {
dest[0] = stbi__compute_y_16(src[0], src[1], src[2]);
dest[1] = 0xffff;
}
break;
- STBI__CASE(4, 1) {
- dest[0] = stbi__compute_y_16(src[0], src[1], src[2]);
- }
+ STBI__CASE(4, 1) { dest[0] = stbi__compute_y_16(src[0], src[1], src[2]); }
break;
STBI__CASE(4, 2) {
dest[0] = stbi__compute_y_16(src[0], src[1], src[2]);
@@ -2003,8 +1920,8 @@ static stbi__uint16 * stbi__convert_format16(stbi__uint16 * data, int img_n,
STBI_ASSERT(0);
STBI_FREE(data);
STBI_FREE(good);
- return (stbi__uint16 *) stbi__errpuc(
- "unsupported", "Unsupported format conversion");
+ return (stbi__uint16 *) stbi__errpuc("unsupported",
+ "Unsupported format conversion");
}
#undef STBI__CASE
}
@@ -2029,9 +1946,8 @@ static float * stbi__ldr_to_hdr(stbi_uc * data, int x, int y, int comp) {
else n = comp - 1;
for (i = 0; i < x * y; ++i) {
for (k = 0; k < n; ++k) {
- output[i * comp + k]
- = (float) (pow(data[i * comp + k] / 255.0f, stbi__l2h_gamma)
- * stbi__l2h_scale);
+ output[i * comp + k] = (float) (pow(data[i * comp + k] / 255.0f, stbi__l2h_gamma)
+ * stbi__l2h_scale);
}
}
if (n < comp) {
@@ -2060,10 +1976,9 @@ static stbi_uc * stbi__hdr_to_ldr(float * data, int x, int y, int comp) {
else n = comp - 1;
for (i = 0; i < x * y; ++i) {
for (k = 0; k < n; ++k) {
- float z = (float) pow(data[i * comp + k] * stbi__h2l_scale_i,
- stbi__h2l_gamma_i)
- * 255
- + 0.5f;
+ float z
+ = (float) pow(data[i * comp + k] * stbi__h2l_scale_i, stbi__h2l_gamma_i) * 255
+ + 0.5f;
if (z < 0) z = 0;
if (z > 255) z = 255;
output[i * comp + k] = (stbi_uc) stbi__float2int(z);
@@ -2164,11 +2079,10 @@ typedef struct {
// kernels
void (*idct_block_kernel)(stbi_uc * out, int out_stride, short data[64]);
- void (*YCbCr_to_RGB_kernel)(stbi_uc * out, const stbi_uc * y,
- const stbi_uc * pcb, const stbi_uc * pcr,
- int count, int step);
- stbi_uc * (*resample_row_hv_2_kernel)(stbi_uc * out, stbi_uc * in_near,
- stbi_uc * in_far, int w, int hs);
+ void (*YCbCr_to_RGB_kernel)(stbi_uc * out, const stbi_uc * y, const stbi_uc * pcb,
+ const stbi_uc * pcr, int count, int step);
+ stbi_uc * (*resample_row_hv_2_kernel)(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far,
+ int w, int hs);
} stbi__jpeg;
static int stbi__build_huffman(stbi__huffman * h, int * count) {
@@ -2191,8 +2105,7 @@ static int stbi__build_huffman(stbi__huffman * h, int * count) {
h->delta[j] = k - code;
if (h->size[k] == j) {
while (h->size[k] == j) h->code[k++] = (stbi__uint16) (code++);
- if (code - 1 >= (1u << j))
- return stbi__err("bad code lengths", "Corrupt JPEG");
+ if (code - 1 >= (1u << j)) return stbi__err("bad code lengths", "Corrupt JPEG");
}
// compute largest code + 1 for this size, preshifted as needed later
h->maxcode[j] = code << (16 - j);
@@ -2230,14 +2143,12 @@ static void stbi__build_fast_ac(stbi__int16 * fast_ac, stbi__huffman * h) {
if (magbits && len + magbits <= FAST_BITS) {
// magnitude code followed by receive_extend code
- int k = ((i << len) & ((1 << FAST_BITS) - 1))
- >> (FAST_BITS - magbits);
+ int k = ((i << len) & ((1 << FAST_BITS) - 1)) >> (FAST_BITS - magbits);
int m = 1 << (magbits - 1);
if (k < m) k += (~0U << magbits) + 1;
// if the result is small enough, we can fit it in fast_ac table
if (k >= -128 && k <= 127)
- fast_ac[i] = (stbi__int16) ((k * 256) + (run * 16)
- + (len + magbits));
+ fast_ac[i] = (stbi__int16) ((k * 256) + (run * 16) + (len + magbits));
}
}
}
@@ -2262,12 +2173,10 @@ static void stbi__grow_buffer_unsafe(stbi__jpeg * j) {
// (1 << n) - 1
static const stbi__uint32 stbi__bmask[17]
- = {0, 1, 3, 7, 15, 31, 63, 127, 255,
- 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535};
+ = {0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535};
// decode a jpeg huffman value from the bitstream
-stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg * j,
- stbi__huffman * h) {
+stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg * j, stbi__huffman * h) {
unsigned int temp;
int c, k;
@@ -2306,9 +2215,8 @@ stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg * j,
c = ((j->code_buffer >> (32 - k)) & stbi__bmask[k]) + h->delta[k];
if (c < 0 || c >= 256) // symbol id out of bounds!
return -1;
- STBI_ASSERT(
- (((j->code_buffer) >> (32 - h->size[c])) & stbi__bmask[h->size[c]])
- == h->code[c]);
+ STBI_ASSERT((((j->code_buffer) >> (32 - h->size[c])) & stbi__bmask[h->size[c]])
+ == h->code[c]);
// convert the id to a symbol
j->code_bits -= k;
@@ -2317,9 +2225,8 @@ stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg * j,
}
// bias[n] = (-1<<n) + 1
-static const int stbi__jbias[16]
- = {0, -1, -3, -7, -15, -31, -63, -127,
- -255, -511, -1023, -2047, -4095, -8191, -16383, -32767};
+static const int stbi__jbias[16] = {0, -1, -3, -7, -15, -31, -63, -127,
+ -255, -511, -1023, -2047, -4095, -8191, -16383, -32767};
// combined JPEG 'receive' and JPEG 'extend', since baseline
// always extends everything it receives.
@@ -2366,17 +2273,15 @@ stbi_inline static int stbi__jpeg_get_bit(stbi__jpeg * j) {
// given a value that's at position X in the zigzag stream,
// where does it appear in the 8x8 matrix coded as row-major?
static const stbi_uc stbi__jpeg_dezigzag[64 + 15]
- = {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, 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,
+ = {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, 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,
// let corrupt input sample past end
63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63};
// decode one 64-entry block--
-static int stbi__jpeg_decode_block(stbi__jpeg * j, short data[64],
- stbi__huffman * hdc, stbi__huffman * hac,
- stbi__int16 * fac, int b,
+static int stbi__jpeg_decode_block(stbi__jpeg * j, short data[64], stbi__huffman * hdc,
+ stbi__huffman * hac, stbi__int16 * fac, int b,
stbi__uint16 * dequant) {
int diff, dc, k;
int t;
@@ -2409,9 +2314,8 @@ static int stbi__jpeg_decode_block(stbi__jpeg * j, short data[64],
k += (r >> 4) & 15; // run
s = r & 15; // combined length
if (s > j->code_bits)
- return stbi__err(
- "bad huffman code",
- "Combined length longer than code bits available");
+ return stbi__err("bad huffman code",
+ "Combined length longer than code bits available");
j->code_buffer <<= s;
j->code_bits -= s;
// decode into unzigzag'd location
@@ -2436,12 +2340,11 @@ static int stbi__jpeg_decode_block(stbi__jpeg * j, short data[64],
return 1;
}
-static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg * j, short data[64],
- stbi__huffman * hdc, int b) {
+static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg * j, short data[64], stbi__huffman * hdc,
+ int b) {
int diff, dc;
int t;
- if (j->spec_end != 0)
- return stbi__err("can't merge dc and ac", "Corrupt JPEG");
+ if (j->spec_end != 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG");
if (j->code_bits < 16) stbi__grow_buffer_unsafe(j);
@@ -2449,8 +2352,7 @@ static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg * j, short data[64],
// first scan for DC coefficient, must be first
memset(data, 0, 64 * sizeof(data[0])); // 0 all the ac values now
t = stbi__jpeg_huff_decode(j, hdc);
- if (t < 0 || t > 15)
- return stbi__err("can't merge dc and ac", "Corrupt JPEG");
+ if (t < 0 || t > 15) return stbi__err("can't merge dc and ac", "Corrupt JPEG");
diff = t ? stbi__extend_receive(j, t) : 0;
if (!stbi__addints_valid(j->img_comp[b].dc_pred, diff))
@@ -2469,12 +2371,10 @@ static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg * j, short data[64],
// @OPTIMIZE: store non-zigzagged during the decode passes,
// and only de-zigzag when dequantizing
-static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg * j, short data[64],
- stbi__huffman * hac,
+static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg * j, short data[64], stbi__huffman * hac,
stbi__int16 * fac) {
int k;
- if (j->spec_start == 0)
- return stbi__err("can't merge dc and ac", "Corrupt JPEG");
+ if (j->spec_start == 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG");
if (j->succ_high == 0) {
int shift = j->succ_low;
@@ -2495,17 +2395,15 @@ static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg * j, short data[64],
k += (r >> 4) & 15; // run
s = r & 15; // combined length
if (s > j->code_bits)
- return stbi__err(
- "bad huffman code",
- "Combined length longer than code bits available");
+ return stbi__err("bad huffman code",
+ "Combined length longer than code bits available");
j->code_buffer <<= s;
j->code_bits -= s;
zig = stbi__jpeg_dezigzag[k++];
data[zig] = (short) ((r >> 8) * (1 << shift));
} else {
int rs = stbi__jpeg_huff_decode(j, hac);
- if (rs < 0)
- return stbi__err("bad huffman code", "Corrupt JPEG");
+ if (rs < 0) return stbi__err("bad huffman code", "Corrupt JPEG");
s = rs & 15;
r = rs >> 4;
if (s == 0) {
@@ -2519,8 +2417,7 @@ static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg * j, short data[64],
} else {
k += r;
zig = stbi__jpeg_dezigzag[k++];
- data[zig]
- = (short) (stbi__extend_receive(j, s) * (1 << shift));
+ data[zig] = (short) (stbi__extend_receive(j, s) * (1 << shift));
}
}
} while (k <= j->spec_end);
@@ -2547,8 +2444,7 @@ static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg * j, short data[64],
int rs = stbi__jpeg_huff_decode(
j,
hac); // @OPTIMIZE see if we can use the fast path here, advance-by-r is so slow, eh
- if (rs < 0)
- return stbi__err("bad huffman code", "Corrupt JPEG");
+ if (rs < 0) return stbi__err("bad huffman code", "Corrupt JPEG");
s = rs & 15;
r = rs >> 4;
if (s == 0) {
@@ -2562,8 +2458,7 @@ static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg * j, short data[64],
// so we don't have to do anything special here
}
} else {
- if (s != 1)
- return stbi__err("bad huffman code", "Corrupt JPEG");
+ if (s != 1) return stbi__err("bad huffman code", "Corrupt JPEG");
// sign bit
if (stbi__jpeg_get_bit(j)) s = bit;
else s = -bit;
@@ -2651,15 +2546,14 @@ static void stbi__idct_block(stbi_uc * out, int out_stride, short data[64]) {
// columns
for (i = 0; i < 8; ++i, ++d, ++v) {
// if all zeroes, shortcut -- this avoids dequantizing 0s and IDCTing
- if (d[8] == 0 && d[16] == 0 && d[24] == 0 && d[32] == 0 && d[40] == 0
- && d[48] == 0 && d[56] == 0) {
+ if (d[8] == 0 && d[16] == 0 && d[24] == 0 && d[32] == 0 && d[40] == 0 && d[48] == 0
+ && d[56] == 0) {
// no shortcut 0 seconds
// (1|2|3|4|5|6|7)==0 0 seconds
// all separate -0.047 seconds
// 1 && 2|3 && 4|5 && 6|7: -0.047 seconds
int dcterm = d[0] * 4;
- v[0] = v[8] = v[16] = v[24] = v[32] = v[40] = v[48] = v[56]
- = dcterm;
+ v[0] = v[8] = v[16] = v[24] = v[32] = v[40] = v[48] = v[56] = dcterm;
} else {
STBI__IDCT_1D(d[0], d[8], d[16], d[24], d[32], d[40], d[48], d[56])
// constants scaled things up by 1<<12; let's bring them back
@@ -2729,10 +2623,8 @@ static void stbi__idct_simd(stbi_uc * out, int out_stride, short data[64]) {
// out = in << 12 (in 16-bit, out 32-bit)
#define dct_widen(out, in) \
- __m128i out##_l \
- = _mm_srai_epi32(_mm_unpacklo_epi16(_mm_setzero_si128(), (in)), 4); \
- __m128i out##_h \
- = _mm_srai_epi32(_mm_unpackhi_epi16(_mm_setzero_si128(), (in)), 4)
+ __m128i out##_l = _mm_srai_epi32(_mm_unpacklo_epi16(_mm_setzero_si128(), (in)), 4); \
+ __m128i out##_h = _mm_srai_epi32(_mm_unpackhi_epi16(_mm_setzero_si128(), (in)), 4)
// wide add
#define dct_wadd(out, a, b) \
@@ -2751,10 +2643,8 @@ static void stbi__idct_simd(stbi_uc * out, int out_stride, short data[64]) {
__m128i abiased_h = _mm_add_epi32(a##_h, bias); \
dct_wadd(sum, abiased, b); \
dct_wsub(dif, abiased, b); \
- out0 = _mm_packs_epi32(_mm_srai_epi32(sum_l, s), \
- _mm_srai_epi32(sum_h, s)); \
- out1 = _mm_packs_epi32(_mm_srai_epi32(dif_l, s), \
- _mm_srai_epi32(dif_h, s)); \
+ out0 = _mm_packs_epi32(_mm_srai_epi32(sum_l, s), _mm_srai_epi32(sum_h, s)); \
+ out1 = _mm_packs_epi32(_mm_srai_epi32(dif_l, s), _mm_srai_epi32(dif_h, s)); \
}
// 8-bit interleave step (for transposes)
@@ -2798,28 +2688,21 @@ static void stbi__idct_simd(stbi_uc * out, int out_stride, short data[64]) {
}
__m128i rot0_0
- = dct_const(stbi__f2f(0.5411961f),
- stbi__f2f(0.5411961f) + stbi__f2f(-1.847759065f));
- __m128i rot0_1 = dct_const(stbi__f2f(0.5411961f) + stbi__f2f(0.765366865f),
- stbi__f2f(0.5411961f));
- __m128i rot1_0
- = dct_const(stbi__f2f(1.175875602f) + stbi__f2f(-0.899976223f),
- stbi__f2f(1.175875602f));
- __m128i rot1_1
- = dct_const(stbi__f2f(1.175875602f),
- stbi__f2f(1.175875602f) + stbi__f2f(-2.562915447f));
- __m128i rot2_0
- = dct_const(stbi__f2f(-1.961570560f) + stbi__f2f(0.298631336f),
- stbi__f2f(-1.961570560f));
- __m128i rot2_1
- = dct_const(stbi__f2f(-1.961570560f),
- stbi__f2f(-1.961570560f) + stbi__f2f(3.072711026f));
- __m128i rot3_0
- = dct_const(stbi__f2f(-0.390180644f) + stbi__f2f(2.053119869f),
- stbi__f2f(-0.390180644f));
- __m128i rot3_1
- = dct_const(stbi__f2f(-0.390180644f),
- stbi__f2f(-0.390180644f) + stbi__f2f(1.501321110f));
+ = dct_const(stbi__f2f(0.5411961f), stbi__f2f(0.5411961f) + stbi__f2f(-1.847759065f));
+ __m128i rot0_1
+ = dct_const(stbi__f2f(0.5411961f) + stbi__f2f(0.765366865f), stbi__f2f(0.5411961f));
+ __m128i rot1_0 = dct_const(stbi__f2f(1.175875602f) + stbi__f2f(-0.899976223f),
+ stbi__f2f(1.175875602f));
+ __m128i rot1_1 = dct_const(stbi__f2f(1.175875602f),
+ stbi__f2f(1.175875602f) + stbi__f2f(-2.562915447f));
+ __m128i rot2_0 = dct_const(stbi__f2f(-1.961570560f) + stbi__f2f(0.298631336f),
+ stbi__f2f(-1.961570560f));
+ __m128i rot2_1 = dct_const(stbi__f2f(-1.961570560f),
+ stbi__f2f(-1.961570560f) + stbi__f2f(3.072711026f));
+ __m128i rot3_0 = dct_const(stbi__f2f(-0.390180644f) + stbi__f2f(2.053119869f),
+ stbi__f2f(-0.390180644f));
+ __m128i rot3_1 = dct_const(stbi__f2f(-0.390180644f),
+ stbi__f2f(-0.390180644f) + stbi__f2f(1.501321110f));
// rounding biases in column/row passes, see stbi__idct_block for explanation.
__m128i bias_0 = _mm_set1_epi32(512);
@@ -3030,8 +2913,7 @@ static void stbi__idct_simd(stbi_uc * out, int out_stride, short data[64]) {
}
#define dct_trn32(x, y) \
{ \
- int32x4x2_t t \
- = vtrnq_s32(vreinterpretq_s32_s16(x), vreinterpretq_s32_s16(y)); \
+ int32x4x2_t t = vtrnq_s32(vreinterpretq_s32_s16(x), vreinterpretq_s32_s16(y)); \
x = vreinterpretq_s16_s32(t.val[0]); \
y = vreinterpretq_s16_s32(t.val[1]); \
}
@@ -3092,15 +2974,13 @@ static void stbi__idct_simd(stbi_uc * out, int out_stride, short data[64]) {
}
#define dct_trn8_16(x, y) \
{ \
- uint16x4x2_t t \
- = vtrn_u16(vreinterpret_u16_u8(x), vreinterpret_u16_u8(y)); \
+ uint16x4x2_t t = vtrn_u16(vreinterpret_u16_u8(x), vreinterpret_u16_u8(y)); \
x = vreinterpret_u8_u16(t.val[0]); \
y = vreinterpret_u8_u16(t.val[1]); \
}
#define dct_trn8_32(x, y) \
{ \
- uint32x2x2_t t \
- = vtrn_u32(vreinterpret_u32_u8(x), vreinterpret_u32_u8(y)); \
+ uint32x2x2_t t = vtrn_u32(vreinterpret_u32_u8(x), vreinterpret_u32_u8(y)); \
x = vreinterpret_u8_u32(t.val[0]); \
y = vreinterpret_u8_u32(t.val[1]); \
}
@@ -3211,14 +3091,13 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg * z) {
for (j = 0; j < h; ++j) {
for (i = 0; i < w; ++i) {
int ha = z->img_comp[n].ha;
- if (!stbi__jpeg_decode_block(
- z, data, z->huff_dc + z->img_comp[n].hd,
- z->huff_ac + ha, z->fast_ac[ha], n,
- z->dequant[z->img_comp[n].tq]))
+ if (!stbi__jpeg_decode_block(z, data, z->huff_dc + z->img_comp[n].hd,
+ z->huff_ac + ha, z->fast_ac[ha], n,
+ z->dequant[z->img_comp[n].tq]))
return 0;
- z->idct_block_kernel(
- z->img_comp[n].data + z->img_comp[n].w2 * j * 8 + i * 8,
- z->img_comp[n].w2, data);
+ z->idct_block_kernel(z->img_comp[n].data + z->img_comp[n].w2 * j * 8
+ + i * 8,
+ z->img_comp[n].w2, data);
// every data block is an MCU, so countdown the restart interval
if (--z->todo <= 0) {
if (z->code_bits < 24) stbi__grow_buffer_unsafe(z);
@@ -3245,15 +3124,14 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg * z) {
int x2 = (i * z->img_comp[n].h + x) * 8;
int y2 = (j * z->img_comp[n].v + y) * 8;
int ha = z->img_comp[n].ha;
- if (!stbi__jpeg_decode_block(
- z, data, z->huff_dc + z->img_comp[n].hd,
- z->huff_ac + ha, z->fast_ac[ha], n,
- z->dequant[z->img_comp[n].tq]))
+ if (!stbi__jpeg_decode_block(z, data,
+ z->huff_dc + z->img_comp[n].hd,
+ z->huff_ac + ha, z->fast_ac[ha],
+ n, z->dequant[z->img_comp[n].tq]))
return 0;
- z->idct_block_kernel(
- z->img_comp[n].data + z->img_comp[n].w2 * y2
- + x2,
- z->img_comp[n].w2, data);
+ z->idct_block_kernel(z->img_comp[n].data
+ + z->img_comp[n].w2 * y2 + x2,
+ z->img_comp[n].w2, data);
}
}
}
@@ -3280,16 +3158,16 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg * z) {
int h = (z->img_comp[n].y + 7) >> 3;
for (j = 0; j < h; ++j) {
for (i = 0; i < w; ++i) {
- short * data = z->img_comp[n].coeff
- + 64 * (i + j * z->img_comp[n].coeff_w);
+ short * data
+ = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w);
if (z->spec_start == 0) {
if (!stbi__jpeg_decode_block_prog_dc(
z, data, &z->huff_dc[z->img_comp[n].hd], n))
return 0;
} else {
int ha = z->img_comp[n].ha;
- if (!stbi__jpeg_decode_block_prog_ac(
- z, data, &z->huff_ac[ha], z->fast_ac[ha]))
+ if (!stbi__jpeg_decode_block_prog_ac(z, data, &z->huff_ac[ha],
+ z->fast_ac[ha]))
return 0;
}
// every data block is an MCU, so countdown the restart interval
@@ -3314,12 +3192,10 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg * z) {
for (x = 0; x < z->img_comp[n].h; ++x) {
int x2 = (i * z->img_comp[n].h + x);
int y2 = (j * z->img_comp[n].v + y);
- short * data
- = z->img_comp[n].coeff
- + 64 * (x2 + y2 * z->img_comp[n].coeff_w);
+ short * data = z->img_comp[n].coeff
+ + 64 * (x2 + y2 * z->img_comp[n].coeff_w);
if (!stbi__jpeg_decode_block_prog_dc(
- z, data, &z->huff_dc[z->img_comp[n].hd],
- n))
+ z, data, &z->huff_dc[z->img_comp[n].hd], n))
return 0;
}
}
@@ -3352,12 +3228,12 @@ static void stbi__jpeg_finish(stbi__jpeg * z) {
int h = (z->img_comp[n].y + 7) >> 3;
for (j = 0; j < h; ++j) {
for (i = 0; i < w; ++i) {
- short * data = z->img_comp[n].coeff
- + 64 * (i + j * z->img_comp[n].coeff_w);
+ short * data
+ = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w);
stbi__jpeg_dequantize(data, z->dequant[z->img_comp[n].tq]);
- z->idct_block_kernel(
- z->img_comp[n].data + z->img_comp[n].w2 * j * 8 + i * 8,
- z->img_comp[n].w2, data);
+ z->idct_block_kernel(z->img_comp[n].data + z->img_comp[n].w2 * j * 8
+ + i * 8,
+ z->img_comp[n].w2, data);
}
}
}
@@ -3371,8 +3247,7 @@ static int stbi__process_marker(stbi__jpeg * z, int m) {
return stbi__err("expected marker", "Corrupt JPEG");
case 0xDD: // DRI - specify restart interval
- if (stbi__get16be(z->s) != 4)
- return stbi__err("bad DRI len", "Corrupt JPEG");
+ if (stbi__get16be(z->s) != 4) return stbi__err("bad DRI len", "Corrupt JPEG");
z->restart_interval = stbi__get16be(z->s);
return 1;
@@ -3382,14 +3257,12 @@ static int stbi__process_marker(stbi__jpeg * z, int m) {
int q = stbi__get8(z->s);
int p = q >> 4, sixteen = (p != 0);
int t = q & 15, i;
- if (p != 0 && p != 1)
- return stbi__err("bad DQT type", "Corrupt JPEG");
+ if (p != 0 && p != 1) return stbi__err("bad DQT type", "Corrupt JPEG");
if (t > 3) return stbi__err("bad DQT table", "Corrupt JPEG");
for (i = 0; i < 64; ++i)
z->dequant[t][stbi__jpeg_dezigzag[i]]
- = (stbi__uint16) (sixteen ? stbi__get16be(z->s)
- : stbi__get8(z->s));
+ = (stbi__uint16) (sixteen ? stbi__get16be(z->s) : stbi__get8(z->s));
L -= (sixteen ? 129 : 65);
}
return L == 0;
@@ -3402,8 +3275,7 @@ static int stbi__process_marker(stbi__jpeg * z, int m) {
int q = stbi__get8(z->s);
int tc = q >> 4;
int th = q & 15;
- if (tc > 1 || th > 3)
- return stbi__err("bad DHT header", "Corrupt JPEG");
+ if (tc > 1 || th > 3) return stbi__err("bad DHT header", "Corrupt JPEG");
for (i = 0; i < 16; ++i) {
sizes[i] = stbi__get8(z->s);
n += sizes[i];
@@ -3421,8 +3293,7 @@ static int stbi__process_marker(stbi__jpeg * z, int m) {
v = z->huff_ac[th].values;
}
for (i = 0; i < n; ++i) v[i] = stbi__get8(z->s);
- if (tc != 0)
- stbi__build_fast_ac(z->fast_ac[th], z->huff_ac + th);
+ if (tc != 0) stbi__build_fast_ac(z->fast_ac[th], z->huff_ac + th);
L -= n;
}
return L == 0;
@@ -3475,8 +3346,7 @@ static int stbi__process_scan_header(stbi__jpeg * z) {
z->scan_n = stbi__get8(z->s);
if (z->scan_n < 1 || z->scan_n > 4 || z->scan_n > (int) z->s->img_n)
return stbi__err("bad SOS component count", "Corrupt JPEG");
- if (Ls != 6 + 2 * z->scan_n)
- return stbi__err("bad SOS len", "Corrupt JPEG");
+ if (Ls != 6 + 2 * z->scan_n) return stbi__err("bad SOS len", "Corrupt JPEG");
for (i = 0; i < z->scan_n; ++i) {
int id = stbi__get8(z->s), which;
int q = stbi__get8(z->s);
@@ -3484,11 +3354,9 @@ static int stbi__process_scan_header(stbi__jpeg * z) {
if (z->img_comp[which].id == id) break;
if (which == z->s->img_n) return 0; // no match
z->img_comp[which].hd = q >> 4;
- if (z->img_comp[which].hd > 3)
- return stbi__err("bad DC huff", "Corrupt JPEG");
+ if (z->img_comp[which].hd > 3) return stbi__err("bad DC huff", "Corrupt JPEG");
z->img_comp[which].ha = q & 15;
- if (z->img_comp[which].ha > 3)
- return stbi__err("bad AC huff", "Corrupt JPEG");
+ if (z->img_comp[which].ha > 3) return stbi__err("bad AC huff", "Corrupt JPEG");
z->order[i] = which;
}
@@ -3500,9 +3368,8 @@ static int stbi__process_scan_header(stbi__jpeg * z) {
z->succ_high = (aa >> 4);
z->succ_low = (aa & 15);
if (z->progressive) {
- if (z->spec_start > 63 || z->spec_end > 63
- || z->spec_start > z->spec_end || z->succ_high > 13
- || z->succ_low > 13)
+ if (z->spec_start > 63 || z->spec_end > 63 || z->spec_start > z->spec_end
+ || z->succ_high > 13 || z->succ_low > 13)
return stbi__err("bad SOS", "Corrupt JPEG");
} else {
if (z->spec_start != 0) return stbi__err("bad SOS", "Corrupt JPEG");
@@ -3543,24 +3410,21 @@ static int stbi__process_frame_header(stbi__jpeg * z, int scan) {
if (Lf < 11) return stbi__err("bad SOF len", "Corrupt JPEG"); // JPEG
p = stbi__get8(s);
if (p != 8)
- return stbi__err(
- "only 8-bit",
- "JPEG format not supported: 8-bit only"); // JPEG baseline
+ return stbi__err("only 8-bit",
+ "JPEG format not supported: 8-bit only"); // JPEG baseline
s->img_y = stbi__get16be(s);
if (s->img_y == 0)
return stbi__err(
"no header height",
"JPEG format not supported: delayed height"); // Legal, but we don't handle it--but neither does IJG
s->img_x = stbi__get16be(s);
- if (s->img_x == 0)
- return stbi__err("0 width", "Corrupt JPEG"); // JPEG requires
+ if (s->img_x == 0) return stbi__err("0 width", "Corrupt JPEG"); // JPEG requires
if (s->img_y > STBI_MAX_DIMENSIONS)
return stbi__err("too large", "Very large image (corrupt?)");
if (s->img_x > STBI_MAX_DIMENSIONS)
return stbi__err("too large", "Very large image (corrupt?)");
c = stbi__get8(s);
- if (c != 3 && c != 1 && c != 4)
- return stbi__err("bad component count", "Corrupt JPEG");
+ if (c != 3 && c != 1 && c != 4) return stbi__err("bad component count", "Corrupt JPEG");
s->img_n = c;
for (i = 0; i < c; ++i) {
z->img_comp[i].data = NULL;
@@ -3598,10 +3462,8 @@ static int stbi__process_frame_header(stbi__jpeg * z, int scan) {
// check that plane subsampling factors are integer ratios; our resamplers can't deal with fractional ratios
// and I've never seen a non-corrupted JPEG file actually use them
for (i = 0; i < s->img_n; ++i) {
- if (h_max % z->img_comp[i].h != 0)
- return stbi__err("bad H", "Corrupt JPEG");
- if (v_max % z->img_comp[i].v != 0)
- return stbi__err("bad V", "Corrupt JPEG");
+ if (h_max % z->img_comp[i].h != 0) return stbi__err("bad H", "Corrupt JPEG");
+ if (v_max % z->img_comp[i].v != 0) return stbi__err("bad V", "Corrupt JPEG");
}
// compute interleaved mcu info
@@ -3629,25 +3491,22 @@ static int stbi__process_frame_header(stbi__jpeg * z, int scan) {
z->img_comp[i].coeff = 0;
z->img_comp[i].raw_coeff = 0;
z->img_comp[i].linebuf = NULL;
- z->img_comp[i].raw_data
- = stbi__malloc_mad2(z->img_comp[i].w2, z->img_comp[i].h2, 15);
+ z->img_comp[i].raw_data = stbi__malloc_mad2(z->img_comp[i].w2, z->img_comp[i].h2, 15);
if (z->img_comp[i].raw_data == NULL)
- return stbi__free_jpeg_components(
- z, i + 1, stbi__err("outofmem", "Out of memory"));
+ return stbi__free_jpeg_components(z, i + 1,
+ stbi__err("outofmem", "Out of memory"));
// align blocks for idct using mmx/sse
- z->img_comp[i].data
- = (stbi_uc *) (((size_t) z->img_comp[i].raw_data + 15) & ~15);
+ z->img_comp[i].data = (stbi_uc *) (((size_t) z->img_comp[i].raw_data + 15) & ~15);
if (z->progressive) {
// w2, h2 are multiples of 8 (see above)
z->img_comp[i].coeff_w = z->img_comp[i].w2 / 8;
z->img_comp[i].coeff_h = z->img_comp[i].h2 / 8;
- z->img_comp[i].raw_coeff = stbi__malloc_mad3(
- z->img_comp[i].w2, z->img_comp[i].h2, sizeof(short), 15);
+ z->img_comp[i].raw_coeff
+ = stbi__malloc_mad3(z->img_comp[i].w2, z->img_comp[i].h2, sizeof(short), 15);
if (z->img_comp[i].raw_coeff == NULL)
- return stbi__free_jpeg_components(
- z, i + 1, stbi__err("outofmem", "Out of memory"));
- z->img_comp[i].coeff
- = (short *) (((size_t) z->img_comp[i].raw_coeff + 15) & ~15);
+ return stbi__free_jpeg_components(z, i + 1,
+ stbi__err("outofmem", "Out of memory"));
+ z->img_comp[i].coeff = (short *) (((size_t) z->img_comp[i].raw_coeff + 15) & ~15);
}
}
@@ -3731,8 +3590,7 @@ static int stbi__decode_jpeg_image(stbi__jpeg * j) {
int Ld = stbi__get16be(j->s);
stbi__uint32 NL = stbi__get16be(j->s);
if (Ld != 4) return stbi__err("bad DNL len", "Corrupt JPEG");
- if (NL != j->s->img_y)
- return stbi__err("bad DNL height", "Corrupt JPEG");
+ if (NL != j->s->img_y) return stbi__err("bad DNL height", "Corrupt JPEG");
m = stbi__get_marker(j);
} else {
if (!stbi__process_marker(j, m)) return 1;
@@ -3745,13 +3603,13 @@ static int stbi__decode_jpeg_image(stbi__jpeg * j) {
// static jfif-centered resampling (across block boundaries)
-typedef stbi_uc * (*resample_row_func)(stbi_uc * out, stbi_uc * in0,
- stbi_uc * in1, int w, int hs);
+typedef stbi_uc * (*resample_row_func)(stbi_uc * out, stbi_uc * in0, stbi_uc * in1, int w,
+ int hs);
#define stbi__div4(x) ((stbi_uc) ((x) >> 2))
-static stbi_uc * resample_row_1(stbi_uc * out, stbi_uc * in_near,
- stbi_uc * in_far, int w, int hs) {
+static stbi_uc * resample_row_1(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, int w,
+ int hs) {
STBI_NOTUSED(out);
STBI_NOTUSED(in_far);
STBI_NOTUSED(w);
@@ -3759,8 +3617,8 @@ static stbi_uc * resample_row_1(stbi_uc * out, stbi_uc * in_near,
return in_near;
}
-static stbi_uc * stbi__resample_row_v_2(stbi_uc * out, stbi_uc * in_near,
- stbi_uc * in_far, int w, int hs) {
+static stbi_uc * stbi__resample_row_v_2(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far,
+ int w, int hs) {
// need to generate two samples vertically for every one in input
int i;
STBI_NOTUSED(hs);
@@ -3768,8 +3626,8 @@ static stbi_uc * stbi__resample_row_v_2(stbi_uc * out, stbi_uc * in_near,
return out;
}
-static stbi_uc * stbi__resample_row_h_2(stbi_uc * out, stbi_uc * in_near,
- stbi_uc * in_far, int w, int hs) {
+static stbi_uc * stbi__resample_row_h_2(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far,
+ int w, int hs) {
// need to generate two samples horizontally for every one in input
int i;
stbi_uc * input = in_near;
@@ -3798,8 +3656,8 @@ static stbi_uc * stbi__resample_row_h_2(stbi_uc * out, stbi_uc * in_near,
#define stbi__div16(x) ((stbi_uc) ((x) >> 4))
-static stbi_uc * stbi__resample_row_hv_2(stbi_uc * out, stbi_uc * in_near,
- stbi_uc * in_far, int w, int hs) {
+static stbi_uc * stbi__resample_row_hv_2(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far,
+ int w, int hs) {
// need to generate 2x2 samples for every one in input
int i, t0, t1;
if (w == 1) {
@@ -3858,8 +3716,7 @@ static stbi_uc * stbi__resample_row_hv_2_simd(stbi_uc * out, stbi_uc * in_near,
__m128i prv0 = _mm_slli_si128(curr, 2);
__m128i nxt0 = _mm_srli_si128(curr, 2);
__m128i prev = _mm_insert_epi16(prv0, t1, 0);
- __m128i next
- = _mm_insert_epi16(nxt0, 3 * in_near[i + 8] + in_far[i + 8], 7);
+ __m128i next = _mm_insert_epi16(nxt0, 3 * in_near[i + 8] + in_far[i + 8], 7);
// horizontal filter, polyphase implementation since it's convenient:
// even pixels = 3*cur + prev = cur*4 + (prev - cur)
@@ -3899,8 +3756,7 @@ static stbi_uc * stbi__resample_row_hv_2_simd(stbi_uc * out, stbi_uc * in_near,
int16x8_t prv0 = vextq_s16(curr, curr, 7);
int16x8_t nxt0 = vextq_s16(curr, curr, 1);
int16x8_t prev = vsetq_lane_s16(t1, prv0, 0);
- int16x8_t next
- = vsetq_lane_s16(3 * in_near[i + 8] + in_far[i + 8], nxt0, 7);
+ int16x8_t next = vsetq_lane_s16(3 * in_near[i + 8] + in_far[i + 8], nxt0, 7);
// horizontal filter, polyphase implementation since it's convenient:
// even pixels = 3*cur + prev = cur*4 + (prev - cur)
@@ -3941,8 +3797,8 @@ static stbi_uc * stbi__resample_row_hv_2_simd(stbi_uc * out, stbi_uc * in_near,
}
#endif
-static stbi_uc * stbi__resample_row_generic(stbi_uc * out, stbi_uc * in_near,
- stbi_uc * in_far, int w, int hs) {
+static stbi_uc * stbi__resample_row_generic(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far,
+ int w, int hs) {
// resample with nearest-neighbor
int i, j;
STBI_NOTUSED(in_far);
@@ -3954,9 +3810,8 @@ static stbi_uc * stbi__resample_row_generic(stbi_uc * out, stbi_uc * in_near,
// this is a reduced-precision calculation of YCbCr-to-RGB introduced
// to make sure the code produces the same results in both SIMD and scalar
#define stbi__float2fixed(x) (((int) ((x) * 4096.0f + 0.5f)) << 8)
-static void stbi__YCbCr_to_RGB_row(stbi_uc * out, const stbi_uc * y,
- const stbi_uc * pcb, const stbi_uc * pcr,
- int count, int step) {
+static void stbi__YCbCr_to_RGB_row(stbi_uc * out, const stbi_uc * y, const stbi_uc * pcb,
+ const stbi_uc * pcr, int count, int step) {
int i;
for (i = 0; i < count; ++i) {
int y_fixed = (y[i] << 20) + (1 << 19); // rounding
@@ -3991,9 +3846,8 @@ static void stbi__YCbCr_to_RGB_row(stbi_uc * out, const stbi_uc * y,
}
#if defined(STBI_SSE2) || defined(STBI_NEON)
-static void stbi__YCbCr_to_RGB_simd(stbi_uc * out, stbi_uc const * y,
- stbi_uc const * pcb, stbi_uc const * pcr,
- int count, int step) {
+static void stbi__YCbCr_to_RGB_simd(stbi_uc * out, stbi_uc const * y, stbi_uc const * pcb,
+ stbi_uc const * pcr, int count, int step) {
int i = 0;
#ifdef STBI_SSE2
@@ -4004,10 +3858,8 @@ static void stbi__YCbCr_to_RGB_simd(stbi_uc * out, stbi_uc const * y,
// this is a fairly straightforward implementation and not super-optimized.
__m128i signflip = _mm_set1_epi8(-0x80);
__m128i cr_const0 = _mm_set1_epi16((short) (1.40200f * 4096.0f + 0.5f));
- __m128i cr_const1
- = _mm_set1_epi16(-(short) (0.71414f * 4096.0f + 0.5f));
- __m128i cb_const0
- = _mm_set1_epi16(-(short) (0.34414f * 4096.0f + 0.5f));
+ __m128i cr_const1 = _mm_set1_epi16(-(short) (0.71414f * 4096.0f + 0.5f));
+ __m128i cb_const0 = _mm_set1_epi16(-(short) (0.34414f * 4096.0f + 0.5f));
__m128i cb_const1 = _mm_set1_epi16((short) (1.77200f * 4096.0f + 0.5f));
__m128i y_bias = _mm_set1_epi8((char) (unsigned char) 128);
__m128i xw = _mm_set1_epi16(255); // alpha channel
@@ -4074,10 +3926,8 @@ static void stbi__YCbCr_to_RGB_simd(stbi_uc * out, stbi_uc const * y,
uint8x8_t y_bytes = vld1_u8(y + i);
uint8x8_t cr_bytes = vld1_u8(pcr + i);
uint8x8_t cb_bytes = vld1_u8(pcb + i);
- int8x8_t cr_biased
- = vreinterpret_s8_u8(vsub_u8(cr_bytes, signflip));
- int8x8_t cb_biased
- = vreinterpret_s8_u8(vsub_u8(cb_bytes, signflip));
+ int8x8_t cr_biased = vreinterpret_s8_u8(vsub_u8(cr_bytes, signflip));
+ int8x8_t cb_biased = vreinterpret_s8_u8(vsub_u8(cb_bytes, signflip));
// expand to s16
int16x8_t yws = vreinterpretq_s16_u16(vshll_n_u8(y_bytes, 4));
@@ -4181,14 +4031,13 @@ static stbi_uc stbi__blinn_8x8(stbi_uc x, stbi_uc y) {
return (stbi_uc) ((t + (t >> 8)) >> 8);
}
-static stbi_uc * load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y,
- int * comp, int req_comp) {
+static stbi_uc * load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y, int * comp,
+ int req_comp) {
int n, decode_n, is_rgb;
z->s->img_n = 0; // make stbi__cleanup_jpeg safe
// validate req_comp
- if (req_comp < 0 || req_comp > 4)
- return stbi__errpuc("bad req_comp", "Internal error");
+ if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error");
// load a jpeg image from whichever source, but leave in YCbCr format
if (!stbi__decode_jpeg_image(z)) {
@@ -4199,8 +4048,7 @@ static stbi_uc * load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y,
// determine actual number of components to generate
n = req_comp ? req_comp : z->s->img_n >= 3 ? 3 : 1;
- is_rgb = z->s->img_n == 3
- && (z->rgb == 3 || (z->app14_color_transform == 0 && !z->jfif));
+ is_rgb = z->s->img_n == 3 && (z->rgb == 3 || (z->app14_color_transform == 0 && !z->jfif));
if (z->s->img_n == 3 && n < 3 && !is_rgb) decode_n = 1;
else decode_n = z->s->img_n;
@@ -4240,12 +4088,9 @@ static stbi_uc * load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y,
r->line0 = r->line1 = z->img_comp[k].data;
if (r->hs == 1 && r->vs == 1) r->resample = resample_row_1;
- else if (r->hs == 1 && r->vs == 2)
- r->resample = stbi__resample_row_v_2;
- else if (r->hs == 2 && r->vs == 1)
- r->resample = stbi__resample_row_h_2;
- else if (r->hs == 2 && r->vs == 2)
- r->resample = z->resample_row_hv_2_kernel;
+ else if (r->hs == 1 && r->vs == 2) r->resample = stbi__resample_row_v_2;
+ else if (r->hs == 2 && r->vs == 1) r->resample = stbi__resample_row_h_2;
+ else if (r->hs == 2 && r->vs == 2) r->resample = z->resample_row_hv_2_kernel;
else r->resample = stbi__resample_row_generic;
}
@@ -4262,14 +4107,12 @@ static stbi_uc * load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y,
for (k = 0; k < decode_n; ++k) {
stbi__resample * r = &res_comp[k];
int y_bot = r->ystep >= (r->vs >> 1);
- coutput[k] = r->resample(
- z->img_comp[k].linebuf, y_bot ? r->line1 : r->line0,
- y_bot ? r->line0 : r->line1, r->w_lores, r->hs);
+ coutput[k] = r->resample(z->img_comp[k].linebuf, y_bot ? r->line1 : r->line0,
+ y_bot ? r->line0 : r->line1, r->w_lores, r->hs);
if (++r->ystep >= r->vs) {
r->ystep = 0;
r->line0 = r->line1;
- if (++r->ypos < z->img_comp[k].y)
- r->line1 += z->img_comp[k].w2;
+ if (++r->ypos < z->img_comp[k].y) r->line1 += z->img_comp[k].w2;
}
}
if (n >= 3) {
@@ -4284,8 +4127,7 @@ static stbi_uc * load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y,
out += n;
}
} else {
- z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2],
- z->s->img_x, n);
+ z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n);
}
} else if (z->s->img_n == 4) {
if (z->app14_color_transform == 0) { // CMYK
@@ -4298,8 +4140,7 @@ static stbi_uc * load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y,
out += n;
}
} else if (z->app14_color_transform == 2) { // YCCK
- z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2],
- z->s->img_x, n);
+ z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n);
for (i = 0; i < z->s->img_x; ++i) {
stbi_uc m = coutput[3][i];
out[0] = stbi__blinn_8x8(255 - out[0], m);
@@ -4308,8 +4149,7 @@ static stbi_uc * load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y,
out += n;
}
} else { // YCbCr + alpha? Ignore the fourth channel for now
- z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2],
- z->s->img_x, n);
+ z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n);
}
} else
for (i = 0; i < z->s->img_x; ++i) {
@@ -4321,12 +4161,12 @@ static stbi_uc * load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y,
if (is_rgb) {
if (n == 1)
for (i = 0; i < z->s->img_x; ++i)
- *out++ = stbi__compute_y(
- coutput[0][i], coutput[1][i], coutput[2][i]);
+ *out++
+ = stbi__compute_y(coutput[0][i], coutput[1][i], coutput[2][i]);
else {
for (i = 0; i < z->s->img_x; ++i, out += 2) {
- out[0] = stbi__compute_y(
- coutput[0][i], coutput[1][i], coutput[2][i]);
+ out[0]
+ = stbi__compute_y(coutput[0][i], coutput[1][i], coutput[2][i]);
out[1] = 255;
}
}
@@ -4342,8 +4182,7 @@ static stbi_uc * load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y,
}
} else if (z->s->img_n == 4 && z->app14_color_transform == 2) {
for (i = 0; i < z->s->img_x; ++i) {
- out[0] = stbi__blinn_8x8(255 - coutput[0][i],
- coutput[3][i]);
+ out[0] = stbi__blinn_8x8(255 - coutput[0][i], coutput[3][i]);
out[1] = 255;
out += n;
}
@@ -4362,16 +4201,13 @@ static stbi_uc * load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y,
stbi__cleanup_jpeg(z);
*out_x = z->s->img_x;
*out_y = z->s->img_y;
- if (comp)
- *comp = z->s->img_n >= 3
- ? 3
- : 1; // report original components, not output
+ if (comp) *comp = z->s->img_n >= 3 ? 3 : 1; // report original components, not output
return output;
}
}
-static void * stbi__jpeg_load(stbi__context * s, int * x, int * y, int * comp,
- int req_comp, stbi__result_info * ri) {
+static void * stbi__jpeg_load(stbi__context * s, int * x, int * y, int * comp, int req_comp,
+ stbi__result_info * ri) {
unsigned char * result;
stbi__jpeg * j = (stbi__jpeg *) stbi__malloc(sizeof(stbi__jpeg));
if (!j) return stbi__errpuc("outofmem", "Out of memory");
@@ -4460,8 +4296,7 @@ stbi_inline static int stbi__bit_reverse(int v, int bits) {
return stbi__bitreverse16(v) >> (16 - bits);
}
-static int stbi__zbuild_huffman(stbi__zhuffman * z, const stbi_uc * sizelist,
- int num) {
+static int stbi__zbuild_huffman(stbi__zhuffman * z, const stbi_uc * sizelist, int num) {
int i, k = 0;
int code, next_code[16], sizes[17];
@@ -4479,8 +4314,7 @@ static int stbi__zbuild_huffman(stbi__zhuffman * z, const stbi_uc * sizelist,
z->firstsymbol[i] = (stbi__uint16) k;
code = (code + sizes[i]);
if (sizes[i])
- if (code - 1 >= (1 << i))
- return stbi__err("bad codelengths", "Corrupt PNG");
+ if (code - 1 >= (1 << i)) return stbi__err("bad codelengths", "Corrupt PNG");
z->maxcode[i] = code << (16 - i); // preshift for inner loop
code <<= 1;
k += sizes[i];
@@ -4526,9 +4360,7 @@ typedef struct {
stbi__zhuffman z_length, z_distance;
} stbi__zbuf;
-stbi_inline static int stbi__zeof(stbi__zbuf * z) {
- return (z->zbuffer >= z->zbuffer_end);
-}
+stbi_inline static int stbi__zeof(stbi__zbuf * z) { return (z->zbuffer >= z->zbuffer_end); }
stbi_inline static stbi_uc stbi__zget8(stbi__zbuf * z) {
return stbi__zeof(z) ? 0 : *z->zbuffer++;
@@ -4565,15 +4397,13 @@ static int stbi__zhuffman_decode_slowpath(stbi__zbuf * a, stbi__zhuffman * z) {
// code size is s, so:
b = (k >> (16 - s)) - z->firstcode[s] + z->firstsymbol[s];
if (b >= STBI__ZNSYMS) return -1; // some data was corrupt somewhere!
- if (z->size[b] != s)
- return -1; // was originally an assert, but report failure instead.
+ if (z->size[b] != s) return -1; // was originally an assert, but report failure instead.
a->code_buffer >>= s;
a->num_bits -= s;
return z->value[b];
}
-stbi_inline static int stbi__zhuffman_decode(stbi__zbuf * a,
- stbi__zhuffman * z) {
+stbi_inline static int stbi__zhuffman_decode(stbi__zbuf * a, stbi__zhuffman * z) {
int b, s;
if (a->num_bits < 16) {
if (stbi__zeof(a)) {
@@ -4608,12 +4438,10 @@ static int stbi__zexpand(stbi__zbuf * z, char * zout,
char * q;
unsigned int cur, limit, old_limit;
z->zout = zout;
- if (!z->z_expandable)
- return stbi__err("output buffer limit", "Corrupt PNG");
+ if (!z->z_expandable) return stbi__err("output buffer limit", "Corrupt PNG");
cur = (unsigned int) (z->zout - z->zout_start);
limit = old_limit = (unsigned) (z->zout_end - z->zout_start);
- if (UINT_MAX - cur < (unsigned) n)
- return stbi__err("outofmem", "Out of memory");
+ if (UINT_MAX - cur < (unsigned) n) return stbi__err("outofmem", "Out of memory");
while (cur + n > limit) {
if (limit > UINT_MAX / 2) return stbi__err("outofmem", "Out of memory");
limit *= 2;
@@ -4631,18 +4459,16 @@ static const int stbi__zlength_base[31]
= {3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
-static const int stbi__zlength_extra[31]
- = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
- 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0};
+static const int stbi__zlength_extra[31] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
+ 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0};
static const int stbi__zdist_base[32]
= {1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33,
49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537,
2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0};
-static const int stbi__zdist_extra[32]
- = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6,
- 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13};
+static const int stbi__zdist_extra[32] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6,
+ 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13};
static int stbi__parse_huffman_block(stbi__zbuf * a) {
char * zout = a->zout;
@@ -4677,18 +4503,15 @@ static int stbi__parse_huffman_block(stbi__zbuf * a) {
"Corrupt PNG"); // per DEFLATE, length codes 286 and 287 must not appear in compressed data
z -= 257;
len = stbi__zlength_base[z];
- if (stbi__zlength_extra[z])
- len += stbi__zreceive(a, stbi__zlength_extra[z]);
+ if (stbi__zlength_extra[z]) len += stbi__zreceive(a, stbi__zlength_extra[z]);
z = stbi__zhuffman_decode(a, &a->z_distance);
if (z < 0 || z >= 30)
return stbi__err(
"bad huffman code",
"Corrupt PNG"); // per DEFLATE, distance codes 30 and 31 must not appear in compressed data
dist = stbi__zdist_base[z];
- if (stbi__zdist_extra[z])
- dist += stbi__zreceive(a, stbi__zdist_extra[z]);
- if (zout - a->zout_start < dist)
- return stbi__err("bad dist", "Corrupt PNG");
+ if (stbi__zdist_extra[z]) dist += stbi__zreceive(a, stbi__zdist_extra[z]);
+ if (zout - a->zout_start < dist) return stbi__err("bad dist", "Corrupt PNG");
if (len > a->zout_end - zout) {
if (!stbi__zexpand(a, zout, len)) return 0;
zout = a->zout;
@@ -4733,8 +4556,7 @@ static int stbi__compute_huffman_codes(stbi__zbuf * a) {
n = 0;
while (n < ntot) {
int c = stbi__zhuffman_decode(a, &z_codelength);
- if (c < 0 || c >= 19)
- return stbi__err("bad codelengths", "Corrupt PNG");
+ if (c < 0 || c >= 19) return stbi__err("bad codelengths", "Corrupt PNG");
if (c < 16) lencodes[n++] = (stbi_uc) c;
else {
stbi_uc fill = 0;
@@ -4749,8 +4571,7 @@ static int stbi__compute_huffman_codes(stbi__zbuf * a) {
} else {
return stbi__err("bad codelengths", "Corrupt PNG");
}
- if (ntot - n < c)
- return stbi__err("bad codelengths", "Corrupt PNG");
+ if (ntot - n < c) return stbi__err("bad codelengths", "Corrupt PNG");
memset(lencodes + n, fill, c);
n += c;
}
@@ -4768,8 +4589,7 @@ static int stbi__parse_uncompressed_block(stbi__zbuf * a) {
// drain the bit-packed data into header
k = 0;
while (a->num_bits > 0) {
- header[k++]
- = (stbi_uc) (a->code_buffer & 255); // suppress MSVC run-time check
+ header[k++] = (stbi_uc) (a->code_buffer & 255); // suppress MSVC run-time check
a->code_buffer >>= 8;
a->num_bits -= 8;
}
@@ -4779,8 +4599,7 @@ static int stbi__parse_uncompressed_block(stbi__zbuf * a) {
len = header[1] * 256 + header[0];
nlen = header[3] * 256 + header[2];
if (nlen != (len ^ 0xffff)) return stbi__err("zlib corrupt", "Corrupt PNG");
- if (a->zbuffer + len > a->zbuffer_end)
- return stbi__err("read past buffer", "Corrupt PNG");
+ if (a->zbuffer + len > a->zbuffer_end) return stbi__err("read past buffer", "Corrupt PNG");
if (a->zout + len > a->zout_end)
if (!stbi__zexpand(a, a->zout, len)) return 0;
memcpy(a->zout, a->zbuffer, len);
@@ -4794,8 +4613,7 @@ static int stbi__parse_zlib_header(stbi__zbuf * a) {
int cm = cmf & 15;
/* int cinfo = cmf >> 4; */
int flg = stbi__zget8(a);
- if (stbi__zeof(a))
- return stbi__err("bad zlib header", "Corrupt PNG"); // zlib spec
+ if (stbi__zeof(a)) return stbi__err("bad zlib header", "Corrupt PNG"); // zlib spec
if ((cmf * 256 + flg) % 31 != 0)
return stbi__err("bad zlib header", "Corrupt PNG"); // zlib spec
if (flg & 32)
@@ -4809,18 +4627,16 @@ static int stbi__parse_zlib_header(stbi__zbuf * a) {
}
static const stbi_uc stbi__zdefault_length[STBI__ZNSYMS]
- = {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, 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,
- 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, 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,
- 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, 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,
- 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, 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};
+ = {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, 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, 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, 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, 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, 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, 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, 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};
static const stbi_uc stbi__zdefault_distance[32]
= {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5};
@@ -4854,11 +4670,9 @@ static int stbi__parse_zlib(stbi__zbuf * a, int parse_header) {
} else {
if (type == 1) {
// use fixed code lengths
- if (!stbi__zbuild_huffman(&a->z_length, stbi__zdefault_length,
- STBI__ZNSYMS))
+ if (!stbi__zbuild_huffman(&a->z_length, stbi__zdefault_length, STBI__ZNSYMS))
return 0;
- if (!stbi__zbuild_huffman(&a->z_distance,
- stbi__zdefault_distance, 32))
+ if (!stbi__zbuild_huffman(&a->z_distance, stbi__zdefault_distance, 32))
return 0;
} else {
if (!stbi__compute_huffman_codes(a)) return 0;
@@ -4869,8 +4683,7 @@ static int stbi__parse_zlib(stbi__zbuf * a, int parse_header) {
return 1;
}
-static int stbi__do_zlib(stbi__zbuf * a, char * obuf, int olen, int exp,
- int parse_header) {
+static int stbi__do_zlib(stbi__zbuf * a, char * obuf, int olen, int exp, int parse_header) {
a->zout_start = obuf;
a->zout = obuf;
a->zout_end = obuf + olen;
@@ -4880,8 +4693,7 @@ static int stbi__do_zlib(stbi__zbuf * a, char * obuf, int olen, int exp,
}
STBIDEF char * stbi_zlib_decode_malloc_guesssize(const char * buffer, int len,
- int initial_size,
- int * outlen) {
+ int initial_size, int * outlen) {
stbi__zbuf a;
char * p = (char *) stbi__malloc(initial_size);
if (p == NULL) return NULL;
@@ -4896,15 +4708,12 @@ STBIDEF char * stbi_zlib_decode_malloc_guesssize(const char * buffer, int len,
}
}
-STBIDEF char * stbi_zlib_decode_malloc(char const * buffer, int len,
- int * outlen) {
+STBIDEF char * stbi_zlib_decode_malloc(char const * buffer, int len, int * outlen) {
return stbi_zlib_decode_malloc_guesssize(buffer, len, 16384, outlen);
}
-STBIDEF char * stbi_zlib_decode_malloc_guesssize_headerflag(const char * buffer,
- int len,
- int initial_size,
- int * outlen,
+STBIDEF char * stbi_zlib_decode_malloc_guesssize_headerflag(const char * buffer, int len,
+ int initial_size, int * outlen,
int parse_header) {
stbi__zbuf a;
char * p = (char *) stbi__malloc(initial_size);
@@ -4920,18 +4729,15 @@ STBIDEF char * stbi_zlib_decode_malloc_guesssize_headerflag(const char * buffer,
}
}
-STBIDEF int stbi_zlib_decode_buffer(char * obuffer, int olen,
- char const * ibuffer, int ilen) {
+STBIDEF int stbi_zlib_decode_buffer(char * obuffer, int olen, char const * ibuffer, int ilen) {
stbi__zbuf a;
a.zbuffer = (stbi_uc *) ibuffer;
a.zbuffer_end = (stbi_uc *) ibuffer + ilen;
- if (stbi__do_zlib(&a, obuffer, olen, 0, 1))
- return (int) (a.zout - a.zout_start);
+ if (stbi__do_zlib(&a, obuffer, olen, 0, 1)) return (int) (a.zout - a.zout_start);
else return -1;
}
-STBIDEF char * stbi_zlib_decode_noheader_malloc(char const * buffer, int len,
- int * outlen) {
+STBIDEF char * stbi_zlib_decode_noheader_malloc(char const * buffer, int len, int * outlen) {
stbi__zbuf a;
char * p = (char *) stbi__malloc(16384);
if (p == NULL) return NULL;
@@ -4946,13 +4752,12 @@ STBIDEF char * stbi_zlib_decode_noheader_malloc(char const * buffer, int len,
}
}
-STBIDEF int stbi_zlib_decode_noheader_buffer(char * obuffer, int olen,
- const char * ibuffer, int ilen) {
+STBIDEF int stbi_zlib_decode_noheader_buffer(char * obuffer, int olen, const char * ibuffer,
+ int ilen) {
stbi__zbuf a;
a.zbuffer = (stbi_uc *) ibuffer;
a.zbuffer_end = (stbi_uc *) ibuffer + ilen;
- if (stbi__do_zlib(&a, obuffer, olen, 0, 0))
- return (int) (a.zout - a.zout_start);
+ if (stbi__do_zlib(&a, obuffer, olen, 0, 0)) return (int) (a.zout - a.zout_start);
else return -1;
}
#endif
@@ -4984,8 +4789,7 @@ static int stbi__check_png_header(stbi__context * s) {
static const stbi_uc png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
int i;
for (i = 0; i < 8; ++i)
- if (stbi__get8(s) != png_sig[i])
- return stbi__err("bad png sig", "Not a PNG");
+ if (stbi__get8(s) != png_sig[i]) return stbi__err("bad png sig", "Not a PNG");
return 1;
}
@@ -5022,14 +4826,13 @@ static int stbi__paeth(int a, int b, int c) {
return t1;
}
-static const stbi_uc stbi__depth_scale_table[9]
- = {0, 0xff, 0x55, 0, 0x11, 0, 0, 0, 0x01};
+static const stbi_uc stbi__depth_scale_table[9] = {0, 0xff, 0x55, 0, 0x11, 0, 0, 0, 0x01};
// adds an extra all-255 alpha channel
// dest == src is legal
// img_n must be 1 or 3
-static void stbi__create_png_alpha_expand8(stbi_uc * dest, stbi_uc * src,
- stbi__uint32 x, int img_n) {
+static void stbi__create_png_alpha_expand8(stbi_uc * dest, stbi_uc * src, stbi__uint32 x,
+ int img_n) {
int i;
// must process data backwards since we allow dest==src
if (img_n == 1) {
@@ -5049,9 +4852,8 @@ static void stbi__create_png_alpha_expand8(stbi_uc * dest, stbi_uc * src,
}
// create the png data from post-deflated data
-static int stbi__create_png_image_raw(stbi__png * a, stbi_uc * raw,
- stbi__uint32 raw_len, int out_n,
- stbi__uint32 x, stbi__uint32 y, int depth,
+static int stbi__create_png_image_raw(stbi__png * a, stbi_uc * raw, stbi__uint32 raw_len,
+ int out_n, stbi__uint32 x, stbi__uint32 y, int depth,
int color) {
int bytes = (depth == 16 ? 2 : 1);
stbi__context * s = a->s;
@@ -5067,8 +4869,8 @@ static int stbi__create_png_image_raw(stbi__png * a, stbi_uc * raw,
int width = x;
STBI_ASSERT(out_n == s->img_n || out_n == s->img_n + 1);
- a->out = (stbi_uc *) stbi__malloc_mad3(
- x, y, output_bytes, 0); // extra bytes to write off the end into
+ a->out = (stbi_uc *) stbi__malloc_mad3(x, y, output_bytes,
+ 0); // extra bytes to write off the end into
if (!a->out) return stbi__err("outofmem", "Out of memory");
// note: error exits here don't need to clean up a->out individually,
@@ -5123,32 +4925,28 @@ static int stbi__create_png_image_raw(stbi__png * a, stbi_uc * raw,
cur[k] = STBI__BYTECAST(raw[k] + cur[k - filter_bytes]);
break;
case STBI__F_up:
- for (k = 0; k < nk; ++k)
- cur[k] = STBI__BYTECAST(raw[k] + prior[k]);
+ for (k = 0; k < nk; ++k) cur[k] = STBI__BYTECAST(raw[k] + prior[k]);
break;
case STBI__F_avg:
for (k = 0; k < filter_bytes; ++k)
cur[k] = STBI__BYTECAST(raw[k] + (prior[k] >> 1));
for (k = filter_bytes; k < nk; ++k)
- cur[k] = STBI__BYTECAST(
- raw[k] + ((prior[k] + cur[k - filter_bytes]) >> 1));
+ cur[k]
+ = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k - filter_bytes]) >> 1));
break;
case STBI__F_paeth:
for (k = 0; k < filter_bytes; ++k)
cur[k] = STBI__BYTECAST(
- raw[k]
- + prior[k]); // prior[k] == stbi__paeth(0,prior[k],0)
+ raw[k] + prior[k]); // prior[k] == stbi__paeth(0,prior[k],0)
for (k = filter_bytes; k < nk; ++k)
- cur[k] = STBI__BYTECAST(
- raw[k]
- + stbi__paeth(cur[k - filter_bytes], prior[k],
- prior[k - filter_bytes]));
+ cur[k] = STBI__BYTECAST(raw[k]
+ + stbi__paeth(cur[k - filter_bytes], prior[k],
+ prior[k - filter_bytes]));
break;
case STBI__F_avg_first:
memcpy(cur, raw, filter_bytes);
for (k = filter_bytes; k < nk; ++k)
- cur[k]
- = STBI__BYTECAST(raw[k] + (cur[k - filter_bytes] >> 1));
+ cur[k] = STBI__BYTECAST(raw[k] + (cur[k - filter_bytes] >> 1));
break;
}
@@ -5156,9 +4954,8 @@ static int stbi__create_png_image_raw(stbi__png * a, stbi_uc * raw,
// expand decoded bits in cur to dest, also adding an extra alpha channel if desired
if (depth < 8) {
- stbi_uc scale = (color == 0)
- ? stbi__depth_scale_table[depth]
- : 1; // scale grayscale values to 0..255 range
+ stbi_uc scale = (color == 0) ? stbi__depth_scale_table[depth]
+ : 1; // scale grayscale values to 0..255 range
stbi_uc * in = cur;
stbi_uc * out = dest;
stbi_uc inb = 0;
@@ -5187,8 +4984,7 @@ static int stbi__create_png_image_raw(stbi__png * a, stbi_uc * raw,
}
// insert alpha=255 values if desired
- if (img_n != out_n)
- stbi__create_png_alpha_expand8(dest, dest, x, img_n);
+ if (img_n != out_n) stbi__create_png_alpha_expand8(dest, dest, x, img_n);
} else if (depth == 8) {
if (img_n == out_n) memcpy(dest, cur, x * img_n);
else stbi__create_png_alpha_expand8(dest, cur, x, img_n);
@@ -5227,20 +5023,18 @@ static int stbi__create_png_image_raw(stbi__png * a, stbi_uc * raw,
}
static int stbi__create_png_image(stbi__png * a, stbi_uc * image_data,
- stbi__uint32 image_data_len, int out_n,
- int depth, int color, int interlaced) {
+ stbi__uint32 image_data_len, int out_n, int depth, int color,
+ int interlaced) {
int bytes = (depth == 16 ? 2 : 1);
int out_bytes = out_n * bytes;
stbi_uc * final;
int p;
if (!interlaced)
- return stbi__create_png_image_raw(a, image_data, image_data_len, out_n,
- a->s->img_x, a->s->img_y, depth,
- color);
+ return stbi__create_png_image_raw(a, image_data, image_data_len, out_n, a->s->img_x,
+ a->s->img_y, depth, color);
// de-interlacing
- final
- = (stbi_uc *) stbi__malloc_mad3(a->s->img_x, a->s->img_y, out_bytes, 0);
+ final = (stbi_uc *) stbi__malloc_mad3(a->s->img_x, a->s->img_y, out_bytes, 0);
if (!final) return stbi__err("outofmem", "Out of memory");
for (p = 0; p < 7; ++p) {
int xorig[] = {0, 4, 0, 2, 0, 1, 0};
@@ -5252,10 +5046,9 @@ static int stbi__create_png_image(stbi__png * a, stbi_uc * image_data,
x = (a->s->img_x - xorig[p] + xspc[p] - 1) / xspc[p];
y = (a->s->img_y - yorig[p] + yspc[p] - 1) / yspc[p];
if (x && y) {
- stbi__uint32 img_len
- = ((((a->s->img_n * x * depth) + 7) >> 3) + 1) * y;
- if (!stbi__create_png_image_raw(a, image_data, image_data_len,
- out_n, x, y, depth, color)) {
+ stbi__uint32 img_len = ((((a->s->img_n * x * depth) + 7) >> 3) + 1) * y;
+ if (!stbi__create_png_image_raw(a, image_data, image_data_len, out_n, x, y, depth,
+ color)) {
STBI_FREE(final);
return 0;
}
@@ -5263,8 +5056,7 @@ static int stbi__create_png_image(stbi__png * a, stbi_uc * image_data,
for (i = 0; i < x; ++i) {
int out_y = j * yspc[p] + yorig[p];
int out_x = i * xspc[p] + xorig[p];
- memcpy(final + out_y * a->s->img_x * out_bytes
- + out_x * out_bytes,
+ memcpy(final + out_y * a->s->img_x * out_bytes + out_x * out_bytes,
a->out + (j * x + i) * out_bytes, out_bytes);
}
}
@@ -5301,8 +5093,7 @@ static int stbi__compute_transparency(stbi__png * z, stbi_uc tc[3], int out_n) {
return 1;
}
-static int stbi__compute_transparency16(stbi__png * z, stbi__uint16 tc[3],
- int out_n) {
+static int stbi__compute_transparency16(stbi__png * z, stbi__uint16 tc[3], int out_n) {
stbi__context * s = z->s;
stbi__uint32 i, pixel_count = s->img_x * s->img_y;
stbi__uint16 * p = (stbi__uint16 *) z->out;
@@ -5325,8 +5116,7 @@ static int stbi__compute_transparency16(stbi__png * z, stbi__uint16 tc[3],
return 1;
}
-static int stbi__expand_png_palette(stbi__png * a, stbi_uc * palette, int len,
- int pal_img_n) {
+static int stbi__expand_png_palette(stbi__png * a, stbi_uc * palette, int len, int pal_img_n) {
stbi__uint32 i, pixel_count = a->s->img_x * a->s->img_y;
stbi_uc *p, *temp_out, *orig = a->out;
@@ -5365,8 +5155,7 @@ static int stbi__expand_png_palette(stbi__png * a, stbi_uc * palette, int len,
static int stbi__unpremultiply_on_load_global = 0;
static int stbi__de_iphone_flag_global = 0;
-STBIDEF void
-stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply) {
+STBIDEF void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply) {
stbi__unpremultiply_on_load_global = flag_true_if_should_unpremultiply;
}
@@ -5380,17 +5169,14 @@ STBIDEF void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert) {
#else
static STBI_THREAD_LOCAL int stbi__unpremultiply_on_load_local,
stbi__unpremultiply_on_load_set;
-static STBI_THREAD_LOCAL int stbi__de_iphone_flag_local,
- stbi__de_iphone_flag_set;
+static STBI_THREAD_LOCAL int stbi__de_iphone_flag_local, stbi__de_iphone_flag_set;
-STBIDEF void
-stbi_set_unpremultiply_on_load_thread(int flag_true_if_should_unpremultiply) {
+STBIDEF void stbi_set_unpremultiply_on_load_thread(int flag_true_if_should_unpremultiply) {
stbi__unpremultiply_on_load_local = flag_true_if_should_unpremultiply;
stbi__unpremultiply_on_load_set = 1;
}
-STBIDEF void
-stbi_convert_iphone_png_to_rgb_thread(int flag_true_if_should_convert) {
+STBIDEF void stbi_convert_iphone_png_to_rgb_thread(int flag_true_if_should_convert) {
stbi__de_iphone_flag_local = flag_true_if_should_convert;
stbi__de_iphone_flag_set = 1;
}
@@ -5399,8 +5185,7 @@ stbi_convert_iphone_png_to_rgb_thread(int flag_true_if_should_convert) {
(stbi__unpremultiply_on_load_set ? stbi__unpremultiply_on_load_local \
: stbi__unpremultiply_on_load_global)
#define stbi__de_iphone_flag \
- (stbi__de_iphone_flag_set ? stbi__de_iphone_flag_local \
- : stbi__de_iphone_flag_global)
+ (stbi__de_iphone_flag_set ? stbi__de_iphone_flag_local : stbi__de_iphone_flag_global)
#endif // STBI_THREAD_LOCAL
static void stbi__de_iphone(stbi__png * z) {
@@ -5446,8 +5231,7 @@ static void stbi__de_iphone(stbi__png * z) {
}
#define STBI__PNG_TYPE(a, b, c, d) \
- (((unsigned) (a) << 24) + ((unsigned) (b) << 16) + ((unsigned) (c) << 8) \
- + (unsigned) (d))
+ (((unsigned) (a) << 24) + ((unsigned) (b) << 16) + ((unsigned) (c) << 8) + (unsigned) (d))
static int stbi__parse_png_file(stbi__png * z, int scan, int req_comp) {
stbi_uc palette[1024], pal_img_n = 0;
@@ -5476,43 +5260,34 @@ static int stbi__parse_png_file(stbi__png * z, int scan, int req_comp) {
int comp, filter;
if (!first) return stbi__err("multiple IHDR", "Corrupt PNG");
first = 0;
- if (c.length != 13)
- return stbi__err("bad IHDR len", "Corrupt PNG");
+ if (c.length != 13) return stbi__err("bad IHDR len", "Corrupt PNG");
s->img_x = stbi__get32be(s);
s->img_y = stbi__get32be(s);
if (s->img_y > STBI_MAX_DIMENSIONS)
- return stbi__err("too large",
- "Very large image (corrupt?)");
+ return stbi__err("too large", "Very large image (corrupt?)");
if (s->img_x > STBI_MAX_DIMENSIONS)
- return stbi__err("too large",
- "Very large image (corrupt?)");
+ return stbi__err("too large", "Very large image (corrupt?)");
z->depth = stbi__get8(s);
- if (z->depth != 1 && z->depth != 2 && z->depth != 4
- && z->depth != 8 && z->depth != 16)
+ if (z->depth != 1 && z->depth != 2 && z->depth != 4 && z->depth != 8
+ && z->depth != 16)
return stbi__err("1/2/4/8/16-bit only",
"PNG not supported: 1/2/4/8/16-bit only");
color = stbi__get8(s);
if (color > 6) return stbi__err("bad ctype", "Corrupt PNG");
- if (color == 3 && z->depth == 16)
- return stbi__err("bad ctype", "Corrupt PNG");
+ if (color == 3 && z->depth == 16) return stbi__err("bad ctype", "Corrupt PNG");
if (color == 3) pal_img_n = 3;
- else if (color & 1)
- return stbi__err("bad ctype", "Corrupt PNG");
+ else if (color & 1) return stbi__err("bad ctype", "Corrupt PNG");
comp = stbi__get8(s);
if (comp) return stbi__err("bad comp method", "Corrupt PNG");
filter = stbi__get8(s);
- if (filter)
- return stbi__err("bad filter method", "Corrupt PNG");
+ if (filter) return stbi__err("bad filter method", "Corrupt PNG");
interlace = stbi__get8(s);
- if (interlace > 1)
- return stbi__err("bad interlace method", "Corrupt PNG");
- if (!s->img_x || !s->img_y)
- return stbi__err("0-pixel image", "Corrupt PNG");
+ if (interlace > 1) return stbi__err("bad interlace method", "Corrupt PNG");
+ if (!s->img_x || !s->img_y) return stbi__err("0-pixel image", "Corrupt PNG");
if (!pal_img_n) {
s->img_n = (color & 2 ? 3 : 1) + (color & 4 ? 1 : 0);
if ((1 << 30) / s->img_x / s->img_n < s->img_y)
- return stbi__err("too large",
- "Image too large to decode");
+ return stbi__err("too large", "Image too large to decode");
} else {
// if paletted, then pal_n is our final components, and
// img_n is # components to decompress/filter.
@@ -5526,11 +5301,9 @@ static int stbi__parse_png_file(stbi__png * z, int scan, int req_comp) {
case STBI__PNG_TYPE('P', 'L', 'T', 'E'): {
if (first) return stbi__err("first not IHDR", "Corrupt PNG");
- if (c.length > 256 * 3)
- return stbi__err("invalid PLTE", "Corrupt PNG");
+ if (c.length > 256 * 3) return stbi__err("invalid PLTE", "Corrupt PNG");
pal_len = c.length / 3;
- if (pal_len * 3 != c.length)
- return stbi__err("invalid PLTE", "Corrupt PNG");
+ if (pal_len * 3 != c.length) return stbi__err("invalid PLTE", "Corrupt PNG");
for (i = 0; i < pal_len; ++i) {
palette[i * 4 + 0] = stbi__get8(s);
palette[i * 4 + 1] = stbi__get8(s);
@@ -5542,23 +5315,18 @@ static int stbi__parse_png_file(stbi__png * z, int scan, int req_comp) {
case STBI__PNG_TYPE('t', 'R', 'N', 'S'): {
if (first) return stbi__err("first not IHDR", "Corrupt PNG");
- if (z->idata)
- return stbi__err("tRNS after IDAT", "Corrupt PNG");
+ if (z->idata) return stbi__err("tRNS after IDAT", "Corrupt PNG");
if (pal_img_n) {
if (scan == STBI__SCAN_header) {
s->img_n = 4;
return 1;
}
- if (pal_len == 0)
- return stbi__err("tRNS before PLTE", "Corrupt PNG");
- if (c.length > pal_len)
- return stbi__err("bad tRNS len", "Corrupt PNG");
+ if (pal_len == 0) return stbi__err("tRNS before PLTE", "Corrupt PNG");
+ if (c.length > pal_len) return stbi__err("bad tRNS len", "Corrupt PNG");
pal_img_n = 4;
- for (i = 0; i < c.length; ++i)
- palette[i * 4 + 3] = stbi__get8(s);
+ for (i = 0; i < c.length; ++i) palette[i * 4 + 3] = stbi__get8(s);
} else {
- if (!(s->img_n & 1))
- return stbi__err("tRNS with alpha", "Corrupt PNG");
+ if (!(s->img_n & 1)) return stbi__err("tRNS with alpha", "Corrupt PNG");
if (c.length != (stbi__uint32) s->img_n * 2)
return stbi__err("bad tRNS len", "Corrupt PNG");
has_trans = 1;
@@ -5569,14 +5337,12 @@ static int stbi__parse_png_file(stbi__png * z, int scan, int req_comp) {
}
if (z->depth == 16) {
for (k = 0; k < s->img_n; ++k)
- tc16[k] = (stbi__uint16) stbi__get16be(
- s); // copy the values as-is
+ tc16[k] = (stbi__uint16) stbi__get16be(s); // copy the values as-is
} else {
for (k = 0; k < s->img_n; ++k)
- tc[k]
- = (stbi_uc) (stbi__get16be(s) & 255)
- * stbi__depth_scale_table
- [z->depth]; // non 8-bit images will be larger
+ tc[k] = (stbi_uc) (stbi__get16be(s) & 255)
+ * stbi__depth_scale_table
+ [z->depth]; // non 8-bit images will be larger
}
}
break;
@@ -5584,28 +5350,23 @@ static int stbi__parse_png_file(stbi__png * z, int scan, int req_comp) {
case STBI__PNG_TYPE('I', 'D', 'A', 'T'): {
if (first) return stbi__err("first not IHDR", "Corrupt PNG");
- if (pal_img_n && !pal_len)
- return stbi__err("no PLTE", "Corrupt PNG");
+ if (pal_img_n && !pal_len) return stbi__err("no PLTE", "Corrupt PNG");
if (scan == STBI__SCAN_header) {
// header scan definitely stops at first IDAT
if (pal_img_n) s->img_n = pal_img_n;
return 1;
}
if (c.length > (1u << 30))
- return stbi__err("IDAT size limit",
- "IDAT section larger than 2^30 bytes");
+ return stbi__err("IDAT size limit", "IDAT section larger than 2^30 bytes");
if ((int) (ioff + c.length) < (int) ioff) return 0;
if (ioff + c.length > idata_limit) {
stbi__uint32 idata_limit_old = idata_limit;
stbi_uc * p;
- if (idata_limit == 0)
- idata_limit = c.length > 4096 ? c.length : 4096;
+ if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096;
while (ioff + c.length > idata_limit) idata_limit *= 2;
STBI_NOTUSED(idata_limit_old);
- p = (stbi_uc *) STBI_REALLOC_SIZED(
- z->idata, idata_limit_old, idata_limit);
- if (p == NULL)
- return stbi__err("outofmem", "Out of memory");
+ p = (stbi_uc *) STBI_REALLOC_SIZED(z->idata, idata_limit_old, idata_limit);
+ if (p == NULL) return stbi__err("outofmem", "Out of memory");
z->idata = p;
}
if (!stbi__getn(s, z->idata + ioff, c.length))
@@ -5618,48 +5379,36 @@ static int stbi__parse_png_file(stbi__png * z, int scan, int req_comp) {
stbi__uint32 raw_len, bpl;
if (first) return stbi__err("first not IHDR", "Corrupt PNG");
if (scan != STBI__SCAN_load) return 1;
- if (z->idata == NULL)
- return stbi__err("no IDAT", "Corrupt PNG");
+ if (z->idata == NULL) return stbi__err("no IDAT", "Corrupt PNG");
// initial guess for decoded data size to avoid unnecessary reallocs
- bpl = (s->img_x * z->depth + 7)
- / 8; // bytes per line, per component
+ bpl = (s->img_x * z->depth + 7) / 8; // bytes per line, per component
raw_len = bpl * s->img_y * s->img_n /* pixels */
+ s->img_y /* filter mode per row */;
- z->expanded
- = (stbi_uc *) stbi_zlib_decode_malloc_guesssize_headerflag(
- (char *) z->idata, ioff, raw_len, (int *) &raw_len,
- !is_iphone);
+ z->expanded = (stbi_uc *) stbi_zlib_decode_malloc_guesssize_headerflag(
+ (char *) z->idata, ioff, raw_len, (int *) &raw_len, !is_iphone);
if (z->expanded == NULL) return 0; // zlib should set error
STBI_FREE(z->idata);
z->idata = NULL;
- if ((req_comp == s->img_n + 1 && req_comp != 3 && !pal_img_n)
- || has_trans)
+ if ((req_comp == s->img_n + 1 && req_comp != 3 && !pal_img_n) || has_trans)
s->img_out_n = s->img_n + 1;
else s->img_out_n = s->img_n;
- if (!stbi__create_png_image(z, z->expanded, raw_len,
- s->img_out_n, z->depth, color,
- interlace))
+ if (!stbi__create_png_image(z, z->expanded, raw_len, s->img_out_n, z->depth,
+ color, interlace))
return 0;
if (has_trans) {
if (z->depth == 16) {
- if (!stbi__compute_transparency16(z, tc16,
- s->img_out_n))
- return 0;
+ if (!stbi__compute_transparency16(z, tc16, s->img_out_n)) return 0;
} else {
- if (!stbi__compute_transparency(z, tc, s->img_out_n))
- return 0;
+ if (!stbi__compute_transparency(z, tc, s->img_out_n)) return 0;
}
}
- if (is_iphone && stbi__de_iphone_flag && s->img_out_n > 2)
- stbi__de_iphone(z);
+ if (is_iphone && stbi__de_iphone_flag && s->img_out_n > 2) stbi__de_iphone(z);
if (pal_img_n) {
// pal_img_n == 3 or 4
s->img_n = pal_img_n; // record the actual colors we had
s->img_out_n = pal_img_n;
if (req_comp >= 3) s->img_out_n = req_comp;
- if (!stbi__expand_png_palette(z, palette, pal_len,
- s->img_out_n))
- return 0;
+ if (!stbi__expand_png_palette(z, palette, pal_len, s->img_out_n)) return 0;
} else if (has_trans) {
// non-paletted image with tRNS -> source image has (constant) alpha
++s->img_n;
@@ -5683,9 +5432,8 @@ static int stbi__parse_png_file(stbi__png * z, int scan, int req_comp) {
invalid_chunk[2] = STBI__BYTECAST(c.type >> 8);
invalid_chunk[3] = STBI__BYTECAST(c.type >> 0);
#endif
- return stbi__err(
- invalid_chunk,
- "PNG not supported: unknown PNG chunk type");
+ return stbi__err(invalid_chunk,
+ "PNG not supported: unknown PNG chunk type");
}
stbi__skip(s, c.length);
break;
@@ -5695,11 +5443,10 @@ static int stbi__parse_png_file(stbi__png * z, int scan, int req_comp) {
}
}
-static void * stbi__do_png(stbi__png * p, int * x, int * y, int * n,
- int req_comp, stbi__result_info * ri) {
+static void * stbi__do_png(stbi__png * p, int * x, int * y, int * n, int req_comp,
+ stbi__result_info * ri) {
void * result = NULL;
- if (req_comp < 0 || req_comp > 4)
- return stbi__errpuc("bad req_comp", "Internal error");
+ if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error");
if (stbi__parse_png_file(p, STBI__SCAN_load, req_comp)) {
if (p->depth <= 8) ri->bits_per_channel = 8;
else if (p->depth == 16) ri->bits_per_channel = 16;
@@ -5710,13 +5457,11 @@ static void * stbi__do_png(stbi__png * p, int * x, int * y, int * n,
p->out = NULL;
if (req_comp && req_comp != p->s->img_out_n) {
if (ri->bits_per_channel == 8)
- result = stbi__convert_format((unsigned char *) result,
- p->s->img_out_n, req_comp,
- p->s->img_x, p->s->img_y);
+ result = stbi__convert_format((unsigned char *) result, p->s->img_out_n,
+ req_comp, p->s->img_x, p->s->img_y);
else
- result = stbi__convert_format16((stbi__uint16 *) result,
- p->s->img_out_n, req_comp,
- p->s->img_x, p->s->img_y);
+ result = stbi__convert_format16((stbi__uint16 *) result, p->s->img_out_n,
+ req_comp, p->s->img_x, p->s->img_y);
p->s->img_out_n = req_comp;
if (result == NULL) return result;
}
@@ -5734,8 +5479,8 @@ static void * stbi__do_png(stbi__png * p, int * x, int * y, int * n,
return result;
}
-static void * stbi__png_load(stbi__context * s, int * x, int * y, int * comp,
- int req_comp, stbi__result_info * ri) {
+static void * stbi__png_load(stbi__context * s, int * x, int * y, int * comp, int req_comp,
+ stbi__result_info * ri) {
stbi__png p;
p.s = s;
return stbi__do_png(&p, x, y, comp, req_comp, ri);
@@ -5926,8 +5671,8 @@ static void * stbi__bmp_parse_header(stbi__context * s, stbi__bmp_data * info) {
"BMP type not supported: unsupported "
"compression"); // this includes PNG/JPEG modes
if (compress == 3 && info->bpp != 16 && info->bpp != 32)
- return stbi__errpuc(
- "bad BMP", "bad BMP"); // bitfields requires 16 or 32 bits/pixel
+ return stbi__errpuc("bad BMP",
+ "bad BMP"); // bitfields requires 16 or 32 bits/pixel
stbi__get32le(s); // discard sizeof
stbi__get32le(s); // discard hres
stbi__get32le(s); // discard vres
@@ -5958,18 +5703,15 @@ static void * stbi__bmp_parse_header(stbi__context * s, stbi__bmp_data * info) {
} else {
// V4/V5 header
int i;
- if (hsz != 108 && hsz != 124)
- return stbi__errpuc("bad BMP", "bad BMP");
+ if (hsz != 108 && hsz != 124) return stbi__errpuc("bad BMP", "bad BMP");
info->mr = stbi__get32le(s);
info->mg = stbi__get32le(s);
info->mb = stbi__get32le(s);
info->ma = stbi__get32le(s);
- if (compress
- != 3) // override mr/mg/mb unless in BI_BITFIELDS mode, as per docs
+ if (compress != 3) // override mr/mg/mb unless in BI_BITFIELDS mode, as per docs
stbi__bmp_set_mask_defaults(info, compress);
stbi__get32le(s); // discard color space
- for (i = 0; i < 12; ++i)
- stbi__get32le(s); // discard color space parameters
+ for (i = 0; i < 12; ++i) stbi__get32le(s); // discard color space parameters
if (hsz == 124) {
stbi__get32le(s); // discard rendering intent
stbi__get32le(s); // discard offset of profile data
@@ -5981,8 +5723,8 @@ static void * stbi__bmp_parse_header(stbi__context * s, stbi__bmp_data * info) {
return (void *) 1;
}
-static void * stbi__bmp_load(stbi__context * s, int * x, int * y, int * comp,
- int req_comp, stbi__result_info * ri) {
+static void * stbi__bmp_load(stbi__context * s, int * x, int * y, int * comp, int req_comp,
+ stbi__result_info * ri) {
stbi_uc * out;
unsigned int mr = 0, mg = 0, mb = 0, ma = 0, all_a;
stbi_uc pal[256][4];
@@ -5992,8 +5734,7 @@ static void * stbi__bmp_load(stbi__context * s, int * x, int * y, int * comp,
STBI_NOTUSED(ri);
info.all_a = 255;
- if (stbi__bmp_parse_header(s, &info) == NULL)
- return NULL; // error code already set
+ if (stbi__bmp_parse_header(s, &info) == NULL) return NULL; // error code already set
flip_vertically = ((int) s->img_y) > 0;
s->img_y = abs((int) s->img_y);
@@ -6012,17 +5753,14 @@ static void * stbi__bmp_load(stbi__context * s, int * x, int * y, int * comp,
if (info.hsz == 12) {
if (info.bpp < 24) psize = (info.offset - info.extra_read - 24) / 3;
} else {
- if (info.bpp < 16)
- psize = (info.offset - info.extra_read - info.hsz) >> 2;
+ if (info.bpp < 16) psize = (info.offset - info.extra_read - info.hsz) >> 2;
}
if (psize == 0) {
// accept some number of extra bytes after the header, but if the offset points either to before
// the header ends or implies a large amount of extra data, reject the file as malformed
int bytes_read_so_far
- = s->callback_already_read
- + (int) (s->img_buffer - s->img_buffer_original);
- int header_limit
- = 1024; // max we actually read is below 256 bytes currently.
+ = s->callback_already_read + (int) (s->img_buffer - s->img_buffer_original);
+ int header_limit = 1024; // max we actually read is below 256 bytes currently.
int extra_data_limit
= 256
* 4; // what ordinarily goes here is a palette; 256 entries*4 bytes is its max size.
@@ -6116,8 +5854,8 @@ static void * stbi__bmp_load(stbi__context * s, int * x, int * y, int * comp,
}
}
} else {
- int rshift = 0, gshift = 0, bshift = 0, ashift = 0, rcount = 0,
- gcount = 0, bcount = 0, acount = 0;
+ int rshift = 0, gshift = 0, bshift = 0, ashift = 0, rcount = 0, gcount = 0, bcount = 0,
+ acount = 0;
int z = 0;
int easy = 0;
stbi__skip(s, info.offset - info.extra_read - info.hsz);
@@ -6128,9 +5866,7 @@ static void * stbi__bmp_load(stbi__context * s, int * x, int * y, int * comp,
if (info.bpp == 24) {
easy = 1;
} else if (info.bpp == 32) {
- if (mb == 0xff && mg == 0xff00 && mr == 0x00ff0000
- && ma == 0xff000000)
- easy = 2;
+ if (mb == 0xff && mg == 0xff00 && mr == 0x00ff0000 && ma == 0xff000000) easy = 2;
}
if (!easy) {
if (!mr || !mg || !mb) {
@@ -6167,15 +5903,11 @@ static void * stbi__bmp_load(stbi__context * s, int * x, int * y, int * comp,
int bpp = info.bpp;
for (i = 0; i < (int) s->img_x; ++i) {
stbi__uint32 v
- = (bpp == 16 ? (stbi__uint32) stbi__get16le(s)
- : stbi__get32le(s));
+ = (bpp == 16 ? (stbi__uint32) stbi__get16le(s) : stbi__get32le(s));
unsigned int a;
- out[z++] = STBI__BYTECAST(
- stbi__shiftsigned(v & mr, rshift, rcount));
- out[z++] = STBI__BYTECAST(
- stbi__shiftsigned(v & mg, gshift, gcount));
- out[z++] = STBI__BYTECAST(
- stbi__shiftsigned(v & mb, bshift, bcount));
+ out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mr, rshift, rcount));
+ out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mg, gshift, gcount));
+ out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mb, bshift, bcount));
a = (ma ? stbi__shiftsigned(v & ma, ashift, acount) : 255);
all_a |= a;
if (target == 4) out[z++] = STBI__BYTECAST(a);
@@ -6204,8 +5936,7 @@ static void * stbi__bmp_load(stbi__context * s, int * x, int * y, int * comp,
if (req_comp && req_comp != target) {
out = stbi__convert_format(out, target, req_comp, s->img_x, s->img_y);
- if (out == NULL)
- return out; // stbi__convert_format frees input on failure
+ if (out == NULL) return out; // stbi__convert_format frees input on failure
}
*x = s->img_x;
@@ -6240,8 +5971,7 @@ static int stbi__tga_get_comp(int bits_per_pixel, int is_grey, int * is_rgb16) {
}
static int stbi__tga_info(stbi__context * s, int * x, int * y, int * comp) {
- int tga_w, tga_h, tga_comp, tga_image_type, tga_bits_per_pixel,
- tga_colormap_bpp;
+ int tga_w, tga_h, tga_comp, tga_image_type, tga_bits_per_pixel, tga_colormap_bpp;
int sz, tga_colormap_type;
stbi__get8(s); // discard Offset
tga_colormap_type = stbi__get8(s); // colormap type
@@ -6255,8 +5985,7 @@ static int stbi__tga_info(stbi__context * s, int * x, int * y, int * comp) {
stbi__rewind(s);
return 0;
}
- stbi__skip(
- s, 4); // skip index of first colormap entry and number of entries
+ stbi__skip(s, 4); // skip index of first colormap entry and number of entries
sz = stbi__get8(s); // check bits per palette color entry
if ((sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32)) {
stbi__rewind(s);
@@ -6265,8 +5994,8 @@ static int stbi__tga_info(stbi__context * s, int * x, int * y, int * comp) {
stbi__skip(s, 4); // skip image x and y origin
tga_colormap_bpp = sz;
} else { // "normal" image w/o colormap - only RGB or grey allowed, +/- RLE
- if ((tga_image_type != 2) && (tga_image_type != 3)
- && (tga_image_type != 10) && (tga_image_type != 11)) {
+ if ((tga_image_type != 2) && (tga_image_type != 3) && (tga_image_type != 10)
+ && (tga_image_type != 11)) {
stbi__rewind(s);
return 0; // only RGB or grey allowed, +/- RLE
}
@@ -6294,9 +6023,8 @@ static int stbi__tga_info(stbi__context * s, int * x, int * y, int * comp) {
}
tga_comp = stbi__tga_get_comp(tga_colormap_bpp, 0, NULL);
} else {
- tga_comp = stbi__tga_get_comp(
- tga_bits_per_pixel, (tga_image_type == 3) || (tga_image_type == 11),
- NULL);
+ tga_comp = stbi__tga_get_comp(tga_bits_per_pixel,
+ (tga_image_type == 3) || (tga_image_type == 11), NULL);
}
if (!tga_comp) {
stbi__rewind(s);
@@ -6316,13 +6044,10 @@ static int stbi__tga_test(stbi__context * s) {
if (tga_color_type > 1) goto errorEnd; // only RGB or indexed allowed
sz = stbi__get8(s); // image type
if (tga_color_type == 1) { // colormapped (paletted) image
- if (sz != 1 && sz != 9)
- goto errorEnd; // colortype 1 demands image type 1 or 9
- stbi__skip(
- s, 4); // skip index of first colormap entry and number of entries
+ if (sz != 1 && sz != 9) goto errorEnd; // colortype 1 demands image type 1 or 9
+ stbi__skip(s, 4); // skip index of first colormap entry and number of entries
sz = stbi__get8(s); // check bits per palette color entry
- if ((sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32))
- goto errorEnd;
+ if ((sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32)) goto errorEnd;
stbi__skip(s, 4); // skip image x and y origin
} else { // "normal" image w/o colormap
if ((sz != 2) && (sz != 3) && (sz != 10) && (sz != 11))
@@ -6334,8 +6059,7 @@ static int stbi__tga_test(stbi__context * s) {
sz = stbi__get8(s); // bits per pixel
if ((tga_color_type == 1) && (sz != 8) && (sz != 16))
goto errorEnd; // for colormapped images, bpp is size of an index
- if ((sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32))
- goto errorEnd;
+ if ((sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32)) goto errorEnd;
res = 1; // if we got this far, everything's good and we can return 1 instead of 0
@@ -6363,8 +6087,8 @@ static void stbi__tga_read_rgb16(stbi__context * s, stbi_uc * out) {
// so let's treat all 15 and 16bit TGAs as RGB with no alpha.
}
-static void * stbi__tga_load(stbi__context * s, int * x, int * y, int * comp,
- int req_comp, stbi__result_info * ri) {
+static void * stbi__tga_load(stbi__context * s, int * x, int * y, int * comp, int req_comp,
+ stbi__result_info * ri) {
// read in the TGA header stuff
int tga_offset = stbi__get8(s);
int tga_indexed = stbi__get8(s);
@@ -6406,11 +6130,8 @@ static void * stbi__tga_load(stbi__context * s, int * x, int * y, int * comp,
tga_inverted = 1 - ((tga_inverted >> 5) & 1);
// If I'm paletted, then I'll use the number of bits from the palette
- if (tga_indexed)
- tga_comp = stbi__tga_get_comp(tga_palette_bits, 0, &tga_rgb16);
- else
- tga_comp = stbi__tga_get_comp(tga_bits_per_pixel, (tga_image_type == 3),
- &tga_rgb16);
+ if (tga_indexed) tga_comp = stbi__tga_get_comp(tga_palette_bits, 0, &tga_rgb16);
+ else tga_comp = stbi__tga_get_comp(tga_bits_per_pixel, (tga_image_type == 3), &tga_rgb16);
if (!tga_comp) // shouldn't really happen, stbi__tga_test() should have ensured basic consistency
return stbi__errpuc("bad format", "Can't find out TGA pixelformat");
@@ -6423,8 +6144,7 @@ static void * stbi__tga_load(stbi__context * s, int * x, int * y, int * comp,
if (!stbi__mad3sizes_valid(tga_width, tga_height, tga_comp, 0))
return stbi__errpuc("too large", "Corrupt TGA");
- tga_data = (unsigned char *) stbi__malloc_mad3(tga_width, tga_height,
- tga_comp, 0);
+ tga_data = (unsigned char *) stbi__malloc_mad3(tga_width, tga_height, tga_comp, 0);
if (!tga_data) return stbi__errpuc("outofmem", "Out of memory");
// skip to the data's starting position (offset usually = 0)
@@ -6439,8 +6159,7 @@ static void * stbi__tga_load(stbi__context * s, int * x, int * y, int * comp,
} else {
// do I need to load a palette?
if (tga_indexed) {
- if (tga_palette_len
- == 0) { /* you have to have at least one entry! */
+ if (tga_palette_len == 0) { /* you have to have at least one entry! */
STBI_FREE(tga_data);
return stbi__errpuc("bad palette", "Corrupt TGA");
}
@@ -6448,8 +6167,7 @@ static void * stbi__tga_load(stbi__context * s, int * x, int * y, int * comp,
// any data to skip? (offset usually = 0)
stbi__skip(s, tga_palette_start);
// load the palette
- tga_palette = (unsigned char *) stbi__malloc_mad2(tga_palette_len,
- tga_comp, 0);
+ tga_palette = (unsigned char *) stbi__malloc_mad2(tga_palette_len, tga_comp, 0);
if (!tga_palette) {
STBI_FREE(tga_data);
return stbi__errpuc("outofmem", "Out of memory");
@@ -6461,8 +6179,7 @@ static void * stbi__tga_load(stbi__context * s, int * x, int * y, int * comp,
stbi__tga_read_rgb16(s, pal_entry);
pal_entry += tga_comp;
}
- } else if (!stbi__getn(s, tga_palette,
- tga_palette_len * tga_comp)) {
+ } else if (!stbi__getn(s, tga_palette, tga_palette_len * tga_comp)) {
STBI_FREE(tga_data);
STBI_FREE(tga_palette);
return stbi__errpuc("bad palette", "Corrupt TGA");
@@ -6489,8 +6206,7 @@ static void * stbi__tga_load(stbi__context * s, int * x, int * y, int * comp,
// load however much data we did have
if (tga_indexed) {
// read in index, then perform the lookup
- int pal_idx = (tga_bits_per_pixel == 8) ? stbi__get8(s)
- : stbi__get16le(s);
+ int pal_idx = (tga_bits_per_pixel == 8) ? stbi__get8(s) : stbi__get16le(s);
if (pal_idx >= tga_palette_len) {
// invalid index
pal_idx = 0;
@@ -6513,8 +6229,7 @@ static void * stbi__tga_load(stbi__context * s, int * x, int * y, int * comp,
} // end of reading a pixel
// copy data
- for (j = 0; j < tga_comp; ++j)
- tga_data[i * tga_comp + j] = raw_data[j];
+ for (j = 0; j < tga_comp; ++j) tga_data[i * tga_comp + j] = raw_data[j];
// in case we're in RLE mode, keep counting down
--RLE_count;
@@ -6552,13 +6267,11 @@ static void * stbi__tga_load(stbi__context * s, int * x, int * y, int * comp,
// convert to target component count
if (req_comp && req_comp != tga_comp)
- tga_data = stbi__convert_format(tga_data, tga_comp, req_comp, tga_width,
- tga_height);
+ tga_data = stbi__convert_format(tga_data, tga_comp, req_comp, tga_width, tga_height);
// the things I do to get rid of an error message, and yet keep
// Microsoft's C compilers happy... [8^(
- tga_palette_start = tga_palette_len = tga_palette_bits = tga_x_origin
- = tga_y_origin = 0;
+ tga_palette_start = tga_palette_len = tga_palette_bits = tga_x_origin = tga_y_origin = 0;
STBI_NOTUSED(tga_palette_start);
// OK, done
return tga_data;
@@ -6575,8 +6288,7 @@ static int stbi__psd_test(stbi__context * s) {
return r;
}
-static int stbi__psd_decode_rle(stbi__context * s, stbi_uc * p,
- int pixelCount) {
+static int stbi__psd_decode_rle(stbi__context * s, stbi_uc * p, int pixelCount) {
int count, nleft, len;
count = 0;
@@ -6613,8 +6325,8 @@ static int stbi__psd_decode_rle(stbi__context * s, stbi_uc * p,
return 1;
}
-static void * stbi__psd_load(stbi__context * s, int * x, int * y, int * comp,
- int req_comp, stbi__result_info * ri, int bpc) {
+static void * stbi__psd_load(stbi__context * s, int * x, int * y, int * comp, int req_comp,
+ stbi__result_info * ri, int bpc) {
int pixelCount;
int channelCount, compression;
int channel, i;
@@ -6629,8 +6341,7 @@ static void * stbi__psd_load(stbi__context * s, int * x, int * y, int * comp,
// Check file type version.
if (stbi__get16be(s) != 1)
- return stbi__errpuc("wrong version",
- "Unsupported version of PSD image");
+ return stbi__errpuc("wrong version", "Unsupported version of PSD image");
// Skip 6 reserved bytes.
stbi__skip(s, 6);
@@ -6653,8 +6364,7 @@ static void * stbi__psd_load(stbi__context * s, int * x, int * y, int * comp,
// Make sure the depth is 8 bits.
bitdepth = stbi__get16be(s);
if (bitdepth != 8 && bitdepth != 16)
- return stbi__errpuc("unsupported bit depth",
- "PSD bit depth is not 8 or 16 bit");
+ return stbi__errpuc("unsupported bit depth", "PSD bit depth is not 8 or 16 bit");
// Make sure the color mode is RGB.
// Valid options are:
@@ -6667,8 +6377,7 @@ static void * stbi__psd_load(stbi__context * s, int * x, int * y, int * comp,
// 8: Duotone
// 9: Lab color
if (stbi__get16be(s) != 3)
- return stbi__errpuc("wrong color format",
- "PSD is not in RGB color format");
+ return stbi__errpuc("wrong color format", "PSD is not in RGB color format");
// Skip the Mode Data. (It's the palette for indexed color; other info for other modes.)
stbi__skip(s, stbi__get32be(s));
@@ -6685,12 +6394,10 @@ static void * stbi__psd_load(stbi__context * s, int * x, int * y, int * comp,
// 1: RLE compressed
compression = stbi__get16be(s);
if (compression > 1)
- return stbi__errpuc("bad compression",
- "PSD has an unknown compression format");
+ return stbi__errpuc("bad compression", "PSD has an unknown compression format");
// Check size
- if (!stbi__mad3sizes_valid(4, w, h, 0))
- return stbi__errpuc("too large", "Corrupt PSD");
+ if (!stbi__mad3sizes_valid(4, w, h, 0)) return stbi__errpuc("too large", "Corrupt PSD");
// Create the destination image.
@@ -6726,8 +6433,7 @@ static void * stbi__psd_load(stbi__context * s, int * x, int * y, int * comp,
p = out + channel;
if (channel >= channelCount) {
// Fill this channel with default data.
- for (i = 0; i < pixelCount; i++, p += 4)
- *p = (channel == 3 ? 255 : 0);
+ for (i = 0; i < pixelCount; i++, p += 4) *p = (channel == 3 ? 255 : 0);
} else {
// Read the RLE data.
if (!stbi__psd_decode_rle(s, p, pixelCount)) {
@@ -6765,8 +6471,7 @@ static void * stbi__psd_load(stbi__context * s, int * x, int * y, int * comp,
for (i = 0; i < pixelCount; i++, p += 4)
*p = (stbi_uc) (stbi__get16be(s) >> 8);
} else {
- for (i = 0; i < pixelCount; i++, p += 4)
- *p = stbi__get8(s);
+ for (i = 0; i < pixelCount; i++, p += 4) *p = stbi__get8(s);
}
}
}
@@ -6805,11 +6510,9 @@ static void * stbi__psd_load(stbi__context * s, int * x, int * y, int * comp,
// convert to desired output format
if (req_comp && req_comp != 4) {
if (ri->bits_per_channel == 16)
- out = (stbi_uc *) stbi__convert_format16((stbi__uint16 *) out, 4,
- req_comp, w, h);
+ out = (stbi_uc *) stbi__convert_format16((stbi__uint16 *) out, 4, req_comp, w, h);
else out = stbi__convert_format(out, 4, req_comp, w, h);
- if (out == NULL)
- return out; // stbi__convert_format frees input on failure
+ if (out == NULL) return out; // stbi__convert_format frees input on failure
}
if (comp) *comp = 4;
@@ -6857,8 +6560,7 @@ static stbi_uc * stbi__readval(stbi__context * s, int channel, stbi_uc * dest) {
for (i = 0; i < 4; ++i, mask >>= 1) {
if (channel & mask) {
- if (stbi__at_eof(s))
- return stbi__errpuc("bad file", "PIC file too short");
+ if (stbi__at_eof(s)) return stbi__errpuc("bad file", "PIC file too short");
dest[i] = stbi__get8(s);
}
}
@@ -6873,8 +6575,8 @@ static void stbi__copyval(int channel, stbi_uc * dest, const stbi_uc * src) {
if (channel & mask) dest[i] = src[i];
}
-static stbi_uc * stbi__pic_load_core(stbi__context * s, int width, int height,
- int * comp, stbi_uc * result) {
+static stbi_uc * stbi__pic_load_core(stbi__context * s, int width, int height, int * comp,
+ stbi_uc * result) {
int act_comp = 0, num_packets = 0, y, chained;
stbi__pic_packet packets[10];
@@ -6897,8 +6599,7 @@ static stbi_uc * stbi__pic_load_core(stbi__context * s, int width, int height,
if (stbi__at_eof(s))
return stbi__errpuc("bad file", "file too short (reading packets)");
- if (packet->size != 8)
- return stbi__errpuc("bad format", "packet isn't 8bpp");
+ if (packet->size != 8) return stbi__errpuc("bad format", "packet isn't 8bpp");
} while (chained);
*comp = (act_comp & 0x10 ? 4 : 3); // has alpha channel?
@@ -6912,8 +6613,7 @@ static stbi_uc * stbi__pic_load_core(stbi__context * s, int width, int height,
switch (packet->type) {
default:
- return stbi__errpuc("bad format",
- "packet has bad compression type");
+ return stbi__errpuc("bad format", "packet has bad compression type");
case 0: { //uncompressed
int x;
@@ -6932,8 +6632,8 @@ static stbi_uc * stbi__pic_load_core(stbi__context * s, int width, int height,
count = stbi__get8(s);
if (stbi__at_eof(s))
- return stbi__errpuc(
- "bad file", "file too short (pure read count)");
+ return stbi__errpuc("bad file",
+ "file too short (pure read count)");
if (count > left) count = (stbi_uc) left;
@@ -6950,9 +6650,8 @@ static stbi_uc * stbi__pic_load_core(stbi__context * s, int width, int height,
while (left > 0) {
int count = stbi__get8(s), i;
if (stbi__at_eof(s))
- return stbi__errpuc(
- "bad file",
- "file too short (mixed read count)");
+ return stbi__errpuc("bad file",
+ "file too short (mixed read count)");
if (count >= 128) { // Repeated
stbi_uc value[4];
@@ -6960,23 +6659,19 @@ static stbi_uc * stbi__pic_load_core(stbi__context * s, int width, int height,
if (count == 128) count = stbi__get16be(s);
else count -= 127;
if (count > left)
- return stbi__errpuc("bad file",
- "scanline overrun");
+ return stbi__errpuc("bad file", "scanline overrun");
- if (!stbi__readval(s, packet->channel, value))
- return 0;
+ if (!stbi__readval(s, packet->channel, value)) return 0;
for (i = 0; i < count; ++i, dest += 4)
stbi__copyval(packet->channel, dest, value);
} else { // Raw
++count;
if (count > left)
- return stbi__errpuc("bad file",
- "scanline overrun");
+ return stbi__errpuc("bad file", "scanline overrun");
for (i = 0; i < count; ++i, dest += 4)
- if (!stbi__readval(s, packet->channel, dest))
- return 0;
+ if (!stbi__readval(s, packet->channel, dest)) return 0;
}
left -= count;
}
@@ -6989,8 +6684,8 @@ static stbi_uc * stbi__pic_load_core(stbi__context * s, int width, int height,
return result;
}
-static void * stbi__pic_load(stbi__context * s, int * px, int * py, int * comp,
- int req_comp, stbi__result_info * ri) {
+static void * stbi__pic_load(stbi__context * s, int * px, int * py, int * comp, int req_comp,
+ stbi__result_info * ri) {
stbi_uc * result;
int i, x, y, internal_comp;
STBI_NOTUSED(ri);
@@ -7007,8 +6702,7 @@ static void * stbi__pic_load(stbi__context * s, int * px, int * py, int * comp,
if (x > STBI_MAX_DIMENSIONS)
return stbi__errpuc("too large", "Very large image (corrupt?)");
- if (stbi__at_eof(s))
- return stbi__errpuc("bad file", "file too short (pic header)");
+ if (stbi__at_eof(s)) return stbi__errpuc("bad file", "file too short (pic header)");
if (!stbi__mad3sizes_valid(x, y, 4, 0))
return stbi__errpuc("too large", "PIC image too large to decode");
@@ -7053,8 +6747,7 @@ typedef struct {
typedef struct {
int w, h;
stbi_uc * out; // output buffer (always 4 components)
- stbi_uc *
- background; // The current "background" as far as a gif is concerned
+ stbi_uc * background; // The current "background" as far as a gif is concerned
stbi_uc * history;
int flags, bgindex, ratio, transparent, eflags;
stbi_uc pal[256][4];
@@ -7087,8 +6780,8 @@ static int stbi__gif_test(stbi__context * s) {
return r;
}
-static void stbi__gif_parse_colortable(stbi__context * s, stbi_uc pal[256][4],
- int num_entries, int transp) {
+static void stbi__gif_parse_colortable(stbi__context * s, stbi_uc pal[256][4], int num_entries,
+ int transp) {
int i;
for (i = 0; i < num_entries; ++i) {
pal[i][2] = stbi__get8(s);
@@ -7098,16 +6791,14 @@ static void stbi__gif_parse_colortable(stbi__context * s, stbi_uc pal[256][4],
}
}
-static int stbi__gif_header(stbi__context * s, stbi__gif * g, int * comp,
- int is_info) {
+static int stbi__gif_header(stbi__context * s, stbi__gif * g, int * comp, int is_info) {
stbi_uc version;
if (stbi__get8(s) != 'G' || stbi__get8(s) != 'I' || stbi__get8(s) != 'F'
|| stbi__get8(s) != '8')
return stbi__err("not GIF", "Corrupt GIF");
version = stbi__get8(s);
- if (version != '7' && version != '9')
- return stbi__err("not GIF", "Corrupt GIF");
+ if (version != '7' && version != '9') return stbi__err("not GIF", "Corrupt GIF");
if (stbi__get8(s) != 'a') return stbi__err("not GIF", "Corrupt GIF");
stbi__g_failure_reason = "";
@@ -7124,13 +6815,11 @@ static int stbi__gif_header(stbi__context * s, stbi__gif * g, int * comp,
return stbi__err("too large", "Very large image (corrupt?)");
if (comp != 0)
- *comp
- = 4; // can't actually tell whether it's 3 or 4 until we parse the comments
+ *comp = 4; // can't actually tell whether it's 3 or 4 until we parse the comments
if (is_info) return 1;
- if (g->flags & 0x80)
- stbi__gif_parse_colortable(s, g->pal, 2 << (g->flags & 7), -1);
+ if (g->flags & 0x80) stbi__gif_parse_colortable(s, g->pal, 2 << (g->flags & 7), -1);
return 1;
}
@@ -7155,8 +6844,7 @@ static void stbi__out_gif_code(stbi__gif * g, stbi__uint16 code) {
// recurse to decode the prefixes, since the linked-list is backwards,
// and working backwards through an interleaved image would be nasty
- if (g->codes[code].prefix >= 0)
- stbi__out_gif_code(g, g->codes[code].prefix);
+ if (g->codes[code].prefix >= 0) stbi__out_gif_code(g, g->codes[code].prefix);
if (g->cur_y >= g->max_y) return;
@@ -7248,11 +6936,9 @@ static stbi_uc * stbi__process_gif_raster(stbi__context * s, stbi__gif * g) {
p->prefix = (stbi__int16) oldcode;
p->first = g->codes[oldcode].first;
- p->suffix
- = (code == avail) ? p->first : g->codes[code].first;
+ p->suffix = (code == avail) ? p->first : g->codes[code].first;
} else if (code == avail)
- return stbi__errpuc("illegal code in raster",
- "Corrupt GIF");
+ return stbi__errpuc("illegal code in raster", "Corrupt GIF");
stbi__out_gif_code(g, (stbi__uint16) code);
@@ -7271,9 +6957,8 @@ static stbi_uc * stbi__process_gif_raster(stbi__context * s, stbi__gif * g) {
// this function is designed to support animated gifs, although stb_image doesn't support it
// two back is the image from two frames ago, used for a very specific disposal format
-static stbi_uc * stbi__gif_load_next(stbi__context * s, stbi__gif * g,
- int * comp, int req_comp,
- stbi_uc * two_back) {
+static stbi_uc * stbi__gif_load_next(stbi__context * s, stbi__gif * g, int * comp,
+ int req_comp, stbi_uc * two_back) {
int dispose;
int first_frame;
int pi;
@@ -7382,13 +7067,11 @@ static stbi_uc * stbi__gif_load_next(stbi__context * s, stbi__gif * g,
if (g->lflags & 0x80) {
stbi__gif_parse_colortable(s, g->lpal, 2 << (g->lflags & 7),
- g->eflags & 0x01 ? g->transparent
- : -1);
+ g->eflags & 0x01 ? g->transparent : -1);
g->color_table = (stbi_uc *) g->lpal;
} else if (g->flags & 0x80) {
g->color_table = (stbi_uc *) g->pal;
- } else
- return stbi__errpuc("missing color table", "Corrupt GIF");
+ } else return stbi__errpuc("missing color table", "Corrupt GIF");
o = stbi__process_gif_raster(s, g);
if (!o) return NULL;
@@ -7417,10 +7100,9 @@ static stbi_uc * stbi__gif_load_next(stbi__context * s, stbi__gif * g,
len = stbi__get8(s);
if (len == 4) {
g->eflags = stbi__get8(s);
- g->delay
- = 10
- * stbi__get16le(
- s); // delay - 1/100th of a second, saving as 1/1000ths.
+ g->delay = 10
+ * stbi__get16le(
+ s); // delay - 1/100th of a second, saving as 1/1000ths.
// unset old transparent
if (g->transparent >= 0) {
@@ -7448,8 +7130,7 @@ static stbi_uc * stbi__gif_load_next(stbi__context * s, stbi__gif * g,
}
case 0x3B: // gif stream termination code
- return (
- stbi_uc *) s; // using '1' causes warning on some compilers
+ return (stbi_uc *) s; // using '1' causes warning on some compilers
default:
return stbi__errpuc("unknown code", "Corrupt GIF");
@@ -7457,8 +7138,7 @@ static stbi_uc * stbi__gif_load_next(stbi__context * s, stbi__gif * g,
}
}
-static void * stbi__load_gif_main_outofmem(stbi__gif * g, stbi_uc * out,
- int ** delays) {
+static void * stbi__load_gif_main_outofmem(stbi__gif * g, stbi_uc * out, int ** delays) {
STBI_FREE(g->out);
STBI_FREE(g->history);
STBI_FREE(g->background);
@@ -7468,8 +7148,8 @@ static void * stbi__load_gif_main_outofmem(stbi__gif * g, stbi_uc * out,
return stbi__errpuc("outofmem", "Out of memory");
}
-static void * stbi__load_gif_main(stbi__context * s, int ** delays, int * x,
- int * y, int * z, int * comp, int req_comp) {
+static void * stbi__load_gif_main(stbi__context * s, int ** delays, int * x, int * y, int * z,
+ int * comp, int req_comp) {
if (stbi__gif_test(s)) {
int layers = 0;
stbi_uc * u = 0;
@@ -7499,34 +7179,28 @@ static void * stbi__load_gif_main(stbi__context * s, int ** delays, int * x,
stride = g.w * g.h * 4;
if (out) {
- void * tmp = (stbi_uc *) STBI_REALLOC_SIZED(
- out, out_size, layers * stride);
- if (!tmp)
- return stbi__load_gif_main_outofmem(&g, out, delays);
+ void * tmp
+ = (stbi_uc *) STBI_REALLOC_SIZED(out, out_size, layers * stride);
+ if (!tmp) return stbi__load_gif_main_outofmem(&g, out, delays);
else {
out = (stbi_uc *) tmp;
out_size = layers * stride;
}
if (delays) {
- int * new_delays = (int *) STBI_REALLOC_SIZED(
- *delays, delays_size, sizeof(int) * layers);
- if (!new_delays)
- return stbi__load_gif_main_outofmem(&g, out,
- delays);
+ int * new_delays = (int *) STBI_REALLOC_SIZED(*delays, delays_size,
+ sizeof(int) * layers);
+ if (!new_delays) return stbi__load_gif_main_outofmem(&g, out, delays);
*delays = new_delays;
delays_size = layers * sizeof(int);
}
} else {
out = (stbi_uc *) stbi__malloc(layers * stride);
- if (!out)
- return stbi__load_gif_main_outofmem(&g, out, delays);
+ if (!out) return stbi__load_gif_main_outofmem(&g, out, delays);
out_size = layers * stride;
if (delays) {
*delays = (int *) stbi__malloc(layers * sizeof(int));
- if (!*delays)
- return stbi__load_gif_main_outofmem(&g, out,
- delays);
+ if (!*delays) return stbi__load_gif_main_outofmem(&g, out, delays);
delays_size = layers * sizeof(int);
}
}
@@ -7557,8 +7231,8 @@ static void * stbi__load_gif_main(stbi__context * s, int ** delays, int * x,
}
}
-static void * stbi__gif_load(stbi__context * s, int * x, int * y, int * comp,
- int req_comp, stbi__result_info * ri) {
+static void * stbi__gif_load(stbi__context * s, int * x, int * y, int * comp, int req_comp,
+ stbi__result_info * ri) {
stbi_uc * u = 0;
stbi__gif g;
memset(&g, 0, sizeof(g));
@@ -7572,8 +7246,7 @@ static void * stbi__gif_load(stbi__context * s, int * x, int * y, int * comp,
// moved conversion to after successful load so that the same
// can be done for multiple frames.
- if (req_comp && req_comp != 4)
- u = stbi__convert_format(u, 4, req_comp, g.w, g.h);
+ if (req_comp && req_comp != 4) u = stbi__convert_format(u, 4, req_comp, g.w, g.h);
} else if (g.out) {
// if there was an error and we allocated an image buffer, free it!
STBI_FREE(g.out);
@@ -7639,8 +7312,7 @@ static void stbi__hdr_convert(float * output, stbi_uc * input, int req_comp) {
float f1;
// Exponent
f1 = (float) ldexp(1.0f, input[3] - (int) (128 + 8));
- if (req_comp <= 2)
- output[0] = (input[0] + input[1] + input[2]) * f1 / 3;
+ if (req_comp <= 2) output[0] = (input[0] + input[1] + input[2]) * f1 / 3;
else {
output[0] = input[0] * f1;
output[1] = input[1] * f1;
@@ -7664,8 +7336,8 @@ static void stbi__hdr_convert(float * output, stbi_uc * input, int req_comp) {
}
}
-static float * stbi__hdr_load(stbi__context * s, int * x, int * y, int * comp,
- int req_comp, stbi__result_info * ri) {
+static float * stbi__hdr_load(stbi__context * s, int * x, int * y, int * comp, int req_comp,
+ stbi__result_info * ri) {
char buffer[STBI__HDR_BUFLEN];
char * token;
int valid = 0;
@@ -7680,8 +7352,7 @@ static float * stbi__hdr_load(stbi__context * s, int * x, int * y, int * comp,
// Check identifier
headerToken = stbi__hdr_gettoken(s, buffer);
- if (strcmp(headerToken, "#?RADIANCE") != 0
- && strcmp(headerToken, "#?RGBE") != 0)
+ if (strcmp(headerToken, "#?RADIANCE") != 0 && strcmp(headerToken, "#?RGBE") != 0)
return stbi__errpf("not HDR", "Corrupt HDR image");
// Parse header
@@ -7691,8 +7362,7 @@ static float * stbi__hdr_load(stbi__context * s, int * x, int * y, int * comp,
if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0) valid = 1;
}
- if (!valid)
- return stbi__errpf("unsupported format", "Unsupported HDR format");
+ if (!valid) return stbi__errpf("unsupported format", "Unsupported HDR format");
// Parse width and height
// can't use sscanf() if we're not using stdio!
@@ -7722,8 +7392,7 @@ static float * stbi__hdr_load(stbi__context * s, int * x, int * y, int * comp,
return stbi__errpf("too large", "HDR image is too large");
// Read data
- hdr_data = (float *) stbi__malloc_mad4(width, height, req_comp,
- sizeof(float), 0);
+ hdr_data = (float *) stbi__malloc_mad4(width, height, req_comp, sizeof(float), 0);
if (!hdr_data) return stbi__errpf("outofmem", "Out of memory");
// Load image data
@@ -7735,9 +7404,8 @@ static float * stbi__hdr_load(stbi__context * s, int * x, int * y, int * comp,
stbi_uc rgbe[4];
main_decode_loop:
stbi__getn(s, rgbe, 4);
- stbi__hdr_convert(hdr_data + j * width * req_comp
- + i * req_comp,
- rgbe, req_comp);
+ stbi__hdr_convert(hdr_data + j * width * req_comp + i * req_comp, rgbe,
+ req_comp);
}
}
} else {
@@ -7767,8 +7435,7 @@ static float * stbi__hdr_load(stbi__context * s, int * x, int * y, int * comp,
if (len != width) {
STBI_FREE(hdr_data);
STBI_FREE(scanline);
- return stbi__errpf("invalid decoded scanline length",
- "corrupt HDR");
+ return stbi__errpf("invalid decoded scanline length", "corrupt HDR");
}
if (scanline == NULL) {
scanline = (stbi_uc *) stbi__malloc_mad2(width, 4, 0);
@@ -7790,27 +7457,23 @@ static float * stbi__hdr_load(stbi__context * s, int * x, int * y, int * comp,
if ((count == 0) || (count > nleft)) {
STBI_FREE(hdr_data);
STBI_FREE(scanline);
- return stbi__errpf("corrupt",
- "bad RLE data in HDR");
+ return stbi__errpf("corrupt", "bad RLE data in HDR");
}
- for (z = 0; z < count; ++z)
- scanline[i++ * 4 + k] = value;
+ for (z = 0; z < count; ++z) scanline[i++ * 4 + k] = value;
} else {
// Dump
if ((count == 0) || (count > nleft)) {
STBI_FREE(hdr_data);
STBI_FREE(scanline);
- return stbi__errpf("corrupt",
- "bad RLE data in HDR");
+ return stbi__errpf("corrupt", "bad RLE data in HDR");
}
- for (z = 0; z < count; ++z)
- scanline[i++ * 4 + k] = stbi__get8(s);
+ for (z = 0; z < count; ++z) scanline[i++ * 4 + k] = stbi__get8(s);
}
}
}
for (i = 0; i < width; ++i)
- stbi__hdr_convert(hdr_data + (j * width + i) * req_comp,
- scanline + i * 4, req_comp);
+ stbi__hdr_convert(hdr_data + (j * width + i) * req_comp, scanline + i * 4,
+ req_comp);
}
if (scanline) STBI_FREE(scanline);
}
@@ -8026,13 +7689,13 @@ static int stbi__pnm_test(stbi__context * s) {
return 1;
}
-static void * stbi__pnm_load(stbi__context * s, int * x, int * y, int * comp,
- int req_comp, stbi__result_info * ri) {
+static void * stbi__pnm_load(stbi__context * s, int * x, int * y, int * comp, int req_comp,
+ stbi__result_info * ri) {
stbi_uc * out;
STBI_NOTUSED(ri);
- ri->bits_per_channel = stbi__pnm_info(s, (int *) &s->img_x,
- (int *) &s->img_y, (int *) &s->img_n);
+ ri->bits_per_channel
+ = stbi__pnm_info(s, (int *) &s->img_x, (int *) &s->img_y, (int *) &s->img_n);
if (ri->bits_per_channel == 0) return 0;
if (s->img_y > STBI_MAX_DIMENSIONS)
@@ -8044,48 +7707,40 @@ static void * stbi__pnm_load(stbi__context * s, int * x, int * y, int * comp,
*y = s->img_y;
if (comp) *comp = s->img_n;
- if (!stbi__mad4sizes_valid(s->img_n, s->img_x, s->img_y,
- ri->bits_per_channel / 8, 0))
+ if (!stbi__mad4sizes_valid(s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, 0))
return stbi__errpuc("too large", "PNM too large");
- out = (stbi_uc *) stbi__malloc_mad4(s->img_n, s->img_x, s->img_y,
- ri->bits_per_channel / 8, 0);
+ out = (stbi_uc *) stbi__malloc_mad4(s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8,
+ 0);
if (!out) return stbi__errpuc("outofmem", "Out of memory");
- if (!stbi__getn(s, out,
- s->img_n * s->img_x * s->img_y
- * (ri->bits_per_channel / 8))) {
+ if (!stbi__getn(s, out, s->img_n * s->img_x * s->img_y * (ri->bits_per_channel / 8))) {
STBI_FREE(out);
return stbi__errpuc("bad PNM", "PNM file truncated");
}
if (req_comp && req_comp != s->img_n) {
if (ri->bits_per_channel == 16) {
- out = (stbi_uc *) stbi__convert_format16(
- (stbi__uint16 *) out, s->img_n, req_comp, s->img_x, s->img_y);
+ out = (stbi_uc *) stbi__convert_format16((stbi__uint16 *) out, s->img_n, req_comp,
+ s->img_x, s->img_y);
} else {
- out = stbi__convert_format(out, s->img_n, req_comp, s->img_x,
- s->img_y);
+ out = stbi__convert_format(out, s->img_n, req_comp, s->img_x, s->img_y);
}
- if (out == NULL)
- return out; // stbi__convert_format frees input on failure
+ if (out == NULL) return out; // stbi__convert_format frees input on failure
}
return out;
}
static int stbi__pnm_isspace(char c) {
- return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f'
- || c == '\r';
+ return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r';
}
static void stbi__pnm_skip_whitespace(stbi__context * s, char * c) {
for (;;) {
- while (!stbi__at_eof(s) && stbi__pnm_isspace(*c))
- *c = (char) stbi__get8(s);
+ while (!stbi__at_eof(s) && stbi__pnm_isspace(*c)) *c = (char) stbi__get8(s);
if (stbi__at_eof(s) || *c != '#') break;
- while (!stbi__at_eof(s) && *c != '\n' && *c != '\r')
- *c = (char) stbi__get8(s);
+ while (!stbi__at_eof(s) && *c != '\n' && *c != '\r') *c = (char) stbi__get8(s);
}
}
@@ -8098,9 +7753,8 @@ static int stbi__pnm_getinteger(stbi__context * s, char * c) {
value = value * 10 + (*c - '0');
*c = (char) stbi__get8(s);
if ((value > 214748364) || (value == 214748364 && *c > '7'))
- return stbi__err(
- "integer parse overflow",
- "Parsing an integer in the PPM header overflowed a 32-bit int");
+ return stbi__err("integer parse overflow",
+ "Parsing an integer in the PPM header overflowed a 32-bit int");
}
return value;
@@ -8124,22 +7778,19 @@ static int stbi__pnm_info(stbi__context * s, int * x, int * y, int * comp) {
return 0;
}
- *comp = (t == '6') ? 3
- : 1; // '5' is 1-component .pgm; '6' is 3-component .ppm
+ *comp = (t == '6') ? 3 : 1; // '5' is 1-component .pgm; '6' is 3-component .ppm
c = (char) stbi__get8(s);
stbi__pnm_skip_whitespace(s, &c);
*x = stbi__pnm_getinteger(s, &c); // read width
if (*x == 0)
- return stbi__err("invalid width",
- "PPM image header had zero or overflowing width");
+ return stbi__err("invalid width", "PPM image header had zero or overflowing width");
stbi__pnm_skip_whitespace(s, &c);
*y = stbi__pnm_getinteger(s, &c); // read height
if (*y == 0)
- return stbi__err("invalid width",
- "PPM image header had zero or overflowing width");
+ return stbi__err("invalid width", "PPM image header had zero or overflowing width");
stbi__pnm_skip_whitespace(s, &c);
maxv = stbi__pnm_getinteger(s, &c); // read max value
@@ -8193,8 +7844,7 @@ static int stbi__info_main(stbi__context * s, int * x, int * y, int * comp) {
#ifndef STBI_NO_TGA
if (stbi__tga_info(s, x, y, comp)) return 1;
#endif
- return stbi__err("unknown image type",
- "Image not of any known type, or corrupt");
+ return stbi__err("unknown image type", "Image not of any known type, or corrupt");
}
static int stbi__is_16_main(stbi__context * s) {
@@ -8252,15 +7902,15 @@ STBIDEF int stbi_is_16_bit_from_file(FILE * f) {
}
#endif // !STBI_NO_STDIO
-STBIDEF int stbi_info_from_memory(stbi_uc const * buffer, int len, int * x,
- int * y, int * comp) {
+STBIDEF int stbi_info_from_memory(stbi_uc const * buffer, int len, int * x, int * y,
+ int * comp) {
stbi__context s;
stbi__start_mem(&s, buffer, len);
return stbi__info_main(&s, x, y, comp);
}
-STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const * c, void * user,
- int * x, int * y, int * comp) {
+STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const * c, void * user, int * x,
+ int * y, int * comp) {
stbi__context s;
stbi__start_callbacks(&s, (stbi_io_callbacks *) c, user);
return stbi__info_main(&s, x, y, comp);
@@ -8272,8 +7922,7 @@ STBIDEF int stbi_is_16_bit_from_memory(stbi_uc const * buffer, int len) {
return stbi__is_16_main(&s);
}
-STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const * c,
- void * user) {
+STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const * c, void * user) {
stbi__context s;
stbi__start_callbacks(&s, (stbi_io_callbacks *) c, user);
return stbi__is_16_main(&s);
diff --git a/mwe/resource-manager/tiledMap.cpp b/mwe/resource-manager/tiledMap.cpp
index 836929c..85fc30e 100644
--- a/mwe/resource-manager/tiledMap.cpp
+++ b/mwe/resource-manager/tiledMap.cpp
@@ -49,8 +49,7 @@ void TiledMap::SetMapTextures() {
for (const auto & ts : tileSets) {
m_MapTextures.emplace_back(new TextureMap);
- if (!m_MapTextures.back()->loadFromFile(ts.getImagePath(),
- m_Renderer)) {
+ if (!m_MapTextures.back()->loadFromFile(ts.getImagePath(), m_Renderer)) {
std::cerr << "Failed opening " << ts.getImagePath() << "\n";
}
}
@@ -63,8 +62,7 @@ void TiledMap::SetMapLayers() {
for (auto i = 0u; i < mapLayers.size(); ++i) {
if (mapLayers[i]->getType() == tmx::Layer::Type::Tile) {
m_RenderLayers.emplace_back(new MapLayer);
- m_RenderLayers.back()->create(this->m_TmxMap, i,
- this->m_MapTextures);
+ m_RenderLayers.back()->create(this->m_TmxMap, i, this->m_MapTextures);
}
}
}