summaryrefslogtreecommitdiff
path: root/lodepng.cpp
diff options
context:
space:
mode:
authorLode <lvandeve@gmail.com>2014-12-01 01:20:53 +0100
committerLode <lvandeve@gmail.com>2014-12-01 01:20:53 +0100
commit88a62942a142dc5a922e7d25b231bca057c613cd (patch)
treed416e25cae574559706da797d693036451b70ecf /lodepng.cpp
parentbf09e0a5f173ba07821b782b8297dbfc139d5fed (diff)
parent14f76d0f5b3099d9a48f3dfeab40575eff477063 (diff)
Merge branch 'ansi_c_only' of https://github.com/slowriot/lodepng into slowriot-ansi_c_only
Diffstat (limited to 'lodepng.cpp')
-rw-r--r--lodepng.cpp509
1 files changed, 254 insertions, 255 deletions
diff --git a/lodepng.cpp b/lodepng.cpp
index dfe4b65..af18a00 100644
--- a/lodepng.cpp
+++ b/lodepng.cpp
@@ -179,7 +179,7 @@ static unsigned uivector_resizev(uivector* p, size_t size, unsigned value)
{
size_t oldsize = p->size, i;
if(!uivector_resize(p, size)) return 0;
- for(i = oldsize; i < size; i++) p->data[i] = value;
+ for(i = oldsize; i < size; ++i) p->data[i] = value;
return 1;
}
@@ -203,7 +203,7 @@ static unsigned uivector_copy(uivector* p, const uivector* q)
{
size_t i;
if(!uivector_resize(p, q->size)) return 0;
- for(i = 0; i < q->size; i++) p->data[i] = q->data[i];
+ for(i = 0; i != q->size; ++i) p->data[i] = q->data[i];
return 1;
}
#endif /*LODEPNG_COMPILE_ENCODER*/
@@ -265,7 +265,7 @@ static unsigned ucvector_resizev(ucvector* p, size_t size, unsigned char value)
{
size_t oldsize = p->size, i;
if(!ucvector_resize(p, size)) return 0;
- for(i = oldsize; i < size; i++) p->data[i] = value;
+ for(i = oldsize; i < size; ++i) p->data[i] = value;
return 1;
}
#endif /*LODEPNG_COMPILE_DECODER*/
@@ -324,10 +324,10 @@ static void string_cleanup(char** out)
static void string_set(char** out, const char* in)
{
- size_t insize = strlen(in), i = 0;
+ size_t insize = strlen(in), i;
if(string_resize(out, insize))
{
- for(i = 0; i < insize; i++)
+ for(i = 0; i != insize; ++i)
{
(*out)[i] = in[i];
}
@@ -423,19 +423,19 @@ unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const
if(((*bitpointer) & 7) == 0) ucvector_push_back(bitstream, (unsigned char)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)++;\
+ ++(*bitpointer);\
}
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, (unsigned char)((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, (unsigned char)((value >> (nbits - 1 - i)) & 1));
}
#endif /*LODEPNG_COMPILE_ENCODER*/
@@ -446,17 +446,17 @@ static void addBitsToStreamReversed(size_t* bitpointer, ucvector* bitstream, uns
static unsigned char readBitFromStream(size_t* bitpointer, const unsigned char* bitstream)
{
unsigned char result = (unsigned char)(READBIT(*bitpointer, bitstream));
- (*bitpointer)++;
+ ++(*bitpointer);
return result;
}
static unsigned readBitsFromStream(size_t* bitpointer, const unsigned char* bitstream, size_t nbits)
{
unsigned result = 0, i;
- for(i = 0; i < nbits; i++)
+ for(i = 0; i != nbits; ++i)
{
result += ((unsigned)READBIT(*bitpointer, bitstream)) << i;
- (*bitpointer)++;
+ ++(*bitpointer);
}
return result;
}
@@ -519,7 +519,7 @@ typedef struct HuffmanTree
static void HuffmanTree_draw(HuffmanTree* tree)
{
std::cout << "tree. length: " << tree->numcodes << " maxbitlen: " << tree->maxbitlen << std::endl;
- for(size_t i = 0; i < tree->tree1d.size; i++)
+ for(size_t i = 0; i != tree->tree1d.size; ++i)
{
if(tree->lengths.data[i])
std::cout << i << " " << tree->tree1d.data[i] << " " << tree->lengths.data[i] << std::endl;
@@ -561,14 +561,14 @@ static unsigned HuffmanTree_make2DTree(HuffmanTree* tree)
There is only memory for such good tree currently, if there are more nodes
(due to too long length codes), error 55 will happen
*/
- for(n = 0; n < tree->numcodes * 2; n++)
+ for(n = 0; n < tree->numcodes * 2; ++n)
{
tree->tree2d[n] = 32767; /*32767 here means the tree2d isn't filled there yet*/
}
- for(n = 0; n < tree->numcodes; n++) /*the codes*/
+ for(n = 0; n < tree->numcodes; ++n) /*the codes*/
{
- for(i = 0; i < tree->lengths[n]; i++) /*the bits for this code*/
+ 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);
/*oversubscribed, see comment in lodepng_error_text*/
@@ -584,7 +584,7 @@ static unsigned HuffmanTree_make2DTree(HuffmanTree* tree)
{
/*put address of the next step in here, first that address has to be found of course
(it's just nodefilled + 1)...*/
- nodefilled++;
+ ++nodefilled;
/*addresses encoded with numcodes added to it*/
tree->tree2d[2 * treepos + bit] = nodefilled + tree->numcodes;
treepos = nodefilled;
@@ -594,7 +594,7 @@ static unsigned HuffmanTree_make2DTree(HuffmanTree* tree)
}
}
- for(n = 0; n < tree->numcodes * 2; n++)
+ for(n = 0; n < tree->numcodes * 2; ++n)
{
if(tree->tree2d[n] == 32767) tree->tree2d[n] = 0; /*remove possible remaining 32767's*/
}
@@ -611,7 +611,8 @@ static unsigned HuffmanTree_makeFromLengths2(HuffmanTree* tree)
{
uivector blcount;
uivector nextcode;
- unsigned bits, n, error = 0;
+ unsigned error = 0;
+ unsigned bits, n;
uivector_init(&blcount);
uivector_init(&nextcode);
@@ -626,14 +627,14 @@ static unsigned HuffmanTree_makeFromLengths2(HuffmanTree* tree)
if(!error)
{
/*step 1: count number of instances of each code length*/
- for(bits = 0; bits < tree->numcodes; bits++) blcount.data[tree->lengths[bits]]++;
+ for(bits = 0; bits != tree->numcodes; ++bits) ++blcount.data[tree->lengths[bits]];
/*step 2: generate the nextcode values*/
- for(bits = 1; bits <= tree->maxbitlen; bits++)
+ for(bits = 1; bits <= tree->maxbitlen; ++bits)
{
nextcode.data[bits] = (nextcode.data[bits - 1] + blcount.data[bits - 1]) << 1;
}
/*step 3: generate all the codes*/
- for(n = 0; n < tree->numcodes; n++)
+ for(n = 0; n != tree->numcodes; ++n)
{
if(tree->lengths[n] != 0) tree->tree1d[n] = nextcode.data[tree->lengths[n]]++;
}
@@ -657,7 +658,7 @@ static unsigned HuffmanTree_makeFromLengths(HuffmanTree* tree, const unsigned* b
unsigned i;
tree->lengths = (unsigned*)lodepng_malloc(numcodes * sizeof(unsigned));
if(!tree->lengths) return 83; /*alloc fail*/
- for(i = 0; i < numcodes; i++) tree->lengths[i] = bitlen[i];
+ for(i = 0; i != numcodes; ++i) tree->lengths[i] = bitlen[i];
tree->numcodes = (unsigned)numcodes; /*number of symbols*/
tree->maxbitlen = maxbitlen;
return HuffmanTree_makeFromLengths2(tree);
@@ -696,20 +697,20 @@ static void coin_copy(Coin* c1, const Coin* c2)
static void add_coins(Coin* c1, const Coin* c2)
{
size_t i;
- for(i = 0; i < c2->symbols.size; i++) uivector_push_back(&c1->symbols, c2->symbols.data[i]);
+ for(i = 0; i != c2->symbols.size; ++i) uivector_push_back(&c1->symbols, c2->symbols.data[i]);
c1->weight += c2->weight;
}
static void init_coins(Coin* coins, size_t num)
{
size_t i;
- for(i = 0; i < num; i++) coin_init(&coins[i]);
+ for(i = 0; i != num; ++i) coin_init(&coins[i]);
}
static void cleanup_coins(Coin* coins, size_t num)
{
size_t i;
- for(i = 0; i < num; i++) coin_cleanup(&coins[i]);
+ for(i = 0; i != num; ++i) coin_cleanup(&coins[i]);
}
static int coin_compare(const void* a, const void* b) {
@@ -722,13 +723,13 @@ static unsigned append_symbol_coins(Coin* coins, const unsigned* frequencies, un
{
unsigned i;
unsigned j = 0; /*index of present symbols*/
- for(i = 0; i < numcodes; i++)
+ for(i = 0; i != numcodes; ++i)
{
if(frequencies[i] != 0) /*only include symbols that are present*/
{
coins[j].weight = frequencies[i] / (float)sum;
uivector_push_back(&coins[j].symbols, i);
- j++;
+ ++j;
}
}
return 0;
@@ -747,16 +748,16 @@ unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequen
if(numcodes == 0) return 80; /*error: a tree of 0 symbols is not supposed to be made*/
- for(i = 0; i < numcodes; i++)
+ for(i = 0; i != numcodes; ++i)
{
if(frequencies[i] > 0)
{
- numpresent++;
+ ++numpresent;
sum += frequencies[i];
}
}
- for(i = 0; i < numcodes; i++) lengths[i] = 0;
+ for(i = 0; i != numcodes; ++i) lengths[i] = 0;
/*ensure at least two present symbols. There should be at least one symbol
according to RFC 1951 section 3.2.7. To decoders incorrectly require two. To
@@ -769,7 +770,7 @@ unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequen
}
else if(numpresent == 1)
{
- for(i = 0; i < numcodes; i++)
+ for(i = 0; i != numcodes; ++i)
{
if(frequencies[i])
{
@@ -803,7 +804,7 @@ unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequen
if(!error)
{
unsigned numprev = 0;
- for(j = 1; j <= maxbitlen && !error; j++) /*each of the remaining rows*/
+ for(j = 1; j <= maxbitlen && !error; ++j) /*each of the remaining rows*/
{
unsigned tempnum;
Coin* tempcoins;
@@ -836,11 +837,11 @@ unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequen
if(!error)
{
- /*calculate the lenghts of each symbol, as the amount of times a coin of each symbol is used*/
- for(i = 0; i + 1 < numpresent; i++)
+ /*calculate the lengths of each symbol, as the amount of times a coin of each symbol is used*/
+ for(i = 0; i + 1 < numpresent; ++i)
{
Coin* coin = &coins[i];
- for(j = 0; j < coin->symbols.size; j++) lengths[coin->symbols.data[j]]++;
+ for(j = 0; j < coin->symbols.size; ++j) ++lengths[coin->symbols.data[j]];
}
}
@@ -858,7 +859,7 @@ static unsigned HuffmanTree_makeFromFrequencies(HuffmanTree* tree, const unsigne
size_t mincodes, size_t numcodes, unsigned maxbitlen)
{
unsigned error = 0;
- while(!frequencies[numcodes - 1] && numcodes > mincodes) numcodes--; /*trim zeroes*/
+ while(!frequencies[numcodes - 1] && numcodes > mincodes) --numcodes; /*trim zeroes*/
tree->maxbitlen = maxbitlen;
tree->numcodes = (unsigned)numcodes; /*number of symbols*/
tree->lengths = (unsigned*)lodepng_realloc(tree->lengths, numcodes * sizeof(unsigned));
@@ -890,10 +891,10 @@ static unsigned generateFixedLitLenTree(HuffmanTree* tree)
if(!bitlen) return 83; /*alloc fail*/
/*288 possible codes: 0-255=literals, 256=endcode, 257-285=lengthcodes, 286-287=unused*/
- for(i = 0; i <= 143; i++) bitlen[i] = 8;
- for(i = 144; i <= 255; i++) bitlen[i] = 9;
- for(i = 256; i <= 279; i++) bitlen[i] = 7;
- for(i = 280; i <= 287; i++) bitlen[i] = 8;
+ for(i = 0; i <= 143; ++i) bitlen[i] = 8;
+ for(i = 144; i <= 255; ++i) bitlen[i] = 9;
+ for(i = 256; i <= 279; ++i) bitlen[i] = 7;
+ for(i = 280; i <= 287; ++i) bitlen[i] = 8;
error = HuffmanTree_makeFromLengths(tree, bitlen, NUM_DEFLATE_CODE_SYMBOLS, 15);
@@ -909,7 +910,7 @@ static unsigned generateFixedDistanceTree(HuffmanTree* tree)
if(!bitlen) return 83; /*alloc fail*/
/*there are 32 distance codes, but 30-31 are unused*/
- for(i = 0; i < NUM_DISTANCE_SYMBOLS; i++) bitlen[i] = 5;
+ for(i = 0; i != NUM_DISTANCE_SYMBOLS; ++i) bitlen[i] = 5;
error = HuffmanTree_makeFromLengths(tree, bitlen, NUM_DISTANCE_SYMBOLS, 15);
lodepng_free(bitlen);
@@ -934,7 +935,7 @@ static unsigned huffmanDecodeSymbol(const unsigned char* in, size_t* bp,
the expression below because this is the biggest bottleneck while decoding
*/
ct = codetree->tree2d[(treepos << 1) + READBIT(*bp, in)];
- (*bp)++;
+ ++(*bp);
if(ct < codetree->numcodes) return ct; /*the symbol is decoded, return it*/
else treepos = ct - codetree->numcodes; /*symbol not yet decoded, instead move tree position*/
@@ -993,7 +994,7 @@ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d,
bitlen_cl = (unsigned*)lodepng_malloc(NUM_CODE_LENGTH_CODES * sizeof(unsigned));
if(!bitlen_cl) ERROR_BREAK(83 /*alloc fail*/);
- for(i = 0; i < NUM_CODE_LENGTH_CODES; i++)
+ for(i = 0; i != NUM_CODE_LENGTH_CODES; ++i)
{
if(i < HCLEN) bitlen_cl[CLCL_ORDER[i]] = readBitsFromStream(bp, in, 3);
else bitlen_cl[CLCL_ORDER[i]] = 0; /*if not, it must stay 0*/
@@ -1006,8 +1007,8 @@ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d,
bitlen_ll = (unsigned*)lodepng_malloc(NUM_DEFLATE_CODE_SYMBOLS * sizeof(unsigned));
bitlen_d = (unsigned*)lodepng_malloc(NUM_DISTANCE_SYMBOLS * sizeof(unsigned));
if(!bitlen_ll || !bitlen_d) ERROR_BREAK(83 /*alloc fail*/);
- for(i = 0; i < NUM_DEFLATE_CODE_SYMBOLS; i++) bitlen_ll[i] = 0;
- for(i = 0; i < NUM_DISTANCE_SYMBOLS; i++) bitlen_d[i] = 0;
+ for(i = 0; i != NUM_DEFLATE_CODE_SYMBOLS; ++i) bitlen_ll[i] = 0;
+ for(i = 0; i != NUM_DISTANCE_SYMBOLS; ++i) bitlen_d[i] = 0;
/*i is the current symbol we're reading in the part that contains the code lengths of lit/len and dist codes*/
i = 0;
@@ -1018,7 +1019,7 @@ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d,
{
if(i < HLIT) bitlen_ll[i] = code;
else bitlen_d[i - HLIT] = code;
- i++;
+ ++i;
}
else if(code == 16) /*repeat previous*/
{
@@ -1033,12 +1034,12 @@ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d,
if(i < HLIT + 1) value = bitlen_ll[i - 1];
else value = bitlen_d[i - HLIT - 1];
/*repeat this value in the next lengths*/
- for(n = 0; n < replength; n++)
+ for(n = 0; n < replength; ++n)
{
if(i >= HLIT + HDIST) ERROR_BREAK(13); /*error: i is larger than the amount of codes*/
if(i < HLIT) bitlen_ll[i] = value;
else bitlen_d[i - HLIT] = value;
- i++;
+ ++i;
}
}
else if(code == 17) /*repeat "0" 3-10 times*/
@@ -1048,13 +1049,13 @@ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d,
replength += readBitsFromStream(bp, in, 3);
/*repeat this value in the next lengths*/
- for(n = 0; n < replength; n++)
+ for(n = 0; n < replength; ++n)
{
if(i >= HLIT + HDIST) ERROR_BREAK(14); /*error: i is larger than the amount of codes*/
if(i < HLIT) bitlen_ll[i] = 0;
else bitlen_d[i - HLIT] = 0;
- i++;
+ ++i;
}
}
else if(code == 18) /*repeat "0" 11-138 times*/
@@ -1064,13 +1065,13 @@ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d,
replength += readBitsFromStream(bp, in, 7);
/*repeat this value in the next lengths*/
- for(n = 0; n < replength; n++)
+ for(n = 0; n < replength; ++n)
{
if(i >= HLIT + HDIST) ERROR_BREAK(15); /*error: i is larger than the amount of codes*/
if(i < HLIT) bitlen_ll[i] = 0;
else bitlen_d[i - HLIT] = 0;
- i++;
+ ++i;
}
}
else /*if(code == (unsigned)(-1))*/ /*huffmanDecodeSymbol returns (unsigned)(-1) in case of error*/
@@ -1129,7 +1130,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;
- (*pos)++;
+ ++(*pos);
}
else if(code_ll >= FIRST_LENGTH_CODE_INDEX && code_ll <= LAST_LENGTH_CODE_INDEX) /*length code*/
{
@@ -1171,11 +1172,11 @@ static unsigned inflateHuffmanBlock(ucvector* out, const unsigned char* in, size
backward = start - distance;
if(!ucvector_resize(out, (*pos) + length)) ERROR_BREAK(83 /*alloc fail*/);
- for(forward = 0; forward < length; forward++)
+ for(forward = 0; forward < length; ++forward)
{
out->data[(*pos)] = out->data[backward];
- (*pos)++;
- backward++;
+ ++(*pos);
+ ++backward;
if(backward >= start) backward = start - distance;
}
}
@@ -1204,7 +1205,7 @@ static unsigned inflateNoCompression(ucvector* out, const unsigned char* in, siz
unsigned LEN, NLEN, n, error = 0;
/*go to first boundary of byte*/
- while(((*bp) & 0x7) != 0) (*bp)++;
+ while(((*bp) & 0x7) != 0) ++(*bp);
p = (*bp) / 8; /*byte position*/
/*read LEN (2 bytes) and NLEN (2 bytes)*/
@@ -1219,7 +1220,7 @@ static unsigned inflateNoCompression(ucvector* out, const unsigned char* in, siz
/*read the literal data: LEN bytes are now stored in the out buffer*/
if(p + LEN > inlength) return 23; /*error: reading outside of in buffer*/
- for(n = 0; n < LEN; n++) out->data[(*pos)++] = in[p++];
+ for(n = 0; n < LEN; ++n) out->data[(*pos)++] = in[p++];
(*bp) = p * 8;
@@ -1304,7 +1305,7 @@ given array must be sorted (if no value is smaller, it returns the size of the g
static size_t searchCodeIndex(const unsigned* array, size_t array_size, size_t value)
{
/*linear search implementation*/
- /*for(size_t i = 1; i < array_size; i++) if(array[i] > value) return i - 1;
+ /*for(size_t i = 1; i < array_size; ++i) if(array[i] > value) return i - 1;
return array_size - 1;*/
/*binary search implementation (not that much faster) (precondition: array_size > 0)*/
@@ -1375,12 +1376,12 @@ static unsigned hash_init(Hash* hash, unsigned windowsize)
}
/*initialize hash table*/
- for(i = 0; i < HASH_NUM_VALUES; i++) hash->head[i] = -1;
- for(i = 0; i < windowsize; i++) hash->val[i] = -1;
- for(i = 0; i < windowsize; i++) hash->chain[i] = i; /*same value as index indicates uninitialized*/
+ for(i = 0; i != HASH_NUM_VALUES; ++i) hash->head[i] = -1;
+ for(i = 0; i != windowsize; ++i) hash->val[i] = -1;
+ for(i = 0; i != windowsize; ++i) hash->chain[i] = i; /*same value as index indicates uninitialized*/
- for(i = 0; i <= MAX_SUPPORTED_DEFLATE_LENGTH; i++) hash->headz[i] = -1;
- for(i = 0; i < windowsize; i++) hash->chainz[i] = i; /*same value as index indicates uninitialized*/
+ for(i = 0; i <= MAX_SUPPORTED_DEFLATE_LENGTH; ++i) hash->headz[i] = -1;
+ for(i = 0; i != windowsize; ++i) hash->chainz[i] = i; /*same value as index indicates uninitialized*/
return 0;
}
@@ -1414,7 +1415,7 @@ static unsigned getHash(const unsigned char* data, size_t size, size_t pos)
size_t amount, i;
if(pos >= size) return 0;
amount = size - pos;
- for(i = 0; i < amount; i++) result ^= (unsigned)(data[pos + i] << (i * 8u));
+ for(i = 0; i != amount; ++i) result ^= (unsigned)(data[pos + i] << (i * 8u));
}
return result & HASH_BIT_MASK;
}
@@ -1425,7 +1426,7 @@ static unsigned countZeros(const unsigned char* data, size_t size, size_t pos)
const unsigned char* end = start + MAX_SUPPORTED_DEFLATE_LENGTH;
if(end > data + size) end = data + size;
data = start;
- while (data != end && *data == 0) data++;
+ while (data != end && *data == 0) ++data;
/*subtracting two addresses returned as 32-bit number (max value is MAX_SUPPORTED_DEFLATE_LENGTH)*/
return (unsigned)(data - start);
}
@@ -1479,7 +1480,7 @@ static unsigned encodeLZ77(uivector* out, Hash* hash,
if(nicematch > MAX_SUPPORTED_DEFLATE_LENGTH) nicematch = MAX_SUPPORTED_DEFLATE_LENGTH;
- for(pos = inpos; pos < insize; pos++)
+ for(pos = inpos; pos < insize; ++pos)
{
size_t wpos = pos & (windowsize - 1); /*position for in 'circular' hash buffers*/
unsigned chainlength = 0;
@@ -1489,7 +1490,7 @@ static unsigned encodeLZ77(uivector* out, Hash* hash,
if(usezeros && hashval == 0)
{
if (numzeros == 0) numzeros = countZeros(in, insize, pos);
- else if (pos + numzeros > insize || in[pos + numzeros - 1] != 0) numzeros--;
+ else if (pos + numzeros > insize || in[pos + numzeros - 1] != 0) --numzeros;
}
else
{
@@ -1583,7 +1584,7 @@ static unsigned encodeLZ77(uivector* out, Hash* hash,
offset = lazyoffset;
hash->head[hashval] = -1; /*the same hashchain update will be done, this ensures no wrong alteration*/
hash->headz[numzeros] = -1; /*idem*/
- pos--;
+ --pos;
}
}
}
@@ -1603,15 +1604,15 @@ static unsigned encodeLZ77(uivector* out, Hash* hash,
else
{
addLengthDistance(out, length, offset);
- for(i = 1; i < length; i++)
+ for(i = 1; i < length; ++i)
{
- pos++;
+ ++pos;
wpos = pos & (windowsize - 1);
hashval = getHash(in, insize, pos);
if(usezeros && hashval == 0)
{
if (numzeros == 0) numzeros = countZeros(in, insize, pos);
- else if (pos + numzeros > insize || in[pos + numzeros - 1] != 0) numzeros--;
+ else if (pos + numzeros > insize || in[pos + numzeros - 1] != 0) --numzeros;
}
else
{
@@ -1634,7 +1635,7 @@ static unsigned deflateNoCompression(ucvector* out, const unsigned char* data, s
size_t i, j, numdeflateblocks = (datasize + 65534) / 65535;
unsigned datapos = 0;
- for(i = 0; i < numdeflateblocks; i++)
+ for(i = 0; i != numdeflateblocks; ++i)
{
unsigned BFINAL, BTYPE, LEN, NLEN;
unsigned char firstbyte;
@@ -1655,7 +1656,7 @@ static unsigned deflateNoCompression(ucvector* out, const unsigned char* data, s
ucvector_push_back(out, (unsigned char)(NLEN / 256));
/*Decompressed data*/
- for(j = 0; j < 65535 && datapos < datasize; j++)
+ for(j = 0; j < 65535 && datapos < datasize; ++j)
{
ucvector_push_back(out, data[datapos++]);
}
@@ -1673,7 +1674,7 @@ static void writeLZ77data(size_t* bp, ucvector* out, const uivector* lz77_encode
const HuffmanTree* tree_ll, const HuffmanTree* tree_d)
{
size_t i = 0;
- for(i = 0; i < lz77_encoded->size; i++)
+ for(i = 0; i != lz77_encoded->size; ++i)
{
unsigned val = lz77_encoded->data[i];
addHuffmanSymbol(bp, out, HuffmanTree_getCode(tree_ll, val), HuffmanTree_getLength(tree_ll, val));
@@ -1766,21 +1767,21 @@ static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash,
else
{
if(!uivector_resize(&lz77_encoded, datasize)) ERROR_BREAK(83 /*alloc fail*/);
- for(i = datapos; i < dataend; i++) lz77_encoded.data[i] = data[i]; /*no LZ77, but still will be Huffman compressed*/
+ for(i = datapos; i < dataend; ++i) lz77_encoded.data[i] = data[i]; /*no LZ77, but still will be Huffman compressed*/
}
if(!uivector_resizev(&frequencies_ll, 286, 0)) ERROR_BREAK(83 /*alloc fail*/);
if(!uivector_resizev(&frequencies_d, 30, 0)) ERROR_BREAK(83 /*alloc fail*/);
/*Count the frequencies of lit, len and dist codes*/
- for(i = 0; i < lz77_encoded.size; i++)
+ for(i = 0; i != lz77_encoded.size; ++i)
{
unsigned symbol = lz77_encoded.data[i];
- frequencies_ll.data[symbol]++;
+ ++frequencies_ll.data[symbol];
if(symbol > 256)
{
unsigned dist = lz77_encoded.data[i + 2];
- frequencies_d.data[dist]++;
+ ++frequencies_d.data[dist];
i += 3;
}
}
@@ -1796,19 +1797,19 @@ static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash,
numcodes_ll = tree_ll.numcodes; if(numcodes_ll > 286) numcodes_ll = 286;
numcodes_d = tree_d.numcodes; if(numcodes_d > 30) numcodes_d = 30;
/*store the code lengths of both generated trees in bitlen_lld*/
- for(i = 0; i < numcodes_ll; i++) uivector_push_back(&bitlen_lld, HuffmanTree_getLength(&tree_ll, (unsigned)i));
- for(i = 0; i < numcodes_d; i++) uivector_push_back(&bitlen_lld, HuffmanTree_getLength(&tree_d, (unsigned)i));
+ for(i = 0; i != numcodes_ll; ++i) uivector_push_back(&bitlen_lld, HuffmanTree_getLength(&tree_ll, (unsigned)i));
+ for(i = 0; i != numcodes_d; ++i) uivector_push_back(&bitlen_lld, HuffmanTree_getLength(&tree_d, (unsigned)i));
/*run-length compress bitlen_ldd into bitlen_lld_e by using repeat codes 16 (copy length 3-6 times),
17 (3-10 zeroes), 18 (11-138 zeroes)*/
- for(i = 0; i < (unsigned)bitlen_lld.size; i++)
+ for(i = 0; i != (unsigned)bitlen_lld.size; ++i)
{
unsigned j = 0; /*amount of repititions*/
- while(i + j + 1 < (unsigned)bitlen_lld.size && bitlen_lld.data[i + j + 1] == bitlen_lld.data[i]) j++;
+ while(i + j + 1 < (unsigned)bitlen_lld.size && bitlen_lld.data[i + j + 1] == bitlen_lld.data[i]) ++j;
if(bitlen_lld.data[i] == 0 && j >= 2) /*repeat code for zeroes*/
{
- j++; /*include the first zero*/
+ ++j; /*include the first zero*/
if(j <= 10) /*repeat code 17 supports max 10 zeroes*/
{
uivector_push_back(&bitlen_lld_e, 17);
@@ -1827,7 +1828,7 @@ static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash,
size_t k;
unsigned num = j / 6, rest = j % 6;
uivector_push_back(&bitlen_lld_e, bitlen_lld.data[i]);
- for(k = 0; k < num; k++)
+ for(k = 0; k < num; ++k)
{
uivector_push_back(&bitlen_lld_e, 16);
uivector_push_back(&bitlen_lld_e, 6 - 3);
@@ -1849,12 +1850,12 @@ static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash,
/*generate tree_cl, the huffmantree of huffmantrees*/
if(!uivector_resizev(&frequencies_cl, NUM_CODE_LENGTH_CODES, 0)) ERROR_BREAK(83 /*alloc fail*/);
- for(i = 0; i < bitlen_lld_e.size; i++)
+ for(i = 0; i != bitlen_lld_e.size; ++i)
{
- frequencies_cl.data[bitlen_lld_e.data[i]]++;
+ ++frequencies_cl.data[bitlen_lld_e.data[i]];
/*after a repeat code come the bits that specify the number of repetitions,
those don't need to be in the frequencies_cl calculation*/
- if(bitlen_lld_e.data[i] >= 16) i++;
+ if(bitlen_lld_e.data[i] >= 16) ++i;
}
error = HuffmanTree_makeFromFrequencies(&tree_cl, frequencies_cl.data,
@@ -1862,7 +1863,7 @@ static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash,
if(error) break;
if(!uivector_resize(&bitlen_cl, tree_cl.numcodes)) ERROR_BREAK(83 /*alloc fail*/);
- for(i = 0; i < tree_cl.numcodes; i++)
+ for(i = 0; i != tree_cl.numcodes; ++i)
{
/*lenghts of code length tree is in the order as specified by deflate*/
bitlen_cl.data[i] = HuffmanTree_getLength(&tree_cl, CLCL_ORDER[i]);
@@ -1898,16 +1899,16 @@ static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash,
HDIST = (unsigned)(numcodes_d - 1);
HCLEN = (unsigned)bitlen_cl.size - 4;
/*trim zeroes for HCLEN. HLIT and HDIST were already trimmed at tree creation*/
- while(!bitlen_cl.data[HCLEN + 4 - 1] && HCLEN > 0) HCLEN--;
+ while(!bitlen_cl.data[HCLEN + 4 - 1] && HCLEN > 0) --HCLEN;
addBitsToStream(bp, out, HLIT, 5);
addBitsToStream(bp, out, HDIST, 5);
addBitsToStream(bp, out, HCLEN, 4);
/*write the code lenghts of the code length alphabet*/
- for(i = 0; i < HCLEN + 4; i++) addBitsToStream(bp, out, bitlen_cl.data[i], 3);
+ for(i = 0; i != HCLEN + 4; ++i) addBitsToStream(bp, out, bitlen_cl.data[i], 3);
/*write the lenghts of the lit/len AND the dist alphabet*/
- for(i = 0; i < bitlen_lld_e.size; i++)
+ for(i = 0; i != bitlen_lld_e.size; ++i)
{
addHuffmanSymbol(bp, out, HuffmanTree_getCode(&tree_cl, bitlen_lld_e.data[i]),
HuffmanTree_getLength(&tree_cl, bitlen_lld_e.data[i]));
@@ -1976,7 +1977,7 @@ static unsigned deflateFixed(ucvector* out, size_t* bp, Hash* hash,
}
else /*no LZ77, but still will be Huffman compressed*/
{
- for(i = datapos; i < dataend; i++)
+ for(i = datapos; i < dataend; ++i)
{
addHuffmanSymbol(bp, out, HuffmanTree_getCode(&tree_ll, data[i]), HuffmanTree_getLength(&tree_ll, data[i]));
}
@@ -2014,7 +2015,7 @@ static unsigned lodepng_deflatev(ucvector* out, const unsigned char* in, size_t
error = hash_init(&hash, settings->windowsize);
if(error) return error;
- for(i = 0; i < numdeflateblocks && !error; i++)
+ for(i = 0; i != numdeflateblocks && !error; ++i)
{
unsigned final = (i == numdeflateblocks - 1);
size_t start = i * blocksize;
@@ -2077,7 +2078,7 @@ static unsigned update_adler32(unsigned adler, const unsigned char* data, unsign
{
s1 += (*data++);
s2 += s1;
- amount--;
+ --amount;
}
s1 %= 65521;
s2 %= 65521;
@@ -2166,12 +2167,10 @@ unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, const unsig
/*initially, *out must be NULL and outsize 0, if you just give some random *out
that's pointing to a non allocated buffer, this'll crash*/
ucvector outv;
- size_t i;
unsigned error;
unsigned char* deflatedata = 0;
- size_t deflatesize = 0;
+ size_t deflatesize = 0, i;
- unsigned ADLER32;
/*zlib data: 1 byte CMF (CM+CINFO), 1 byte FLG, deflate data, 4 byte ADLER32 checksum of the Decompressed data*/
unsigned CMF = 120; /*0b01111000: CM 8, CINFO 7. With CINFO 7, any window size up to 32768 can be used.*/
unsigned FLEVEL = 0;
@@ -2190,8 +2189,8 @@ unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, const unsig
if(!error)
{
- ADLER32 = adler32(in, (unsigned)insize);
- for(i = 0; i < deflatesize; i++) ucvector_push_back(&outv, deflatedata[i]);
+ unsigned ADLER32 = adler32(in, (unsigned)insize);
+ for(i = 0; i != deflatesize; ++i) ucvector_push_back(&outv, deflatedata[i]);
lodepng_free(deflatedata);
lodepng_add32bitInt(&outv, ADLER32);
}
@@ -2335,7 +2334,7 @@ unsigned lodepng_crc32(const unsigned char* buf, size_t len)
unsigned c = 0xffffffffL;
size_t n;
- for(n = 0; n < len; n++)
+ for(n = 0; n < len; ++n)
{
c = lodepng_crc32_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
}
@@ -2349,7 +2348,7 @@ unsigned lodepng_crc32(const unsigned char* buf, size_t len)
static unsigned char readBitFromReversedStream(size_t* bitpointer, const unsigned char* bitstream)
{
unsigned char result = (unsigned char)((bitstream[(*bitpointer) >> 3] >> (7 - ((*bitpointer) & 0x7))) & 1);
- (*bitpointer)++;
+ ++(*bitpointer);
return result;
}
@@ -2357,7 +2356,7 @@ static unsigned readBitsFromReversedStream(size_t* bitpointer, const unsigned ch
{
unsigned result = 0;
size_t i;
- for(i = nbits - 1; i < nbits; i--)
+ for(i = nbits - 1; i < nbits; --i)
{
result += (unsigned)readBitFromReversedStream(bitpointer, bitstream) << i;
}
@@ -2373,7 +2372,7 @@ static void setBitOfReversedStream0(size_t* bitpointer, unsigned char* bitstream
/*earlier bit of huffman code is in a lesser significant bit of an earlier byte*/
bitstream[(*bitpointer) >> 3] |= (bit << (7 - ((*bitpointer) & 0x7)));
}
- (*bitpointer)++;
+ ++(*bitpointer);
}
#endif /*LODEPNG_COMPILE_DECODER*/
@@ -2382,7 +2381,7 @@ static void setBitOfReversedStream(size_t* bitpointer, unsigned char* bitstream,
/*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))));
else bitstream[(*bitpointer) >> 3] |= (1 << (7 - ((*bitpointer) & 0x7)));
- (*bitpointer)++;
+ ++(*bitpointer);
}
/* ////////////////////////////////////////////////////////////////////////// */
@@ -2397,7 +2396,7 @@ unsigned lodepng_chunk_length(const unsigned char* chunk)
void lodepng_chunk_type(char type[5], const unsigned char* chunk)
{
unsigned i;
- for(i = 0; i < 4; i++) type[i] = (char)chunk[4 + i];
+ for(i = 0; i != 4; ++i) type[i] = (char)chunk[4 + i];
type[4] = 0; /*null termination char*/
}
@@ -2475,7 +2474,7 @@ unsigned lodepng_chunk_append(unsigned char** out, size_t* outlength, const unsi
(*outlength) = new_length;
chunk_start = &(*out)[new_length - total_chunk_length];
- for(i = 0; i < total_chunk_length; i++) chunk_start[i] = chunk[i];
+ for(i = 0; i != total_chunk_length; ++i) chunk_start[i] = chunk[i];
return 0;
}
@@ -2503,7 +2502,7 @@ unsigned lodepng_chunk_create(unsigned char** out, size_t* outlength, unsigned l
chunk[7] = (unsigned char)type[3];
/*3: the data*/
- for(i = 0; i < length; i++) chunk[8 + i] = data[i];
+ for(i = 0; i != length; ++i) chunk[8 + i] = data[i];
/*4: CRC (of the chunkname characters and the data)*/
lodepng_chunk_generate_crc(chunk);
@@ -2575,7 +2574,7 @@ unsigned lodepng_color_mode_copy(LodePNGColorMode* dest, const LodePNGColorMode*
{
dest->palette = (unsigned char*)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];
+ for(i = 0; i != source->palettesize * 4; ++i) dest->palette[i] = source->palette[i];
}
return 0;
}
@@ -2593,7 +2592,7 @@ static int lodepng_color_mode_equal(const LodePNGColorMode* a, const LodePNGColo
if(a->key_b != b->key_b) return 0;
}
if(a->palettesize != b->palettesize) return 0;
- for(i = 0; i < a->palettesize * 4; i++)
+ for(i = 0; i != a->palettesize * 4; ++i)
{
if(a->palette[i] != b->palette[i]) return 0;
}
@@ -2624,7 +2623,7 @@ unsigned lodepng_palette_add(LodePNGColorMode* info,
info->palette[4 * info->palettesize + 1] = g;
info->palette[4 * info->palettesize + 2] = b;
info->palette[4 * info->palettesize + 3] = a;
- info->palettesize++;
+ ++info->palettesize;
return 0;
}
@@ -2657,7 +2656,7 @@ unsigned lodepng_is_palette_type(const LodePNGColorMode* info)
unsigned lodepng_has_palette_alpha(const LodePNGColorMode* info)
{
size_t i;
- for(i = 0; i < info->palettesize; i++)
+ for(i = 0; i != info->palettesize; ++i)
{
if(info->palette[i * 4 + 3] < 255) return 1;
}
@@ -2697,14 +2696,14 @@ static size_t lodepng_get_raw_size_idat(unsigned w, unsigned h, const LodePNGCol
static void LodePNGUnknownChunks_init(LodePNGInfo* info)
{
unsigned i;
- for(i = 0; i < 3; i++) info->unknown_chunks_data[i] = 0;
- for(i = 0; i < 3; i++) info->unknown_chunks_size[i] = 0;
+ for(i = 0; i != 3; ++i) info->unknown_chunks_data[i] = 0;
+ for(i = 0; i != 3; ++i) info->unknown_chunks_size[i] = 0;
}
static void LodePNGUnknownChunks_cleanup(LodePNGInfo* info)
{
unsigned i;
- for(i = 0; i < 3; i++) lodepng_free(info->unknown_chunks_data[i]);
+ for(i = 0; i != 3; ++i) lodepng_free(info->unknown_chunks_data[i]);
}
static unsigned LodePNGUnknownChunks_copy(LodePNGInfo* dest, const LodePNGInfo* src)
@@ -2713,13 +2712,13 @@ static unsigned LodePNGUnknownChunks_copy(LodePNGInfo* dest, const LodePNGInfo*
LodePNGUnknownChunks_cleanup(dest);
- for(i = 0; i < 3; i++)
+ for(i = 0; i != 3; ++i)
{
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]);
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++)
+ for(j = 0; j < src->unknown_chunks_size[i]; ++j)
{
dest->unknown_chunks_data[i][j] = src->unknown_chunks_data[i][j];
}
@@ -2740,7 +2739,7 @@ static void LodePNGText_init(LodePNGInfo* info)
static void LodePNGText_cleanup(LodePNGInfo* info)
{
size_t i;
- for(i = 0; i < info->text_num; i++)
+ for(i = 0; i != info->text_num; ++i)
{
string_cleanup(&info->text_keys[i]);
string_cleanup(&info->text_strings[i]);
@@ -2755,7 +2754,7 @@ static unsigned LodePNGText_copy(LodePNGInfo* dest, const LodePNGInfo* source)
dest->text_keys = 0;
dest->text_strings = 0;
dest->text_num = 0;
- for(i = 0; i < source->text_num; i++)
+ for(i = 0; i != source->text_num; ++i)
{
CERROR_TRY_RETURN(lodepng_add_text(dest, source->text_keys[i], source->text_strings[i]));
}
@@ -2778,7 +2777,7 @@ unsigned lodepng_add_text(LodePNGInfo* info, const char* key, const char* str)
return 83; /*alloc fail*/
}
- info->text_num++;
+ ++info->text_num;
info->text_keys = new_keys;
info->text_strings = new_strings;
@@ -2805,7 +2804,7 @@ static void LodePNGIText_init(LodePNGInfo* info)
static void LodePNGIText_cleanup(LodePNGInfo* info)
{
size_t i;
- for(i = 0; i < info->itext_num; i++)
+ for(i = 0; i != info->itext_num; ++i)
{
string_cleanup(&info->itext_keys[i]);
string_cleanup(&info->itext_langtags[i]);
@@ -2826,7 +2825,7 @@ static unsigned LodePNGIText_copy(LodePNGInfo* dest, const LodePNGInfo* source)
dest->itext_transkeys = 0;
dest->itext_strings = 0;
dest->itext_num = 0;
- for(i = 0; i < source->itext_num; i++)
+ for(i = 0; i != source->itext_num; ++i)
{
CERROR_TRY_RETURN(lodepng_add_itext(dest, source->itext_keys[i], source->itext_langtags[i],
source->itext_transkeys[i], source->itext_strings[i]));
@@ -2855,7 +2854,7 @@ unsigned lodepng_add_itext(LodePNGInfo* info, const char* key, const char* langt
return 83; /*alloc fail*/
}
- info->itext_num++;
+ ++info->itext_num;
info->itext_keys = new_keys;
info->itext_langtags = new_langtags;
info->itext_transkeys = new_transkeys;
@@ -2963,14 +2962,14 @@ struct ColorTree
static void color_tree_init(ColorTree* tree)
{
int i;
- for(i = 0; i < 16; i++) tree->children[i] = 0;
+ for(i = 0; i != 16; ++i) tree->children[i] = 0;
tree->index = -1;
}
static void color_tree_cleanup(ColorTree* tree)
{
int i;
- for(i = 0; i < 16; i++)
+ for(i = 0; i != 16; ++i)
{
if(tree->children[i])
{
@@ -2984,7 +2983,7 @@ static void color_tree_cleanup(ColorTree* tree)
static int color_tree_get(ColorTree* tree, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
{
int bit = 0;
- for(bit = 0; bit < 8; bit++)
+ for(bit = 0; bit < 8; ++bit)
{
int i = 8 * ((r >> bit) & 1) + 4 * ((g >> bit) & 1) + 2 * ((b >> bit) & 1) + 1 * ((a >> bit) & 1);
if(!tree->children[i]) return -1;
@@ -3006,7 +3005,7 @@ static void color_tree_add(ColorTree* tree,
unsigned char r, unsigned char g, unsigned char b, unsigned char a, unsigned index)
{
int bit;
- for(bit = 0; bit < 8; bit++)
+ for(bit = 0; bit < 8; ++bit)
{
int i = 8 * ((r >> bit) & 1) + 4 * ((g >> bit) & 1) + 2 * ((b >> bit) & 1) + 1 * ((a >> bit) & 1);
if(!tree->children[i])
@@ -3255,7 +3254,7 @@ static void getPixelColorsRGBA8(unsigned char* buffer, size_t numpixels,
{
if(mode->bitdepth == 8)
{
- for(i = 0; i < numpixels; i++, buffer += num_channels)
+ for(i = 0; i != numpixels; ++i, buffer += num_channels)
{
buffer[0] = buffer[1] = buffer[2] = in[i];
if(has_alpha) buffer[3] = mode->key_defined && in[i] == mode->key_r ? 0 : 255;
@@ -3263,7 +3262,7 @@ static void getPixelColorsRGBA8(unsigned char* buffer, size_t numpixels,
}
else if(mode->bitdepth == 16)
{
- for(i = 0; i < numpixels; i++, buffer += num_channels)
+ for(i = 0; i != numpixels; ++i, buffer += num_channels)
{
buffer[0] = buffer[1] = buffer[2] = in[i * 2];
if(has_alpha) buffer[3] = mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r ? 0 : 255;
@@ -3273,7 +3272,7 @@ static void getPixelColorsRGBA8(unsigned char* buffer, size_t numpixels,
{
unsigned highest = ((1U << mode->bitdepth) - 1U); /*highest possible value for this bit depth*/
size_t j = 0;
- for(i = 0; i < numpixels; i++, buffer += num_channels)
+ for(i = 0; i != numpixels; ++i, buffer += num_channels)
{
unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth);
buffer[0] = buffer[1] = buffer[2] = (value * 255) / highest;
@@ -3285,7 +3284,7 @@ static void getPixelColorsRGBA8(unsigned char* buffer, size_t numpixels,
{
if(mode->bitdepth == 8)
{
- for(i = 0; i < numpixels; i++, buffer += num_channels)
+ for(i = 0; i != numpixels; ++i, buffer += num_channels)
{
buffer[0] = in[i * 3 + 0];
buffer[1] = in[i * 3 + 1];
@@ -3296,7 +3295,7 @@ static void getPixelColorsRGBA8(unsigned char* buffer, size_t numpixels,
}
else
{
- for(i = 0; i < numpixels; i++, buffer += num_channels)
+ for(i = 0; i != numpixels; ++i, buffer += num_channels)
{
buffer[0] = in[i * 6 + 0];
buffer[1] = in[i * 6 + 2];
@@ -3312,7 +3311,7 @@ static void getPixelColorsRGBA8(unsigned char* buffer, size_t numpixels,
{
unsigned index;
size_t j = 0;
- for(i = 0; i < numpixels; i++, buffer += num_channels)
+ for(i = 0; i != numpixels; ++i, buffer += num_channels)
{
if(mode->bitdepth == 8) index = in[i];
else index = readBitsFromReversedStream(&j, in, mode->bitdepth);
@@ -3337,7 +3336,7 @@ static void getPixelColorsRGBA8(unsigned char* buffer, size_t numpixels,
{
if(mode->bitdepth == 8)
{
- for(i = 0; i < numpixels; i++, buffer += num_channels)
+ for(i = 0; i != numpixels; ++i, buffer += num_channels)
{
buffer[0] = buffer[1] = buffer[2] = in[i * 2 + 0];
if(has_alpha) buffer[3] = in[i * 2 + 1];
@@ -3345,7 +3344,7 @@ static void getPixelColorsRGBA8(unsigned char* buffer, size_t numpixels,
}
else
{
- for(i = 0; i < numpixels; i++, buffer += num_channels)
+ for(i = 0; i != numpixels; ++i, buffer += num_channels)
{
buffer[0] = buffer[1] = buffer[2] = in[i * 4 + 0];
if(has_alpha) buffer[3] = in[i * 4 + 2];
@@ -3356,7 +3355,7 @@ static void getPixelColorsRGBA8(unsigned char* buffer, size_t numpixels,
{
if(mode->bitdepth == 8)
{
- for(i = 0; i < numpixels; i++, buffer += num_channels)
+ for(i = 0; i != numpixels; ++i, buffer += num_channels)
{
buffer[0] = in[i * 4 + 0];
buffer[1] = in[i * 4 + 1];
@@ -3366,7 +3365,7 @@ static void getPixelColorsRGBA8(unsigned char* buffer, size_t numpixels,
}
else
{
- for(i = 0; i < numpixels; i++, buffer += num_channels)
+ for(i = 0; i != numpixels; ++i, buffer += num_channels)
{
buffer[0] = in[i * 8 + 0];
buffer[1] = in[i * 8 + 2];
@@ -3423,7 +3422,7 @@ unsigned lodepng_convert(unsigned char* out, const unsigned char* in,
if(lodepng_color_mode_equal(mode_out, mode_in))
{
size_t numbytes = lodepng_get_raw_size(w, h, mode_in);
- for(i = 0; i < numbytes; i++) out[i] = in[i];
+ for(i = 0; i != numbytes; ++i) out[i] = in[i];
return 0;
}
@@ -3432,7 +3431,7 @@ unsigned lodepng_convert(unsigned char* out, const unsigned char* in,
size_t palsize = 1u << mode_out->bitdepth;
if(mode_out->palettesize < palsize) palsize = mode_out->palettesize;
color_tree_init(&tree);
- for(i = 0; i < palsize; i++)
+ for(i = 0; i != palsize; ++i)
{
unsigned char* p = &mode_out->palette[i * 4];
color_tree_add(&tree, p[0], p[1], p[2], p[3], i);
@@ -3441,7 +3440,7 @@ unsigned lodepng_convert(unsigned char* out, const unsigned char* in,
if(mode_in->bitdepth == 16 && mode_out->bitdepth == 16)
{
- for(i = 0; i < numpixels; i++)
+ for(i = 0; i != numpixels; ++i)
{
unsigned short r = 0, g = 0, b = 0, a = 0;
getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in);
@@ -3459,7 +3458,7 @@ unsigned lodepng_convert(unsigned char* out, const unsigned char* in,
else
{
unsigned char r = 0, g = 0, b = 0, a = 0;
- for(i = 0; i < numpixels; i++)
+ for(i = 0; i != numpixels; ++i)
{
getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in);
rgba8ToPixel(out, i, mode_out, &tree, r, g, b, a);
@@ -3534,7 +3533,7 @@ unsigned lodepng_get_color_profile(LodePNGColorProfile* profile,
if(mode->bitdepth == 16)
{
unsigned short r, g, b, a;
- for(i = 0; i < numpixels; i++)
+ for(i = 0; i != numpixels; ++i)
{
getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode);
if((r & 255u) != ((r >> 8) & 255u) || (g & 255u) != ((g >> 8) & 255u) ||
@@ -3552,7 +3551,7 @@ unsigned lodepng_get_color_profile(LodePNGColorProfile* profile,
profile->bits = 16;
bits_done = numcolors_done = 1; /*counting colors no longer useful, palette doesn't support 16-bit*/
- for(i = 0; i < numpixels; i++)
+ for(i = 0; i != numpixels; ++i)
{
getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode);
@@ -3591,7 +3590,7 @@ unsigned lodepng_get_color_profile(LodePNGColorProfile* profile,
}
else /* < 16-bit */
{
- for(i = 0; i < numpixels; i++)
+ for(i = 0; i != numpixels; ++i)
{
unsigned char r = 0, g = 0, b = 0, a = 0;
getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode);
@@ -3650,7 +3649,7 @@ unsigned lodepng_get_color_profile(LodePNGColorProfile* profile,
p[n * 4 + 2] = b;
p[n * 4 + 3] = a;
}
- profile->numcolors++;
+ ++profile->numcolors;
numcolors_done = profile->numcolors >= maxnumcolors;
}
}
@@ -3679,7 +3678,7 @@ unsigned lodepng_auto_choose_color(LodePNGColorMode* mode_out,
{
LodePNGColorProfile prof;
unsigned error = 0;
- unsigned i, n, palettebits, grey_ok, palette_ok;
+ unsigned n, i, palettebits, grey_ok, palette_ok;
lodepng_color_profile_init(&prof);
error = lodepng_get_color_profile(&prof, image, w, h, mode_in);
@@ -3701,7 +3700,7 @@ unsigned lodepng_auto_choose_color(LodePNGColorMode* mode_out,
{
unsigned char* p = prof.palette;
lodepng_palette_clear(mode_out); /*remove potential earlier palette*/
- for(i = 0; i < prof.numcolors; i++)
+ for(i = 0; i != prof.numcolors; ++i)
{
error = lodepng_palette_add(mode_out, p[i * 4 + 0], p[i * 4 + 1], p[i * 4 + 2], p[i * 4 + 3]);
if(error) break;
@@ -3784,7 +3783,7 @@ static void Adam7_getpassvalues(unsigned passw[7], unsigned passh[7], size_t fil
unsigned i;
/*calculate width and height in pixels of each pass*/
- for(i = 0; i < 7; i++)
+ for(i = 0; i != 7; ++i)
{
passw[i] = (w + ADAM7_DX[i] - ADAM7_IX[i] - 1) / ADAM7_DX[i];
passh[i] = (h + ADAM7_DY[i] - ADAM7_IY[i] - 1) / ADAM7_DY[i];
@@ -3793,7 +3792,7 @@ static void Adam7_getpassvalues(unsigned passw[7], unsigned passh[7], size_t fil
}
filter_passstart[0] = padded_passstart[0] = passstart[0] = 0;
- for(i = 0; i < 7; i++)
+ for(i = 0; i != 7; ++i)
{
/*if passw[i] is 0, it's 0 bytes, not 1 (no filtertype-byte)*/
filter_passstart[i + 1] = filter_passstart[i]
@@ -3890,53 +3889,53 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
switch(filterType)
{
case 0:
- for(i = 0; i < length; i++) recon[i] = scanline[i];
+ for(i = 0; i != length; ++i) recon[i] = scanline[i];
break;
case 1:
- for(i = 0; i < bytewidth; i++) recon[i] = scanline[i];
- for(i = bytewidth; i < length; i++) recon[i] = scanline[i] + recon[i - bytewidth];
+ for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i];
+ for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + recon[i - bytewidth];
break;
case 2:
if(precon)
{
- for(i = 0; i < length; i++) recon[i] = scanline[i] + precon[i];
+ for(i = 0; i != length; ++i) recon[i] = scanline[i] + precon[i];
}
else
{
- for(i = 0; i < length; i++) recon[i] = scanline[i];
+ for(i = 0; i != length; ++i) recon[i] = scanline[i];
}
break;
case 3:
if(precon)
{
- for(i = 0; i < bytewidth; i++) recon[i] = scanline[i] + precon[i] / 2;
- for(i = bytewidth; i < length; i++) recon[i] = scanline[i] + ((recon[i - bytewidth] + precon[i]) / 2);
+ for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i] + precon[i] / 2;
+ for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + ((recon[i - bytewidth] + precon[i]) / 2);
}
else
{
- for(i = 0; i < bytewidth; i++) recon[i] = scanline[i];
- for(i = bytewidth; i < length; i++) recon[i] = scanline[i] + recon[i - bytewidth] / 2;
+ for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i];
+ for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + recon[i - bytewidth] / 2;
}
break;
case 4:
if(precon)
{
- for(i = 0; i < bytewidth; i++)
+ for(i = 0; i != bytewidth; ++i)
{
recon[i] = (scanline[i] + precon[i]); /*paethPredictor(0, precon[i], 0) is always precon[i]*/
}
- for(i = bytewidth; i < length; i++)
+ for(i = bytewidth; i < length; ++i)
{
recon[i] = (scanline[i] + paethPredictor(recon[i - bytewidth], precon[i], precon[i - bytewidth]));
}
}
else
{
- for(i = 0; i < bytewidth; i++)
+ for(i = 0; i != bytewidth; ++i)
{
recon[i] = scanline[i];
}
- for(i = bytewidth; i < length; i++)
+ for(i = bytewidth; i < length; ++i)
{
/*paethPredictor(recon[i - bytewidth], 0, 0) is always recon[i - bytewidth]*/
recon[i] = (scanline[i] + recon[i - bytewidth]);
@@ -3965,7 +3964,7 @@ static unsigned unfilter(unsigned char* out, const unsigned char* in, unsigned w
size_t bytewidth = (bpp + 7) / 8;
size_t linebytes = (w * bpp + 7) / 8;
- for(y = 0; y < h; y++)
+ for(y = 0; y < h; ++y)
{
size_t outindex = linebytes * y;
size_t inindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/
@@ -4000,16 +3999,16 @@ static void Adam7_deinterlace(unsigned char* out, const unsigned char* in, unsig
if(bpp >= 8)
{
- for(i = 0; i < 7; i++)
+ for(i = 0; i != 7; ++i)
{
unsigned x, y, b;
size_t bytewidth = bpp / 8;
- for(y = 0; y < passh[i]; y++)
- for(x = 0; x < passw[i]; x++)
+ for(y = 0; y < passh[i]; ++y)
+ for(x = 0; x < passw[i]; ++x)
{
size_t pixelinstart = passstart[i] + (y * passw[i] + x) * bytewidth;
size_t pixeloutstart = ((ADAM7_IY[i] + y * ADAM7_DY[i]) * w + ADAM7_IX[i] + x * ADAM7_DX[i]) * bytewidth;
- for(b = 0; b < bytewidth; b++)
+ for(b = 0; b < bytewidth; ++b)
{
out[pixeloutstart + b] = in[pixelinstart + b];
}
@@ -4018,18 +4017,18 @@ static void Adam7_deinterlace(unsigned char* out, const unsigned char* in, unsig
}
else /*bpp < 8: Adam7 with pixels < 8 bit is a bit trickier: with bit pointers*/
{
- for(i = 0; i < 7; i++)
+ for(i = 0; i != 7; ++i)
{
unsigned x, y, b;
unsigned ilinebits = bpp * passw[i];
unsigned olinebits = bpp * w;
size_t obp, ibp; /*bit pointers (for out and in buffer)*/
- for(y = 0; y < passh[i]; y++)
- for(x = 0; x < passw[i]; x++)
+ for(y = 0; y < passh[i]; ++y)
+ for(x = 0; x < passw[i]; ++x)
{
ibp = (8 * passstart[i]) + (y * ilinebits + x * bpp);
obp = (ADAM7_IY[i] + y * ADAM7_DY[i]) * olinebits + (ADAM7_IX[i] + x * ADAM7_DX[i]) * bpp;
- for(b = 0; b < bpp; b++)
+ for(b = 0; b < bpp; ++b)
{
unsigned char bit = readBitFromReversedStream(&ibp, in);
/*note that this function assumes the out buffer is completely 0, use setBitOfReversedStream otherwise*/
@@ -4055,10 +4054,10 @@ static void removePaddingBits(unsigned char* out, const unsigned char* in,
unsigned y;
size_t diff = ilinebits - olinebits;
size_t ibp = 0, obp = 0; /*input and output bit pointers*/
- for(y = 0; y < h; y++)
+ for(y = 0; y < h; ++y)
{
size_t x;
- for(x = 0; x < olinebits; x++)
+ for(x = 0; x < olinebits; ++x)
{
unsigned char bit = readBitFromReversedStream(&ibp, in);
setBitOfReversedStream(&obp, out, bit);
@@ -4100,7 +4099,7 @@ static unsigned postProcessScanlines(unsigned char* out, unsigned char* in,
Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp);
- for(i = 0; i < 7; i++)
+ for(i = 0; i != 7; ++i)
{
CERROR_TRY_RETURN(unfilter(&in[padded_passstart[i]], &in[filter_passstart[i]], passw[i], passh[i], bpp));
/*TODO: possible efficiency improvement: if in this reduced image the bits fit nicely in 1 scanline,
@@ -4133,7 +4132,7 @@ static unsigned readChunk_PLTE(LodePNGColorMode* color, const unsigned char* dat
}
if(color->palettesize > 256) return 38; /*error: palette too big*/
- for(i = 0; i < color->palettesize; i++)
+ for(i = 0; i != color->palettesize; ++i)
{
color->palette[4 * i + 0] = data[pos++]; /*R*/
color->palette[4 * i + 1] = data[pos++]; /*G*/
@@ -4152,7 +4151,7 @@ static unsigned readChunk_tRNS(LodePNGColorMode* color, const unsigned char* dat
/*error: more alpha values given than there are palette entries*/
if(chunkLength > color->palettesize) return 38;
- for(i = 0; i < chunkLength; i++) color->palette[4 * i + 3] = data[i];
+ for(i = 0; i != chunkLength; ++i) color->palette[4 * i + 3] = data[i];
}
else if(color->colortype == LCT_GREY)
{
@@ -4224,7 +4223,7 @@ static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, siz
unsigned length, string2_begin;
length = 0;
- while(length < chunkLength && data[length] != 0) length++;
+ while(length < chunkLength && data[length] != 0) ++length;
/*even though it's not allowed by the standard, no error is thrown if
there's no null termination char, if the text is empty*/
if(length < 1 || length > 79) CERROR_BREAK(error, 89); /*keyword too short or long*/
@@ -4233,7 +4232,7 @@ static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, siz
if(!key) CERROR_BREAK(error, 83); /*alloc fail*/
key[length] = 0;
- for(i = 0; i < length; i++) key[i] = (char)data[i];
+ for(i = 0; i != length; ++i) key[i] = (char)data[i];
string2_begin = length + 1; /*skip keyword null terminator*/
@@ -4242,7 +4241,7 @@ static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, siz
if(!str) CERROR_BREAK(error, 83); /*alloc fail*/
str[length] = 0;
- for(i = 0; i < length; i++) str[i] = (char)data[string2_begin + i];
+ for(i = 0; i != length; ++i) str[i] = (char)data[string2_begin + i];
error = lodepng_add_text(info, key, str);
@@ -4270,7 +4269,7 @@ static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSetting
while(!error) /*not really a while loop, only used to break on error*/
{
- for(length = 0; length < chunkLength && data[length] != 0; length++) ;
+ for(length = 0; length < chunkLength && data[length] != 0; ++length) ;
if(length + 2 >= chunkLength) CERROR_BREAK(error, 75); /*no null termination, corrupt?*/
if(length < 1 || length > 79) CERROR_BREAK(error, 89); /*keyword too short or long*/
@@ -4278,7 +4277,7 @@ static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSetting
if(!key) CERROR_BREAK(error, 83); /*alloc fail*/
key[length] = 0;
- for(i = 0; i < length; i++) key[i] = (char)data[i];
+ for(i = 0; i != length; ++i) key[i] = (char)data[i];
if(data[length + 1] != 0) CERROR_BREAK(error, 72); /*the 0 byte indicating compression must be 0*/
@@ -4323,7 +4322,7 @@ static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSetting
if(chunkLength < 5) CERROR_BREAK(error, 30); /*iTXt chunk too short*/
/*read the key*/
- for(length = 0; length < chunkLength && data[length] != 0; length++) ;
+ for(length = 0; length < chunkLength && data[length] != 0; ++length) ;
if(length + 3 >= chunkLength) CERROR_BREAK(error, 75); /*no null termination char, corrupt?*/
if(length < 1 || length > 79) CERROR_BREAK(error, 89); /*keyword too short or long*/
@@ -4331,7 +4330,7 @@ static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSetting
if(!key) CERROR_BREAK(error, 83); /*alloc fail*/
key[length] = 0;
- for(i = 0; i < length; i++) key[i] = (char)data[i];
+ for(i = 0; i != length; ++i) key[i] = (char)data[i];
/*read the compression method*/
compressed = data[length + 1];
@@ -4343,24 +4342,24 @@ static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSetting
/*read the langtag*/
begin = length + 3;
length = 0;
- for(i = begin; i < chunkLength && data[i] != 0; i++) length++;
+ for(i = begin; i < chunkLength && data[i] != 0; ++i) ++length;
langtag = (char*)lodepng_malloc(length + 1);
if(!langtag) CERROR_BREAK(error, 83); /*alloc fail*/
langtag[length] = 0;
- for(i = 0; i < length; i++) langtag[i] = (char)data[begin + i];
+ for(i = 0; i != length; ++i) langtag[i] = (char)data[begin + i];
/*read the transkey*/
begin += length + 1;
length = 0;
- for(i = begin; i < chunkLength && data[i] != 0; i++) length++;
+ for(i = begin; i < chunkLength && data[i] != 0; ++i) ++length;
transkey = (char*)lodepng_malloc(length + 1);
if(!transkey) CERROR_BREAK(error, 83); /*alloc fail*/
transkey[length] = 0;
- for(i = 0; i < length; i++) transkey[i] = (char)data[begin + i];
+ for(i = 0; i != length; ++i) transkey[i] = (char)data[begin + i];
/*read the actual text*/
begin += length + 1;
@@ -4382,7 +4381,7 @@ static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSetting
if(!ucvector_resize(&decoded, length + 1)) CERROR_BREAK(error, 83 /*alloc fail*/);
decoded.data[length] = 0;
- for(i = 0; i < length; i++) decoded.data[i] = data[begin + i];
+ for(i = 0; i != length; ++i) decoded.data[i] = data[begin + i];
}
error = lodepng_add_itext(info, key, langtag, transkey, (char*)decoded.data);
@@ -4489,7 +4488,7 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
{
size_t oldsize = idat.size;
if(!ucvector_resize(&idat, oldsize + chunkLength)) CERROR_BREAK(state->error, 83 /*alloc fail*/);
- for(i = 0; i < chunkLength; i++) idat.data[oldsize + i] = data[i];
+ for(i = 0; i != chunkLength; ++i) idat.data[oldsize + i] = data[i];
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
critical_pos = 3;
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
@@ -4817,7 +4816,7 @@ static unsigned addChunk_PLTE(ucvector* out, const LodePNGColorMode* info)
size_t i;
ucvector PLTE;
ucvector_init(&PLTE);
- for(i = 0; i < info->palettesize * 4; i++)
+ for(i = 0; i != info->palettesize * 4; ++i)
{
/*add all channels except alpha channel*/
if(i % 4 != 3) ucvector_push_back(&PLTE, info->palette[i]);
@@ -4838,13 +4837,13 @@ static unsigned addChunk_tRNS(ucvector* out, const LodePNGColorMode* info)
{
size_t amount = info->palettesize;
/*the tail of palette values that all have 255 as alpha, does not have to be encoded*/
- for(i = info->palettesize; i > 0; i--)
+ for(i = info->palettesize; i != 0; --i)
{
- if(info->palette[4 * (i - 1) + 3] == 255) amount--;
+ if(info->palette[4 * (i - 1) + 3] == 255) --amount;
else break;
}
/*add only alpha channel*/
- for(i = 0; i < amount; i++) ucvector_push_back(&tRNS, info->palette[4 * i + 3]);
+ for(i = 0; i != amount; ++i) ucvector_push_back(&tRNS, info->palette[4 * i + 3]);
}
else if(info->colortype == LCT_GREY)
{
@@ -4903,10 +4902,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, (unsigned char)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, (unsigned char)textstring[i]);
error = addChunk(out, "tEXt", text.data, text.size);
ucvector_cleanup(&text);
@@ -4922,7 +4921,7 @@ 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, (unsigned char)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*/
@@ -4931,7 +4930,7 @@ static unsigned addChunk_zTXt(ucvector* out, const char* keyword, const char* te
(unsigned char*)textstring, textsize, zlibsettings);
if(!error)
{
- for(i = 0; i < compressed.size; i++) ucvector_push_back(&data, compressed.data[i]);
+ for(i = 0; i != compressed.size; ++i) ucvector_push_back(&data, compressed.data[i]);
error = addChunk(out, "zTXt", data.data, data.size);
}
@@ -4949,14 +4948,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, (unsigned char)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, (unsigned char)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, (unsigned char)transkey[i]);
ucvector_push_back(&data, 0); /*null termination char*/
if(compressed)
@@ -4967,13 +4966,13 @@ static unsigned addChunk_iTXt(ucvector* out, unsigned compressed, const char* ke
(unsigned char*)textstring, textsize, zlibsettings);
if(!error)
{
- for(i = 0; i < compressed_data.size; i++) ucvector_push_back(&data, compressed_data.data[i]);
+ for(i = 0; i != compressed_data.size; ++i) ucvector_push_back(&data, compressed_data.data[i]);
}
ucvector_cleanup(&compressed_data);
}
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, (unsigned char)textstring[i]);
}
if(!error) error = addChunk(out, "iTXt", data.data, data.size);
@@ -5053,49 +5052,49 @@ static void filterScanline(unsigned char* out, const unsigned char* scanline, co
switch(filterType)
{
case 0: /*None*/
- for(i = 0; i < length; i++) out[i] = scanline[i];
+ for(i = 0; i != length; ++i) out[i] = scanline[i];
break;
case 1: /*Sub*/
- for(i = 0; i < bytewidth; i++) out[i] = scanline[i];
- for(i = bytewidth; i < length; i++) out[i] = scanline[i] - scanline[i - bytewidth];
+ for(i = 0; i != bytewidth; ++i) out[i] = scanline[i];
+ for(i = bytewidth; i < length; ++i) out[i] = scanline[i] - scanline[i - bytewidth];
break;
case 2: /*Up*/
if(prevline)
{
- for(i = 0; i < length; i++) out[i] = scanline[i] - prevline[i];
+ for(i = 0; i != length; ++i) out[i] = scanline[i] - prevline[i];
}
else
{
- for(i = 0; i < length; i++) out[i] = scanline[i];
+ for(i = 0; i != length; ++i) out[i] = scanline[i];
}
break;
case 3: /*Average*/
if(prevline)
{
- for(i = 0; i < bytewidth; i++) out[i] = scanline[i] - prevline[i] / 2;
- for(i = bytewidth; i < length; i++) out[i] = scanline[i] - ((scanline[i - bytewidth] + prevline[i]) / 2);
+ for(i = 0; i != bytewidth; ++i) out[i] = scanline[i] - prevline[i] / 2;
+ for(i = bytewidth; i < length; ++i) out[i] = scanline[i] - ((scanline[i - bytewidth] + prevline[i]) / 2);
}
else
{
- for(i = 0; i < bytewidth; i++) out[i] = scanline[i];
- for(i = bytewidth; i < length; i++) out[i] = scanline[i] - scanline[i - bytewidth] / 2;
+ for(i = 0; i != bytewidth; ++i) out[i] = scanline[i];
+ for(i = bytewidth; i < length; ++i) out[i] = scanline[i] - scanline[i - bytewidth] / 2;
}
break;
case 4: /*Paeth*/
if(prevline)
{
/*paethPredictor(0, prevline[i], 0) is always prevline[i]*/
- for(i = 0; i < bytewidth; i++) out[i] = (scanline[i] - prevline[i]);
- for(i = bytewidth; i < length; i++)
+ for(i = 0; i != bytewidth; ++i) out[i] = (scanline[i] - prevline[i]);
+ for(i = bytewidth; i < length; ++i)
{
out[i] = (scanline[i] - paethPredictor(scanline[i - bytewidth], prevline[i], prevline[i - bytewidth]));
}
}
else
{
- for(i = 0; i < bytewidth; i++) out[i] = scanline[i];
+ for(i = 0; i != bytewidth; ++i) out[i] = scanline[i];
/*paethPredictor(scanline[i - bytewidth], 0, 0) is always scanline[i - bytewidth]*/
- for(i = bytewidth; i < length; i++) out[i] = (scanline[i] - scanline[i - bytewidth]);
+ for(i = bytewidth; i < length; ++i) out[i] = (scanline[i] - scanline[i - bytewidth]);
}
break;
default: return; /*unexisting filter type given*/
@@ -5107,7 +5106,7 @@ static float flog2(float f)
{
float result = 0;
while(f > 32) { result += 4; f /= 16; }
- while(f > 2) { result++; f /= 2; }
+ while(f > 2) { ++result; f /= 2; }
return result + 1.442695f * (f * f * f / 3 - 3 * f * f / 2 + 3 * f - 1.83333f);
}
@@ -5150,7 +5149,7 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
if(strategy == LFS_ZERO)
{
- for(y = 0; y < h; y++)
+ for(y = 0; y != h; ++y)
{
size_t outindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/
size_t inindex = linebytes * y;
@@ -5167,7 +5166,7 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
size_t smallest = 0;
unsigned char type, bestType = 0;
- for(type = 0; type < 5; type++)
+ for(type = 0; type != 5; ++type)
{
ucvector_init(&attempt[type]);
if(!ucvector_resize(&attempt[type], linebytes)) return 83; /*alloc fail*/
@@ -5175,10 +5174,10 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
if(!error)
{
- for(y = 0; y < h; y++)
+ for(y = 0; y != h; ++y)
{
/*try the 5 filter types*/
- for(type = 0; type < 5; type++)
+ for(type = 0; type != 5; ++type)
{
filterScanline(attempt[type].data, &in[y * linebytes], prevline, linebytes, bytewidth, type);
@@ -5186,11 +5185,11 @@ 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].data[x]);
+ for(x = 0; x != linebytes; ++x) sum[type] += (unsigned char)(attempt[type].data[x]);
}
else
{
- for(x = 0; x < linebytes; x++)
+ for(x = 0; x != linebytes; ++x)
{
/*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.
@@ -5212,11 +5211,11 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
/*now fill the out values*/
out[y * (linebytes + 1)] = bestType; /*the first byte of a scanline will be the filter type*/
- for(x = 0; x < linebytes; x++) out[y * (linebytes + 1) + 1 + x] = attempt[bestType].data[x];
+ for(x = 0; x != linebytes; ++x) out[y * (linebytes + 1) + 1 + x] = attempt[bestType].data[x];
}
}
- for(type = 0; type < 5; type++) ucvector_cleanup(&attempt[type]);
+ for(type = 0; type != 5; ++type) ucvector_cleanup(&attempt[type]);
}
else if(strategy == LFS_ENTROPY)
{
@@ -5226,23 +5225,23 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
unsigned type, bestType = 0;
unsigned count[256];
- for(type = 0; type < 5; type++)
+ for(type = 0; type != 5; ++type)
{
ucvector_init(&attempt[type]);
if(!ucvector_resize(&attempt[type], linebytes)) return 83; /*alloc fail*/
}
- for(y = 0; y < h; y++)
+ for(y = 0; y != h; ++y)
{
/*try the 5 filter types*/
- for(type = 0; type < 5; type++)
+ for(type = 0; type != 5; ++type)
{
filterScanline(attempt[type].data, &in[y * linebytes], prevline, linebytes, bytewidth, type);
- for(x = 0; x < 256; x++) count[x] = 0;
- for(x = 0; x < linebytes; x++) count[attempt[type].data[x]]++;
- count[type]++; /*the filter type itself is part of the scanline*/
+ for(x = 0; x != 256; ++x) count[x] = 0;
+ for(x = 0; x != linebytes; ++x) ++count[attempt[type].data[x]];
+ ++count[type]; /*the filter type itself is part of the scanline*/
sum[type] = 0;
- for(x = 0; x < 256; x++)
+ for(x = 0; x != 256; ++x)
{
float p = count[x] / (float)(linebytes + 1);
sum[type] += count[x] == 0 ? 0 : flog2(1 / p) * p;
@@ -5259,14 +5258,14 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
/*now fill the out values*/
out[y * (linebytes + 1)] = bestType; /*the first byte of a scanline will be the filter type*/
- for(x = 0; x < linebytes; x++) out[y * (linebytes + 1) + 1 + x] = attempt[bestType].data[x];
+ for(x = 0; x != linebytes; ++x) out[y * (linebytes + 1) + 1 + x] = attempt[bestType].data[x];
}
- for(type = 0; type < 5; type++) ucvector_cleanup(&attempt[type]);
+ for(type = 0; type != 5; ++type) ucvector_cleanup(&attempt[type]);
}
else if(strategy == LFS_PREDEFINED)
{
- for(y = 0; y < h; y++)
+ for(y = 0; y != h; ++y)
{
size_t outindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/
size_t inindex = linebytes * y;
@@ -5296,14 +5295,14 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
images only, so disable it*/
zlibsettings.custom_zlib = 0;
zlibsettings.custom_deflate = 0;
- for(type = 0; type < 5; type++)
+ for(type = 0; type != 5; ++type)
{
ucvector_init(&attempt[type]);
ucvector_resize(&attempt[type], linebytes); /*todo: give error if resize failed*/
}
- for(y = 0; y < h; y++) /*try the 5 filter types*/
+ for(y = 0; y != h; ++y) /*try the 5 filter types*/
{
- for(type = 0; type < 5; type++)
+ for(type = 0; type != 5; ++type)
{
unsigned testsize = attempt[type].size;
/*if(testsize > 8) testsize /= 8;*/ /*it already works good enough by testing a part of the row*/
@@ -5322,9 +5321,9 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
}
prevline = &in[y * linebytes];
out[y * (linebytes + 1)] = bestType; /*the first byte of a scanline will be the filter type*/
- for(x = 0; x < linebytes; x++) out[y * (linebytes + 1) + 1 + x] = attempt[bestType].data[x];
+ for(x = 0; x != linebytes; ++x) out[y * (linebytes + 1) + 1 + x] = attempt[bestType].data[x];
}
- for(type = 0; type < 5; type++) ucvector_cleanup(&attempt[type]);
+ for(type = 0; type != 5; ++type) ucvector_cleanup(&attempt[type]);
}
else return 88; /* unknown filter strategy */
@@ -5339,17 +5338,17 @@ static void addPaddingBits(unsigned char* out, const unsigned char* in,
unsigned y;
size_t diff = olinebits - ilinebits;
size_t obp = 0, ibp = 0; /*bit pointers*/
- for(y = 0; y < h; y++)
+ for(y = 0; y != h; ++y)
{
size_t x;
- for(x = 0; x < ilinebits; x++)
+ for(x = 0; x < ilinebits; ++x)
{
unsigned char bit = readBitFromReversedStream(&ibp, in);
setBitOfReversedStream(&obp, out, bit);
}
/*obp += diff; --> no, fill in some value in the padding bits too, to avoid
"Use of uninitialised value of size ###" warning from valgrind*/
- for(x = 0; x < diff; x++) setBitOfReversedStream(&obp, out, 0);
+ for(x = 0; x != diff; ++x) setBitOfReversedStream(&obp, out, 0);
}
}
@@ -5374,16 +5373,16 @@ static void Adam7_interlace(unsigned char* out, const unsigned char* in, unsigne
if(bpp >= 8)
{
- for(i = 0; i < 7; i++)
+ for(i = 0; i != 7; ++i)
{
unsigned x, y, b;
size_t bytewidth = bpp / 8;
- for(y = 0; y < passh[i]; y++)
- for(x = 0; x < passw[i]; x++)
+ for(y = 0; y < passh[i]; ++y)
+ for(x = 0; x < passw[i]; ++x)
{
size_t pixelinstart = ((ADAM7_IY[i] + y * ADAM7_DY[i]) * w + ADAM7_IX[i] + x * ADAM7_DX[i]) * bytewidth;
size_t pixeloutstart = passstart[i] + (y * passw[i] + x) * bytewidth;
- for(b = 0; b < bytewidth; b++)
+ for(b = 0; b < bytewidth; ++b)
{
out[pixeloutstart + b] = in[pixelinstart + b];
}
@@ -5392,18 +5391,18 @@ static void Adam7_interlace(unsigned char* out, const unsigned char* in, unsigne
}
else /*bpp < 8: Adam7 with pixels < 8 bit is a bit trickier: with bit pointers*/
{
- for(i = 0; i < 7; i++)
+ for(i = 0; i != 7; ++i)
{
unsigned x, y, b;
unsigned ilinebits = bpp * passw[i];
unsigned olinebits = bpp * w;
size_t obp, ibp; /*bit pointers (for out and in buffer)*/
- for(y = 0; y < passh[i]; y++)
- for(x = 0; x < passw[i]; x++)
+ for(y = 0; y < passh[i]; ++y)
+ for(x = 0; x < passw[i]; ++x)
{
ibp = (ADAM7_IY[i] + y * ADAM7_DY[i]) * olinebits + (ADAM7_IX[i] + x * ADAM7_DX[i]) * bpp;
obp = (8 * passstart[i]) + (y * ilinebits + x * bpp);
- for(b = 0; b < bpp; b++)
+ for(b = 0; b < bpp; ++b)
{
unsigned char bit = readBitFromReversedStream(&ibp, in);
setBitOfReversedStream(&obp, out, bit);
@@ -5474,7 +5473,7 @@ static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const
unsigned i;
Adam7_interlace(adam7, in, w, h, bpp);
- for(i = 0; i < 7; i++)
+ for(i = 0; i != 7; ++i)
{
if(bpp < 8)
{
@@ -5513,7 +5512,7 @@ static unsigned getPaletteTranslucency(const unsigned char* palette, size_t pale
size_t i;
unsigned key = 0;
unsigned r = 0, g = 0, b = 0; /*the value of the color with alpha 0, so long as color keying is possible*/
- for(i = 0; i < palettesize; i++)
+ for(i = 0; i != palettesize; ++i)
{
if(!key && palette[4 * i + 3] == 0)
{
@@ -5658,7 +5657,7 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
/*tIME*/
if(info.time_defined) addChunk_tIME(&outv, &info.time);
/*tEXt and/or zTXt*/
- for(i = 0; i < info.text_num; i++)
+ for(i = 0; i != info.text_num; ++i)
{
if(strlen(info.text_keys[i]) > 79)
{
@@ -5683,7 +5682,7 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
if(state->encoder.add_id)
{
unsigned alread_added_id_text = 0;
- for(i = 0; i < info.text_num; i++)
+ for(i = 0; i != info.text_num; ++i)
{
if(!strcmp(info.text_keys[i], "LodePNG"))
{
@@ -5697,7 +5696,7 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
}
}
/*iTXt*/
- for(i = 0; i < info.itext_num; i++)
+ for(i = 0; i != info.itext_num; ++i)
{
if(strlen(info.itext_keys[i]) > 79)
{