Image: Add OIIO support APIs #105519

Merged
Jesse Yurkovich merged 7 commits from deadpin/blender:oiio-support into main 2023-03-14 04:42:29 +01:00

This adds a new set of APIs supporting the loading and saving of image
formats through OIIO. It makes use of the recent IOProxy work in OIIO
to align with the existing Blender image loading/saving machinery.

The support code here has been prototyped to work with ~7 of our image
formats so far[1]. It includes centralized handling of IB_test,
IB_mem, and IB_metadata flags, which the existing code did not
handle consistently or at all depending on the format.[2]

The PSD format (format_psd.cc) is included here since the prior
location of the code has been restructured away. It serves as an example
of how the loading code typically flows for all the other formats.[3]


This continues the work for #101413

[1] The BMP,DDS,HDR,PNG,TIFF,and TARGA formats will be sent for review after this
[2] There is a small change in OpenEXR that is a result of the better metadata handling. If a loaded image has its "compression" metadata set, and the user then re-saves the image as OpenEXR, the API call to add this piece of metadata to the OpenEXR stream will fail. We simply do not transfer this attribute now; it's already been set for the image anyhow.
[3] Incidentally this will address #70495 for "free"

This adds a new set of APIs supporting the loading and saving of image formats through OIIO. It makes use of the recent IOProxy work in OIIO to align with the existing Blender image loading/saving machinery. The support code here has been prototyped to work with ~7 of our image formats so far[1]. It includes centralized handling of `IB_test`, `IB_mem`, and `IB_metadata` flags, which the existing code did not handle consistently or at all depending on the format.[2] The PSD format (`format_psd.cc`) is included here since the prior location of the code has been restructured away. It serves as an example of how the loading code typically flows for all the other formats.[3] ---- This continues the work for #101413 [1] The BMP,DDS,HDR,PNG,TIFF,and TARGA formats will be sent for review after this [2] There is a small change in OpenEXR that is a result of the better metadata handling. If a loaded image has its "compression" metadata set, and the user then re-saves the image as OpenEXR, the API call to add this piece of metadata to the OpenEXR stream will fail. We simply do not transfer this attribute now; it's already been set for the image anyhow. [3] Incidentally this will address #70495 for "free"
Jesse Yurkovich added 1 commit 2023-03-07 04:23:29 +01:00
ab7c93e629 Image: Add OIIO support APIs
This adds a new set of APIs supporting the loading and saving of image
formats through OIIO. It makes use of the recent IOProxy work in OIIO
to align with the existing Blender image loading/saving machinery.

The support code here has been prototyped to work with ~7 of our image
formats so far[1]. It includes centralized handling of `IB_test`,
`IB_mem`, and `IB_metadata` flags, which the existing code did not
handle consistently or at all depending on the format.

The PSD format (`format_psd.cc`) is included here since the prior
location of the code has been restructured away. It serves as an example
of how the loading code typically flows for all the other formats.[2]

----
This continues the work for #101413

