rem: bool bheaderonly = settings.SetGetHeaderOnly(); bool bdataonly = settings.SetGetDataOnly();
add: bool bheaderonly = false, bdataonly = false;
context: translate_from_bits(BPositionIO *inSource, ssize_t amtread, uint8 *read,	BMessage *ioExtension, uint32 outType, BPositionIO *outDestination,	SGITranslatorSettings &settings){	TranslatorBitmap bitsHeader;//  TODO: how do I comply with these requests for SGIImage?!?	bool bheaderonly = settings.SetGetHeaderOnly();	bool bdataonly = settings.SetGetDataOnly();	uint32 compression = settings.SetGetCompression();	status_t ret = identify_bits_header(inSource, NULL, amtread, read, &bitsHeader);	if (ret < B_OK)		return ret;	// Translate B_TRANSLATOR_BITMAP to B_TRANSLATOR_BITMAP, easy enough :)	if (outType == B_TRANSLATOR_BITMAP) {		// write out bitsHeader (only if configured to)		if (bheaderonly || (!bheaderonly && !bdataonly)) {			if (swap_data(B_UINT32_TYPE, &bitsHeader,				sizeof(TranslatorBitmap), B_SWAP_HOST_TO_BENDIAN) != B_OK)				return B_ERROR;			if (outDestination->Write(&bitsHeader,				sizeof(TranslatorBitmap)) != sizeof(TranslatorBitmap))				return B_ERROR;		}				// write out the data (only if configured to)		if (bdataonly || (!bheaderonly && !bdataonly)) {			uint32 size = 4096;			uint8* buf = new uint8[size];			uint32 remaining = B_BENDIAN_TO_HOST_INT32(bitsHeader.dataSize);			ssize_t rd, writ = B_ERROR;			rd = inSource->Read(buf, size);			while (rd > 0) {				writ = outDestination->Write(buf, rd);				if (writ < 0)					break;				remaining -= static_cast<uint32>(writ);				rd = inSource->Read(buf, min_c(size, remaining));			}			delete[] buf;					if (remaining > 0)				// writ may contain a more specific error				return writ < 0 ? writ : B_ERROR;			else				return B_OK;		} else			return B_OK;			// Translate B_TRANSLATOR_BITMAP to SGI_FORMAT	} else if (outType == SGI_FORMAT) {		// common fields which are independent of the bitmap format		uint32 width = bitsHeader.bounds.IntegerWidth() + 1;		uint32 height = bitsHeader.bounds.IntegerHeight() + 1;		uint32 bytesPerRow = bitsHeader.rowBytes;		uint32 bytesPerChannel = 1;		color_space format = bitsHeader.colors;	uint32 channelCount;		switch (format) {			case B_GRAY8:				channelCount = 1;				break;			case B_RGB32:			case B_RGB32_BIG:			case B_RGB24:			case B_RGB24_BIG:				channelCount = 3;				break;			case B_RGBA32:			case B_RGBA32_BIG:				channelCount = 4;				break;			default:				return B_NO_TRANSLATOR;		}		// Set up SGI header		SGIImage* sgiImage = new SGIImage();		status_t ret = sgiImage->SetTo(outDestination, width, height,									   channelCount, bytesPerChannel, compression);		if (ret >= B_OK) {			// read one row at a time,			// convert to the correct format			// and write out the results				// SGI Images store each channel separately			// a buffer is allocated big enough to hold all channels			// then the pointers are assigned with offsets into that buffer			uint8** rows = new(nothrow) uint8*[channelCount];			if (rows)				rows[0] = new(nothrow) uint8[width * channelCount * bytesPerChannel];			// rowBuffer is going to hold the converted data			uint8* rowBuffer = new(nothrow) uint8[bytesPerRow];			if (rows && rows[0] && rowBuffer) {				// assign the other pointers (channel offsets in row buffer)				for (uint32 i = 1; i < channelCount; i++)					rows[i] = rows[0] + i * width;				// loop through all lines of the image				for (int32 y = height - 1; y >= 0 && ret >= B_OK; y--) {					ret = inSource->Read(rowBuffer, bytesPerRow);					// see if an error happened while reading					if (ret < B_OK)						break;					// convert to native format (big endian)					switch (format) {						case B_GRAY8: {							uint8* src = rowBuffer;							for (uint32 x = 0; x < width; x++) {								rows[0][x] = src[0];								src += 1;							}							break;						}						case B_RGB24: {							uint8* src = rowBuffer;							for (uint32 x = 0; x < width; x++) {								rows[0][x] = src[2];								rows[1][x] = src[1];								rows[2][x] = src[0];								src += 3;							}							break;						}						case B_RGB24_BIG: {							uint8* src = rowBuffer;							for (uint32 x = 0; x < width; x++) {								rows[0][x] = src[0];								rows[1][x] = src[1];								rows[2][x] = src[2];								src += 3;							}							break;						}						case B_RGB32: {							uint8* src = rowBuffer;							for (uint32 x = 0; x < width; x++) {								rows[0][x] = src[2];								rows[1][x] = src[1];								rows[2][x] = src[0];								// ignore src[3]								src += 4;							}							break;						}						case B_RGB32_BIG: {							uint8* src = rowBuffer;							for (uint32 x = 0; x < width; x++) {								rows[0][x] = src[1];								rows[1][x] = src[2];								rows[2][x] = src[3];								// ignore src[0]								src += 4;							}							break;						}						case B_RGBA32: {							uint8* src = rowBuffer;							for (uint32 x = 0; x < width; x++) {								rows[0][x] = src[2];								rows[1][x] = src[1];								rows[2][x] = src[0];								rows[3][x] = src[3];								src += 4;							}							break;						}						case B_RGBA32_BIG: {							uint8* src = rowBuffer;							for (uint32 x = 0; x < width; x++) {								rows[0][x] = src[1];								rows[1][x] = src[2];								rows[2][x] = src[3];								rows[3][x] = src[0];								src += 4;							}							break;						}						default:							// cannot be here							break;					} // switch (format)						// for each channel, write a row buffer					for (uint32 z = 0; z < channelCount; z++) {						ret = sgiImage->WriteRow(rows[z], y, z);						if (ret < B_OK) {printf("WriteRow() returned %s!\n", strerror(ret));							break;						}					}					} // for (uint32 y = 0; y < height && ret >= B_OK; y++)				if (ret >= B_OK)					ret = B_OK;			} else // if (rows && rows[0] && rowBuffer)				ret = B_NO_MEMORY;				delete[] rows[0];			delete[] rows;			delete[] rowBuffer;		}		// done with the SGIImage object		delete sgiImage;		return ret;	}	return B_NO_TRANSLATOR;}