Add new comment

OK I'm a bit disappointed

OK I'm a bit disappointed about that. Looking at the source in dcraw_common.cpp it appears that the "document mode" stuff has been #ifdef-ed out of existence.

I had specified equivalent options to those I used with dcraw and captured the output file by sub-classing libraw and over-riding just dcraw_ppm_tiff_writer() and write_ppm_tiff() which worked a treat except that it didn't produce the 16 bit PGM greyscale data I hoped for but instead produced a 16 bit PPM RGB bitmap (which I confirmed using dcraw_emu).

Advice and guidance in more detail of how to get at the grayscale data will be greatly welcome

Might I ask why you explicitly disabled the "document mode" code?

Here's what my code looks like right now:

			if (!m_bColorRAW)
			{
				// Document mode (i.e. don't demosaic the image in libraw).
				O.no_interpolation = 1;
			};
 
			// Don't stretch or rotate raw pixels (equivalent to dcraw -j)
			O.use_fuji_rotate = 0;
 
			// Don't flip the image (equivalent to dcraw -t 0)
			O.user_flip = 0;
 
			// Output color space : raw-> sRGB (default)
			/*
			argv[argc] = _T("-o");
			argc++;
			argv[argc] = _T("0");
			argc++;*/
 
			workspace.GetValue(REGENTRY_BASEKEY_RAWSETTINGS, _T("BlackPointTo0"), bBlackPointTo0);
			if (bBlackPointTo0)
			{
				// Set black point to 0 
				O.user_black = 0;
			};
 
			// Output is 16 bits (equivalent of dcraw flag -4)
			O.gamm[0] = O.gamm[1] = O.no_auto_bright = 1;
			O.output_bps = 16;
 
			lstrcpy(g_szInputFileName, (LPCTSTR)m_strFileName);
			g_Progress = pProgress;
 
			if ((ret = rawProcessor.unpack()) != LIBRAW_SUCCESS)
			{
				bResult = FALSE;
				ZTRACE_RUNTIME("Cannot unpack %s: %s", m_strFileName, libraw_strerror(ret));
			}
			if (!bResult) break;
 
			if (LIBRAW_SUCCESS != (ret = rawProcessor.dcraw_process()))
			{
				ZTRACE_RUNTIME("Cannot do postprocessing on %s: %s", m_strFileName, libraw_strerror(ret));
				if (LIBRAW_FATAL_ERROR(ret))
					bResult = FALSE;
			}
			if (!bResult) break;
			pFiller = new BitMapFiller(pBitmap, pProgress);
			pFiller->SetWhiteBalance(fRedScale, fGreenScale, fBlueScale);
			// Get the Colour Filter Array type and set into the bitmap filler
			m_CFAType = GetCurrentCFAType();
			pFiller->SetCFAType(m_CFAType);
 
			// Set up the intercept code to write the image data to our bitmap instead of 
			// to an external file, and invoke the overridden dcraw_ppm_tiff_writer()
			rawProcessor.setBitMapFiller(pFiller);
			if (LIBRAW_SUCCESS != (ret = rawProcessor.dcraw_ppm_tiff_writer("")))
			{
				bResult = FALSE;
				ZTRACE_RUNTIME("Cannot write image data to bitmap %s", libraw_strerror(ret));
			}

Thanks

David Partridge