Re: ColorGray shade(0.0)
Bob Friesenhahn <[email protected]> Tue, 3 Oct 2006 11:16:17 -0500 (CDT)
| Newsgroups | gmane.comp.video.graphicsmagick.apis |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 3 Oct 2006, Lars Benner wrote:
> Hi List,
>
> I hope this is the right place for reporting, what I think, is a strange
> behavior of the ColorGray class of Magik++.
>
> I am trying to set the pixel color of an image this way:
>
> ColorGray color;
> color.shade(v);
> aImage.pixelColor(color);
>
> But every time v is 0.0, an exception is thrown at aImage.pixelColor(color):
The available pixelColor signatures are:
// Get/set pixel color at location x & y.
void pixelColor ( const unsigned int x_,
const unsigned int y_,
const Color &color_ );
Color pixelColor ( const unsigned int x_,
const unsigned int y_ ) const;
which means that your sample code should not compile.
There is an oddity of the Color class in that transparent black is
considered to be an invalid color. A color constructed without
arguments is constructed as an invalid color. This allows "unsetting"
color option values without consuming more storage space. Setting the
shade does not alter the alpha from the default of transparent so
there is an exception.
If you use
ColorGray color;
color.shade(v);
color.alphaQuantum(OpaqueOpacity);
then there should not be a thrown exception.
> Is this a problem of the API respectively the class or do I simply not
> understand the deeper meaning.
I think that there is a bug in the API in that the pixelColor() method
has no business enforcing the pixel color. I think that this is a
legacy holdover from days when the Color was composed differently.
Change Magick++/lib/Image.cpp to:
// Set the color of a pixel.
void Magick::Image::pixelColor ( const unsigned int x_, const unsigned int y_,
const Color &color_ )
{
// Test arguments to ensure they are within the image.
if ( y_ > rows() || x_ > columns() )
throwExceptionExplicit( OptionError,
"Access outside of image boundary" );
modifyImage();
// Set image to DirectClass
classType( DirectClass );
// Get pixel view
Pixels pixels(*this);
// Set pixel value
*(pixels.get(x_, y_, 1, 1 )) = color_;
// Tell ImageMagick that pixels have been updated
pixels.sync();
return;
}
and the exception should go away and you should be able to use
transparent black. I will fix this for the next release.
Bob
======================================
Bob Friesenhahn
[email protected], http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV