[devel] Reversed earlier change of transformation order; move

png_expand_16 back where it was before libpng-1.5.3beta07.
The change doesn't work because it requires 16 bit gamma tables when the code
only generates 8 bit ones.  This fails silently; the libpng code just doesn't
do any gamma correction.  Moving the tests back leaves the old, inaccurate, 8
bit gamma calculations, but these are clearly better than none!
diff --git a/pngvalid.c b/pngvalid.c
index a3ddf18..3a548bc 100644
--- a/pngvalid.c
+++ b/pngvalid.c
@@ -1528,6 +1528,7 @@
    double                   error_gray_16;
    double                   error_color_8;
    double                   error_color_16;
+   double                   error_indexed;
 
    /* Flags: */
    /* Whether or not to interlace. */
@@ -1593,6 +1594,7 @@
    pm->maxout16 = pm->maxpc16 = pm->maxabs16 = pm->maxcalc16 = 0;
    pm->error_gray_2 = pm->error_gray_4 = pm->error_gray_8 = 0;
    pm->error_gray_16 = pm->error_color_8 = pm->error_color_16 = 0;
+   pm->error_indexed = 0;
    pm->interlace_type = PNG_INTERLACE_NONE;
    pm->test_standard = 0;
    pm->test_size = 0;
@@ -6814,6 +6816,12 @@
             png_error(pp, "bad bit depth (internal: 2)");
          }
       }
+
+      else if (d.this.colour_type == 3)
+      {
+         if (d.maxerrout > d.pm->error_indexed)
+            d.pm->error_indexed = d.maxerrout;
+      }
    }
 
    Catch(fault)
@@ -7184,8 +7192,9 @@
 static void
 init_gamma_errors(png_modifier *pm)
 {
-   pm->error_gray_2 = pm->error_gray_4 = pm->error_gray_8 = pm->error_color_8 =
-      0;
+   pm->error_gray_2 = pm->error_gray_4 = pm->error_gray_8 = 0;
+   pm->error_color_8 = 0;
+   pm->error_indexed = 0;
    pm->error_gray_16 = pm->error_color_16 = 0;
 }
 
@@ -7201,6 +7210,7 @@
       printf("  4 bit gray:  %.5f\n", pm->error_gray_4);
       printf("  8 bit gray:  %.5f\n", pm->error_gray_8);
       printf("  8 bit color: %.5f\n", pm->error_color_8);
+      printf("  indexed:     %.5f\n", pm->error_indexed);
    }
 
 #ifdef DO_16BIT
@@ -7655,6 +7665,7 @@
 int main(int argc, PNG_CONST char **argv)
 {
    volatile int summary = 1;  /* Print the error summary at the end */
+   volatile int memstats = 0; /* Print memory statistics at the end */
 
    /* Create the given output file on success: */
    PNG_CONST char *volatile touch = NULL;
@@ -7667,6 +7678,10 @@
    static double
       gammas[]={2.2, 1.0, 2.2/1.45, 1.8, 1.5, 2.4, 2.5, 2.62, 2.9};
 
+   /* This records the command and arguments: */
+   size_t cp = 0;
+   char command[1024];
+
    png_modifier pm;
    context(&pm.this, fault);
 
@@ -7679,6 +7694,9 @@
     */
    store_ensure_image(&pm.this, NULL, 2, TRANSFORM_ROWMAX, TRANSFORM_HEIGHTMAX);
 
+   /* Don't give argv[0], it's normally some horrible libtool string: */
+   cp = safecat(command, sizeof command, cp, "pngvalid");
+
    /* Default to error on warning: */
    pm.this.treat_warnings_as_errors = 1;
 
@@ -7716,7 +7734,11 @@
    /* Now parse the command line options. */
    while (--argc >= 1)
    {
-      if (strcmp(*++argv, "-v") == 0)
+      /* Record each argument for posterity: */
+      cp = safecat(command, sizeof command, cp, " ");
+      cp = safecat(command, sizeof command, cp, *++argv);
+
+      if (strcmp(*argv, "-v") == 0)
          pm.this.verbose = 1;
 
       else if (strcmp(*argv, "-l") == 0)
@@ -7730,7 +7752,10 @@
 
       else if (strcmp(*argv, "--speed") == 0)
          pm.this.speed = 1, pm.ngammas = (sizeof gammas)/(sizeof gammas[0]),
-            pm.test_standard = 0;
+            pm.test_standard = 0, summary = 0;
+
+      else if (strcmp(*argv, "--memory") == 0)
+         memstats = 1;
 
       else if (strcmp(*argv, "--size") == 0)
          pm.test_size = 1;
@@ -7962,7 +7987,7 @@
 
 #ifdef PNG_READ_GAMMA_SUPPORTED
       if (pm.ngammas > 0)
-         perform_gamma_test(&pm, summary && !pm.this.speed);
+         perform_gamma_test(&pm, summary);
 #endif
    }
 
@@ -7979,18 +8004,22 @@
       exit(1);
    }
 
-   if (summary && !pm.this.speed)
+   if (summary)
    {
-      printf("Results using %s point arithmetic %s\n",
+      printf("%s: %s: %s point arithmetic, %d errors, %d warnings\n",
+         (pm.this.nerrors || (pm.this.treat_warnings_as_errors &&
+            pm.this.nwarnings)) ? "FAIL" : "PASS",
+         command,
 #if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || PNG_LIBPNG_VER < 10500
          "floating",
 #else
          "fixed",
 #endif
-         (pm.this.nerrors || (pm.this.treat_warnings_as_errors &&
-            pm.this.nwarnings)) ? "(errors)" : (pm.this.nwarnings ?
-               "(warnings)" : "(no errors or warnings)")
-      );
+         pm.this.nerrors, pm.this.nwarnings);
+   }
+
+   if (memstats)
+   {
       printf("Allocated memory statistics (in bytes):\n"
          "\tread  %lu maximum single, %lu peak, %lu total\n"
          "\twrite %lu maximum single, %lu peak, %lu total\n",