about summary refs log tree commit diff
path: root/lib/libppm1.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libppm1.c')
-rw-r--r--lib/libppm1.c33
1 files changed, 12 insertions, 21 deletions
diff --git a/lib/libppm1.c b/lib/libppm1.c
index ccc8adb5..01539169 100644
--- a/lib/libppm1.c
+++ b/lib/libppm1.c
@@ -64,33 +64,19 @@ ppm_nextimage(FILE * const fileP,
 
 
 void
-ppm_readppminitrest(FILE *   const fileP,
+ppm_readppminitrest(FILE *   const ifP,
                     int *    const colsP,
                     int *    const rowsP,
                     pixval * const maxvalP) {
-    unsigned int maxval;
-
-    /* Read size. */
-    *colsP = (int)pm_getuint(fileP);
-    *rowsP = (int)pm_getuint(fileP);
-
-    /* Read maxval. */
-    maxval = pm_getuint(fileP);
-    if (maxval > PPM_OVERALLMAXVAL)
-        pm_error("maxval of input image (%u) is too large.  "
-                 "The maximum allowed by the PPM format is %u.",
-                 maxval, PPM_OVERALLMAXVAL);
-    if (maxval == 0)
-        pm_error("maxval of input image is zero.");
-
-    *maxvalP = maxval;
+
+    pgm_readpgminitrest(ifP, colsP, rowsP, maxvalP);
 }
 
 
 
-static void
-validateComputableSize(unsigned int const cols,
-                       unsigned int const rows) {
+void
+ppm_validateComputableSize(unsigned int const cols,
+                           unsigned int const rows) {
 /*----------------------------------------------------------------------------
    Validate that the dimensions of the image are such that it can be
    processed in typical ways on this machine without worrying about
@@ -150,7 +136,9 @@ ppm_readppminit(FILE *   const fileP,
         pm_error("bad magic number 0x%x - not a PPM, PGM, PBM, or PAM file",
                  realFormat);
     }
-    validateComputableSize(*colsP, *rowsP);
+    ppm_validateComputableSize(*colsP, *rowsP);
+
+    pgm_validateComputableMaxval(*maxvalP);
 }
 
 
@@ -502,3 +490,6 @@ ppm_check(FILE *               const fileP,
         pm_check(fileP, checkType, needRasterSize, retvalP);
     }
 }
+
+
+