| 4715 | } |
| 4716 | |
| 4717 | unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h, |
| 4718 | LodePNGState* state, |
| 4719 | const unsigned char* in, size_t insize) |
| 4720 | { |
| 4721 | *out = 0; |
| 4722 | decodeGeneric(out, w, h, state, in, insize); |
| 4723 | if(state->error) return state->error; |
| 4724 | if(!state->decoder.color_convert || lodepng_color_mode_equal(&state->info_raw, &state->info_png.color)) |
| 4725 | { |
| 4726 | /*same color type, no copying or converting of data needed*/ |
| 4727 | /*store the info_png color settings on the info_raw so that the info_raw still reflects what colortype |
| 4728 | the raw image has to the end user*/ |
| 4729 | if(!state->decoder.color_convert) |
| 4730 | { |
| 4731 | state->error = lodepng_color_mode_copy(&state->info_raw, &state->info_png.color); |
| 4732 | if(state->error) return state->error; |
| 4733 | } |
| 4734 | } |
| 4735 | else |
| 4736 | { |
| 4737 | /*color conversion needed; sort of copy of the data*/ |
| 4738 | unsigned char* data = *out; |
| 4739 | size_t outsize; |
| 4740 | |
| 4741 | /*TODO: check if this works according to the statement in the documentation: "The converter can convert |
| 4742 | from greyscale input color type, to 8-bit greyscale or greyscale with alpha"*/ |
| 4743 | if(!(state->info_raw.colortype == LCT_RGB || state->info_raw.colortype == LCT_RGBA) |
| 4744 | && !(state->info_raw.bitdepth == 8)) |
| 4745 | { |
| 4746 | return 56; /*unsupported color mode conversion*/ |
| 4747 | } |
| 4748 | |
| 4749 | outsize = lodepng_get_raw_size(*w, *h, &state->info_raw); |
| 4750 | *out = (unsigned char*)lodepng_malloc(outsize); |
| 4751 | if(!(*out)) |
| 4752 | { |
| 4753 | state->error = 83; /*alloc fail*/ |
| 4754 | } |
| 4755 | else state->error = lodepng_convert(*out, data, &state->info_raw, |
| 4756 | &state->info_png.color, *w, *h); |
| 4757 | lodepng_free(data); |
| 4758 | } |
| 4759 | return state->error; |
| 4760 | } |
| 4761 | |
| 4762 | unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in, |
| 4763 | size_t insize, LodePNGColorType colortype, unsigned bitdepth) |
no test coverage detected