Python Plugin - DDS Support (windows only)

Hi everyone,

I developed a Python plugin for Krita that allows to export the current file/document open in Krita into DDS format. You may find the download link, installation and usage instructions in the GitHub page here:
DDS File Exporter for Krita

I am currently working on an additional plugin that also allows to import DDS files into Krita. I have finished developing another Python plugin that allows to import DDS files into Krita as PNG:
DDS File Importer for Krita

Let me know your thoughts on it and, hopefully, this will provide a basis for Krita developers to incorporate support to this format into the native application.

Please note that these plugins are based on a Windows command line utility, meaning that they can only be used in a Windows operating system.

11 Likes

Welcome to the forum, @esuriddick. I don’t know what DDS is but I appreciate the work that must have gone into creating a Krita plugin.

1 Like

Thank you for this welcoming message @Sooz :slight_smile:

The main purpose of the DirectDraw Surface (DDS) file format is to provide a compact and efficient way to store and transmit 3D graphics and animations in Windows-based applications. It was developed by Microsoft to provide a way to display complex 3D graphics and animations on computers with limited processing power, which is why it is commonly found in the gaming industry (e.g., Skyrim, Space Engineers, etc.).

Since I’ve mainly found it in the gaming industry, the only alternatives that I had until now when modding a game was to either resort to Photoshop, which has an official plugin released by Nvidia, or GIMP, which has an unofficial plugin. So every time I had to work with this file format, I had to install GIMP specifically just to import/export images in this format. I got tired of it x)

1 Like

If I understand correctly, these plugins are Windows-only since they rely on a Windows command line utility? If so, I feel that should be mentioned somewhere.

1 Like

Correct. I added the ā€œwindowsā€ tag when I created the topic, but I’ll include this in the original topic. Thanks for the heads up!

:two_hearts: :two_hearts: :two_hearts: :two_hearts: :two_hearts: u are the best

1 Like

There’s some issue.

  • When I try to import a dds file (BC7-SRGB), it opens with a darker color, not the original color. Because of that, when I export it as BC7-SRGB, the colors are darker than the original. However, when exported as BC7-UNORM, it looks like the original colors. Is it all importing as linear?

  • For textures that use alpha values, they don’t seem to be exporting correctly. it could be my mistake, so I’m still not sure about this.

Hi NAES,

  • When importing into Krita, the output format is hardcoded as ā€œR8G8B8A8_UNORMā€, and the colorspace is set to ā€œsRGBiā€ (used when only the input is in sRGB).
  • I tried some texture files from Space Engineers and the alpha values seemed OK on my end.

Would it be possible to share examples of textures for both issues to determine whether there is something I can do to improve the plugin?


This difference is in the color.

When I exported it back to BC7-SRGB with the imported left, the colors came out too dark. It wasn’t until I exported to BC7-UNORM (and saw it applied) that the colors looked more like the original.


This is what I imported with a edited code that was suggested to me on social media (regarding the issue). I don’t know if this is a perfect solution, but I found that replacing -srgbi with -srgb made the darkening go away. I’m not sure if it will cause any other issues.

Hi again,

Thanks for the swift reply :slight_smile: I’m not an artist nor an expert on the topic of colorspaces and formats, but indeed I think I’ll improve upon the importer to give the possibility to import in SRGB or otherwise.
What you did shouldn’t cause any issue on the importing :slight_smile: All you did was to tell the program that the output file should be in SRGB as well, which explains the darkening issues.

Concerning the second issue (alpha values), did you reach any conclusion of whether you had an issue due to the plugin or everything is good?



Some files, like this one, have things that need to invert alpha to be visible.


However, when I export this and import it back in, the values that should be visible when invert alpha are missing.
I didn’t touch a thing, I just exported it and then imported it.

Oops, there’s a limit on the number of images. I’ll split it up.

image
As an alternative, in most cases, organizing your layers this way will also store data that requires invert alpha.


However, when I export to DDS Exporter and try to invert alpha, I still don’t see it.


