Wrong colors when drawing on YCbCr images

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
naoliv
Posts: 110
Joined: 2007-12-10T18:54:27-07:00
Location: Brazil

Wrong colors when drawing on YCbCr images

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Wrong colors when drawing on YCbCr images

Post 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.
Post Reply