Add an optional "frame" & "tile_index" argument to Image.scale() #117549

Merged
Philipp Oeser merged 4 commits from lichtwerk/blender:117539 into main 2024-02-01 17:28:48 +01:00
Member

BKE_image_scale -- which is only used for the python API -- was
getting the ImBuf without providing an ImageUser.
This is fine, but always gets the first tile (and the current frame for sequences).

To resolve this, add an optional "frame" & "tile_index" argument so these can be specified explicitly (similar to layer_index and pass_index already used for some other API functions).

Fixes #117539 : Image.scale() always works on the first tile

`BKE_image_scale` -- which is only used for the python API -- was getting the `ImBuf` without providing an `ImageUser`. This is fine, but always gets the first tile (and the current frame for sequences). To resolve this, add an optional "frame" & "tile_index" argument so these can be specified explicitly (similar to layer_index and pass_index already used for some other API functions). Fixes #117539 : Image.scale() always works on the first tile
Philipp Oeser added 1 commit 2024-01-26 16:09:33 +01:00
`BKE_image_scale` -- which is only used for the python API -- was
getting the `ImBuf` without providing an `ImageUser`.
This is fine, but always gets the first tile.

In order to respect `Image.tiles.active_index` for the scaling
operation, we can create a default `ImageUser` and set its `tile`.

Afaict, no other members of the `ImageUser` need to be set for tiled
images, so should be no other functional changes (compared to passing a
nullptr).
Philipp Oeser added the
Interest
Images & Movies
Interest
Python API
labels 2024-01-26 16:09:54 +01:00
Philipp Oeser added this to the Python API project 2024-01-26 16:10:32 +01:00
Philipp Oeser requested review from Sergey Sharybin 2024-01-26 16:37:21 +01:00
Brecht Van Lommel requested changes 2024-01-26 16:41:48 +01:00
Brecht Van Lommel left a comment
Owner

API functions like this should not rely on what is active or selected, that's the main way in which they different from operators.

This whole image API suffers from not properly exposing the individual image buffers well. The easiest thing to do with the current API would be to add an optional tile_index argument, similar to layer_index and pass_index already used for some other API functions.

API functions like this should not rely on what is active or selected, that's the main way in which they different from operators. This whole image API suffers from not properly exposing the individual image buffers well. The easiest thing to do with the current API would be to add an optional `tile_index` argument, similar to `layer_index` and `pass_index` already used for some other API functions.
Philipp Oeser changed title from Fix #117539: Image.scale() always works on the first tile to WIP: Fix #117539: Image.scale() always works on the first tile 2024-01-26 16:43:28 +01:00
Philipp Oeser added 2 commits 2024-01-30 15:01:05 +01:00
do this instead of relying on an active tile from the API.

NOTE: also added "frame" argument here (since it it a nice way to scale
whole sequences from within blender)
Philipp Oeser changed title from WIP: Fix #117539: Image.scale() always works on the first tile to Add an optional "frame" & "tile_index" argument to Image.scale() 2024-01-30 15:02:19 +01:00
Philipp Oeser requested review from Brecht Van Lommel 2024-01-30 15:06:22 +01:00
Brecht Van Lommel requested changes 2024-01-30 15:29:12 +01:00
@ -184,1 +186,3 @@
if (!BKE_image_scale(image, width, height)) {
ImageUser iuser{};
BKE_imageuser_default(&iuser);
bool use_imageuser = false;

Just always use the image user.

Just always use the image user.
lichtwerk marked this conversation as resolved
@ -185,0 +208,4 @@
/* Not exactly sure if we should check this beforehand? */
char filepath[FILE_MAX];
BKE_image_user_file_path(&iuser, image, filepath);
if (BLI_open(filepath, O_BINARY | O_RDONLY, 0) == -1) {

This leaks a file handle.

This leaks a file handle.
lichtwerk marked this conversation as resolved
@ -185,0 +218,4 @@
}
use_imageuser = true;
}

I don't think it has to be checking if the tile and frame are valid. It requires the logic here and the one in acquiring the image buffer to match, and that's difficult to verify and maintain.

I would just check the return value of BKE_image_scale, and tweak the error message to be something like "Failed to load image buffer".

I don't think it has to be checking if the tile and frame are valid. It requires the logic here and the one in acquiring the image buffer to match, and that's difficult to verify and maintain. I would just check the return value of `BKE_image_scale`, and tweak the error message to be something like "Failed to load image buffer".
lichtwerk marked this conversation as resolved
Philipp Oeser added 1 commit 2024-01-31 12:45:40 +01:00
remove check if the tile and frame are valid
Some checks failed
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
af5ecfc250
Philipp Oeser requested review from Brecht Van Lommel 2024-01-31 12:47:01 +01:00
Brecht Van Lommel approved these changes 2024-02-01 14:39:56 +01:00
Author
Member

@blender-bot build

@blender-bot build
Author
Member

test failed to an unrelated issue (from the time the PR was made)

test failed to an unrelated issue (from the time the PR was made)
Philipp Oeser merged commit 3d60209d3d into main 2024-02-01 17:28:48 +01:00
Philipp Oeser deleted branch 117539 2024-02-01 17:28:51 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
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
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#117549
No description provided.