[1] The BMP,DDS,HDR,PNG,TIFF,and TARGA formats will be sent for review after this
[2] Incidentally this will address #70495 for "free"
Jesse Yurkovich added this to the Core project 2023-03-07 10:48:25 +01:00
Brecht Van Lommel requested review from Brecht Van Lommel 2023-03-10 13:27:22 +01:00
Brecht Van Lommel requested changes 2023-03-11 01:32:36 +01:00
@ -0,0 +37,4 @@
size_t pwrite(const void *buf, size_t size, int64_t offset) override
{
std::lock_guard<std::mutex> lock(mutex_);

A mutex lock here seems risky for performance, do we know that it only writes in large chunks and the overhead is not too bad?

A mutex lock here seems risky for performance, do we know that it only writes in large chunks and the overhead is not too bad?
deadpin marked this conversation as resolved
@ -0,0 +42,4 @@
/* If buffer is too small increase it. */
size_t end = offset + size;
while (end > ibuf_->encodedbuffersize) {
imb_enlargeencodedbufferImBuf(ibuf_);

I'm not sure this is working correctly. imb_enlargeencodedbufferImBuf seems to assume that the data to memcpy as the buffer is enlarged is encodedsize bytes from the start of the buffer. But this looks like it can write anywhere in the full buffer?

I'm not sure this is working correctly. `imb_enlargeencodedbufferImBuf` seems to assume that the data to memcpy as the buffer is enlarged is `encodedsize` bytes from the start of the buffer. But this looks like it can write anywhere in the full buffer?
brecht marked this conversation as resolved
@ -0,0 +220,4 @@
ibuf->flags |= (spec.extra_attribs.empty()) ? 0 : IB_metadata;
for (const auto &attrib : spec.extra_attribs) {
IMB_metadata_set_field(ibuf->metadata, attrib.name().c_str(), attrib.get_string().c_str());

I'm a bit unsure about the performance implications of this. I vaguely remember some file formats having really big metadata, which may not be efficient to convert to a string.

Though I'm not really sure now where I saw that, maybe it's fine to ignore for now.

I'm a bit unsure about the performance implications of this. I vaguely remember some file formats having really big metadata, which may not be efficient to convert to a string. Though I'm not really sure now where I saw that, maybe it's fine to ignore for now.
brecht marked this conversation as resolved
@ -0,0 +10,4 @@
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
using uchar = unsigned char;

Use BLI_sys_types.h instead., otherwise might conflict if both are included.

Use `BLI_sys_types.h` instead., otherwise might conflict if both are included.
deadpin marked this conversation as resolved
@ -0,0 +15,4 @@
/**
* Parameters and settings used while reading image formats.
*/
struct ReadContext {

These structs should have either a prefix or be in a namespace, the names are too generic.

These structs should have either a prefix or be in a namespace, the names are too generic.
deadpin marked this conversation as resolved
@ -68,9 +68,6 @@ const char *imb_ext_image[] = {
};
const char *imb_ext_image_filepath_only[] = {

I guess this variable can be removed entirely now.

I guess this variable can be removed entirely now.
deadpin marked this conversation as resolved
Jesse Yurkovich added 5 commits 2023-03-13 01:23:46 +01:00
Jesse Yurkovich reviewed 2023-03-13 01:28:49 +01:00
@ -0,0 +37,4 @@
return size;
}
size_t pwrite(const void *buf, size_t size, int64_t offset) override
Author
Member

I clarified with Larry over at OIIO and we can drop the mutex. I was using their internal IOProxies as an example of how to build ours but it turns out we'd only need the mutex if our code was calling pwrite concurrently with OIIO. Performance was within noise for me, as the lock is uncontended in our case, but it can be removed entirely.

I clarified with Larry over at OIIO and we can drop the mutex. I was using their internal IOProxies as an example of how to build ours but it turns out we'd only need the mutex if our code was calling `pwrite` concurrently with OIIO. Performance was within noise for me, as the lock is uncontended in our case, but it can be removed entirely.
brecht marked this conversation as resolved
@ -0,0 +42,4 @@
/* If buffer is too small increase it. */
size_t end = offset + size;
while (end > ibuf_->encodedbuffersize) {
if (!imb_enlargeencodedbufferImBuf(ibuf_)) {
Author
Member

Good eye. It happened to work because of how OIIO calls into this (effectively in order) but a general caller of pwrite would indeed be problematic. Should be fixed now.

Good eye. It happened to work because of how OIIO calls into this (effectively in order) but a general caller of pwrite would indeed be problematic. Should be fixed now.
brecht marked this conversation as resolved
Brecht Van Lommel approved these changes 2023-03-13 11:10:58 +01:00

@blender-bot build

@blender-bot build
Jesse Yurkovich added 1 commit 2023-03-13 23:58:30 +01:00
Author
Member

@blender-bot build

@blender-bot build
Jesse Yurkovich merged commit 8929ed75d4 into main 2023-03-14 04:42:29 +01:00
Jesse Yurkovich deleted branch oiio-support 2023-03-14 04:42:30 +01:00
Bastien Montagne removed this from the Core project 2023-07-03 12:48:04 +02:00
Sign in to join this conversation.
No reviewers
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
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#105519
No description provided.