MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / lodepng_encode

Function lodepng_encode

src/lodepng.cpp:5661–5853  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5659#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
5660
5661unsigned lodepng_encode(unsigned char** out, size_t* outsize,
5662 const unsigned char* image, unsigned w, unsigned h,
5663 LodePNGState* state)
5664{
5665 LodePNGInfo info;
5666 ucvector outv;
5667 unsigned char* data = 0; /*uncompressed version of the IDAT chunk data*/
5668 size_t datasize = 0;
5669
5670 /*provide some proper output values if error will happen*/
5671 *out = 0;
5672 *outsize = 0;
5673 state->error = 0;
5674
5675 lodepng_info_init(&info);
5676 lodepng_info_copy(&info, &state->info_png);
5677
5678 if((info.color.colortype == LCT_PALETTE || state->encoder.force_palette)
5679 && (info.color.palettesize == 0 || info.color.palettesize > 256))
5680 {
5681 state->error = 68; /*invalid palette size, it is only allowed to be 1-256*/
5682 return state->error;
5683 }
5684
5685 if(state->encoder.auto_convert != LAC_NO)
5686 {
5687 state->error = lodepng_auto_choose_color(&info.color, image, w, h, &state->info_raw,
5688 state->encoder.auto_convert);
5689 }
5690 if(state->error) return state->error;
5691
5692 if(state->encoder.zlibsettings.btype > 2)
5693 {
5694 CERROR_RETURN_ERROR(state->error, 61); /*error: unexisting btype*/
5695 }
5696 if(state->info_png.interlace_method > 1)
5697 {
5698 CERROR_RETURN_ERROR(state->error, 71); /*error: unexisting interlace mode*/
5699 }
5700
5701 state->error = checkColorValidity(info.color.colortype, info.color.bitdepth);
5702 if(state->error) return state->error; /*error: unexisting color type given*/
5703 state->error = checkColorValidity(state->info_raw.colortype, state->info_raw.bitdepth);
5704 if(state->error) return state->error; /*error: unexisting color type given*/
5705
5706 if(!lodepng_color_mode_equal(&state->info_raw, &info.color))
5707 {
5708 unsigned char* converted;
5709 size_t size = (w * h * lodepng_get_bpp(&info.color) + 7) / 8;
5710
5711 converted = (unsigned char*)lodepng_malloc(size);
5712 if(!converted && size) state->error = 83; /*alloc fail*/
5713 if(!state->error)
5714 {
5715 state->error = lodepng_convert(converted, image, &info.color, &state->info_raw, w, h, 0 /*fix_png*/);
5716 }
5717 if(!state->error) preProcessScanlines(&data, &datasize, converted, w, h, &info, &state->encoder);
5718 lodepng_free(converted);

Callers 2

lodepng_encode_memoryFunction · 0.85
encodeFunction · 0.85

Calls 15

lodepng_info_initFunction · 0.85
lodepng_info_copyFunction · 0.85
checkColorValidityFunction · 0.85
lodepng_color_mode_equalFunction · 0.85
lodepng_get_bppFunction · 0.85
lodepng_mallocFunction · 0.85
lodepng_convertFunction · 0.85
preProcessScanlinesFunction · 0.85
lodepng_freeFunction · 0.85
ucvector_initFunction · 0.85
writeSignatureFunction · 0.85

Tested by

no test coverage detected