From f86e0719bbfc311a755a471e9c9010386d26ce0b Mon Sep 17 00:00:00 2001 From: Alison Watson Date: Mon, 25 Nov 2019 17:23:46 -0500 Subject: [PATCH] unsigned char -> uint8_t (ISO/IEC 2382-1:1993) --- source/common.c | 2 +- source/gl_draw.c | 2 +- source/gl_mesh.c | 2 +- source/image.c | 18 +- source/in_sdl.c | 4 +- source/lodepng.c | 558 +++++++++++++++++++-------------------- source/lodepng.h | 222 ++++++++-------- source/net_defs.h | 6 +- source/net_sys.h | 4 +- source/progs.h | 2 +- source/protocol.h | 6 +- source/q_sound.h | 2 +- source/q_stdinc.h | 2 +- source/r_brush.c | 2 +- source/snd_mem.c | 4 +- source/snd_mix.c | 6 +- source/snd_mp3.c | 12 +- source/snd_mpg123.c | 2 +- source/snd_opus.c | 4 +- source/snd_sdl.c | 2 +- source/snd_umx.c | 6 +- source/stb_image_write.h | 44 +-- 22 files changed, 456 insertions(+), 456 deletions(-) diff --git a/source/common.c b/source/common.c index 3d40c1a..44337ef 100644 --- a/source/common.c +++ b/source/common.c @@ -791,7 +791,7 @@ int MSG_ReadByte (void) return -1; } - c = (unsigned char)net_message.data[msg_readcount]; + c = (uint8_t)net_message.data[msg_readcount]; msg_readcount++; return c; diff --git a/source/gl_draw.c b/source/gl_draw.c index 0f67904..f4ab97a 100644 --- a/source/gl_draw.c +++ b/source/gl_draw.c @@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" -//extern unsigned char d_15to8table[65536]; //johnfitz -- never used +//extern uint8_t d_15to8table[65536]; //johnfitz -- never used cvar_t scr_conalpha = {"scr_conalpha", "0.5", CVAR_ARCHIVE}; //johnfitz diff --git a/source/gl_mesh.c b/source/gl_mesh.c index e522089..52c5851 100644 --- a/source/gl_mesh.c +++ b/source/gl_mesh.c @@ -516,7 +516,7 @@ static void GLMesh_LoadVertexBuffer (qmodel_t *m, const aliashdr_t *hdr) xyz[v].xyz[2] = trivert.v[2]; xyz[v].xyz[3] = 1; // need w 1 for 4 byte vertex compression - // map the normal coordinates in [-1..1] to [-127..127] and store in an unsigned char. + // map the normal coordinates in [-1..1] to [-127..127] and store in an uint8_t. // this introduces some error (less than 0.004), but the normals were very coarse // to begin with xyz[v].normal[0] = 127 * r_avertexnormals[trivert.lightnormalindex][0]; diff --git a/source/image.c b/source/image.c index c4c77c8..b9ab96b 100644 --- a/source/image.c +++ b/source/image.c @@ -38,7 +38,7 @@ static char loadfilename[MAX_OSPATH]; //file scope so that error messages can us typedef struct stdio_buffer_s { FILE *f; - unsigned char buffer[1024]; + uint8_t buffer[1024]; int size; int pos; } stdio_buffer_t; @@ -102,11 +102,11 @@ byte *Image_LoadImage (const char *name, int *width, int *height) //============================================================================== typedef struct targaheader_s { - unsigned char id_length, colormap_type, image_type; + uint8_t id_length, colormap_type, image_type; uint16_t colormap_index, colormap_length; - unsigned char colormap_size; + uint8_t colormap_size; uint16_t x_origin, y_origin, width, height; - unsigned char pixel_size, attributes; + uint8_t pixel_size, attributes; } targaheader_t; #define TARGAHEADERSIZE 18 //size on disk @@ -240,7 +240,7 @@ byte *Image_LoadTGA (FILE *fin, int *width, int *height) //johnfitz for(column=0; column=0; row--) { //johnfitz -- fix for upside-down targas @@ -545,8 +545,8 @@ qboolean Image_WritePNG (const char *name, byte *data, int width, int height, in unsigned error; char pathname[MAX_OSPATH]; byte *flipped; - unsigned char *filters; - unsigned char *png; + uint8_t *filters; + uint8_t *png; size_t pngsize; LodePNGState state; @@ -557,7 +557,7 @@ qboolean Image_WritePNG (const char *name, byte *data, int width, int height, in q_snprintf (pathname, sizeof(pathname), "%s/%s", com_gamedir, name); flipped = (!upsidedown)? CopyFlipped (data, width, height, bpp) : data; - filters = (unsigned char *) malloc (height); + filters = (uint8_t *) malloc (height); if (!filters || !flipped) { if (!upsidedown) diff --git a/source/in_sdl.c b/source/in_sdl.c index 0bf30f3..792ec8a 100644 --- a/source/in_sdl.c +++ b/source/in_sdl.c @@ -855,8 +855,8 @@ void IN_SendKeyEvents (void) // SDL2 uses the local keyboard layout and handles modifiers // (shift for uppercase, etc.) for us. { - unsigned char *ch; - for (ch = (unsigned char *)event.text.text; *ch; ch++) + uint8_t *ch; + for (ch = (uint8_t *)event.text.text; *ch; ch++) if ((*ch & ~0x7F) == 0) Char_Event (*ch); } diff --git a/source/lodepng.c b/source/lodepng.c index eff7b0c..6bf1af4 100644 --- a/source/lodepng.c +++ b/source/lodepng.c @@ -204,7 +204,7 @@ static unsigned uivector_push_back(uivector* p, unsigned c) /*dynamic vector of unsigned chars*/ typedef struct ucvector { - unsigned char* data; + uint8_t* data; size_t size; /*used size*/ size_t allocsize; /*allocated size*/ } ucvector; @@ -219,7 +219,7 @@ static unsigned ucvector_reserve(ucvector* p, size_t allocsize) if(data) { p->allocsize = newsize; - p->data = (unsigned char*)data; + p->data = (uint8_t*)data; } else return 0; /*error: not enough memory*/ } @@ -229,7 +229,7 @@ static unsigned ucvector_reserve(ucvector* p, size_t allocsize) /*returns 1 if success, 0 if failure ==> nothing done*/ static unsigned ucvector_resize(ucvector* p, size_t size) { - if(!ucvector_reserve(p, size * sizeof(unsigned char))) return 0; + if(!ucvector_reserve(p, size * sizeof(uint8_t))) return 0; p->size = size; return 1; /*success*/ } @@ -253,7 +253,7 @@ static void ucvector_init(ucvector* p) #ifdef LODEPNG_COMPILE_ZLIB /*you can both convert from vector to buffer&size and vica versa. If you use init_buffer to take over a buffer and size, it is not needed to use cleanup*/ -static void ucvector_init_buffer(ucvector* p, unsigned char* buffer, size_t size) +static void ucvector_init_buffer(ucvector* p, uint8_t* buffer, size_t size) { p->data = buffer; p->allocsize = p->size = size; @@ -262,7 +262,7 @@ static void ucvector_init_buffer(ucvector* p, unsigned char* buffer, size_t size #if (defined(LODEPNG_COMPILE_PNG) && defined(LODEPNG_COMPILE_ANCILLARY_CHUNKS)) || defined(LODEPNG_COMPILE_ENCODER) /*returns 1 if success, 0 if failure ==> nothing done*/ -static unsigned ucvector_push_back(ucvector* p, unsigned char c) +static unsigned ucvector_push_back(ucvector* p, uint8_t c) { if(!ucvector_resize(p, p->size + 1)) return 0; p->data[p->size - 1] = c; @@ -317,19 +317,19 @@ static void string_set(char** out, const char* in) /* ////////////////////////////////////////////////////////////////////////// */ -static unsigned lodepng_read32bitInt(const unsigned char* buffer) +static unsigned lodepng_read32bitInt(const uint8_t* buffer) { return (unsigned)((buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3]); } #if defined(LODEPNG_COMPILE_PNG) || defined(LODEPNG_COMPILE_ENCODER) /*buffer must have at least 4 allocated bytes available*/ -static void lodepng_set32bitInt(unsigned char* buffer, unsigned value) +static void lodepng_set32bitInt(uint8_t* buffer, unsigned value) { - buffer[0] = (unsigned char)((value >> 24) & 0xff); - buffer[1] = (unsigned char)((value >> 16) & 0xff); - buffer[2] = (unsigned char)((value >> 8) & 0xff); - buffer[3] = (unsigned char)((value ) & 0xff); + buffer[0] = (uint8_t)((value >> 24) & 0xff); + buffer[1] = (uint8_t)((value >> 16) & 0xff); + buffer[2] = (uint8_t)((value >> 8) & 0xff); + buffer[3] = (uint8_t)((value ) & 0xff); } #endif /*defined(LODEPNG_COMPILE_PNG) || defined(LODEPNG_COMPILE_ENCODER)*/ @@ -370,7 +370,7 @@ static long lodepng_filesize(const char* filename) } /* load file into buffer that already has the correct allocated size. Returns error code.*/ -static unsigned lodepng_buffer_file(unsigned char* out, size_t size, const char* filename) +static unsigned lodepng_buffer_file(uint8_t* out, size_t size, const char* filename) { FILE* file; size_t readsize; @@ -384,20 +384,20 @@ static unsigned lodepng_buffer_file(unsigned char* out, size_t size, const char* return 0; } -unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename) +unsigned lodepng_load_file(uint8_t** out, size_t* outsize, const char* filename) { long size = lodepng_filesize(filename); if (size < 0) return 78; *outsize = (size_t)size; - *out = (unsigned char*)lodepng_malloc((size_t)size); + *out = (uint8_t*)lodepng_malloc((size_t)size); if(!(*out) && size > 0) return 83; /*the above malloc failed*/ return lodepng_buffer_file(*out, (size_t)size, filename); } /*write given buffer to the file, overwriting the file, it doesn't append to it.*/ -unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename) +unsigned lodepng_save_file(const uint8_t* buffer, size_t buffersize, const char* filename) { FILE* file; file = fopen(filename, "wb" ); @@ -418,10 +418,10 @@ unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const #ifdef LODEPNG_COMPILE_ZLIB #ifdef LODEPNG_COMPILE_ENCODER /*TODO: this ignores potential out of memory errors*/ -#define addBitToStream(/*size_t**/ bitpointer, /*ucvector**/ bitstream, /*unsigned char*/ bit)\ +#define addBitToStream(/*size_t**/ bitpointer, /*ucvector**/ bitstream, /*uint8_t*/ bit)\ {\ /*add a new byte at the end*/\ - if(((*bitpointer) & 7) == 0) ucvector_push_back(bitstream, (unsigned char)0);\ + if(((*bitpointer) & 7) == 0) ucvector_push_back(bitstream, (uint8_t)0);\ /*earlier bit of huffman code is in a lesser significant bit of an earlier byte*/\ (bitstream->data[bitstream->size - 1]) |= (bit << ((*bitpointer) & 0x7));\ ++(*bitpointer);\ @@ -430,28 +430,28 @@ unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const static void addBitsToStream(size_t* bitpointer, ucvector* bitstream, unsigned value, size_t nbits) { size_t i; - for(i = 0; i != nbits; ++i) addBitToStream(bitpointer, bitstream, (unsigned char)((value >> i) & 1)); + for(i = 0; i != nbits; ++i) addBitToStream(bitpointer, bitstream, (uint8_t)((value >> i) & 1)); } static void addBitsToStreamReversed(size_t* bitpointer, ucvector* bitstream, unsigned value, size_t nbits) { size_t i; - for(i = 0; i != nbits; ++i) addBitToStream(bitpointer, bitstream, (unsigned char)((value >> (nbits - 1 - i)) & 1)); + for(i = 0; i != nbits; ++i) addBitToStream(bitpointer, bitstream, (uint8_t)((value >> (nbits - 1 - i)) & 1)); } #endif /*LODEPNG_COMPILE_ENCODER*/ #ifdef LODEPNG_COMPILE_DECODER -#define READBIT(bitpointer, bitstream) ((bitstream[bitpointer >> 3] >> (bitpointer & 0x7)) & (unsigned char)1) +#define READBIT(bitpointer, bitstream) ((bitstream[bitpointer >> 3] >> (bitpointer & 0x7)) & (uint8_t)1) -static unsigned char readBitFromStream(size_t* bitpointer, const unsigned char* bitstream) +static uint8_t readBitFromStream(size_t* bitpointer, const uint8_t* bitstream) { - unsigned char result = (unsigned char)(READBIT(*bitpointer, bitstream)); + uint8_t result = (uint8_t)(READBIT(*bitpointer, bitstream)); ++(*bitpointer); return result; } -static unsigned readBitsFromStream(size_t* bitpointer, const unsigned char* bitstream, size_t nbits) +static unsigned readBitsFromStream(size_t* bitpointer, const uint8_t* bitstream, size_t nbits) { unsigned result = 0, i; for(i = 0; i != nbits; ++i) @@ -571,7 +571,7 @@ static unsigned HuffmanTree_make2DTree(HuffmanTree* tree) { for(i = 0; i != tree->lengths[n]; ++i) /*the bits for this code*/ { - unsigned char bit = (unsigned char)((tree->tree1d[n] >> (tree->lengths[n] - i - 1)) & 1); + uint8_t bit = (uint8_t)((tree->tree1d[n] >> (tree->lengths[n] - i - 1)) & 1); /*oversubscribed, see comment in lodepng_error_text*/ if(treepos > 2147483647 || treepos + 2 > tree->numcodes) return 55; if(tree->tree2d[2 * treepos + bit] == 32767) /*not yet filled in*/ @@ -944,7 +944,7 @@ static unsigned generateFixedDistanceTree(HuffmanTree* tree) returns the code, or (unsigned)(-1) if error happened inbitlength is the length of the complete buffer, in bits (so its byte length times 8) */ -static unsigned huffmanDecodeSymbol(const unsigned char* in, size_t* bp, +static unsigned huffmanDecodeSymbol(const uint8_t* in, size_t* bp, const HuffmanTree* codetree, size_t inbitlength) { unsigned treepos = 0, ct; @@ -981,7 +981,7 @@ static void getTreeInflateFixed(HuffmanTree* tree_ll, HuffmanTree* tree_d) /*get the tree of a deflated block with dynamic tree, the tree itself is also Huffman compressed with a known tree*/ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d, - const unsigned char* in, size_t* bp, size_t inlength) + const uint8_t* in, size_t* bp, size_t inlength) { /*make sure that length values that aren't filled in will be 0, or a wrong tree will be generated*/ unsigned error = 0; @@ -1128,7 +1128,7 @@ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d, } /*inflate a block with dynamic of fixed Huffman tree*/ -static unsigned inflateHuffmanBlock(ucvector* out, const unsigned char* in, size_t* bp, +static unsigned inflateHuffmanBlock(ucvector* out, const uint8_t* in, size_t* bp, size_t* pos, size_t inlength, unsigned btype) { unsigned error = 0; @@ -1150,7 +1150,7 @@ static unsigned inflateHuffmanBlock(ucvector* out, const unsigned char* in, size { /*ucvector_push_back would do the same, but for some reason the two lines below run 10% faster*/ if(!ucvector_resize(out, (*pos) + 1)) ERROR_BREAK(83 /*alloc fail*/); - out->data[*pos] = (unsigned char)code_ll; + out->data[*pos] = (uint8_t)code_ll; ++(*pos); } else if(code_ll >= FIRST_LENGTH_CODE_INDEX && code_ll <= LAST_LENGTH_CODE_INDEX) /*length code*/ @@ -1222,7 +1222,7 @@ static unsigned inflateHuffmanBlock(ucvector* out, const unsigned char* in, size return error; } -static unsigned inflateNoCompression(ucvector* out, const unsigned char* in, size_t* bp, size_t* pos, size_t inlength) +static unsigned inflateNoCompression(ucvector* out, const uint8_t* in, size_t* bp, size_t* pos, size_t inlength) { size_t p; unsigned LEN, NLEN, n, error = 0; @@ -1251,7 +1251,7 @@ static unsigned inflateNoCompression(ucvector* out, const unsigned char* in, siz } static unsigned lodepng_inflatev(ucvector* out, - const unsigned char* in, size_t insize, + const uint8_t* in, size_t insize, const LodePNGDecompressSettings* settings) { /*bit pointer in the "in" data, current byte is bp >> 3, current bit is bp & 0x7 (from lsb to msb of the byte)*/ @@ -1280,8 +1280,8 @@ static unsigned lodepng_inflatev(ucvector* out, return error; } -unsigned lodepng_inflate(unsigned char** out, size_t* outsize, - const unsigned char* in, size_t insize, +unsigned lodepng_inflate(uint8_t** out, size_t* outsize, + const uint8_t* in, size_t insize, const LodePNGDecompressSettings* settings) { unsigned error; @@ -1293,8 +1293,8 @@ unsigned lodepng_inflate(unsigned char** out, size_t* outsize, return error; } -static unsigned inflate(unsigned char** out, size_t* outsize, - const unsigned char* in, size_t insize, +static unsigned inflate(uint8_t** out, size_t* outsize, + const uint8_t* in, size_t insize, const LodePNGDecompressSettings* settings) { if(settings->custom_inflate) @@ -1418,7 +1418,7 @@ static void hash_cleanup(Hash* hash) -static unsigned getHash(const unsigned char* data, size_t size, size_t pos) +static unsigned getHash(const uint8_t* data, size_t size, size_t pos) { unsigned result = 0; if(pos + 2 < size) @@ -1439,10 +1439,10 @@ static unsigned getHash(const unsigned char* data, size_t size, size_t pos) return result & HASH_BIT_MASK; } -static unsigned countZeros(const unsigned char* data, size_t size, size_t pos) +static unsigned countZeros(const uint8_t* data, size_t size, size_t pos) { - const unsigned char* start = data + pos; - const unsigned char* end = start + MAX_SUPPORTED_DEFLATE_LENGTH; + const uint8_t* start = data + pos; + const uint8_t* end = start + MAX_SUPPORTED_DEFLATE_LENGTH; if(end > data + size) end = data + size; data = start; while(data != end && *data == 0) ++data; @@ -1472,7 +1472,7 @@ the "dictionary". A brute force search through all possible distances would be s this hash technique is one out of several ways to speed this up. */ static unsigned encodeLZ77(uivector* out, Hash* hash, - const unsigned char* in, size_t inpos, size_t insize, unsigned windowsize, + const uint8_t* in, size_t inpos, size_t insize, unsigned windowsize, unsigned minmatch, unsigned nicematch, unsigned lazymatching) { size_t pos; @@ -1491,7 +1491,7 @@ static unsigned encodeLZ77(uivector* out, Hash* hash, unsigned hashval; unsigned current_offset, current_length; unsigned prev_offset; - const unsigned char *lastptr, *foreptr, *backptr; + const uint8_t *lastptr, *foreptr, *backptr; unsigned hashpos; if(windowsize == 0 || windowsize > 32768) return 60; /*error: windowsize smaller/larger than allowed*/ @@ -1650,7 +1650,7 @@ static unsigned encodeLZ77(uivector* out, Hash* hash, /* /////////////////////////////////////////////////////////////////////////// */ -static unsigned deflateNoCompression(ucvector* out, const unsigned char* data, size_t datasize) +static unsigned deflateNoCompression(ucvector* out, const uint8_t* data, size_t datasize) { /*non compressed deflate block data: 1 bit BFINAL,2 bits BTYPE,(5 bits): it jumps to start of next byte, 2 bytes LEN, 2 bytes NLEN, LEN bytes literal DATA*/ @@ -1660,22 +1660,22 @@ static unsigned deflateNoCompression(ucvector* out, const unsigned char* data, s for(i = 0; i != numdeflateblocks; ++i) { unsigned BFINAL, BTYPE, LEN, NLEN; - unsigned char firstbyte; + uint8_t firstbyte; BFINAL = (i == numdeflateblocks - 1); BTYPE = 0; - firstbyte = (unsigned char)(BFINAL + ((BTYPE & 1) << 1) + ((BTYPE & 2) << 1)); + firstbyte = (uint8_t)(BFINAL + ((BTYPE & 1) << 1) + ((BTYPE & 2) << 1)); ucvector_push_back(out, firstbyte); LEN = 65535; if(datasize - datapos < 65535) LEN = (unsigned)datasize - datapos; NLEN = 65535 - LEN; - ucvector_push_back(out, (unsigned char)(LEN & 255)); - ucvector_push_back(out, (unsigned char)(LEN >> 8)); - ucvector_push_back(out, (unsigned char)(NLEN & 255)); - ucvector_push_back(out, (unsigned char)(NLEN >> 8)); + ucvector_push_back(out, (uint8_t)(LEN & 255)); + ucvector_push_back(out, (uint8_t)(LEN >> 8)); + ucvector_push_back(out, (uint8_t)(NLEN & 255)); + ucvector_push_back(out, (uint8_t)(NLEN >> 8)); /*Decompressed data*/ for(j = 0; j < 65535 && datapos < datasize; ++j) @@ -1722,7 +1722,7 @@ static void writeLZ77data(size_t* bp, ucvector* out, const uivector* lz77_encode /*Deflate for a block of type "dynamic", that is, with freely, optimally, created huffman trees*/ static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash, - const unsigned char* data, size_t datapos, size_t dataend, + const uint8_t* data, size_t datapos, size_t dataend, const LodePNGCompressSettings* settings, unsigned final) { unsigned error = 0; @@ -1967,7 +1967,7 @@ static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash, } static unsigned deflateFixed(ucvector* out, size_t* bp, Hash* hash, - const unsigned char* data, + const uint8_t* data, size_t datapos, size_t dataend, const LodePNGCompressSettings* settings, unsigned final) { @@ -2014,7 +2014,7 @@ static unsigned deflateFixed(ucvector* out, size_t* bp, Hash* hash, return error; } -static unsigned lodepng_deflatev(ucvector* out, const unsigned char* in, size_t insize, +static unsigned lodepng_deflatev(ucvector* out, const uint8_t* in, size_t insize, const LodePNGCompressSettings* settings) { unsigned error = 0; @@ -2055,8 +2055,8 @@ static unsigned lodepng_deflatev(ucvector* out, const unsigned char* in, size_t return error; } -unsigned lodepng_deflate(unsigned char** out, size_t* outsize, - const unsigned char* in, size_t insize, +unsigned lodepng_deflate(uint8_t** out, size_t* outsize, + const uint8_t* in, size_t insize, const LodePNGCompressSettings* settings) { unsigned error; @@ -2068,8 +2068,8 @@ unsigned lodepng_deflate(unsigned char** out, size_t* outsize, return error; } -static unsigned deflate(unsigned char** out, size_t* outsize, - const unsigned char* in, size_t insize, +static unsigned deflate(uint8_t** out, size_t* outsize, + const uint8_t* in, size_t insize, const LodePNGCompressSettings* settings) { if(settings->custom_deflate) @@ -2088,7 +2088,7 @@ static unsigned deflate(unsigned char** out, size_t* outsize, /* / Adler32 */ /* ////////////////////////////////////////////////////////////////////////// */ -static unsigned update_adler32(unsigned adler, const unsigned char* data, unsigned len) +static unsigned update_adler32(unsigned adler, const uint8_t* data, unsigned len) { unsigned s1 = adler & 0xffff; unsigned s2 = (adler >> 16) & 0xffff; @@ -2112,7 +2112,7 @@ static unsigned update_adler32(unsigned adler, const unsigned char* data, unsign } /*Return the adler32 of the bytes data[0..len-1]*/ -static unsigned adler32(const unsigned char* data, unsigned len) +static unsigned adler32(const uint8_t* data, unsigned len) { return update_adler32(1L, data, len); } @@ -2123,7 +2123,7 @@ static unsigned adler32(const unsigned char* data, unsigned len) #ifdef LODEPNG_COMPILE_DECODER -unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, const unsigned char* in, +unsigned lodepng_zlib_decompress(uint8_t** out, size_t* outsize, const uint8_t* in, size_t insize, const LodePNGDecompressSettings* settings) { unsigned error = 0; @@ -2168,7 +2168,7 @@ unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, const uns return 0; /*no error*/ } -static unsigned zlib_decompress(unsigned char** out, size_t* outsize, const unsigned char* in, +static unsigned zlib_decompress(uint8_t** out, size_t* outsize, const uint8_t* in, size_t insize, const LodePNGDecompressSettings* settings) { if(settings->custom_zlib) @@ -2185,7 +2185,7 @@ static unsigned zlib_decompress(unsigned char** out, size_t* outsize, const unsi #ifdef LODEPNG_COMPILE_ENCODER -unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in, +unsigned lodepng_zlib_compress(uint8_t** out, size_t* outsize, const uint8_t* in, size_t insize, const LodePNGCompressSettings* settings) { /*initially, *out must be NULL and outsize 0, if you just give some random *out @@ -2193,7 +2193,7 @@ unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, const unsig ucvector outv; size_t i; unsigned error; - unsigned char* deflatedata = 0; + uint8_t* deflatedata = 0; size_t deflatesize = 0; /*zlib data: 1 byte CMF (CM+CINFO), 1 byte FLG, deflate data, 4 byte ADLER32 checksum of the Decompressed data*/ @@ -2207,8 +2207,8 @@ unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, const unsig /*ucvector-controlled version of the output buffer, for dynamic array*/ ucvector_init_buffer(&outv, *out, *outsize); - ucvector_push_back(&outv, (unsigned char)(CMFFLG >> 8)); - ucvector_push_back(&outv, (unsigned char)(CMFFLG & 255)); + ucvector_push_back(&outv, (uint8_t)(CMFFLG >> 8)); + ucvector_push_back(&outv, (uint8_t)(CMFFLG & 255)); error = deflate(&deflatedata, &deflatesize, in, insize, settings); @@ -2227,7 +2227,7 @@ unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, const unsig } /* compress using the default or custom zlib function */ -static unsigned zlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in, +static unsigned zlib_compress(uint8_t** out, size_t* outsize, const uint8_t* in, size_t insize, const LodePNGCompressSettings* settings) { if(settings->custom_zlib) @@ -2245,7 +2245,7 @@ static unsigned zlib_compress(unsigned char** out, size_t* outsize, const unsign #else /*no LODEPNG_COMPILE_ZLIB*/ #ifdef LODEPNG_COMPILE_DECODER -static unsigned zlib_decompress(unsigned char** out, size_t* outsize, const unsigned char* in, +static unsigned zlib_decompress(uint8_t** out, size_t* outsize, const uint8_t* in, size_t insize, const LodePNGDecompressSettings* settings) { if(!settings->custom_zlib) return 87; /*no custom zlib function provided */ @@ -2253,7 +2253,7 @@ static unsigned zlib_decompress(unsigned char** out, size_t* outsize, const unsi } #endif /*LODEPNG_COMPILE_DECODER*/ #ifdef LODEPNG_COMPILE_ENCODER -static unsigned zlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in, +static unsigned zlib_compress(uint8_t** out, size_t* outsize, const uint8_t* in, size_t insize, const LodePNGCompressSettings* settings) { if(!settings->custom_zlib) return 87; /*no custom zlib function provided */ @@ -2356,7 +2356,7 @@ static unsigned lodepng_crc32_table[256] = { }; /*Return the CRC of the bytes buf[0..len-1].*/ -unsigned lodepng_crc32(const unsigned char* data, size_t length) +unsigned lodepng_crc32(const uint8_t* data, size_t length) { unsigned r = 0xffffffffu; size_t i; @@ -2367,21 +2367,21 @@ unsigned lodepng_crc32(const unsigned char* data, size_t length) return r ^ 0xffffffffu; } #else /* !LODEPNG_NO_COMPILE_CRC */ -unsigned lodepng_crc32(const unsigned char* data, size_t length); +unsigned lodepng_crc32(const uint8_t* data, size_t length); #endif /* !LODEPNG_NO_COMPILE_CRC */ /* ////////////////////////////////////////////////////////////////////////// */ /* / Reading and writing single bits and bytes from/to stream for LodePNG / */ /* ////////////////////////////////////////////////////////////////////////// */ -static unsigned char readBitFromReversedStream(size_t* bitpointer, const unsigned char* bitstream) +static uint8_t readBitFromReversedStream(size_t* bitpointer, const uint8_t* bitstream) { - unsigned char result = (unsigned char)((bitstream[(*bitpointer) >> 3] >> (7 - ((*bitpointer) & 0x7))) & 1); + uint8_t result = (uint8_t)((bitstream[(*bitpointer) >> 3] >> (7 - ((*bitpointer) & 0x7))) & 1); ++(*bitpointer); return result; } -static unsigned readBitsFromReversedStream(size_t* bitpointer, const unsigned char* bitstream, size_t nbits) +static unsigned readBitsFromReversedStream(size_t* bitpointer, const uint8_t* bitstream, size_t nbits) { unsigned result = 0; size_t i; @@ -2394,7 +2394,7 @@ static unsigned readBitsFromReversedStream(size_t* bitpointer, const unsigned ch } #ifdef LODEPNG_COMPILE_DECODER -static void setBitOfReversedStream0(size_t* bitpointer, unsigned char* bitstream, unsigned char bit) +static void setBitOfReversedStream0(size_t* bitpointer, uint8_t* bitstream, uint8_t bit) { /*the current bit in bitstream must be 0 for this to work*/ if(bit) @@ -2406,10 +2406,10 @@ static void setBitOfReversedStream0(size_t* bitpointer, unsigned char* bitstream } #endif /*LODEPNG_COMPILE_DECODER*/ -static void setBitOfReversedStream(size_t* bitpointer, unsigned char* bitstream, unsigned char bit) +static void setBitOfReversedStream(size_t* bitpointer, uint8_t* bitstream, uint8_t bit) { /*the current bit in bitstream may be 0 or 1 for this to work*/ - if(bit == 0) bitstream[(*bitpointer) >> 3] &= (unsigned char)(~(1 << (7 - ((*bitpointer) & 0x7)))); + if(bit == 0) bitstream[(*bitpointer) >> 3] &= (uint8_t)(~(1 << (7 - ((*bitpointer) & 0x7)))); else bitstream[(*bitpointer) >> 3] |= (1 << (7 - ((*bitpointer) & 0x7))); ++(*bitpointer); } @@ -2418,50 +2418,50 @@ static void setBitOfReversedStream(size_t* bitpointer, unsigned char* bitstream, /* / PNG chunks / */ /* ////////////////////////////////////////////////////////////////////////// */ -unsigned lodepng_chunk_length(const unsigned char* chunk) +unsigned lodepng_chunk_length(const uint8_t* chunk) { return lodepng_read32bitInt(&chunk[0]); } -void lodepng_chunk_type(char type[5], const unsigned char* chunk) +void lodepng_chunk_type(char type[5], const uint8_t* chunk) { unsigned i; for(i = 0; i != 4; ++i) type[i] = (char)chunk[4 + i]; type[4] = 0; /*null termination char*/ } -unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type) +uint8_t lodepng_chunk_type_equals(const uint8_t* chunk, const char* type) { if(strlen(type) != 4) return 0; return (chunk[4] == type[0] && chunk[5] == type[1] && chunk[6] == type[2] && chunk[7] == type[3]); } -unsigned char lodepng_chunk_ancillary(const unsigned char* chunk) +uint8_t lodepng_chunk_ancillary(const uint8_t* chunk) { return((chunk[4] & 32) != 0); } -unsigned char lodepng_chunk_private(const unsigned char* chunk) +uint8_t lodepng_chunk_private(const uint8_t* chunk) { return((chunk[6] & 32) != 0); } -unsigned char lodepng_chunk_safetocopy(const unsigned char* chunk) +uint8_t lodepng_chunk_safetocopy(const uint8_t* chunk) { return((chunk[7] & 32) != 0); } -unsigned char* lodepng_chunk_data(unsigned char* chunk) +uint8_t* lodepng_chunk_data(uint8_t* chunk) { return &chunk[8]; } -const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk) +const uint8_t* lodepng_chunk_data_const(const uint8_t* chunk) { return &chunk[8]; } -unsigned lodepng_chunk_check_crc(const unsigned char* chunk) +unsigned lodepng_chunk_check_crc(const uint8_t* chunk) { unsigned length = lodepng_chunk_length(chunk); unsigned CRC = lodepng_read32bitInt(&chunk[length + 8]); @@ -2471,34 +2471,34 @@ unsigned lodepng_chunk_check_crc(const unsigned char* chunk) else return 0; } -void lodepng_chunk_generate_crc(unsigned char* chunk) +void lodepng_chunk_generate_crc(uint8_t* chunk) { unsigned length = lodepng_chunk_length(chunk); unsigned CRC = lodepng_crc32(&chunk[4], length + 4); lodepng_set32bitInt(chunk + 8 + length, CRC); } -unsigned char* lodepng_chunk_next(unsigned char* chunk) +uint8_t* lodepng_chunk_next(uint8_t* chunk) { unsigned total_chunk_length = lodepng_chunk_length(chunk) + 12; return &chunk[total_chunk_length]; } -const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk) +const uint8_t* lodepng_chunk_next_const(const uint8_t* chunk) { unsigned total_chunk_length = lodepng_chunk_length(chunk) + 12; return &chunk[total_chunk_length]; } -unsigned lodepng_chunk_append(unsigned char** out, size_t* outlength, const unsigned char* chunk) +unsigned lodepng_chunk_append(uint8_t** out, size_t* outlength, const uint8_t* chunk) { unsigned i; unsigned total_chunk_length = lodepng_chunk_length(chunk) + 12; - unsigned char *chunk_start, *new_buffer; + uint8_t *chunk_start, *new_buffer; size_t new_length = (*outlength) + total_chunk_length; if(new_length < total_chunk_length || new_length < (*outlength)) return 77; /*integer overflow happened*/ - new_buffer = (unsigned char*)lodepng_realloc(*out, new_length); + new_buffer = (uint8_t*)lodepng_realloc(*out, new_length); if(!new_buffer) return 83; /*alloc fail*/ (*out) = new_buffer; (*outlength) = new_length; @@ -2509,14 +2509,14 @@ unsigned lodepng_chunk_append(unsigned char** out, size_t* outlength, const unsi return 0; } -unsigned lodepng_chunk_create(unsigned char** out, size_t* outlength, unsigned length, - const char* type, const unsigned char* data) +unsigned lodepng_chunk_create(uint8_t** out, size_t* outlength, unsigned length, + const char* type, const uint8_t* data) { unsigned i; - unsigned char *chunk, *new_buffer; + uint8_t *chunk, *new_buffer; size_t new_length = (*outlength) + length + 12; if(new_length < length + 12 || new_length < (*outlength)) return 77; /*integer overflow happened*/ - new_buffer = (unsigned char*)lodepng_realloc(*out, new_length); + new_buffer = (uint8_t*)lodepng_realloc(*out, new_length); if(!new_buffer) return 83; /*alloc fail*/ (*out) = new_buffer; (*outlength) = new_length; @@ -2526,10 +2526,10 @@ unsigned lodepng_chunk_create(unsigned char** out, size_t* outlength, unsigned l lodepng_set32bitInt(chunk, (unsigned)length); /*2: chunk name (4 letters)*/ - chunk[4] = (unsigned char)type[0]; - chunk[5] = (unsigned char)type[1]; - chunk[6] = (unsigned char)type[2]; - chunk[7] = (unsigned char)type[3]; + chunk[4] = (uint8_t)type[0]; + chunk[5] = (uint8_t)type[1]; + chunk[6] = (uint8_t)type[2]; + chunk[7] = (uint8_t)type[3]; /*3: the data*/ for(i = 0; i != length; ++i) chunk[8 + i] = data[i]; @@ -2602,7 +2602,7 @@ unsigned lodepng_color_mode_copy(LodePNGColorMode* dest, const LodePNGColorMode* *dest = *source; if(source->palette) { - dest->palette = (unsigned char*)lodepng_malloc(1024); + dest->palette = (uint8_t*)lodepng_malloc(1024); if(!dest->palette && source->palettesize) return 83; /*alloc fail*/ for(i = 0; i != source->palettesize * 4; ++i) dest->palette[i] = source->palette[i]; } @@ -2637,15 +2637,15 @@ void lodepng_palette_clear(LodePNGColorMode* info) } unsigned lodepng_palette_add(LodePNGColorMode* info, - unsigned char r, unsigned char g, unsigned char b, unsigned char a) + uint8_t r, uint8_t g, uint8_t b, uint8_t a) { - unsigned char* data; + uint8_t* data; /*the same resize technique as C++ std::vectors is used, and here it's made so that for a palette with the max of 256 colors, it'll have the exact alloc size*/ if(!info->palette) /*allocate palette if empty*/ { /*room for 256 colors with 4 bytes each*/ - data = (unsigned char*)lodepng_realloc(info->palette, 1024); + data = (uint8_t*)lodepng_realloc(info->palette, 1024); if(!data) return 83; /*alloc fail*/ else info->palette = data; } @@ -2747,7 +2747,7 @@ static unsigned LodePNGUnknownChunks_copy(LodePNGInfo* dest, const LodePNGInfo* { size_t j; dest->unknown_chunks_size[i] = src->unknown_chunks_size[i]; - dest->unknown_chunks_data[i] = (unsigned char*)lodepng_malloc(src->unknown_chunks_size[i]); + dest->unknown_chunks_data[i] = (uint8_t*)lodepng_malloc(src->unknown_chunks_size[i]); if(!dest->unknown_chunks_data[i] && dest->unknown_chunks_size[i]) return 83; /*alloc fail*/ for(j = 0; j < src->unknown_chunks_size[i]; ++j) { @@ -2958,7 +2958,7 @@ unsigned lodepng_info_copy(LodePNGInfo* dest, const LodePNGInfo* source) /* ////////////////////////////////////////////////////////////////////////// */ /*index: bitgroup index, bits: bitgroup size(1, 2 or 4), in: bitgroup value, out: octet array to add bits to*/ -static void addColorBits(unsigned char* out, size_t index, unsigned bits, unsigned in) +static void addColorBits(uint8_t* out, size_t index, unsigned bits, unsigned in) { unsigned m = bits == 1 ? 7 : bits == 2 ? 3 : 1; /*8 / bits - 1*/ /*p = the partial index in the byte, e.g. with 4 palettebits it is 0 for first half or 1 for second half*/ @@ -3004,7 +3004,7 @@ static void color_tree_cleanup(ColorTree* tree) } /*returns -1 if color not present, its index otherwise*/ -static int color_tree_get(ColorTree* tree, unsigned char r, unsigned char g, unsigned char b, unsigned char a) +static int color_tree_get(ColorTree* tree, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { int bit = 0; for(bit = 0; bit < 8; ++bit) @@ -3017,7 +3017,7 @@ static int color_tree_get(ColorTree* tree, unsigned char r, unsigned char g, uns } #ifdef LODEPNG_COMPILE_ENCODER -static int color_tree_has(ColorTree* tree, unsigned char r, unsigned char g, unsigned char b, unsigned char a) +static int color_tree_has(ColorTree* tree, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { return color_tree_get(tree, r, g, b, a) >= 0; } @@ -3026,7 +3026,7 @@ static int color_tree_has(ColorTree* tree, unsigned char r, unsigned char g, uns /*color is not allowed to already exist. Index should be >= 0 (it's signed to be compatible with using -1 for "doesn't exist")*/ static void color_tree_add(ColorTree* tree, - unsigned char r, unsigned char g, unsigned char b, unsigned char a, unsigned index) + uint8_t r, uint8_t g, uint8_t b, uint8_t a, unsigned index) { int bit; for(bit = 0; bit < 8; ++bit) @@ -3043,13 +3043,13 @@ static void color_tree_add(ColorTree* tree, } /*put a pixel, given its RGBA color, into image of any color type*/ -static unsigned rgba8ToPixel(unsigned char* out, size_t i, +static unsigned rgba8ToPixel(uint8_t* out, size_t i, const LodePNGColorMode* mode, ColorTree* tree /*for palette*/, - unsigned char r, unsigned char g, unsigned char b, unsigned char a) + uint8_t r, uint8_t g, uint8_t b, uint8_t a) { if(mode->colortype == LCT_GREY) { - unsigned char grey = r; /*((uint16_t)r + g + b) / 3*/; + uint8_t grey = r; /*((uint16_t)r + g + b) / 3*/; if(mode->bitdepth == 8) out[i] = grey; else if(mode->bitdepth == 16) out[i * 2 + 0] = out[i * 2 + 1] = grey; else @@ -3083,7 +3083,7 @@ static unsigned rgba8ToPixel(unsigned char* out, size_t i, } else if(mode->colortype == LCT_GREY_ALPHA) { - unsigned char grey = r; /*((uint16_t)r + g + b) / 3*/; + uint8_t grey = r; /*((uint16_t)r + g + b) / 3*/; if(mode->bitdepth == 8) { out[i * 2 + 0] = grey; @@ -3117,7 +3117,7 @@ static unsigned rgba8ToPixel(unsigned char* out, size_t i, } /*put a pixel, given its RGBA16 color, into image of any color 16-bitdepth type*/ -static void rgba16ToPixel(unsigned char* out, size_t i, +static void rgba16ToPixel(uint8_t* out, size_t i, const LodePNGColorMode* mode, uint16_t r, uint16_t g, uint16_t b, uint16_t a) { @@ -3158,9 +3158,9 @@ static void rgba16ToPixel(unsigned char* out, size_t i, } /*Get RGBA8 color of pixel with index i (y * width + x) from the raw image with given color type.*/ -static void getPixelColorRGBA8(unsigned char* r, unsigned char* g, - unsigned char* b, unsigned char* a, - const unsigned char* in, size_t i, +static void getPixelColorRGBA8(uint8_t* r, uint8_t* g, + uint8_t* b, uint8_t* a, + const uint8_t* in, size_t i, const LodePNGColorMode* mode) { if(mode->colortype == LCT_GREY) @@ -3268,8 +3268,8 @@ mode test cases, optimized to convert the colors much faster, when converting to RGBA or RGB with 8 bit per cannel. buffer must be RGBA or RGB output with enough memory, if has_alpha is true the output is RGBA. mode has the color mode of the input buffer.*/ -static void getPixelColorsRGBA8(unsigned char* buffer, size_t numpixels, - unsigned has_alpha, const unsigned char* in, +static void getPixelColorsRGBA8(uint8_t* buffer, size_t numpixels, + unsigned has_alpha, const uint8_t* in, const LodePNGColorMode* mode) { unsigned num_channels = has_alpha ? 4 : 3; @@ -3403,7 +3403,7 @@ static void getPixelColorsRGBA8(unsigned char* buffer, size_t numpixels, /*Get RGBA16 color of pixel with index i (y * width + x) from the raw image with given color type, but the given color type must be 16-bit itself.*/ static void getPixelColorRGBA16(uint16_t* r, uint16_t* g, uint16_t* b, uint16_t* a, - const unsigned char* in, size_t i, const LodePNGColorMode* mode) + const uint8_t* in, size_t i, const LodePNGColorMode* mode) { if(mode->colortype == LCT_GREY) { @@ -3436,7 +3436,7 @@ static void getPixelColorRGBA16(uint16_t* r, uint16_t* g, uint16_t* b, uint16_t* } } -unsigned lodepng_convert(unsigned char* out, const unsigned char* in, +unsigned lodepng_convert(uint8_t* out, const uint8_t* in, const LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in, unsigned w, unsigned h) { @@ -3455,7 +3455,7 @@ unsigned lodepng_convert(unsigned char* out, const unsigned char* in, if(mode_out->colortype == LCT_PALETTE) { size_t palettesize = mode_out->palettesize; - const unsigned char* palette = mode_out->palette; + const uint8_t* palette = mode_out->palette; size_t palsize = (size_t)1u << mode_out->bitdepth; /*if the user specified output palette but did not give the values, assume they want the values of the input color type (assuming that one is palette). @@ -3478,7 +3478,7 @@ unsigned lodepng_convert(unsigned char* out, const unsigned char* in, color_tree_init(&tree); for(i = 0; i != palsize; ++i) { - const unsigned char* p = &palette[i * 4]; + const uint8_t* p = &palette[i * 4]; color_tree_add(&tree, p[0], p[1], p[2], p[3], i); } } @@ -3502,7 +3502,7 @@ unsigned lodepng_convert(unsigned char* out, const unsigned char* in, } else { - unsigned char r = 0, g = 0, b = 0, a = 0; + uint8_t r = 0, g = 0, b = 0, a = 0; for(i = 0; i != numpixels; ++i) { getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in); @@ -3545,7 +3545,7 @@ void lodepng_color_profile_init(LodePNGColorProfile* profile) }*/ /*Returns how many bits needed to represent given value (max 8 bit)*/ -static unsigned getValueRequiredBits(unsigned char value) +static unsigned getValueRequiredBits(uint8_t value) { if(value == 0 || value == 255) return 1; /*The scaling of 2-bit and 4-bit values uses multiples of 85 and 17*/ @@ -3556,7 +3556,7 @@ static unsigned getValueRequiredBits(unsigned char value) /*profile must already have been inited with mode. It's ok to set some parameters of profile to done already.*/ unsigned lodepng_get_color_profile(LodePNGColorProfile* profile, - const unsigned char* in, unsigned w, unsigned h, + const uint8_t* in, unsigned w, unsigned h, const LodePNGColorMode* mode) { unsigned error = 0; @@ -3651,7 +3651,7 @@ unsigned lodepng_get_color_profile(LodePNGColorProfile* profile, } else /* < 16-bit */ { - unsigned char r = 0, g = 0, b = 0, a = 0; + uint8_t r = 0, g = 0, b = 0, a = 0; for(i = 0; i != numpixels; ++i) { getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode); @@ -3705,7 +3705,7 @@ unsigned lodepng_get_color_profile(LodePNGColorProfile* profile, color_tree_add(&tree, r, g, b, a, profile->numcolors); if(profile->numcolors < 256) { - unsigned char* p = profile->palette; + uint8_t* p = profile->palette; unsigned n = profile->numcolors; p[n * 4 + 0] = r; p[n * 4 + 1] = g; @@ -3752,7 +3752,7 @@ are less than 256 colors, ... Updates values of mode with a potentially smaller color model. mode_out should contain the user chosen color model, but will be overwritten with the new chosen one.*/ unsigned lodepng_auto_choose_color(LodePNGColorMode* mode_out, - const unsigned char* image, unsigned w, unsigned h, + const uint8_t* image, unsigned w, unsigned h, const LodePNGColorMode* mode_in) { LodePNGColorProfile prof; @@ -3778,7 +3778,7 @@ unsigned lodepng_auto_choose_color(LodePNGColorMode* mode_out, if(palette_ok) { - unsigned char* p = prof.palette; + uint8_t* p = prof.palette; lodepng_palette_clear(mode_out); /*remove potential earlier palette*/ for(i = 0; i != prof.numcolors; ++i) { @@ -3823,15 +3823,15 @@ Paeth predicter, used by PNG filter type 4 The parameters are of type int16_t, but should come from unsigned chars, the shorts are only needed to make the paeth calculation correct. */ -static unsigned char paethPredictor(int16_t a, int16_t b, int16_t c) +static uint8_t paethPredictor(int16_t a, int16_t b, int16_t c) { int16_t pa = abs(b - c); int16_t pb = abs(a - c); int16_t pc = abs(a + b - c - c); - if(pc < pa && pc < pb) return (unsigned char)c; - else if(pb < pa) return (unsigned char)b; - else return (unsigned char)a; + if(pc < pa && pc < pb) return (uint8_t)c; + else if(pb < pa) return (uint8_t)b; + else return (uint8_t)a; } /*shared values used by multiple Adam7 related functions*/ @@ -3892,7 +3892,7 @@ static void Adam7_getpassvalues(unsigned passw[7], unsigned passh[7], size_t fil /*read the information from the header and store it in the LodePNGInfo. return value is error*/ unsigned lodepng_inspect(unsigned* w, unsigned* h, LodePNGState* state, - const unsigned char* in, size_t insize) + const uint8_t* in, size_t insize) { LodePNGInfo* info = &state->info_png; if(insize == 0 || in == 0) @@ -3957,8 +3957,8 @@ unsigned lodepng_inspect(unsigned* w, unsigned* h, LodePNGState* state, return state->error; } -static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scanline, const unsigned char* precon, - size_t bytewidth, unsigned char filterType, size_t length) +static unsigned unfilterScanline(uint8_t* recon, const uint8_t* scanline, const uint8_t* precon, + size_t bytewidth, uint8_t filterType, size_t length) { /* For PNG filter method 0 @@ -4031,7 +4031,7 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan return 0; } -static unsigned unfilter(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp) +static unsigned unfilter(uint8_t* out, const uint8_t* in, unsigned w, unsigned h, unsigned bpp) { /* For PNG filter method 0 @@ -4042,7 +4042,7 @@ static unsigned unfilter(unsigned char* out, const unsigned char* in, unsigned w */ unsigned y; - unsigned char* prevline = 0; + uint8_t* prevline = 0; /*bytewidth is used for filtering, is 1 when bpp < 8, number of bytes per pixel otherwise*/ size_t bytewidth = (bpp + 7) / 8; @@ -4052,7 +4052,7 @@ static unsigned unfilter(unsigned char* out, const unsigned char* in, unsigned w { size_t outindex = linebytes * y; size_t inindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/ - unsigned char filterType = in[inindex]; + uint8_t filterType = in[inindex]; CERROR_TRY_RETURN(unfilterScanline(&out[outindex], &in[inindex + 1], prevline, bytewidth, filterType, linebytes)); @@ -4073,7 +4073,7 @@ out must be big enough AND must be 0 everywhere if bpp < 8 in the current implem (because that's likely a little bit faster) NOTE: comments about padding bits are only relevant if bpp < 8 */ -static void Adam7_deinterlace(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp) +static void Adam7_deinterlace(uint8_t* out, const uint8_t* in, unsigned w, unsigned h, unsigned bpp) { unsigned passw[7], passh[7]; size_t filter_passstart[8], padded_passstart[8], passstart[8]; @@ -4114,7 +4114,7 @@ static void Adam7_deinterlace(unsigned char* out, const unsigned char* in, unsig obp = (ADAM7_IY[i] + y * ADAM7_DY[i]) * olinebits + (ADAM7_IX[i] + x * ADAM7_DX[i]) * bpp; for(b = 0; b < bpp; ++b) { - unsigned char bit = readBitFromReversedStream(&ibp, in); + uint8_t bit = readBitFromReversedStream(&ibp, in); /*note that this function assumes the out buffer is completely 0, use setBitOfReversedStream otherwise*/ setBitOfReversedStream0(&obp, out, bit); } @@ -4123,7 +4123,7 @@ static void Adam7_deinterlace(unsigned char* out, const unsigned char* in, unsig } } -static void removePaddingBits(unsigned char* out, const unsigned char* in, +static void removePaddingBits(uint8_t* out, const uint8_t* in, size_t olinebits, size_t ilinebits, unsigned h) { /* @@ -4143,7 +4143,7 @@ static void removePaddingBits(unsigned char* out, const unsigned char* in, size_t x; for(x = 0; x < olinebits; ++x) { - unsigned char bit = readBitFromReversedStream(&ibp, in); + uint8_t bit = readBitFromReversedStream(&ibp, in); setBitOfReversedStream(&obp, out, bit); } ibp += diff; @@ -4153,7 +4153,7 @@ static void removePaddingBits(unsigned char* out, const unsigned char* in, /*out must be buffer big enough to contain full image, and in must contain the full decompressed data from the IDAT chunks (with filter index bytes and possible padding bits) return value is error*/ -static unsigned postProcessScanlines(unsigned char* out, unsigned char* in, +static unsigned postProcessScanlines(uint8_t* out, uint8_t* in, unsigned w, unsigned h, const LodePNGInfo* info_png) { /* @@ -4203,12 +4203,12 @@ static unsigned postProcessScanlines(unsigned char* out, unsigned char* in, return 0; } -static unsigned readChunk_PLTE(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength) +static unsigned readChunk_PLTE(LodePNGColorMode* color, const uint8_t* data, size_t chunkLength) { unsigned pos = 0, i; if(color->palette) lodepng_free(color->palette); color->palettesize = chunkLength / 3; - color->palette = (unsigned char*)lodepng_malloc(4 * color->palettesize); + color->palette = (uint8_t*)lodepng_malloc(4 * color->palettesize); if(!color->palette && color->palettesize) { color->palettesize = 0; @@ -4227,7 +4227,7 @@ static unsigned readChunk_PLTE(LodePNGColorMode* color, const unsigned char* dat return 0; /* OK */ } -static unsigned readChunk_tRNS(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength) +static unsigned readChunk_tRNS(LodePNGColorMode* color, const uint8_t* data, size_t chunkLength) { unsigned i; if(color->colortype == LCT_PALETTE) @@ -4263,7 +4263,7 @@ static unsigned readChunk_tRNS(LodePNGColorMode* color, const unsigned char* dat #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS /*background color chunk (bKGD)*/ -static unsigned readChunk_bKGD(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) +static unsigned readChunk_bKGD(LodePNGInfo* info, const uint8_t* data, size_t chunkLength) { if(info->color.colortype == LCT_PALETTE) { @@ -4296,7 +4296,7 @@ static unsigned readChunk_bKGD(LodePNGInfo* info, const unsigned char* data, siz } /*text chunk (tEXt)*/ -static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) +static unsigned readChunk_tEXt(LodePNGInfo* info, const uint8_t* data, size_t chunkLength) { unsigned error = 0; char *key = 0, *str = 0; @@ -4340,7 +4340,7 @@ static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, siz /*compressed text chunk (zTXt)*/ static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings, - const unsigned char* data, size_t chunkLength) + const uint8_t* data, size_t chunkLength) { unsigned error = 0; unsigned i; @@ -4371,7 +4371,7 @@ static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSetting length = chunkLength - string2_begin; /*will fail if zlib error, e.g. if length is too small*/ error = zlib_decompress(&decoded.data, &decoded.size, - (const unsigned char*)(&data[string2_begin]), + (const uint8_t*)(&data[string2_begin]), length, zlibsettings); if(error) break; ucvector_push_back(&decoded, 0); @@ -4389,7 +4389,7 @@ static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSetting /*international text chunk (iTXt)*/ static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings, - const unsigned char* data, size_t chunkLength) + const uint8_t* data, size_t chunkLength) { unsigned error = 0; unsigned i; @@ -4454,7 +4454,7 @@ static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSetting { /*will fail if zlib error, e.g. if length is too small*/ error = zlib_decompress(&decoded.data, &decoded.size, - (const unsigned char*)(&data[begin]), + (const uint8_t*)(&data[begin]), length, zlibsettings); if(error) break; if(decoded.allocsize < decoded.size) decoded.allocsize = decoded.size; @@ -4481,7 +4481,7 @@ static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSetting return error; } -static unsigned readChunk_tIME(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) +static unsigned readChunk_tIME(LodePNGInfo* info, const uint8_t* data, size_t chunkLength) { if(chunkLength != 7) return 73; /*invalid tIME chunk size*/ @@ -4496,7 +4496,7 @@ static unsigned readChunk_tIME(LodePNGInfo* info, const unsigned char* data, siz return 0; /* OK */ } -static unsigned readChunk_pHYs(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) +static unsigned readChunk_pHYs(LodePNGInfo* info, const uint8_t* data, size_t chunkLength) { if(chunkLength != 9) return 74; /*invalid pHYs chunk size*/ @@ -4510,12 +4510,12 @@ static unsigned readChunk_pHYs(LodePNGInfo* info, const unsigned char* data, siz #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ /*read a PNG, the result will be in the same color type as the PNG (hence "generic")*/ -static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h, +static void decodeGeneric(uint8_t** out, unsigned* w, unsigned* h, LodePNGState* state, - const unsigned char* in, size_t insize) + const uint8_t* in, size_t insize) { - unsigned char IEND = 0; - const unsigned char* chunk; + uint8_t IEND = 0; + const uint8_t* chunk; size_t i; ucvector idat; /*the data from idat chunks*/ ucvector scanlines; @@ -4551,7 +4551,7 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h, while(!IEND && !state->error) { unsigned chunkLength; - const unsigned char* data; /*the data in the chunk*/ + const uint8_t* data; /*the data in the chunk*/ /*error: size of the in buffer too small to contain next chunk*/ if((size_t)((chunk - in) + 12) > insize || chunk < in) @@ -4711,7 +4711,7 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h, if(!state->error) { outsize = lodepng_get_raw_size(*w, *h, &state->info_png.color); - *out = (unsigned char*)lodepng_malloc(outsize); + *out = (uint8_t*)lodepng_malloc(outsize); if(!*out) state->error = 83; /*alloc fail*/ } if(!state->error) @@ -4722,9 +4722,9 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h, ucvector_cleanup(&scanlines); } -unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h, +unsigned lodepng_decode(uint8_t** out, unsigned* w, unsigned* h, LodePNGState* state, - const unsigned char* in, size_t insize) + const uint8_t* in, size_t insize) { *out = 0; decodeGeneric(out, w, h, state, in, insize); @@ -4743,7 +4743,7 @@ unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h, else { /*color conversion needed; sort of copy of the data*/ - unsigned char* data = *out; + uint8_t* data = *out; size_t outsize; /*TODO: check if this works according to the statement in the documentation: "The converter can convert @@ -4755,7 +4755,7 @@ unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h, } outsize = lodepng_get_raw_size(*w, *h, &state->info_raw); - *out = (unsigned char*)lodepng_malloc(outsize); + *out = (uint8_t*)lodepng_malloc(outsize); if(!(*out)) { state->error = 83; /*alloc fail*/ @@ -4767,7 +4767,7 @@ unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h, return state->error; } -unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in, +unsigned lodepng_decode_memory(uint8_t** out, unsigned* w, unsigned* h, const uint8_t* in, size_t insize, LodePNGColorType colortype, unsigned bitdepth) { unsigned error; @@ -4780,21 +4780,21 @@ unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, co return error; } -unsigned lodepng_decode32(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in, size_t insize) +unsigned lodepng_decode32(uint8_t** out, unsigned* w, unsigned* h, const uint8_t* in, size_t insize) { return lodepng_decode_memory(out, w, h, in, insize, LCT_RGBA, 8); } -unsigned lodepng_decode24(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in, size_t insize) +unsigned lodepng_decode24(uint8_t** out, unsigned* w, unsigned* h, const uint8_t* in, size_t insize) { return lodepng_decode_memory(out, w, h, in, insize, LCT_RGB, 8); } #ifdef LODEPNG_COMPILE_DISK -unsigned lodepng_decode_file(unsigned char** out, unsigned* w, unsigned* h, const char* filename, +unsigned lodepng_decode_file(uint8_t** out, unsigned* w, unsigned* h, const char* filename, LodePNGColorType colortype, unsigned bitdepth) { - unsigned char* buffer = 0; + uint8_t* buffer = 0; size_t buffersize; unsigned error; error = lodepng_load_file(&buffer, &buffersize, filename); @@ -4803,12 +4803,12 @@ unsigned lodepng_decode_file(unsigned char** out, unsigned* w, unsigned* h, cons return error; } -unsigned lodepng_decode32_file(unsigned char** out, unsigned* w, unsigned* h, const char* filename) +unsigned lodepng_decode32_file(uint8_t** out, unsigned* w, unsigned* h, const char* filename) { return lodepng_decode_file(out, w, h, filename, LCT_RGBA, 8); } -unsigned lodepng_decode24_file(unsigned char** out, unsigned* w, unsigned* h, const char* filename) +unsigned lodepng_decode24_file(uint8_t** out, unsigned* w, unsigned* h, const char* filename) { return lodepng_decode_file(out, w, h, filename, LCT_RGB, 8); } @@ -4869,7 +4869,7 @@ void lodepng_state_copy(LodePNGState* dest, const LodePNGState* source) /* ////////////////////////////////////////////////////////////////////////// */ /*chunkName must be string of 4 characters*/ -static unsigned addChunk(ucvector* out, const char* chunkName, const unsigned char* data, size_t length) +static unsigned addChunk(ucvector* out, const char* chunkName, const uint8_t* data, size_t length) { CERROR_TRY_RETURN(lodepng_chunk_create(&out->data, &out->size, (unsigned)length, chunkName, data)); out->allocsize = out->size; /*fix the allocsize again*/ @@ -4898,8 +4898,8 @@ static unsigned addChunk_IHDR(ucvector* out, unsigned w, unsigned h, lodepng_add32bitInt(&header, w); /*width*/ lodepng_add32bitInt(&header, h); /*height*/ - ucvector_push_back(&header, (unsigned char)bitdepth); /*bit depth*/ - ucvector_push_back(&header, (unsigned char)colortype); /*color type*/ + ucvector_push_back(&header, (uint8_t)bitdepth); /*bit depth*/ + ucvector_push_back(&header, (uint8_t)colortype); /*color type*/ ucvector_push_back(&header, 0); /*compression method*/ ucvector_push_back(&header, 0); /*filter method*/ ucvector_push_back(&header, interlace_method); /*interlace method*/ @@ -4949,20 +4949,20 @@ static unsigned addChunk_tRNS(ucvector* out, const LodePNGColorMode* info) { if(info->key_defined) { - ucvector_push_back(&tRNS, (unsigned char)(info->key_r >> 8)); - ucvector_push_back(&tRNS, (unsigned char)(info->key_r & 255)); + ucvector_push_back(&tRNS, (uint8_t)(info->key_r >> 8)); + ucvector_push_back(&tRNS, (uint8_t)(info->key_r & 255)); } } else if(info->colortype == LCT_RGB) { if(info->key_defined) { - ucvector_push_back(&tRNS, (unsigned char)(info->key_r >> 8)); - ucvector_push_back(&tRNS, (unsigned char)(info->key_r & 255)); - ucvector_push_back(&tRNS, (unsigned char)(info->key_g >> 8)); - ucvector_push_back(&tRNS, (unsigned char)(info->key_g & 255)); - ucvector_push_back(&tRNS, (unsigned char)(info->key_b >> 8)); - ucvector_push_back(&tRNS, (unsigned char)(info->key_b & 255)); + ucvector_push_back(&tRNS, (uint8_t)(info->key_r >> 8)); + ucvector_push_back(&tRNS, (uint8_t)(info->key_r & 255)); + ucvector_push_back(&tRNS, (uint8_t)(info->key_g >> 8)); + ucvector_push_back(&tRNS, (uint8_t)(info->key_g & 255)); + ucvector_push_back(&tRNS, (uint8_t)(info->key_b >> 8)); + ucvector_push_back(&tRNS, (uint8_t)(info->key_b & 255)); } } @@ -4972,7 +4972,7 @@ static unsigned addChunk_tRNS(ucvector* out, const LodePNGColorMode* info) return error; } -static unsigned addChunk_IDAT(ucvector* out, const unsigned char* data, size_t datasize, +static unsigned addChunk_IDAT(ucvector* out, const uint8_t* data, size_t datasize, LodePNGCompressSettings* zlibsettings) { ucvector zlibdata; @@ -5002,10 +5002,10 @@ static unsigned addChunk_tEXt(ucvector* out, const char* keyword, const char* te size_t i; ucvector text; ucvector_init(&text); - for(i = 0; keyword[i] != 0; ++i) ucvector_push_back(&text, (unsigned char)keyword[i]); + for(i = 0; keyword[i] != 0; ++i) ucvector_push_back(&text, (uint8_t)keyword[i]); if(i < 1 || i > 79) return 89; /*error: invalid keyword size*/ ucvector_push_back(&text, 0); /*0 termination char*/ - for(i = 0; textstring[i] != 0; ++i) ucvector_push_back(&text, (unsigned char)textstring[i]); + for(i = 0; textstring[i] != 0; ++i) ucvector_push_back(&text, (uint8_t)textstring[i]); error = addChunk(out, "tEXt", text.data, text.size); ucvector_cleanup(&text); @@ -5021,13 +5021,13 @@ static unsigned addChunk_zTXt(ucvector* out, const char* keyword, const char* te ucvector_init(&data); ucvector_init(&compressed); - for(i = 0; keyword[i] != 0; ++i) ucvector_push_back(&data, (unsigned char)keyword[i]); + for(i = 0; keyword[i] != 0; ++i) ucvector_push_back(&data, (uint8_t)keyword[i]); if(i < 1 || i > 79) return 89; /*error: invalid keyword size*/ ucvector_push_back(&data, 0); /*0 termination char*/ ucvector_push_back(&data, 0); /*compression method: 0*/ error = zlib_compress(&compressed.data, &compressed.size, - (const unsigned char*)textstring, textsize, zlibsettings); + (const uint8_t*)textstring, textsize, zlibsettings); if(!error) { for(i = 0; i != compressed.size; ++i) ucvector_push_back(&data, compressed.data[i]); @@ -5048,14 +5048,14 @@ static unsigned addChunk_iTXt(ucvector* out, unsigned compressed, const char* ke ucvector_init(&data); - for(i = 0; keyword[i] != 0; ++i) ucvector_push_back(&data, (unsigned char)keyword[i]); + for(i = 0; keyword[i] != 0; ++i) ucvector_push_back(&data, (uint8_t)keyword[i]); if(i < 1 || i > 79) return 89; /*error: invalid keyword size*/ ucvector_push_back(&data, 0); /*null termination char*/ ucvector_push_back(&data, compressed ? 1 : 0); /*compression flag*/ ucvector_push_back(&data, 0); /*compression method*/ - for(i = 0; langtag[i] != 0; ++i) ucvector_push_back(&data, (unsigned char)langtag[i]); + for(i = 0; langtag[i] != 0; ++i) ucvector_push_back(&data, (uint8_t)langtag[i]); ucvector_push_back(&data, 0); /*null termination char*/ - for(i = 0; transkey[i] != 0; ++i) ucvector_push_back(&data, (unsigned char)transkey[i]); + for(i = 0; transkey[i] != 0; ++i) ucvector_push_back(&data, (uint8_t)transkey[i]); ucvector_push_back(&data, 0); /*null termination char*/ if(compressed) @@ -5063,7 +5063,7 @@ static unsigned addChunk_iTXt(ucvector* out, unsigned compressed, const char* ke ucvector compressed_data; ucvector_init(&compressed_data); error = zlib_compress(&compressed_data.data, &compressed_data.size, - (const unsigned char*)textstring, textsize, zlibsettings); + (const uint8_t*)textstring, textsize, zlibsettings); if(!error) { for(i = 0; i != compressed_data.size; ++i) ucvector_push_back(&data, compressed_data.data[i]); @@ -5072,7 +5072,7 @@ static unsigned addChunk_iTXt(ucvector* out, unsigned compressed, const char* ke } else /*not compressed*/ { - for(i = 0; textstring[i] != 0; ++i) ucvector_push_back(&data, (unsigned char)textstring[i]); + for(i = 0; textstring[i] != 0; ++i) ucvector_push_back(&data, (uint8_t)textstring[i]); } if(!error) error = addChunk(out, "iTXt", data.data, data.size); @@ -5087,21 +5087,21 @@ static unsigned addChunk_bKGD(ucvector* out, const LodePNGInfo* info) ucvector_init(&bKGD); if(info->color.colortype == LCT_GREY || info->color.colortype == LCT_GREY_ALPHA) { - ucvector_push_back(&bKGD, (unsigned char)(info->background_r >> 8)); - ucvector_push_back(&bKGD, (unsigned char)(info->background_r & 255)); + ucvector_push_back(&bKGD, (uint8_t)(info->background_r >> 8)); + ucvector_push_back(&bKGD, (uint8_t)(info->background_r & 255)); } else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_RGBA) { - ucvector_push_back(&bKGD, (unsigned char)(info->background_r >> 8)); - ucvector_push_back(&bKGD, (unsigned char)(info->background_r & 255)); - ucvector_push_back(&bKGD, (unsigned char)(info->background_g >> 8)); - ucvector_push_back(&bKGD, (unsigned char)(info->background_g & 255)); - ucvector_push_back(&bKGD, (unsigned char)(info->background_b >> 8)); - ucvector_push_back(&bKGD, (unsigned char)(info->background_b & 255)); + ucvector_push_back(&bKGD, (uint8_t)(info->background_r >> 8)); + ucvector_push_back(&bKGD, (uint8_t)(info->background_r & 255)); + ucvector_push_back(&bKGD, (uint8_t)(info->background_g >> 8)); + ucvector_push_back(&bKGD, (uint8_t)(info->background_g & 255)); + ucvector_push_back(&bKGD, (uint8_t)(info->background_b >> 8)); + ucvector_push_back(&bKGD, (uint8_t)(info->background_b & 255)); } else if(info->color.colortype == LCT_PALETTE) { - ucvector_push_back(&bKGD, (unsigned char)(info->background_r & 255)); /*palette index*/ + ucvector_push_back(&bKGD, (uint8_t)(info->background_r & 255)); /*palette index*/ } error = addChunk(out, "bKGD", bKGD.data, bKGD.size); @@ -5113,15 +5113,15 @@ static unsigned addChunk_bKGD(ucvector* out, const LodePNGInfo* info) static unsigned addChunk_tIME(ucvector* out, const LodePNGTime* time) { unsigned error = 0; - unsigned char* data = (unsigned char*)lodepng_malloc(7); + uint8_t* data = (uint8_t*)lodepng_malloc(7); if(!data) return 83; /*alloc fail*/ - data[0] = (unsigned char)(time->year >> 8); - data[1] = (unsigned char)(time->year & 255); - data[2] = (unsigned char)time->month; - data[3] = (unsigned char)time->day; - data[4] = (unsigned char)time->hour; - data[5] = (unsigned char)time->minute; - data[6] = (unsigned char)time->second; + data[0] = (uint8_t)(time->year >> 8); + data[1] = (uint8_t)(time->year & 255); + data[2] = (uint8_t)time->month; + data[3] = (uint8_t)time->day; + data[4] = (uint8_t)time->hour; + data[5] = (uint8_t)time->minute; + data[6] = (uint8_t)time->second; error = addChunk(out, "tIME", data, 7); lodepng_free(data); return error; @@ -5145,8 +5145,8 @@ static unsigned addChunk_pHYs(ucvector* out, const LodePNGInfo* info) #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ -static void filterScanline(unsigned char* out, const unsigned char* scanline, const unsigned char* prevline, - size_t length, size_t bytewidth, unsigned char filterType) +static void filterScanline(uint8_t* out, const uint8_t* scanline, const uint8_t* prevline, + size_t length, size_t bytewidth, uint8_t filterType) { size_t i; switch(filterType) @@ -5210,7 +5210,7 @@ static float flog2(float f) return result + 1.442695f * (f * f * f / 3 - 3 * f * f / 2 + 3 * f - 1.83333f); } -static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, +static unsigned filter(uint8_t* out, const uint8_t* in, unsigned w, unsigned h, const LodePNGColorMode* info, const LodePNGEncoderSettings* settings) { /* @@ -5224,7 +5224,7 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w, size_t linebytes = (w * bpp + 7) / 8; /*bytewidth is used for filtering, is 1 when bpp < 8, number of bytes per pixel otherwise*/ size_t bytewidth = (bpp + 7) / 8; - const unsigned char* prevline = 0; + const uint8_t* prevline = 0; unsigned x, y; unsigned error = 0; LodePNGFilterStrategy strategy = settings->filter_strategy; @@ -5262,13 +5262,13 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w, { /*adaptive filtering*/ size_t sum[5]; - unsigned char* attempt[5]; /*five filtering attempts, one for each filter type*/ + uint8_t* attempt[5]; /*five filtering attempts, one for each filter type*/ size_t smallest = 0; - unsigned char type, bestType = 0; + uint8_t type, bestType = 0; for(type = 0; type != 5; ++type) { - attempt[type] = (unsigned char*)lodepng_malloc(linebytes); + attempt[type] = (uint8_t*)lodepng_malloc(linebytes); if(!attempt[type]) return 83; /*alloc fail*/ } @@ -5285,7 +5285,7 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w, sum[type] = 0; if(type == 0) { - for(x = 0; x != linebytes; ++x) sum[type] += (unsigned char)(attempt[type][x]); + for(x = 0; x != linebytes; ++x) sum[type] += (uint8_t)(attempt[type][x]); } else { @@ -5294,7 +5294,7 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w, /*For differences, each byte should be treated as signed, values above 127 are negative (converted to signed char). Filtertype 0 isn't a difference though, so use unsigned there. This means filtertype 0 is almost never chosen, but that is justified.*/ - unsigned char s = attempt[type][x]; + uint8_t s = attempt[type][x]; sum[type] += s < 128 ? s : (255U - s); } } @@ -5320,14 +5320,14 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w, else if(strategy == LFS_ENTROPY) { float sum[5]; - unsigned char* attempt[5]; /*five filtering attempts, one for each filter type*/ + uint8_t* attempt[5]; /*five filtering attempts, one for each filter type*/ float smallest = 0; unsigned type, bestType = 0; unsigned count[256]; for(type = 0; type != 5; ++type) { - attempt[type] = (unsigned char*)lodepng_malloc(linebytes); + attempt[type] = (uint8_t*)lodepng_malloc(linebytes); if(!attempt[type]) return 83; /*alloc fail*/ } @@ -5369,7 +5369,7 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w, { size_t outindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/ size_t inindex = linebytes * y; - unsigned char type = settings->predefined_filters[y]; + uint8_t type = settings->predefined_filters[y]; out[outindex] = type; /*filter type byte*/ filterScanline(&out[outindex + 1], &in[inindex], prevline, linebytes, bytewidth, type); prevline = &in[inindex]; @@ -5381,10 +5381,10 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w, deflate the scanline after every filter attempt to see which one deflates best. This is very slow and gives only slightly smaller, sometimes even larger, result*/ size_t size[5]; - unsigned char* attempt[5]; /*five filtering attempts, one for each filter type*/ + uint8_t* attempt[5]; /*five filtering attempts, one for each filter type*/ size_t smallest = 0; unsigned type = 0, bestType = 0; - unsigned char* dummy; + uint8_t* dummy; LodePNGCompressSettings zlibsettings = settings->zlibsettings; /*use fixed tree on the attempts so that the tree is not adapted to the filtertype on purpose, to simulate the true case where the tree is the same for the whole image. Sometimes it gives @@ -5397,7 +5397,7 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w, zlibsettings.custom_deflate = 0; for(type = 0; type != 5; ++type) { - attempt[type] = (unsigned char*)lodepng_malloc(linebytes); + attempt[type] = (uint8_t*)lodepng_malloc(linebytes); if(!attempt[type]) return 83; /*alloc fail*/ } for(y = 0; y != h; ++y) /*try the 5 filter types*/ @@ -5430,7 +5430,7 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w, return error; } -static void addPaddingBits(unsigned char* out, const unsigned char* in, +static void addPaddingBits(uint8_t* out, const uint8_t* in, size_t olinebits, size_t ilinebits, unsigned h) { /*The opposite of the removePaddingBits function @@ -5443,7 +5443,7 @@ static void addPaddingBits(unsigned char* out, const unsigned char* in, size_t x; for(x = 0; x < ilinebits; ++x) { - unsigned char bit = readBitFromReversedStream(&ibp, in); + uint8_t bit = readBitFromReversedStream(&ibp, in); setBitOfReversedStream(&obp, out, bit); } /*obp += diff; --> no, fill in some value in the padding bits too, to avoid @@ -5463,7 +5463,7 @@ in has the following size in bits: w * h * bpp. out is possibly bigger due to padding bits between reduced images NOTE: comments about padding bits are only relevant if bpp < 8 */ -static void Adam7_interlace(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp) +static void Adam7_interlace(uint8_t* out, const uint8_t* in, unsigned w, unsigned h, unsigned bpp) { unsigned passw[7], passh[7]; size_t filter_passstart[8], padded_passstart[8], passstart[8]; @@ -5504,7 +5504,7 @@ static void Adam7_interlace(unsigned char* out, const unsigned char* in, unsigne obp = (8 * passstart[i]) + (y * ilinebits + x * bpp); for(b = 0; b < bpp; ++b) { - unsigned char bit = readBitFromReversedStream(&ibp, in); + uint8_t bit = readBitFromReversedStream(&ibp, in); setBitOfReversedStream(&obp, out, bit); } } @@ -5514,7 +5514,7 @@ static void Adam7_interlace(unsigned char* out, const unsigned char* in, unsigne /*out must be buffer big enough to contain uncompressed IDAT chunk data, and in must contain the full image. return value is error**/ -static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const unsigned char* in, +static unsigned preProcessScanlines(uint8_t** out, size_t* outsize, const uint8_t* in, unsigned w, unsigned h, const LodePNGInfo* info_png, const LodePNGEncoderSettings* settings) { @@ -5529,7 +5529,7 @@ static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const if(info_png->interlace_method == 0) { *outsize = h + (h * ((w * bpp + 7) / 8)); /*image size plus an extra byte per scanline + possible padding bits*/ - *out = (unsigned char*)lodepng_malloc(*outsize); + *out = (uint8_t*)lodepng_malloc(*outsize); if(!(*out) && (*outsize)) error = 83; /*alloc fail*/ if(!error) @@ -5537,7 +5537,7 @@ static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const /*non multiple of 8 bits per scanline, padding bits needed per scanline*/ if(bpp < 8 && w * bpp != ((w * bpp + 7) / 8) * 8) { - unsigned char* padded = (unsigned char*)lodepng_malloc(h * ((w * bpp + 7) / 8)); + uint8_t* padded = (uint8_t*)lodepng_malloc(h * ((w * bpp + 7) / 8)); if(!padded) error = 83; /*alloc fail*/ if(!error) { @@ -5557,15 +5557,15 @@ static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const { unsigned passw[7], passh[7]; size_t filter_passstart[8], padded_passstart[8], passstart[8]; - unsigned char* adam7; + uint8_t* adam7; Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp); *outsize = filter_passstart[7]; /*image size plus an extra byte per scanline + possible padding bits*/ - *out = (unsigned char*)lodepng_malloc(*outsize); + *out = (uint8_t*)lodepng_malloc(*outsize); if(!(*out)) error = 83; /*alloc fail*/ - adam7 = (unsigned char*)lodepng_malloc(passstart[7]); + adam7 = (uint8_t*)lodepng_malloc(passstart[7]); if(!adam7 && passstart[7]) error = 83; /*alloc fail*/ if(!error) @@ -5577,7 +5577,7 @@ static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const { if(bpp < 8) { - unsigned char* padded = (unsigned char*)lodepng_malloc(padded_passstart[i + 1] - padded_passstart[i]); + uint8_t* padded = (uint8_t*)lodepng_malloc(padded_passstart[i + 1] - padded_passstart[i]); if(!padded) ERROR_BREAK(83); /*alloc fail*/ addPaddingBits(padded, &adam7[passstart[i]], ((passw[i] * bpp + 7) / 8) * 8, passw[i] * bpp, passh[i]); @@ -5607,7 +5607,7 @@ returns 0 if the palette is opaque, returns 1 if the palette has a single color with alpha 0 ==> color key returns 2 if the palette is semi-translucent. */ -static unsigned getPaletteTranslucency(const unsigned char* palette, size_t palettesize) +static unsigned getPaletteTranslucency(const uint8_t* palette, size_t palettesize) { size_t i; unsigned key = 0; @@ -5628,9 +5628,9 @@ static unsigned getPaletteTranslucency(const unsigned char* palette, size_t pale } #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS -static unsigned addUnknownChunks(ucvector* out, unsigned char* data, size_t datasize) +static unsigned addUnknownChunks(ucvector* out, uint8_t* data, size_t datasize) { - unsigned char* inchunk = data; + uint8_t* inchunk = data; while((size_t)(inchunk - data) < datasize) { CERROR_TRY_RETURN(lodepng_chunk_append(&out->data, &out->size, inchunk)); @@ -5641,13 +5641,13 @@ static unsigned addUnknownChunks(ucvector* out, unsigned char* data, size_t data } #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ -unsigned lodepng_encode(unsigned char** out, size_t* outsize, - const unsigned char* image, unsigned w, unsigned h, +unsigned lodepng_encode(uint8_t** out, size_t* outsize, + const uint8_t* image, unsigned w, unsigned h, LodePNGState* state) { LodePNGInfo info; ucvector outv; - unsigned char* data = 0; /*uncompressed version of the IDAT chunk data*/ + uint8_t* data = 0; /*uncompressed version of the IDAT chunk data*/ size_t datasize = 0; /*provide some proper output values if error will happen*/ @@ -5685,10 +5685,10 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize, { if(!lodepng_color_mode_equal(&state->info_raw, &info.color)) { - unsigned char* converted; + uint8_t* converted; size_t size = (w * h * (size_t)lodepng_get_bpp(&info.color) + 7) / 8; - converted = (unsigned char*)lodepng_malloc(size); + converted = (uint8_t*)lodepng_malloc(size); if(!converted && size) state->error = 83; /*alloc fail*/ if(!state->error) { @@ -5840,7 +5840,7 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize, return state->error; } -unsigned lodepng_encode_memory(unsigned char** out, size_t* outsize, const unsigned char* image, +unsigned lodepng_encode_memory(uint8_t** out, size_t* outsize, const uint8_t* image, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { unsigned error; @@ -5856,21 +5856,21 @@ unsigned lodepng_encode_memory(unsigned char** out, size_t* outsize, const unsig return error; } -unsigned lodepng_encode32(unsigned char** out, size_t* outsize, const unsigned char* image, unsigned w, unsigned h) +unsigned lodepng_encode32(uint8_t** out, size_t* outsize, const uint8_t* image, unsigned w, unsigned h) { return lodepng_encode_memory(out, outsize, image, w, h, LCT_RGBA, 8); } -unsigned lodepng_encode24(unsigned char** out, size_t* outsize, const unsigned char* image, unsigned w, unsigned h) +unsigned lodepng_encode24(uint8_t** out, size_t* outsize, const uint8_t* image, unsigned w, unsigned h) { return lodepng_encode_memory(out, outsize, image, w, h, LCT_RGB, 8); } #ifdef LODEPNG_COMPILE_DISK -unsigned lodepng_encode_file(const char* filename, const unsigned char* image, unsigned w, unsigned h, +unsigned lodepng_encode_file(const char* filename, const uint8_t* image, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { - unsigned char* buffer; + uint8_t* buffer; size_t buffersize; unsigned error = lodepng_encode_memory(&buffer, &buffersize, image, w, h, colortype, bitdepth); if(!error) error = lodepng_save_file(buffer, buffersize, filename); @@ -5878,12 +5878,12 @@ unsigned lodepng_encode_file(const char* filename, const unsigned char* image, u return error; } -unsigned lodepng_encode32_file(const char* filename, const unsigned char* image, unsigned w, unsigned h) +unsigned lodepng_encode32_file(const char* filename, const uint8_t* image, unsigned w, unsigned h) { return lodepng_encode_file(filename, image, w, h, LCT_RGBA, 8); } -unsigned lodepng_encode24_file(const char* filename, const unsigned char* image, unsigned w, unsigned h) +unsigned lodepng_encode24_file(const char* filename, const uint8_t* image, unsigned w, unsigned h) { return lodepng_encode_file(filename, image, w, h, LCT_RGB, 8); } @@ -6024,7 +6024,7 @@ namespace lodepng { #ifdef LODEPNG_COMPILE_DISK -unsigned load_file(std::vector& buffer, const std::string& filename) +unsigned load_file(std::vector& buffer, const std::string& filename) { long size = lodepng_filesize(filename.c_str()); if(size < 0) return 78; @@ -6033,7 +6033,7 @@ unsigned load_file(std::vector& buffer, const std::string& filena } /*write given buffer to the file, overwriting the file, it doesn't append to it.*/ -unsigned save_file(const std::vector& buffer, const std::string& filename) +unsigned save_file(const std::vector& buffer, const std::string& filename) { return lodepng_save_file(buffer.empty() ? 0 : &buffer[0], buffer.size(), filename.c_str()); } @@ -6041,10 +6041,10 @@ unsigned save_file(const std::vector& buffer, const std::string& #ifdef LODEPNG_COMPILE_ZLIB #ifdef LODEPNG_COMPILE_DECODER -unsigned decompress(std::vector& out, const unsigned char* in, size_t insize, +unsigned decompress(std::vector& out, const uint8_t* in, size_t insize, const LodePNGDecompressSettings& settings) { - unsigned char* buffer = 0; + uint8_t* buffer = 0; size_t buffersize = 0; unsigned error = zlib_decompress(&buffer, &buffersize, in, insize, &settings); if(buffer) @@ -6055,7 +6055,7 @@ unsigned decompress(std::vector& out, const unsigned char* in, si return error; } -unsigned decompress(std::vector& out, const std::vector& in, +unsigned decompress(std::vector& out, const std::vector& in, const LodePNGDecompressSettings& settings) { return decompress(out, in.empty() ? 0 : &in[0], in.size(), settings); @@ -6063,10 +6063,10 @@ unsigned decompress(std::vector& out, const std::vector& out, const unsigned char* in, size_t insize, +unsigned compress(std::vector& out, const uint8_t* in, size_t insize, const LodePNGCompressSettings& settings) { - unsigned char* buffer = 0; + uint8_t* buffer = 0; size_t buffersize = 0; unsigned error = zlib_compress(&buffer, &buffersize, in, insize, &settings); if(buffer) @@ -6077,7 +6077,7 @@ unsigned compress(std::vector& out, const unsigned char* in, size return error; } -unsigned compress(std::vector& out, const std::vector& in, +unsigned compress(std::vector& out, const std::vector& in, const LodePNGCompressSettings& settings) { return compress(out, in.empty() ? 0 : &in[0], in.size(), settings); @@ -6112,10 +6112,10 @@ State& State::operator=(const State& other) #ifdef LODEPNG_COMPILE_DECODER -unsigned decode(std::vector& out, unsigned& w, unsigned& h, const unsigned char* in, +unsigned decode(std::vector& out, unsigned& w, unsigned& h, const uint8_t* in, size_t insize, LodePNGColorType colortype, unsigned bitdepth) { - unsigned char* buffer; + uint8_t* buffer; unsigned error = lodepng_decode_memory(&buffer, &w, &h, in, insize, colortype, bitdepth); if(buffer && !error) { @@ -6129,17 +6129,17 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h, const return error; } -unsigned decode(std::vector& out, unsigned& w, unsigned& h, - const std::vector& in, LodePNGColorType colortype, unsigned bitdepth) +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + const std::vector& in, LodePNGColorType colortype, unsigned bitdepth) { return decode(out, w, h, in.empty() ? 0 : &in[0], (unsigned)in.size(), colortype, bitdepth); } -unsigned decode(std::vector& out, unsigned& w, unsigned& h, +unsigned decode(std::vector& out, unsigned& w, unsigned& h, State& state, - const unsigned char* in, size_t insize) + const uint8_t* in, size_t insize) { - unsigned char* buffer = NULL; + uint8_t* buffer = NULL; unsigned error = lodepng_decode(&buffer, &w, &h, &state, in, insize); if(buffer && !error) { @@ -6150,18 +6150,18 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h, return error; } -unsigned decode(std::vector& out, unsigned& w, unsigned& h, +unsigned decode(std::vector& out, unsigned& w, unsigned& h, State& state, - const std::vector& in) + const std::vector& in) { return decode(out, w, h, state, in.empty() ? 0 : &in[0], in.size()); } #ifdef LODEPNG_COMPILE_DISK -unsigned decode(std::vector& out, unsigned& w, unsigned& h, const std::string& filename, +unsigned decode(std::vector& out, unsigned& w, unsigned& h, const std::string& filename, LodePNGColorType colortype, unsigned bitdepth) { - std::vector buffer; + std::vector buffer; unsigned error = load_file(buffer, filename); if(error) return error; return decode(out, w, h, buffer, colortype, bitdepth); @@ -6178,10 +6178,10 @@ static size_t lodepng_get_raw_size_lct(unsigned w, unsigned h, LodePNGColorType return ((n / 8) * bpp) + ((n & 7) * bpp + 7) / 8; } -unsigned encode(std::vector& out, const unsigned char* in, unsigned w, unsigned h, +unsigned encode(std::vector& out, const uint8_t* in, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { - unsigned char* buffer; + uint8_t* buffer; size_t buffersize; unsigned error = lodepng_encode_memory(&buffer, &buffersize, in, w, h, colortype, bitdepth); if(buffer) @@ -6192,19 +6192,19 @@ unsigned encode(std::vector& out, const unsigned char* in, unsign return error; } -unsigned encode(std::vector& out, - const std::vector& in, unsigned w, unsigned h, +unsigned encode(std::vector& out, + const std::vector& in, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { if(lodepng_get_raw_size_lct(w, h, colortype, bitdepth) > in.size()) return 84; return encode(out, in.empty() ? 0 : &in[0], w, h, colortype, bitdepth); } -unsigned encode(std::vector& out, - const unsigned char* in, unsigned w, unsigned h, +unsigned encode(std::vector& out, + const uint8_t* in, unsigned w, unsigned h, State& state) { - unsigned char* buffer; + uint8_t* buffer; size_t buffersize; unsigned error = lodepng_encode(&buffer, &buffersize, in, w, h, &state); if(buffer) @@ -6215,8 +6215,8 @@ unsigned encode(std::vector& out, return error; } -unsigned encode(std::vector& out, - const std::vector& in, unsigned w, unsigned h, +unsigned encode(std::vector& out, + const std::vector& in, unsigned w, unsigned h, State& state) { if(lodepng_get_raw_size(w, h, &state.info_raw) > in.size()) return 84; @@ -6225,17 +6225,17 @@ unsigned encode(std::vector& out, #ifdef LODEPNG_COMPILE_DISK unsigned encode(const std::string& filename, - const unsigned char* in, unsigned w, unsigned h, + const uint8_t* in, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { - std::vector buffer; + std::vector buffer; unsigned error = encode(buffer, in, w, h, colortype, bitdepth); if(!error) error = save_file(buffer, filename); return error; } unsigned encode(const std::string& filename, - const std::vector& in, unsigned w, unsigned h, + const std::vector& in, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { if(lodepng_get_raw_size_lct(w, h, colortype, bitdepth) > in.size()) return 84; diff --git a/source/lodepng.h b/source/lodepng.h index b8e6c78..ebbc591 100644 --- a/source/lodepng.h +++ b/source/lodepng.h @@ -113,33 +113,33 @@ colortype: the desired color type for the raw output image. See explanation on P bitdepth: the desired bit depth for the raw output image. See explanation on PNG color types. Return value: LodePNG error code (0 means no error). */ -unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, - const unsigned char* in, size_t insize, +unsigned lodepng_decode_memory(uint8_t** out, unsigned* w, unsigned* h, + const uint8_t* in, size_t insize, LodePNGColorType colortype, unsigned bitdepth); /*Same as lodepng_decode_memory, but always decodes to 32-bit RGBA raw image*/ -unsigned lodepng_decode32(unsigned char** out, unsigned* w, unsigned* h, - const unsigned char* in, size_t insize); +unsigned lodepng_decode32(uint8_t** out, unsigned* w, unsigned* h, + const uint8_t* in, size_t insize); /*Same as lodepng_decode_memory, but always decodes to 24-bit RGB raw image*/ -unsigned lodepng_decode24(unsigned char** out, unsigned* w, unsigned* h, - const unsigned char* in, size_t insize); +unsigned lodepng_decode24(uint8_t** out, unsigned* w, unsigned* h, + const uint8_t* in, size_t insize); #ifdef LODEPNG_COMPILE_DISK /* Load PNG from disk, from file with given name. Same as the other decode functions, but instead takes a filename as input. */ -unsigned lodepng_decode_file(unsigned char** out, unsigned* w, unsigned* h, +unsigned lodepng_decode_file(uint8_t** out, unsigned* w, unsigned* h, const char* filename, LodePNGColorType colortype, unsigned bitdepth); /*Same as lodepng_decode_file, but always decodes to 32-bit RGBA raw image.*/ -unsigned lodepng_decode32_file(unsigned char** out, unsigned* w, unsigned* h, +unsigned lodepng_decode32_file(uint8_t** out, unsigned* w, unsigned* h, const char* filename); /*Same as lodepng_decode_file, but always decodes to 24-bit RGB raw image.*/ -unsigned lodepng_decode24_file(unsigned char** out, unsigned* w, unsigned* h, +unsigned lodepng_decode24_file(uint8_t** out, unsigned* w, unsigned* h, const char* filename); #endif /*LODEPNG_COMPILE_DISK*/ #endif /*LODEPNG_COMPILE_DECODER*/ @@ -162,17 +162,17 @@ colortype: the color type of the raw input image. See explanation on PNG color t bitdepth: the bit depth of the raw input image. See explanation on PNG color types. Return value: LodePNG error code (0 means no error). */ -unsigned lodepng_encode_memory(unsigned char** out, size_t* outsize, - const unsigned char* image, unsigned w, unsigned h, +unsigned lodepng_encode_memory(uint8_t** out, size_t* outsize, + const uint8_t* image, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth); /*Same as lodepng_encode_memory, but always encodes from 32-bit RGBA raw image.*/ -unsigned lodepng_encode32(unsigned char** out, size_t* outsize, - const unsigned char* image, unsigned w, unsigned h); +unsigned lodepng_encode32(uint8_t** out, size_t* outsize, + const uint8_t* image, unsigned w, unsigned h); /*Same as lodepng_encode_memory, but always encodes from 24-bit RGB raw image.*/ -unsigned lodepng_encode24(unsigned char** out, size_t* outsize, - const unsigned char* image, unsigned w, unsigned h); +unsigned lodepng_encode24(uint8_t** out, size_t* outsize, + const uint8_t* image, unsigned w, unsigned h); #ifdef LODEPNG_COMPILE_DISK /* @@ -181,16 +181,16 @@ Same as the other encode functions, but instead takes a filename as output. NOTE: This overwrites existing files without warning! */ unsigned lodepng_encode_file(const char* filename, - const unsigned char* image, unsigned w, unsigned h, + const uint8_t* image, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth); /*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image.*/ unsigned lodepng_encode32_file(const char* filename, - const unsigned char* image, unsigned w, unsigned h); + const uint8_t* image, unsigned w, unsigned h); /*Same as lodepng_encode_file, but always encodes from 24-bit RGB raw image.*/ unsigned lodepng_encode24_file(const char* filename, - const unsigned char* image, unsigned w, unsigned h); + const uint8_t* image, unsigned w, unsigned h); #endif /*LODEPNG_COMPILE_DISK*/ #endif /*LODEPNG_COMPILE_ENCODER*/ @@ -201,18 +201,18 @@ namespace lodepng #ifdef LODEPNG_COMPILE_DECODER /*Same as lodepng_decode_memory, but decodes to an std::vector. The colortype is the format to output the pixels to. Default is RGBA 8-bit per channel.*/ -unsigned decode(std::vector& out, unsigned& w, unsigned& h, - const unsigned char* in, size_t insize, +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + const uint8_t* in, size_t insize, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); -unsigned decode(std::vector& out, unsigned& w, unsigned& h, - const std::vector& in, +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + const std::vector& in, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); #ifdef LODEPNG_COMPILE_DISK /* Converts PNG file from disk to raw pixel data in memory. Same as the other decode functions, but instead takes a filename as input. */ -unsigned decode(std::vector& out, unsigned& w, unsigned& h, +unsigned decode(std::vector& out, unsigned& w, unsigned& h, const std::string& filename, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); #endif /* LODEPNG_COMPILE_DISK */ @@ -221,11 +221,11 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h, #ifdef LODEPNG_COMPILE_ENCODER /*Same as lodepng_encode_memory, but encodes to an std::vector. colortype is that of the raw input data. The output PNG color type will be auto chosen.*/ -unsigned encode(std::vector& out, - const unsigned char* in, unsigned w, unsigned h, +unsigned encode(std::vector& out, + const uint8_t* in, unsigned w, unsigned h, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); -unsigned encode(std::vector& out, - const std::vector& in, unsigned w, unsigned h, +unsigned encode(std::vector& out, + const std::vector& in, unsigned w, unsigned h, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); #ifdef LODEPNG_COMPILE_DISK /* @@ -234,10 +234,10 @@ Same as the other encode functions, but instead takes a filename as output. NOTE: This overwrites existing files without warning! */ unsigned encode(const std::string& filename, - const unsigned char* in, unsigned w, unsigned h, + const uint8_t* in, unsigned w, unsigned h, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); unsigned encode(const std::string& filename, - const std::vector& in, unsigned w, unsigned h, + const std::vector& in, unsigned w, unsigned h, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); #endif /* LODEPNG_COMPILE_DISK */ #endif /* LODEPNG_COMPILE_ENCODER */ @@ -259,14 +259,14 @@ struct LodePNGDecompressSettings unsigned ignore_adler32; /*if 1, continue and don't give an error message if the Adler32 checksum is corrupted*/ /*use custom zlib decoder instead of built in one (default: null)*/ - unsigned (*custom_zlib)(unsigned char**, size_t*, - const unsigned char*, size_t, + unsigned (*custom_zlib)(uint8_t**, size_t*, + const uint8_t*, size_t, const LodePNGDecompressSettings*); /*use custom deflate decoder instead of built in one (default: null) if custom_zlib is used, custom_deflate is ignored since only the built in zlib function will call custom_deflate*/ - unsigned (*custom_inflate)(unsigned char**, size_t*, - const unsigned char*, size_t, + unsigned (*custom_inflate)(uint8_t**, size_t*, + const uint8_t*, size_t, const LodePNGDecompressSettings*); const void* custom_context; /*optional custom settings for custom functions*/ @@ -293,14 +293,14 @@ struct LodePNGCompressSettings /*deflate = compress*/ unsigned lazymatching; /*use lazy matching: better compression but a bit slower. Default: true*/ /*use custom zlib encoder instead of built in one (default: null)*/ - unsigned (*custom_zlib)(unsigned char**, size_t*, - const unsigned char*, size_t, + unsigned (*custom_zlib)(uint8_t**, size_t*, + const uint8_t*, size_t, const LodePNGCompressSettings*); /*use custom deflate encoder instead of built in one (default: null) if custom_zlib is used, custom_deflate is ignored since only the built in zlib function will call custom_deflate*/ - unsigned (*custom_deflate)(unsigned char**, size_t*, - const unsigned char*, size_t, + unsigned (*custom_deflate)(uint8_t**, size_t*, + const uint8_t*, size_t, const LodePNGCompressSettings*); const void* custom_context; /*optional custom settings for custom functions*/ @@ -335,7 +335,7 @@ typedef struct LodePNGColorMode The palette is only supported for color type 3. */ - unsigned char* palette; /*palette in RGBARGBA... order. When allocated, must be either 0, or have size 1024*/ + uint8_t* palette; /*palette in RGBARGBA... order. When allocated, must be either 0, or have size 1024*/ size_t palettesize; /*palette size in number of colors (amount of bytes is 4 * palettesize)*/ /* @@ -364,7 +364,7 @@ unsigned lodepng_color_mode_copy(LodePNGColorMode* dest, const LodePNGColorMode* void lodepng_palette_clear(LodePNGColorMode* info); /*add 1 color to the palette*/ unsigned lodepng_palette_add(LodePNGColorMode* info, - unsigned char r, unsigned char g, unsigned char b, unsigned char a); + uint8_t r, uint8_t g, uint8_t b, uint8_t a); /*get the total amount of bits per pixel, based on colortype and bitdepth in the struct*/ unsigned lodepng_get_bpp(const LodePNGColorMode* info); @@ -477,7 +477,7 @@ typedef struct LodePNGInfo Do not allocate or traverse this data yourself. Use the chunk traversing functions declared later, such as lodepng_chunk_next and lodepng_chunk_append, to read/write this struct. */ - unsigned char* unknown_chunks_data[3]; + uint8_t* unknown_chunks_data[3]; size_t unknown_chunks_size[3]; /*size in bytes of the unknown chunks, given for protection*/ #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ } LodePNGInfo; @@ -508,7 +508,7 @@ For < 8 bpp images, there should not be padding bits at the end of scanlines. For 16-bit per channel colors, uses big endian format like PNG does. Return value is LodePNG error code */ -unsigned lodepng_convert(unsigned char* out, const unsigned char* in, +unsigned lodepng_convert(uint8_t* out, const uint8_t* in, const LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in, unsigned w, unsigned h); @@ -569,7 +569,7 @@ typedef struct LodePNGColorProfile uint16_t key_b; unsigned alpha; /*image is not opaque and alpha channel or alpha palette required*/ unsigned numcolors; /*amount of colors, up to 257. Not valid if bits == 16.*/ - unsigned char palette[1024]; /*Remembers up to the first 256 RGBA colors, in no particular order*/ + uint8_t palette[1024]; /*Remembers up to the first 256 RGBA colors, in no particular order*/ unsigned bits; /*bits per channel (not for palette). 1,2 or 4 for greyscale only. 16 if 16-bit per channel required.*/ } LodePNGColorProfile; @@ -577,12 +577,12 @@ void lodepng_color_profile_init(LodePNGColorProfile* profile); /*Get a LodePNGColorProfile of the image.*/ unsigned lodepng_get_color_profile(LodePNGColorProfile* profile, - const unsigned char* image, unsigned w, unsigned h, + const uint8_t* image, unsigned w, unsigned h, const LodePNGColorMode* mode_in); /*The function LodePNG uses internally to decide the PNG color with auto_convert. Chooses an optimal color model, e.g. grey if only grey pixels, palette if < 256 colors, ...*/ unsigned lodepng_auto_choose_color(LodePNGColorMode* mode_out, - const unsigned char* image, unsigned w, unsigned h, + const uint8_t* image, unsigned w, unsigned h, const LodePNGColorMode* mode_in); /*Settings for the encoder.*/ @@ -604,7 +604,7 @@ typedef struct LodePNGEncoderSettings the same length as the amount of scanlines in the image, and each value must <= 5. You have to cleanup this buffer, LodePNG will never free it. Don't forget that filter_palette_zero must be set to 0 to ensure this is also used on palette or low bitdepth images.*/ - const unsigned char* predefined_filters; + const uint8_t* predefined_filters; /*force creating a PLTE chunk if colortype is 2 or 6 (= a suggested palette). If colortype is 3, PLTE is _always_ created.*/ @@ -651,9 +651,9 @@ void lodepng_state_copy(LodePNGState* dest, const LodePNGState* source); Same as lodepng_decode_memory, but uses a LodePNGState to allow custom settings and getting much more information about the PNG image and color mode. */ -unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h, +unsigned lodepng_decode(uint8_t** out, unsigned* w, unsigned* h, LodePNGState* state, - const unsigned char* in, size_t insize); + const uint8_t* in, size_t insize); /* Read the PNG header, but not the actual data. This returns only the information @@ -662,14 +662,14 @@ information is placed in the info_png field of the LodePNGState. */ unsigned lodepng_inspect(unsigned* w, unsigned* h, LodePNGState* state, - const unsigned char* in, size_t insize); + const uint8_t* in, size_t insize); #endif /*LODEPNG_COMPILE_DECODER*/ #ifdef LODEPNG_COMPILE_ENCODER /*This function allocates the out buffer with standard malloc and stores the size in *outsize.*/ -unsigned lodepng_encode(unsigned char** out, size_t* outsize, - const unsigned char* image, unsigned w, unsigned h, +unsigned lodepng_encode(uint8_t** out, size_t* outsize, + const uint8_t* image, unsigned w, unsigned h, LodePNGState* state); #endif /*LODEPNG_COMPILE_ENCODER*/ @@ -690,43 +690,43 @@ Gets the length of the data of the chunk. Total chunk length has 12 bytes more. There must be at least 4 bytes to read from. If the result value is too large, it may be corrupt data. */ -unsigned lodepng_chunk_length(const unsigned char* chunk); +unsigned lodepng_chunk_length(const uint8_t* chunk); /*puts the 4-byte type in null terminated string*/ -void lodepng_chunk_type(char type[5], const unsigned char* chunk); +void lodepng_chunk_type(char type[5], const uint8_t* chunk); /*check if the type is the given type*/ -unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type); +uint8_t lodepng_chunk_type_equals(const uint8_t* chunk, const char* type); /*0: it's one of the critical chunk types, 1: it's an ancillary chunk (see PNG standard)*/ -unsigned char lodepng_chunk_ancillary(const unsigned char* chunk); +uint8_t lodepng_chunk_ancillary(const uint8_t* chunk); /*0: public, 1: private (see PNG standard)*/ -unsigned char lodepng_chunk_private(const unsigned char* chunk); +uint8_t lodepng_chunk_private(const uint8_t* chunk); /*0: the chunk is unsafe to copy, 1: the chunk is safe to copy (see PNG standard)*/ -unsigned char lodepng_chunk_safetocopy(const unsigned char* chunk); +uint8_t lodepng_chunk_safetocopy(const uint8_t* chunk); /*get pointer to the data of the chunk, where the input points to the header of the chunk*/ -unsigned char* lodepng_chunk_data(unsigned char* chunk); -const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk); +uint8_t* lodepng_chunk_data(uint8_t* chunk); +const uint8_t* lodepng_chunk_data_const(const uint8_t* chunk); /*returns 0 if the crc is correct, 1 if it's incorrect (0 for OK as usual!)*/ -unsigned lodepng_chunk_check_crc(const unsigned char* chunk); +unsigned lodepng_chunk_check_crc(const uint8_t* chunk); /*generates the correct CRC from the data and puts it in the last 4 bytes of the chunk*/ -void lodepng_chunk_generate_crc(unsigned char* chunk); +void lodepng_chunk_generate_crc(uint8_t* chunk); /*iterate to next chunks. don't use on IEND chunk, as there is no next chunk then*/ -unsigned char* lodepng_chunk_next(unsigned char* chunk); -const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk); +uint8_t* lodepng_chunk_next(uint8_t* chunk); +const uint8_t* lodepng_chunk_next_const(const uint8_t* chunk); /* Appends chunk to the data in out. The given chunk should already have its chunk header. The out variable and outlength are updated to reflect the new reallocated buffer. Returns error code (0 if it went ok) */ -unsigned lodepng_chunk_append(unsigned char** out, size_t* outlength, const unsigned char* chunk); +unsigned lodepng_chunk_append(uint8_t** out, size_t* outlength, const uint8_t* chunk); /* Appends new chunk to out. The chunk to append is given by giving its length, type @@ -734,12 +734,12 @@ and data separately. The type is a 4-letter string. The out variable and outlength are updated to reflect the new reallocated buffer. Returne error code (0 if it went ok) */ -unsigned lodepng_chunk_create(unsigned char** out, size_t* outlength, unsigned length, - const char* type, const unsigned char* data); +unsigned lodepng_chunk_create(uint8_t** out, size_t* outlength, unsigned length, + const char* type, const uint8_t* data); /*Calculate CRC32 of buffer*/ -unsigned lodepng_crc32(const unsigned char* buf, size_t len); +unsigned lodepng_crc32(const uint8_t* buf, size_t len); #endif /*LODEPNG_COMPILE_PNG*/ @@ -752,8 +752,8 @@ part of zlib that is required for PNG, it does not support dictionaries. #ifdef LODEPNG_COMPILE_DECODER /*Inflate a buffer. Inflate is the decompression step of deflate. Out buffer must be freed after use.*/ -unsigned lodepng_inflate(unsigned char** out, size_t* outsize, - const unsigned char* in, size_t insize, +unsigned lodepng_inflate(uint8_t** out, size_t* outsize, + const uint8_t* in, size_t insize, const LodePNGDecompressSettings* settings); /* @@ -762,8 +762,8 @@ data must be according to the zlib specification. Either, *out must be NULL and *outsize must be 0, or, *out must be a valid buffer and *outsize its size in bytes. out must be freed by user after usage. */ -unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, - const unsigned char* in, size_t insize, +unsigned lodepng_zlib_decompress(uint8_t** out, size_t* outsize, + const uint8_t* in, size_t insize, const LodePNGDecompressSettings* settings); #endif /*LODEPNG_COMPILE_DECODER*/ @@ -775,8 +775,8 @@ The data is output in the format of the zlib specification. Either, *out must be NULL and *outsize must be 0, or, *out must be a valid buffer and *outsize its size in bytes. out must be freed by user after usage. */ -unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, - const unsigned char* in, size_t insize, +unsigned lodepng_zlib_compress(uint8_t** out, size_t* outsize, + const uint8_t* in, size_t insize, const LodePNGCompressSettings* settings); /* @@ -787,8 +787,8 @@ unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequen size_t numcodes, unsigned maxbitlen); /*Compress a buffer with deflate. See RFC 1951. Out buffer must be freed after use.*/ -unsigned lodepng_deflate(unsigned char** out, size_t* outsize, - const unsigned char* in, size_t insize, +unsigned lodepng_deflate(uint8_t** out, size_t* outsize, + const uint8_t* in, size_t insize, const LodePNGCompressSettings* settings); #endif /*LODEPNG_COMPILE_ENCODER*/ @@ -803,7 +803,7 @@ outsize: output parameter, size of the allocated out buffer filename: the path to the file to load return value: error code (0 means ok) */ -unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename); +unsigned lodepng_load_file(uint8_t** out, size_t* outsize, const char* filename); /* Save a file from buffer to disk. Warning, if it exists, this function overwrites @@ -813,7 +813,7 @@ buffersize: size of the buffer to write filename: the path to the file to save to return value: error code (0 means ok) */ -unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename); +unsigned lodepng_save_file(const uint8_t* buffer, size_t buffersize, const char* filename); #endif /*LODEPNG_COMPILE_DISK*/ #ifdef LODEPNG_COMPILE_CPP @@ -832,21 +832,21 @@ class State : public LodePNGState #ifdef LODEPNG_COMPILE_DECODER /* Same as other lodepng::decode, but using a State for more settings and information. */ -unsigned decode(std::vector& out, unsigned& w, unsigned& h, +unsigned decode(std::vector& out, unsigned& w, unsigned& h, State& state, - const unsigned char* in, size_t insize); -unsigned decode(std::vector& out, unsigned& w, unsigned& h, + const uint8_t* in, size_t insize); +unsigned decode(std::vector& out, unsigned& w, unsigned& h, State& state, - const std::vector& in); + const std::vector& in); #endif /*LODEPNG_COMPILE_DECODER*/ #ifdef LODEPNG_COMPILE_ENCODER /* Same as other lodepng::encode, but using a State for more settings and information. */ -unsigned encode(std::vector& out, - const unsigned char* in, unsigned w, unsigned h, +unsigned encode(std::vector& out, + const uint8_t* in, unsigned w, unsigned h, State& state); -unsigned encode(std::vector& out, - const std::vector& in, unsigned w, unsigned h, +unsigned encode(std::vector& out, + const std::vector& in, unsigned w, unsigned h, State& state); #endif /*LODEPNG_COMPILE_ENCODER*/ @@ -855,34 +855,34 @@ unsigned encode(std::vector& out, Load a file from disk into an std::vector. return value: error code (0 means ok) */ -unsigned load_file(std::vector& buffer, const std::string& filename); +unsigned load_file(std::vector& buffer, const std::string& filename); /* Save the binary data in an std::vector to a file on disk. The file is overwritten without warning. */ -unsigned save_file(const std::vector& buffer, const std::string& filename); +unsigned save_file(const std::vector& buffer, const std::string& filename); #endif /* LODEPNG_COMPILE_DISK */ #endif /* LODEPNG_COMPILE_PNG */ #ifdef LODEPNG_COMPILE_ZLIB #ifdef LODEPNG_COMPILE_DECODER -/* Zlib-decompress an unsigned char buffer */ -unsigned decompress(std::vector& out, const unsigned char* in, size_t insize, +/* Zlib-decompress an uint8_t buffer */ +unsigned decompress(std::vector& out, const uint8_t* in, size_t insize, const LodePNGDecompressSettings& settings = lodepng_default_decompress_settings); /* Zlib-decompress an std::vector */ -unsigned decompress(std::vector& out, const std::vector& in, +unsigned decompress(std::vector& out, const std::vector& in, const LodePNGDecompressSettings& settings = lodepng_default_decompress_settings); #endif /* LODEPNG_COMPILE_DECODER */ #ifdef LODEPNG_COMPILE_ENCODER -/* Zlib-compress an unsigned char buffer */ -unsigned compress(std::vector& out, const unsigned char* in, size_t insize, +/* Zlib-compress an uint8_t buffer */ +unsigned compress(std::vector& out, const uint8_t* in, size_t insize, const LodePNGCompressSettings& settings = lodepng_default_compress_settings); /* Zlib-compress an std::vector */ -unsigned compress(std::vector& out, const std::vector& in, +unsigned compress(std::vector& out, const std::vector& in, const LodePNGCompressSettings& settings = lodepng_default_compress_settings); #endif /* LODEPNG_COMPILE_ENCODER */ #endif /* LODEPNG_COMPILE_ZLIB */ @@ -1315,7 +1315,7 @@ not the first bit of a new byte. 6.4. A note about 16-bits per channel and endianness ---------------------------------------------------- -LodePNG uses unsigned char arrays for 16-bit per channel colors too, just like +LodePNG uses uint8_t arrays for 16-bit per channel colors too, just like for any other color format. The 16-bit values are stored in big endian (most significant byte first) in these arrays. This is the opposite order of the little endian used by x86 CPU's. @@ -1329,7 +1329,7 @@ converting to/from all that is outside the scope of LodePNG. This may mean that, depending on your use case, you may want to convert the big endian output of LodePNG to little endian with a for loop. This is certainly not always needed, many applications and libraries support big endian 16-bit colors -anyway, but it means you cannot simply cast the unsigned char* buffer to an +anyway, but it means you cannot simply cast the uint8_t* buffer to an uint16_t* buffer on x86 CPUs. @@ -1374,18 +1374,18 @@ exploits, always make sure the buffer contains all the data of the chunks. When using lodepng_chunk_next, make sure the returned value is within the allocated memory. -unsigned lodepng_chunk_length(const unsigned char* chunk): +unsigned lodepng_chunk_length(const uint8_t* chunk): Get the length of the chunk's data. The total chunk length is this length + 12. -void lodepng_chunk_type(char type[5], const unsigned char* chunk): -unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type): +void lodepng_chunk_type(char type[5], const uint8_t* chunk): +uint8_t lodepng_chunk_type_equals(const uint8_t* chunk, const char* type): Get the type of the chunk or compare if it's a certain type -unsigned char lodepng_chunk_critical(const unsigned char* chunk): -unsigned char lodepng_chunk_private(const unsigned char* chunk): -unsigned char lodepng_chunk_safetocopy(const unsigned char* chunk): +uint8_t lodepng_chunk_critical(const uint8_t* chunk): +uint8_t lodepng_chunk_private(const uint8_t* chunk): +uint8_t lodepng_chunk_safetocopy(const uint8_t* chunk): Check if the chunk is critical in the PNG standard (only IHDR, PLTE, IDAT and IEND are). Check if the chunk is private (public chunks are part of the standard, private ones not). @@ -1393,26 +1393,26 @@ Check if the chunk is safe to copy. If it's not, then, when modifying data in a chunk, unsafe to copy chunks of the old image may NOT be saved in the new one if your program doesn't handle that type of unknown chunk. -unsigned char* lodepng_chunk_data(unsigned char* chunk): -const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk): +uint8_t* lodepng_chunk_data(uint8_t* chunk): +const uint8_t* lodepng_chunk_data_const(const uint8_t* chunk): Get a pointer to the start of the data of the chunk. -unsigned lodepng_chunk_check_crc(const unsigned char* chunk): -void lodepng_chunk_generate_crc(unsigned char* chunk): +unsigned lodepng_chunk_check_crc(const uint8_t* chunk): +void lodepng_chunk_generate_crc(uint8_t* chunk): Check if the crc is correct or generate a correct one. -unsigned char* lodepng_chunk_next(unsigned char* chunk): -const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk): +uint8_t* lodepng_chunk_next(uint8_t* chunk): +const uint8_t* lodepng_chunk_next_const(const uint8_t* chunk): Iterate to the next chunk. This works if you have a buffer with consecutive chunks. Note that these functions do no boundary checking of the allocated data whatsoever, so make sure there is enough data available in the buffer to be able to go to the next chunk. -unsigned lodepng_chunk_append(unsigned char** out, size_t* outlength, const unsigned char* chunk): -unsigned lodepng_chunk_create(unsigned char** out, size_t* outlength, unsigned length, - const char* type, const unsigned char* data): +unsigned lodepng_chunk_append(uint8_t** out, size_t* outlength, const uint8_t* chunk): +unsigned lodepng_chunk_create(uint8_t** out, size_t* outlength, unsigned length, + const char* type, const uint8_t* data): These functions are used to create new chunks that are appended to the data in *out that has length *outlength. The append function appends an existing chunk to the new data. The create @@ -1529,7 +1529,7 @@ int main(int argc, char *argv[]) const char* filename = argc > 1 ? argv[1] : "test.png"; //load and decode - std::vector image; + std::vector image; unsigned width, height; unsigned error = lodepng::decode(image, width, height, filename); @@ -1547,7 +1547,7 @@ int main(int argc, char *argv[]) int main(int argc, char *argv[]) { unsigned error; - unsigned char* image; + uint8_t* image; size_t width, height; const char* filename = argc > 1 ? argv[1] : "test.png"; diff --git a/source/net_defs.h b/source/net_defs.h index 30a5f31..27a4895 100644 --- a/source/net_defs.h +++ b/source/net_defs.h @@ -27,12 +27,12 @@ struct qsockaddr { #if defined(HAVE_SA_LEN) - unsigned char qsa_len; - unsigned char qsa_family; + uint8_t qsa_len; + uint8_t qsa_family; #else int16_t qsa_family; #endif /* BSD, sockaddr */ - unsigned char qsa_data[14]; + uint8_t qsa_data[14]; }; #define NET_HEADERSIZE (2 * sizeof(uint32_t)) diff --git a/source/net_sys.h b/source/net_sys.h index a0696b0..8f3bd21 100644 --- a/source/net_sys.h +++ b/source/net_sys.h @@ -32,8 +32,8 @@ #if defined(PLATFORM_BSD) || defined(PLATFORM_OSX) || \ defined(PLATFORM_AMIGA) /* bsdsocket.library */ || \ defined(__GNU__) /* GNU/Hurd */ || defined(__riscos__) -/* struct sockaddr has unsigned char sa_len as the first member in BSD - * variants and the family member is also an unsigned char instead of an +/* struct sockaddr has uint8_t sa_len as the first member in BSD + * variants and the family member is also an uint8_t instead of an * uint16_t. This should matter only when PLATFORM_UNIX is defined, * however, checking for the offset of sa_family in every platform that * provide a struct sockaddr doesn't hurt either (see down below for the diff --git a/source/progs.h b/source/progs.h index f434d59..24e51e9 100644 --- a/source/progs.h +++ b/source/progs.h @@ -46,7 +46,7 @@ typedef struct edict_s int leafnums[MAX_ENT_LEAFS]; entity_state_t baseline; - unsigned char alpha; /* johnfitz -- hack to support alpha since it's not part of entvars_t */ + uint8_t alpha; /* johnfitz -- hack to support alpha since it's not part of entvars_t */ qboolean sendinterval; /* johnfitz -- send time until nextthink to client for better lerp timing */ float freetime; /* sv.time when the object was freed */ diff --git a/source/protocol.h b/source/protocol.h index 8effd0a..7a4fc64 100644 --- a/source/protocol.h +++ b/source/protocol.h @@ -237,9 +237,9 @@ typedef struct vec3_t angles; uint16_t modelindex; //johnfitz -- was int uint16_t frame; //johnfitz -- was int - unsigned char colormap; //johnfitz -- was int - unsigned char skin; //johnfitz -- was int - unsigned char alpha; //johnfitz -- added + uint8_t colormap; //johnfitz -- was int + uint8_t skin; //johnfitz -- was int + uint8_t alpha; //johnfitz -- added int effects; } entity_state_t; diff --git a/source/q_sound.h b/source/q_sound.h index ded7b5d..aab8599 100644 --- a/source/q_sound.h +++ b/source/q_sound.h @@ -58,7 +58,7 @@ typedef struct int samplebits; int signed8; /* device opened for S8 format? (e.g. Amiga AHI) */ int speed; - unsigned char *buffer; + uint8_t *buffer; } dma_t; /* !!! if this is changed, it must be changed in asm_i386.h too !!! */ diff --git a/source/q_stdinc.h b/source/q_stdinc.h index 5ccbee6..057a5e6 100644 --- a/source/q_stdinc.h +++ b/source/q_stdinc.h @@ -83,7 +83,7 @@ _Static_assert(sizeof(THE_DUMMY_ENUM) == sizeof(int), "enum not sizeof(int)"); /*==========================================================================*/ -typedef unsigned char byte; +typedef uint8_t byte; typedef enum { false = 0, diff --git a/source/r_brush.c b/source/r_brush.c index 95148f3..9d9771d 100644 --- a/source/r_brush.c +++ b/source/r_brush.c @@ -38,7 +38,7 @@ gltexture_t *lightmap_textures[MAX_LIGHTMAPS]; //johnfitz -- changed to an array unsigned blocklights[BLOCK_WIDTH*BLOCK_HEIGHT*3]; //johnfitz -- was 18*18, added lit support (*3) and loosened surface extents maximum (BLOCK_WIDTH*BLOCK_HEIGHT) typedef struct glRect_s { - unsigned char l,t,w,h; + uint8_t l,t,w,h; } glRect_t; glpoly_t *lightmap_polys[MAX_LIGHTMAPS]; diff --git a/source/snd_mem.c b/source/snd_mem.c index 337bc68..7af850e 100644 --- a/source/snd_mem.c +++ b/source/snd_mem.c @@ -60,7 +60,7 @@ static void ResampleSfx (sfx_t *sfx, int inrate, int inwidth, byte *data) { // fast special case for (i = 0; i < outcount; i++) - ((signed char *)sc->data)[i] = (int)( (unsigned char)(data[i]) - 128); + ((signed char *)sc->data)[i] = (int)( (uint8_t)(data[i]) - 128); } else { @@ -74,7 +74,7 @@ static void ResampleSfx (sfx_t *sfx, int inrate, int inwidth, byte *data) if (inwidth == 2) sample = LittleShort ( ((int16_t *)data)[srcsample] ); else - sample = (int)( (unsigned char)(data[srcsample]) - 128) << 8; + sample = (int)( (uint8_t)(data[srcsample]) - 128) << 8; if (sc->width == 2) ((int16_t *)sc->data)[i] = sample; else diff --git a/source/snd_mix.c b/source/snd_mix.c index 402324d..ec5e496 100644 --- a/source/snd_mix.c +++ b/source/snd_mix.c @@ -120,7 +120,7 @@ static void S_TransferPaintBuffer (int endtime) } else if (shm->samplebits == 8 && !shm->signed8) { - unsigned char *out = shm->buffer; + uint8_t *out = shm->buffer; while (count--) { val = *p / 256; @@ -473,7 +473,7 @@ static void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count, int { int data; int *lscale, *rscale; - unsigned char *sfx; + uint8_t *sfx; int i; if (ch->leftvol > 255) @@ -483,7 +483,7 @@ static void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count, int lscale = snd_scaletable[ch->leftvol >> 3]; rscale = snd_scaletable[ch->rightvol >> 3]; - sfx = (unsigned char *)sc->data + ch->pos; + sfx = (uint8_t *)sc->data + ch->pos; for (i = 0; i < count; i++) { diff --git a/source/snd_mp3.c b/source/snd_mp3.c index 697c908..b6b5681 100644 --- a/source/snd_mp3.c +++ b/source/snd_mp3.c @@ -55,7 +55,7 @@ static mad_timer_t const mad_timer_zero_stub = {0, 0}; /* Private data */ typedef struct _mp3_priv_t { - unsigned char mp3_buffer[MP3_BUFFER_SIZE]; + uint8_t mp3_buffer[MP3_BUFFER_SIZE]; struct mad_stream Stream; struct mad_frame Frame; struct mad_synth Synth; @@ -67,7 +67,7 @@ typedef struct _mp3_priv_t /* This function merges the functions tagtype() and id3_tag_query() * from MAD's libid3tag, so we don't have to link to it * Returns 0 if the frame is not an ID3 tag, tag length if it is */ -static inline qboolean tag_is_id3v1(const unsigned char *data, size_t length) +static inline qboolean tag_is_id3v1(const uint8_t *data, size_t length) { if (length >= 3 && data[0] == 'T' && data[1] == 'A' && data[2] == 'G') @@ -77,7 +77,7 @@ static inline qboolean tag_is_id3v1(const unsigned char *data, size_t length) return false; } -static inline qboolean tag_is_id3v2(const unsigned char *data, size_t length) +static inline qboolean tag_is_id3v2(const uint8_t *data, size_t length) { if (length >= 10 && (data[0] == 'I' && data[1] == 'D' && data[2] == '3') && @@ -93,7 +93,7 @@ static inline qboolean tag_is_id3v2(const unsigned char *data, size_t length) * http://wiki.hydrogenaud.io/index.php?title=APEv2_specification * Detect an APEv2 tag. (APEv1 has no header, so no luck.) */ -static inline qboolean tag_is_apetag(const unsigned char *data, size_t length) +static inline qboolean tag_is_apetag(const uint8_t *data, size_t length) { uint32_t v; @@ -109,7 +109,7 @@ static inline qboolean tag_is_apetag(const unsigned char *data, size_t length) return true; } -static size_t mp3_tagsize(const unsigned char *data, size_t length) +static size_t mp3_tagsize(const uint8_t *data, size_t length) { size_t size; @@ -118,7 +118,7 @@ static size_t mp3_tagsize(const unsigned char *data, size_t length) if (tag_is_id3v2(data, length)) { - unsigned char flags = data[5]; + uint8_t flags = data[5]; size = 10 + (data[6]<<21) + (data[7]<<14) + (data[8]<<7) + data[9]; if (flags & ID3_TAG_FLAG_FOOTERPRESENT) size += 10; diff --git a/source/snd_mpg123.c b/source/snd_mpg123.c index 7b866ca..0da5eca 100644 --- a/source/snd_mpg123.c +++ b/source/snd_mpg123.c @@ -180,7 +180,7 @@ static int S_MP3_CodecReadStream (snd_stream_t *stream, int bytes, void *buffer) { mp3_priv_t *priv = (mp3_priv_t *) stream->priv; size_t bytes_read = 0; - int res = mpg123_read (priv->handle, (unsigned char *)buffer, (size_t)bytes, &bytes_read); + int res = mpg123_read (priv->handle, (uint8_t *)buffer, (size_t)bytes, &bytes_read); switch (res) { case MPG123_DONE: diff --git a/source/snd_opus.c b/source/snd_opus.c index 1ed189c..e55108a 100644 --- a/source/snd_opus.c +++ b/source/snd_opus.c @@ -40,7 +40,7 @@ static int opc_fclose (void *f) return 0; /* we fclose() elsewhere. */ } -static int opc_fread (void *f, unsigned char *buf, int size) +static int opc_fread (void *f, uint8_t *buf, int size) { int ret; @@ -69,7 +69,7 @@ static opus_int64 opc_ftell (void *f) static const OpusFileCallbacks opc_qfs = { - (int (*)(void *, unsigned char *, int)) opc_fread, + (int (*)(void *, uint8_t *, int)) opc_fread, (int (*)(void *, opus_int64, int)) opc_fseek, (opus_int64 (*)(void *)) opc_ftell, (int (*)(void *)) opc_fclose diff --git a/source/snd_sdl.c b/source/snd_sdl.c index 15ea0bb..aa5f0da 100644 --- a/source/snd_sdl.c +++ b/source/snd_sdl.c @@ -159,7 +159,7 @@ qboolean SNDDMA_Init (dma_t *dma) buffersize = shm->samples * (shm->samplebits / 8); Con_Printf ("SDL audio driver: %s, %d bytes buffer\n", drivername, buffersize); - shm->buffer = (unsigned char *) calloc (1, buffersize); + shm->buffer = (uint8_t *) calloc (1, buffersize); if (!shm->buffer) { SDL_CloseAudio(); diff --git a/source/snd_umx.c b/source/snd_umx.c index 587b63d..92cb822 100644 --- a/source/snd_umx.c +++ b/source/snd_umx.c @@ -142,7 +142,7 @@ _retry: return UMUSIC_XM; } if (type == UMUSIC_MP2) { - unsigned char *p = (unsigned char *)sig; + uint8_t *p = (uint8_t *)sig; uint16_t u = ((p[0] << 8) | p[1]) & 0xFFFE; if (u == 0xFFFC || u == 0xFFF4) return UMUSIC_MP2; @@ -276,12 +276,12 @@ static int probe_umx (fshandle_t *f, const struct upkg_hdr *hdr, static int32_t probe_header (void *header) { struct upkg_hdr *hdr; - unsigned char *p; + uint8_t *p; uint32_t *swp; int i; /* byte swap the header - all members are 32 bit LE values */ - p = (unsigned char *) header; + p = (uint8_t *) header; swp = (uint32_t *) header; for (i = 0; i < UPKG_HDR_SIZE/4; i++, p += 4) { swp[i] = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); diff --git a/source/stb_image_write.h b/source/stb_image_write.h index af287ce..978fc20 100644 --- a/source/stb_image_write.h +++ b/source/stb_image_write.h @@ -201,7 +201,7 @@ STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, #define STBIW_ASSERT(x) assert(x) #endif -#define STBIW_UCHAR(x) (unsigned char) ((x) & 0xff) +#define STBIW_UCHAR(x) (uint8_t) ((x) & 0xff) typedef struct { @@ -240,7 +240,7 @@ static void stbi__end_write_file(stbi__write_context *s) typedef uint32_t stbiw_uint32; typedef int stb_image_write_test[sizeof(stbiw_uint32)==4 ? 1 : -1]; -static void stbiw__putc(stbi__write_context *s, unsigned char c) +static void stbiw__putc(stbi__write_context *s, uint8_t c) { s->func(s->context, &c, 1); } @@ -253,7 +253,7 @@ static void stbiw__putc(stbi__write_context *s, unsigned char c) * public domain Simple, Minimalistic JPEG writer - http://www.jonolick.com/code.html */ -static const unsigned char stbiw__jpg_ZigZag[] = { 0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18, +static const uint8_t stbiw__jpg_ZigZag[] = { 0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18, 24,31,40,44,53,10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60,21,34,37,47,50,56,59,61,35,36,48,49,57,58,62,63 }; static void stbiw__jpg_writeBits(stbi__write_context *s, int *bitBufP, int *bitCntP, const uint16_t *bs) { @@ -261,7 +261,7 @@ static void stbiw__jpg_writeBits(stbi__write_context *s, int *bitBufP, int *bitC bitCnt += bs[1]; bitBuf |= bs[0] << (24 - bitCnt); while(bitCnt >= 8) { - unsigned char c = (bitBuf >> 16) & 255; + uint8_t c = (bitBuf >> 16) & 255; stbiw__putc(s, c); if(c == 255) { stbiw__putc(s, 0); @@ -403,10 +403,10 @@ static int stbiw__jpg_processDU(stbi__write_context *s, int *bitBuf, int *bitCnt static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, int comp, const void* data, int quality) { // Constants that don't pollute global namespace - static const unsigned char std_dc_luminance_nrcodes[] = {0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0}; - static const unsigned char std_dc_luminance_values[] = {0,1,2,3,4,5,6,7,8,9,10,11}; - static const unsigned char std_ac_luminance_nrcodes[] = {0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d}; - static const unsigned char std_ac_luminance_values[] = { + static const uint8_t std_dc_luminance_nrcodes[] = {0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0}; + static const uint8_t std_dc_luminance_values[] = {0,1,2,3,4,5,6,7,8,9,10,11}; + static const uint8_t std_ac_luminance_nrcodes[] = {0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d}; + static const uint8_t std_ac_luminance_values[] = { 0x01,0x02,0x03,0x00,0x04,0x11,0x05,0x12,0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08, 0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16,0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28, 0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59, @@ -415,10 +415,10 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in 0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2, 0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa }; - static const unsigned char std_dc_chrominance_nrcodes[] = {0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0}; - static const unsigned char std_dc_chrominance_values[] = {0,1,2,3,4,5,6,7,8,9,10,11}; - static const unsigned char std_ac_chrominance_nrcodes[] = {0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,0x77}; - static const unsigned char std_ac_chrominance_values[] = { + static const uint8_t std_dc_chrominance_nrcodes[] = {0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0}; + static const uint8_t std_dc_chrominance_values[] = {0,1,2,3,4,5,6,7,8,9,10,11}; + static const uint8_t std_ac_chrominance_nrcodes[] = {0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,0x77}; + static const uint8_t std_ac_chrominance_values[] = { 0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71,0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91, 0xa1,0xb1,0xc1,0x09,0x23,0x33,0x52,0xf0,0x15,0x62,0x72,0xd1,0x0a,0x16,0x24,0x34,0xe1,0x25,0xf1,0x17,0x18,0x19,0x1a,0x26, 0x27,0x28,0x29,0x2a,0x35,0x36,0x37,0x38,0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58, @@ -475,7 +475,7 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in int row, col, i, k; float fdtbl_Y[64], fdtbl_UV[64]; - unsigned char YTable[64], UVTable[64]; + uint8_t YTable[64], UVTable[64]; if(!data || !width || !height || comp > 4 || comp < 1) { return 0; @@ -487,9 +487,9 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in for(i = 0; i < 64; ++i) { int uvti, yti = (YQT[i]*quality+50)/100; - YTable[stbiw__jpg_ZigZag[i]] = (unsigned char) (yti < 1 ? 1 : yti > 255 ? 255 : yti); + YTable[stbiw__jpg_ZigZag[i]] = (uint8_t) (yti < 1 ? 1 : yti > 255 ? 255 : yti); uvti = (UVQT[i]*quality+50)/100; - UVTable[stbiw__jpg_ZigZag[i]] = (unsigned char) (uvti < 1 ? 1 : uvti > 255 ? 255 : uvti); + UVTable[stbiw__jpg_ZigZag[i]] = (uint8_t) (uvti < 1 ? 1 : uvti > 255 ? 255 : uvti); } for(row = 0, k = 0; row < 8; ++row) { @@ -501,13 +501,13 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in // Write Headers { - static const unsigned char head0[] = { 0xFF,0xD8,0xFF,0xE0,0,0x10,'J','F','I','F',0,1,1,0,0,1,0,1,0,0,0xFF,0xDB,0,0x84,0 }; - static const unsigned char head2[] = { 0xFF,0xDA,0,0xC,3,1,0,2,0x11,3,0x11,0,0x3F,0 }; - unsigned char head1[] = { 0xFF,0xC0,0,0x11,8, /*[5]*/0,/*[6]*/0,/*[7]*/0,/*[8]*/0, + static const uint8_t head0[] = { 0xFF,0xD8,0xFF,0xE0,0,0x10,'J','F','I','F',0,1,1,0,0,1,0,1,0,0,0xFF,0xDB,0,0x84,0 }; + static const uint8_t head2[] = { 0xFF,0xDA,0,0xC,3,1,0,2,0x11,3,0x11,0,0x3F,0 }; + uint8_t head1[] = { 0xFF,0xC0,0,0x11,8, /*[5]*/0,/*[6]*/0,/*[7]*/0,/*[8]*/0, 3,1,0x11,0,2,0x11,1,3,0x11,1,0xFF,0xC4,0x01,0xA2,0 }; - head1[5] = (unsigned char)(height>>8); + head1[5] = (uint8_t)(height>>8); head1[6] = STBIW_UCHAR(height); - head1[7] = (unsigned char)(width>>8); + head1[7] = (uint8_t)(width>>8); head1[8] = STBIW_UCHAR(width); s->func(s->context, (void*)head0, sizeof(head0)); s->func(s->context, (void*)YTable, sizeof(YTable)); @@ -531,7 +531,7 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in // Encode 8x8 macroblocks { static const uint16_t fillBits[] = {0x7F, 7}; - const unsigned char *imageData = (const unsigned char *)data; + const uint8_t *imageData = (const uint8_t *)data; int DCY=0, DCU=0, DCV=0; int bitBuf=0, bitCnt=0; // comp == 2 is grey+alpha (alpha is ignored) @@ -635,7 +635,7 @@ STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const 0.93 (2014-05-27) warning fixes 0.92 (2010-08-01) - casts to unsigned char to fix warnings + casts to uint8_t to fix warnings 0.91 (2010-07-17) first public release 0.90 first internal release