Skip to content

Expose white balance coefficients applied during postprocessing#277

Merged
letmaik merged 4 commits intomainfrom
copilot/add-auto-white-balance-coefficients
Jan 28, 2026
Merged

Expose white balance coefficients applied during postprocessing#277
letmaik merged 4 commits intomainfrom
copilot/add-auto-white-balance-coefficients

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 27, 2026

LibRaw stores the actual white balance multipliers applied during processing in imgdata.color.pre_mul[], but rawpy only exposed pre-processing coefficients (camera_whitebalance, daylight_whitebalance). This makes it impossible to retrieve the coefficients used when use_auto_wb=True or verify what was actually applied.

Changes

  • New property auto_whitebalance: Returns the 4-channel WB coefficients from imgdata.color.pre_mul[] after postprocessing

    • Returns None before postprocess() or dcraw_process() is called
    • Works with all WB modes: auto, camera, user-specified, and daylight
  • Added dcraw_process_called flag: Tracks processing state to ensure property only returns meaningful values

Usage

import rawpy

with rawpy.imread('image.nef') as raw:
    print(raw.auto_whitebalance)  # None - no processing yet
    
    rgb = raw.postprocess(use_auto_wb=True)
    print(raw.auto_whitebalance)  # [2.34, 1.00, 1.82, 1.0] - actual coefficients used

The property name follows the issue request for "auto white balance coefficients", though it returns the applied coefficients regardless of WB mode.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Get auto white balance coefficients</issue_title>
<issue_description>Any chance you could add a way to get the auto white balance coefficients after postprocessing? Based on this forum post, it looks like LibRaw supports this with "imgdata.color.pre_mul[] coeffs."

Note that the related issues #12 and #221 are about generating wb coefficients from a gray box (i.e. the -A flag in dcraw). I'm asking about entire-image wb (-a). Also, the above forum post came a year after this was mentioned in #12, so the LibRaw function might be newer.

Also, if it's possible to calculate the wb coefficients without fully postprocessing (e.g. via a separate function), that'd be even better for my use case.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 27, 2026 23:15
…ocessing

Co-authored-by: letmaik <530988+letmaik@users.noreply.github.com>
Co-authored-by: letmaik <530988+letmaik@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ability to get auto white balance coefficients after postprocessing Expose white balance coefficients applied during postprocessing Jan 27, 2026
Copilot AI requested a review from letmaik January 27, 2026 23:21
@letmaik letmaik marked this pull request as ready for review January 27, 2026 23:32
@letmaik letmaik merged commit fbfe66b into main Jan 28, 2026
110 checks passed
@letmaik letmaik deleted the copilot/add-auto-white-balance-coefficients branch January 28, 2026 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get auto white balance coefficients

2 participants