Changing colorspace on image with pixels set from Python erases all pixels #93714

Open
opened 2021-12-05 18:41:10 +01:00 by Simon Wendsche · 7 comments

Blender Version
Broken: 3.0 (and older)

Short description of error

  • Image created with Python, pixel values set with foreach_set()
  • Changing the colorspace erases all pixels, setting them to black

Exact steps for others to reproduce the error

Open this .blend file: image_test.blend

Execute the Python script in the text editor:

import bpy
import random

img = bpy.data.images.new("test", 200, 200, alpha=True, float_buffer=True, is_data=False)

# Fill pixels with colors
img.pixels.foreach_set([random.random() for x in range(200*200*4)])

# Changing the colorspace will set all pixels to black
img.colorspace_settings.name = "Linear"

Expected Behaviour

In my opinion, Blender should convert the pixels from the old colorspace to the new one. The output should be the same as when changing colorspace on an image loaded from disk.

**Blender Version** Broken: 3.0 (and older) **Short description of error** * Image created with Python, pixel values set with `foreach_set()` * Changing the colorspace erases all pixels, setting them to black **Exact steps for others to reproduce the error** Open this .blend file: [image_test.blend](https://archive.blender.org/developer/F12692495/image_test.blend) Execute the Python script in the text editor: ```Py import bpy import random img = bpy.data.images.new("test", 200, 200, alpha=True, float_buffer=True, is_data=False) # Fill pixels with colors img.pixels.foreach_set([random.random() for x in range(200*200*4)]) # Changing the colorspace will set all pixels to black img.colorspace_settings.name = "Linear" ``` **Expected Behaviour** In my opinion, Blender should convert the pixels from the old colorspace to the new one. The output should be the same as when changing colorspace on an image loaded from disk.
Author

Added subscriber: @BYOB

Added subscriber: @BYOB

Added subscriber: @iss

Added subscriber: @iss

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'

Image buffer content is supposed to be in common colorspace - Linear if buffer is float, sRGB otherwise. All operations rely on this. You specify only in what colorspace image is saved on disk. Since this image is generated, setting it's colorspace is "not valid" operation. This is because file format does inform what colorspace should be (it is not possible to save linear data in PNG format, this is same for render result/bakes, conversion happens when file is saved to disk).

Not quite sure why changing colorspace is allowed for predefined generated images. Also I think this could be sanitized in RNA rather than just disabling this in UI.

I will confirm as I think this could be handled in better way, but this may be closed as "not a bug".

Image buffer content is supposed to be in common colorspace - Linear if buffer is float, sRGB otherwise. All operations rely on this. You specify only in what colorspace image is saved on disk. Since this image is generated, setting it's colorspace is "not valid" operation. This is because file format does inform what colorspace should be (it is not possible to save linear data in PNG format, this is same for render result/bakes, conversion happens when file is saved to disk). Not quite sure why changing colorspace is allowed for predefined generated images. Also I think this could be sanitized in RNA rather than just disabling this in UI. I will confirm as I think this could be handled in better way, but this may be closed as "not a bug".

Added subscriber: @brecht

Added subscriber: @brecht

I think that for generated images we can just make it not reload / regenerate the image.

There's two reason why you still might want to have this color space editable for generated images:

  • Most color spaces should not matter, however setting the color space to non-color data should make a difference.
  • It can be useful to set the color space in anticipation of saving the image to disk.
I think that for generated images we can just make it not reload / regenerate the image. There's two reason why you still might want to have this color space editable for generated images: * Most color spaces should not matter, however setting the color space to non-color data should make a difference. * It can be useful to set the color space in anticipation of saving the image to disk.
Bastien Montagne added this to the Core project 2023-02-09 15:42:54 +01:00
Bastien Montagne removed this from the Core project 2023-02-09 18:20:37 +01:00
Philipp Oeser removed the
Interest
VFX & Video
label 2023-02-10 09:31:34 +01:00
Contributor

@brecht "It can be useful to set the color space in anticipation of saving the image to disk." I totally agree!

@brecht "It can be useful to set the color space in anticipation of saving the image to disk." I totally agree!
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
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, Assets & 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
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
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
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
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
4 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#93714
No description provided.