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

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
mortoray
Posts: 17
Joined: 2014-02-12T21:36:17-07:00
Authentication code: 6789

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

Post 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
Last edited by mortoray on 2014-04-04T00:10:14-07:00, edited 2 times in total.
mortoray
Posts: 17
Joined: 2014-02-12T21:36:17-07:00
Authentication code: 6789

Re: Corrupt output image wit sepia and WEBP

Post 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
mortoray
Posts: 17
Joined: 2014-02-12T21:36:17-07:00
Authentication code: 6789

Re: Corrupt output image wit sepia and WEBP

Post by mortoray »

It appears this can happen with any combination of an alpha input, the sepia filter, and alpha output.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Corrupt output image wit sepia and WEBP

Post 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?
mortoray
Posts: 17
Joined: 2014-02-12T21:36:17-07:00
Authentication code: 6789

Re: Corrupt output image wit sepia and WEBP

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

Re: Corrupt output image wit sepia and WEBP

Post 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
mortoray
Posts: 17
Joined: 2014-02-12T21:36:17-07:00
Authentication code: 6789

Re: Corrupt output image wit sepia and WEBP

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

Re: Corrupt output image wit sepia and WEBP

Post by fmw42 »

Sorry, I have no further ideas.
mortoray
Posts: 17
Joined: 2014-02-12T21:36:17-07:00
Authentication code: 6789

Re: Corrupt output image wit sepia and WEBP

Post 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.
mortoray
Posts: 17
Joined: 2014-02-12T21:36:17-07:00
Authentication code: 6789

Defect in fx.c found

Post 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.
mortoray
Posts: 17
Joined: 2014-02-12T21:36:17-07:00
Authentication code: 6789

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

Post by mortoray »

Any update on this defect?
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

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

Post by dlemstra »

This has been fixed in ImageMagick 6.8.9-0.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Alexvb6
Posts: 49
Joined: 2012-10-12T16:50:15-07:00
Authentication code: 67789

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

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