Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safe Compression Commit #2808

Merged
merged 1 commit into from
Feb 12, 2021

Conversation

ExeVirus
Copy link
Contributor

@ExeVirus ExeVirus commented Jan 23, 2021

Addresses #2803 concerns

Only a single program was used to safely compress all textures in MTG.

This was done using optipng with the following settings:

optipng -o7 -zm1-9 -nc -strip all -clobber %%f

The key command used is -nc, which stops color mode changes. I.e. any RGBA textures will remain RGBA textures, with none being changed to 8-bit indexed mode.

The resulting compression:

type size (Bytes) % of original texture size
Original 247,571 100%
Compressed 152,189 61.5%
Unsafe Compressed 140,719 56.8%

Summary: Saves 93.14 KB

@ExeVirus
Copy link
Contributor Author

We may someday go back and attempt further compression by reducing bit depth, but since 5.4 release is Saturday, let's do the less controversial, safe commit.

@mlloewen
Copy link

You might want to check out oxipng found at https://github.com/shssoichiro/oxipng. In short it is a rewrite of optipng in rustlang with some enhancements(multithread etc).

@rubenwardy
Copy link
Contributor

rubenwardy commented Feb 1, 2021

Hi,

please may you add a file optimize_textures.sh

#!/bin/bash

# Colors with 0 alpha need to be preserved, because opaque leaves ignore alpha.
# For that purpose, the use of indexed colors is disabled (-nc).

find -name '*.png' -print0 | xargs -0 optipng -o7 -zm1-9 -nc -strip all -clobber

Any caveats with texture optimisation should be documented.

Why are index color modes a problem?

@rubenwardy rubenwardy self-requested a review February 1, 2021 15:34
@sfan5
Copy link
Contributor

sfan5 commented Feb 1, 2021

Why are index color modes a problem?

I don't think it's indexed color specifically but rather the fact that converting it to indexed color will also drop the RGB portion from fully transparent pixels.

For that, see https://github.com/minetest/minetest/blob/master/doc/texture_packs.txt#L226-L232 or #2803 (comment)

@ExeVirus
Copy link
Contributor Author

ExeVirus commented Feb 1, 2021

Ruben, what do you mean by "add a File" I can do so easily, but I don't know where to put it.

@rubenwardy
Copy link
Contributor

Ruben, what do you mean by "add a File" I can do so easily, but I don't know where to put it.

I was referring to the root of this repository. A utils folder would make sense if there were more than one utility script

@ExeVirus ExeVirus force-pushed the Safe_Compress_Textures branch 2 times, most recently from ac4fec2 to 243ac7c Compare February 2, 2021 00:01
@ExeVirus
Copy link
Contributor Author

ExeVirus commented Feb 2, 2021

Okay, rebased and added optimize_textures.sh as written by Rubenwardy.
Tested the script on this PR on Lubuntu 20.04 LTS, same result as PR.

@rubenwardy rubenwardy added this to the 5.4.0 milestone Feb 6, 2021
#!/bin/bash

# Colors with 0 alpha need to be preserved, because opaque leaves ignore alpha.
# For that purpose, the use of indexed colors is disabled (-nc).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put this in an "utils" folder in case an .obj compression script is added in the future.

Copy link
Contributor

@rubenwardy rubenwardy Feb 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this to the utils folder is fine by me

Copy link
Contributor Author

@ExeVirus ExeVirus Feb 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, will do. This brings up the question: should I go ahead and add the compress.obj script to the same utils folder in #2807? Then, should I add a readme.md to that folder saying how to use both scripts in a new PR?

Edit: I will update it to work with the updated water textures as well.

Only a single program was used to safely compress all textures in MTG.

This was done using optipng with the following settings:

```
optipng -o7 -zm1-9 -nc -strip all -clobber %%f
```

The key command used is -nc, which stops color mode changes. I.e. any RGBA textures will remain RGBA textures, with none being changes to 8-bit indexed mode.

The resulting compression:

| type | size (Bytes) | % of original texture size |
| --- | --- | --- |
| Original | 247,571 | 100% |
| Compressed | 152,189 | 61.5% |

**Summary: Saves 93.14 KB**

A script has been added: utils/optimize_textures.sh which will perform this compression automatically, assuming optipng is installed.
@ExeVirus ExeVirus force-pushed the Safe_Compress_Textures branch from 243ac7c to 454bb6d Compare February 11, 2021 14:01
@ExeVirus
Copy link
Contributor Author

Okay, conflicts dealt with, changed the script directory to "utils"

Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alpha contents are preserved. No texture format warnings. Looks good.

@SmallJoker SmallJoker merged commit 6bd0599 into luanti-org:master Feb 12, 2021
ronoaldo pushed a commit to ronoaldo/minetest_game that referenced this pull request Feb 21, 2021
Only a single program was used to safely compress all textures in MTG.

 * `optipng -o7 -zm1-9 -nc -strip all -clobber %%f`

The key command used is -nc, which stops color mode changes. I.e. any RGBA textures will remain RGBA textures, with none being changes to 8-bit indexed mode.

utils/optimize_textures.sh performs this compression automatically, assuming optipng is installed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants