Example 3 Save a PNG file to disk using a State, normally needed for more advanced usage. The image argument has width * height RGBA pixels or width * height * 4 bytes */
| 70 | The image argument has width * height RGBA pixels or width * height * 4 bytes |
| 71 | */ |
| 72 | void encodeWithState(const char* filename, const unsigned char* image, unsigned width, unsigned height) { |
| 73 | unsigned error; |
| 74 | unsigned char* png; |
| 75 | size_t pngsize; |
| 76 | LodePNGState state; |
| 77 | |
| 78 | lodepng_state_init(&state); |
| 79 | /*optionally customize the state*/ |
| 80 | |
| 81 | error = lodepng_encode(&png, &pngsize, image, width, height, &state); |
| 82 | if(!error) lodepng_save_file(png, pngsize, filename); |
| 83 | |
| 84 | /*if there's an error, display it*/ |
| 85 | if(error) printf("error %u: %s\n", error, lodepng_error_text(error)); |
| 86 | |
| 87 | lodepng_state_cleanup(&state); |
| 88 | free(png); |
| 89 | } |
| 90 | |
| 91 | int main(int argc, char *argv[]) { |
| 92 | const char* filename = argc > 1 ? argv[1] : "test.png"; |
nothing calls this directly
no test coverage detected