libtiff/tif_getimage.c:447: error: Buffer Overrun L3
  Offset: [0, 255] Size: [0, +oo] by call to `PickContigCase`.

libtiff/tif_getimage.c:246:2: Assignment
244. 	img->row_offset = 0;
245. 	img->col_offset = 0;
246. 	img->redcmap = NULL;
      ^
247. 	img->greencmap = NULL;
248. 	img->bluecmap = NULL;

libtiff/tif_getimage.c:447:8: Call
445. 	    !(planarconfig == PLANARCONFIG_SEPARATE && img->samplesperpixel > 1);
446. 	if (img->isContig) {
447. 		if (!PickContigCase(img)) {
            ^
448. 			sprintf(emsg, "Sorry, can not handle image");
449. 			return 0;

libtiff/tif_getimage.c:2379:1: Parameter `*img->redcmap`
  2377.  * Select the appropriate conversion routine for packed data.
  2378.  */
  2379. static int
        ^
  2380. PickContigCase(TIFFRGBAImage* img)
  2381. {

libtiff/tif_getimage.c:2419:8: Call
  2417. 			break;
  2418. 		case PHOTOMETRIC_SEPARATED:
  2419. 			if (buildMap(img)) {
               ^
  2420. 				if (img->bitspersample == 8) {
  2421. 					if (!img->Map)

libtiff/tif_getimage.c:2341:1: Parameter `*img->redcmap`
    2339.  * by the associated put routine.
    2340.  */
    2341. static int
          ^
    2342. buildMap(TIFFRGBAImage* img)
    2343. {

libtiff/tif_getimage.c:2369:34: Call
    2367. 	 * unpacking tables for samples < 8 bits.
    2368. 	 */
    2369. 	if (img->bitspersample <= 8 && !makecmap(img))
                                           ^
    2370. 	    return (0);
    2371. 	break;

libtiff/tif_getimage.c:2303:10: <Offset trace>
2301. 	}
2302.     p = (uint32*)(img->PALmap + 256);
2303.     for (i = 0; i < 256; i++) {
               ^
2304. 	TIFFRGBValue c;
2305. 	img->PALmap[i] = p;

libtiff/tif_getimage.c:2303:10: Assignment
      2301. 	}
      2302.     p = (uint32*)(img->PALmap + 256);
      2303.     for (i = 0; i < 256; i++) {
                     ^
      2304. 	TIFFRGBValue c;
      2305. 	img->PALmap[i] = p;

libtiff/tif_getimage.c:2329:6: Assignment
      2327. 	    break;
      2328. 	case 8:
      2329. 	    CMAP(i);
                 ^
      2330. 	    break;
      2331. 	}

libtiff/tif_getimage.c:2285:1: <Length trace>
2283.  * number.
2284.  */
2285. static int
      ^
2286. makecmap(TIFFRGBAImage* img)
2287. {

libtiff/tif_getimage.c:2285:1: Parameter `*img->redcmap`
      2283.  * number.
      2284.  */
      2285. static int
            ^
      2286. makecmap(TIFFRGBAImage* img)
      2287. {

libtiff/tif_getimage.c:2290:5: Assignment
      2288.     int bitspersample = img->bitspersample;
      2289.     int nsamples = 8 / bitspersample;
      2290.     uint16* r = img->redcmap;
                ^
      2291.     uint16* g = img->greencmap;
      2292.     uint16* b = img->bluecmap;

libtiff/tif_getimage.c:2329:6: Array access: Offset: [0, 255] Size: [0, +oo] by call to `PickContigCase` 
      2327. 	    break;
      2328. 	case 8:
      2329. 	    CMAP(i);
                 ^
      2330. 	    break;
      2331. 	}

static int
makecmap(TIFFRGBAImage* img)
{
    int bitspersample = img->bitspersample;
    int nsamples = 8 / bitspersample;
    uint16* r = img->redcmap;
    uint16* g = img->greencmap;
    uint16* b = img->bluecmap;
    uint32 *p;
    int i;
    img->PALmap = (uint32**) _TIFFmalloc(
	256*sizeof (uint32 *)+(256*nsamples*sizeof(uint32)));
    if (img->PALmap == NULL) {
		TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif), "No space for Palette mapping table");
		return (0);
	}
    p = (uint32*)(img->PALmap + 256);
    for (i = 0; i < 256; i++) {
	TIFFRGBValue c;
	img->PALmap[i] = p;
#define	CMAP(x)	c = (TIFFRGBValue) x; *p++ = PACK(r[c]&0xff, g[c]&0xff, b[c]&0xff);
	switch (bitspersample) {
	case 1:
	    CMAP(i>>7);
	    CMAP((i>>6)&1);
	    CMAP((i>>5)&1);
	    CMAP((i>>4)&1);
	    CMAP((i>>3)&1);
	    CMAP((i>>2)&1);
	    CMAP((i>>1)&1);
	    CMAP(i&1);
	    break;
	case 2:
	    CMAP(i>>6);
	    CMAP((i>>4)&3);
	    CMAP((i>>2)&3);
	    CMAP(i&3);
	    break;
	case 4:
	    CMAP(i>>4);
	    CMAP(i&0xf);
	    break;
	case 8:
	    CMAP(i);
	    break;
	}
#undef CMAP
    }
    return (1);
}
['int\nTIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024])\n{\n\tuint16* sampleinfo;\n\tuint16 extrasamples;\n\tuint16 planarconfig;\n\tuint16 compress;\n\tint colorchannels;\n\tuint16 *red_orig, *green_orig, *blue_orig;\n\tint n_color;\n\timg->row_offset = 0;\n\timg->col_offset = 0;\n\timg->redcmap = NULL;\n\timg->greencmap = NULL;\n\timg->bluecmap = NULL;\n\timg->req_orientation = ORIENTATION_BOTLEFT;\n\timg->tif = tif;\n\timg->stoponerr = stop;\n\tTIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &img->bitspersample);\n\tswitch (img->bitspersample) {\n\t\tcase 1:\n\t\tcase 2:\n\t\tcase 4:\n\t\tcase 8:\n\t\tcase 16:\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tsprintf(emsg, "Sorry, can not handle images with %d-bit samples",\n\t\t\t    img->bitspersample);\n\t\t\treturn (0);\n\t}\n\timg->alpha = 0;\n\tTIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &img->samplesperpixel);\n\tTIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES,\n\t    &extrasamples, &sampleinfo);\n\tif (extrasamples >= 1)\n\t{\n\t\tswitch (sampleinfo[0]) {\n\t\t\tcase EXTRASAMPLE_UNSPECIFIED:\n\t\t\t\tif (img->samplesperpixel > 3)\n\t\t\t\t\timg->alpha = EXTRASAMPLE_ASSOCALPHA;\n\t\t\t\tbreak;\n\t\t\tcase EXTRASAMPLE_ASSOCALPHA:\n\t\t\tcase EXTRASAMPLE_UNASSALPHA:\n\t\t\t\timg->alpha = sampleinfo[0];\n\t\t\t\tbreak;\n\t\t}\n\t}\n#ifdef DEFAULT_EXTRASAMPLE_AS_ALPHA\n\tif( !TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric))\n\t\timg->photometric = PHOTOMETRIC_MINISWHITE;\n\tif( extrasamples == 0\n\t    && img->samplesperpixel == 4\n\t    && img->photometric == PHOTOMETRIC_RGB )\n\t{\n\t\timg->alpha = EXTRASAMPLE_ASSOCALPHA;\n\t\textrasamples = 1;\n\t}\n#endif\n\tcolorchannels = img->samplesperpixel - extrasamples;\n\tTIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &compress);\n\tTIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planarconfig);\n\tif (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric)) {\n\t\tswitch (colorchannels) {\n\t\t\tcase 1:\n\t\t\t\tif (isCCITTCompression(tif))\n\t\t\t\t\timg->photometric = PHOTOMETRIC_MINISWHITE;\n\t\t\t\telse\n\t\t\t\t\timg->photometric = PHOTOMETRIC_MINISBLACK;\n\t\t\t\tbreak;\n\t\t\tcase 3:\n\t\t\t\timg->photometric = PHOTOMETRIC_RGB;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tsprintf(emsg, "Missing needed %s tag", photoTag);\n\t\t\t\treturn (0);\n\t\t}\n\t}\n\tswitch (img->photometric) {\n\t\tcase PHOTOMETRIC_PALETTE:\n\t\t\tif (!TIFFGetField(tif, TIFFTAG_COLORMAP,\n\t\t\t    &red_orig, &green_orig, &blue_orig)) {\n\t\t\t\tsprintf(emsg, "Missing required \\"Colormap\\" tag");\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tn_color = (1L << img->bitspersample);\n\t\t\timg->redcmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color);\n\t\t\timg->greencmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color);\n\t\t\timg->bluecmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color);\n\t\t\tif( !img->redcmap || !img->greencmap || !img->bluecmap ) {\n\t\t\t\tsprintf(emsg, "Out of memory for colormap copy");\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t\t_TIFFmemcpy( img->redcmap, red_orig, n_color * 2 );\n\t\t\t_TIFFmemcpy( img->greencmap, green_orig, n_color * 2 );\n\t\t\t_TIFFmemcpy( img->bluecmap, blue_orig, n_color * 2 );\n\t\tcase PHOTOMETRIC_MINISWHITE:\n\t\tcase PHOTOMETRIC_MINISBLACK:\n\t\t\tif (planarconfig == PLANARCONFIG_CONTIG\n\t\t\t    && img->samplesperpixel != 1\n\t\t\t    && img->bitspersample < 8 ) {\n\t\t\t\tsprintf(emsg,\n\t\t\t\t    "Sorry, can not handle contiguous data with %s=%d, "\n\t\t\t\t    "and %s=%d and Bits/Sample=%d",\n\t\t\t\t    photoTag, img->photometric,\n\t\t\t\t    "Samples/pixel", img->samplesperpixel,\n\t\t\t\t    img->bitspersample);\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_YCBCR:\n\t\t\tif (planarconfig == PLANARCONFIG_CONTIG)\n\t\t\t\tswitch (compress) {\n\t\t\t\t\tcase COMPRESSION_JPEG:\n\t\t\t\t\t\tTIFFSetField(tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);\n\t\t\t\t\t\timg->photometric = PHOTOMETRIC_RGB;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\t ;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_RGB:\n\t\t\tif (colorchannels < 3) {\n\t\t\t\tsprintf(emsg, "Sorry, can not handle RGB image with %s=%d",\n\t\t\t\t    "Color channels", colorchannels);\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_SEPARATED:\n\t\t\t{\n\t\t\t\tuint16 inkset;\n\t\t\t\tTIFFGetFieldDefaulted(tif, TIFFTAG_INKSET, &inkset);\n\t\t\t\tif (inkset != INKSET_CMYK) {\n\t\t\t\t\tsprintf(emsg, "Sorry, can not handle separated image with %s=%d",\n\t\t\t\t\t    "InkSet", inkset);\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (img->samplesperpixel < 4) {\n\t\t\t\t\tsprintf(emsg, "Sorry, can not handle separated image with %s=%d",\n\t\t\t\t\t    "Samples/pixel", img->samplesperpixel);\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_LOGL:\n\t\t\tif (compress != COMPRESSION_SGILOG) {\n\t\t\t\tsprintf(emsg, "Sorry, LogL data must have %s=%d",\n\t\t\t\t    "Compression", COMPRESSION_SGILOG);\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tTIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_8BIT);\n\t\t\timg->photometric = PHOTOMETRIC_MINISBLACK;\n\t\t\timg->bitspersample = 8;\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_LOGLUV:\n\t\t\tif (compress != COMPRESSION_SGILOG && compress != COMPRESSION_SGILOG24) {\n\t\t\t\tsprintf(emsg, "Sorry, LogLuv data must have %s=%d or %d",\n\t\t\t\t    "Compression", COMPRESSION_SGILOG, COMPRESSION_SGILOG24);\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tif (planarconfig != PLANARCONFIG_CONTIG) {\n\t\t\t\tsprintf(emsg, "Sorry, can not handle LogLuv images with %s=%d",\n\t\t\t\t    "Planarconfiguration", planarconfig);\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tTIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_8BIT);\n\t\t\timg->photometric = PHOTOMETRIC_RGB;\n\t\t\timg->bitspersample = 8;\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_CIELAB:\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tsprintf(emsg, "Sorry, can not handle image with %s=%d",\n\t\t\t    photoTag, img->photometric);\n\t\t\treturn (0);\n\t}\n\timg->Map = NULL;\n\timg->BWmap = NULL;\n\timg->PALmap = NULL;\n\timg->ycbcr = NULL;\n\timg->cielab = NULL;\n\timg->UaToAa = NULL;\n\timg->Bitdepth16To8 = NULL;\n\tTIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &img->width);\n\tTIFFGetField(tif, TIFFTAG_IMAGELENGTH, &img->height);\n\tTIFFGetFieldDefaulted(tif, TIFFTAG_ORIENTATION, &img->orientation);\n\timg->isContig =\n\t    !(planarconfig == PLANARCONFIG_SEPARATE && img->samplesperpixel > 1);\n\tif (img->isContig) {\n\t\tif (!PickContigCase(img)) {\n\t\t\tsprintf(emsg, "Sorry, can not handle image");\n\t\t\treturn 0;\n\t\t}\n\t} else {\n\t\tif (!PickSeparateCase(img)) {\n\t\t\tsprintf(emsg, "Sorry, can not handle image");\n\t\t\treturn 0;\n\t\t}\n\t}\n\treturn 1;\n}', 'static int\nPickContigCase(TIFFRGBAImage* img)\n{\n\timg->get = TIFFIsTiled(img->tif) ? gtTileContig : gtStripContig;\n\timg->put.contig = NULL;\n\tswitch (img->photometric) {\n\t\tcase PHOTOMETRIC_RGB:\n\t\t\tswitch (img->bitspersample) {\n\t\t\t\tcase 8:\n\t\t\t\t\tif (img->alpha == EXTRASAMPLE_ASSOCALPHA)\n\t\t\t\t\t\timg->put.contig = putRGBAAcontig8bittile;\n\t\t\t\t\telse if (img->alpha == EXTRASAMPLE_UNASSALPHA)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (BuildMapUaToAa(img))\n\t\t\t\t\t\t\timg->put.contig = putRGBUAcontig8bittile;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\timg->put.contig = putRGBcontig8bittile;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 16:\n\t\t\t\t\tif (img->alpha == EXTRASAMPLE_ASSOCALPHA)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (BuildMapBitdepth16To8(img))\n\t\t\t\t\t\t\timg->put.contig = putRGBAAcontig16bittile;\n\t\t\t\t\t}\n\t\t\t\t\telse if (img->alpha == EXTRASAMPLE_UNASSALPHA)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (BuildMapBitdepth16To8(img) &&\n\t\t\t\t\t\t    BuildMapUaToAa(img))\n\t\t\t\t\t\t\timg->put.contig = putRGBUAcontig16bittile;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tif (BuildMapBitdepth16To8(img))\n\t\t\t\t\t\t\timg->put.contig = putRGBcontig16bittile;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_SEPARATED:\n\t\t\tif (buildMap(img)) {\n\t\t\t\tif (img->bitspersample == 8) {\n\t\t\t\t\tif (!img->Map)\n\t\t\t\t\t\timg->put.contig = putRGBcontig8bitCMYKtile;\n\t\t\t\t\telse\n\t\t\t\t\t\timg->put.contig = putRGBcontig8bitCMYKMaptile;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_PALETTE:\n\t\t\tif (buildMap(img)) {\n\t\t\t\tswitch (img->bitspersample) {\n\t\t\t\t\tcase 8:\n\t\t\t\t\t\timg->put.contig = put8bitcmaptile;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 4:\n\t\t\t\t\t\timg->put.contig = put4bitcmaptile;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 2:\n\t\t\t\t\t\timg->put.contig = put2bitcmaptile;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 1:\n\t\t\t\t\t\timg->put.contig = put1bitcmaptile;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_MINISWHITE:\n\t\tcase PHOTOMETRIC_MINISBLACK:\n\t\t\tif (buildMap(img)) {\n\t\t\t\tswitch (img->bitspersample) {\n\t\t\t\t\tcase 16:\n\t\t\t\t\t\timg->put.contig = put16bitbwtile;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 8:\n\t\t\t\t\t\timg->put.contig = putgreytile;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 4:\n\t\t\t\t\t\timg->put.contig = put4bitbwtile;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 2:\n\t\t\t\t\t\timg->put.contig = put2bitbwtile;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 1:\n\t\t\t\t\t\timg->put.contig = put1bitbwtile;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_YCBCR:\n\t\t\tif (img->bitspersample == 8)\n\t\t\t{\n\t\t\t\tif (initYCbCrConversion(img)!=0)\n\t\t\t\t{\n\t\t\t\t\tuint16 SubsamplingHor;\n\t\t\t\t\tuint16 SubsamplingVer;\n\t\t\t\t\tTIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRSUBSAMPLING, &SubsamplingHor, &SubsamplingVer);\n\t\t\t\t\tswitch ((SubsamplingHor<<4)|SubsamplingVer) {\n\t\t\t\t\t\tcase 0x44:\n\t\t\t\t\t\t\timg->put.contig = putcontig8bitYCbCr44tile;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 0x42:\n\t\t\t\t\t\t\timg->put.contig = putcontig8bitYCbCr42tile;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 0x41:\n\t\t\t\t\t\t\timg->put.contig = putcontig8bitYCbCr41tile;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 0x22:\n\t\t\t\t\t\t\timg->put.contig = putcontig8bitYCbCr22tile;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 0x21:\n\t\t\t\t\t\t\timg->put.contig = putcontig8bitYCbCr21tile;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 0x12:\n\t\t\t\t\t\t\timg->put.contig = putcontig8bitYCbCr12tile;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 0x11:\n\t\t\t\t\t\t\timg->put.contig = putcontig8bitYCbCr11tile;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_CIELAB:\n\t\t\tif (buildMap(img)) {\n\t\t\t\tif (img->bitspersample == 8)\n\t\t\t\t\timg->put.contig = initCIELabConversion(img);\n\t\t\t\tbreak;\n\t\t\t}\n\t}\n\treturn ((img->get!=NULL) && (img->put.contig!=NULL));\n}', 'static int\nbuildMap(TIFFRGBAImage* img)\n{\n    switch (img->photometric) {\n    case PHOTOMETRIC_RGB:\n    case PHOTOMETRIC_YCBCR:\n    case PHOTOMETRIC_SEPARATED:\n\tif (img->bitspersample == 8)\n\t    break;\n    case PHOTOMETRIC_MINISBLACK:\n    case PHOTOMETRIC_MINISWHITE:\n\tif (!setupMap(img))\n\t    return (0);\n\tbreak;\n    case PHOTOMETRIC_PALETTE:\n\tif (checkcmap(img) == 16)\n\t    cvtcmap(img);\n\telse\n\t    TIFFWarningExt(img->tif->tif_clientdata, TIFFFileName(img->tif), "Assuming 8-bit colormap");\n\tif (img->bitspersample <= 8 && !makecmap(img))\n\t    return (0);\n\tbreak;\n    }\n    return (1);\n}', 'static int\nmakecmap(TIFFRGBAImage* img)\n{\n    int bitspersample = img->bitspersample;\n    int nsamples = 8 / bitspersample;\n    uint16* r = img->redcmap;\n    uint16* g = img->greencmap;\n    uint16* b = img->bluecmap;\n    uint32 *p;\n    int i;\n    img->PALmap = (uint32**) _TIFFmalloc(\n\t256*sizeof (uint32 *)+(256*nsamples*sizeof(uint32)));\n    if (img->PALmap == NULL) {\n\t\tTIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif), "No space for Palette mapping table");\n\t\treturn (0);\n\t}\n    p = (uint32*)(img->PALmap + 256);\n    for (i = 0; i < 256; i++) {\n\tTIFFRGBValue c;\n\timg->PALmap[i] = p;\n#define\tCMAP(x)\tc = (TIFFRGBValue) x; *p++ = PACK(r[c]&0xff, g[c]&0xff, b[c]&0xff);\n\tswitch (bitspersample) {\n\tcase 1:\n\t    CMAP(i>>7);\n\t    CMAP((i>>6)&1);\n\t    CMAP((i>>5)&1);\n\t    CMAP((i>>4)&1);\n\t    CMAP((i>>3)&1);\n\t    CMAP((i>>2)&1);\n\t    CMAP((i>>1)&1);\n\t    CMAP(i&1);\n\t    break;\n\tcase 2:\n\t    CMAP(i>>6);\n\t    CMAP((i>>4)&3);\n\t    CMAP((i>>2)&3);\n\t    CMAP(i&3);\n\t    break;\n\tcase 4:\n\t    CMAP(i>>4);\n\t    CMAP(i&0xf);\n\t    break;\n\tcase 8:\n\t    CMAP(i);\n\t    break;\n\t}\n#undef CMAP\n    }\n    return (1);\n}']