Image "Save As" and changing colorspace: invalid colorspace change #101331

Closed
opened 2022-09-24 16:38:07 +02:00 by Florent Masson · 15 comments

System Information
Operating system: Windows 10
Graphics card: RTX3700

Blender Version
Broken: 3.3.0 Probably caused by 5baa3ecda6.
Worked: 3.1.2

Short description of error
When saving an image, we can change the color space in the save properties.

When we do this, we can see that the Color Space for the image has been changed in the image properties, but the image itself has not changed within Blender.

Similarly in Python, we can see that this value has been changed (bpy.data.images- [x].colorspace_settings.name)

Afterwards, setting back the Color Space to 'sRGB' makes visual changes to the image and you are unable to get back the original image

The exported file is different (darker), as if a Linear -> sRGB has been made instead of the requested opposite.

Blender 3.1 does not have the option to change color space when saving the image but according to a few tests, the image is converted to sRGB before saving (ie if you have a linear encoding and save the file, the image is switched to sRGB and the exported file is the same as in blender)

Exact steps for others to reproduce the error

  • Open attached file
  • Click Image > Save As...
  • Change Color Space to Linear
  • Click Save As Image
    ColorSpaceBug.blend
**System Information** Operating system: Windows 10 Graphics card: RTX3700 **Blender Version** Broken: 3.3.0 Probably caused by 5baa3ecda6. Worked: 3.1.2 **Short description of error** When saving an image, we can change the color space in the save properties. When we do this, we can see that the `Color Space` for the image has been changed in the image properties, but the image itself has not changed within Blender. Similarly in Python, we can see that this value has been changed (`bpy.data.images- [x].colorspace_settings.name`) Afterwards, setting back the `Color Space` to 'sRGB' makes visual changes to the image and you are unable to get back the original image The exported file is different (darker), as if a Linear -> sRGB has been made instead of the requested opposite. Blender 3.1 does not have the option to change color space when saving the image but according to a few tests, the image is converted to sRGB before saving (ie if you have a linear encoding and save the file, the image is switched to sRGB and the exported file is the same as in blender) **Exact steps for others to reproduce the error** - Open attached file - Click Image > Save As... - Change `Color Space` to `Linear` - Click `Save As Image` [ColorSpaceBug.blend](https://archive.blender.org/developer/F13563323/ColorSpaceBug.blend)
Author

Added subscriber: @FlorentM

Added subscriber: @FlorentM
Florent Masson changed title from Image "Save As" and changing colorspace: colorspace is changed without change on the image to Image "Save As" and changing colorspace: invalid colorspace change 2022-09-24 18:15:00 +02:00
Author

As an additional comment (I don't know where it belongs), the behavior of python API Image.save() has a breaking change.
Before, the image was automatically converted to sRGB before saving and it's not the case anymore. So probably the function should have an optional parameter where the default behavior is backwards compatible.
(This was my initial issue as I have scripts for automatically baking AO on linear images and then saving them)

As an additional comment (I don't know where it belongs), the behavior of python API Image.save() has a breaking change. Before, the image was automatically converted to sRGB before saving and it's not the case anymore. So probably the function should have an optional parameter where the default behavior is backwards compatible. (This was my initial issue as I have scripts for automatically baking AO on linear images and then saving them)

Added subscriber: @mano-wii

Added subscriber: @mano-wii

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

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

Probably caused by 5baa3ecda6.

It looks like there is an unwanted color space conversion.

Not sure if it's a bug or intentional, but it looks like a bug at first glance.

Probably caused by 5baa3ecda6. It looks like there is an unwanted color space conversion. Not sure if it's a bug or intentional, but it looks like a bug at first glance.
Member

Added subscribers: @brecht, @PratikPB2123

Added subscribers: @brecht, @PratikPB2123

Changed status from 'Confirmed' to: 'Needs User Info'

Changed status from 'Confirmed' to: 'Needs User Info'

When saving an image, we can change the color space in the save properties.

When we do this, we can see that the Color Space for the image has been changed in the image properties, but the image itself has not changed within Blender.

This is by design. When setting a color space in the save dialog, it means the image will be saved in that colorspace in the file. It's not meant to change how the image looks, it's just specifying how the image is encoded in the file.

Afterwards, setting back the Color Space to 'sRGB' makes visual changes to the image and you are unable to get back the original image

This setting is the colorspace of the file on disk. So since it was saved as Linear, for Blender to read it back correctly the setting should specify the image on disk is in Linear color space.

As an additional comment (I don't know where it belongs), the behavior of python API Image.save() has a breaking change.
Before, the image was automatically converted to sRGB before saving and it's not the case anymore. So probably the function should have an optional parameter where the default behavior is backwards compatible.

I'm not exactly sure what this refers to, what the state of the image is before saving, but I believe it's an intentional change.

The image.save() method should now save the image in whatever colorspace was specified in the image settings, instead of ignoring it and guessing a colorspace.

> When saving an image, we can change the color space in the save properties. > > When we do this, we can see that the Color Space for the image has been changed in the image properties, but the image itself has not changed within Blender. This is by design. When setting a color space in the save dialog, it means the image will be saved in that colorspace in the file. It's not meant to change how the image looks, it's just specifying how the image is encoded in the file. > Afterwards, setting back the Color Space to 'sRGB' makes visual changes to the image and you are unable to get back the original image This setting is the colorspace of the file on disk. So since it was saved as Linear, for Blender to read it back correctly the setting should specify the image on disk is in Linear color space. > As an additional comment (I don't know where it belongs), the behavior of python API Image.save() has a breaking change. > Before, the image was automatically converted to sRGB before saving and it's not the case anymore. So probably the function should have an optional parameter where the default behavior is backwards compatible. I'm not exactly sure what this refers to, what the state of the image is before saving, but I believe it's an intentional change. The `image.save()` method should now save the image in whatever colorspace was specified in the image settings, instead of ignoring it and guessing a colorspace.
Author

This is by design. When setting a color space in the save dialog, it means the image will be saved in that colorspace in the file. It's not meant to change how the image looks, it's just specifying how the image is encoded in the file.

I get that, but the bug is that it DOES change the color space within blender when it shouldn't, try the use case
Before saving
image.png
After saving as 'linear'
image.png
Note the color space has changed in the image properties but the visual has not changed
When I switch it back to sRGB, the image is altered:
image.png

As an additional comment (I don't know where it belongs), the behavior of python API Image.save() has a breaking change.
Before, the image was automatically converted to sRGB before saving and it's not the case anymore. So probably the function should have an optional parameter where the default behavior is backwards compatible.

I'm not exactly sure what this refers to, what the state of the image is before saving, but I believe it's an intentional change.

The image.save() method should now save the image in whatever colorspace was specified in the image settings, instead of ignoring it and guessing a colorspace.

The use case is this: have an image in linear encoding. Use Image.save() as PNG. Before 3.3, the image was converted to sRGB before saving (I don't believe it was ignoring and guessing what it was). And the sRGB encoding stayed in blender. Now it's not converted and using the colorspace in the image settings.
I could not find anything related to the behavior change in blender 3.2 or 3.3 changelogs, either for "save as..." dialog or API function.
The previous API behavior (automatically changing image format to sRGB) was undocumented.
So it's just we had an undocumented behavior that has been changed in an uncommunicated change. It broke my scripts and I hope I'm the only one.

> This is by design. When setting a color space in the save dialog, it means the image will be saved in that colorspace in the file. It's not meant to change how the image looks, it's just specifying how the image is encoded in the file. I get that, but the bug is that it DOES change the color space within blender when it shouldn't, try the use case Before saving ![image.png](https://archive.blender.org/developer/F13579982/image.png) After saving as 'linear' ![image.png](https://archive.blender.org/developer/F13579992/image.png) Note the color space has changed in the image properties but the visual has not changed When I switch it back to sRGB, the image is altered: ![image.png](https://archive.blender.org/developer/F13579996/image.png) >> As an additional comment (I don't know where it belongs), the behavior of python API Image.save() has a breaking change. >> Before, the image was automatically converted to sRGB before saving and it's not the case anymore. So probably the function should have an optional parameter where the default behavior is backwards compatible. > > I'm not exactly sure what this refers to, what the state of the image is before saving, but I believe it's an intentional change. > > The `image.save()` method should now save the image in whatever colorspace was specified in the image settings, instead of ignoring it and guessing a colorspace. The use case is this: have an image in linear encoding. Use Image.save() as PNG. Before 3.3, the image was converted to sRGB before saving (I don't believe it was ignoring and guessing what it was). And the sRGB encoding stayed in blender. Now it's not converted and using the colorspace in the image settings. I could not find anything related to the behavior change in blender 3.2 or 3.3 changelogs, either for "save as..." dialog or API function. The previous API behavior (automatically changing image format to sRGB) was undocumented. So it's just we had an undocumented behavior that has been changed in an uncommunicated change. It broke my scripts and I hope I'm the only one.

In #101331#1423330, @FlorentM wrote:
Note the color space has changed in the image properties but the visual has not changed

That is the intent. You saved the file in a different color space, so now the colorspace setting is changed to match the colorspace of the file.

When I switch it back to sRGB, the image is altered:

The file is not in sRGB colorspace, so indicating that it is will indeed give the wrong result.

> In #101331#1423330, @FlorentM wrote: > Note the color space has changed in the image properties but the visual has not changed That is the intent. You saved the file in a different color space, so now the colorspace setting is changed to match the colorspace of the file. > When I switch it back to sRGB, the image is altered: The file is not in sRGB colorspace, so indicating that it is will indeed give the wrong result.
Author

Mmmm I'm still puzzled by the behavior change. If you start from a linear image, you do get different results
ColorSpaceBug2.blend

3.3: "Save as " changing to sRGB in the save dialog
image.png

vs

3.1: "Save as" - no select box, automatically changes to sRGB
image.png

Well, maybe I do not understand well the meaning of this "Color Space" attribute in the image properties
image.png
Changing color space does not actually alters the image data buffer, and only the conversion that is applied when it's displayed?

And so, according to https://developer.blender.org/T74610, the behavior in 3.1 was actually a long-standing bug that has been fixed?

Mmmm I'm still puzzled by the behavior change. If you start from a linear image, you do get different results [ColorSpaceBug2.blend](https://archive.blender.org/developer/F13581621/ColorSpaceBug2.blend) 3.3: "Save as " changing to sRGB in the save dialog ![image.png](https://archive.blender.org/developer/F13581626/image.png) vs 3.1: "Save as" - no select box, automatically changes to sRGB ![image.png](https://archive.blender.org/developer/F13581631/image.png) Well, maybe I do not understand well the meaning of this "Color Space" attribute in the image properties ![image.png](https://archive.blender.org/developer/F13581616/image.png) Changing color space does not actually alters the image data buffer, and only the conversion that is applied when it's displayed? And so, according to https://developer.blender.org/T74610, the behavior in 3.1 was actually a long-standing bug that has been fixed?

I think I understood what Brencht explained and it no longer seems like a bug to me.
Let's consider an image using the sRGB color space as an example.
If you save this image as being in Linear space, it takes the entire sRGB color transform and converts it to Linear.
Thus, its Linear becomes what it used to be sRGB (the interface changes to Linear for convenience).
If you change the space before Linear to sRGB, you are transforming the color of what is already transformed. It's like applying sRGB twice.

I may have misunderstood however.

On the other question raised (image.save()) I suggest doing another report.

In the submission template and guidelines, it is informed:
If there are multiple bugs, make multiple bug reports.

I think I understood what Brencht explained and it no longer seems like a bug to me. Let's consider an image using the `sRGB` color space as an example. If you save this image as being in `Linear` space, it takes the entire `sRGB` color transform and converts it to `Linear`. Thus, its `Linear` becomes what it used to be `sRGB` (the interface changes to `Linear` for convenience). If you change the space before `Linear` to `sRGB`, you are transforming the color of what is already transformed. It's like applying `sRGB` twice. I may have misunderstood however. On the other question raised (`image.save()`) I suggest doing another report. > **In the [submission template and guidelines](https://developer.blender.org/maniphest/task/edit/form/1/), it is informed:** > If there are multiple bugs, make multiple bug reports.

Changed status from 'Needs User Info' to: 'Archived'

Changed status from 'Needs User Info' to: 'Archived'

And so, according to https://developer.blender.org/T74610, the behavior in 3.1 was actually a long-standing bug that has been fixed?

Yes. Saving an image in a different colorspace in the file should not change it visually, that was a bug.

Changing color space does not actually alters the image data buffer, and only the conversion that is applied when it's displayed?

The way to understand it is that Blender works in scene linear color space, and the colorspace settings are about converting to and from that for file I/O and display.
https://docs.blender.org/manual/en/dev/render/color_management.html

There are some caveats in the implementation, in practice conversion may be delayed or cancel out for performance/memory/precision reasons. But the meaning and visual display of the color in Blender remains the same, regardless of the color space, bit depth or compression used in the file on disk.

> And so, according to https://developer.blender.org/T74610, the behavior in 3.1 was actually a long-standing bug that has been fixed? Yes. Saving an image in a different colorspace in the file should not change it visually, that was a bug. > Changing color space does not actually alters the image data buffer, and only the conversion that is applied when it's displayed? The way to understand it is that Blender works in scene linear color space, and the colorspace settings are about converting to and from that for file I/O and display. https://docs.blender.org/manual/en/dev/render/color_management.html There are some caveats in the implementation, in practice conversion may be delayed or cancel out for performance/memory/precision reasons. But the meaning and visual display of the color in Blender remains the same, regardless of the color space, bit depth or compression used in the file on disk.

The Python API change is not a bug either, but should been better documented in the release notes.

The Python API change is not a bug either, but should been better documented in the release notes.
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#101331
No description provided.