Add features table, refactor test texture generation, encode alpha for A1R5G5B5 images #1

Open
erlehmann wants to merge 15 commits from features-table into master
Owner

New Features

  • I added a features table, so tga_encoder users can check for e.g. tga_encoder.features.scanline_order.top_bottom.

Bugfixes

  • When RGBA pixels are encoded in the A1R5G5B5 color format, the alpha channel is set to transparent if alpha < 128. The alpha channel was not encoded at all for the A1R5G5B5 color format previously, wasting an entire bit per pixel.

Refactoring

  • TGA test texture generation uses the features table to cover all feature combinations.
  • Scanline orders ”bottom-top” and “top-bottom” were renamed to “bottom_top” and “top_bottom”.
  • Test texture filenames use a hyphen-minus to separate filename parts (TGA type, color format, scanline order).

Image Programs

Imagemagick

Decoding

Do not use a program that is part of imagemagick (e.g. display(1)) or relies on it to view/process tga_encoder output.

For years, imagemagick developers have assumed that scanline order and rotation information refer to the same concept. They refuse to fix any bugs that manifest as “images are shown/processed upside down”, telling users to use the -auto-orient command-line option (which seems to trigger the bug twice in most cases, therefore showing/processing images correctly).

GIMP

Decoding

GIMP 2.10 shows colored garbage on transparent background for the following files:

  • type1-B8G8R8A8-bottom_top.tga
  • type1-B8G8R8A8-top_bottom.tga

This seems to be a bug in GIMP.

MTpaint

Transparency

mtpaint 3.40 does not show transparency for TGA type 1 images.

It is unclear if this is a bug in mtpaint or in tga_encoder.

tga2ansi

tga2ansi shows all images as expected.

I wrote tga2ansi as a reference TGA decoder. Note that tga2ansi has little error handling.

Test Plan

Generate Images

  • Execute generate_test_textures.lua with the tools subdirectory set as the working directory.

Using a program of your choice (write down which one), verify that each of the following images can be loaded:

  • type10-A1R5G5B5-bottom_top.tga
  • type10-A1R5G5B5-top_bottom.tga
  • type10-B8G8R8A8-bottom_top.tga
  • type10-B8G8R8A8-top_bottom.tga
  • type10-B8G8R8-bottom_top.tga
  • type10-B8G8R8-top_bottom.tga
  • type1-A1R5G5B5-bottom_top.tga
  • type1-A1R5G5B5-top_bottom.tga
  • type1-B8G8R8A8-bottom_top.tga
  • type1-B8G8R8A8-top_bottom.tga
  • type1-B8G8R8-bottom_top.tga
  • type1-B8G8R8-top_bottom.tga
  • type2-A1R5G5B5-bottom_top.tga
  • type2-A1R5G5B5-top_bottom.tga
  • type2-B8G8R8A8-bottom_top.tga
  • type2-B8G8R8A8-top_bottom.tga
  • type2-B8G8R8-bottom_top.tga
  • type2-B8G8R8-top_bottom.tga
  • type3-Y8-bottom_top.tga
  • type3-Y8-top_bottom.tga

Visual Confirmation

Colors & Scanline Order

Using a program of your choice (write down which one), verify that each of the following images shows the letters T (red, closest to top left corner), G (green, center) and A (blue, closest to bottom right corner).

  • type10-A1R5G5B5-bottom_top.tga
  • type10-A1R5G5B5-top_bottom.tga
  • type10-B8G8R8A8-bottom_top.tga
  • type10-B8G8R8A8-top_bottom.tga
  • type10-B8G8R8-bottom_top.tga
  • type10-B8G8R8-top_bottom.tga
  • type1-A1R5G5B5-bottom_top.tga
  • type1-A1R5G5B5-top_bottom.tga
  • type1-B8G8R8A8-bottom_top.tga
  • type1-B8G8R8A8-top_bottom.tga
  • type1-B8G8R8-bottom_top.tga
  • type1-B8G8R8-top_bottom.tga
  • type2-A1R5G5B5-bottom_top.tga
  • type2-A1R5G5B5-top_bottom.tga
  • type2-B8G8R8A8-bottom_top.tga
  • type2-B8G8R8A8-top_bottom.tga
  • type2-B8G8R8-bottom_top.tga
  • type2-B8G8R8-top_bottom.tga

Using a program of your choice (write down which one), verify that each of the following images shows the letters T (gray, closest to top left corner), G (light gray, center) and A (dark gray, closest to bottom right corner).

  • type3-Y8-bottom_top.tga
  • type3-Y8-top_bottom.tga

