MCPcopy Create free account
hub / github.com/DFHack/dfhack / lodepng_decode

Function lodepng_decode

depends/lodepng/lodepng.cpp:4951–4986  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4949}
4950
4951unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h,
4952 LodePNGState* state,
4953 const unsigned char* in, size_t insize) {
4954 *out = 0;
4955 decodeGeneric(out, w, h, state, in, insize);
4956 if(state->error) return state->error;
4957 if(!state->decoder.color_convert || lodepng_color_mode_equal(&state->info_raw, &state->info_png.color)) {
4958 /*same color type, no copying or converting of data needed*/
4959 /*store the info_png color settings on the info_raw so that the info_raw still reflects what colortype
4960 the raw image has to the end user*/
4961 if(!state->decoder.color_convert) {
4962 state->error = lodepng_color_mode_copy(&state->info_raw, &state->info_png.color);
4963 if(state->error) return state->error;
4964 }
4965 } else { /*color conversion needed*/
4966 unsigned char* data = *out;
4967 size_t outsize;
4968
4969 /*TODO: check if this works according to the statement in the documentation: "The converter can convert
4970 from grayscale input color type, to 8-bit grayscale or grayscale with alpha"*/
4971 if(!(state->info_raw.colortype == LCT_RGB || state->info_raw.colortype == LCT_RGBA)
4972 && !(state->info_raw.bitdepth == 8)) {
4973 return 56; /*unsupported color mode conversion*/
4974 }
4975
4976 outsize = lodepng_get_raw_size(*w, *h, &state->info_raw);
4977 *out = (unsigned char*)lodepng_malloc(outsize);
4978 if(!(*out)) {
4979 state->error = 83; /*alloc fail*/
4980 }
4981 else state->error = lodepng_convert(*out, data, &state->info_raw,
4982 &state->info_png.color, *w, *h);
4983 lodepng_free(data);
4984 }
4985 return state->error;
4986}
4987
4988unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in,
4989 size_t insize, LodePNGColorType colortype, unsigned bitdepth) {

Callers 2

lodepng_decode_memoryFunction · 0.85
decodeFunction · 0.85

Calls 7

decodeGenericFunction · 0.85
lodepng_color_mode_equalFunction · 0.85
lodepng_color_mode_copyFunction · 0.85
lodepng_get_raw_sizeFunction · 0.85
lodepng_mallocFunction · 0.85
lodepng_convertFunction · 0.85
lodepng_freeFunction · 0.85

Tested by

no test coverage detected