static void
PS_FlipBytes(unsigned char* buf, tsize_t count)
{
	int i;
	unsigned char temp;
	if (count <= 0 || bitspersample <= 8) {
		return;
	}
	count--;
	for (i = 0; i < count; i += 2) {
		temp = buf[i];
		buf[i] = buf[i + 1];
		buf[i + 1] = temp;
	}
}
['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}', 'void\nPSDataColorContig(FILE* fd, TIFF* tif, uint32 w, uint32 h, int nc)\n{\n\tuint32 row;\n\tint breaklen = MAXLINE, es = samplesperpixel - nc;\n\ttsize_t cc;\n\tunsigned char *tf_buf;\n\tunsigned char *cp, c;\n\t(void) w;\n\ttf_buf = (unsigned char *) _TIFFmalloc(tf_bytesperrow);\n\tif (tf_buf == NULL) {\n\t\tTIFFError(filename, "No space for scanline buffer");\n\t\treturn;\n\t}\n\tfor (row = 0; row < h; row++) {\n\t\tif (TIFFReadScanline(tif, tf_buf, row, 0) < 0)\n\t\t\tbreak;\n\t\tcp = tf_buf;\n\t\tif (bitspersample == 16 && !HOST_BIGENDIAN) {\n\t\t\tPS_FlipBytes(cp, tf_bytesperrow);\n\t\t}\n\t\tif (alpha) {\n\t\t\tint adjust;\n\t\t\tcc = 0;\n\t\t\tfor (; cc < tf_bytesperrow; cc += samplesperpixel) {\n\t\t\t\tDOBREAK(breaklen, nc, fd);\n\t\t\t\tadjust = 255 - cp[nc];\n\t\t\t\tswitch (nc) {\n\t\t\t\tcase 4: c = *cp++ + adjust; PUTHEX(c,fd);\n\t\t\t\tcase 3: c = *cp++ + adjust; PUTHEX(c,fd);\n\t\t\t\tcase 2: c = *cp++ + adjust; PUTHEX(c,fd);\n\t\t\t\tcase 1: c = *cp++ + adjust; PUTHEX(c,fd);\n\t\t\t\t}\n\t\t\t\tcp += es;\n\t\t\t}\n\t\t} else {\n\t\t\tcc = 0;\n\t\t\tfor (; cc < tf_bytesperrow; cc += samplesperpixel) {\n\t\t\t\tDOBREAK(breaklen, nc, fd);\n\t\t\t\tswitch (nc) {\n\t\t\t\tcase 4: c = *cp++; PUTHEX(c,fd);\n\t\t\t\tcase 3: c = *cp++; PUTHEX(c,fd);\n\t\t\t\tcase 2: c = *cp++; PUTHEX(c,fd);\n\t\t\t\tcase 1: c = *cp++; PUTHEX(c,fd);\n\t\t\t\t}\n\t\t\t\tcp += es;\n\t\t\t}\n\t\t}\n\t}\n\t_TIFFfree((char *) tf_buf);\n}', 'static void\nPS_FlipBytes(unsigned char* buf, tsize_t count)\n{\n\tint i;\n\tunsigned char temp;\n\tif (count <= 0 || bitspersample <= 8) {\n\t\treturn;\n\t}\n\tcount--;\n\tfor (i = 0; i < count; i += 2) {\n\t\ttemp = buf[i];\n\t\tbuf[i] = buf[i + 1];\n\t\tbuf[i + 1] = temp;\n\t}\n}']