Write .dds-file with custom mipmaps - possible?

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
User avatar
HansCz
Posts: 10
Joined: 2016-08-03T19:43:12-07:00
Authentication code: 1151

Write .dds-file with custom mipmaps - possible?

Post 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
Last edited by HansCz on 2016-08-03T21:24:12-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

Does the DDS format support a mip-map structure? If so can you point the developers to that format description.
User avatar
HansCz
Posts: 10
Joined: 2016-08-03T19:43:12-07:00
Authentication code: 1151

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

Post 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[]
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
User avatar
HansCz
Posts: 10
Joined: 2016-08-03T19:43:12-07:00
Authentication code: 1151

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

Post 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?
Last edited by HansCz on 2016-08-03T21:26:01-07:00, edited 1 time in total.
User avatar
HansCz
Posts: 10
Joined: 2016-08-03T19:43:12-07:00
Authentication code: 1151

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

Post 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.
User avatar
HansCz
Posts: 10
Joined: 2016-08-03T19:43:12-07:00
Authentication code: 1151

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

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
User avatar
HansCz
Posts: 10
Joined: 2016-08-03T19:43:12-07:00
Authentication code: 1151

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

Post by HansCz »

Thanks :) A PM has been sent. I'll post any responses here.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

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

Post 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
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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?
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

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

Post 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.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
User avatar
HansCz
Posts: 10
Joined: 2016-08-03T19:43:12-07:00
Authentication code: 1151

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

Post 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.
Post Reply