Transparency

No Alpha Channel (B8G8R8, Y8)

Using a program of your choice (write down which one), verify that each of the following images has a black background and a white 2×2 square in the bottom left corner.

  • type10-B8G8R8-bottom_top.tga
  • type10-B8G8R8-top_bottom.tga
  • type1-B8G8R8-bottom_top.tga
  • type1-B8G8R8-top_bottom.tga
  • type2-B8G8R8-bottom_top.tga
  • type2-B8G8R8-top_bottom.tga
  • type3-Y8-bottom_top.tga
  • type3-Y8-top_bottom.tga

1-Bit Alpha Channel (A1R5G5B5)

Using a program of your choice (write down which one), verify that each of the following images has a transparent background and a white 2×2 square in the bottom left corner.

  • type10-A1R5G5B5-bottom_top.tga
  • type10-A1R5G5B5-top_bottom.tga
  • type1-A1R5G5B5-bottom_top.tga
  • type1-A1R5G5B5-top_bottom.tga
  • type2-A1R5G5B5-bottom_top.tga
  • type2-A1R5G5B5-top_bottom.tga

8-Bit Alpha Channel (B8G8R8A8)

Using a program of your choice (write down which one), verify that each of the following images has a partially transparent black background and a partially transparent white 2×2 square in the bottom left corner.

  • type10-B8G8R8A8-bottom_top.tga
  • type10-B8G8R8A8-top_bottom.tga
  • type1-B8G8R8A8-bottom_top.tga
  • type1-B8G8R8A8-top_bottom.tga
  • type2-B8G8R8A8-bottom_top.tga
  • type2-B8G8R8A8-top_bottom.tga

Results Table

You can use this table to report test results (change ☐ to ☑ on success and ☒ on failure). Ignore empty cells.

