nickbabcock / Pfim

.NET Standard targa (.tga) and direct draw surface (.dds) image decoder
https://nickbabcock.github.io/Pfim/
MIT License
110 stars 18 forks source link

(DDS) Some dds files are not readable. #107

Open lazydevyo opened 1 year ago

lazydevyo commented 1 year ago

I know this is a known issue, I want to read a dds file on runtime in Unity. pfim already supports more dds types than Unity on runtime. but some DDS files do not seem to be readable. I'm not exactly sure what type of DDS file it is. photoshop seems to read it without issues using the Nvidia plugin. In Photoshop is a single gray channel image. Any idea if it would anytime possible to read this kind of DDSs?

nickbabcock commented 1 year ago

Feel free to upload a sample image of this problem

lazydevyo commented 1 year ago

Here is the image DDS

nickbabcock commented 1 year ago

That image looks to be readable. The end result is that the image can be displayed but it looks off as the image lacks a blue channel and Pfim kinda wants to shoehorn one in. Is that what this issue is about, that images that lack a specific color channel look incorrect?

lazydevyo commented 1 year ago

I'm getting System.NotImplementedException: The method or operation is not implemented.

`  var format = image.Format switch
            {
                ImageFormat.Rgba32 => PixelFormat.Format32bppArgb,
                _ => throw new NotImplementedException(),// see the sample for more details
            };`
     Edit: btw I'm using the command line to convert a bulk of images, and then read them as pngs in Unity, using C#s process(); , I tried pfim directly in Unity, but didn't have good luck. I have, to try the mono sample, but after I get the command line to work first.
nickbabcock commented 1 year ago

Yeah that NotImplementedException is a todo for you to fill out. It is up to the caller to take the data that Pfim provides and make something of use for it like how some of the samples do it: https://github.com/nickbabcock/Pfim/blob/14535949c87f023e8586741c5f09daa115a2ee8c/src/Pfim.Viewer.Forms/Form1.cs#L35-L60

lazydevyo commented 1 year ago

The final png image indeed looks wrong, it has all three channels (RGB), while the original DDS has a single (Gray) channel. which means it's a grayscale image. I think Pfim should look at the channels and export with the same channel structure, or a supported structure for pngs. I got close to the original DDS, by converting the png to grayscale like so: byte grayscale = (byte)(originalColor.R 0 + originalColor.G 0 + originalColor.B * 1); Does not look perfect but it's something I can work with. png