| 4584 | } |
| 4585 | |
| 4586 | unsigned 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 | |
| 4631 | unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in, |
| 4632 | size_t insize, LodePNGColorType colortype, unsigned bitdepth) |
no test coverage detected