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

Fix suboptimal CLX encoding #3

Merged
merged 1 commit into from
Apr 10, 2023
Merged

Fix suboptimal CLX encoding #3

merged 1 commit into from
Apr 10, 2023

Conversation

glebm
Copy link
Collaborator

@glebm glebm commented Apr 10, 2023

Previously we did not check the fill width after the end of the encoding loop, resulting in frequent width=1 Fill commands.

Before:

CLX sprite: 16x20 pixelDataSize=97b

command width bytes color(s)
Transp. 80 1
Pixels 2 3 203 199
Fill 3 2 202
Pixels 2 3 199 201
Fill 1 2 205
Transp. 8 1
Pixels 3 4 205 199 196
Fill 4 2 197
Fill 1 2 202
Transp. 9 1
Pixels 6 7 206 199 197 203 206 202
Fill 1 2 204
Transp. 10 1
Pixels 4 5 206 199 197 205
Fill 1 2 207
Transp. 12 1
Pixels 3 4 206 197 197
Fill 1 2 205
Transp. 9 1
Pixels 7 8 207 205 203 206 206 197 197
Fill 1 2 206
Transp. 8 1
Pixels 3 4 204 197 199
Fill 1 2 205
Transp. 1 1
Pixels 2 3 202 197
Fill 1 2 204
Transp. 8 1
Pixels 7 8 206 197 199 207 206 199 196
Fill 1 2 205
Transp. 9 1
Pixels 1 2 203
Fill 4 2 197
Fill 1 2 202
Transp. 10 1
Pixels 5 6 207 205 199 199 203
Fill 1 2 207
Transp. 89 1

After:

CLX sprite: 16x20 pixelDataSize=88b

command width bytes color(s)
Transp. 80 1
Pixels 2 3 203 199
Fill 3 2 202
Pixels 3 4 199 201 205
Transp. 8 1
Pixels 3 4 205 199 196
Fill 4 2 197
Pixels 1 2 202
Transp. 9 1
Pixels 7 8 206 199 197 203 206 202 204
Transp. 10 1
Pixels 5 6 206 199 197 205 207
Transp. 12 1
Pixels 4 5 206 197 197 205
Transp. 9 1
Pixels 8 9 207 205 203 206 206 197 197 206
Transp. 8 1
Pixels 4 5 204 197 199 205
Transp. 1 1
Pixels 3 4 202 197 204
Transp. 8 1
Pixels 8 9 206 197 199 207 206 199 196 205
Transp. 9 1
Pixels 1 2 203
Fill 4 2 197
Pixels 1 2 202
Transp. 10 1
Pixels 6 7 207 205 199 199 203 207
Transp. 89 1

Previously we did not check the fill width after the end of the encoding
loop, resulting in frequent width=1 Fill commands.

Before:

CLX sprite: 16x20 pixelDataSize=97b

command | width | bytes | color(s)
--------|------:|------:|---------
Transp. |    80 |     1 |
Pixels  |     2 |     3 | 203 199
Fill    |     3 |     2 | 202
Pixels  |     2 |     3 | 199 201
Fill    |     1 |     2 | 205
Transp. |     8 |     1 |
Pixels  |     3 |     4 | 205 199 196
Fill    |     4 |     2 | 197
Fill    |     1 |     2 | 202
Transp. |     9 |     1 |
Pixels  |     6 |     7 | 206 199 197 203 206 202
Fill    |     1 |     2 | 204
Transp. |    10 |     1 |
Pixels  |     4 |     5 | 206 199 197 205
Fill    |     1 |     2 | 207
Transp. |    12 |     1 |
Pixels  |     3 |     4 | 206 197 197
Fill    |     1 |     2 | 205
Transp. |     9 |     1 |
Pixels  |     7 |     8 | 207 205 203 206 206 197 197
Fill    |     1 |     2 | 206
Transp. |     8 |     1 |
Pixels  |     3 |     4 | 204 197 199
Fill    |     1 |     2 | 205
Transp. |     1 |     1 |
Pixels  |     2 |     3 | 202 197
Fill    |     1 |     2 | 204
Transp. |     8 |     1 |
Pixels  |     7 |     8 | 206 197 199 207 206 199 196
Fill    |     1 |     2 | 205
Transp. |     9 |     1 |
Pixels  |     1 |     2 | 203
Fill    |     4 |     2 | 197
Fill    |     1 |     2 | 202
Transp. |    10 |     1 |
Pixels  |     5 |     6 | 207 205 199 199 203
Fill    |     1 |     2 | 207
Transp. |    89 |     1 |

After:

CLX sprite: 16x20 pixelDataSize=88b

command | width | bytes | color(s)
--------|------:|------:|---------
Transp. |    80 |     1 |
Pixels  |     2 |     3 | 203 199
Fill    |     3 |     2 | 202
Pixels  |     3 |     4 | 199 201 205
Transp. |     8 |     1 |
Pixels  |     3 |     4 | 205 199 196
Fill    |     4 |     2 | 197
Pixels  |     1 |     2 | 202
Transp. |     9 |     1 |
Pixels  |     7 |     8 | 206 199 197 203 206 202 204
Transp. |    10 |     1 |
Pixels  |     5 |     6 | 206 199 197 205 207
Transp. |    12 |     1 |
Pixels  |     4 |     5 | 206 197 197 205
Transp. |     9 |     1 |
Pixels  |     8 |     9 | 207 205 203 206 206 197 197 206
Transp. |     8 |     1 |
Pixels  |     4 |     5 | 204 197 199 205
Transp. |     1 |     1 |
Pixels  |     3 |     4 | 202 197 204
Transp. |     8 |     1 |
Pixels  |     8 |     9 | 206 197 199 207 206 199 196 205
Transp. |     9 |     1 |
Pixels  |     1 |     2 | 203
Fill    |     4 |     2 | 197
Pixels  |     1 |     2 | 202
Transp. |    10 |     1 |
Pixels  |     6 |     7 | 207 205 199 199 203 207
Transp. |    89 |     1 |
glebm added a commit to glebm/devilutionX that referenced this pull request Apr 10, 2023
glebm added a commit to glebm/devilutionX that referenced this pull request Apr 10, 2023
@AJenbo AJenbo merged commit e825e35 into main Apr 10, 2023
@AJenbo
Copy link
Member

AJenbo commented Apr 10, 2023

The table is very helpful for better understanding how this all works 👍

@AJenbo AJenbo deleted the fix-clx-encode branch April 10, 2023 15:34
glebm added a commit to diasurgical/devilutionx-mpq-tools that referenced this pull request Apr 10, 2023
AJenbo pushed a commit to diasurgical/DevilutionX that referenced this pull request Apr 10, 2023
AJenbo pushed a commit to diasurgical/DevilutionX that referenced this pull request Apr 10, 2023
artifacts-storage pushed a commit to artifacts-storage/devilutionx-artifacts that referenced this pull request Apr 10, 2023
artifacts-storage pushed a commit to artifacts-storage/devilutionx-artifacts that referenced this pull request Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants