Fix #120175: File Output node has wrong BW output #120206

Merged
Omar Emara merged 2 commits from OmarEmaraDev/blender:fix-120175 into main 2024-04-04 08:52:09 +02:00
Member

The File Output node produces wrong output when the output is set to BW.
This is because the image saving logic assumes float buffers always have
4 channels and ignores the image buffer channels member. So for single
channel images, the code weighted sum neighbouring pixels and asigned
them as a single pixel, producing bleeding at best and crashes at worst.

To fix this, we skip Color to BW conversion if the image is already BW.
And, we fix the functions that assume 4 channels for float buffers.

The File Output node produces wrong output when the output is set to BW. This is because the image saving logic assumes float buffers always have 4 channels and ignores the image buffer channels member. So for single channel images, the code weighted sum neighbouring pixels and asigned them as a single pixel, producing bleeding at best and crashes at worst. To fix this, we skip Color to BW conversion if the image is already BW. And, we fix the functions that assume 4 channels for float buffers.
Omar Emara added the
Module
VFX & Video
Interest
Compositing
labels 2024-04-03 13:40:02 +02:00
Omar Emara requested review from Sergey Sharybin 2024-04-03 13:40:48 +02:00
Sergey Sharybin requested changes 2024-04-03 14:32:32 +02:00
Dismissed
Sergey Sharybin left a comment
Owner

This seems a bit strange, as the other usages of IMB_color_to_bw are not covered, and with this change you potentially leave byte buffer as color and not BW.

I think doing something like this in the IMB_color_to_bw is fine:

  if (rct_fl) {
    if (ibuf->channels >= 3) {
      for (i = IMB_get_rect_len(ibuf); i > 0; i--, rct_fl += ibuf->channels) {
        rct_fl[0] = rct_fl[1] = rct_fl[2] = IMB_colormanagement_get_luminance(rct_fl);
      }
    }
  }

The PR should also be against the main branch. See https://developer.blender.org/docs/handbook/release_process/release_branch/#after-a-release

This seems a bit strange, as the other usages of `IMB_color_to_bw` are not covered, and with this change you potentially leave byte buffer as color and not BW. I think doing something like this in the `IMB_color_to_bw` is fine: ``` if (rct_fl) { if (ibuf->channels >= 3) { for (i = IMB_get_rect_len(ibuf); i > 0; i--, rct_fl += ibuf->channels) { rct_fl[0] = rct_fl[1] = rct_fl[2] = IMB_colormanagement_get_luminance(rct_fl); } } } ``` The PR should also be against the main branch. See https://developer.blender.org/docs/handbook/release_process/release_branch/#after-a-release
Author
Member

The only other IMB_color_to_bw usage is guaranteed to be a byte buffer, so it is not affected. As for the byte buffer, I just assumed float and byte buffers would be mutually exclusive as many parts of the code already do.

I wanted to update IMB_color_to_bw and IMB_saturation directly, but I thought it is best to leave that out of 4.1. But if you think this is best, I will update the patch. The other thing that we will be doing a redundant buffer duplication in most cases.

The only other `IMB_color_to_bw` usage is guaranteed to be a byte buffer, so it is not affected. As for the byte buffer, I just assumed float and byte buffers would be mutually exclusive as many parts of the code already do. I wanted to update `IMB_color_to_bw` and `IMB_saturation` directly, but I thought it is best to leave that out of 4.1. But if you think this is best, I will update the patch. The other thing that we will be doing a redundant buffer duplication in most cases.
Omar Emara changed target branch from blender-v4.1-release to main 2024-04-03 14:52:14 +02:00
Omar Emara force-pushed fix-120175 from f64d9008f1 to 4489aa978c 2024-04-03 14:54:15 +02:00 Compare

Byte and float buffers are not mutually exclusive. Accessing data will choose the best suitable buffer, but pixel transforms are expected to keep both in sync. For example. in the IMB_color_to_bw you see if (rct_fl) { ... } if (rct) { ... }.

Maybe with the way how some other areas work it is fine to have check on a higher level, but it somehow does not feel fully reliable.

The corrective release is scheduled for 16 April, so it seems to be OK amount of time to possibly catch unexpected issues with a change in IMB_color_to_bw. The change in IMB_saturation we can limit to the main only.

P.S. If we want to be extra careful, we can follow the IMB_gpu_get_texture_format and use channels = image_buffer->channels == 0 ? 4 : image_buffer->channels.

Byte and float buffers are not mutually exclusive. Accessing data will choose the best suitable buffer, but pixel transforms are expected to keep both in sync. For example. in the `IMB_color_to_bw` you see `if (rct_fl) { ... } if (rct) { ... }`. Maybe with the way how some other areas work it is fine to have check on a higher level, but it somehow does not feel fully reliable. The corrective release is scheduled for 16 April, so it seems to be OK amount of time to possibly catch unexpected issues with a change in `IMB_color_to_bw`. The change in `IMB_saturation` we can limit to the main only. P.S. If we want to be extra careful, we can follow the `IMB_gpu_get_texture_format` and use `channels = image_buffer->channels == 0 ? 4 : image_buffer->channels`.
Author
Member

@Sergey I added !(ibuf->float_buffer.data && !ibuf->byte_buffer.data && ibuf->channels == 1) to avoid redundant duplication, not sure if you would be pro adding it.

@Sergey I added `!(ibuf->float_buffer.data && !ibuf->byte_buffer.data && ibuf->channels == 1)` to avoid redundant duplication, not sure if you would be pro adding it.
Sergey Sharybin approved these changes 2024-04-03 15:44:59 +02:00
Sergey Sharybin left a comment
Owner

I think it is fine to have that check, as it avoids unnecessary ImBug duplications if the ImBuf is a single-channel already.

I think it is fine to have that check, as it avoids unnecessary ImBug duplications if the `ImBuf` is a single-channel already.
Omar Emara merged commit 0c91ad9008 into main 2024-04-04 08:52:09 +02:00
Omar Emara deleted branch fix-120175 2024-04-04 08:52:12 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
FBX
Interest
Freestyle
Interest
Geometry Nodes
Interest
glTF
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#120206
No description provided.