
Thread
2011.12.21 14:52 "[Tiff] Proposed patch for ppm2tiff", by Jürgen_Buchmüller
The attached patch extends the ppm2tiff tool with an option
-m mode open the output.tif with 'mode', e.g. a for append
This makes it easy to put multiple PNM images, or e.g djpeg outputs, into a single TIFF like:
djpeg 1.jpg | ppm2tiff -m a -c jpeg:90 output.tif
djpeg 2.jpg | ppm2tiff -m a -c jpeg:90 output.tif
...
djpeg 9.jpg | ppm2tiff -m a -c jpeg:90 output.tif
Right now you have to create single TIFFs and later use tiffcp to join them into a multi-image TIFF.
The patch is against 3.9.1 while I don't think it should fail on newer releases, unless ppm2tiff.c changed too much.
Regards,
Juergen
--
Jürgen Buchmüller <pullmoll@t-online.de>
--- tiff_3_9_1.old/tools/ppm2tiff.c 2006-04-20 14:36:23.000000000 +0200
+++ tiff_3_9_1/tools/ppm2tiff.c 2011-12-21 15:10:57.592872206 +0100
@@ -75,6 +75,7 @@
uint32 rowsperstrip = (uint32) -1;
double resolution = -1;
unsigned char *buf = NULL;
+ char tiff_mode[32] = "w";
tsize_t linebytes = 0;
uint16 spp = 1;
uint16 bpp = 8;
@@ -90,12 +91,16 @@
fprintf(stderr, "%s: Too few arguments\n", argv[0]);
usage();
}
- while ((c = getopt(argc, argv, "c:r:R:")) != -1)
+ while ((c = getopt(argc, argv, "c:m:r:R:")) != -1)
switch (c) {
case 'c': /* compression scheme */
if (!processCompressOptions(optarg))
usage();
break;
+ case 'm':
+ strncpy(tiff_mode, optarg, sizeof(tiff_mode) - 1);
+ tiff_mode[sizeof(tiff_mode) - 1] = '\0';
+ break;
case 'r': /* rows/strip */
rowsperstrip = atoi(optarg);
break;
@@ -190,7 +195,7 @@
BadPPM(infile);
break;
}
- out = TIFFOpen(argv[optind], "w");
+ out = TIFFOpen(argv[optind], tiff_mode);
if (out == NULL)
return (-4);
TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (uint32) w);
@@ -319,6 +324,7 @@
char* stuff[] = {
"usage: ppm2tiff [options] input.ppm output.tif",
"where options are:",
+" -m mode open the output.tif with 'mode', e.g. a for append",
" -r # make each strip have no more than # rows",
" -R # set x&y resolution (dpi)",
"",