3

I'm having some difficulty using the ImageMagick command line utility to properly convert a png to a DDS file with the DXT5 compression algorithm.

convert -format dds -define dds:compression=dxt5 leia.png leia.dds

This was done using Version: ImageMagick 6.8.9-10 Q16 x86_64 2016-09-14. I am able to view the file locally, so it appears correct. When I load it into OpenGL however, I just see artifacts all over the place (random color pixels). To confirm the generated file was a DDS file:

od -bc leia.dds | head

Which generated:

$ od -bc leia.dds | head
0000000   104 104 123 040 174 000 000 000 007 020 010 000 356 002 000 000
           D   D   S       |  \0  \0  \0  \a 020  \b  \0 356 002  \0  \0
0000020   024 003 000 000 120 014 000 000 000 000 000 000 001 000 000 000
         024 003  \0  \0   P  \f  \0  \0  \0  \0  \0  \0 001  \0  \0  \0
0000040   111 115 101 107 105 115 101 107 111 103 113 000 000 000 000 000
           I   M   A   G   E   M   A   G   I   C   K  \0  \0  \0  \0  \0
0000060   000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
          \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000100   000 000 000 000 000 000 000 000 000 000 000 000 040 000 000 000
          \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0      \0  \0  \0

You can see the first part of the header which contains the DDS header.

So for giggles, I decided, hey, maybe I should try converting this image using a separate utility, just to make sure there is nothing wrong with the file. When I then loaded in this file to OpenGL, it worked correctly.

When the file downloaded, I also checked the header again and saw:

od -bc leia-online.dds | head
0000000   104 104 123 040 174 000 000 000 007 020 010 000 356 002 000 000
           D   D   S       |  \0  \0  \0  \a 020  \b  \0 356 002  \0  \0
0000020   024 003 000 000 300 012 011 000 000 000 000 000 001 000 000 000
         024 003  \0  \0 300  \n  \t  \0  \0  \0  \0  \0 001  \0  \0  \0
0000040   111 115 101 107 105 115 101 107 111 103 113 000 000 000 000 000
           I   M   A   G   E   M   A   G   I   C   K  \0  \0  \0  \0  \0
0000060   000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
          \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000100   000 000 000 000 000 000 000 000 000 000 000 000 040 000 000 000
          \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0      \0  \0  \0
  1. It appears the online tool is using ImageMagick, same as I.
  2. If you look at the first result it, Octals 20-23 are: 120 014 000 000 vs the online result of: 300 012 011 000. According to this indexes 20-23 point to the 'byte count'

So basically, my underlying question is this: How do I properly convert a png file to a dds texture using ImageMagick?

Update:

The online imagemagick generated the image header with:

width: 788 height: 750 linearSize: 592576 mipmap_count: 1

My local version of imagemagick generated the image header with:

width: 788 height: 750 linearSize: 3152 mipmap_count: 1

So I wonder if I'm missing a flag somewhere to get it to correctly write the header that the online version might be using?

Deftness
  • 265
  • 1
  • 4
  • 21
  • 1
    You first ask about DTX. Then you say DDS. I know little about each, but apparently they are different. So which is it? The best I can offer is to look at the ImageMagick pages for defines for DDS. See http://www.imagemagick.org/script/formats.php and http://www.imagemagick.org/script/command-line-options.php#define – fmw42 Jun 21 '17 at 22:08
  • My fault, I just read: http://www.buckarooshangar.com/flightgear/tut_dds.html. So I'm using the DDS file format to store an image compressed by DXT5 algorithm. I'll update the question clarifying this. – Deftness Jun 21 '17 at 22:25
  • I just did a quick test, and the same command created an image with a correct linearSize. I noticed that ImageMagick converts to the most appropriate format (asked for dxt5, got dxt1 since there were no alpha channel), so it could be that. Check the fourCC of the invalid image. – pleluron Jun 21 '17 at 23:07
  • Yup, just checked the color codes, and both say they're DXT5. Hmm strange - could there be something amiss with my version of Imagemagick? – Deftness Jun 21 '17 at 23:11
  • Could be. What is the format of the input image? – pleluron Jun 21 '17 at 23:17
  • The input image was just a standard PNG image (Generic RGB Profile) – Deftness Jun 22 '17 at 00:41

1 Answers1

2

As it turns out, it was a just a matter of my ImageMagick version. Upgrading from

ImageMagick 6.8.9-10 Q16 x86_64 2016-09-14 http://www.imagemagick.org

to

ImageMagick 7.0.6-0 Q16 x86_64 2017-06-12 http://www.imagemagick.org

fixed it. Thanks for everyone's help!

Deftness
  • 265
  • 1
  • 4
  • 21