rem: for (uint32 i = 0; i < details.width; i++) { memset(pbits, invert + ptiff[i], 3); pbits += 4;
add: if (details.interpretation == PHOTO_WHITEZERO) { for (uint32 i = 0; i < details.width; i++) { memset(pbits, 255 - ptiff[i], 3); pbits += 4; } } else { for (uint32 i = 0; i < details.width; i++) { memset(pbits, ptiff[i], 3); pbits += 4; }
context: tiff_to_bits(uint8 *ptiff, uint32 tifflen, uint8 *pbits, TiffDetails &details){	uint8 *ptiffend = ptiff + tifflen;		switch (details.imageType) {		case TIFF_BILEVEL:			if (details.bitsPerPixel == 1) {				// black and white				uint8 black[3] = { 0x00, 0x00, 0x00 },					white[3] = { 0xFF, 0xFF, 0xFF };				uint8 *colors[2];				if (details.interpretation == PHOTO_WHITEZERO) {					colors[0] = white;					colors[1] = black;				} else {					colors[0] = black;					colors[1] = white;				}							for (uint32 i = 0; i < details.width; i++) {					uint8 eightbits = (ptiff + (i / 8))[0];					uint8 abit;					abit = (eightbits >> (7 - (i % 8))) & 1;									memcpy(pbits + (i * 4), colors[abit], 3);				}			} else {				// grayscale				uint8 invert = 0;				if (details.interpretation == PHOTO_WHITEZERO)					invert = 0xff;				if (details.bitsPerPixel == 8) {					for (uint32 i = 0; i < details.width; i++) {						memset(pbits, invert + ptiff[i], 3);						pbits += 4;					}				} else if (details.bitsPerPixel == 4) {					const uint8 mask = 0x0f;									for (uint32 i = 0; i < details.width; i++) {						uint8 values = (ptiff + (i / 2))[0];						uint8 value = (values >> (4 * (1 - (i % 2)))) & mask;						memset(pbits, invert + (value * 16), 3);						pbits += 4;					}				}			}						break;					case TIFF_PALETTE:		{			// NOTE: All of the entries in the color map were			// divided by 256 before they were copied to pcolorMap.			//			// The first 3rd of the color map is made of the Red values,			// the second 3rd of the color map is made of the Green values,			// and the last 3rd of the color map is made of the Blue values.			if (details.bitsPerPixel == 8) {				for (uint32 i = 0; i < details.width; i++) {					pbits[2] = details.pcolorMap[ptiff[i]];					pbits[1] = details.pcolorMap[256 + ptiff[i]];					pbits[0] = details.pcolorMap[512 + ptiff[i]];					pbits += 4;				}			} else if (details.bitsPerPixel == 4) {				const uint8 mask = 0x0f;				for (uint32 i = 0; i < details.width; i++) {					uint8 indices = (ptiff + (i / 2))[0];					uint8 index = (indices >> (4 * (1 - (i % 2)))) & mask;										pbits[2] = details.pcolorMap[index];					pbits[1] = details.pcolorMap[16 + index];					pbits[0] = details.pcolorMap[32 + index];										pbits += 4;				}			}			break;		}					case TIFF_RGB:			while (ptiff < ptiffend) {				pbits[2] = ptiff[0];				pbits[1] = ptiff[1];				pbits[0] = ptiff[2];				ptiff += 3;				pbits += 4;			}			break;					case TIFF_CMYK:		{			while (ptiff < ptiffend) {				int32 comp;				comp = 255 - ptiff[0] - ptiff[3];				pbits[2] = (comp < 0) ? 0 : comp;				comp = 255 - ptiff[1] - ptiff[3];				pbits[1] = (comp < 0) ? 0 : comp;								comp = 255 - ptiff[2] - ptiff[3];				pbits[0] = (comp < 0) ? 0 : comp;								ptiff += 4;				pbits += 4;			}			break;		}	}}