root/ext/gd/libgd/gd2time.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

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

/* [<][>][^][v][top][bottom][index][help] */