MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / decodeGeneric

Function decodeGeneric

samples/cgpu/cgpu-basic/mandelbrot/lodepng.c:4523–4722  ·  view source on GitHub ↗

read a PNG, the result will be in the same color type as the PNG (hence "generic")*/

Source from the content-addressed store, hash-verified

4521
4522/*read a PNG, the result will be in the same color type as the PNG (hence "generic")*/
4523static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
4524 LodePNGState* state,
4525 const unsigned char* in, size_t insize)
4526{
4527 unsigned char IEND = 0;
4528 const unsigned char* chunk;
4529 size_t i;
4530 ucvector idat; /*the data from idat chunks*/
4531 ucvector scanlines;
4532 size_t predict;
4533 size_t numpixels;
4534 size_t outsize = 0;
4535
4536 /*for unknown chunk order*/
4537 unsigned unknown = 0;
4538#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
4539 unsigned critical_pos = 1; /*1 = after IHDR, 2 = after PLTE, 3 = after IDAT*/
4540#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
4541
4542 /*provide some proper output values if error will happen*/
4543 *out = 0;
4544
4545 state->error = lodepng_inspect(w, h, state, in, insize); /*reads header and resets other parameters in state->info_png*/
4546 if(state->error) return;
4547
4548 numpixels = *w * *h;
4549
4550 /*multiplication overflow*/
4551 if(*h != 0 && numpixels / *h != *w) CERROR_RETURN(state->error, 92);
4552 /*multiplication overflow possible further below. Allows up to 2^31-1 pixel
4553 bytes with 16-bit RGBA, the rest is room for filter bytes.*/
4554 if(numpixels > 268435455) CERROR_RETURN(state->error, 92);
4555
4556 ucvector_init(&idat);
4557 chunk = &in[33]; /*first byte of the first chunk after the header*/
4558
4559 /*loop through the chunks, ignoring unknown chunks and stopping at IEND chunk.
4560 IDAT data is put at the start of the in buffer*/
4561 while(!IEND && !state->error)
4562 {
4563 unsigned chunkLength;
4564 const unsigned char* data; /*the data in the chunk*/
4565
4566 /*error: size of the in buffer too small to contain next chunk*/
4567 if((size_t)((chunk - in) + 12) > insize || chunk < in) CERROR_BREAK(state->error, 30);
4568
4569 /*length of the data of the chunk, excluding the length bytes, chunk type and CRC bytes*/
4570 chunkLength = lodepng_chunk_length(chunk);
4571 /*error: chunk length larger than the max PNG chunk size*/
4572 if(chunkLength > 2147483647) CERROR_BREAK(state->error, 63);
4573
4574 if((size_t)((chunk - in) + chunkLength + 12) > insize || (chunk + chunkLength + 12) < in)
4575 {
4576 CERROR_BREAK(state->error, 64); /*error: size of the in buffer too small to contain next chunk*/
4577 }
4578
4579 data = lodepng_chunk_data_const(chunk);
4580

Callers 1

lodepng_decodeFunction · 0.85

Calls 15

lodepng_inspectFunction · 0.85
ucvector_initFunction · 0.85
lodepng_chunk_lengthFunction · 0.85
lodepng_chunk_data_constFunction · 0.85
ucvector_resizeFunction · 0.85
readChunk_PLTEFunction · 0.85
readChunk_tRNSFunction · 0.85
lodepng_chunk_ancillaryFunction · 0.85
lodepng_chunk_appendFunction · 0.85
lodepng_chunk_check_crcFunction · 0.85
lodepng_chunk_next_constFunction · 0.85

Tested by

no test coverage detected