martin-marek / hdr-plus-swift

📸Night mode on any camera. Based on HDR+.
https://burst.photo
GNU General Public License v3.0
208 stars 11 forks source link

Reconsidering handing of black level #39

Open Alex-Vasile opened 11 months ago

Alex-Vasile commented 11 months ago

Currently handling of black levels for the image requires the black level be carrying around and passed to multiple functions, far downstream of the dng to texture conversion.

Option 1: have image_url_to_texture return a float32 texture with the black level already subtracted.

The adobe DNG sdk (and likely the open source one) has functionality for querying black level for individual sub-pixels, making that portion of the implementation easier.

Option 2: carry around more information about black level

_Original public discussion started in https://github.com/martin-marek/hdr-plus-swift/pull/38#discussion_r1359950165_

Alex-Vasile commented 11 months ago

Further consideration, I am not sure the black level is currently being handled correctly. prepare_texture, and the code it was based on, ensures that values are above zero after the black level has been re-added: https://github.com/martin-marek/hdr-plus-swift/blob/8be652ff83854a4d8c25d27b1f1ba78e326a6b3d/burstphoto/texture/texture.metal#L547-L549

While this does prevent negative values in the texture returned by this function, it does not set all pixels below the black level to 0.

I was under the impression that pixels with intensities below the black level should be zeroed out. I.e. the above two lines should be replaced by:

pixel_value = max(0.0f, pixel_value - black_level)*corr_factor + black_level;