Python API for Blender's internal image functions #54272

Open
opened 2018-03-08 14:46:00 +01:00 by Campbell Barton · 22 comments

Note, this is a summary of the discussion with @Sergey on IRC after it was requested that pillow be included with Blender. While I don't intend to work on this near term, I'm happy to help someone else take on this task - @ideasman42 .


(NOTE) Update: A very basic image API has been committed to master & 2.8 branch 409cfba1a3, this was done so we can more easily accept incremental improvements.

There are cases where it's useful to manipulate image data in Python, outside of Blender's image data-blocks (which are user data that's saved to file).

The Python module 'pillow' is a capable module, however we would prefer to expose Blender's internal image operations, instead of bundling pillow with Blender.

Reasons include:

  • 100% compatibility with Blender's file formats, so all files that load in Blender load through Python (including details like compression methods, meta-data and particular color-management settings).
  • Bundling pillow adds more burden for platform maintainers, also increases download size.
  • Image support can be buggy (security CVE's, bugs in one image loader not in another).
  • Using Blender's image support means any improvements here will benefit Blender too.
  • Potential for better integration with the rest of Blender (so passing images from Python can be used in Blender as-is).

We could initially support a basic API:

    • load/save (done)
    • rotate
    • scale
    • crop
    • simple color operations (brightness contrast)
    • direct pixel access using Python buffers.

Once basic support is working well we might consider:

  • more advanced effects (perhaps de-duplicate with the sequencer effects/modifiers).
  • color management access & conversion.
  • text drawing (using the blf API, which already works in C, use for text in the sequencer).
  • blitting content between images.

... others cold be added, these are just suggestions.

Note that additions to this API would mean some refactoring & improvements to ImBuf since the Python API would be a thin wrapper on ImBuf operations.

*Note, this is a summary of the discussion with @Sergey on IRC after it was requested that pillow be included with Blender. While I don't intend to work on this near term, I'm happy to help someone else take on this task - @ideasman42 .* --- (NOTE) Update: A very basic image API has been committed to master & 2.8 branch 409cfba1a3, this was done so we can more easily accept incremental improvements. There are cases where it's useful to manipulate image data in Python, outside of Blender's image data-blocks (which are user data that's saved to file). The Python module ['pillow' ](https://python-pillow.org) is a capable module, however we would prefer to expose Blender's internal image operations, instead of bundling pillow with Blender. Reasons include: - 100% compatibility with Blender's file formats, so all files that load in Blender load through Python (including details like compression methods, meta-data and particular color-management settings). - Bundling pillow adds more burden for platform maintainers, also increases download size. - Image support can be buggy (security CVE's, bugs in one image loader not in another). - Using Blender's image support means any improvements here will benefit Blender too. - Potential for better integration with the rest of Blender *(so passing images from Python can be used in Blender as-is)*. We could initially support a basic API: - - [x] load/save (done) - - [ ] rotate - - [x] scale - - [x] crop - - [ ] simple color operations (brightness contrast) - - [ ] direct pixel access using Python buffers. Once basic support is working well we might consider: - more advanced effects (perhaps de-duplicate with the sequencer effects/modifiers). - color management access & conversion. - text drawing (using the `blf` API, which already works in C, use for text in the sequencer). - blitting content between images. ... others cold be added, these are just suggestions. Note that additions to this API would mean some refactoring & improvements to `ImBuf` since the Python API would be a thin wrapper on `ImBuf` operations.
Campbell Barton self-assigned this 2018-03-08 14:46:00 +01:00
Author
Owner

Added subscribers: @Sergey, @ideasman42

Added subscribers: @Sergey, @ideasman42

Added subscriber: @Scaredyfish

Added subscriber: @Scaredyfish
Member

Added subscriber: @JohnRoper

Added subscriber: @JohnRoper

Added subscriber: @dr.sybren

Added subscriber: @dr.sybren

Added subscriber: @PathanAmrullaKhan

Added subscriber: @PathanAmrullaKhan

I would like to be part of this. Though I can not work full time as I have another full-time job.

I would like to be part of this. Though I can not work full time as I have another full-time job.

Added subscriber: @idlecode

Added subscriber: @idlecode
Campbell Barton was unassigned by Kilon Alios 2018-06-07 02:06:57 +02:00
Member

Added subscriber: @DimitrisChloupis

Added subscriber: @DimitrisChloupis
Author
Owner

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Campbell Barton self-assigned this 2018-06-07 08:06:22 +02:00
Author
Owner

Committed to master, closing.

Committed to master, closing.

Added subscriber: @RayMairlot

Added subscriber: @RayMairlot
Author
Owner

Correction, the API was only committed at a very basic level, so keep this open.

Correction, the API was only committed at a very basic level, so keep this open.
Author
Owner

Changed status from 'Resolved' to: 'Open'

Changed status from 'Resolved' to: 'Open'

Added subscriber: @vitorbalbio-3

Added subscriber: @vitorbalbio-3
Member

Added subscriber: @cmbasnett

Added subscriber: @cmbasnett
Member

This comment was removed by @cmbasnett

*This comment was removed by @cmbasnett*

Added subscriber: @ivpe

Added subscriber: @ivpe

Added subscriber: @slumber

Added subscriber: @slumber

Added subscriber: @Andrey_Sokolov

Added subscriber: @Andrey_Sokolov

Added subscriber: @Andrew_D-1

Added subscriber: @Andrew_D-1

Added subscriber: @MACHIN3

Added subscriber: @MACHIN3

Added subscriber: @thanhph111

Added subscriber: @thanhph111
Philipp Oeser removed the
Interest
Python API
label 2023-02-10 09:04:53 +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
16 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#54272
No description provided.