gd2time.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <stdio.h>
  2. #include <stdlib.h> /* for atoi */
  3. #include <time.h> /* For time */
  4. #include "gd.h"
  5. /* A short program which converts a .png file into a .gd file, for
  6. your convenience in creating images on the fly from a
  7. basis image that must be loaded quickly. The .gd format
  8. is not intended to be a general-purpose format. */
  9. int
  10. main (int argc, char **argv)
  11. {
  12. gdImagePtr im;
  13. FILE *in;
  14. int x, y, w, h;
  15. int c;
  16. int i;
  17. int t0;
  18. if (argc != 7)
  19. {
  20. fprintf (stderr, "Usage: gd2time filename.gd count x y w h\n");
  21. exit (1);
  22. }
  23. c = atoi (argv[2]);
  24. x = atoi (argv[3]);
  25. y = atoi (argv[4]);
  26. w = atoi (argv[5]);
  27. h = atoi (argv[6]);
  28. printf ("Extracting %d times from (%d, %d), size is %dx%d\n", c, x, y, w, h);
  29. t0 = time (0);
  30. for (i = 0; i < c; i++)
  31. {
  32. in = fopen (argv[1], "rb");
  33. if (!in)
  34. {
  35. fprintf (stderr, "Input file does not exist!\n");
  36. exit (1);
  37. }
  38. im = gdImageCreateFromGd2Part (in, x, y, w, h);
  39. fclose (in);
  40. if (!im)
  41. {
  42. fprintf (stderr, "Error reading source file!\n");
  43. exit (1);
  44. }
  45. gdImageDestroy (im);
  46. };
  47. t0 = time (0) - t0;
  48. printf ("%d seconds to extract (& destroy) %d times\n", t0, c);
  49. return 0;
  50. }