Page 1 of 1

Wrong colors when drawing on YCbCr images

Posted: 2008-03-11T19:53:14-07:00
by naoliv
Hi!

From this bugs report on Debian http://bugs.debian.org/462895:

Code: Select all

Hi,

Image::Magick (and probably ImageMagick proper) seems rather broken when
working in non-RGB colorspaces. Witness for instance the following
script:

  use Image::Magick;
  my $m = Image::Magick->new(size=>"200x200");
  $m->Read("xc:green");
  $m->Set(colorspace=>'YCbCr');
  $m->Draw(primitive=>"rectangle", fill=>"white", points=>"0,0 100,100"); 
  $m->Write("test.jpeg");

The resulting background is correctly enough green (showing that the
colorspace conversion worked), but the square is pink. This is because
#ffffff in YCbCr is, of course, pink, not white.

I can work around this to some degree, by giving explicit hex codes
to Draw() instead of color names. However, I cannot find a reasonable
way of drawing FreeType text, since drawing black text on a white
background yields ugly green fringes where there should have been grey
pixels (ie. the antialiasing doesn't understand YCbCr either).
Tested with ImageMagick 6.3.7-9

Thank you!

Best regards,
Nelson

Re: Wrong colors when drawing on YCbCr images

Posted: 2008-03-12T06:30:54-07:00
by magick
The results of drawing in any colorspace other than RGB is undefined. If an image is in another colorspace than RGB you must first convert the colorspace to RGB, draw on it, and then convert the colorspace back to the original colorspace.