Page 1 of 2

Write .dds-file with custom mipmaps - possible?

Posted: 2016-08-03T19:59:01-07:00
by HansCz
Given an image list containing quadratic images with side lengths in powers of 2, would it be possible to write these out to a dds file as mipmaps?

For example:

image list contains 6 images:

image 1: 1024px x 1024px
image 2: 512px x 512px
image 3: 256px x 256px
image 4: 128px x 128px
image 5: 64px x 64px
image 6: 32px x 32px

I would like it to be exported as a .dds file with image 1 as the main image, and all the following images as mipmaps.

My use case attempts to achieve certain image effects when applying this dds file to a shader. In doing this, the conventional application of mipmaps as automatically generated, downscaled versions of the main image (Image 1 in my example) is not sufficient. From reading the docs, I gather this is what ImageMagick currently does.

In short, I need to be able to manually specify the contents of each mipmap.

Is this currently possible? If not, would it be possible to implement?

I'm currently using version 6.9.5-4 of ImageMagick.

Thank you for your time.

- Hans

Re: Write .dds-file with custom mipmaps - possible?

Posted: 2016-08-03T20:18:15-07:00
by fmw42
IM currently does not have any built in support for mipmaps, as far as I know. The closest is to write a pyramid tiff.

Re: Write .dds-file with custom mipmaps - possible?

Posted: 2016-08-03T20:20:31-07:00
by fmw42
Does the DDS format support a mip-map structure? If so can you point the developers to that format description.

Re: Write .dds-file with custom mipmaps - possible?

Posted: 2016-08-03T20:37:40-07:00
by HansCz
Good call.
The closest to a format description I have been able to find so far, is this:

Reference for DDS
https://msdn.microsoft.com/en-us/librar ... s.85).aspx

Programming Guide for DDS
https://msdn.microsoft.com/en-us/librar ... s.85).aspx

and yes, it does support a mipmap structure. see:

DDS File Layout
https://msdn.microsoft.com/en-us/librar ... le_Layout1
...A pointer to an array of bytes that contains the main surface data.


BYTE bdata[]


A pointer to an array of bytes that contains the remaining surfaces such as; mipmap levels, faces in a cube map, depths in a volume texture. Follow these links for more information about the DDS file layout for a: texture, a cube map, or a volume texture.


BYTE bdata2[]

Re: Write .dds-file with custom mipmaps - possible?

Posted: 2016-08-03T20:51:34-07:00
by fmw42
According to that document, DDS does support mipmap.

The IM page on formats at http://www.imagemagick.org/script/formats.php does imply that mipmaps are supported. See the -define for using that. Sorry I know little about DDS format. Perhaps one of the Windows users can comment further or one of the IM developers regarding its use.

Re: Write .dds-file with custom mipmaps - possible?

Posted: 2016-08-03T21:13:33-07:00
by HansCz
Thanks, Fred. I'll look into it.

(shuffles off to read about -define and what it can do for DDS files...)

maybe the current DDS writer can be modified to assemble mipmaps from an imagelist, rather than autogenerating them from a base image. Hmmm....

In the meantime, I found this:

DirectXTex texture processing library
https://github.com/Microsoft/DirectXTex

It looks like it has code for generating a .DDS file with mipmaps, but again, auto-generated.

Maybe it could serve as a base for further investigation?

Re: Write .dds-file with custom mipmaps - possible?

Posted: 2016-08-03T21:16:37-07:00
by HansCz
I would like to talk to the person(s) who wrote the writer to determine if this is even feasible. He/she/they must be out there somewhere...I'll have a look around.

Re: Write .dds-file with custom mipmaps - possible?

Posted: 2016-08-03T21:37:35-07:00
by HansCz
searchcode.com to the rescue. It seems the current author is a certain Dirk Lemstra,
https://searchcode.com/codesearch/view/115223297/

Code: Select all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%                            DDDD   DDDD   SSSSS                              %
%                            D   D  D   D  SS                                 %
%                            D   D  D   D   SSS                               %
%                            D   D  D   D     SS                              %
%                            DDDD   DDDD   SSSSS                              %
%                                                                             %
%                                                                             %
%           Read/Write Microsoft Direct Draw Surface Image Format             %
%                                                                             %
%                              Software Design                                %
%                             Bianca van Schaik                               %
%                                March 2008                                   %
%                               Dirk Lemstra                                  %
%                              September 2013                                 %
Now to find him :)

It seems he is on github:
https://github.com/dlemstra

...and he is the latest committer to DDS.c as of today:
https://github.com/ImageMagick/ImageMag ... ders/dds.c

He has a profile on this very forum. Yay!:
memberlist.php?mode=viewprofile&u=24371

I'll compose a PM and see if he will answer.

Re: Write .dds-file with custom mipmaps - possible?

Posted: 2016-08-03T22:01:56-07:00
by fmw42
You can PM him on this forum as dlemstra. He answers on both forums.

But if DDS does not support custom mipmaps, then I would be surprised if IM will support that. Be he and magick provide the definitive answer.

Re: Write .dds-file with custom mipmaps - possible?

Posted: 2016-08-03T22:09:13-07:00
by HansCz
Thanks :) A PM has been sent. I'll post any responses here.

Re: Write .dds-file with custom mipmaps - possible?

Posted: 2016-08-04T12:47:53-07:00
by dlemstra
The dds coder currently auto generates the DDS mipmaps. I am open to adding this feature but I wonder how we should make this feature available. Maybe this:

Code: Select all

convert image1.png -define dds:mipmap-files="image2.png, image3.png" image1.dds

Re: Write .dds-file with custom mipmaps - possible?

Posted: 2016-08-04T12:54:45-07:00
by snibgo
Wouldn't it be more logical to take all the images in the current list, with a simpler define? Like this:

Code: Select all

convert image1.png image2.png image3.png -define dds:fromlist image1.dds

Re: Write .dds-file with custom mipmaps - possible?

Posted: 2016-08-04T12:57:19-07:00
by fmw42
HansCz wrote:I would like it to be exported as a .dds file with image 1 as the main image, and all the following images as mipmaps.
Just for clarification are you saying you want only one output image whose different resolution maps come from the different input images? Or are you asking for multiple output images with mipmaps for each?

Re: Write .dds-file with custom mipmaps - possible?

Posted: 2016-08-05T12:04:09-07:00
by dlemstra
snibgo wrote:Wouldn't it be more logical to take all the images in the current list, with a simpler define? Like this:

Code: Select all

convert image1.png image2.png image3.png -define dds:fromlist image1.dds
I also though about using this but I had the idea that this would be bad if you wanted to write multiple files in the same command. But now thinking about it that shouldn't be an issue. I'll talk with magick and see if he also thinks this is a good idea and then add it.

Re: Write .dds-file with custom mipmaps - possible?

Posted: 2016-08-05T20:17:24-07:00
by HansCz
This is great news! :) Glad to hear you are willing to consider it. Eagerly awaiting any further developments!

fmw42 wrote:Just for clarification are you saying you want only one output image whose different resolution maps come from the different input images? Or are you asking for multiple output images with mipmaps for each?
One output image with custom mipmaps was my initial thought. But anything that can speed up batching would be a nice addition.

Later there might also be texture arrays and 3d textures to consider. This would most likely demand some careful consideration of how the command should be formatted to avoid ambiguity as much as possible... But first things first :) I'm just happy you're willing to consider simple custom mipmaps on one texture for now :)

I know quite a few shader programmers in the Unity game engine community are going to love this.

Again. Thank you for considering this.