Regression: image.save_render() command changes color profile and file type when saving. #98444

Closed
opened 2022-05-27 15:31:11 +02:00 by Eugenio Pignataro · 27 comments

Ubuntu 22.04
Nvidia 1070 Ti

Broken: version: 3.3.0 Alpha May 18 89ccff62d2
Worked: 3.2 May 2 5188c14718

When you save a newly baked float Normal Image with Linear profile using the bpy.data.images["Untitled"].save_render("/path/to/save/file.exr") command, blender saves it as a 16 bit PNG with sRGB values and a .exr extension.

Previously it would save the image buffer as a linear OpenEXR Image file.

Steps:
1 -Bake a float normal map in memory in Linear color profile
2 - Save the picture with save_render python command.
3 - open the .exr in image editor.
4 - You will see the color profile loaded as sRGB.
5 - Various other programs won't open it because it is actually a 16 bit PNG file with the wrong extension.

blendFile: test.blend

Working video 3.2: https://www.dropbox.com/s/e4mat4i77ix6i7q/2022-05-27%2010-18-27.mp4?dl=0
Non Working video 3.3: https://www.dropbox.com/s/35x24pobe6plafp/2022-05-27%2010-21-14.mp4?dl=0

Same procedure, different result.

Ubuntu 22.04 Nvidia 1070 Ti Broken: version: 3.3.0 Alpha May 18 89ccff62d2df Worked: 3.2 May 2 5188c14718c5 When you save a newly baked float Normal Image with Linear profile using the `bpy.data.images["Untitled"].save_render("/path/to/save/file.exr")` command, blender saves it as a 16 bit PNG with sRGB values and a `.exr` extension. Previously it would save the image buffer as a linear OpenEXR Image file. Steps: 1 -Bake a float normal map in memory in Linear color profile 2 - Save the picture with save_render python command. 3 - open the `.exr` in image editor. 4 - You will see the color profile loaded as sRGB. 5 - Various other programs won't open it because it is actually a 16 bit PNG file with the wrong extension. blendFile: [test.blend](https://archive.blender.org/developer/F13114799/test.blend) Working video 3.2: https://www.dropbox.com/s/e4mat4i77ix6i7q/2022-05-27%2010-18-27.mp4?dl=0 Non Working video 3.3: https://www.dropbox.com/s/35x24pobe6plafp/2022-05-27%2010-21-14.mp4?dl=0 Same procedure, different result.
Author
Member

Added subscriber: @EugenioPignataro

Added subscriber: @EugenioPignataro
Member

Added subscriber: @OmarEmaraDev

Added subscriber: @OmarEmaraDev
Member

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

Changed status from 'Needs Triage' to: 'Needs User Info'
Member

Does EXR images store color profiles at all? As far as I know, EXR files can't store the color space, so this is most likely Blender assuming a color space upon reading the image back.
It loads as linear for me regardless. Does this happen with the default OCIO config and factory settings?

Does EXR images store color profiles at all? As far as I know, EXR files can't store the color space, so this is most likely Blender assuming a color space upon reading the image back. It loads as linear for me regardless. Does this happen with the default OCIO config and factory settings?
Author
Member

Hi Omar! In the previous versions this worked fine.

Blender saves pixel information baked as sRGB.
image.png

If I set the image loaded as Linear (normal map):
image.png

