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