Oneplus 5 DNGs don't look right

I tried many DNGs and raws from different cameras, and besides for the SD980 problem I reported yesterday, which was not really LibRaw's fault, they all worked very nicely, and I got results comparable to RawTherapee.

I tried some Oneplus 5 samples, which I got from here: http://www.photographyblog.com/previews/oneplus_5_photos/ (scroll to the bottom for the DNGs). They all look really bad (try the beach ones) both in my program and IrfanView's raw viewer, but they look nicely in RawTherapee. The red channel is almost identical to the green one all over except for the obvious red/green parts. But the sky and the beach are the same. With RawTherapee, on the other hand, the red channel is much darker on the sky. The camera_mul wb seems to have reasonable values, but pre_mul (which I don't use) has some strange values that don;t work either.

Can you please a look at them when you have some time?

Forums: 

From _01.DNG sample, using

From _01.DNG sample, using raw-identify -v:
Makernotes 'As shot' WB multipliers: 2.031746 1.000000 1.729730 0.000000
and
Derived D65 multipliers: 6.630021 0.866640 0.901968

This file is shot under daylight, so D65 mutipliers looks incorrect: too weak for blue and too strong for red.
D65 (daylight) multipliers are calculated from DNG ColorMatrix* tag(s). So, embedded profile for this file looks incorrect.

Use as-shot, or auto WB for this camera (I do not see any way to do this automatically in LibRaw because pre_mul is within 'more or less correct values' (6.63/0.86 = 7.7 does not 'high enough' to throw it out automatically)

-- Alex Tutubalin @LibRaw LLC

Also, with as-shot balance

Also, with as-shot balance sky is 'too cyan' in FastRawViewer, that also points to not-so-correct embedded color profile.

-- Alex Tutubalin @LibRaw LLC

Any idea how RawTherapee

Any idea how RawTherapee gets it right?
Is there a way to force LibRaw to manually calculate the WB and put it in cam_mul or something like that? Or is it too orthogonal to it's purpose? :)

params.use_camera_wb will

params.use_camera_wb will force to use As-shot balance
params.use_auto_wb will switch to auto-balance
params.user_mul[4] allows to use user-specified WB

-- Alex Tutubalin @LibRaw LLC

I meant, if there was a way

I meant, if there was a way to only get the WB, without fully process the image (so that I can do my own processing).

as-shot balance (cam_mul) is

as-shot balance (cam_mul) is avaliable just after LibRaw::open_file()

To calculate auto-wb you may use raw data with black subtracted (Libraw does this at LibRaw::scale_colors() call, before interpolation step)

-- Alex Tutubalin @LibRaw LLC

Sorry, I meant if there was a

Sorry, I meant if there was a way to get the auto WB. I know I can get the "as shot" WB.

Right now, I do things like this:
Init, open, unpack, raw2image, black subtraction, apply WB, debayer, sRGB, gamma curve then I do things like contrast and saturation.

Is there a function I can call after black subtraction to make LibRaw return an auto calculated WB, preferably accessible from C, without doing further data processing?

There is no exposed function.

There is no exposed function.

You may steal code from internal\dcraw_common.cpp:scale_colors() function;

Starting with

  if (use_auto_wb || (use_camera_wb && cam_mul[0] == -1))
  {

And up to final calculation of pre_mul:

 pre_mul[geshifilter-c] = dsum[c + 4] / dsum[c];


This code cycle through image[] 8x8 blocks, skip blocks with data near sensor saturation and calculates pixel sum/count for other (non-saturated) blocks to get mean per-channel values. This code assumes entire image is (average) gray. If not, auto-WB will not work well.[/geshifilter-c]

-- Alex Tutubalin @LibRaw LLC

sorry for geshifilter-c in

sorry for geshifilter-c in previous message, sometimes code formatter on our site works strange :)

this is just [ c ]

-- Alex Tutubalin @LibRaw LLC

Oh, so this won't work for a

Oh, so this won't work for a photo of the sea and sky, or a forest canopy with little sky, etc.
I will take a look at that code after I finish some other things, thanks!

Yes, auto balance does not

Yes, auto balance does not work well for colored shots. Use as-shot (camera wb) instead.

-- Alex Tutubalin @LibRaw LLC

Well, if the "as shot"

Well, if the "as shot" multipliers worked, I wouldn't have asked about the auto WB thing :)