Closed cabeca1143 closed 3 months ago
I can see an issue in your code - the data array that you get from GetBgra32Data
is row-first, but your loops are column-first. Try switching the loops in your code:
for (int y = 0; y < img.Height; y++)
{
for (int x = 0; x < img.Width; x++)
{
Also, ImageSharp has a built-in method to do this for you, try this code instead:
using var fileStream = File.OpenRead(InputPath);
var testFile = new VtfFile(fileStream);
var image = testFile.Images.First();
var pixelData = image.GetBgra32Data();
var outputImg = Image.LoadPixelData<Bgra32>(pixelData, image.Width, image.Height);
outputImg.SaveAsBmp(OutputPath);
Aw shoot, can't believe I overlooked that 🤡 Thanks for the tip!
As I started dumping sprays, I noticed quite a lot of them end up as single pixels. From my testing, 191 out of the 377 sprays end up as single pixels. I'll attach a few of them.
That's most likely because you are selecting the first image inside the VTF. For files with mipmaps, the first image is often the very smallest mipmap. Try selecting the largest image rather than the first one. (e.g. testFile.Images.MaxBy(x => x.Width)
).
With version 1.1.0 and the new Sledge.Formats.Texture.ImageSharp
extension package, I've added some extension methods to make this easier. Example code looks like:
using var file = File.OpenRead(@"path/to/some.vtf");
var vtf = new VtfFile(file);
using var image = vtf.ToImage<Rgba32>();
image.Save(@"path/to/some.png");
I've been trying convert TF2 sprays into bmp files, but the images end up all warped and I'm unable to pinpoint the issue.
This is the original image:![image](https://github.com/LogicAndTrick/sledge-formats/assets/72713387/1f7ae24f-25f6-491d-9d39-924ac3278645)
And this is what I end up with:![Output](https://github.com/LogicAndTrick/sledge-formats/assets/72713387/0a02ed2b-9c83-4e21-a6d8-25e3c22e0ca8)
Here's a snipet of my code:![image](https://github.com/LogicAndTrick/sledge-formats/assets/72713387/ea21a2d8-8058-4494-97cf-dc0d647c08da)
Perhaps I misinterpreted how the pixels in the byte array are organized? I couldn't find much information about it. The spray is in the
Dxt1
format.