Hi Omar! In the previous versions this worked fine. Blender saves pixel information baked as sRGB. ![image.png](https://archive.blender.org/developer/F13114775/image.png) If I set the image loaded as Linear (normal map): ![image.png](https://archive.blender.org/developer/F13114778/image.png)
Author
Member

I've tried with default OCIO, same problem.

I made a new video:

https://www.dropbox.com/s/xnrbfgnproc5tko/2022-05-27%2011-18-33.mp4?dl=0

blendFile: test.blend

I've tried with default OCIO, same problem. I made a new video: https://www.dropbox.com/s/xnrbfgnproc5tko/2022-05-27%2011-18-33.mp4?dl=0 blendFile: [test.blend](https://archive.blender.org/developer/F13114799/test.blend)
Author
Member

This is an older .exr in the newest blender version.
it's working fine.
I believe that the problem is in the save step.

image.png

This is an older .exr in the newest blender version. it's working fine. I believe that the problem is in the save step. ![image.png](https://archive.blender.org/developer/F13114803/image.png)
Member

In 3.2 in your video, it seems to be loaded as sRGB OETF, not linear, which is contrary to what you want, right?
It loads as sRGB in both versions for me. My point was that EXR files don't actually store any color space information, so Blender make make the decision based on something else.

In 3.2 in your video, it seems to be loaded as `sRGB OETF`, not linear, which is contrary to what you want, right? It loads as sRGB in both versions for me. My point was that EXR files don't actually store any color space information, so Blender make make the decision based on something else.
Author
Member

Hi Omar, we are testing the last blender build with my partner.

We are close to find the problem.

The last version it seems to be using color management options for saving the file.

The previous versions doesn't force the use of the CM options to save the images with "save_render()"

The usual way to load an EXR Normal Map is in Linear, and the undistorted base value is .5 .5 1

Hi Omar, we are testing the last blender build with my partner. We are close to find the problem. The last version it seems to be using color management options for saving the file. The previous versions doesn't force the use of the CM options to save the images with "save_render()" The usual way to load an EXR Normal Map is in Linear, and the undistorted base value is .5 .5 1
Member

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

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

Added subscriber: @NahuelBelich

Added subscriber: @NahuelBelich

I have the blender defaults color management and notice the same behaviuor with the test file provided in the comments(following the steps).
With the blender default i can reproduce the problem, its using the Color management options instead of saving linear. This may or not be a big issue but something to consider, however we also notice a second big (huge) issue that could be related to this, saving exr files using the console can no longer be opened with Krita, it returns an error
(QString::arg: Argument missing: Loading canceled. Error:)
nor can be opened in djview imagin 2.0.6
image.png

Working properly build:
hash: 56d1d19c88
commit date: 2022-04-20 14:55

oldest failing build i have
hash: 89ccff62d2
commit date: 2022-05-18 21:09

I have the blender defaults color management and notice the same behaviuor with the test file provided in the comments(following the steps). With the blender default i can reproduce the problem, its using the Color management options instead of saving linear. This may or not be a big issue but something to consider, however we also notice a second big (huge) issue that could be related to this, saving exr files using the console can no longer be opened with Krita, it returns an error (QString::arg: Argument missing: Loading canceled. Error:) nor can be opened in djview imagin 2.0.6 ![image.png](https://archive.blender.org/developer/F13115163/image.png) Working properly build: hash: 56d1d19c88e0 commit date: 2022-04-20 14:55 oldest failing build i have hash: 89ccff62d2df commit date: 2022-05-18 21:09
Member

Added subscriber: @EAW

Added subscriber: @EAW
Member

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

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

I can confirm.

Sorry my bad english and thanks a bunch!

@EugenioPignataro your English is perfectly understandable. 😀

saving exr files using the console can no longer be opened with Krita, it returns an error
nor can be opened in djview imagin 2.0.6

@NahuelBelich It turns out that Blender is saving them as 16bit PNG files with the .exr extension.

Ifranview 4.58 gives the error message of

Warning!
The File: "C:\home\tomate\defaultOCIO.exr" is a PNG file with incorrect extension.
Rename?

Examining the file in a HEX editor confirms that it is a PNG file. Changing the extension allows the file to be opened normally.

I'll update the report.

I won't be able to bisect until tommorow.

I can confirm. >Sorry my bad english and thanks a bunch! @EugenioPignataro your English is perfectly understandable. 😀 >saving exr files using the console can no longer be opened with Krita, it returns an error >nor can be opened in djview imagin 2.0.6 @NahuelBelich It turns out that Blender is saving them as 16bit PNG files with the .exr extension. Ifranview 4.58 gives the error message of >Warning! >The File: "C:\home\tomate\defaultOCIO.exr" is a PNG file with incorrect extension. >Rename? Examining the file in a HEX editor confirms that it is a PNG file. Changing the extension allows the file to be opened normally. I'll update the report. I won't be able to bisect until tommorow.
Evan Wilson changed title from Error image.save_render() command color profile. to Regression: image.save_render() command changes color profile and file type when saving. 2022-05-28 08:02:00 +02:00
Author
Member

Ohh thanks Evan! thanks Omar.
We are working on a PBR Baker Addon, so... save_render command is very important for us.

thank you very much again!

Ohh thanks Evan! thanks Omar. We are working on a PBR Baker Addon, so... save_render command is very important for us. thank you very much again!

Added subscribers: @brecht, @mont29

Added subscribers: @brecht, @mont29

@brecht this one might be for you I think? Thanks.

@brecht this one might be for you I think? Thanks.

I'll restore the old behavior.

Note that technically normal maps should be set to Non-Color instead of Linear. With the default OpenColorIO config you might not notice the difference, but in general it will not work correctly.

I'll restore the old behavior. Note that technically normal maps should be set to Non-Color instead of Linear. With the default OpenColorIO config you might not notice the difference, but in general it will not work correctly.

This issue was referenced by fc1ae52994

This issue was referenced by fc1ae52994016fc4d43053caa412212726f7e223

Changed status from 'Confirmed' to: 'Archived'

Changed status from 'Confirmed' to: 'Archived'

Actually, looking closer I don't think this is a bug.

Blender 3.1.2, 3.2 and 3.3 are all saving a PNG file with EXR extension. It uses the settings in the Output panel, the extension in the file path is not what determines the file type.

The difference is in this bugfix from 5baa3ec.

* Fix missing color space conversion for 16 bit PNGs, where it assumed wrongly
  assumed ibuf->rect would be used for saving. Add BKE_image_format_is_byte to
  more accurately test this.

That is, 16 bit PNG would save renders without color space conversion (i.e. Linear), while 8 bit PNG would do the proper color space conversion. However both should work the same way, PNG files have a 0..1 range and can't store linear HDR colors, regardless if it's 8 bit or 16 bit.

If you want to save a non-color image through the render pipeline, you need to either:

  • Change the output file type to EXR
  • Set the view transform to Raw for other file types
Actually, looking closer I don't think this is a bug. Blender 3.1.2, 3.2 and 3.3 are all saving a PNG file with EXR extension. It uses the settings in the Output panel, the extension in the file path is not what determines the file type. The difference is in this bugfix from 5baa3ec. > * Fix missing color space conversion for 16 bit PNGs, where it assumed wrongly > assumed ibuf->rect would be used for saving. Add BKE_image_format_is_byte to > more accurately test this. That is, 16 bit PNG would save renders without color space conversion (i.e. Linear), while 8 bit PNG would do the proper color space conversion. However both should work the same way, PNG files have a 0..1 range and can't store linear HDR colors, regardless if it's 8 bit or 16 bit. If you want to save a non-color image through the render pipeline, you need to either: * Change the output file type to EXR * Set the view transform to Raw for other file types
Author
Member

Hi Bretch, thanks for your help.

I'm following your instructions:

Output
image.png

CM
image.png

Run command:
bpy.data.images['Untitled'].save_render("/home/tomate/test.exr")

Djv error:
image.png

What am I doing wrong?

If I save the picture from uv/imageEditor space everything works fine!

Save as:
Screenshot from 2022-05-30 10-56-30.png

Djv works fine:
image.png

And blender recognizes the color profile.
Screenshot from 2022-05-30 10-57-41.png

I tried everything, but I can't get a good result.

Thanks a bunch.

Hi Bretch, thanks for your help. I'm following your instructions: Output ![image.png](https://archive.blender.org/developer/F13123106/image.png) CM ![image.png](https://archive.blender.org/developer/F13123115/image.png) Run command: bpy.data.images['Untitled'].save_render("/home/tomate/test.exr") Djv error: ![image.png](https://archive.blender.org/developer/F13123119/image.png) What am I doing wrong? If I save the picture from uv/imageEditor space everything works fine! Save as: ![Screenshot from 2022-05-30 10-56-30.png](https://archive.blender.org/developer/F13123131/Screenshot_from_2022-05-30_10-56-30.png) Djv works fine: ![image.png](https://archive.blender.org/developer/F13123137/image.png) And blender recognizes the color profile. ![Screenshot from 2022-05-30 10-57-41.png](https://archive.blender.org/developer/F13123140/Screenshot_from_2022-05-30_10-57-41.png) I tried everything, but I can't get a good result. Thanks a bunch.

Ok, it seems there is a bug where this output setting is ignored. It was confusing because the example blend had this set to PNG while presumably your real test case had it set to EXR.

Ok, it seems there is a bug where this output setting is ignored. It was confusing because the example blend had this set to PNG while presumably your real test case had it set to EXR.

Changed status from 'Archived' to: 'Resolved'

Changed status from 'Archived' to: 'Resolved'
Author
Member

Now blender works fine!

Thanks Brecht!

Now blender works fine! Thanks Brecht!

This issue was referenced by None@62938

This issue was referenced by None@62938
Thomas Dinges added this to the 3.2 milestone 2023-02-08 15:51:07 +01:00
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
7 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#98444
No description provided.