rem: bytescopied = width * 3; while (width--) { ptga[0] = pbits[0]; ptga[1] = pbits[0]; ptga[2] = pbits[0];  ptga += 3; pbits++; }
add: bytescopied = width; memcpy(ptga, pbits, bytescopied);
context: pix_bits_to_tga(uint8 *pbits, uint8 *ptga, color_space fromspace,	uint16 width, const color_map *pmap, int32 bitsBytesPerPixel){	status_t bytescopied = 0;		switch (fromspace) {		case B_RGBA32:			bytescopied = width * 4;			memcpy(ptga, pbits, bytescopied);			break;							case B_RGBA32_BIG:			bytescopied = width * 4;			while (width--) {				ptga[0] = pbits[3];				ptga[1] = pbits[2];				ptga[2] = pbits[1];				ptga[3] = pbits[0];								ptga += 4;				pbits += 4;			}			break;						case B_CMYA32:			bytescopied = width * 4;			while (width--) {				ptga[0] = 255 - pbits[2];				ptga[1] = 255 - pbits[1];				ptga[2] = 255 - pbits[0];				ptga[3] = pbits[3];								ptga += 4;				pbits += 4;			}			break;							case B_RGB32:		case B_RGB24:			bytescopied = width * 3;				while (width--) {				memcpy(ptga, pbits, 3);								ptga += 3;				pbits += bitsBytesPerPixel;			}			break;							case B_CMYK32:		{			int32 comp;			bytescopied = width * 3;			while (width--) {							comp = 255 - pbits[2] - pbits[3];				ptga[0] = (comp < 0) ? 0 : comp;									comp = 255 - pbits[1] - pbits[3];				ptga[1] = (comp < 0) ? 0 : comp;									comp = 255 - pbits[0] - pbits[3];				ptga[2] = (comp < 0) ? 0 : comp;								ptga += 3;				pbits += 4;			}			break;		}						case B_CMY32:		case B_CMY24:			bytescopied = width * 3;			while (width--) {				ptga[0] = 255 - pbits[2];				ptga[1] = 255 - pbits[1];				ptga[2] = 255 - pbits[0];								ptga += 3;				pbits += bitsBytesPerPixel;			}			break;							case B_RGB16:		case B_RGB16_BIG:		{			// Expand to 24 bit because the TGA format handles			// 16 bit images differently than the Be Image Format			// which would cause a loss in quality			uint16 val;			bytescopied = width * 3;			while (width--) {				if (fromspace == B_RGB16)					val = pbits[0] + (pbits[1] << 8);				else					val = pbits[1] + (pbits[0] << 8);				ptga[0] =					((val & 0x1f) << 3) | ((val & 0x1f) >> 2);				ptga[1] =					((val & 0x7e0) >> 3) | ((val & 0x7e0) >> 9);				ptga[2] =					((val & 0xf800) >> 8) | ((val & 0xf800) >> 13);									ptga += 3;				pbits += 2;			}			break;		}						case B_RGBA15:			bytescopied = width * 2;			memcpy(ptga, pbits, bytescopied);			break;						case B_RGBA15_BIG:			bytescopied = width * 2;			while (width--) {				ptga[0] = pbits[1];				ptga[1] = pbits[0];								ptga += 2;				pbits += 2;			}			break;		case B_RGB15:			bytescopied = width * 2;			while (width--) {				ptga[0] = pbits[0];				ptga[1] = pbits[1] | 0x80;					// alpha bit is always 1								ptga += 2;				pbits += 2;			}			break;							case B_RGB15_BIG:			bytescopied = width * 2;			while (width--) {				ptga[0] = pbits[1];				ptga[1] = pbits[0] | 0x80;					// alpha bit is always 1								ptga += 2;				pbits += 2;			}			break;								case B_RGB32_BIG:			bytescopied = width * 3;			while (width--) {				ptga[0] = pbits[3];				ptga[1] = pbits[2];				ptga[2] = pbits[1];								ptga += 3;				pbits += 4;			}			break;								case B_RGB24_BIG:			bytescopied = width * 3;			while (width--) {				ptga[0] = pbits[2];				ptga[1] = pbits[1];				ptga[2] = pbits[0];								ptga += 3;				pbits += 3;			}			break;						case B_CMAP8:		{			rgb_color c;			bytescopied = width * 3;			while (width--) {				c = pmap->color_list[pbits[0]];				ptga[0] = c.blue;				ptga[1] = c.green;				ptga[2] = c.red;								ptga += 3;				pbits++;			}			break;		}							case B_GRAY8:			bytescopied = width * 3;			while (width--) {				ptga[0] = pbits[0];				ptga[1] = pbits[0];				ptga[2] = pbits[0];								ptga += 3;				pbits++;			}			break;								default:			bytescopied = B_ERROR;			break;	} // switch (fromspace)		return bytescopied;}