Skip to content

Initial VTF support #6487

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

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open

Initial VTF support #6487

wants to merge 45 commits into from

Conversation

REDxEYE
Copy link
Contributor

@REDxEYE REDxEYE commented Aug 7, 2022

This pull request adds initial support for VTF image format

Changes proposed in this pull request:

  • Add support for Valve Texture Format images

@REDxEYE REDxEYE changed the title Initial VTF read support Initial VTF support Aug 7, 2022
@REDxEYE
Copy link
Contributor Author

REDxEYE commented Aug 7, 2022

Can I provide arguments to save the function? Like compression mode, flags and etc?

@radarhere
Copy link
Member

Like im.save("out.vtf", compression=...)? Yes. Those arguments will become part of the im.encoderinfo dictionary.

@REDxEYE
Copy link
Contributor Author

REDxEYE commented Aug 8, 2022

Yes, that's just what I needed, thanks!

@REDxEYE
Copy link
Contributor Author

REDxEYE commented Aug 9, 2022

@radarhere Do I need to encode the image row-by-row or i can go like 4 rows at once because Bcn works in blocks of 4 by 4 pixels?
I never worked with Pillow C API, so i need some help

@radarhere
Copy link
Member

@radarhere Do I need to encode the image row-by-row or i can go like 4 rows at once because Bcn works in blocks of 4 by 4 pixels? I never worked with Pillow C API, so i need some help

No, you don't have to.

A while ago, I attempted to implement DXT1 encoding. You might find that helpful - radarhere@363fab4

@REDxEYE
Copy link
Contributor Author

REDxEYE commented Aug 10, 2022

I see, your attempt is quite close to what I wrote, but I used a different way to get 2 main colors for the block. Can I reuse some of your code from 363fab4?

@radarhere
Copy link
Member

Feel free

@REDxEYE REDxEYE requested a review from radarhere August 12, 2022 00:17
@REDxEYE
Copy link
Contributor Author

REDxEYE commented Aug 12, 2022

@radarhere Can you please review my bcn encoder?

@radarhere
Copy link
Member

radarhere commented Aug 12, 2022

Slightly confused - this PR is still a draft, but you'd like a review?

Also, your lint problems could be resolved by just using the black formatting - REDxEYE#2. Is there a particular part of the styling that you dislike?

@REDxEYE
Copy link
Contributor Author

REDxEYE commented Aug 12, 2022

Slightly confused - this PR is still a draft, but you'd like a review?

Also, your lint problems could be resolved by just using the black formatting - REDxEYE#2. Is there a particular part of the styling that you dislike?

I'm asking for a encoder code review, pr itself not even close to be ready :)

@REDxEYE REDxEYE marked this pull request as ready for review August 24, 2022 18:08
@radarhere
Copy link
Member

#8807 has been merged with something close to my previous encoder.

I'm not opposed to using a different approach to improve it, but in the tests I added, I have

out = str(tmp_path / "temp.dds")
with Image.open(TEST_FILE_DXT1) as im:
  im.convert("RGB").save(out, pixel_format="DXT1")
assert_image_similar_tofile(im, out, 1.84)

If I run that against your encoder, I get https://github.com/radarhere/Pillow/actions/runs/13935788461/job/39003253301

AssertionError: average pixel value difference 4.1112 > epsilon 1.8400
assert 1.84 >= 4.1111907958984375

If I save the outputs, comparison.zip, and zoom in to visually compare them,

Screenshot 2025-03-19 at 11 16 21 am
I think it is clear that the version in main is closer to the original test file than the version in this PR.

Feel free to disagree.

@REDxEYE
Copy link
Contributor Author

REDxEYE commented Mar 21, 2025

Ye, will update PR later

@radarhere
Copy link
Member

Looking at https://developer.valvesoftware.com/wiki/VTF_(Valve_Texture_Format), it says

DXT1_ONEBITALPHA format does not properly work; use regular DXT1 with 1-bit alpha flag enabled instead.

Do you mind if I remove support from this PR?

@REDxEYE
Copy link
Contributor Author

REDxEYE commented Apr 26, 2025

Ye, i'm totally okay



@pytest.mark.parametrize(
"etalon_path, file_path, expected_mode, epsilon",
Copy link
Member

Choose a reason for hiding this comment

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

What does 'etalon' refer to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

supposed to be like reference image or something :)

@radarhere
Copy link
Member

All of the test images you've included are able to be distributed as part of Pillow under our license, yes?

@REDxEYE
Copy link
Contributor Author

REDxEYE commented May 6, 2025

Yes, these are test images i created myself, so they are non-copyrighted

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.

2 participants