| 4735 | } |
| 4736 | |
| 4737 | unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h, |
| 4738 | LodePNGState* state, |
| 4739 | const unsigned char* in, size_t insize) |
| 4740 | { |
| 4741 | *out = 0; |
| 4742 | decodeGeneric(out, w, h, state, in, insize); |
| 4743 | if(state->error) return state->error; |
| 4744 | if(!state->decoder.color_convert || lodepng_color_mode_equal(&state->info_raw, &state->info_png.color)) |
| 4745 | { |
| 4746 | /*same color type, no copying or converting of data needed*/ |
| 4747 | /*store the info_png color settings on the info_raw so that the info_raw still reflects what colortype |
| 4748 | the raw image has to the end user*/ |
| 4749 | if(!state->decoder.color_convert) |
| 4750 | { |
| 4751 | state->error = lodepng_color_mode_copy(&state->info_raw, &state->info_png.color); |
| 4752 | if(state->error) return state->error; |
| 4753 | } |
| 4754 | } |
| 4755 | else |
| 4756 | { |
| 4757 | /*color conversion needed; sort of copy of the data*/ |
| 4758 | unsigned char* data = *out; |
| 4759 | size_t outsize; |
| 4760 | |
| 4761 | /*TODO: check if this works according to the statement in the documentation: "The converter can convert |
| 4762 | from greyscale input color type, to 8-bit greyscale or greyscale with alpha"*/ |
| 4763 | if(!(state->info_raw.colortype == LCT_RGB || state->info_raw.colortype == LCT_RGBA) |
| 4764 | && !(state->info_raw.bitdepth == 8)) |
| 4765 | { |
| 4766 | return 56; /*unsupported color mode conversion*/ |
| 4767 | } |
| 4768 | |
| 4769 | outsize = lodepng_get_raw_size(*w, *h, &state->info_raw); |
| 4770 | *out = (unsigned char*)lodepng_malloc(outsize); |
| 4771 | if(!(*out)) |
| 4772 | { |
| 4773 | state->error = 83; /*alloc fail*/ |
| 4774 | } |
| 4775 | else state->error = lodepng_convert(*out, data, &state->info_raw, &state->info_png.color, *w, *h, state->decoder.fix_png); |
| 4776 | lodepng_free(data); |
| 4777 | } |
| 4778 | return state->error; |
| 4779 | } |
| 4780 | |
| 4781 | unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in, |
| 4782 | size_t insize, LodePNGColorType colortype, unsigned bitdepth) |
no test coverage detected