Filename File Exists TGA (RGB) TGA (Gray) Opaque Black Background Transparent Background Partially Transparent Black Background Opaque White Square Partially Transparent White Square
0 type10-A1R5G5B5-bottom_top.tga
1 type10-A1R5G5B5-top_bottom.tga
2 type10-B8G8R8A8-bottom_top.tga
3 type10-B8G8R8A8-top_bottom.tga
4 type10-B8G8R8-bottom_top.tga
5 type10-B8G8R8-top_bottom.tga
6 type1-A1R5G5B5-bottom_top.tga
7 type1-A1R5G5B5-top_bottom.tga
8 type1-B8G8R8A8-bottom_top.tga
9 type1-B8G8R8A8-top_bottom.tga
10 type1-B8G8R8-bottom_top.tga
11 type1-B8G8R8-top_bottom.tga
12 type2-A1R5G5B5-bottom_top.tga
13 type2-A1R5G5B5-top_bottom.tga
14 type2-B8G8R8A8-bottom_top.tga
15 type2-B8G8R8A8-top_bottom.tga
16 type2-B8G8R8-bottom_top.tga
17 type2-B8G8R8-top_bottom.tga
18 type3-Y8-bottom_top.tga
19 type3-Y8-top_bottom.tga
# New Features * I added a features table, so `tga_encoder` users can check for e.g. `tga_encoder.features.scanline_order.top_bottom`. # Bugfixes * When RGBA pixels are encoded in the `A1R5G5B5` color format, the alpha channel is set to transparent if alpha < 128. The alpha channel was not encoded at all for the `A1R5G5B5` color format previously, wasting an entire bit per pixel. # Refactoring * TGA test texture generation uses the features table to cover all feature combinations. * Scanline orders ”bottom-top” and “top-bottom” were renamed to “bottom_top” and “top_bottom”. * Test texture filenames use a hyphen-minus to separate filename parts (TGA type, color format, scanline order). # Image Programs ## Imagemagick ### Decoding **Do not use a program that is part of *imagemagick* (e.g. `display(1)`) or relies on it to view/process `tga_encoder` output.** For years, *imagemagick* developers have assumed that scanline order and rotation information refer to the same concept. They refuse to fix any bugs that manifest as “images are shown/processed upside down”, telling users to use the `-auto-orient` command-line option (which seems to trigger the bug twice in most cases, therefore showing/processing images correctly). ## GIMP ### Decoding GIMP 2.10 shows colored garbage on transparent background for the following files: - `type1-B8G8R8A8-bottom_top.tga` - `type1-B8G8R8A8-top_bottom.tga` This seems to be a bug in GIMP. ## MTpaint ### Transparency mtpaint 3.40 does not show transparency for TGA type 1 images. It is unclear if this is a bug in mtpaint or in `tga_encoder`. ## tga2ansi [tga2ansi](http://news.dieweltistgarnichtso.net/bin/tga2ansi) shows all images as expected. I wrote `tga2ansi` as a reference TGA decoder. Note that `tga2ansi` has little error handling. # Test Plan ## Generate Images - [ ] Execute `generate_test_textures.lua` with the `tools` subdirectory set as the working directory. Using a program of your choice (write down which one), verify that each of the following images can be loaded: - [ ] `type10-A1R5G5B5-bottom_top.tga` - [ ] `type10-A1R5G5B5-top_bottom.tga` - [ ] `type10-B8G8R8A8-bottom_top.tga` - [ ] `type10-B8G8R8A8-top_bottom.tga` - [ ] `type10-B8G8R8-bottom_top.tga` - [ ] `type10-B8G8R8-top_bottom.tga` - [ ] `type1-A1R5G5B5-bottom_top.tga` - [ ] `type1-A1R5G5B5-top_bottom.tga` - [ ] `type1-B8G8R8A8-bottom_top.tga` - [ ] `type1-B8G8R8A8-top_bottom.tga` - [ ] `type1-B8G8R8-bottom_top.tga` - [ ] `type1-B8G8R8-top_bottom.tga` - [ ] `type2-A1R5G5B5-bottom_top.tga` - [ ] `type2-A1R5G5B5-top_bottom.tga` - [ ] `type2-B8G8R8A8-bottom_top.tga` - [ ] `type2-B8G8R8A8-top_bottom.tga` - [ ] `type2-B8G8R8-bottom_top.tga` - [ ] `type2-B8G8R8-top_bottom.tga` - [ ] `type3-Y8-bottom_top.tga` - [ ] `type3-Y8-top_bottom.tga` ## Visual Confirmation ### Colors & Scanline Order Using a program of your choice (write down which one), verify that each of the following images shows the letters T (red, closest to top left corner), G (green, center) and A (blue, closest to bottom right corner). - [ ] `type10-A1R5G5B5-bottom_top.tga` - [ ] `type10-A1R5G5B5-top_bottom.tga` - [ ] `type10-B8G8R8A8-bottom_top.tga` - [ ] `type10-B8G8R8A8-top_bottom.tga` - [ ] `type10-B8G8R8-bottom_top.tga` - [ ] `type10-B8G8R8-top_bottom.tga` - [ ] `type1-A1R5G5B5-bottom_top.tga` - [ ] `type1-A1R5G5B5-top_bottom.tga` - [ ] `type1-B8G8R8A8-bottom_top.tga` - [ ] `type1-B8G8R8A8-top_bottom.tga` - [ ] `type1-B8G8R8-bottom_top.tga` - [ ] `type1-B8G8R8-top_bottom.tga` - [ ] `type2-A1R5G5B5-bottom_top.tga` - [ ] `type2-A1R5G5B5-top_bottom.tga` - [ ] `type2-B8G8R8A8-bottom_top.tga` - [ ] `type2-B8G8R8A8-top_bottom.tga` - [ ] `type2-B8G8R8-bottom_top.tga` - [ ] `type2-B8G8R8-top_bottom.tga` Using a program of your choice (write down which one), verify that each of the following images shows the letters T (gray, closest to top left corner), G (light gray, center) and A (dark gray, closest to bottom right corner). - [ ] `type3-Y8-bottom_top.tga` - [ ] `type3-Y8-top_bottom.tga` ### Transparency #### No Alpha Channel (B8G8R8, Y8) Using a program of your choice (write down which one), verify that each of the following images has a black background and a white 2×2 square in the bottom left corner. - [ ] `type10-B8G8R8-bottom_top.tga` - [ ] `type10-B8G8R8-top_bottom.tga` - [ ] `type1-B8G8R8-bottom_top.tga` - [ ] `type1-B8G8R8-top_bottom.tga` - [ ] `type2-B8G8R8-bottom_top.tga` - [ ] `type2-B8G8R8-top_bottom.tga` - [ ] `type3-Y8-bottom_top.tga` - [ ] `type3-Y8-top_bottom.tga` #### 1-Bit Alpha Channel (A1R5G5B5) Using a program of your choice (write down which one), verify that each of the following images has a transparent background and a white 2×2 square in the bottom left corner. - [ ] `type10-A1R5G5B5-bottom_top.tga` - [ ] `type10-A1R5G5B5-top_bottom.tga` - [ ] `type1-A1R5G5B5-bottom_top.tga` - [ ] `type1-A1R5G5B5-top_bottom.tga` - [ ] `type2-A1R5G5B5-bottom_top.tga` - [ ] `type2-A1R5G5B5-top_bottom.tga` #### 8-Bit Alpha Channel (B8G8R8A8) Using a program of your choice (write down which one), verify that each of the following images has a partially transparent black background and a partially transparent white 2×2 square in the bottom left corner. - [ ] `type10-B8G8R8A8-bottom_top.tga` - [ ] `type10-B8G8R8A8-top_bottom.tga` - [ ] `type1-B8G8R8A8-bottom_top.tga` - [ ] `type1-B8G8R8A8-top_bottom.tga` - [ ] `type2-B8G8R8A8-bottom_top.tga` - [ ] `type2-B8G8R8A8-top_bottom.tga` ## Results Table You can use this table to report test results (change ☐ to ☑ on success and ☒ on failure). Ignore empty cells. | № | Filename | File Exists | TGA (RGB) | TGA (Gray) | Opaque Black Background | Transparent Background | Partially Transparent Black Background | Opaque White Square | Partially Transparent White Square | |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- | 0 | `type10-A1R5G5B5-bottom_top.tga` | ☐ | ☐ | | | ☐ | | ☐ | | | 1 | `type10-A1R5G5B5-top_bottom.tga` | ☐ | ☐ | | | ☐ | | ☐ | | | 2 | `type10-B8G8R8A8-bottom_top.tga` | ☐ | ☐ | | | | ☐ | | ☐ | | 3 | `type10-B8G8R8A8-top_bottom.tga` | ☐ | ☐ | | | | ☐ | | ☐ | | 4 | `type10-B8G8R8-bottom_top.tga` | ☐ | ☐ | | ☐ | | | ☐ | | | 5 | `type10-B8G8R8-top_bottom.tga` | ☐ | ☐ | | ☐ | | | ☐ | | | 6 | `type1-A1R5G5B5-bottom_top.tga` | ☐ | ☐ | | | ☐ | | ☐ | | | 7 | `type1-A1R5G5B5-top_bottom.tga` | ☐ | ☐ | | | ☐ | | ☐ | | | 8 | `type1-B8G8R8A8-bottom_top.tga` | ☐ | ☐ | | | | ☐ | | ☐ | | 9 | `type1-B8G8R8A8-top_bottom.tga` | ☐ | ☐ | | | | ☐ | | ☐ | | 10 | `type1-B8G8R8-bottom_top.tga` | ☐ | ☐ | | ☐ | | | ☐ | | | 11 | `type1-B8G8R8-top_bottom.tga` | ☐ | ☐ | | ☐ | | | ☐ | | | 12 | `type2-A1R5G5B5-bottom_top.tga` | ☐ | ☐ | | | ☐ | | ☐ | | | 13 | `type2-A1R5G5B5-top_bottom.tga` | ☐ | ☐ | | | ☐ | | ☐ | | | 14 | `type2-B8G8R8A8-bottom_top.tga` | ☐ | ☐ | | | | ☐ | | ☐ | | 15 | `type2-B8G8R8A8-top_bottom.tga` | ☐ | ☐ | | | | ☐ | | ☐ | | 16 | `type2-B8G8R8-bottom_top.tga` | ☐ | ☐ | | ☐ | | | ☐ | | | 17 | `type2-B8G8R8-top_bottom.tga` | ☐ | ☐ | | ☐ | | | ☐ | | | 18 | `type3-Y8-bottom_top.tga` | ☐ | | ☐ | ☐ | | | ☐ | | | 19 | `type3-Y8-top_bottom.tga` | ☐ | | ☐ | ☐ | | | ☐ | |
erlehmann added 6 commits 2023-10-18 04:29:49 +02:00
erlehmann added 1 commit 2023-10-18 05:03:16 +02:00
erlehmann added 1 commit 2023-10-18 05:08:22 +02:00
erlehmann added 1 commit 2023-10-20 01:08:22 +02:00
erlehmann added 1 commit 2023-11-27 23:15:48 +01:00
e599c9fe83
Use keys with truthy values in features table
If the features table uses keys with truthy values, it is easy to check
for the presence of some feature by checking if the corresponding table
entry (e.g. “tga_encoder.features.color_format.A1R5G5B5”) is truthy.
erlehmann added 1 commit 2023-11-28 21:51:13 +01:00
0272fa5ccd
Change scanline order names
The scanline order ”bottom-top” has been changed to ”bottom_top”.
The scanline order “top-bottom” has been changed to “top_bottom”.

