summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lodepng.cpp518
1 files changed, 255 insertions, 263 deletions
diff --git a/lodepng.cpp b/lodepng.cpp
index e1d6dbe..1b1a0bd 100644
--- a/lodepng.cpp
+++ b/lodepng.cpp
@@ -174,7 +174,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;
}
@@ -198,7 +198,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*/
@@ -260,7 +260,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*/
@@ -319,10 +319,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);
if(string_resize(out, insize))
{
- for(i = 0; i < insize; i++)
+ for(size_t i = 0; i != insize; ++i)
{
(*out)[i] = in[i];
}
@@ -418,19 +418,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*/
@@ -441,17 +441,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;
}
@@ -514,7 +514,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;
@@ -556,14 +556,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);
if(treepos > tree->numcodes - 2) return 55; /*oversubscribed, see comment in lodepng_error_text*/
@@ -578,7 +578,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;
@@ -588,7 +588,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*/
}
@@ -605,7 +605,7 @@ static unsigned HuffmanTree_makeFromLengths2(HuffmanTree* tree)
{
uivector blcount;
uivector nextcode;
- unsigned bits, n, error = 0;
+ unsigned error = 0;
uivector_init(&blcount);
uivector_init(&nextcode);
@@ -620,16 +620,16 @@ 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(unsigned 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(unsigned 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(unsigned n = 0; n != tree->numcodes; ++n)
{
- if(tree->lengths[n] != 0) tree->tree1d[n] = nextcode.data[tree->lengths[n]]++;
+ if(tree->lengths[n] != 0) tree->tree1d[n] = ++nextcode.data[tree->lengths[n]];
}
}
@@ -651,7 +651,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);
@@ -690,20 +690,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) {
@@ -716,13 +716,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;
@@ -741,16 +741,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
@@ -763,7 +763,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])
{
@@ -797,7 +797,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;
@@ -831,10 +831,10 @@ 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 < numpresent - 1; i++)
+ for(i = 0; i != numpresent - 1; ++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]];
}
}
@@ -852,7 +852,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));
@@ -884,10 +884,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);
@@ -903,7 +903,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);
@@ -928,7 +928,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*/
@@ -987,7 +987,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*/
@@ -1000,8 +1000,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;
@@ -1012,7 +1012,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*/
{
@@ -1027,12 +1027,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*/
@@ -1042,13 +1042,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*/
@@ -1058,13 +1058,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*/
@@ -1123,7 +1123,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*/
{
@@ -1165,11 +1165,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;
}
}
@@ -1197,7 +1197,7 @@ static unsigned inflateNoCompression(ucvector* out, const unsigned char* in, siz
/*go to first boundary of byte*/
size_t p;
unsigned LEN, NLEN, n, error = 0;
- while(((*bp) & 0x7) != 0) (*bp)++;
+ while(((*bp) & 0x7) != 0) ++(*bp);
p = (*bp) / 8; /*byte position*/
/*read LEN (2 bytes) and NLEN (2 bytes)*/
@@ -1212,7 +1212,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;
@@ -1297,7 +1297,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)*/
@@ -1368,12 +1368,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;
}
@@ -1407,7 +1407,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;
}
@@ -1418,7 +1418,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);
}
@@ -1472,7 +1472,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;
@@ -1482,7 +1482,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
{
@@ -1541,7 +1541,7 @@ static unsigned encodeLZ77(uivector* out, Hash* hash,
}
if(hashpos == hash->chain[hashpos]) break;
-
+
if(numzeros >= 3 && length > numzeros) {
hashpos = hash->chainz[hashpos];
if(hash->zeros[hashpos] != numzeros) break;
@@ -1576,7 +1576,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;
}
}
}
@@ -1596,15 +1596,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
{
@@ -1627,7 +1627,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;
@@ -1648,7 +1648,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++]);
}
@@ -1666,7 +1666,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));
@@ -1759,21 +1759,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;
}
}
@@ -1789,19 +1789,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);
@@ -1820,7 +1820,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);
@@ -1842,12 +1842,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,
@@ -1855,7 +1855,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]);
@@ -1891,16 +1891,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]));
@@ -1946,7 +1946,6 @@ static unsigned deflateFixed(ucvector* out, size_t* bp, Hash* hash,
unsigned BFINAL = final;
unsigned error = 0;
- size_t i;
HuffmanTree_init(&tree_ll);
HuffmanTree_init(&tree_d);
@@ -1969,7 +1968,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(size_t i = datapos; i < dataend; ++i)
{
addHuffmanSymbol(bp, out, HuffmanTree_getCode(&tree_ll, data[i]), HuffmanTree_getLength(&tree_ll, data[i]));
}
@@ -2007,7 +2006,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;
@@ -2070,7 +2069,7 @@ static unsigned update_adler32(unsigned adler, const unsigned char* data, unsign
{
s1 += (*data++);
s2 += s1;
- amount--;
+ --amount;
}
s1 %= 65521;
s2 %= 65521;
@@ -2159,12 +2158,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;
- 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;
@@ -2183,8 +2180,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(size_t i = 0; i != deflatesize; ++i) ucvector_push_back(&outv, deflatedata[i]);
lodepng_free(deflatedata);
lodepng_add32bitInt(&outv, ADLER32);
}
@@ -2328,7 +2325,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);
}
@@ -2342,15 +2339,14 @@ 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;
}
static unsigned readBitsFromReversedStream(size_t* bitpointer, const unsigned char* bitstream, size_t nbits)
{
unsigned result = 0;
- size_t i;
- for(i = nbits - 1; i < nbits; i--)
+ for(size_t i = nbits - 1; i < nbits; --i)
{
result += (unsigned)readBitFromReversedStream(bitpointer, bitstream) << i;
}
@@ -2366,7 +2362,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*/
@@ -2375,7 +2371,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);
}
/* ////////////////////////////////////////////////////////////////////////// */
@@ -2390,7 +2386,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*/
}
@@ -2468,7 +2464,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;
}
@@ -2496,7 +2492,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);
@@ -2561,14 +2557,13 @@ void lodepng_color_mode_cleanup(LodePNGColorMode* info)
unsigned lodepng_color_mode_copy(LodePNGColorMode* dest, const LodePNGColorMode* source)
{
- size_t i;
lodepng_color_mode_cleanup(dest);
*dest = *source;
if(source->palette)
{
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(size_t i = 0; i != source->palettesize * 4; ++i) dest->palette[i] = source->palette[i];
}
return 0;
}
@@ -2586,7 +2581,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;
}
@@ -2617,7 +2612,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;
}
@@ -2650,7 +2645,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;
}
@@ -2690,14 +2685,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)
@@ -2706,13 +2701,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];
}
@@ -2733,7 +2728,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]);
@@ -2748,7 +2743,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]));
}
@@ -2771,7 +2766,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;
@@ -2798,7 +2793,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]);
@@ -2819,7 +2814,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]));
@@ -2848,7 +2843,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;
@@ -2956,14 +2951,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])
{
@@ -2977,7 +2972,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;
@@ -2999,7 +2994,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])
@@ -3248,7 +3243,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;
@@ -3256,7 +3251,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;
@@ -3266,7 +3261,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;
@@ -3278,7 +3273,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];
@@ -3289,7 +3284,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];
@@ -3305,7 +3300,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);
@@ -3330,7 +3325,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];
@@ -3338,7 +3333,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];
@@ -3349,7 +3344,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];
@@ -3359,7 +3354,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];
@@ -3416,7 +3411,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;
}
@@ -3425,7 +3420,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);
@@ -3434,7 +3429,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);
@@ -3452,7 +3447,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);
@@ -3527,7 +3522,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) ||
@@ -3545,10 +3540,10 @@ 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);
-
+
if(!colored_done && (r != g || r != b))
{
profile->colored = 1;
@@ -3584,7 +3579,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);
@@ -3643,7 +3638,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;
}
}
@@ -3672,7 +3667,7 @@ unsigned lodepng_auto_choose_color(LodePNGColorMode* mode_out,
{
LodePNGColorProfile prof;
unsigned error = 0;
- unsigned i, n, palettebits, grey_ok, palette_ok;
+ unsigned n, palettebits, grey_ok, palette_ok;
lodepng_color_profile_init(&prof);
error = lodepng_get_color_profile(&prof, image, w, h, mode_in);
@@ -3694,7 +3689,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(unsigned 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;
@@ -3777,7 +3772,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];
@@ -3786,7 +3781,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]
@@ -3878,53 +3873,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]);
@@ -3953,7 +3948,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*/
@@ -3988,16 +3983,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];
}
@@ -4006,18 +4001,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*/
@@ -4043,10 +4038,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);
@@ -4088,7 +4083,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,
@@ -4110,7 +4105,7 @@ static unsigned postProcessScanlines(unsigned char* out, unsigned char* in,
static unsigned readChunk_PLTE(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength)
{
- unsigned pos = 0, i;
+ unsigned pos = 0;
if(color->palette) lodepng_free(color->palette);
color->palettesize = chunkLength / 3;
color->palette = (unsigned char*)lodepng_malloc(4 * color->palettesize);
@@ -4121,7 +4116,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(unsigned i = 0; i != color->palettesize; ++i)
{
color->palette[4 * i + 0] = data[pos++]; /*R*/
color->palette[4 * i + 1] = data[pos++]; /*G*/
@@ -4134,13 +4129,12 @@ static unsigned readChunk_PLTE(LodePNGColorMode* color, const unsigned char* dat
static unsigned readChunk_tRNS(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength)
{
- unsigned i;
if(color->colortype == LCT_PALETTE)
{
/*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(unsigned i = 0; i != chunkLength; ++i) color->palette[4 * i + 3] = data[i];
}
else if(color->colortype == LCT_GREY)
{
@@ -4212,7 +4206,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*/
@@ -4221,7 +4215,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*/
@@ -4230,7 +4224,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);
@@ -4258,7 +4252,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*/
@@ -4266,7 +4260,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*/
@@ -4311,7 +4305,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*/
@@ -4319,7 +4313,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];
@@ -4331,24 +4325,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;
@@ -4370,7 +4364,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);
@@ -4476,7 +4470,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*/
@@ -4801,10 +4795,9 @@ static unsigned addChunk_IHDR(ucvector* out, unsigned w, unsigned h,
static unsigned addChunk_PLTE(ucvector* out, const LodePNGColorMode* info)
{
unsigned error = 0;
- size_t i;
ucvector PLTE;
ucvector_init(&PLTE);
- for(i = 0; i < info->palettesize * 4; i++)
+ for(size_t i = 0; i != info->palettesize * 4; ++i)
{
/*add all channels except alpha channel*/
if(i % 4 != 3) ucvector_push_back(&PLTE, info->palette[i]);
@@ -4818,20 +4811,19 @@ static unsigned addChunk_PLTE(ucvector* out, const LodePNGColorMode* info)
static unsigned addChunk_tRNS(ucvector* out, const LodePNGColorMode* info)
{
unsigned error = 0;
- size_t i;
ucvector tRNS;
ucvector_init(&tRNS);
if(info->colortype == LCT_PALETTE)
{
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(size_t 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(size_t i = 0; i != amount; ++i) ucvector_push_back(&tRNS, info->palette[4 * i + 3]);
}
else if(info->colortype == LCT_GREY)
{
@@ -4890,10 +4882,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);
@@ -4909,7 +4901,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*/
@@ -4918,7 +4910,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);
}
@@ -4936,14 +4928,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)
@@ -4954,13 +4946,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);
@@ -5040,49 +5032,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*/
@@ -5094,7 +5086,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);
}
@@ -5137,7 +5129,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;
@@ -5154,7 +5146,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*/
@@ -5162,10 +5154,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);
@@ -5173,11 +5165,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.
@@ -5199,11 +5191,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)
{
@@ -5213,23 +5205,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;
@@ -5246,14 +5238,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;
@@ -5283,14 +5275,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*/
@@ -5309,9 +5301,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 */
@@ -5326,17 +5318,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);
}
}
@@ -5361,16 +5353,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];
}
@@ -5379,18 +5371,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);
@@ -5461,7 +5453,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)
{
@@ -5500,7 +5492,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)
{
@@ -5645,7 +5637,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)
{
@@ -5670,7 +5662,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"))
{
@@ -5684,7 +5676,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)
{