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

ARGB8888 is read by VTFLib as GBAR8888 #13

Open
DBotThePony opened this issue Mar 8, 2021 · 8 comments
Open

ARGB8888 is read by VTFLib as GBAR8888 #13

DBotThePony opened this issue Mar 8, 2021 · 8 comments

Comments

@DBotThePony
Copy link

Sample file:
argb8888.zip
Expected, and in-game result:
gmod_ci3nqbMLrP
VTFEdit:
VTFEdit_GziD1nWS5u

@DBotThePony DBotThePony changed the title ARGB8888 is read by VTFEdit as GBAR8888 ARGB8888 is read by VTFLib as GBAR8888 Mar 9, 2021
@thegrb93
Copy link

thegrb93 commented Mar 9, 2021

The way the channels are permutated look like the color data region is offsetted by two bytes.

@thegrb93
Copy link

thegrb93 commented Mar 9, 2021

The top-left and bottom-right pixel look fine though so maybe it's the channel mixing failing due to incorrect enum.

@thegrb93
Copy link

thegrb93 commented Mar 9, 2021

VTFLib/VTFLib/VTFFile.cpp

Lines 3592 to 3604 in ae19fcf

{ 32, 4, 8, 8, 8, 8, 0, 1, 2, 3, vlFalse, vlTrue, NULL, NULL, IMAGE_FORMAT_RGBA8888},
{ 32, 4, 8, 8, 8, 8, 3, 2, 1, 0, vlFalse, vlTrue, NULL, NULL, IMAGE_FORMAT_ABGR8888},
{ 24, 3, 8, 8, 8, 0, 0, 1, 2, -1, vlFalse, vlTrue, NULL, NULL, IMAGE_FORMAT_RGB888},
{ 24, 3, 8, 8, 8, 0, 2, 1, 0, -1, vlFalse, vlTrue, NULL, NULL, IMAGE_FORMAT_BGR888},
{ 16, 2, 5, 6, 5, 0, 0, 1, 2, -1, vlFalse, vlTrue, NULL, NULL, IMAGE_FORMAT_RGB565},
{ 8, 1, 8, 8, 8, 0, 0, -1, -1, -1, vlFalse, vlTrue, ToLuminance, FromLuminance, IMAGE_FORMAT_I8},
{ 16, 2, 8, 8, 8, 8, 0, -1, -1, 1, vlFalse, vlTrue, ToLuminance, FromLuminance, IMAGE_FORMAT_IA88},
{ 8, 1, 0, 0, 0, 0, -1, -1, -1, -1, vlFalse, vlFalse, NULL, NULL, IMAGE_FORMAT_P8},
{ 8, 1, 0, 0, 0, 8, -1, -1, -1, 0, vlFalse, vlTrue, NULL, NULL, IMAGE_FORMAT_A8},
{ 24, 3, 8, 8, 8, 8, 0, 1, 2, -1, vlFalse, vlTrue, ToBlueScreen, FromBlueScreen, IMAGE_FORMAT_RGB888_BLUESCREEN},
{ 24, 3, 8, 8, 8, 8, 2, 1, 0, -1, vlFalse, vlTrue, ToBlueScreen, FromBlueScreen, IMAGE_FORMAT_BGR888_BLUESCREEN},
{ 32, 4, 8, 8, 8, 8, 3, 0, 1, 2, vlFalse, vlTrue, NULL, NULL, IMAGE_FORMAT_ARGB8888},
{ 32, 4, 8, 8, 8, 8, 2, 1, 0, 3, vlFalse, vlTrue, NULL, NULL, IMAGE_FORMAT_BGRA8888},

Mixing table looks fine at least

@thegrb93
Copy link

thegrb93 commented Mar 9, 2021

Enum here

VTFLib/lib/VTFLib.h

Lines 86 to 101 in f5e7991

typedef enum tagVTFImageFormat
{
IMAGE_FORMAT_RGBA8888 = 0,
IMAGE_FORMAT_ABGR8888,
IMAGE_FORMAT_RGB888,
IMAGE_FORMAT_BGR888,
IMAGE_FORMAT_RGB565,
IMAGE_FORMAT_I8,
IMAGE_FORMAT_IA88,
IMAGE_FORMAT_P8,
IMAGE_FORMAT_A8,
IMAGE_FORMAT_RGB888_BLUESCREEN,
IMAGE_FORMAT_BGR888_BLUESCREEN,
IMAGE_FORMAT_ARGB8888,
IMAGE_FORMAT_BGRA8888,
IMAGE_FORMAT_DXT1,

@DBotThePony
Copy link
Author

DBotThePony commented Mar 9, 2021

That's not something to do with offset, VTFLib straight swap color channels (even IF that's byte offset, then why it doesn't happen with ABGR8888?):

In-game test, topleft and bottomleft are textures loaded by game engine, first is correctly encoded ARGB8888 texture (using my implementation), second is VTFEdit ARGB8888 encoded texture. Second column is my implementation of VTF texture reader.
gmod_sXIGLcRpsK

However, if i do next swap in my code from this
Code_5ahrURJsFY

To this
Code_lT4lNoFG16

Results are
gmod_3YPbIvtwqp

argb8888_vtfedit.zip

@thegrb93
Copy link

thegrb93 commented Mar 9, 2021

Perhaps a bug with the shifts+masks in

vlBool ConvertTemplated(vlByte *lpSource, vlByte *lpDest, vlUInt uiWidth, vlUInt uiHeight, const SVTFImageConvertInfo& SourceInfo, const SVTFImageConvertInfo& DestInfo)

@thegrb93
Copy link

Attempted to debug but compiling on VS2019 is a no-go. Undefined references via DDS Utilities

@thegrb93
Copy link

thegrb93 commented Mar 10, 2021

I compared your vtf with one saved by vtf-edit. The image data in yours starts at D0 and vtf-edit's starts at CE which agrees with the 2-byte offset mentioned before.

Nevermind, checked the pixel values and vtf-edit's start at D0 too. Must be broken shifting+masking as mentioned before.

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

No branches or pull requests

2 participants