[patch] non-square DDS output images have an incorrect number of mipmaps

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
snake5
Posts: 1
Joined: 2016-09-14T01:53:15-07:00
Authentication code: 1151

[patch] non-square DDS output images have an incorrect number of mipmaps

Post by snake5 »

Non-square DDS images generated by ImageMagick do not have mipmaps levels up to 1x1, which are necessary for the image to be successfully loaded in graphics APIs like OpenGL (otherwise they'll appear black instead with mipmap minification filtering enabled).

https://www.opengl.org/sdk/docs/man/htm ... eter.xhtml ("until the final mipmap, which has dimension 1×1")

This patch fixes the issue:

Code: Select all

diff --git a/coders/dds.c b/coders/dds.c
index a8ec9cc..dd2b493 100644
--- a/coders/dds.c
+++ b/coders/dds.c
@@ -2671,7 +2671,7 @@ static MagickBooleanType WriteDDSImage(const ImageInfo *image_info,
         {
           columns=image->columns;
           rows=image->rows;
-          while (columns != 1 && rows != 1 && mipmaps != maxMipmaps)
+          while ((columns != 1 || rows != 1) && mipmaps != maxMipmaps)
           {
             columns=DIV2(columns);
             rows=DIV2(rows);
@@ -3017,7 +3017,7 @@ static MagickBooleanType WriteMipmaps(Image *image, const size_t pixelFormat,

   for (i=0; i< (ssize_t) mipmaps; i++)
   {
-    resize_image = ResizeImage(image,columns/2,rows/2,TriangleFilter,
+    resize_image = ResizeImage(image,DIV2(columns),DIV2(rows),TriangleFilter,
       exception);

     if (resize_image == (Image *) NULL)
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: [patch] non-square DDS output images have an incorrect number of mipmaps

Post by magick »

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
Post Reply