Add new comment

Inconsistent color results

Hi,

First off, thanks for the library and continued support. I have been using DCRAW for a couple of
years but recently I felt the need to jump the ship and turn to LibRaw. It seams like a solid solution but
I was experiencing some problems and it's gotta be something that I did wrong or a bug. So here it goes...

The procedure I have written is simple, it takes an image that is already loaded in memory and converts it to
a Windows Bitmap. I have supplied the entire function, but the bitmap part is fine. The problem I have appears
somewhere in the first 10 lines as I have placed a call to dcraw_ppm_tiff_writer() and the output is not consistent.
On occasions,the image is loaded just fine, but most of the time, the result I get is dominantly RED or GREEN and
I can't figure out the problem.

I am using VS2013 Express for this.

Does anybody see what might have been wrong? Thanks in advance!

P.S. Test images I use are:
http://www.rawsamples.ch/raws/nikon/d3x/RAW_NIKON_D3X.NEF (comes out red)
http://www.rawsamples.ch/raws/canon/1dsm2/RAW_CANON_1DSM2.CR2 (comes out green)

// INPUT ARGUMENTS:
// lpData: in - source buffer
// uSize:  in - source buffer size
// Point:  out - width & height
//
// RETURN: Windows Bitmap
//
extern "C" DLLEXPORT HBITMAP RawLoad(void* lpData, DWORD uSize, POINT* Point)
{
	LibRaw raw;
	libraw_processed_image_t *image = NULL;
	HBITMAP hBmp = NULL;
 
	if (raw.open_buffer(lpData, uSize) != LIBRAW_SUCCESS) return NULL;
 
	raw.imgdata.params.half_size = 1;
	raw.imgdata.params.user_flip = 0;
	if (raw.unpack() != LIBRAW_SUCCESS) return NULL;
	if (raw.dcraw_process() != LIBRAW_SUCCESS) return NULL;
 
	// for debugging purposes
	raw.dcraw_ppm_tiff_writer("test.ppm");
 
	image = raw.dcraw_make_mem_image();
	if (image == NULL) return NULL;
 
	BITMAPINFO BitmapInfo;
	ZeroMemory(&BitmapInfo, sizeof BITMAPINFO);
	BitmapInfo.bmiHeader.biCompression = BI_RGB;
	BitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	BitmapInfo.bmiHeader.biPlanes = 1;
	BitmapInfo.bmiHeader.biBitCount = 32;
	BitmapInfo.bmiHeader.biWidth = image->width;
	Point->x = image->width;
	BitmapInfo.bmiHeader.biHeight = -image->height;
	Point->y = image->height;
 
	HDC hDC = GetDC(NULL);
	unsigned char* lpDib;
	hBmp = CreateDIBSection(hDC, &BitmapInfo, DIB_RGB_COLORS, (void**)&lpDib, NULL, NULL);
	ReleaseDC(NULL, hDC);
	if (hBmp == NULL) return NULL;
	if (&lpDib == NULL) return NULL;
 
	int i;
	unsigned char * src = image->data;
	unsigned char * dest = lpDib;
	for (i = image->data_size/3; --i; dest += 4, src += 3)
	{
		dest[0] = src[2];
		dest[1] = src[1];
		dest[2] = src[0];
		dest[3] = 0;
	}
	for (i = 0; i < 3; ++i)
	{
		dest[i] = src[i];
	}
	raw.dcraw_clear_mem(image);
	return hBmp;
}

Forums: