png.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #define _XOPEN_SOURCE
  2. #include "img.h"
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. int main(int argc, char **argv)
  6. {
  7. if (argc != 4) {
  8. fprintf(stderr, "\nusage: %s count width height", argv[0]);
  9. exit(EXIT_FAILURE);
  10. }
  11. int width, height, c;
  12. c = atoi(argv[1]);
  13. width = atoi(argv[2]);
  14. height = atoi(argv[3]);
  15. pix_row rows[width];
  16. pix p;
  17. char filename[60];
  18. int i, j, x, y, count;
  19. image img;
  20. p.r = 200;
  21. p.g = 200;
  22. p.b = 200;
  23. srand48(1000);
  24. for (count = 0; count < (c); count++) {
  25. for (i = 0; i < width; i++) {
  26. rows[i].p = malloc(height * sizeof(pix));
  27. for (j = 0; j < height; j++) {
  28. p.r = (int) (drand48() * 255);
  29. p.g = (int) (drand48() * 255);
  30. p.b = (int) (drand48() * 255);
  31. rows[i].p[j] = p;
  32. }
  33. }
  34. sprintf(filename, "images/image%05d.png", count);
  35. img = initialize_png("image010", filename, width, height);
  36. write_image(&img, rows);
  37. finish_image(&img);
  38. for (i = 0; i < width; i++) {
  39. free(rows[i].p);
  40. }
  41. }
  42. return (0);
  43. }