Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. // gcc <file>.c -lpng; ./a.out < VhGrd.png > out.png
  2.  
  3. #include <stdlib.h> // malloc, EXIT_*
  4. #include <string.h> // memset
  5. #include <png.h>
  6.  
  7. #define EXIT_PNG(F) if (!F) { \
  8.     fprintf(stderr, "%s\n", img.message); \
  9.     return EXIT_FAILURE; \
  10. }
  11.  
  12. int main(int argc, char **args)
  13. {
  14.     png_image img;
  15.     memset(&img, 0, sizeof(img));
  16.     img.version = PNG_IMAGE_VERSION;
  17.     EXIT_PNG(png_image_begin_read_from_stdio(&img, stdin))
  18.  
  19.     void *pixels = malloc(img.width * img.height * 4);
  20.     EXIT_PNG(png_image_finish_read(&img, NULL, pixels, 0, NULL))
  21.  
  22.     EXIT_PNG(png_image_write_to_stdio(&img, stdout, 0, pixels, 0, NULL));
  23.     return EXIT_SUCCESS;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement