extract YCbCr values from a jpeg-image
Posted: 2009-09-13T09:22:00-07:00
Hi there!
I'm using MagickCore API to read an image and extract pixels. I would like to know to know if it is possible to extract the YCbCr values from a jpeg image for example (without any conversion to RGB in between).
I'm using the following code to extract pixels:
But as I understand it, PixelPacket supports only RGBA and CMYK. Is there some other way to get the YCbCr values (if the image is stored as YCbCr)?
I'm using MagickCore API to read an image and extract pixels. I would like to know to know if it is possible to extract the YCbCr values from a jpeg image for example (without any conversion to RGB in between).
I'm using the following code to extract pixels:
Code: Select all
void main(int argc, char *argv[])
{
ExceptionInfo *exception;
Image *image, *images;
ImageInfo *image_info;
int z0,z1,z2,z3;
MagickCoreGenesis(argv[1], MagickTrue);
image_info = CloneImageInfo((ImageInfo *) NULL);
exception = AcquireExceptionInfo();
(void) strcpy(image_info->filename, "red.jpg");
image_info->colorspace = YCbCrColorspace;
images = ReadImage(image_info, exception);
images = CoalesceImages(images, exception);
image = GetImageFromList(images, 0);
register const PixelPacket *p;
for (int y=0; y < 480; y++) {
p = AcquireImagePixels(image, 0, 480-1-y, 640, 1, exception);
for (int x=0; x < 480; x++) {
z0=p->blue;
z1=p->green;
z2=p->red;
z3=255-p->opacity;
char BUF[256];
sprintf(BUF, "blue %d, green %d, red %d\n", z0, z1, z2);
OutputDebugString(BUF);
p++;
}
}
DestroyImage(image);
DestroyImageInfo(image_info);
DestroyExceptionInfo(exception);
MagickCoreTerminus();
}