NeilJed / VTFLib

VTFLib is a LGPL open source programming library that provides a C and C++ API for reading and writing Valve VTF and VMT format image files.
GNU Lesser General Public License v2.1
157 stars 50 forks source link

ARGB8888 is read by VTFLib as GBAR8888 #13

Open DBotThePony opened 3 years ago

DBotThePony commented 3 years ago

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

thegrb93 commented 3 years ago

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

thegrb93 commented 3 years ago

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

thegrb93 commented 3 years ago

https://github.com/NeilJed/VTFLib/blob/ae19fcff1d4b5aa7e76ad3a69838f9fe77699d95/VTFLib/VTFFile.cpp#L3592-L3604 Mixing table looks fine at least

thegrb93 commented 3 years ago

Enum here https://github.com/NeilJed/VTFLib/blob/f5e7991c92232111ca6e6e54aba130f43327cfd2/lib/VTFLib.h#L86-L101

DBotThePony commented 3 years ago

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 commented 3 years ago

Perhaps a bug with the shifts+masks in https://github.com/NeilJed/VTFLib/blob/ae19fcff1d4b5aa7e76ad3a69838f9fe77699d95/VTFLib/VTFFile.cpp#L3772

thegrb93 commented 3 years ago

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

thegrb93 commented 3 years ago

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.