The scanline order names were changed so that API consumers can check if
“tga_encoder.features.scanline_order.top_bottom” is truthy instead of
having to check “tga_encoder.features.scanline_order["top-bottom"]”.

This is a breaking change, but since no release of tga_encoder happened
since commit 01bcbbf927 which allowed the
scanline order to be specified, it can not affect any mod on ContentDB.
erlehmann added 1 commit 2023-11-29 18:13:16 +01:00
72a4f41aa7
Use hyphen-minus to separate test texture filename parts
The scanline orders “bottom_top” and “top_bottom” contain an underscore.
Therefore, the underscore is no longer an appropriate separator for the
test texture filename parts (TGA type, color format, scanline order).
erlehmann changed title from WIP: Add features table, refactor test texture generation, encode alpha for A1R5G5B5 images to Add features table, refactor test texture generation, encode alpha for A1R5G5B5 images 2023-11-29 19:23:33 +01:00
Author
Owner

I tested this in Minetest and found that it does not seem to render TGA Type 10 with scanline order “top_bottom” correctly (look at the corruption of the letter “A” in the second row).

I can not explain the thing where only the letter A is decoded.

I tested this in Minetest and found that it does not seem to render TGA Type 10 with scanline order “top_bottom” correctly (look at the corruption of the letter “A” in the second row). I can not explain the thing where only the letter A is decoded.
erlehmann added 1 commit 2023-12-01 00:30:32 +01:00
Author
Owner

