UI: SVG Thumbnails #109567

Merged
Harley Acheson merged 11 commits from Harley/blender:SvgThumbs into main 2023-07-12 22:39:30 +02:00
Member

Allow SVG files to have previews in the File Browser. Adds
nanosvgrast.h to extern\nanosvg, which is an SVG rasterizer that is
an optional part of the nanosvg source.


image

This no longer adds the ability to load an SVG files into the Image Editor, it only allows thumbnailing of this file type.

Related RCS suggestion: https://blender.community/c/rightclickselect/2WBW/

Allow SVG files to have previews in the File Browser. Adds nanosvgrast.h to extern\nanosvg\, which is an SVG rasterizer that is an optional part of the nanosvg source. --- ![image](/attachments/b851269f-1696-458b-a0ab-fb7ecc1fe4e0) This no longer adds the ability to load an SVG files into the Image Editor, it only allows thumbnailing of this file type. Related RCS suggestion: https://blender.community/c/rightclickselect/2WBW/
Harley Acheson added 1 commit 2023-06-30 19:45:45 +02:00
928f552796 WIP: SVG Thumbnails
Allow SVG files to have previews in the File Browser. Adds
nanosvgrast.h to extern\nanosvg, which is an SVG rasterizer that is an
optional part of the nanosvg source.
Harley Acheson added this to the User Interface project 2023-06-30 19:46:11 +02:00
Author
Member

Tested with 201 samples from w3.org; worked well and fast. Some examples of the preview samples created from them (the resulting PNG files).

0a8a3c2151dc065e34934e4609895b1c

30db24de9fd41eafca28c8c16ccf4095

501d5de30c4ea5278c6b69429df15572

960c96225012d8c42da56ab060ce0892

Tested with 201 samples from w3.org; worked well and fast. Some examples of the preview samples created from them (the resulting PNG files). ![0a8a3c2151dc065e34934e4609895b1c](/attachments/20948dca-23e3-4e25-95d0-82bd6a3f1624) ![30db24de9fd41eafca28c8c16ccf4095](/attachments/193d8bfe-eff2-43f2-a650-1ef842db2eae) ![501d5de30c4ea5278c6b69429df15572](/attachments/1c020103-a285-4897-ac8b-b0f945a639e6) ![960c96225012d8c42da56ab060ce0892](/attachments/28b16b37-7355-4add-a76a-b0e4b5faf259)
Harley Acheson added 1 commit 2023-07-01 02:21:36 +02:00
Harley Acheson changed title from WIP: SVG Thumbnails to UI: SVG Thumbnails 2023-07-01 02:22:24 +02:00
Harley Acheson added 1 commit 2023-07-01 20:11:02 +02:00
Harley Acheson requested review from Campbell Barton 2023-07-01 20:17:23 +02:00
Harley Acheson added 1 commit 2023-07-02 21:39:59 +02:00

This should be evaluated as a design task before going though review.

I'm concerned that this introduces support for something which users will find incomplete, and request fixes - either pushing development focus into a new area - or leaving SVG support "incomplete/broken" from a user perspective.

Once supported users may reasonably request:

  • Control/override resolution, some SVG files may define pixel dimensions which are very large - this isn't a problem for vector drawing software, but will impact Blender if it needs to allocate a single buffer.
  • Text/font handling.
  • Control over color-space, alpha blending.

There is some potential that users start to use SVG for projects in a way that means updates to nanoSVG (even improvements) could make users files render differently.

With this change it's not clear what users expectations should be. If we add support for a format with a lot of limitations, which users run into and view as bugs... we might be better off not supporting it, so users convert the SVG's to images outside of Blender which is what they might have to do anyway.

This should be evaluated as a design task before going though review. I'm concerned that this introduces support for something which users will find incomplete, and request fixes - either pushing development focus into a new area - or leaving SVG support "incomplete/broken" from a user perspective. Once supported users may reasonably request: - Control/override resolution, some SVG files may define pixel dimensions which are very large - this isn't a problem for vector drawing software, but will impact Blender if it needs to allocate a single buffer. - Text/font handling. - Control over color-space, alpha blending. There is some potential that users start to use SVG for projects in a way that means updates to nanoSVG (even improvements) could make users files render differently. With this change it's not clear what users expectations should be. If we add support for a format with a lot of limitations, which users run into and view as bugs... we might be better off not supporting it, so users convert the SVG's to images outside of Blender which is what they might have to do anyway.

We have two official release add-ons importing SVG (the one importing as curves, and the one importing as greasepencil). As such, I think having preview of SVG in the file browser makes sense.

But I would not expose it as a loadable image format indeed, unless it is decided to fully support our own SVG rasterizer, with all the necessary features.

In any case, this should indeed be a design task first.

We have two official release add-ons importing SVG (the one importing as curves, and the one importing as greasepencil). As such, I think having preview of SVG in the file browser makes sense. But I would not expose it as a loadable image format indeed, unless it is decided to fully support our own SVG rasterizer, with all the necessary features. In any case, this should indeed be a design task first.
Harley Acheson added 1 commit 2023-07-04 20:45:51 +02:00
Author
Member

