[patch] non-square DDS output images have an incorrect number of mipmaps
Posted: 2016-09-14T02:03:43-07:00
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:
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)