Page 1 of 1

GetPixels() or Get(Pixel[x,y])

Posted: 2018-11-06T18:23:19-07:00
by Flodelarab
Hello :D

Code: Select all

my @cp=$image->GetPixels(x=>$x,y=>$y, height=>1, width=>1);                                                                                                                                                                                                               
print "$x $y ".$image->Get("pixel[$x,$y]")." $cp[0] $cp[1] $cp[2] $cp[3] $res\n";                                                                                                                                                                                 
gives, for example, such lines, with a png picture, having an alpha channel (RGBA) :

Code: Select all

                                                                                                                                                                                                                  
923 0 45232,45746,44461,64764 45232 45746 44461 771 39                                                                                                                                                                                                                       
109 1 0,514,514,257 0 514 514 65278 42                                                                                                                                                                                                                                      
218 2 257,514,257,771 257 514 257 64764 100                                                                                                                                                                                                                                 
(...)                                                                                                                                                                                                             
478 9 65021,65278,65021,65535 65021 65278 65021 0 100                                                                                                                                                                                                                       
692 10 65021,65278,65535,65021 65021 65278 65535 514 110  
541 4 64764,65535,65535,65278 64764 65535 65535 257 61
RGB values are the same. Ok. Check! :)
A is not the same. (A from RGBA). Ko. Don't give me 5 :(

Hexadecimal values going by couple:
0101 <-> FDFD
0202 <-> FEFE
0303 <-> FCFC
0000 <-> FFFF

Does anyone know what is going wrong ? :shock:
Why GetPixels() and Get(Pixel[]) give different values ?
What is the relation between those 2 values of opacity ?

Thank you for your attention.

Re: GetPixels() or Get(Pixel[x,y])

Posted: 2018-11-06T19:03:41-07:00
by snibgo
What version of IM are you using? At one time, IM recorded alpha as transparency (ie 0 was opaque, 100% was transparent). Now, it records alpha as opacity (ie 0 is transparent, 100% is opaque).

Note that 64764 + 771 = 65535, 257 + 65278 = 65535, etc.

Re: GetPixels() or Get(Pixel[x,y])

Posted: 2018-11-07T05:24:37-07:00
by Flodelarab
First, thank you for your fast answer.

Second, my version of ImageMagick is 6.97 (Debian installation).
/usr/share/perl5/Image/Magick.pm points onto /usr/lib/x86_64-linux-gnu/perl5/5.24/Image/Magick/Q16.pm that is version 6.97.
Note that 64764 + 771 = 65535, 257 + 65278 = 65535, etc.
OK.
I will consider big values as correct values, and low values as old methods, because my picture is totally opaque, at first.
Surely, I have used Set(Pixels[]) to write and Getpixels() to read. So, unstable.

Thanks 8)

Re: GetPixels() or Get(Pixel[x,y])

Posted: 2018-12-02T12:49:15-07:00
by Flodelarab
To be complete, I post the code I have and works :

Code: Select all

my @cp=$image->GetPixels(x=>$x,y=>$y,width=>1,height=>1, map=>'RGBA');
and

Code: Select all

if ($s==3) {
                        $cp[$s] = 65535-$cp[$s];
                }

Code: Select all

$image->Set("pixel[$x,$y]"=>"$cp[0],$cp[1],$cp[2],$cp[3]",map=>'rgba',normalize=>'false');
Other codes don't work because of normalization (values between 0 and 1) or bad alpha value returned.

Hope this helps others.