Page 1 of 1

Sepia filter doesn't handle alpha channel (corrupt output)

Posted: 2014-04-02T23:41:34-07:00
by mortoray
I hit a situation where the generated image is corrupt. It happens when I resize a WEBP image and apply a sepia filter. If I don't resize, or I don't apply a filter, or I apply a different filter, it doesn't happen.

Code: Select all

convert tux.webp -resize 190 -sepia-tone 50% out.png
Below is the input image. Sorry, that server doesn't server WEBP content-type correctly, so you'll have to download to view it.

Image
( http://disemia.com/temp/tux.webp )

The resulting output:

Image

Re: Corrupt output image wit sepia and WEBP

Posted: 2014-04-02T23:43:21-07:00
by mortoray
Version info:
Version: ImageMagick 6.8.8-10 Q16 x86_64 2014-04-01 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC OpenMP
Delegates: bzlib djvu fontconfig freetype jng jpeg lcms lqr openexr pangocairo png tiff webp x xml zlib

WebP Version 0.4.0

gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

Re: Corrupt output image wit sepia and WEBP

Posted: 2014-04-02T23:49:03-07:00
by mortoray
It appears this can happen with any combination of an alpha input, the sepia filter, and alpha output.

Re: Corrupt output image wit sepia and WEBP

Posted: 2014-04-03T09:59:02-07:00
by fmw42
Your command works fine for me under IM 6.8.8.10 Q16 Mac OSX Snow Leopard


Version: ImageMagick 6.8.8-10 Q16 x86_64 2014-03-28 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib cairo fftw fontconfig freetype gslib jbig jng jpeg lcms lqr ltdl lzma openexr png ps rsvg tiff webp x xml zlib

See if disabling OpenMP helps.

Possibly also a delegate library version issue?

Re: Corrupt output image wit sepia and WEBP

Posted: 2014-04-03T22:13:02-07:00
by mortoray
How do I disable OpenMP?

Note this only seems to happen with the sepia filter. I've not seen the problem with any other transformation yet. And it appears consistent now, any transparent input into the sepia filter causes this issue.

Re: Corrupt output image wit sepia and WEBP

Posted: 2014-04-03T22:23:22-07:00
by fmw42
mortoray wrote:How do I disable OpenMP?
Typically it is done when you run

./configure --disable-openmp

when installing from source. see http://www.imagemagick.org/script/advan ... #configure

If you installed from binary or source, then try your command with

Code: Select all

MAGICK_THREAD_LIMIT=1 convert ....
or

Code: Select all

convert -limit thread 1 ....

Most likely, you may need to update your libwebp delegate library and reinstall IM. My version is webp @0.3.1_0

Re: Corrupt output image wit sepia and WEBP

Posted: 2014-04-03T22:28:37-07:00
by mortoray
I'm running webp 0.4.0 (downloaded the newest a few days ago). But as I mentioned, it isn't limited to webp. I'm seeing the problem with PNG files as well.

The two thread limit options didn't change the result.

Re: Corrupt output image wit sepia and WEBP

Posted: 2014-04-03T23:00:20-07:00
by fmw42
Sorry, I have no further ideas.

Re: Corrupt output image wit sepia and WEBP

Posted: 2014-04-03T23:09:49-07:00
by mortoray
The same thing also happens on the version of IM in Ubuntu 12.04. So it's not likely something I configured wrong.

Defect in fx.c found

Posted: 2014-04-04T00:12:43-07:00
by mortoray
I believe I found the problem. On fx.c:4122 clone image is called with an explicit width/height, meaning the source pixels are not copied:

Code: Select all

sepia_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
The problem is that the alpha channel is never set in the remainder of the function: only SetPixelRed/Green/Blue are called. Thus I believe the alpha channel just stays in in its uninitialized state.

If I put 0,0 in CloneImage for the size the result is as expected (though slightly wasteful copying). I'm not sure how else the alpha channel should be copied.

Re: Sepia filter doesn't handle alpha channel (corrupt outpu

Posted: 2014-04-13T21:00:45-07:00
by mortoray
Any update on this defect?

Re: Sepia filter doesn't handle alpha channel (corrupt outpu

Posted: 2014-04-13T23:48:31-07:00
by dlemstra
This has been fixed in ImageMagick 6.8.9-0.

Re: Sepia filter doesn't handle alpha channel (corrupt output)

Posted: 2018-02-21T12:23:07-07:00
by Alexvb6
Hi,

For those of you who are forced to use ImageMagick below 6.8.9, and still need to keep and convey the initial Alpha channel of the source PNG image, here is a fully working workaround.

The trick is to extract the initial Alpha channel of the PNG image, then to reapply it with the "Composite" method after having applied the "-sepia" operator :

I hope it will help some people :)

Code: Select all

convert flash.png ^
-set colorspace RGB -alpha extract -write mpr:ExtractedInitialImageAlpha ^
+delete ^

flash.png -sepia-tone 80% -write mpr:SepiaImg ^
+delete ^

mpr:SepiaImg ^
mpr:ExtractedInitialImageAlpha ^
-alpha Off ^
-compose CopyOpacity -composite ^
RESULT-Sepia-With-Alpha.png