region not restricting modification

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
6bit
Posts: 8
Joined: 2016-11-21T11:02:09-07:00
Authentication code: 1151

region not restricting modification

Post by 6bit »

Hi,

I had a problem when using -region to clear an area in a (RGBA) png: areas outside the region were being changed.
It appears that the RGB of areas outside the region are multiplied by the A value.
I think this must be a bug not a feature.
I have reduced the problem to the following micro size:

quark:Example$ magick -size 10x10 xc:none -fill '#FAFAFAFA' -draw 'rectangle 4,4 5,4' -fill '#FFFFFFFF' -draw 'rectangle 4,5 5,5' PNG32:a.png
quark:Example$ magick a.png -region 2x2+0+0 -alpha transparent +region PNG32:b.png
quark:Example$ magick a.png -format '%[pixel:p{4,4}]\n' info:-
srgba(250,250,250,0.980392)
quark:Example$ magick b.png -format '%[pixel:p{4,4}]\n' info:-
srgba(245,245,245,0.980392)

Since the -alpha transparent operation was in a -region not including the displayed pixel, I suppose the pixel should not be different.
My goal is simply to clear (set to R,G,B,A=0,0,0,0) an arbitrary rectangular region without effecting any other part of my image.
Maybe there is another way...?

I am running:
quark:Example$ magick -version
Version: ImageMagick 7.0.9-17 Q16 x86_64 2020-01-24 https://imagemagick.org
Copyright: © 1999-2020 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP(3.1)
Delegates (built-in): bzlib freetype heic jng jp2 jpeg lcms ltdl lzma openexr png tiff webp xml zlib

Installed via brew on MacOS Mojave.

Thx

User avatar
fmw42
Posts: 26292
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: region not restricting modification

Post by fmw42 »

-region is different in IM 7. See the porting guide at https://imagemagick.org/script/porting.php#cli. This is not a bug.

Use a write mask. See https://imagemagick.org/Usage/masking/#write_mask

User avatar
magick
Site Admin
Posts: 11224
Joined: 2003-05-31T11:32:55-07:00

Re: region not restricting modification

Post by magick »

Fred, the -region option does have behavioral changes from IMv6. IMv6 utilizes a 4 byte per pixel image to mask and the processing is embedded exclusively in the pixel cache. With IMv7, the mask is just another channel. Its more efficient and is more powerful because you can set a read or write mask or both. With IMv7, each algorithm is responsible to check the mask before reading or writing. This check was not performed when setting the alpha channel. We committed a patch to the ImageMagick Git repo to fix this bug and now @6bit's command lines work as expected.

User avatar
fmw42
Posts: 26292
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: region not restricting modification

Post by fmw42 »

OK. Thanks magick. Sorry, 6bit.

6bit
Posts: 8
Joined: 2016-11-21T11:02:09-07:00
Authentication code: 1151

Re: region not restricting modification

Post by 6bit »

All good.

Thanks.

Post Reply