First screenshot: TGA test nodes with Minetest 5.7.0-443-ga7e545609:
Second screenshot: TGA test nodes with Minetest 5.4.1

First screenshot: TGA test nodes with Minetest 5.7.0-443-ga7e545609: Second screenshot: TGA test nodes with Minetest 5.4.1
Author
Owner

Status update:

  • Both Minetst and GIMP fail to display the TGA Type 1 B8G8R8A8 test texture.
  • All of sxiv, mtpaint, imagemagick show the TGA Type 1 B8G8R8A8 test texture with a black (instead of 50% transparent black) background, but the colors of the letters are as intended.

The Minetest issue in 5.8.0-dev where only the blue letter A is shown might happen because BGRA input is evaluated as ARGB, as everything non-blue looks transparent. Changing IrrlichtMT CColorConverter::convert_B8G8R8A8toA8R8G8B8 to just copy input to output fixes the issue, but this fix is obviously incorrect. Maybe the color conversion happens twice somehow?

Status update: * Both Minetst and GIMP fail to display the TGA Type 1 B8G8R8A8 test texture. * All of sxiv, mtpaint, imagemagick show the TGA Type 1 B8G8R8A8 test texture with a black (instead of 50% transparent black) background, but the colors of the letters are as intended. The Minetest issue in 5.8.0-dev where only the blue letter A is shown might happen because BGRA input is evaluated as ARGB, as everything non-blue looks transparent. Changing IrrlichtMT `CColorConverter::convert_B8G8R8A8toA8R8G8B8` to just copy input to output fixes the issue, but this fix is obviously incorrect. Maybe the color conversion happens twice somehow?
erlehmann added 2 commits 2024-03-19 11:55:48 +01:00
9497a0303c
Add 2×2 white square to bottom left corner of test textures
As the alpha channel of the color is above 127, the square should
show as opaque white in TGA images with the color format A1R5G5B5.
Author
Owner

tga2ansi rendering of generated test images for TGA type 1, 2, 3, 10:

`tga2ansi` rendering of generated test images for TGA type 1, 2, 3, 10:
Author
Owner

The alpha channel was not encoded for colormapped images using the A1R5G5B5 color format.

The bug has been fixed in in commit 50466ca08b.

The alpha channel was not encoded for colormapped images using the `A1R5G5B5` color format. The bug has been fixed in in commit 50466ca08b917fdb4063f9220e30f9431ace96c8.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
You can also view command line instructions.

Step 1:

From your project repository, check out a new branch and test the changes.
git checkout -b features-table master
git pull origin features-table

Step 2:

Merge the changes and update on Gitea.
git checkout master
git merge --no-ff features-table
git push origin master
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 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: erlehmann/tga_encoder#1
No description provided.