Images loaded from palletized TGA files lack alpha channels #110437

Open
opened 2023-07-25 00:19:05 +02:00 by siliconspecter · 6 comments

System Information
Operating system: Windows 11 Home
Graphics card: Intel ARC A750 8GB

Blender Version
Broken: 3.6.1 and 4.0.0 2ed108cb84
Worked: None tested

Short description of error
When a palletized TGA file is loaded as an image, any transparent pixels come through as opaque black.
This does not occur for unpalletized TGA files; they come through transparent as expected.

An example of the same file in both palletized and unpalletized formats is attached. The files look identical in Aseprite.

Exact steps for others to reproduce the error

  • UV Editing
  • Image -> Open...
  • Select palletized TGA file
  • Note that the area surrounding the vegetation at the bottom of the image is black: palletized.png
  • Image -> Open...
  • Select unpalletized TGA file.
  • Note that the area surrounding the vegetation at the bottom of the image is transparent: unpalletized.png

This can additionally be confirmed by looking at the histogram, with the unpalletized file having a small spike at 0% for alpha while the palletized file is flat until 100%.

**System Information** Operating system: Windows 11 Home Graphics card: Intel ARC A750 8GB **Blender Version** Broken: 3.6.1 and 4.0.0 2ed108cb84cf Worked: None tested **Short description of error** When a palletized TGA file is loaded as an image, any transparent pixels come through as opaque black. This does not occur for unpalletized TGA files; they come through transparent as expected. An example of the same file in both palletized and unpalletized formats is attached. The files look identical in Aseprite. **Exact steps for others to reproduce the error** - UV Editing - Image -> Open... - Select palletized TGA file - Note that the area surrounding the vegetation at the bottom of the image is black: ![palletized.png](/attachments/5dabefd5-88fd-41dc-b121-b726b8cfd09f) - Image -> Open... - Select unpalletized TGA file. - Note that the area surrounding the vegetation at the bottom of the image is transparent: ![unpalletized.png](/attachments/7cf108fd-0b82-46df-a07e-f769f25f4a40) This can additionally be confirmed by looking at the histogram, with the unpalletized file having a small spike at 0% for alpha while the palletized file is flat until 100%.
siliconspecter added the
Type
Report
Status
Needs Triage
Priority
Normal
labels 2023-07-25 00:19:05 +02:00
Member

Can confirm that palletized tga doesn't load with alpha. (But not sure if pallet+alpha is to spec)

  • imagemagick and geeqie is loading both correctly
  • Thunar thumbnail preview isn't loading alpha on palletized tga.
  • GIMP failed to load palletized tga completely, doesn't show correct image.

Here's what GIMP shows on palletized tga when alpha channel is manually removed after loading:

图片

Can confirm that palletized tga doesn't load with alpha. (But not sure if pallet+alpha is to spec) - `imagemagick` and `geeqie` is loading both correctly - Thunar thumbnail preview isn't loading alpha on palletized tga. - `GIMP` failed to load palletized tga completely, doesn't show correct image. Here's what GIMP shows on palletized tga when alpha channel is manually removed after loading: ![图片](/attachments/49e5e083-b370-49d1-a530-037c528f1102)
8.8 KiB

This is a problematic texture, with an unfortunate history.

The texture itself declares in its header (byte offset 17) that it contains 0 bits of alpha [1]. Our imaging library is now respecting this data and so no alpha channel is created for it.

Previous blender versions: Older Blender versions were "broken" in 2 ways actually, but by accident, allowed things to work in some cases. First this texture will not work in Cycles if the alpha channel is expected. Eevee and the Image Editor work by accident. You can see that it's actually being loaded as RGB with no Alpha [4] but by luck happens to work due to a quirk of the old image loading code.

