Home | History | Annotate | Download | only in lodepng

Lines Matching refs:chunk

2362 unsigned lodepng_chunk_length(const unsigned char* chunk)
2364 return lodepng_read32bitInt(&chunk[0]);
2367 void lodepng_chunk_type(char type[5], const unsigned char* chunk)
2370 for(i = 0; i < 4; i++) type[i] = chunk[4 + i];
2374 unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type)
2377 return (chunk[4] == type[0] && chunk[5] == type[1] && chunk[6] == type[2] && chunk[7] == type[3]);
2380 unsigned char lodepng_chunk_ancillary(const unsigned char* chunk)
2382 return((chunk[4] & 32) != 0);
2385 unsigned char lodepng_chunk_private(const unsigned char* chunk)
2387 return((chunk[6] & 32) != 0);
2390 unsigned char lodepng_chunk_safetocopy(const unsigned char* chunk)
2392 return((chunk[7] & 32) != 0);
2395 unsigned char* lodepng_chunk_data(unsigned char* chunk)
2397 return &chunk[8];
2400 const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk)
2402 return &chunk[8];
2405 unsigned lodepng_chunk_check_crc(const unsigned char* chunk)
2407 unsigned length = lodepng_chunk_length(chunk);
2408 unsigned CRC = lodepng_read32bitInt(&chunk[length + 8]);
2409 /*the CRC is taken of the data and the 4 chunk type letters, not the length*/
2410 unsigned checksum = lodepng_crc32(&chunk[4], length + 4);
2415 void lodepng_chunk_generate_crc(unsigned char* chunk)
2417 unsigned length = lodepng_chunk_length(chunk);
2418 unsigned CRC = lodepng_crc32(&chunk[4], length + 4);
2419 lodepng_set32bitInt(chunk + 8 + length, CRC);
2422 unsigned char* lodepng_chunk_next(unsigned char* chunk)
2424 unsigned total_chunk_length = lodepng_chunk_length(chunk) + 12;
2425 return &chunk[total_chunk_length];
2428 const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk)
2430 unsigned total_chunk_length = lodepng_chunk_length(chunk) + 12;
2431 return &chunk[total_chunk_length];
2434 unsigned lodepng_chunk_append(unsigned char** out, size_t* outlength, const unsigned char* chunk)
2437 unsigned total_chunk_length = lodepng_chunk_length(chunk) + 12;
2448 for(i = 0; i < total_chunk_length; i++) chunk_start[i] = chunk[i];
2457 unsigned char *chunk, *new_buffer;
2464 chunk = &(*out)[(*outlength) - length - 12];
2467 lodepng_set32bitInt(chunk, (unsigned)length);
2469 /*2: chunk name (4 letters)*/
2470 chunk[4] = type[0];
2471 chunk[5] = type[1];
2472 chunk[6] = type[2];
2473 chunk[7] = type[3];
2476 for(i = 0; i < length; i++) chunk[8 + i] = data[i];
2479 lodepng_chunk_generate_crc(chunk);
3592 /*only use color key if numpixels large enough to justify tRNS chunk size*/
3975 CERROR_RETURN_ERROR(state->error, 29); /*error: it doesn't start with a IHDR chunk!*/
4290 /*error: this chunk must be 2 bytes for greyscale image*/
4298 /*error: this chunk must be 6 bytes for RGB image*/
4306 else return 42; /*error: tRNS chunk not allowed for other color models*/
4313 /*background color chunk (bKGD)*/
4318 /*error: this chunk must be 1 byte for indexed color image*/
4326 /*error: this chunk must be 2 bytes for greyscale image*/
4335 /*error: this chunk must be 6 bytes for greyscale image*/
4347 /*text chunk (tEXt)*/
4390 /*compressed text chunk (zTXt)*/
4439 /*international text chunk (iTXt)*/
4453 /*Quick check if the chunk length isn't too small. Even without check
4455 if(chunkLength < 5) CERROR_BREAK(error, 30); /*iTXt chunk too short*/
4535 if(chunkLength != 7) return 73; /*invalid tIME chunk size*/
4550 if(chunkLength != 9) return 74; /*invalid pHYs chunk size*/
4567 const unsigned char* chunk;
4572 /*for unknown chunk order*/
4585 chunk = &in[33]; /*first byte of the first chunk after the header*/
4587 /*loop through the chunks, ignoring unknown chunks and stopping at IEND chunk.
4592 const unsigned char* data; /*the data in the chunk*/
4594 /*error: size of the in buffer too small to contain next chunk*/
4595 if((size_t)((chunk - in) + 12) > insize || chunk < in) CERROR_BREAK(state->error, 30);
4597 /*length of the data of the chunk, excluding the length bytes, chunk type and CRC bytes*/
4598 chunkLength = lodepng_chunk_length(chunk);
4599 /*error: chunk length larger than the max PNG chunk size*/
4602 if((size_t)((chunk - in) + chunkLength + 12) > insize || (chunk + chunkLength + 12) < in)
4604 CERROR_BREAK(state->error, 64); /*error: size of the in buffer too small to contain next chunk*/
4607 data = lodepng_chunk_data_const(chunk);
4609 /*IDAT chunk, containing compressed image data*/
4610 if(lodepng_chunk_type_equals(chunk, "IDAT"))
4619 /*IEND chunk*/
4620 else if(lodepng_chunk_type_equals(chunk, "IEND"))
4624 /*palette chunk (PLTE)*/
4625 else if(lodepng_chunk_type_equals(chunk, "PLTE"))
4633 /*palette transparency chunk (tRNS)*/
4634 else if(lodepng_chunk_type_equals(chunk, "tRNS"))
4640 /*background color chunk (bKGD)*/
4641 else if(lodepng_chunk_type_equals(chunk, "bKGD"))
4646 /*text chunk (tEXt)*/
4647 else if(lodepng_chunk_type_equals(chunk, "tEXt"))
4655 /*compressed text chunk (zTXt)*/
4656 else if(lodepng_chunk_type_equals(chunk, "zTXt"))
4664 /*international text chunk (iTXt)*/
4665 else if(lodepng_chunk_type_equals(chunk, "iTXt"))
4673 else if(lodepng_chunk_type_equals(chunk, "tIME"))
4678 else if(lodepng_chunk_type_equals(chunk, "pHYs"))
4684 else /*it's not an implemented chunk type, so ignore it: skip over the data*/
4686 /*error: unknown critical chunk (5th bit of first byte of chunk type is 0)*/
4687 if(!lodepng_chunk_ancillary(chunk)) CERROR_BREAK(state->error, 69);
4694 &state->info_png.unknown_chunks_size[critical_pos - 1], chunk);
4700 if(!state->decoder.ignore_crc && !unknown) /*check CRC if wanted, only on known chunk types*/
4702 if(lodepng_chunk_check_crc(chunk)) CERROR_BREAK(state->error, 57); /*invalid CRC*/
4705 if(!IEND) chunk = lodepng_chunk_next_const(chunk);
5533 /*out must be buffer big enough to contain uncompressed IDAT chunk data, and in must contain the full image.
5667 unsigned char* data = 0; /*uncompressed version of the IDAT chunk data*/
5782 state->error = 66; /*text chunk too large*/
5787 state->error = 67; /*text chunk too small*/
5799 /*LodePNG version id in text chunk*/
5813 addChunk_tEXt(&outv, "LodePNG", VERSION_STRING); /*it's shorter as tEXt than as zTXt chunk*/
5821 state->error = 66; /*text chunk too large*/
5826 state->error = 67; /*text chunk too small*/
5955 case 29: return "first chunk is not the header chunk";
5956 case 30: return "chunk length too large, chunk broken off at end of file";
5961 case 35: return "chunk length of a chunk is too large or the chunk too small";
5965 case 39: return "more palette alpha values given in tRNS chunk than there are colors in the palette";
5966 case 40: return "tRNS chunk has wrong size for greyscale image";
5967 case 41: return "tRNS chunk has wrong size for RGB image";
5968 case 42: return "tRNS chunk appeared while it was not allowed for this color type";
5969 case 43: return "bKGD chunk has wrong size for palette image";
5970 case 44: return "bKGD chunk has wrong size for greyscale image";
5971 case 45: return "bKGD chunk has wrong size for RGB image";
5996 case 63: return "length of a chunk too long, max allowed for PNG is 2147483647 bytes per chunk"; /*(2^31-1)*/
5999 case 66: return "the length of a text chunk keyword given to the encoder is longer than the maximum of 79 bytes";
6000 case 67: return "the length of a text chunk keyword given to the encoder is smaller than the minimum of 1 byte";
6001 case 68: return "tried to encode a PLTE chunk with a palette that has less than 1 or more than 256 colors";
6002 case 69: return "unknown chunk type with 'critical' flag encountered by the decoder";
6004 case 72: return "while decoding, unexisting compression method encountering in zTXt or iTXt chunk (it must be 0)";
6005 case 73: return "invalid tIME chunk size";
6006 case 74: return "invalid pHYs chunk size";
6008 case 75: return "no null termination char found while decoding text chunk";
6009 case 76: return "iTXt chunk too short to contain required bytes";
6022 case 89: return "text chunk keyword too short or long: must have size 1-79";