Possible bug compose:clamp=off Perl Magick

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
miket
Posts: 60
Joined: 2016-08-12T13:19:13-07:00
Authentication code: 1151

Possible bug compose:clamp=off Perl Magick

Post by miket »

Hi,

Version: ImageMagick 7.0.5-3 Q16 x86_64 2017-03-16 HDR

I'm still having issues getting perl magick to switch off the compose:clamp option.

I've tried a number of options, to no avail.

Using $image->Set(option=>"compose:clamp=off") should, I think, work since that option in PM calls DefineImageOption.

Appropriate code in PM is:

Code: Select all

case 'o':
    {
      if (LocaleCompare(attribute,"option") == 0)
        {
          if (info)
            DefineImageOption(info->image_info,SvPV(sval,na));
          break;
        }
I've tried a number of permutations and combinations in the test code below:

Code: Select all

    my $image_a = Image::Magick->new;
    $image_a->Read('r.png');
    my $image_b = $image_a->Clone();
    $image_b->Color(color=>"grey");

    $image_a->Set(option=>"compose:clamp=off");
    #$image_a->Set(option=>"compose:clamp = off");
    #$image_a->Set(option=>"option:compose:clamp=off");
    #$image_a->Set("compose:clamp"=>"off");
    #$image_a->Set("option:compose:clamp"=>"off");
    #$image_a->Set("option:compose:clamp=off");
    #$image_a->Set("compose:clamp=off");

    $image_a->Composite(image=>$image_b, compose=>"Divide");
    $image_a->Identify();
Is it a bug, or have I missed the correct syntax?

Mike
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Possible bug compose:clamp=off Perl Magick

Post by dlemstra »

You should set an artifact instead of an option. Not sure how you can do that in Perl though.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Possible bug compose:clamp=off Perl Magick

Post by snibgo »

I suppose you have tried Get() before and after the Set()?

I see the documentation http://www.imagemagick.org/script/perl- ... -attribute seems to use single quotes, not double.

I also see:
Where this example uses 'True' and this document says '{True, False}', you can use the case-insensitive strings 'True' and 'False', or you can use the integers 1 and 0.

When you call Get() on a Boolean attribute, Image::Magick returns 1 or 0, not a string.
So it doesn't mention "off" as a valid possibility.

This seems the most likely:

Code: Select all

$image->Set(option=>'compose:clamp=False');
snibgo's IM pages: im.snibgo.com
miket
Posts: 60
Joined: 2016-08-12T13:19:13-07:00
Authentication code: 1151

Re: Possible bug compose:clamp=off Perl Magick

Post by miket »

You should set an artifact instead of an option. Not sure how you can do that in Perl though.
Me neither !!!!! How would you call that in magic.net? I could then search for it in the Perl Q16HDRI.xs file. The Set option command in perl calls DefineImageOption, which is -
DefineImageOption

DefineImageOption() associates an assignment string of the form "key=value" with a global image option. It is equivelent to SetImageOption().

The format of the DefineImageOption method is:

MagickBooleanType DefineImageOption(ImageInfo *image_info,
const char *option)
A description of each parameter follows:

image_info
the image info.
option
the image option assignment string
Should that not do the trick?
miket
Posts: 60
Joined: 2016-08-12T13:19:13-07:00
Authentication code: 1151

Re: Possible bug compose:clamp=off Perl Magick

Post by miket »

Snibgo -

Added these to my tests - to no avail :(

Code: Select all

    #$image_a->Set(option=>'compose:clamp=false');
    #$image_a->Set(option=>'compose:clamp=False');
    #$image_a->Set(option=>'compose:clamp=0');
    #$image_a->Set(option=>'compose:clamp=1');
    # $image_a->Set(option=>'compose:clamp=True');
    # $image_a->Set('compose:clamp'=>'False');
    $image_a->Set('compose:clamp'=>'True');
     
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Possible bug compose:clamp=off Perl Magick

Post by snibgo »

What code do you have that checks whether the Set() has been effective? You use Get(), I suppose?
snibgo's IM pages: im.snibgo.com
miket
Posts: 60
Joined: 2016-08-12T13:19:13-07:00
Authentication code: 1151

Re: Possible bug compose:clamp=off Perl Magick

Post by miket »

I've tried $get = $image_a->Get('option'), but this returns nothing. Also tried Get('compose:clamp') and Get('option:compose:clamp') but still nothing.

In my test, I'm relying on an Identify of $image_a after a compose (which returns values over quantum value) and looking at channel max values. (See my code in the initial post).
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Possible bug compose:clamp=off Perl Magick

Post by snibgo »

Well, if you can't Get it, you can't be certain that you have Set it. Why not try all the combinations for Get, just a sequence of 14 or whatever Get statements, each with a printf or whatever it is in Perl. Clamp is on by default, so the value should be 1 (True).
snibgo's IM pages: im.snibgo.com
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Possible bug compose:clamp=off Perl Magick

Post by dlemstra »

I think this is a missing feature and not a bug. It looks like PerlMagick has no way of setting image artifacts in the API of PerlMagick with IM7. I think @magick needs to take a look at this.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
miket
Posts: 60
Joined: 2016-08-12T13:19:13-07:00
Authentication code: 1151

Re: Possible bug compose:clamp=off Perl Magick

Post by miket »

I'd agree. I've tried all of snibgo's permutations and combinations without success. Also it does not seem possible to "Get" the value of any of the default settings.

Wizards - any chance of adding this really useful feature please?
miket
Posts: 60
Joined: 2016-08-12T13:19:13-07:00
Authentication code: 1151

Re: Possible bug compose:clamp=off Perl Magick

Post by miket »

My previous post on this topic (some 6 months ago, and when I was much less familiar with IM) has received 3400+ views, so presumably the are a few users out there interested in the same issue!
viewtopic.php?f=7&t=30631
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Possible bug compose:clamp=off Perl Magick

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.
miket
Posts: 60
Joined: 2016-08-12T13:19:13-07:00
Authentication code: 1151

Re: Possible bug compose:clamp=off Perl Magick

Post by miket »

ImageMagick 7.0.5-5 Q16 x86_64 2017-04-03 - (ImageMagick-7.0.5-5-beta20170402)

Thanks folks, this now appears to work :)

Just an observation on the implementation:

Running the following test code:

Code: Select all

    print $image_a->Get('compose:clamp')."\n";
    print $image_b->Get('compose:clamp')."\n";

    $w = $image_a->Set("compose:clamp"=>"off");
    $w = $image_b->Set("compose:clamp"=>"on");

    print $image_a->Get('compose:clamp')."\n";
    print $image_b->Get('compose:clamp')."\n";
    
    $image_a->Composite(image=>$image_b, compose=>"Divide");
    $image_a->Identify();
Results in :
The first two Gets return nothing (compose:clamp is not set - despite the default being compose:clamp=on).
The Set function sets both an artifact and a property in the respective images.
The composite has clamp OFF (since image_a has compose:clamp=off).
The second two Gets return the settings in the appropriate images.
The Composite command acts with compose:clamp=off.

Running the same code with image_a "on" and image_b "off", results in the Composite command acting with compose:clamp=on (despite image_b having compose:clamp=off).

This behavior works for me :) but may be unexpected for those previously using command line (where, I believe, the Define Compose:Clamp setting works more as a global setting) - I might be wrong in this assumption since i very rarely use the command line commands.

Anyhoo - thanks again for the fix.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Possible bug compose:clamp=off Perl Magick

Post by snibgo »

miket wrote:... command line (where, I believe, the Define Compose:Clamp setting works more as a global setting) ...
I think that may be true of v7, but not v6.

In v6, there aren't really any global settings. But the setting applied to the first image in the list is the one that counts. This is consistent with your test code: for the composite, image_a is the first or "destination" image, image_b is the second or "source" image.

Anyhow, I'm glad clamp can now be Set and Get in perl.
snibgo's IM pages: im.snibgo.com
Post Reply