I saved the same file as a png with Krita’s own export function (not DDS Exporter) and then invert alpha it, and it’s preserved just fine.

I’m not sure what the causes of difference it.


Somehow, I fixed it. I don’t know if that’s going to cause any other problems, I just changed -pmalpha to -alpha and it worked. I think it’s because the things that require this alpha inversion use separate alpha channels, I don’t know.

During this process, I also realized that exporting to SRGB would cause the image to be whitened (the opposite problem with the DDS Importer).

Based on my experience with the DDS Importer, I edited the code as follows.

                    compression_type_command = compression_type.currentText().split(' (')[0]

↓

                    if compression_type.currentText().split(' (')[0] in 'SRGB':
                        compression_type_command = '-srgb'
                    else:
                        compression_type_command = compression_type.currentText().split(' (')[0]

It worked anyway, this fixed it, but I’m not sure if it’s the right solution.

1st issue - Improper import of DDS with ā€˜_SRGB’ format
I decided to change in the DDS Importer to ā€œ-srgbā€ for all cases instead of ā€˜-srgbi’. I converted the same image to BC7_UNORM and BC7_UNORM_SRGB. Using -srgb retrieved the image that I was previewing with PicoPixel, so I’ll change it to it for good and you shouldn’t have to worry about it in the future :slight_smile:

2nd issue - alpha channels
I’ll add an option to allow for separate alpha channels. Indeed, I always made use of only a single channel, so I didn’t investigate this further before.

3rd issue - whitening of image when exporting
I should note that using BC7_UNORM_SRGB also whitened my original image, while BC7_UNORM kept its original colours:


If I am reading correctly what you changed, the result will always be the same, which is the original command. I tried the following below the original compression_type_command line to accomplish what I think you were aiming for:

compression_type_command = compression_type.currentText().split(' (')[0]
if compression_type.currentText().split(' (')[0].split('_')[-1].upper() == 'SRGB':
    colorspace_command = '-srgb'
else:
    colorspace_command = ''

I also changed the command line to consider this new command:

args = [converter_path
                            ,"-y"
                            ,"-ft"
                            ,"DDS"
                            ,"-f"
                            ,compression_type_command
                            ,colorspace_command
                            ,generate_mipmaps_command
                            ,'-pmalpha'
                            ,force_DX_header_command
                            ,"-o"
                            ,output_file_path
                            ,temp_file_path]

However, I am unable to convert the file and I return an error. I also tried to change to compression_type_command = ā€˜-srgb’, but it returns an error when converting to DDS. Let me know if you were able to solve this whitening when exporting to a _SRGB format and how you did it to incorporate the fix :slight_smile:

Well, I applied it with the code I modified and it worked fine. I also tried applying the code you posted, and it worked the same. (Yes, no whitening)

I’m not a developer, so I have no idea why this works, but at least on my case, these codes seem to produce correct-looking results.

I’m sorry I can’t provide more help or information.

I gave another shot to the code that I shared, and it worked. The only format where I get an error is BC7_UNORM_SRGB. What format were you exporting to?

I exported as BC7_UNROM_SRGB.

Thanks for your help. I really appreciate it.

I found the issue or what I think you might have done to surpass the issue. Texconv has been updated since I last shared the plugin. It now allows to convert without any issues using this command for BC7_UNORM_SRGB. I’ll update also this file in the plugin and update it.
Thank you for your help in debugging the issue! :slight_smile:

1 Like

Hey man! Been using your plugin, however I need to export about 200 different .dds files in roughly one go, and probably more in the future. Do you think it would be possible to have an exporter that exports each layer in a file individually, with the same .dds BCE/DXT criteria?

Thanks for the plugin anywho, good job :slight_smile:

Hi Ja_rl,

Would a plugin that allows you to select a folder and then convert all images there to DDS be sufficient for your purposes?

Not sure if the goal is to convert DDS to another format or to convert from another format to DDS, but my question above remains :slight_smile:

1 Like