| 2475 | } |
| 2476 | |
| 2477 | unsigned lodepng_chunk_create(unsigned char** out, size_t* outlength, unsigned length, |
| 2478 | const char* type, const unsigned char* data) |
| 2479 | { |
| 2480 | unsigned i; |
| 2481 | unsigned char *chunk, *new_buffer; |
| 2482 | size_t new_length = (*outlength) + length + 12; |
| 2483 | if(new_length < length + 12 || new_length < (*outlength)) return 77; /*integer overflow happened*/ |
| 2484 | new_buffer = (unsigned char*)lodepng_realloc(*out, new_length); |
| 2485 | if(!new_buffer) return 83; /*alloc fail*/ |
| 2486 | (*out) = new_buffer; |
| 2487 | (*outlength) = new_length; |
| 2488 | chunk = &(*out)[(*outlength) - length - 12]; |
| 2489 | |
| 2490 | /*1: length*/ |
| 2491 | lodepng_set32bitInt(chunk, (unsigned)length); |
| 2492 | |
| 2493 | /*2: chunk name (4 letters)*/ |
| 2494 | chunk[4] = (unsigned char)type[0]; |
| 2495 | chunk[5] = (unsigned char)type[1]; |
| 2496 | chunk[6] = (unsigned char)type[2]; |
| 2497 | chunk[7] = (unsigned char)type[3]; |
| 2498 | |
| 2499 | /*3: the data*/ |
| 2500 | for(i = 0; i < length; i++) chunk[8 + i] = data[i]; |
| 2501 | |
| 2502 | /*4: CRC (of the chunkname characters and the data)*/ |
| 2503 | lodepng_chunk_generate_crc(chunk); |
| 2504 | |
| 2505 | return 0; |
| 2506 | } |
| 2507 | |
| 2508 | /* ////////////////////////////////////////////////////////////////////////// */ |
| 2509 | /* / Color types and such / */ |
no test coverage detected