rem: bool bheaderonly, bdataonly; bheaderonly = settings.SetGetHeaderOnly(); bdataonly = settings.SetGetDataOnly();
add: bool bheaderonly = false, bdataonly = false;
context: translate_from_png_to_bits(BPositionIO *inSource, BPositionIO *outDestination,	PNGTranslatorSettings &settings){	status_t result = B_ERROR;		// if a libpng errors before this is set		// to a different value, the above is what		// will be returned from this function		bool bheaderonly, bdataonly;	bheaderonly = settings.SetGetHeaderOnly();	bdataonly = settings.SetGetDataOnly();		// for storing decoded PNG row data	uint8 **prows = NULL, *prow = NULL;	png_uint_32 nalloc = 0;		png_structp ppng = NULL;	png_infop pinfo = NULL;	while (ppng == NULL) {		// create PNG read pointer with default error handling routines		ppng = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);		if (!ppng)			break;		// alocate / init memory for image information		pinfo = png_create_info_struct(ppng);		if (!pinfo)			break;		// set error handling		if (setjmp(png_jmpbuf(ppng)))			// When an error occurs in libpng, it uses			// the longjmp function to continue execution			// from this point			break;				// set read callback function		png_set_read_fn(ppng, static_cast<void *>(inSource), pngcb_read_data);				// Read in PNG image info		png_set_sig_bytes(ppng, 8);		png_read_info(ppng, pinfo);					png_uint_32 width, height;		int bit_depth, color_type, interlace_type;		png_get_IHDR(ppng, pinfo, &width, &height, &bit_depth, &color_type,			&interlace_type, int_p_NULL, int_p_NULL);				// Setup image transformations to make converting it easier		bool balpha = false;				if (bit_depth == 16)			png_set_strip_16(ppng);		else if (bit_depth < 8)			png_set_packing(ppng);					if (color_type == PNG_COLOR_TYPE_PALETTE)			png_set_palette_to_rgb(ppng);					if (png_get_valid(ppng, pinfo, PNG_INFO_tRNS)) {			balpha = true;			png_set_tRNS_to_alpha(ppng);		}					// change RGB to BGR as it is in 'bits'		if (color_type & PNG_COLOR_MASK_COLOR)			png_set_bgr(ppng);					// have libpng convert gray to RGB for me		if (color_type == PNG_COLOR_TYPE_GRAY ||			color_type == PNG_COLOR_TYPE_GRAY_ALPHA)			png_set_gray_to_rgb(ppng);					if (color_type & PNG_COLOR_MASK_ALPHA)			balpha = true;					if (!balpha)			// add filler byte for images without alpha			// so that the pixels are 4 bytes each			png_set_filler(ppng, 0xff, PNG_FILLER_AFTER);				// Check that transformed PNG rowbytes matches		// what is expected		const int32 kbytes = 4;		png_uint_32 rowbytes = png_get_rowbytes(ppng, pinfo);		if (rowbytes < kbytes * width)			rowbytes = kbytes * width;				if (!bdataonly) {			// Write out the data to outDestination			// 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 = 4 * width;			if (balpha)				bitsHeader.colors = B_RGBA32;			else				bitsHeader.colors = B_RGB32;			bitsHeader.dataSize = bitsHeader.rowBytes * height;			if (swap_data(B_UINT32_TYPE, &bitsHeader,				sizeof(TranslatorBitmap), B_SWAP_HOST_TO_BENDIAN) != B_OK) {				result = B_ERROR;				break;			}			outDestination->Write(&bitsHeader, sizeof(TranslatorBitmap));						if (bheaderonly) {				result = B_OK;				break;			}		}				if (interlace_type == PNG_INTERLACE_NONE) {			// allocate buffer for storing PNG row			prow = new uint8[rowbytes];			if (!prow) {				result = B_NO_MEMORY;				break;			}			for (png_uint_32 i = 0; i < height; i++) {				png_read_row(ppng, prow, NULL);				outDestination->Write(prow, width * kbytes);			}			result = B_OK;				// Set OK status here, because, in the event of				// an error, png_read_end() will longjmp to error				// handler above and not execute lines below it									// finish reading, pass NULL for info because I			// don't need the extra data			png_read_end(ppng, NULL);						break;					} else {			// interlaced PNG image			prows = new uint8 *[height];			if (!prows) {				result = B_NO_MEMORY;				break;			}			// allocate enough memory to store the whole image			for (nalloc = 0; nalloc < height; nalloc++) {				prows[nalloc] = new uint8[rowbytes];				if (!prows[nalloc])					break;			}						if (nalloc < height)				result = B_NO_MEMORY;			else {				png_read_image(ppng, prows);								for (png_uint_32 i = 0; i < height; i++)					outDestination->Write(prows[i], width * kbytes);				result = B_OK;					// Set OK status here, because, in the event of					// an error, png_read_end() will longjmp to error					// handler above and not execute lines below it								png_read_end(ppng, NULL);			}						break;		}	}		if (ppng) {		delete[] prow;		prow = NULL;				// delete row pointers and array of pointers to rows		while (nalloc) {			nalloc--;			delete[] prows[nalloc];		}		delete[] prows;		prows = NULL;				// free PNG handle / info structures		if (!pinfo)			png_destroy_read_struct(&ppng, png_infopp_NULL, png_infopp_NULL);		else			png_destroy_read_struct(&ppng, &pinfo, png_infopp_NULL);	}	return result;}