What about GIMP: The nightly 2.99.x versions will load it because they have a workaround to bypass the broken textures :( [2]
What about Krita: Krita actually refuses to load the palettized image entirely and issues an error [3]
Others? : Other software, like current released versions of GIMP, are affected too (see Yiming's comment above)

[1] Truevision TGA, File Format Specification, Version 2.0 as PDF, Page 8: https://www.loc.gov/preservation/digital/formats/fdd/fdd000180.shtml
[2] Gimp workaround: https://gitlab.gnome.org/GNOME/gimp/-/blob/master/plug-ins/common/file-tga.c#L550
[3] Krita error logs

24 Jul 2023 18:44:26 -0700: Importing image/x-tga to application/x-krita. Location: T:/palletized.tga. Real location: T:/palletized.tga. Batchmode: 0
24 Jul 2023 18:44:26 -0700: Failed to load image from image/x-tga
24 Jul 2023 18:44:26 -0700: Loading T:\palletized.tga failed: The file format contains unsupported features.
24 Jul 2023 18:44:30 -0700: Loading canceled: .

[4] Blender incorrect format from 3.3.8 LTS

With Palette - subtly broken No Palette - correct
image image
This is a problematic texture, with an unfortunate history. The texture itself declares in its header (byte offset 17) that it contains 0 bits of alpha [1]. Our imaging library is now respecting this data and so no alpha channel is created for it. Previous blender versions: Older Blender versions were "broken" in 2 ways actually, but by accident, allowed things to work in some cases. First this texture will not work in Cycles if the alpha channel is expected. Eevee and the Image Editor work by accident. You can see that it's actually being loaded as RGB with no Alpha [4] but by luck happens to work due to a quirk of the old image loading code. What about GIMP: The nightly 2.99.x versions will load it because they have a workaround to bypass the broken textures :( [2] What about Krita: Krita actually refuses to load the palettized image entirely and issues an error [3] Others? : Other software, like current released versions of GIMP, are affected too (see Yiming's comment above) [1] Truevision TGA, File Format Specification, Version 2.0 as PDF, Page 8: https://www.loc.gov/preservation/digital/formats/fdd/fdd000180.shtml [2] Gimp workaround: https://gitlab.gnome.org/GNOME/gimp/-/blob/master/plug-ins/common/file-tga.c#L550 [3] Krita error logs ``` 24 Jul 2023 18:44:26 -0700: Importing image/x-tga to application/x-krita. Location: T:/palletized.tga. Real location: T:/palletized.tga. Batchmode: 0 24 Jul 2023 18:44:26 -0700: Failed to load image from image/x-tga 24 Jul 2023 18:44:26 -0700: Loading T:\palletized.tga failed: The file format contains unsupported features. 24 Jul 2023 18:44:30 -0700: Loading canceled: . ``` [4] Blender incorrect format from 3.3.8 LTS | With Palette - subtly broken | No Palette - correct | | -- | -- | | ![image](/attachments/6100a7b5-df3c-4128-a6a2-ec97986b0555) | ![image](/attachments/2f11c575-ebcc-4eaf-a6f9-3035d78246b1) |
6.0 KiB
7.7 KiB
Author

So it might be an Aseprite bug that it is creating this file at all? Tonight I’ll experiment with changing the header byte called out see what happens. If palletized TGA cannot have an alpha channel I’ll get a bug raised on the Aseprite side. Cheers.

So it might be an Aseprite bug that it is creating this file at all? Tonight I’ll experiment with changing the header byte called out see what happens. If palletized TGA cannot have an alpha channel I’ll get a bug raised on the Aseprite side. Cheers.
Author

Here's what GIMP shows on palletized tga when alpha channel is manually removed after loading:

Which version of GIMP is that? Testing with 2.10.32, both files loaded with the alpha channel preserved.

> Here's what GIMP shows on palletized tga when alpha channel is manually removed after loading: Which version of GIMP is that? Testing with 2.10.32, both files loaded with the alpha channel preserved.
Author

Ah, so, reading the spec, it seems there is supposed to be an "extension area" following the image data which should contain the following field:

Attributes Type - Field 24 (1 Byte):

Byte 494 - This single byte field contains a value which specifies the type of Alpha channel data contained in the file.

Value Meaning

0: no Alpha data included (bits 3-0 of field 5.6 should also be

set to zero)

1: undefined data in the Alpha field, can be ignored

2: undefined data in the Alpha field, but should be retained

3: useful Alpha channel data is present

I'll raise this as a bug on the Aseprite side, thanks.

Ah, so, reading the spec, it seems there is supposed to be an "extension area" following the image data which should contain the following field: ``` Attributes Type - Field 24 (1 Byte): Byte 494 - This single byte field contains a value which specifies the type of Alpha channel data contained in the file. Value Meaning 0: no Alpha data included (bits 3-0 of field 5.6 should also be set to zero) 1: undefined data in the Alpha field, can be ignored 2: undefined data in the Alpha field, but should be retained 3: useful Alpha channel data is present ``` I'll raise this as a [bug](https://github.com/aseprite/aseprite/issues/3982) on the Aseprite side, thanks.

I tried using GIMP 2.10.18 which failed to load it properly but 2.99.16 succeeds as they have their own workaround in place.

The part of the spec is probably this one -- in the main TGA file header:

Field 5.6 (1 byte) - Image Descriptor:

Bits 3-0: These bits specify the number of attribute bits per
pixel. In the case of the TrueVista, these bits
indicate the number of bits per pixel which are
designated as Alpha Channel bits. For the ICB
and TARGA products, these bits indicate the
number of overlay bits available per pixel. See
field 24 (Attributes Type) for more information

Bits 3-0 in the provided file are 0.

That said, I think even after this is fixed our image library will have issues doing the proper thing. I'll have to work with the upstream project to fix the issue (which can take some time) but having a "valid" set of image files is a good first step for Aseprite to address first.

I tried using GIMP 2.10.18 which failed to load it properly but 2.99.16 succeeds as they have their own workaround in place. The part of the spec is probably this one -- in the main TGA file header: ``` Field 5.6 (1 byte) - Image Descriptor: Bits 3-0: These bits specify the number of attribute bits per pixel. In the case of the TrueVista, these bits indicate the number of bits per pixel which are designated as Alpha Channel bits. For the ICB and TARGA products, these bits indicate the number of overlay bits available per pixel. See field 24 (Attributes Type) for more information ``` Bits 3-0 in the provided file are 0. That said, I think even after this is fixed our image library will have issues doing the proper thing. I'll have to work with the upstream project to fix the issue (which can take some time) but having a "valid" set of image files is a good first step for Aseprite to address first.
Julien Kaspar added
Type
Bug
and removed
Type
Report
labels 2023-07-31 16:07:57 +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
3 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#110437
No description provided.