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

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

Open
lazydevyo opened this issue May 15, 2023 · 6 comments
Open

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

lazydevyo opened this issue May 15, 2023 · 6 comments

Comments

@lazydevyo
Copy link

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?

@lazydevyo lazydevyo changed the title (DDS) Some dds files are not getting read. (DDS) Some dds files are not readable. May 15, 2023
@nickbabcock
Copy link
Owner

Feel free to upload a sample image of this problem

@lazydevyo
Copy link
Author

Here is the image DDS

@nickbabcock
Copy link
Owner

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
Copy link
Author

lazydevyo commented May 22, 2023

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
Copy link
Owner

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:

switch (image.Format)
{
case ImageFormat.Rgb24:
format = PixelFormat.Format24bppRgb;
break;
case ImageFormat.Rgba32:
format = PixelFormat.Format32bppArgb;
break;
case ImageFormat.R5g5b5:
format = PixelFormat.Format16bppRgb555;
break;
case ImageFormat.R5g6b5:
format = PixelFormat.Format16bppRgb565;
break;
case ImageFormat.R5g5b5a1:
format = PixelFormat.Format16bppArgb1555;
break;
case ImageFormat.Rgb8:
format = PixelFormat.Format8bppIndexed;
break;

@lazydevyo
Copy link
Author

lazydevyo commented May 23, 2023

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

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