rem: memset(bitsRowData + (bmppixcol * 4), defaultcolor,
add: bmp_memset(bitsRowData + (bmppixcol * 4), defaultcolor,
context: translate_from_bmppalr_to_bits(BPositionIO *inSource,	BPositionIO *outDestination, int32 datasize, MSInfoHeader &msheader,	const uint8 *palette){	uint16 pixelsPerByte = 8 / msheader.bitsperpixel;	uint16 bitsPerPixel = msheader.bitsperpixel;	uint8 mask = (1 << bitsPerPixel) - 1;	uint8 count, indices, index;	// Setup outDestination so that it can be written to	// from the end of the file to the beginning instead of	// the other way around	int32 bitsRowBytes = msheader.width * 4;	off_t bitsFileSize = (bitsRowBytes * msheader.height) + 		sizeof(TranslatorBitmap);	if (outDestination->SetSize(bitsFileSize) != B_OK)		// This call should work for BFile and BMallocIO objects,		// but may not work for other BPositionIO based types		return B_ERROR;	uint8 *bitsRowData = new uint8[bitsRowBytes];	if (!bitsRowData)		return B_ERROR;	uint32 bmppixcol = 0, bmppixrow = 0;	uint32 defaultcolor = 0;	memcpy(&defaultcolor, palette, 4);	// set bits output to last row in the image	off_t bitsoffset = ((msheader.height - (bmppixrow + 1)) * bitsRowBytes) +		(bmppixcol * 4);	outDestination->Seek(bitsoffset, SEEK_CUR);	ssize_t rd = inSource->Read(&count, 1);	while (rd > 0) {		// repeated color		if (count) {			// abort if count is greater than the number of			// pixels remaining in the current row			if (count + bmppixcol > msheader.width) {				rd = -1;				break;			}						rd = inSource->Read(&indices, 1);			if (rd != 1) {				rd = -1;				break;			}			for (uint8 i = 0; i < count; i++) {				index = (indices >> (bitsPerPixel * ((pixelsPerByte - 1) - 					(i % pixelsPerByte)))) & mask;				memcpy(bitsRowData + (bmppixcol*4), palette + (index*4), 4);				bmppixcol++;			}		// special code		} else {			uint8 code;			rd = inSource->Read(&code, 1);			if (rd != 1) {				rd = -1;				break;			}			switch (code) {				// end of line				case 0:					// if there are columns remaing on this					// line, set them to the color at index zero					if (bmppixcol != msheader.width)						memset(bitsRowData + (bmppixcol * 4), defaultcolor,							(msheader.width - bmppixcol) * 4);					outDestination->Write(bitsRowData, bitsRowBytes);					bmppixcol = 0;					bmppixrow++;					if (bmppixrow < msheader.height)						outDestination->Seek(-(bitsRowBytes * 2), SEEK_CUR);					break;								// end of bitmap								case 1:					// if at the end of a row					if (bmppixcol == msheader.width) {						outDestination->Write(bitsRowData, bitsRowBytes);						bmppixcol = 0;						bmppixrow++;						if (bmppixrow < msheader.height)							outDestination->Seek(-(bitsRowBytes * 2),								SEEK_CUR);					}										while (bmppixrow < msheader.height) {						memset(bitsRowData + (bmppixcol * 4), defaultcolor,							(msheader.width - bmppixcol) * 4);						outDestination->Write(bitsRowData, bitsRowBytes);						bmppixcol = 0;						bmppixrow++;						if (bmppixrow < msheader.height)							outDestination->Seek(-(bitsRowBytes * 2),								SEEK_CUR);					}					rd = 0;						// break out of while loop					break;								// delta, skip several rows and/or columns and				// fill the skipped pixels with the default color								case 2:				{					uint8 da[2], lastcol, dx, dy;					rd = inSource->Read(da, 2);					if (rd != 2) {						rd = -1;						break;					}					dx = da[0];					dy = da[1];										// abort if dx or dy is too large					if ((dx + bmppixcol >= msheader.width) ||						(dy + bmppixrow >= msheader.height)) {						rd = -1;						break;					}														lastcol = bmppixcol;													// set all pixels to the first entry in					// the palette, for the number of rows skipped					while (dy > 0) {						memset(bitsRowData + (bmppixcol * 4), defaultcolor,							(msheader.width - bmppixcol) * 4);						outDestination->Write(bitsRowData, bitsRowBytes);						bmppixcol = 0;						bmppixrow++;						dy--;						outDestination->Seek(-(bitsRowBytes * 2), SEEK_CUR);					}													if (bmppixcol < (uint32) lastcol + dx) {						memset(bitsRowData + (bmppixcol * 4), defaultcolor,							(dx + lastcol - bmppixcol) * 4);						bmppixcol = dx + lastcol;					}										break;				}				// code >= 3				// read code uncompressed indices				default:					// abort if number of uncompressed pixels					// is larger than the number of pixels remaining					// in the current row					if (code + bmppixcol > msheader.width) {						rd = -1;						break;					}										uint8 uncomp[256];					int32 padding;					if (!(code % pixelsPerByte))						padding = (code / pixelsPerByte) % 2;					else						padding = ((code + pixelsPerByte - 							(code % pixelsPerByte)) / pixelsPerByte) % 2;					int32 uncompBytes = (code / pixelsPerByte) + 						((code % pixelsPerByte) ? 1 : 0) + padding;					rd = inSource->Read(uncomp, uncompBytes);					if (rd != uncompBytes) {						rd = -1;						break;					}					for (uint8 i = 0; i < code; i++) {						indices = (uncomp + (i / pixelsPerByte))[0];						index = (indices >>							(bitsPerPixel * ((pixelsPerByte - 1) - 								(i % pixelsPerByte)))) & mask;						memcpy(bitsRowData + (bmppixcol * 4),							palette + (index * 4), 4);						bmppixcol++;					}					break;			}		}		if (rd > 0)			rd = inSource->Read(&count, 1);	}		delete[] bitsRowData;		if (!rd)		return B_OK;	else		return B_NO_TRANSLATOR;}