1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
/*
* mtifftest.c
*
* Tests tiff I/O for:
*
* -- multipage tiff read/write
* -- writing special tiff tags to file
*/
#include <stdio.h>
#include <stdlib.h>
#include "allheaders.h"
static const char *tempmtiff = "/usr/tmp/junkmtiff";
static const char *tempnewmtiff = "/usr/tmp/junknewmtiff";
main(int argc,
char **argv)
{
char *filein, *fileout, *str, *fname, *filename;
char buffer[512];
l_int32 i, count, npages, length;
FILE *fp;
NUMA *naflags, *nasizes;
PIX *pix;
PIXA *pixa;
PIXCMAP *cmap;
SARRAY *savals, *satypes, *sa;
static char mainName[] = "mtifftest";
if (argc != 3)
exit(ERROR_INT(" Syntax: mtifftest filein fileout", mainName, 1));
filein = argv[1];
fileout = argv[2];
#if 0 /* ------------ Test single-to-multipage I/O -------------------*/
/* Use 'filein' to specify a directory of tiff files.
* Read them in and generate a multipage tiff file.
* Then convert that to a G4 compressed and ascii85 encoded
* PS file. */
sa = getFilenamesInDirectory(filein);
sarrayWriteStream(stderr, sa);
sarraySort(sa, sa, L_SORT_INCREASING);
sarrayWriteStream(stderr, sa);
npages = sarrayGetCount(sa);
for (i = 0; i < npages; i++) {
fname = sarrayGetString(sa, i, 0);
filename = genPathname(filein, fname);
pix = pixRead(filename);
if (!pix) continue;
if (i == 0)
pixWriteTiff(tempmtiff, pix, IFF_TIFF_G4, "w+");
else
pixWriteTiff(tempmtiff, pix, IFF_TIFF_G4, "a");
pixDestroy(&pix);
FREE(filename);
}
/* write it out as a PS file */
convertTiffMultipageToPS(tempmtiff, fileout, NULL, 0.95);
sarrayDestroy(&sa);
#endif
#if 1 /* ------------------ Test multipage I/O -------------------*
/* read count of tiff multipage */
fp = fopen(filein, "r");
if (fileFormatIsTiff(fp)) {
tiffGetCount(fp, &npages);
fprintf(stderr, " Tiff: %d page\n", npages);
}
else
exit(ERROR_INT(" file not tiff", mainName, 1));
fclose(fp);
/* split into separate page files */
for (i = 0; i < npages + 1; i++) { /* read one beyond to catch error */
pix = pixReadTiff(filein, i);
if (!pix) continue;
sprintf(buffer, "junkout.%d", i);
pixWrite(buffer, pix, IFF_TIFF_G4);
pixDestroy(&pix);
}
/* read separate page files and write reversed file */
for (i = npages - 1; i >= 0; i--) {
sprintf(buffer, "junkout.%d", i);
pix = pixRead(buffer);
if (!pix) continue;
if (i == npages - 1)
pixWriteTiff(tempmtiff, pix, IFF_TIFF_G4, "w+");
else
pixWriteTiff(tempmtiff, pix, IFF_TIFF_G4, "a");
pixDestroy(&pix);
}
/* read reversed file and reverse again */
pixa = pixaCreate(npages);
for (i = 0; i < 5; i++) {
pix = pixReadTiff(tempmtiff, i);
pixaAddPix(pixa, pix, L_INSERT);
}
for (i = npages - 1; i >= 0; i--) {
pix = pixaGetPix(pixa, i, L_CLONE);
if (i == npages - 1)
pixWriteTiff(tempnewmtiff, pix, IFF_TIFF_G4, "w+");
else
pixWriteTiff(tempnewmtiff, pix, IFF_TIFF_G4, "a");
pixDestroy(&pix);
}
pixaDestroy(&pixa);
#endif
#if 0 /* ----- test adding custom public tags to a tiff header ----- */
pix = pixRead(filein);
naflags = numaCreate(10);
savals = sarrayCreate(10);
satypes = sarrayCreate(10);
nasizes = numaCreate(10);
/* numaAddNumber(naflags, TIFFTAG_XMLPACKET); */ /* XMP: 700 */
numaAddNumber(naflags, 700);
str = "<xmp>This is a Fake XMP packet</xmp>\n<text>Guess what ...?</text>";
length = strlen(str);
sarrayAddString(savals, str, 1);
sarrayAddString(satypes, "char*", 1);
numaAddNumber(nasizes, length); /* get it all */
numaAddNumber(naflags, 269); /* DOCUMENTNAME */
sarrayAddString(savals, "One silly title", 1);
sarrayAddString(satypes, "char*", 1);
numaAddNumber(naflags, 270); /* IMAGEDESCRIPTION */
sarrayAddString(savals, "One page of text", 1);
sarrayAddString(satypes, "char*", 1);
/* the max sample is used by rendering programs
* to scale the dynamic range */
numaAddNumber(naflags, 281); /* MAXSAMPLEVALUE */
sarrayAddString(savals, "4", 1);
sarrayAddString(satypes, "l_uint16", 1);
/* note that date is required to be a 20 byte string */
numaAddNumber(naflags, 306); /* DATETIME */
sarrayAddString(savals, "2004:10:11 09:35:15", 1);
sarrayAddString(satypes, "char*", 1);
/* note that page number requires 2 l_uint16 input */
numaAddNumber(naflags, 297); /* PAGENUMBER */
sarrayAddString(savals, "1-412", 1);
sarrayAddString(satypes, "l_uint16-l_uint16", 1);
pixWriteTiffCustom(fileout, pix, IFF_TIFF_G4, "w", naflags,
savals, satypes, nasizes);
fprintTiffInfo(stderr, fileout);
numaDestroy(&naflags);
numaDestroy(&nasizes);
sarrayDestroy(&savals);
sarrayDestroy(&satypes);
pixDestroy(&pix);
#endif
exit(0);
}
|