about summary refs log tree commit diff
path: root/converter
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2015-05-27 16:47:39 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2015-05-27 16:47:39 +0000
commit921c08b68f785180a918591ea0699de6275d202d (patch)
treee9e41fd791a7250baaaf6c874cb9ae51bb93eb5f /converter
parentd48a2029915d779215178261f3a529b10acb992a (diff)
downloadnetpbm-mirror-921c08b68f785180a918591ea0699de6275d202d.tar.gz
netpbm-mirror-921c08b68f785180a918591ea0699de6275d202d.tar.xz
netpbm-mirror-921c08b68f785180a918591ea0699de6275d202d.zip
Release 10.70.06
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@2528 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter')
-rw-r--r--converter/other/cameratopam/ljpeg.c31
-rw-r--r--converter/other/pnmtorle.c5
-rw-r--r--converter/pbm/pbmtoatk.c8
-rw-r--r--converter/pbm/pbmtog3.c2
-rw-r--r--converter/pbm/pbmtopk.c12
-rw-r--r--converter/pbm/pktopbm.c5
-rw-r--r--converter/pgm/sbigtopgm.c43
-rw-r--r--converter/ppm/ppmtoyuvsplit.c49
8 files changed, 105 insertions, 50 deletions
diff --git a/converter/other/cameratopam/ljpeg.c b/converter/other/cameratopam/ljpeg.c
index 29e4ff98..d5e21d3b 100644
--- a/converter/other/cameratopam/ljpeg.c
+++ b/converter/other/cameratopam/ljpeg.c
@@ -33,21 +33,26 @@ ljpeg_start (FILE * ifp, struct jhead *jh)
   do {
     fread (data, 2, 2, ifp);
     tag =  data[0] << 8 | data[1];
-    len = (data[2] << 8 | data[3]) - 2;
-    if (tag <= 0xff00 || len > 255) return 0;
-    fread (data, 1, len, ifp);
-    switch (tag) {
+    len = (data[2] << 8 | data[3]);
+    if (len < 2)
+      pm_error("Length field is %u; must be at least 2", len);
+    else {
+      unsigned int const dataLen = len - 2;
+      if (tag <= 0xff00 || dataLen > 255) return 0;
+      fread (data, 1, dataLen, ifp);
+      switch (tag) {
       case 0xffc3:
-    jh->bits = data[0];
-    jh->high = data[1] << 8 | data[2];
-    jh->wide = data[3] << 8 | data[4];
-    jh->clrs = data[5];
-    break;
+        jh->bits = data[0];
+        jh->high = data[1] << 8 | data[2];
+        jh->wide = data[3] << 8 | data[4];
+        jh->clrs = data[5];
+        break;
       case 0xffc4:
-    for (dp = data; dp < data+len && *dp < 4; ) {
-      jh->huff[*dp] = free_decode;
-      dp = make_decoder (++dp, 0);
-    }
+        for (dp = data; dp < data+dataLen && *dp < 4; ) {
+          jh->huff[*dp] = free_decode;
+          dp = make_decoder (++dp, 0);
+        }
+      }
     }
   } while (tag != 0xffda);
   jh->row = calloc (jh->wide*jh->clrs, 2);
diff --git a/converter/other/pnmtorle.c b/converter/other/pnmtorle.c
index 180b144f..8908c356 100644
--- a/converter/other/pnmtorle.c
+++ b/converter/other/pnmtorle.c
@@ -212,7 +212,6 @@ main(int argc, char **  argv) {
 
     const char * pnmname;
     const char * outname;
-    static char filename[BUFSIZ];
     int oflag;
 
     pnm_init(&argc, argv);
@@ -239,11 +238,9 @@ main(int argc, char **  argv) {
 
     /* Open the file. */
     if (pnmname == NULL) {
-        strcpy(filename, "stdin");
         fp = pm_openr("-");
     } else {
-        strcpy(filename, pnmname);
-        fp = pm_openr(filename);
+        fp = pm_openr(pnmname);
     }
 
     hdr.rle_file = rle_open_f( hdr.cmd, outname, "wb" );
diff --git a/converter/pbm/pbmtoatk.c b/converter/pbm/pbmtoatk.c
index dd829776..9399f602 100644
--- a/converter/pbm/pbmtoatk.c
+++ b/converter/pbm/pbmtoatk.c
@@ -125,7 +125,6 @@ main(int argc, char *argv[]) {
     register bit *bP;
     int rows, cols, format, row;
     int col;
-    char name[100], *cp;
     unsigned char curbyte, newbyte;
     int curcount, gather;
 
@@ -136,15 +135,8 @@ main(int argc, char *argv[]) {
 
     else if (argc-1 == 1) {
         ifd = pm_openr( argv[1] );
-        strcpy(name, argv[1]);
-        if (streq( name, "-"))
-            strcpy(name, "noname");
-        
-        if ((cp = strchr(name, '.')) != 0)
-            *cp = '\0';
     } else {
         ifd = stdin;
-        strcpy( name, "noname" );
     }
 
     pbm_readpbminit(ifd, &cols, &rows, &format);
diff --git a/converter/pbm/pbmtog3.c b/converter/pbm/pbmtog3.c
index 04ea651f..cd96c9dc 100644
--- a/converter/pbm/pbmtog3.c
+++ b/converter/pbm/pbmtog3.c
@@ -440,7 +440,7 @@ main(int    argc,
 
     MALLOCARRAY_NOFAIL(bitrow, pbm_packed_bytes(cols) + sizeof(wordint));
 
-    MALLOCARRAY_NOFAIL(milepost, readcols + 1);
+    MALLOCARRAY_NOFAIL(milepost, readcols + 2);
 
     initOutStream(cmdline.reversebits);
     puteol();
diff --git a/converter/pbm/pbmtopk.c b/converter/pbm/pbmtopk.c
index a9683190..fc94f855 100644
--- a/converter/pbm/pbmtopk.c
+++ b/converter/pbm/pbmtopk.c
@@ -854,11 +854,17 @@ main(int argc, char *argv[]) {
     initialize_pk() ;
    
     if (--argc < 1) pm_usage(usage) ;
-    strcpy(pkname, *++argv) ;
+    ++argv;
+    if(strlen(*argv) + 4 > NAMELENGTH)
+        pm_error("pkname is too long");
+    strcpy(pkname, *argv) ;
     pbmtopk_add_suffix(pkname, ".pk") ;
    
-    if (--argc < 1) pm_usage(usage) ;
-    strcpy(tfmname, *++argv) ;
+    if (--argc < 1) pm_usage(usage);
+    ++argv;
+    if(strlen(*argv) + 4 > NAMELENGTH)
+        pm_error("tfmname is too long");
+    strcpy(tfmname, *argv) ;
     pbmtopk_add_suffix(tfmname, ".tfm") ;
    
     if (--argc < 1) pm_usage(usage) ;
diff --git a/converter/pbm/pktopbm.c b/converter/pbm/pktopbm.c
index a3584ee5..712f339f 100644
--- a/converter/pbm/pktopbm.c
+++ b/converter/pbm/pktopbm.c
@@ -214,7 +214,10 @@ main(int argc, char *argv[]) {
 
     if (--argc < 1) pm_usage(usage) ;
 
-    strcpy(pkname, *++argv) ;
+    ++argv;
+    if(strlen(*argv) + 4 > NAMELENGTH)
+        pm_error("pkname is too long");
+    strcpy(pkname, *argv) ;
     pktopbm_add_suffix(pkname, ".pk") ;
 
     car = 0 ;
diff --git a/converter/pgm/sbigtopgm.c b/converter/pgm/sbigtopgm.c
index 2e8b4586..3c223c47 100644
--- a/converter/pgm/sbigtopgm.c
+++ b/converter/pgm/sbigtopgm.c
@@ -127,8 +127,8 @@ struct SbigHeader {
     unsigned int cols;
     unsigned int maxval;
     bool isCompressed;
-    bool haveCameraType;
-    char cameraType[80];
+    const char * cameraType;
+        /* Null means information not in header */
 };
 
 
@@ -141,15 +141,19 @@ readSbigHeader(FILE *              const ifP,
     bool gotCompression;
     bool gotWidth;
     bool gotHeight;
-    char buffer[SBIG_HEADER_LENGTH];
+    char * buffer;  /* malloced */
     char * cursor;
     bool endOfHeader;
 
+    MALLOCARRAY_NOFAIL(buffer, SBIG_HEADER_LENGTH + 1);
+
     rc = fread(buffer, SBIG_HEADER_LENGTH, 1, ifP);
 
     if (rc < 1)
         pm_error("error reading SBIG file header");
 
+    buffer[SBIG_HEADER_LENGTH] = '\0';
+
     /*  The SBIG header specification equivalent to maxval is
         "Sat_level", the saturation level of the image.  This
         specification is optional, and was not included in files
@@ -171,6 +175,12 @@ readSbigHeader(FILE *              const ifP,
         converse, pixels having values greater than maxval, results in
         an invalid file which may cause problems in programs which
         attempt to process it.
+
+         According to the official specification, the camera type name is the
+         first item in the header, and may or may not start with "ST-".  But
+         this program has historically had an odd method of detecting camera
+         type, which allows any string starting with "ST-" anywhere in the
+         header, and for now we leave that undisturbed.  2015.05.27.
     */
 
     gotCompression = false;  /* initial value */
@@ -178,7 +188,7 @@ readSbigHeader(FILE *              const ifP,
     gotHeight      = false;  /* initial value */
 
     sbigHeaderP->maxval = 65535;  /* initial assumption */
-    sbigHeaderP->haveCameraType = false;  /* initial assumption */
+    sbigHeaderP->cameraType = NULL;  /* initial assumption */
 
     for (cursor = &buffer[0], endOfHeader = false; !endOfHeader;) {
         char * const cp = strchr(cursor, '\n');
@@ -188,13 +198,14 @@ readSbigHeader(FILE *              const ifP,
                      (unsigned)(cursor - &buffer[0]));
         }
         *cp = '\0';
-        if (strneq(cursor, "ST-", 3)) {
+        if (strneq(cursor, "ST-", 3) ||
+            (cursor == &buffer[0] && strstr(cursor,"Image") != NULL)) {
+
             char * const ep = strchr(cursor + 3, ' ');
 
             if (ep != NULL) {
                 *ep = '\0';
-                strcpy(sbigHeaderP->cameraType, cursor);
-                sbigHeaderP->haveCameraType = true;
+                sbigHeaderP->cameraType = pm_strdup(cursor);
                 *ep = ' ';
             }
         }
@@ -202,8 +213,9 @@ readSbigHeader(FILE *              const ifP,
         looseCanon(cursor);
             /* Convert from standard SBIG to an internal format */
 
-        if (strneq(cursor, "st-", 3)) {
-            sbigHeaderP->isCompressed = (strstr("compressed", cursor) != NULL);
+        if (strneq(cursor, "st-", 3) || cursor == &buffer[0]) {
+            sbigHeaderP->isCompressed =
+                 (strstr(cursor, "compressedimage") != NULL);
             gotCompression = true;
         } else if (strneq(cursor, "height=", 7)) {
             sbigHeaderP->rows = atoi(cursor + 7);
@@ -233,6 +245,15 @@ readSbigHeader(FILE *              const ifP,
 
 
 static void
+termSbigHeader(struct SbigHeader const sbigHeader) {
+
+    if (sbigHeader.cameraType)
+        pm_strfree(sbigHeader.cameraType);
+}
+
+
+
+static void
 writeRaster(FILE *            const ifP,
             struct SbigHeader const hdr,
             FILE *            const ofP) {
@@ -306,7 +327,7 @@ main(int argc, const char ** argv) {
     readSbigHeader(ifP, &hdr);
 
     pm_message("SBIG '%s' %ux%u %s image, saturation level = %u",
-               (hdr.haveCameraType ? hdr.cameraType : "ST-?"),
+               (hdr.cameraType ? hdr.cameraType : "ST-?"),
                hdr.cols, hdr.rows,
                hdr.isCompressed ? "compressed" : "uncompressed",
                hdr.maxval);
@@ -320,6 +341,8 @@ main(int argc, const char ** argv) {
 
     writeRaster(ifP, hdr, stdout);
 
+    termSbigHeader(hdr);
+
     pm_close(ifP);
     pm_close(stdout);
 
diff --git a/converter/ppm/ppmtoyuvsplit.c b/converter/ppm/ppmtoyuvsplit.c
index e4ffaa3a..eb89ad29 100644
--- a/converter/ppm/ppmtoyuvsplit.c
+++ b/converter/ppm/ppmtoyuvsplit.c
@@ -29,8 +29,40 @@
 #endif
 
 #include <string.h>
+#include "nstring.h"
 #include "ppm.h"
 
+
+
+struct FileNameSet {
+    const char * u;
+    const char * v;
+    const char * y;
+};
+
+
+
+static void
+makeOutputFileName(const char *         const baseName,
+                   struct FileNameSet * const fnameP) {
+
+    pm_asprintf(&fnameP->u, "%s.U", baseName);
+    pm_asprintf(&fnameP->v, "%s.V", baseName);
+    pm_asprintf(&fnameP->y, "%s.Y", baseName);
+}
+
+
+
+static void
+termFileNameSet(struct FileNameSet const fname) {
+
+    pm_strfree(fname.u);
+    pm_strfree(fname.v);
+    pm_strfree(fname.y);
+}
+
+
+
 int
 main(int argc, const char ** argv) {
 
@@ -42,7 +74,8 @@ main(int argc, const char ** argv) {
     unsigned int row;
     pixval maxval;
     unsigned char *y1buf, *y2buf, *ubuf, *vbuf;
-    char ufname[256], vfname[256], yfname[256];
+    struct FileNameSet fname;
+        /* Output file names - .U, .V, .Y */
 
     pm_proginit(&argc, argv);
 
@@ -56,17 +89,13 @@ main(int argc, const char ** argv) {
     else
         ifP = stdin;
 
-    strcpy(ufname,argv[1]);
-    strcpy(vfname,argv[1]);
-    strcpy(yfname,argv[1]);
+    makeOutputFileName(argv[1], &fname);
 
-    strcat(ufname,".U");
-    strcat(vfname,".V");
-    strcat(yfname,".Y");
+    uf = pm_openw(fname.u);
+    vf = pm_openw(fname.v);
+    yf = pm_openw(fname.y);
 
-    uf = pm_openw(ufname);
-    vf = pm_openw(vfname);
-    yf = pm_openw(yfname);
+    termFileNameSet(fname);
 
     ppm_readppminit(ifP, &cols, &rows, &maxval, &format);