tools/tiff2ps.c:1558: error: Integer Overflow L2
  ([0, 4294967294] + [0, 4294967294]):unsigned32 by call to `psMaskImage`.

tools/tiff2ps.c:1486:1: Parameter `tif->tif_dir.td_imagelength`
1484.  */
1485. 
1486. int TIFF2PS(FILE* fd, TIFF* tif, double pgwidth, double pgheight, double lm, double bm, int center)
      ^
1487.   {
1488.   uint32 pixwidth = 0, pixheight = 0;  /* Image width and height in pixels */

tools/tiff2ps.c:1506:24: Call
1504.   /* Consolidated all the tag information into one code segment, Richard Nolde */
1505.   do {
1506.      tf_numberstrips = TIFFNumberOfStrips(tif);
                             ^
1507.      TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &tf_rowsperstrip);
1508.      TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &bitspersample);

libtiff/tif_strip.c:58:1: Parameter `tif->tif_dir.td_imagelength`
  56.  * Compute how many strips are in an image.
  57.  */
  58. uint32
      ^
  59. TIFFNumberOfStrips(TIFF* tif)
  60. {

tools/tiff2ps.c:1558:15: Call
1556.         if ((maxPageHeight) || (maxPageWidth)) /* used -H or -W  option */
1557.            {
1558.           if (psMaskImage(fd, tif, rotation, center, &npages, pixwidth, pixheight,
                    ^
1559.                           left_offset, bottom_offset, pgwidth, pgheight,
1560.                            pswidth, psheight, scale) < 0)

tools/tiff2ps.c:1186:1: Parameter `tif->tif_dir.td_imagelength`
  1184.  * by the maxPageHeight or maxPageWidth options.
  1185.  */
  1186. int psMaskImage(FILE *fd, TIFF *tif, int rotation, int center,
        ^
  1187.                 int *npages, double pixwidth, double pixheight,
  1188.                double left_margin, double bottom_margin,

tools/tiff2ps.c:1235:8: Call
  1233.         return (-1);
  1234.         }
  1235.        PSpage(fd, tif, pixwidth, pixheight);
               ^
  1236.        fprintf(fd, "end\n");
  1237.        fprintf(fd, "grestore\n");

tools/tiff2ps.c:2335:1: Parameter `tif->tif_dir.td_imagelength`
    2333. }
    2334. 
    2335. void
          ^
    2336. PSpage(FILE* fd, TIFF* tif, uint32 w, uint32 h)
    2337. {

tools/tiff2ps.c:2343:28: Call
    2341. 		imageOp = "imagemask";
    2342. 
    2343. 	if ((level2 || level3) && PS_Lvl2page(fd, tif, w, h))
                                     ^
    2344. 		return;
    2345. 	ps_bytesperrow = tf_bytesperrow - (extrasamples * bitspersample / 8)*w;

tools/tiff2ps.c:2146:1: Parameter `tif->tif_dir.td_imagelength`
      2144. #define MAXLINE		36
      2145. 
      2146. int
            ^
      2147. PS_Lvl2page(FILE* fd, TIFF* tif, uint32 w, uint32 h)
      2148. {

tools/tiff2ps.c:2162:16: Call
      2160. 
      2161. 	PS_Lvl2colorspace(fd, tif);
      2162. 	use_rawdata = PS_Lvl2ImageDict(fd, tif, w, h);
                           ^
      2163. 
      2164. /* See http://bugzilla.remotesensing.org/show_bug.cgi?id=80 */

tools/tiff2ps.c:1795:1: Parameter `tif->tif_dir.td_imagelength`
        1793. }
        1794. 
        1795. static int
              ^
        1796. PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h)
        1797. {

tools/tiff2ps.c:1814:18: Call
        1812. 	tile_height = h;
        1813. 	if (TIFFIsTiled(tif)) {
        1814. 		repeat_count = TIFFNumberOfTiles(tif);
                               ^
        1815. 		TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tile_width);
        1816. 		TIFFGetField(tif, TIFFTAG_TILELENGTH, &tile_height);

libtiff/tif_tile.c:112:1: <LHS trace>
110.  * Compute how many tiles are in an image.
111.  */
112. uint32
     ^
113. TIFFNumberOfTiles(TIFF* tif)
114. {

libtiff/tif_tile.c:112:1: Parameter `tif->tif_dir.td_imagelength`
          110.  * Compute how many tiles are in an image.
          111.  */
          112. uint32
               ^
          113. TIFFNumberOfTiles(TIFF* tif)
          114. {

libtiff/tif_tile.c:112:1: <RHS trace>
110.  * Compute how many tiles are in an image.
111.  */
112. uint32
     ^
113. TIFFNumberOfTiles(TIFF* tif)
114. {

libtiff/tif_tile.c:112:1: Parameter `tif->tif_dir.td_imagelength`
          110.  * Compute how many tiles are in an image.
          111.  */
          112. uint32
               ^
          113. TIFFNumberOfTiles(TIFF* tif)
          114. {

libtiff/tif_tile.c:129:6: Binary operation: ([0, 4294967294] + [0, 4294967294]):unsigned32 by call to `psMaskImage` 
          127. 	ntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 :
          128. 	    _TIFFMultiply32(tif, _TIFFMultiply32(tif, TIFFhowmany_32(td->td_imagewidth, dx),
          129. 	    TIFFhowmany_32(td->td_imagelength, dy),
                    ^
          130. 	    "TIFFNumberOfTiles"),
          131. 	    TIFFhowmany_32(td->td_imagedepth, dz), "TIFFNumberOfTiles");

uint32
TIFFNumberOfTiles(TIFF* tif)
{
	TIFFDirectory *td = &tif->tif_dir;
	uint32 dx = td->td_tilewidth;
	uint32 dy = td->td_tilelength;
	uint32 dz = td->td_tiledepth;
	uint32 ntiles;
	if (dx == (uint32) -1)
		dx = td->td_imagewidth;
	if (dy == (uint32) -1)
		dy = td->td_imagelength;
	if (dz == (uint32) -1)
		dz = td->td_imagedepth;
	ntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 :
	    _TIFFMultiply32(tif, _TIFFMultiply32(tif, TIFFhowmany_32(td->td_imagewidth, dx),
	    TIFFhowmany_32(td->td_imagelength, dy),
	    "TIFFNumberOfTiles"),
	    TIFFhowmany_32(td->td_imagedepth, dz), "TIFFNumberOfTiles");
	if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
		ntiles = _TIFFMultiply32(tif, ntiles, td->td_samplesperpixel,
		    "TIFFNumberOfTiles");
	return (ntiles);
}
['int TIFF2PS(FILE* fd, TIFF* tif, double pgwidth, double pgheight, double lm, double bm, int center)\n  {\n  uint32 pixwidth = 0, pixheight = 0;\n  double ox = 0.0, oy = 0.0;\n  double pswidth, psheight;\n  double view_width, view_height;\n  double scale = 1.0;\n  double left_offset = lm * PS_UNIT_SIZE;\n  double bottom_offset = bm * PS_UNIT_SIZE;\n  uint32 subfiletype;\n  uint16* sampleinfo;\n  static int npages = 0;\n  if (!TIFFGetField(tif, TIFFTAG_XPOSITION, &ox))\n     ox = 0;\n  if (!TIFFGetField(tif, TIFFTAG_YPOSITION, &oy))\n     oy = 0;\n  do {\n     tf_numberstrips = TIFFNumberOfStrips(tif);\n     TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &tf_rowsperstrip);\n     TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &bitspersample);\n     TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel);\n     TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planarconfiguration);\n     TIFFGetField(tif, TIFFTAG_COMPRESSION, &compression);\n     TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES, &extrasamples, &sampleinfo);\n     alpha = (extrasamples == 1 && sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA);\n     if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric))\n       {\n       switch (samplesperpixel - extrasamples)\n             {\n            case 1: if (isCCITTCompression(tif))\n                      photometric = PHOTOMETRIC_MINISWHITE;\n                    else\n                       photometric = PHOTOMETRIC_MINISBLACK;\n                    break;\n            case 3: photometric = PHOTOMETRIC_RGB;\n                    break;\n            case 4: photometric = PHOTOMETRIC_SEPARATED;\n                    break;\n            }\n       }\n     setupPageState(tif, &pixwidth, &pixheight, &pswidth, &psheight);\n     view_width = pswidth;\n     view_height = psheight;\n     if (get_viewport (pgwidth, pgheight, pswidth, psheight, &view_width, &view_height, rotation))\n       {\n       TIFFError("get_viewport", "Unable to set image viewport");\n       return (1);\n       }\n     if (psStart(fd, npages, auto_rotate, &rotation, &scale, ox, oy,\n                pgwidth, pgheight, view_width, view_height, pswidth, psheight,\n                 left_offset, bottom_offset))\n       return (-1);\n     if (checkImage(tif))\n       {\n       tf_bytesperrow = TIFFScanlineSize(tif);\n       if ((maxPageHeight) || (maxPageWidth)  || (pgwidth != 0) || (pgheight != 0))\n         {\n        if ((maxPageHeight) || (maxPageWidth))\n           {\n          if (psMaskImage(fd, tif, rotation, center, &npages, pixwidth, pixheight,\n                          left_offset, bottom_offset, pgwidth, pgheight,\n                           pswidth, psheight, scale) < 0)\n            return (-1);\n          }\n         else\n           {\n           if (pgwidth != 0 || pgheight != 0)\n             {\n             npages++;\n             fprintf(fd, "%%%%Page: %d %d\\n", npages, npages);\n             if (!generateEPSF && ( level2 || level3 ))\n               {\n              if (psPageSize(fd, rotation, pgwidth, pgheight,\n                              view_width, view_height, pswidth, psheight))\n                return (-1);\n               }\n             fprintf(fd, "gsave\\n");\n             fprintf(fd, "100 dict begin\\n");\n             if (psScaleImage(fd, scale, rotation, center, view_width, view_height,\n                              pswidth, psheight, left_offset, bottom_offset))\n              return (-1);\n             PSpage(fd, tif, pixwidth, pixheight);\n             fprintf(fd, "end\\n");\n             fprintf(fd, "grestore\\n");\n             fprintf(fd, "showpage\\n");\n            }\n          }\n        }\n       else\n         {\n         npages++;\n         fprintf(fd, "%%%%Page: %d %d\\n", npages, npages);\n         if (!generateEPSF && ( level2 || level3 ))\n           {\n          if (psPageSize(fd, rotation, pgwidth, pgheight,\n                          view_width, view_height, pswidth, psheight))\n           return (-1);\n         }\n         fprintf(fd, "gsave\\n");\n         fprintf(fd, "100 dict begin\\n");\n        if (psRotateImage(fd, rotation, pswidth, psheight, left_offset, bottom_offset))\n           return (-1);\n         PSpage(fd, tif, pixwidth, pixheight);\n         fprintf(fd, "end\\n");\n         fprintf(fd, "grestore\\n");\n         fprintf(fd, "showpage\\n");\n         }\n       }\n  if (generateEPSF)\n    break;\n  if (auto_rotate)\n    rotation = 0.0;\n  TIFFGetFieldDefaulted(tif, TIFFTAG_SUBFILETYPE, &subfiletype);\n  } while (((subfiletype & FILETYPE_PAGE) || printAll) && TIFFReadDirectory(tif));\nreturn(npages);\n}', 'uint32\nTIFFNumberOfStrips(TIFF* tif)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint32 nstrips;\n\tnstrips = (td->td_rowsperstrip == (uint32) -1 ? 1 :\n\t     TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip));\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\tnstrips = _TIFFMultiply32(tif, nstrips, (uint32)td->td_samplesperpixel,\n\t\t    "TIFFNumberOfStrips");\n\treturn (nstrips);\n}', 'int psMaskImage(FILE *fd, TIFF *tif, int rotation, int center,\n                int *npages, double pixwidth, double pixheight,\n               double left_margin, double bottom_margin,\n                double pgwidth, double pgheight,\n               double pswidth, double psheight, double scale)\n  {\n  int i, j;\n  int ximages = 1, yimages = 1;\n  int pages = *npages;\n  double view_width = 0;\n  double view_height = 0;\n  if (get_viewport (pgwidth, pgheight, pswidth, psheight, &view_width, &view_height, rotation))\n    {\n    TIFFError ("get_viewport", "Unable to set image viewport");\n    return (-1);\n    }\n  if (get_subimage_count(pgwidth, pgheight, pswidth, psheight,\n                        &ximages, &yimages, rotation, scale) < 1)\n    {\n    TIFFError("get_subimage_count", "Invalid image count: %d columns, %d rows", ximages, yimages);\n    return (-1);\n    }\n  for (i = 0; i < yimages; i++)\n    {\n    for (j = 0; j < ximages; j++)\n       {\n       pages++;\n       *npages = pages;\n       fprintf(fd, "%%%%Page: %d %d\\n", pages, pages);\n       if (!generateEPSF && ( level2 || level3 ))\n         {\n         if (psPageSize(fd, rotation, pgwidth, pgheight,\n                        view_width, view_height, pswidth, psheight))\n           return (-1);\n        }\n       fprintf(fd, "gsave\\n");\n       fprintf(fd, "100 dict begin\\n");\n       if (exportMaskedImage(fd, view_width, view_height, pswidth, psheight,\n                            i, j, left_margin, bottom_margin,\n                            scale, center, rotation))\n        {\n        TIFFError("exportMaskedImage", "Invalid image parameters.");\n        return (-1);\n        }\n       PSpage(fd, tif, pixwidth, pixheight);\n       fprintf(fd, "end\\n");\n       fprintf(fd, "grestore\\n");\n       fprintf(fd, "showpage\\n");\n       }\n    }\n  return (pages);\n  }', 'void\nPSpage(FILE* fd, TIFF* tif, uint32 w, uint32 h)\n{\n\tchar\t*\timageOp = "image";\n\tif ( useImagemask && (bitspersample == 1) )\n\t\timageOp = "imagemask";\n\tif ((level2 || level3) && PS_Lvl2page(fd, tif, w, h))\n\t\treturn;\n\tps_bytesperrow = tf_bytesperrow - (extrasamples * bitspersample / 8)*w;\n\tswitch (photometric) {\n\tcase PHOTOMETRIC_RGB:\n\t\tif (planarconfiguration == PLANARCONFIG_CONTIG) {\n\t\t\tfprintf(fd, "%s", RGBcolorimage);\n\t\t\tPSColorContigPreamble(fd, w, h, 3);\n\t\t\tPSDataColorContig(fd, tif, w, h, 3);\n\t\t} else {\n\t\t\tPSColorSeparatePreamble(fd, w, h, 3);\n\t\t\tPSDataColorSeparate(fd, tif, w, h, 3);\n\t\t}\n\t\tbreak;\n\tcase PHOTOMETRIC_SEPARATED:\n\t\tif (planarconfiguration == PLANARCONFIG_CONTIG) {\n\t\t\tPSColorContigPreamble(fd, w, h, 4);\n\t\t\tPSDataColorContig(fd, tif, w, h, 4);\n\t\t} else {\n\t\t\tPSColorSeparatePreamble(fd, w, h, 4);\n\t\t\tPSDataColorSeparate(fd, tif, w, h, 4);\n\t\t}\n\t\tbreak;\n\tcase PHOTOMETRIC_PALETTE:\n\t\tfprintf(fd, "%s", RGBcolorimage);\n\t\tPhotoshopBanner(fd, w, h, 1, 3, "false 3 colorimage");\n\t\tfprintf(fd, "/scanLine %ld string def\\n",\n\t\t    (long) ps_bytesperrow * 3L);\n\t\tfprintf(fd, "%lu %lu 8\\n",\n\t\t    (unsigned long) w, (unsigned long) h);\n\t\tfprintf(fd, "[%lu 0 0 -%lu 0 %lu]\\n",\n\t\t    (unsigned long) w, (unsigned long) h, (unsigned long) h);\n\t\tfprintf(fd, "{currentfile scanLine readhexstring pop} bind\\n");\n\t\tfprintf(fd, "false 3 colorimage\\n");\n\t\tPSDataPalette(fd, tif, w, h);\n\t\tbreak;\n\tcase PHOTOMETRIC_MINISBLACK:\n\tcase PHOTOMETRIC_MINISWHITE:\n\t\tPhotoshopBanner(fd, w, h, 1, 1, imageOp);\n\t\tfprintf(fd, "/scanLine %ld string def\\n",\n\t\t    (long) ps_bytesperrow);\n\t\tfprintf(fd, "%lu %lu %d\\n",\n\t\t    (unsigned long) w, (unsigned long) h, bitspersample);\n\t\tfprintf(fd, "[%lu 0 0 -%lu 0 %lu]\\n",\n\t\t    (unsigned long) w, (unsigned long) h, (unsigned long) h);\n\t\tfprintf(fd,\n\t\t    "{currentfile scanLine readhexstring pop} bind\\n");\n\t\tfprintf(fd, "%s\\n", imageOp);\n\t\tPSDataBW(fd, tif, w, h);\n\t\tbreak;\n\t}\n\tputc(\'\\n\', fd);\n}', 'int\nPS_Lvl2page(FILE* fd, TIFF* tif, uint32 w, uint32 h)\n{\n\tuint16 fillorder;\n\tint use_rawdata, tiled_image, breaklen = MAXLINE;\n\tuint32 chunk_no, num_chunks;\n        uint64 *bc;\n\tunsigned char *buf_data, *cp;\n\ttsize_t chunk_size, byte_count;\n#if defined( EXP_ASCII85ENCODER )\n\ttsize_t\t\t\tascii85_l;\n\tuint8\t\t*\tascii85_p = 0;\n#endif\n\tPS_Lvl2colorspace(fd, tif);\n\tuse_rawdata = PS_Lvl2ImageDict(fd, tif, w, h);\n#ifdef ENABLE_BROKEN_BEGINENDDATA\n\tfputs("%%BeginData:\\n", fd);\n#endif\n\tfputs("exec\\n", fd);\n\ttiled_image = TIFFIsTiled(tif);\n\tif (tiled_image) {\n\t\tnum_chunks = TIFFNumberOfTiles(tif);\n\t\tTIFFGetField(tif, TIFFTAG_TILEBYTECOUNTS, &bc);\n\t} else {\n\t\tnum_chunks = TIFFNumberOfStrips(tif);\n\t\tTIFFGetField(tif, TIFFTAG_STRIPBYTECOUNTS, &bc);\n\t}\n\tif (use_rawdata) {\n\t\tchunk_size = (tsize_t) bc[0];\n\t\tfor (chunk_no = 1; chunk_no < num_chunks; chunk_no++)\n\t\t\tif ((tsize_t) bc[chunk_no] > chunk_size)\n\t\t\t\tchunk_size = (tsize_t) bc[chunk_no];\n\t} else {\n\t\tif (tiled_image)\n\t\t\tchunk_size = TIFFTileSize(tif);\n\t\telse\n\t\t\tchunk_size = TIFFStripSize(tif);\n\t}\n\tbuf_data = (unsigned char *)_TIFFmalloc(chunk_size);\n\tif (!buf_data) {\n\t\tTIFFError(filename, "Can\'t alloc %lu bytes for %s.",\n\t\t\t(unsigned long) chunk_size, tiled_image ? "tiles" : "strips");\n\t\treturn(FALSE);\n\t}\n#if defined( EXP_ASCII85ENCODER )\n\tif ( ascii85 ) {\n\t    ascii85_p = _TIFFmalloc( (chunk_size+(chunk_size/2)) + 8 );\n\t    if ( !ascii85_p ) {\n\t\t_TIFFfree( buf_data );\n\t\tTIFFError( filename, "Cannot allocate ASCII85 encoding buffer." );\n\t\treturn ( FALSE );\n\t    }\n\t}\n#endif\n\tTIFFGetFieldDefaulted(tif, TIFFTAG_FILLORDER, &fillorder);\n\tfor (chunk_no = 0; chunk_no < num_chunks; chunk_no++) {\n\t\tif (ascii85)\n\t\t\tAscii85Init();\n\t\telse\n\t\t\tbreaklen = MAXLINE;\n\t\tif (use_rawdata) {\n\t\t\tif (tiled_image)\n\t\t\t\tbyte_count = TIFFReadRawTile(tif, chunk_no,\n\t\t\t\t\t\t  buf_data, chunk_size);\n\t\t\telse\n\t\t\t\tbyte_count = TIFFReadRawStrip(tif, chunk_no,\n\t\t\t\t\t\t  buf_data, chunk_size);\n\t\t\tif (fillorder == FILLORDER_LSB2MSB)\n\t\t\t    TIFFReverseBits(buf_data, byte_count);\n\t\t} else {\n\t\t\tif (tiled_image)\n\t\t\t\tbyte_count = TIFFReadEncodedTile(tif,\n\t\t\t\t\t\tchunk_no, buf_data,\n\t\t\t\t\t\tchunk_size);\n\t\t\telse\n\t\t\t\tbyte_count = TIFFReadEncodedStrip(tif,\n\t\t\t\t\t\tchunk_no, buf_data,\n\t\t\t\t\t\tchunk_size);\n\t\t}\n\t\tif (byte_count < 0) {\n\t\t\tTIFFError(filename, "Can\'t read %s %d.",\n\t\t\t\ttiled_image ? "tile" : "strip", chunk_no);\n\t\t\tif (ascii85)\n\t\t\t\tAscii85Put(\'\\0\', fd);\n\t\t}\n\t\tif (bitspersample == 16 && !TIFFIsBigEndian(tif)) {\n\t\t\tPS_FlipBytes(buf_data, byte_count);\n\t\t}\n\t\tif (alpha) {\n\t\t\tint adjust, i, j = 0;\n\t\t\tint ncomps = samplesperpixel - extrasamples;\n\t\t\tfor (i = 0; (i + ncomps) < byte_count; i+=samplesperpixel) {\n\t\t\t\tadjust = 255 - buf_data[i + ncomps];\n\t\t\t\tswitch (ncomps) {\n\t\t\t\t\tcase 1:\n\t\t\t\t\t\tbuf_data[j++] = buf_data[i] + adjust;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 2:\n\t\t\t\t\t\tbuf_data[j++] = buf_data[i] + adjust;\n\t\t\t\t\t\tbuf_data[j++] = buf_data[i+1] + adjust;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 3:\n\t\t\t\t\t\tbuf_data[j++] = buf_data[i] + adjust;\n\t\t\t\t\t\tbuf_data[j++] = buf_data[i+1] + adjust;\n\t\t\t\t\t\tbuf_data[j++] = buf_data[i+2] + adjust;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbyte_count -= j;\n\t\t}\n\t\tif (ascii85) {\n#if defined( EXP_ASCII85ENCODER )\n\t\t\tascii85_l = Ascii85EncodeBlock(ascii85_p, 1, buf_data, byte_count );\n\t\t\tif ( ascii85_l > 0 )\n\t\t\t\tfwrite( ascii85_p, ascii85_l, 1, fd );\n#else\n\t\t\tfor (cp = buf_data; byte_count > 0; byte_count--)\n\t\t\t\tAscii85Put(*cp++, fd);\n#endif\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfor (cp = buf_data; byte_count > 0; byte_count--) {\n\t\t\t\tputc(hex[((*cp)>>4)&0xf], fd);\n\t\t\t\tputc(hex[(*cp)&0xf], fd);\n\t\t\t\tcp++;\n\t\t\t\tif (--breaklen <= 0) {\n\t\t\t\t\tputc(\'\\n\', fd);\n\t\t\t\t\tbreaklen = MAXLINE;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif ( !ascii85 ) {\n\t\t\tif ( level2 || level3 )\n\t\t\t\tputc( \'>\', fd );\n\t\t\tputc(\'\\n\', fd);\n\t\t}\n#if !defined( EXP_ASCII85ENCODER )\n\t\telse\n\t\t\tAscii85Flush(fd);\n#endif\n\t}\n#if defined( EXP_ASCII85ENCODER )\n\tif ( ascii85_p )\n\t    _TIFFfree( ascii85_p );\n#endif\n\t_TIFFfree(buf_data);\n#ifdef ENABLE_BROKEN_BEGINENDDATA\n\tfputs("%%EndData\\n", fd);\n#endif\n\treturn(TRUE);\n}', 'static int\nPS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h)\n{\n\tint use_rawdata;\n\tuint32 tile_width, tile_height;\n\tuint16 predictor, minsamplevalue, maxsamplevalue;\n\tint repeat_count;\n\tchar im_h[64], im_x[64], im_y[64];\n\tchar * imageOp = "image";\n\tif ( useImagemask && (bitspersample == 1) )\n\t\timageOp = "imagemask";\n\t(void)strcpy(im_x, "0");\n\t(void)snprintf(im_y, sizeof(im_y), "%lu", (long) h);\n\t(void)snprintf(im_h, sizeof(im_h), "%lu", (long) h);\n\ttile_width = w;\n\ttile_height = h;\n\tif (TIFFIsTiled(tif)) {\n\t\trepeat_count = TIFFNumberOfTiles(tif);\n\t\tTIFFGetField(tif, TIFFTAG_TILEWIDTH, &tile_width);\n\t\tTIFFGetField(tif, TIFFTAG_TILELENGTH, &tile_height);\n\t\tif (tile_width > w || tile_height > h ||\n\t\t    (w % tile_width) != 0 || (h % tile_height != 0)) {\n\t\t\tfputs("0 0 1 1 rectclip\\n", fd);\n\t\t}\n\t\tif (tile_width < w) {\n\t\t\tfputs("/im_x 0 def\\n", fd);\n\t\t\t(void)strcpy(im_x, "im_x neg");\n\t\t}\n\t\tif (tile_height < h) {\n\t\t\tfputs("/im_y 0 def\\n", fd);\n\t\t\t(void)snprintf(im_y, sizeof(im_y), "%lu im_y sub", (unsigned long) h);\n\t\t}\n\t} else {\n\t\trepeat_count = tf_numberstrips;\n\t\ttile_height = tf_rowsperstrip;\n\t\tif (tile_height > h)\n\t\t\ttile_height = h;\n\t\tif (repeat_count > 1) {\n\t\t\tfputs("/im_y 0 def\\n", fd);\n\t\t\tfprintf(fd, "/im_h %lu def\\n",\n\t\t\t    (unsigned long) tile_height);\n\t\t\t(void)strcpy(im_h, "im_h");\n\t\t\t(void)snprintf(im_y, sizeof(im_y), "%lu im_y sub", (unsigned long) h);\n\t\t}\n\t}\n\tfputs("{ % exec\\n", fd);\n\tif (repeat_count > 1)\n\t\tfprintf(fd, "%d { %% repeat\\n", repeat_count);\n\tif (ascii85)\n\t\tfputs(" /im_stream currentfile /ASCII85Decode filter def\\n",\n\t\t    fd);\n\tfputs(" <<\\n", fd);\n\tfputs("  /ImageType 1\\n", fd);\n\tfprintf(fd, "  /Width %lu\\n", (unsigned long) tile_width);\n\tif (TIFFIsTiled(tif) || tf_numberstrips == 1)\n\t\tfprintf(fd, "  /Height %lu\\n", (unsigned long) tile_height);\n\telse\n\t\tfprintf(fd, "  /Height im_h\\n");\n\tif (planarconfiguration == PLANARCONFIG_SEPARATE && samplesperpixel > 1)\n\t\tfputs("  /MultipleDataSources true\\n", fd);\n\tfprintf(fd, "  /ImageMatrix [ %lu 0 0 %ld %s %s ]\\n",\n\t    (unsigned long) w, - (long)h, im_x, im_y);\n\tfprintf(fd, "  /BitsPerComponent %d\\n", bitspersample);\n\tfprintf(fd, "  /Interpolate %s\\n", interpolate ? "true" : "false");\n\tswitch (samplesperpixel - extrasamples) {\n\tcase 1:\n\t\tswitch (photometric) {\n\t\tcase PHOTOMETRIC_MINISBLACK:\n\t\t\tfputs("  /Decode [0 1]\\n", fd);\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_MINISWHITE:\n\t\t\tswitch (compression) {\n\t\t\tcase COMPRESSION_CCITTRLE:\n\t\t\tcase COMPRESSION_CCITTRLEW:\n\t\t\tcase COMPRESSION_CCITTFAX3:\n\t\t\tcase COMPRESSION_CCITTFAX4:\n\t\t\t\tfputs("  /Decode [0 1]\\n", fd);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tfputs("  /Decode [1 0]\\n", fd);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_PALETTE:\n\t\t\tTIFFGetFieldDefaulted(tif, TIFFTAG_MINSAMPLEVALUE,\n\t\t\t    &minsamplevalue);\n\t\t\tTIFFGetFieldDefaulted(tif, TIFFTAG_MAXSAMPLEVALUE,\n\t\t\t    &maxsamplevalue);\n\t\t\tfprintf(fd, "  /Decode [%u %u]\\n",\n\t\t\t\t    minsamplevalue, maxsamplevalue);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tfputs("  /Decode [0 1]\\n", fd);\n\t\t\tbreak;\n\t\t}\n\t\tbreak;\n\tcase 3:\n\t\tswitch (photometric) {\n\t\tcase PHOTOMETRIC_RGB:\n\t\t\tfputs("  /Decode [0 1 0 1 0 1]\\n", fd);\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_MINISWHITE:\n\t\tcase PHOTOMETRIC_MINISBLACK:\n\t\tdefault:\n\t\t\tfputs("  /Decode [0 1 0 1 0 1]\\n", fd);\n\t\t\tbreak;\n\t\t}\n\t\tbreak;\n\tcase 4:\n\t\tfputs("  /Decode [0 1 0 1 0 1 0 1]\\n", fd);\n\t\tbreak;\n\t}\n\tfputs("  /DataSource", fd);\n\tif (planarconfiguration == PLANARCONFIG_SEPARATE &&\n\t    samplesperpixel > 1)\n\t\tfputs(" [", fd);\n\tif (ascii85)\n\t\tfputs(" im_stream", fd);\n\telse\n\t\tfputs(" currentfile /ASCIIHexDecode filter", fd);\n\tuse_rawdata = TRUE;\n\tswitch (compression) {\n\tcase COMPRESSION_NONE:\n\t\tbreak;\n\tcase COMPRESSION_CCITTRLE:\n\tcase COMPRESSION_CCITTRLEW:\n\tcase COMPRESSION_CCITTFAX3:\n\tcase COMPRESSION_CCITTFAX4:\n\t\tfputs("\\n\\t<<\\n", fd);\n\t\tif (compression == COMPRESSION_CCITTFAX3) {\n\t\t\tuint32 g3_options;\n\t\t\tfputs("\\t /EndOfLine true\\n", fd);\n\t\t\tfputs("\\t /EndOfBlock false\\n", fd);\n\t\t\tif (!TIFFGetField(tif, TIFFTAG_GROUP3OPTIONS,\n\t\t\t\t\t    &g3_options))\n\t\t\t\tg3_options = 0;\n\t\t\tif (g3_options & GROUP3OPT_2DENCODING)\n\t\t\t\tfprintf(fd, "\\t /K %s\\n", im_h);\n\t\t\tif (g3_options & GROUP3OPT_UNCOMPRESSED)\n\t\t\t\tfputs("\\t /Uncompressed true\\n", fd);\n\t\t\tif (g3_options & GROUP3OPT_FILLBITS)\n\t\t\t\tfputs("\\t /EncodedByteAlign true\\n", fd);\n\t\t}\n\t\tif (compression == COMPRESSION_CCITTFAX4) {\n\t\t\tuint32 g4_options;\n\t\t\tfputs("\\t /K -1\\n", fd);\n\t\t\tTIFFGetFieldDefaulted(tif, TIFFTAG_GROUP4OPTIONS,\n\t\t\t\t\t       &g4_options);\n\t\t\tif (g4_options & GROUP4OPT_UNCOMPRESSED)\n\t\t\t\tfputs("\\t /Uncompressed true\\n", fd);\n\t\t}\n\t\tif (!(tile_width == w && w == 1728U))\n\t\t\tfprintf(fd, "\\t /Columns %lu\\n",\n\t\t\t    (unsigned long) tile_width);\n\t\tfprintf(fd, "\\t /Rows %s\\n", im_h);\n\t\tif (compression == COMPRESSION_CCITTRLE ||\n\t\t    compression == COMPRESSION_CCITTRLEW) {\n\t\t\tfputs("\\t /EncodedByteAlign true\\n", fd);\n\t\t\tfputs("\\t /EndOfBlock false\\n", fd);\n\t\t}\n\t\tif (photometric == PHOTOMETRIC_MINISBLACK)\n\t\t\tfputs("\\t /BlackIs1 true\\n", fd);\n\t\tfprintf(fd, "\\t>> /CCITTFaxDecode filter");\n\t\tbreak;\n\tcase COMPRESSION_LZW:\n\t\tTIFFGetFieldDefaulted(tif, TIFFTAG_PREDICTOR, &predictor);\n\t\tif (predictor == 2) {\n\t\t\tfputs("\\n\\t<<\\n", fd);\n\t\t\tfprintf(fd, "\\t /Predictor %u\\n", predictor);\n\t\t\tfprintf(fd, "\\t /Columns %lu\\n",\n\t\t\t    (unsigned long) tile_width);\n\t\t\tfprintf(fd, "\\t /Colors %u\\n", samplesperpixel);\n\t\t\tfprintf(fd, "\\t /BitsPerComponent %u\\n",\n\t\t\t    bitspersample);\n\t\t\tfputs("\\t>>", fd);\n\t\t}\n\t\tfputs(" /LZWDecode filter", fd);\n\t\tbreak;\n\tcase COMPRESSION_DEFLATE:\n\tcase COMPRESSION_ADOBE_DEFLATE:\n\t\tif ( level3 ) {\n\t\t\t TIFFGetFieldDefaulted(tif, TIFFTAG_PREDICTOR, &predictor);\n\t\t\t if (predictor > 1) {\n\t\t\t\tfprintf(fd, "\\t %% PostScript Level 3 only.");\n\t\t\t\tfputs("\\n\\t<<\\n", fd);\n\t\t\t\tfprintf(fd, "\\t /Predictor %u\\n", predictor);\n\t\t\t\tfprintf(fd, "\\t /Columns %lu\\n",\n\t\t\t\t\t(unsigned long) tile_width);\n\t\t\t\tfprintf(fd, "\\t /Colors %u\\n", samplesperpixel);\n\t\t\t\t\tfprintf(fd, "\\t /BitsPerComponent %u\\n",\n\t\t\t\t\tbitspersample);\n\t\t\t\tfputs("\\t>>", fd);\n\t\t\t }\n\t\t\t fputs(" /FlateDecode filter", fd);\n\t\t} else {\n\t\t\tuse_rawdata = FALSE ;\n\t\t}\n\t\tbreak;\n\tcase COMPRESSION_PACKBITS:\n\t\tfputs(" /RunLengthDecode filter", fd);\n\t\tuse_rawdata = TRUE;\n\t    break;\n\tcase COMPRESSION_OJPEG:\n\tcase COMPRESSION_JPEG:\n#ifdef notdef\n\t\tfputs(" /DCTDecode filter", fd);\n\t\tuse_rawdata = TRUE;\n#else\n\t\tuse_rawdata = FALSE;\n#endif\n\t\tbreak;\n\tcase COMPRESSION_NEXT:\n\tcase COMPRESSION_THUNDERSCAN:\n\tcase COMPRESSION_PIXARFILM:\n\tcase COMPRESSION_JBIG:\n\t\tuse_rawdata = FALSE;\n\t\tbreak;\n\tcase COMPRESSION_SGILOG:\n\tcase COMPRESSION_SGILOG24:\n\t\tuse_rawdata = FALSE;\n\t\tbreak;\n\tdefault:\n\t\tuse_rawdata = FALSE;\n\t\tbreak;\n\t}\n\tif (planarconfiguration == PLANARCONFIG_SEPARATE &&\n\t    samplesperpixel > 1) {\n\t\tuint16 i;\n\t\tfor (i = 1; i < samplesperpixel; i++)\n\t\t\tfputs(" dup", fd);\n\t\tfputs(" ]", fd);\n\t}\n\tfprintf( fd, "\\n >> %s\\n", imageOp );\n\tif (ascii85)\n\t\tfputs(" im_stream status { im_stream flushfile } if\\n", fd);\n\tif (repeat_count > 1) {\n\t\tif (tile_width < w) {\n\t\t\tfprintf(fd, " /im_x im_x %lu add def\\n",\n\t\t\t    (unsigned long) tile_width);\n\t\t\tif (tile_height < h) {\n\t\t\t\tfprintf(fd, " im_x %lu ge {\\n",\n\t\t\t\t    (unsigned long) w);\n\t\t\t\tfputs("  /im_x 0 def\\n", fd);\n\t\t\t\tfprintf(fd, " /im_y im_y %lu add def\\n",\n\t\t\t\t    (unsigned long) tile_height);\n\t\t\t\tfputs(" } if\\n", fd);\n\t\t\t}\n\t\t}\n\t\tif (tile_height < h) {\n\t\t\tif (tile_width >= w) {\n\t\t\t\tfprintf(fd, " /im_y im_y %lu add def\\n",\n\t\t\t\t    (unsigned long) tile_height);\n\t\t\t\tif (!TIFFIsTiled(tif)) {\n\t\t\t\t\tfprintf(fd, " /im_h %lu im_y sub",\n\t\t\t\t\t    (unsigned long) h);\n\t\t\t\t\tfprintf(fd, " dup %lu gt { pop",\n\t\t\t\t\t    (unsigned long) tile_height);\n\t\t\t\t\tfprintf(fd, " %lu } if def\\n",\n\t\t\t\t\t    (unsigned long) tile_height);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfputs("} repeat\\n", fd);\n\t}\n\tfputs("}\\n", fd);\n\treturn(use_rawdata);\n}', 'uint32\nTIFFNumberOfTiles(TIFF* tif)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint32 dx = td->td_tilewidth;\n\tuint32 dy = td->td_tilelength;\n\tuint32 dz = td->td_tiledepth;\n\tuint32 ntiles;\n\tif (dx == (uint32) -1)\n\t\tdx = td->td_imagewidth;\n\tif (dy == (uint32) -1)\n\t\tdy = td->td_imagelength;\n\tif (dz == (uint32) -1)\n\t\tdz = td->td_imagedepth;\n\tntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 :\n\t    _TIFFMultiply32(tif, _TIFFMultiply32(tif, TIFFhowmany_32(td->td_imagewidth, dx),\n\t    TIFFhowmany_32(td->td_imagelength, dy),\n\t    "TIFFNumberOfTiles"),\n\t    TIFFhowmany_32(td->td_imagedepth, dz), "TIFFNumberOfTiles");\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\tntiles = _TIFFMultiply32(tif, ntiles, td->td_samplesperpixel,\n\t\t    "TIFFNumberOfTiles");\n\treturn (ntiles);\n}']