rem: bool bheaderonly = settings.SetGetHeaderOnly(); bool bdataonly = settings.SetGetDataOnly();
add: bool bheaderonly = false, bdataonly = false;
context: translate_from_sgi(BPositionIO *inSource, BMessage *ioExtension,	uint32 outType, BPositionIO *outDestination,	SGITranslatorSettings &settings){	status_t ret = B_NO_TRANSLATOR;	// variables needing cleanup	SGIImage* sgiImage = NULL;		ret = identify_sgi_header(inSource, ioExtension, NULL, outType, &sgiImage);	if (ret >= B_OK) {		bool bheaderonly = settings.SetGetHeaderOnly();		bool bdataonly = settings.SetGetDataOnly();			uint32 width = sgiImage->Width();		uint32 height = sgiImage->Height();		uint32 channelCount = sgiImage->CountChannels();		color_space format = B_RGBA32;		uint32 bytesPerRow = 0;		uint32 bytesPerChannel = sgiImage->BytesPerChannel();		if (channelCount == 1) {//			format = B_GRAY8;	// this format is not supported by most applications//			bytesPerRow = width;			format = B_RGB32;			bytesPerRow = width * 4;		} else if (channelCount == 2) {			// means gray (luminance) + alpha, we convert that to B_RGBA32			format = B_RGBA32;			bytesPerRow = width * 4;		} else if (channelCount == 3) {			format = B_RGB32; // should be B_RGB24, but let's not push it too hard...			bytesPerRow = width * 4;		} else if (channelCount == 4) {			format = B_RGBA32;			bytesPerRow = width * 4;		} else			ret = B_NO_TRANSLATOR; // we cannot handle this image		if (ret >= B_OK && !bdataonly) {			// Construct and write Be bitmap header			TranslatorBitmap bitsHeader;			bitsHeader.magic = B_TRANSLATOR_BITMAP;			bitsHeader.bounds.left = 0;			bitsHeader.bounds.top = 0;			bitsHeader.bounds.right = width - 1;			bitsHeader.bounds.bottom = height - 1;			bitsHeader.rowBytes = bytesPerRow;			bitsHeader.colors = format;			bitsHeader.dataSize = bitsHeader.rowBytes * height;			if ((ret = swap_data(B_UINT32_TYPE, &bitsHeader,				sizeof(TranslatorBitmap), B_SWAP_HOST_TO_BENDIAN)) < B_OK) {				return ret;			} else				ret = outDestination->Write(&bitsHeader, sizeof(TranslatorBitmap));		}if (ret < B_OK)printf("error writing bits header: %s\n", strerror(ret));		if (ret >= B_OK && !bheaderonly) {			// 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 * bytesPerChannel;				// loop through all lines of the image				for (int32 y = height - 1; y >= 0 && ret >= B_OK; y--) {					// fill the row buffer with each channel					for (uint32 z = 0; z < channelCount; z++) {						ret = sgiImage->ReadRow(rows[z], y, z);						if (ret < B_OK)							break;					}					// see if an error happened while reading					if (ret < B_OK)						break;					// convert to native format (big endian)					if (bytesPerChannel == 1) {						switch (format) {							case B_GRAY8: {								uint8* dst = rowBuffer;								for (uint32 x = 0; x < width; x++) {									dst[0] = rows[0][x];									dst += 1;								}								break;							}							case B_RGB24: {								uint8* dst = rowBuffer;								for (uint32 x = 0; x < width; x++) {									dst[0] = rows[2][x];									dst[1] = rows[1][x];									dst[2] = rows[0][x];									dst += 3;								}								break;							}							case B_RGB32: {								uint8* dst = rowBuffer;								if (channelCount == 1) {									for (uint32 x = 0; x < width; x++) {										dst[0] = rows[0][x];										dst[1] = rows[0][x];										dst[2] = rows[0][x];										dst[3] = 255;										dst += 4;									}								} else {									for (uint32 x = 0; x < width; x++) {										dst[0] = rows[2][x];										dst[1] = rows[1][x];										dst[2] = rows[0][x];										dst[3] = 255;										dst += 4;									}								}								break;							}							case B_RGBA32: {								uint8* dst = rowBuffer;								if (channelCount == 2) {									for (uint32 x = 0; x < width; x++) {										dst[0] = rows[0][x];										dst[1] = rows[0][x];										dst[2] = rows[0][x];										dst[3] = rows[1][x];										dst += 4;									}								} else {									for (uint32 x = 0; x < width; x++) {										dst[0] = rows[2][x];										dst[1] = rows[1][x];										dst[2] = rows[0][x];										dst[3] = rows[3][x];										dst += 4;									}								}								break;							}							default:								// cannot be here								break;						} // switch (format)						ret = outDestination->Write(rowBuffer, bytesPerRow);					} else {						// support for 16 bits per channel images						uint16** rows16 = (uint16**)rows;						switch (format) {							case B_GRAY8: {								uint8* dst = rowBuffer;								for (uint32 x = 0; x < width; x++) {									dst[0] = rows16[0][x] >> 8;									dst += 1;								}								break;							}							case B_RGB24: {								uint8* dst = rowBuffer;								for (uint32 x = 0; x < width; x++) {									dst[0] = rows16[2][x] >> 8;									dst[1] = rows16[1][x] >> 8;									dst[2] = rows16[0][x] >> 8;									dst += 3;								}								break;							}							case B_RGB32: {								uint8* dst = rowBuffer;								if (channelCount == 1) {									for (uint32 x = 0; x < width; x++) {										dst[0] = rows16[0][x] >> 8;										dst[1] = rows16[0][x] >> 8;										dst[2] = rows16[0][x] >> 8;										dst[3] = 255;										dst += 4;									}								} else {									for (uint32 x = 0; x < width; x++) {										dst[0] = rows16[2][x] >> 8;										dst[1] = rows16[1][x] >> 8;										dst[2] = rows16[0][x] >> 8;										dst[3] = 255;										dst += 4;									}								}								break;							}							case B_RGBA32: {								uint8* dst = rowBuffer;								if (channelCount == 2) {									for (uint32 x = 0; x < width; x++) {										dst[0] = rows16[0][x] >> 8;										dst[1] = rows16[0][x] >> 8;										dst[2] = rows16[0][x] >> 8;										dst[3] = rows16[1][x] >> 8;										dst += 4;									}								} else {									for (uint32 x = 0; x < width; x++) {										dst[0] = rows16[2][x] >> 8;										dst[1] = rows16[1][x] >> 8;										dst[2] = rows16[0][x] >> 8;										dst[3] = rows16[3][x] >> 8;										dst += 4;									}								}								break;							}							default:								// cannot be here								break;						} // switch (format)						ret = outDestination->Write(rowBuffer, bytesPerRow);					} // 16 bit version				} // 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;		} // if (ret >= B_OK && !bheaderonly)	} // if (ret >= B_OK)	delete sgiImage;	return ret;}