]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - filter/rasterbench.c
Update svn:keyword properties.
[thirdparty/cups.git] / filter / rasterbench.c
index a165bed7a7741a0cd705f4aaab1da46563440b09..69e139d37d5d92ea6550da6bef2f944e141305e7 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * "$Id: rasterbench.c 6649 2007-07-11 21:46:42Z mike $"
+ * "$Id$"
  *
- *   Raster benchmark program for the Common UNIX Printing System (CUPS).
+ *   Raster benchmark program for CUPS.
  *
- *   Copyright 2007 by Apple Inc.
+ *   Copyright 2007-2011 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -26,7 +26,8 @@
  * Include necessary headers...
  */
 
-#include "raster.h"
+#include <config.h>
+#include <cups/raster.h>
 #include <stdlib.h>
 #include <sys/time.h>
 #include <signal.h>
@@ -52,7 +53,7 @@ static double compute_median(double *secs);
 static double  get_time(void);
 static void    read_test(int fd);
 static int     run_read_test(void);
-static void    write_test(int fd);
+static void    write_test(int fd, cups_mode_t mode);
 
 
 /*
@@ -60,7 +61,8 @@ static void   write_test(int fd);
  */
 
 int                                    /* O - Exit status */
-main(void)
+main(int  argc,                                /* I - Number of command-line args */
+     char *argv[])                     /* I - Command-line arguments */
 {
   int          i;                      /* Looping var */
   int          ras_fd,                 /* File descriptor for read process */
@@ -69,8 +71,21 @@ main(void)
                write_secs,             /* Write time */
                read_secs,              /* Read time */
                pass_secs[TEST_PASSES]; /* Total test times */
+  cups_mode_t  mode;                   /* Write mode */
 
 
+ /*
+  * See if we have anything on the command-line...
+  */
+
+  if (argc > 2 || (argc == 2 && strcmp(argv[1], "-z")))
+  {
+    puts("Usage: rasterbench [-z]");
+    return (1);
+  }
+
+  mode = argc > 1 ? CUPS_RASTER_WRITE_COMPRESSED : CUPS_RASTER_WRITE;
+
  /*
   * Ignore SIGPIPE...
   */
@@ -91,7 +106,7 @@ main(void)
     ras_fd     = run_read_test();
     start_secs = get_time();
 
-    write_test(ras_fd);
+    write_test(ras_fd, mode);
 
     write_secs = get_time();
     printf(" %.3f write,", write_secs - start_secs);
@@ -168,7 +183,7 @@ read_test(int fd)                   /* I - File descriptor to read from */
 {
   int                  y;              /* Looping var */
   cups_raster_t                *r;             /* Raster stream */
-  cups_page_header_t   header;         /* Page header */
+  cups_page_header2_t  header;         /* Page header */
   unsigned char                buffer[8 * TEST_WIDTH];
                                        /* Read buffer */
 
@@ -183,7 +198,7 @@ read_test(int fd)                   /* I - File descriptor to read from */
     return;
   }
 
-  while (cupsRasterReadHeader(r, &header))
+  while (cupsRasterReadHeader2(r, &header))
   {
     for (y = 0; y < header.cupsHeight; y ++)
       cupsRasterReadPixels(r, buffer, header.cupsBytesPerLine);
@@ -245,12 +260,13 @@ run_read_test(void)
  */
 
 static void
-write_test(int fd)                     /* I - File descriptor to write to */
+write_test(int         fd,             /* I - File descriptor to write to */
+           cups_mode_t mode)           /* I - Write mode */
 {
   int                  page, x, y;     /* Looping vars */
   int                  count;          /* Number of bytes to set */
   cups_raster_t                *r;             /* Raster stream */
-  cups_page_header_t   header;         /* Page header */
+  cups_page_header2_t  header;         /* Page header */
   unsigned char                data[32][8 * TEST_WIDTH];
                                        /* Raster data to write */
 
@@ -260,26 +276,26 @@ write_test(int fd)                        /* I - File descriptor to write to */
   * text with some whitespace.
   */
 
-  srand(time(NULL));
+  CUPS_SRAND(time(NULL));
 
   memset(data, 0, sizeof(data));
 
   for (y = 0; y < 28; y ++)
   {
-    for (x = rand() & 127, count = (rand() & 15) + 1;
+    for (x = CUPS_RAND() & 127, count = (CUPS_RAND() & 15) + 1;
          x < sizeof(data[0]);
          x ++, count --)
     {
       if (count <= 0)
       {
-       x     += (rand() & 15) + 1;
-       count = (rand() & 15) + 1;
+       x     += (CUPS_RAND() & 15) + 1;
+       count = (CUPS_RAND() & 15) + 1;
 
         if (x >= sizeof(data[0]))
          break;
       }
 
-      data[y][x] = rand();
+      data[y][x] = CUPS_RAND();
     }
   }
 
@@ -287,7 +303,7 @@ write_test(int fd)                  /* I - File descriptor to write to */
   * Test write speed...
   */
 
-  if ((r = cupsRasterOpen(fd, CUPS_RASTER_WRITE)) == NULL)
+  if ((r = cupsRasterOpen(fd, mode)) == NULL)
   {
     perror("Unable to create raster output stream");
     return;
@@ -324,7 +340,7 @@ write_test(int fd)                  /* I - File descriptor to write to */
       header.cupsBitsPerPixel = (page & 1) ? 32 : 8;
     }
 
-    cupsRasterWriteHeader(r, &header);
+    cupsRasterWriteHeader2(r, &header);
 
     for (y = 0; y < TEST_HEIGHT; y ++)
       cupsRasterWritePixels(r, data[y & 31], header.cupsBytesPerLine);
@@ -335,5 +351,5 @@ write_test(int fd)                  /* I - File descriptor to write to */
 
 
 /*
- * End of "$Id: rasterbench.c 6649 2007-07-11 21:46:42Z mike $".
+ * End of "$Id$".
  */