mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2024-11-10 07:21:58 +00:00
Some more image.c / lodepng / stb_image_write clean-ups:
image.c: define LODEPNG_NO_COMPILE_CPP for lodepng.c. image.c: define STB_IMAGE_WRITE_STATIC for stb_image_write.h image.c: minor whitespace tidy-up. stb_image_write.h: remove extern declaration for now non-existing stbi_write_tga_with_rle (missed in commit r1468). stb_image_write.h: comment out stbi_write_jpg_to_func() which quakespasm doesn't use. lodepng.c (lodepng_save_file): remove unneeded (char*) cast from buffer. lodepng.c (lodepng_read32bitInt): make it static. lodepng.c (lodepng_get_raw_size_lct): make it static, and move below to the place it is actually used. lodepng.c (lodepng_info_swap): remove (unused function). lodepng.c (readChunk_zTXt,readChunk_iTXt,addChunk_zTXt, addChunk_iTXt): add missing const to casts on const pointers in zlib_compress() calls. (see: https://github.com/lvandeve/lodepng/pull/34). lodepng.c (inflateHuffmanBlock): wrong error code if huffmanDecodeSymbol fail. (see: https://github.com/lvandeve/lodepng/pull/52). git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@1471 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
parent
aaa629d2fc
commit
b08e7b1168
3 changed files with 28 additions and 32 deletions
|
@ -24,9 +24,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "quakedef.h"
|
#include "quakedef.h"
|
||||||
|
|
||||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
#define STB_IMAGE_WRITE_STATIC
|
||||||
#include "stb_image_write.h"
|
#include "stb_image_write.h"
|
||||||
|
|
||||||
#define LODEPNG_NO_COMPILE_DECODER
|
#define LODEPNG_NO_COMPILE_DECODER
|
||||||
|
#define LODEPNG_NO_COMPILE_CPP
|
||||||
#define LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS
|
#define LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS
|
||||||
#define LODEPNG_NO_COMPILE_ERROR_TEXT
|
#define LODEPNG_NO_COMPILE_ERROR_TEXT
|
||||||
#include "lodepng.h"
|
#include "lodepng.h"
|
||||||
|
@ -556,7 +558,6 @@ qboolean Image_WritePNG (const char *name, byte *data, int width, int height, in
|
||||||
|
|
||||||
flipped = (!upsidedown)? CopyFlipped (data, width, height, bpp) : data;
|
flipped = (!upsidedown)? CopyFlipped (data, width, height, bpp) : data;
|
||||||
filters = (unsigned char *) malloc (height);
|
filters = (unsigned char *) malloc (height);
|
||||||
|
|
||||||
if (!filters || !flipped)
|
if (!filters || !flipped)
|
||||||
{
|
{
|
||||||
if (!upsidedown)
|
if (!upsidedown)
|
||||||
|
@ -591,7 +592,6 @@ qboolean Image_WritePNG (const char *name, byte *data, int width, int height, in
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
lodepng_state_cleanup (&state);
|
lodepng_state_cleanup (&state);
|
||||||
|
|
||||||
free (png);
|
free (png);
|
||||||
free (filters);
|
free (filters);
|
||||||
if (!upsidedown)
|
if (!upsidedown)
|
||||||
|
|
|
@ -317,7 +317,7 @@ static void string_set(char** out, const char* in)
|
||||||
|
|
||||||
/* ////////////////////////////////////////////////////////////////////////// */
|
/* ////////////////////////////////////////////////////////////////////////// */
|
||||||
|
|
||||||
unsigned lodepng_read32bitInt(const unsigned char* buffer)
|
static unsigned lodepng_read32bitInt(const unsigned char* buffer)
|
||||||
{
|
{
|
||||||
return (unsigned)((buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3]);
|
return (unsigned)((buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3]);
|
||||||
}
|
}
|
||||||
|
@ -402,7 +402,7 @@ unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const
|
||||||
FILE* file;
|
FILE* file;
|
||||||
file = fopen(filename, "wb" );
|
file = fopen(filename, "wb" );
|
||||||
if(!file) return 79;
|
if(!file) return 79;
|
||||||
fwrite((char*)buffer , 1 , buffersize, file);
|
fwrite(buffer , 1 , buffersize, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1171,7 +1171,7 @@ static unsigned inflateHuffmanBlock(ucvector* out, const unsigned char* in, size
|
||||||
code_d = huffmanDecodeSymbol(in, bp, &tree_d, inbitlength);
|
code_d = huffmanDecodeSymbol(in, bp, &tree_d, inbitlength);
|
||||||
if(code_d > 29)
|
if(code_d > 29)
|
||||||
{
|
{
|
||||||
if(code_ll == (unsigned)(-1)) /*huffmanDecodeSymbol returns (unsigned)(-1) in case of error*/
|
if(code_d == (unsigned)(-1)) /*huffmanDecodeSymbol returns (unsigned)(-1) in case of error*/
|
||||||
{
|
{
|
||||||
/*return error code 10 or 11 depending on the situation that happened in huffmanDecodeSymbol
|
/*return error code 10 or 11 depending on the situation that happened in huffmanDecodeSymbol
|
||||||
(10=no endcode, 11=wrong jump outside of tree)*/
|
(10=no endcode, 11=wrong jump outside of tree)*/
|
||||||
|
@ -2713,14 +2713,6 @@ size_t lodepng_get_raw_size(unsigned w, unsigned h, const LodePNGColorMode* colo
|
||||||
return ((n / 8) * bpp) + ((n & 7) * bpp + 7) / 8;
|
return ((n / 8) * bpp) + ((n & 7) * bpp + 7) / 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t lodepng_get_raw_size_lct(unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth)
|
|
||||||
{
|
|
||||||
/*will not overflow for any color type if roughly w * h < 268435455*/
|
|
||||||
size_t bpp = lodepng_get_bpp_lct(colortype, bitdepth);
|
|
||||||
size_t n = w * h;
|
|
||||||
return ((n / 8) * bpp) + ((n & 7) * bpp + 7) / 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef LODEPNG_COMPILE_PNG
|
#ifdef LODEPNG_COMPILE_PNG
|
||||||
#ifdef LODEPNG_COMPILE_DECODER
|
#ifdef LODEPNG_COMPILE_DECODER
|
||||||
|
@ -2968,13 +2960,6 @@ unsigned lodepng_info_copy(LodePNGInfo* dest, const LodePNGInfo* source)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lodepng_info_swap(LodePNGInfo* a, LodePNGInfo* b)
|
|
||||||
{
|
|
||||||
LodePNGInfo temp = *a;
|
|
||||||
*a = *b;
|
|
||||||
*b = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ////////////////////////////////////////////////////////////////////////// */
|
/* ////////////////////////////////////////////////////////////////////////// */
|
||||||
|
|
||||||
/*index: bitgroup index, bits: bitgroup size(1, 2 or 4), in: bitgroup value, out: octet array to add bits to*/
|
/*index: bitgroup index, bits: bitgroup size(1, 2 or 4), in: bitgroup value, out: octet array to add bits to*/
|
||||||
|
@ -4380,7 +4365,7 @@ static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSetting
|
||||||
length = chunkLength - string2_begin;
|
length = chunkLength - string2_begin;
|
||||||
/*will fail if zlib error, e.g. if length is too small*/
|
/*will fail if zlib error, e.g. if length is too small*/
|
||||||
error = zlib_decompress(&decoded.data, &decoded.size,
|
error = zlib_decompress(&decoded.data, &decoded.size,
|
||||||
(unsigned char*)(&data[string2_begin]),
|
(const unsigned char*)(&data[string2_begin]),
|
||||||
length, zlibsettings);
|
length, zlibsettings);
|
||||||
if(error) break;
|
if(error) break;
|
||||||
ucvector_push_back(&decoded, 0);
|
ucvector_push_back(&decoded, 0);
|
||||||
|
@ -4463,7 +4448,7 @@ static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSetting
|
||||||
{
|
{
|
||||||
/*will fail if zlib error, e.g. if length is too small*/
|
/*will fail if zlib error, e.g. if length is too small*/
|
||||||
error = zlib_decompress(&decoded.data, &decoded.size,
|
error = zlib_decompress(&decoded.data, &decoded.size,
|
||||||
(unsigned char*)(&data[begin]),
|
(const unsigned char*)(&data[begin]),
|
||||||
length, zlibsettings);
|
length, zlibsettings);
|
||||||
if(error) break;
|
if(error) break;
|
||||||
if(decoded.allocsize < decoded.size) decoded.allocsize = decoded.size;
|
if(decoded.allocsize < decoded.size) decoded.allocsize = decoded.size;
|
||||||
|
@ -5023,7 +5008,7 @@ static unsigned addChunk_zTXt(ucvector* out, const char* keyword, const char* te
|
||||||
ucvector_push_back(&data, 0); /*compression method: 0*/
|
ucvector_push_back(&data, 0); /*compression method: 0*/
|
||||||
|
|
||||||
error = zlib_compress(&compressed.data, &compressed.size,
|
error = zlib_compress(&compressed.data, &compressed.size,
|
||||||
(unsigned char*)textstring, textsize, zlibsettings);
|
(const unsigned char*)textstring, textsize, zlibsettings);
|
||||||
if(!error)
|
if(!error)
|
||||||
{
|
{
|
||||||
for(i = 0; i != compressed.size; ++i) ucvector_push_back(&data, compressed.data[i]);
|
for(i = 0; i != compressed.size; ++i) ucvector_push_back(&data, compressed.data[i]);
|
||||||
|
@ -5059,7 +5044,7 @@ static unsigned addChunk_iTXt(ucvector* out, unsigned compressed, const char* ke
|
||||||
ucvector compressed_data;
|
ucvector compressed_data;
|
||||||
ucvector_init(&compressed_data);
|
ucvector_init(&compressed_data);
|
||||||
error = zlib_compress(&compressed_data.data, &compressed_data.size,
|
error = zlib_compress(&compressed_data.data, &compressed_data.size,
|
||||||
(unsigned char*)textstring, textsize, zlibsettings);
|
(const unsigned char*)textstring, textsize, zlibsettings);
|
||||||
if(!error)
|
if(!error)
|
||||||
{
|
{
|
||||||
for(i = 0; i != compressed_data.size; ++i) ucvector_push_back(&data, compressed_data.data[i]);
|
for(i = 0; i != compressed_data.size; ++i) ucvector_push_back(&data, compressed_data.data[i]);
|
||||||
|
@ -6160,6 +6145,14 @@ unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h, const
|
||||||
#endif /* LODEPNG_COMPILE_DISK */
|
#endif /* LODEPNG_COMPILE_DISK */
|
||||||
|
|
||||||
#ifdef LODEPNG_COMPILE_ENCODER
|
#ifdef LODEPNG_COMPILE_ENCODER
|
||||||
|
static size_t lodepng_get_raw_size_lct(unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth)
|
||||||
|
{
|
||||||
|
/*will not overflow for any color type if roughly w * h < 268435455*/
|
||||||
|
size_t bpp = lodepng_get_bpp_lct(colortype, bitdepth);
|
||||||
|
size_t n = w * h;
|
||||||
|
return ((n / 8) * bpp) + ((n & 7) * bpp + 7) / 8;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned encode(std::vector<unsigned char>& out, const unsigned char* in, unsigned w, unsigned h,
|
unsigned encode(std::vector<unsigned char>& out, const unsigned char* in, unsigned w, unsigned h,
|
||||||
LodePNGColorType colortype, unsigned bitdepth)
|
LodePNGColorType colortype, unsigned bitdepth)
|
||||||
{
|
{
|
||||||
|
|
|
@ -134,7 +134,6 @@ extern "C" {
|
||||||
#define STBIWDEF static
|
#define STBIWDEF static
|
||||||
#else
|
#else
|
||||||
#define STBIWDEF extern
|
#define STBIWDEF extern
|
||||||
extern int stbi_write_tga_with_rle;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef STBI_WRITE_NO_STDIO
|
#ifndef STBI_WRITE_NO_STDIO
|
||||||
|
@ -143,7 +142,9 @@ STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const
|
||||||
|
|
||||||
typedef void stbi_write_func(void *context, void *data, int size);
|
typedef void stbi_write_func(void *context, void *data, int size);
|
||||||
|
|
||||||
|
#if 0 /* not used in QuakeSpasm */
|
||||||
STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality);
|
STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -576,12 +577,14 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0 /* not used in QuakeSpasm */
|
||||||
STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality)
|
STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality)
|
||||||
{
|
{
|
||||||
stbi__write_context s;
|
stbi__write_context s;
|
||||||
stbi__start_write_callbacks(&s, func, context);
|
stbi__start_write_callbacks(&s, func, context);
|
||||||
return stbi_write_jpg_core(&s, x, y, comp, (void *) data, quality);
|
return stbi_write_jpg_core(&s, x, y, comp, (void *) data, quality);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef STBI_WRITE_NO_STDIO
|
#ifndef STBI_WRITE_NO_STDIO
|
||||||
|
|
Loading…
Reference in a new issue