| 2451 | } |
| 2452 | |
| 2453 | unsigned lodepng_chunk_create(unsigned char** out, size_t* outlength, unsigned length, |
| 2454 | const char* type, const unsigned char* data) |
| 2455 | { |
| 2456 | unsigned i; |
| 2457 | unsigned char *chunk, *new_buffer; |
| 2458 | size_t new_length = (*outlength) + length + 12; |
| 2459 | if(new_length < length + 12 || new_length < (*outlength)) return 77; /*integer overflow happened*/ |
| 2460 | new_buffer = (unsigned char*)lodepng_realloc(*out, new_length); |
| 2461 | if(!new_buffer) return 83; /*alloc fail*/ |
| 2462 | (*out) = new_buffer; |
| 2463 | (*outlength) = new_length; |
| 2464 | chunk = &(*out)[(*outlength) - length - 12]; |
| 2465 | |
| 2466 | /*1: length*/ |
| 2467 | lodepng_set32bitInt(chunk, (unsigned)length); |
| 2468 | |
| 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]; |
| 2474 | |
| 2475 | /*3: the data*/ |
| 2476 | for(i = 0; i < length; i++) chunk[8 + i] = data[i]; |
| 2477 | |
| 2478 | /*4: CRC (of the chunkname characters and the data)*/ |
| 2479 | lodepng_chunk_generate_crc(chunk); |
| 2480 | |
| 2481 | return 0; |
| 2482 | } |
| 2483 | |
| 2484 | /* ////////////////////////////////////////////////////////////////////////// */ |
| 2485 | /* / Color types and such / */ |
no test coverage detected