MCPcopy Create free account
hub / github.com/HiLab-git/SimpleCRF / lodepng_chunk_create

Function lodepng_chunk_create

dependency/densecrf/examples/lodepng.cpp:2512–2541  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2510}
2511
2512unsigned lodepng_chunk_create(unsigned char** out, size_t* outlength, unsigned length,
2513 const char* type, const unsigned char* data)
2514{
2515 unsigned i;
2516 unsigned char *chunk, *new_buffer;
2517 size_t new_length = (*outlength) + length + 12;
2518 if(new_length < length + 12 || new_length < (*outlength)) return 77; /*integer overflow happened*/
2519 new_buffer = (unsigned char*)lodepng_realloc(*out, new_length);
2520 if(!new_buffer) return 83; /*alloc fail*/
2521 (*out) = new_buffer;
2522 (*outlength) = new_length;
2523 chunk = &(*out)[(*outlength) - length - 12];
2524
2525 /*1: length*/
2526 lodepng_set32bitInt(chunk, (unsigned)length);
2527
2528 /*2: chunk name (4 letters)*/
2529 chunk[4] = (unsigned char)type[0];
2530 chunk[5] = (unsigned char)type[1];
2531 chunk[6] = (unsigned char)type[2];
2532 chunk[7] = (unsigned char)type[3];
2533
2534 /*3: the data*/
2535 for(i = 0; i != length; ++i) chunk[8 + i] = data[i];
2536
2537 /*4: CRC (of the chunkname characters and the data)*/
2538 lodepng_chunk_generate_crc(chunk);
2539
2540 return 0;
2541}
2542
2543/* ////////////////////////////////////////////////////////////////////////// */
2544/* / Color types and such / */

Callers 1

addChunkFunction · 0.85

Calls 3

lodepng_reallocFunction · 0.85
lodepng_set32bitIntFunction · 0.85

Tested by

no test coverage detected