Removing all code to do with loading SVG images, leaving only the code needed for thumbnailing.

Removing Reviewer and setting WIP to take this out of the review queue.

Removing all code to do with loading SVG images, leaving only the code needed for thumbnailing. Removing Reviewer and setting WIP to take this out of the review queue.
Harley Acheson changed title from UI: SVG Thumbnails to WIP: UI: SVG Thumbnails 2023-07-04 20:49:27 +02:00
Campbell Barton reviewed 2023-07-06 09:19:08 +02:00
Campbell Barton left a comment
Owner

I'd rather leave

I'd rather leave
Campbell Barton requested changes 2023-07-06 09:23:45 +02:00
@ -199,6 +199,18 @@ const ImFileType IMB_FILE_TYPES[] = {
/*default_save_role*/ COLOR_ROLE_DEFAULT_BYTE,
},
#endif
{

There should be a code-comment explaining why only the thumbnail callback is set as it's not obvious.

There should be a code-comment explaining why only the thumbnail callback is set as it's not obvious.
Harley marked this conversation as resolved
@ -0,0 +15,4 @@
extern "C" {
ImBuf *imb_load_filepath_thumbnail_svg(const char *filepath,

Also note here, that only thumbnails are supported and why.

Also note here, that only thumbnails are supported and why.
Harley marked this conversation as resolved
@ -46,3 +46,3 @@
const char *imb_ext_image[] = {
".png", ".tga", ".bmp", ".jpg", ".jpeg", ".sgi", ".rgb", ".rgba", ".tif", ".tiff", ".tx",
".png",

With this change SVG are shown when opening an image, which is misleading as they're not supported.

Ideally, add-ons that support SVG can request SVG files are shown and in this case - the thumbnails will be shown.

With this change SVG are shown when opening an image, which is misleading as they're not supported. Ideally, add-ons that support SVG can request SVG files are shown and in this case - the thumbnails will be shown.
Harley marked this conversation as resolved
Harley Acheson added 1 commit 2023-07-06 23:58:23 +02:00
Author
Member

@ideasman42 With this change SVG are shown when opening an image, which is misleading as they're not supported...Ideally, add-ons that support SVG can request SVG files are shown and in this case - the thumbnails will be shown.

I removed SVG from that imb_ext_image list and left it where it is now, which is a file treated as FILE_TYPE_OBJECT_IO. This means that opening an image in Image Editor you no longer see SVG files in the filtered list.

But then I added a new thumbnail source type to match - THB_SOURCE_OBJECT_IO. And for files of this type I only thumbnail those that end in ".svg". This seems interesting to me as it opens a path for thumbnailing other non-image file types.

Note that when using the SVG import scripts we do see SVG files and thumbnails because those are currently set to filter on FILE_TYPE_OBJECT_IO.

> @ideasman42 With this change SVG are shown when opening an image, which is misleading as they're not supported...Ideally, add-ons that support SVG can request SVG files are shown and in this case - the thumbnails will be shown. I removed SVG from that `imb_ext_image` list and left it where it is now, which is a file treated as FILE_TYPE_OBJECT_IO. This means that opening an image in Image Editor you no longer see SVG files in the filtered list. But then I added a new thumbnail source type to match - THB_SOURCE_OBJECT_IO. And for files of this type I only thumbnail those that end in ".svg". This seems interesting to me as it opens a path for thumbnailing other non-image file types. Note that when using the SVG import scripts we do see SVG files and thumbnails because those are currently set to filter on FILE_TYPE_OBJECT_IO.
Harley Acheson changed title from WIP: UI: SVG Thumbnails to UI: SVG Thumbnails 2023-07-07 00:06:39 +02:00
Campbell Barton requested changes 2023-07-07 08:52:24 +02:00
Campbell Barton left a comment
Owner

Minor requests.

Minor requests.
@ -0,0 +13,4 @@
#include "../../../extern/nanosvg/nanosvgrast.h"
extern "C" {

Could the C-only function call a static local function? (to avoid extern "C" the whole file).

Could the C-only function call a static local function? (to avoid `extern "C"` the whole file).
Harley marked this conversation as resolved
@ -0,0 +15,4 @@
extern "C" {
/* Currently only creating thumbnails for this format to support specialized importers. General

It's not so obvious where this kind of info should be included, I'd prefer the file header, as this comment isn't a doc-string for the function, e.g.

/* SPDX-FileCopyrightText: 2023 Blender Foundation
 *
 * SPDX-License-Identifier: GPL-2.0-or-later */

/** \file
 * \ingroup imbuf
 *
 * SVG vector graphics format support for the purpose of thumbnail-display.
 * While loading these as an #ImBuf is trivial to support, it would expose
 * limitations of NANOSVG and users may end up needing more advanced options
 * spesific to loading vector graphics (such as resolution control), see #109567 for details.
 */
It's not so obvious where this kind of info should be included, I'd prefer the file header, as this comment isn't a doc-string for the function, e.g. ``` /* SPDX-FileCopyrightText: 2023 Blender Foundation * * SPDX-License-Identifier: GPL-2.0-or-later */ /** \file * \ingroup imbuf * * SVG vector graphics format support for the purpose of thumbnail-display. * While loading these as an #ImBuf is trivial to support, it would expose * limitations of NANOSVG and users may end up needing more advanced options * spesific to loading vector graphics (such as resolution control), see #109567 for details. */ ```
Harley marked this conversation as resolved
@ -47,2 +47,3 @@
const char *imb_ext_image[] = {
".png", ".tga", ".bmp", ".jpg", ".jpeg", ".sgi", ".rgb", ".rgba", ".tif", ".tiff", ".tx",
".png",
".tga",

This should be reverted entirely.

This should be reverted entirely.
Harley marked this conversation as resolved
Harley Acheson added 1 commit 2023-07-07 19:39:20 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
35707f63df
Changes requested by review.
Author
Member

@ideasman42 - Could the C-only function call a static local function? (to avoid extern "C" the whole file).

Sorry, wasn't really sure what you wanted with this...

When making this "format_svg.cc" file I copied the pattern of the seven other "format_(type).cc" files for consistency. All of them do the whole file extern "C" thing. But this is made a bit weirder in that most of their functions are defined in IMB_filetype.h, inside an extern "C" block.

So I removed the extern "C" block from this file since it isn't really needed anyway.

> @ideasman42 - Could the C-only function call a static local function? (to avoid extern "C" the whole file). Sorry, wasn't really sure what you wanted with this... When making this "format_svg.cc" file I copied the pattern of the seven other "format_(type).cc" files for consistency. All of them do the whole file extern "C" thing. But this is made a bit weirder in that most of their functions are defined in `IMB_filetype.h`, inside an extern "C" block. So I removed the extern "C" block from this file since it isn't really needed anyway.
Campbell Barton approved these changes 2023-07-09 10:01:45 +02:00
Author
Member

@blender-bot build

@blender-bot build
Author
Member

Harley:

This would require more work to merge. Only a single file can have NANOSVG_IMPLEMENTATION while including nanosvg.h. This is now done in some GP code so this would give duplicate symbols. Will have to think of a nice way to proceed.

Harley: This would require more work to merge. Only a single file can have NANOSVG_IMPLEMENTATION while including nanosvg.h. This is now done in some GP code so this would give duplicate symbols. Will have to think of a nice way to proceed.
Harley Acheson added 1 commit 2023-07-10 19:30:36 +02:00
Harley Acheson added 1 commit 2023-07-10 19:35:43 +02:00
Author
Member

Note that changes to build files are done in consolation with @LazyDodo

Note that changes to build files are done in consolation with @LazyDodo
Harley Acheson added 1 commit 2023-07-10 20:15:42 +02:00
Harley Acheson added 1 commit 2023-07-10 20:19:17 +02:00
Author
Member

@blender-bot build

@blender-bot build
Ray molenkamp requested changes 2023-07-10 20:35:10 +02:00
Ray molenkamp left a comment
Member

please provide provenance of the nanosvgrast.h file. There's really only two options here

1 - This from the same revision as noted in extern/nanosvg/README.blender in this case the patch description of this diff should explicitly mention that

2- This is from a different commit and this should be explained in the patch description why it is this way , and the README.blender needs to be updated to note the hash that was used.

Unrelated sidenote: and i'm not gonna reject this diff for it, I'm "not thrilled" blenlib macro's (ELEM) are being used in extern/nanosvg/nanosvg.h @antoniov can you please clean this up in a separate patch? local patch or not /extern files shouldn't be depending on headers from /source

please provide provenance of the `nanosvgrast.h` file. There's really only two options here 1 - This from the same revision as noted in `extern/nanosvg/README.blender` in this case the patch description of this diff should explicitly mention that 2- This is from a different commit and this should be explained in the patch description why it is this way , and the `README.blender` needs to be updated to note the hash that was used. Unrelated sidenote: and i'm not gonna reject this diff for it, I'm "not thrilled" blenlib macro's (`ELEM`) are being used in `extern/nanosvg/nanosvg.h` @antoniov can you please clean this up in a separate patch? local patch or not `/extern` files shouldn't be depending on headers from `/source`

@LazyDodo I have created the fix of nanosvg.h: #109959

@LazyDodo I have created the fix of `nanosvg.h`: https://projects.blender.org/blender/blender/pulls/109959
Ray molenkamp approved these changes 2023-07-12 22:36:52 +02:00
Ray molenkamp left a comment
Member

lgtm

lgtm
Harley Acheson merged commit 565436bf5f into main 2023-07-12 22:39:30 +02:00
Harley Acheson referenced this issue from a commit 2023-07-12 22:39:32 +02:00
Harley Acheson deleted branch SvgThumbs 2023-07-12 22:39:32 +02: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
5 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#109567
No description provided.