Page 1 of 1

Possible bug compose:clamp=off Perl Magick

Posted: 2017-03-30T23:31:41-07:00
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

Re: Possible bug compose:clamp=off Perl Magick

Posted: 2017-03-30T23:50:25-07:00
by dlemstra
You should set an artifact instead of an option. Not sure how you can do that in Perl though.

Re: Possible bug compose:clamp=off Perl Magick

Posted: 2017-03-31T00:23:40-07:00
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');

Re: Possible bug compose:clamp=off Perl Magick

Posted: 2017-03-31T01:00:47-07:00
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?

Re: Possible bug compose:clamp=off Perl Magick

Posted: 2017-03-31T01:11:32-07:00
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');
     

Re: Possible bug compose:clamp=off Perl Magick

Posted: 2017-03-31T01:18:36-07:00
by snibgo
What code do you have that checks whether the Set() has been effective? You use Get(), I suppose?

Re: Possible bug compose:clamp=off Perl Magick

Posted: 2017-03-31T01:42:36-07:00
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).

Re: Possible bug compose:clamp=off Perl Magick

Posted: 2017-03-31T02:23:28-07:00
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).

Re: Possible bug compose:clamp=off Perl Magick

Posted: 2017-03-31T04:11:37-07:00
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.

Re: Possible bug compose:clamp=off Perl Magick

Posted: 2017-03-31T04:48:25-07:00
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?

Re: Possible bug compose:clamp=off Perl Magick

Posted: 2017-03-31T04:52:56-07:00
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

Re: Possible bug compose:clamp=off Perl Magick

Posted: 2017-03-31T13:18:25-07:00
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.

Re: Possible bug compose:clamp=off Perl Magick

Posted: 2017-04-03T05:03:55-07:00
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.

Re: Possible bug compose:clamp=off Perl Magick

Posted: 2017-04-03T11:05:54-07:00
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.