MCPcopy Create free account
hub / github.com/ValveSoftware/openvr / lodepng_decode

Function lodepng_decode

samples/shared/lodepng.cpp:4586–4629  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4584}
4585
4586unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h,
4587 LodePNGState* state,
4588 const unsigned char* in, size_t insize)
4589{
4590 *out = 0;
4591 decodeGeneric(out, w, h, state, in, insize);
4592 if(state->error) return state->error;
4593 if(!state->decoder.color_convert || lodepng_color_mode_equal(&state->info_raw, &state->info_png.color))
4594 {
4595 /*same color type, no copying or converting of data needed*/
4596 /*store the info_png color settings on the info_raw so that the info_raw still reflects what colortype
4597 the raw image has to the end user*/
4598 if(!state->decoder.color_convert)
4599 {
4600 state->error = lodepng_color_mode_copy(&state->info_raw, &state->info_png.color);
4601 if(state->error) return state->error;
4602 }
4603 }
4604 else
4605 {
4606 /*color conversion needed; sort of copy of the data*/
4607 unsigned char* data = *out;
4608 size_t outsize;
4609
4610 /*TODO: check if this works according to the statement in the documentation: "The converter can convert
4611 from greyscale input color type, to 8-bit greyscale or greyscale with alpha"*/
4612 if(!(state->info_raw.colortype == LCT_RGB || state->info_raw.colortype == LCT_RGBA)
4613 && !(state->info_raw.bitdepth == 8))
4614 {
4615 return 56; /*unsupported color mode conversion*/
4616 }
4617
4618 outsize = lodepng_get_raw_size(*w, *h, &state->info_raw);
4619 *out = (unsigned char*)lodepng_malloc(outsize);
4620 if(!(*out))
4621 {
4622 state->error = 83; /*alloc fail*/
4623 }
4624 else state->error = lodepng_convert(*out, data, &state->info_raw,
4625 &state->info_png.color, *w, *h);
4626 lodepng_free(data);
4627 }
4628 return state->error;
4629}
4630
4631unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in,
4632 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