bool ScImgDataLoader_GMagick::readCMYK(Image *input, RawImage *output, int width, int height) { /* Mapping: red: cyan green: magenta blue: yellow opacity: black index: alpha */ //Copied from GraphicsMagick header and modified #define GetCyanSample(p) (p.red) #define GetMagentaSample(p) (p.green) #define GetYellowSample(p) (p.blue) #define GetCMYKBlackSample(p) (p.opacity) #define GetAlphaSample(p) (p) bool hasAlpha = input->matte; if (!output->create(width, height, hasAlpha ? 5 : 4)) return false; ExceptionInfo exception; GetExceptionInfo(&exception); const PixelPacket *pixels = AcquireImagePixels(input, 0, 0, width, height, &exception); if (exception.severity != UndefinedException) CatchException(&exception); if (!pixels) { qCritical() << QObject::tr("Could not get pixel data!"); return false; } const IndexPacket *alpha = 0; if (hasAlpha) { alpha = AccessImmutableIndexes(input); if (!alpha) { qCritical() << QObject::tr("Could not get alpha channel data!"); return false; } } unsigned char *buffer = output->bits(); if (!buffer) { qCritical() << QObject::tr("Could not allocate output buffer!"); return false; } int i; for (i = 0; i < width*height; i++) { *buffer++ = ScaleQuantumToChar(GetCyanSample(pixels[i])); *buffer++ = ScaleQuantumToChar(GetMagentaSample(pixels[i])); *buffer++ = ScaleQuantumToChar(GetYellowSample(pixels[i])); *buffer++ = ScaleQuantumToChar(GetCMYKBlackSample(pixels[i])); if (hasAlpha) { *buffer++ = 255 - ScaleQuantumToChar(GetAlphaSample(alpha[i])); } } return true; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % D i f f e r e n c e I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DifferenceImage() returns an annotated difference image based on the % the difference between a reference image and a compare image. % % The format of the DifferenceImage method is: % % Image *DifferenceImage(const Image *reference_image, % const Image *compare_image, % const DifferenceImageOptions *difference_options, % ExceptionInfo *exception) % % A description of each parameter follows: % % o reference_image: the reference image. % % o compare_image: the comparison image. % % o difference_options: options to use when differencing. % % o channel: the channel(s) to compare. % % o exception: Return any errors or warnings in this structure. % */ static MagickPassFail DifferenceImagePixels(void *mutable_data, /* User provided mutable data */ const void *immutable_data, /* User provided immutable data */ const Image *reference_image, /* Source 1 image */ const PixelPacket *reference_pixels, /* Pixel row in source 1 image */ const IndexPacket *reference_indexes,/* Pixel row indexes in source 1 image */ const Image *compare_image, /* Source 2 image */ const PixelPacket *compare_pixels, /* Pixel row in source 2 image */ const IndexPacket *compare_indexes, /* Pixel row indexes in source 2 image */ Image *result_image, /* Update image */ PixelPacket *result_pixels, /* Pixel row in update image */ IndexPacket *result_indexes, /* Pixel row indexes in update image */ const long npixels, /* Number of pixels in row */ ExceptionInfo *exception /* Exception report */ ) { const DifferenceImageOptions *difference_options = (const DifferenceImageOptions *) immutable_data; register ChannelType channels = difference_options->channel; register long i; register MagickBool change; ARG_NOT_USED(mutable_data); ARG_NOT_USED(compare_image); ARG_NOT_USED(result_image); ARG_NOT_USED(result_indexes); ARG_NOT_USED(exception); for (i=0; i < npixels; i++) { change=MagickFalse; if (IsCMYKColorspace(reference_image->colorspace)) { if (MagickChannelEnabled(channels,CyanChannel) && (GetCyanSample(&reference_pixels[i]) != GetCyanSample(&compare_pixels[i]))) change=MagickTrue; if (MagickChannelEnabled(channels,MagentaChannel) && (GetMagentaSample(&reference_pixels[i]) != GetMagentaSample(&compare_pixels[i]))) change=MagickTrue; if (MagickChannelEnabled(channels,YellowChannel) && (GetYellowSample(&reference_pixels[i]) != GetYellowSample(&compare_pixels[i]))) change=MagickTrue; if (MagickChannelEnabled(channels,BlackChannel) && (GetBlackSample(&reference_pixels[i]) != GetBlackSample(&compare_pixels[i]))) change=MagickTrue; if (MagickChannelEnabled(channels,OpacityChannel) && (reference_indexes[i] != compare_indexes[i])) change=MagickTrue; } else { if (MagickChannelEnabled(channels,RedChannel) && (GetRedSample(&reference_pixels[i]) != GetRedSample(&compare_pixels[i]))) change=MagickTrue; if (MagickChannelEnabled(channels,GreenChannel) && (GetGreenSample(&reference_pixels[i]) != GetGreenSample(&compare_pixels[i]))) change=MagickTrue; if (MagickChannelEnabled(channels,BlueChannel) && (GetBlueSample(&reference_pixels[i]) != GetBlueSample(&compare_pixels[i]))) change=MagickTrue; if (MagickChannelEnabled(channels,OpacityChannel) && (GetOpacitySample(&reference_pixels[i]) != GetOpacitySample(&compare_pixels[i]))) change=MagickTrue; } /* Modify result image to reflect change. */ switch (difference_options->highlight_style) { case UndefinedHighlightStyle: break; case AssignHighlightStyle: { /* Changed pixels are assigned the highlight color. */ if (change) result_pixels[i]=difference_options->highlight_color; else result_pixels[i]=compare_pixels[i]; break; } case ThresholdHighlightStyle: { /* For changed pixels, compare the pixel intensity. If the pixel intensity in the compare image is higher than the reference image, then set the pixel to white, otherwise set it to black. */ if (change) { Quantum compare_intensity, intensity, reference_intensity; compare_intensity=PixelIntensity(&compare_pixels[i]); reference_intensity=PixelIntensity(&reference_pixels[i]); if (compare_intensity > reference_intensity) intensity=MaxRGB; else intensity=0U; result_pixels[i].red = result_pixels[i].green = result_pixels[i].blue = intensity; result_pixels[i].opacity=compare_pixels[i].opacity; } else { result_pixels[i]=compare_pixels[i]; } break; } case TintHighlightStyle: { /* Alpha composite highlight color on top of change pixels. */ if (change) AlphaCompositePixel(&result_pixels[i],&difference_options->highlight_color,0.75*MaxRGBDouble, &compare_pixels[i],compare_pixels[i].opacity); else result_pixels[i]=compare_pixels[i]; break; } case XorHighlightStyle: { if (change) { result_pixels[i].red = compare_pixels[i].red ^ difference_options->highlight_color.red; result_pixels[i].green = compare_pixels[i].green ^ difference_options->highlight_color.green; result_pixels[i].blue = compare_pixels[i].blue ^ difference_options->highlight_color.blue; result_pixels[i].opacity = compare_pixels[i].opacity ^ difference_options->highlight_color.opacity; } else { result_pixels[i]=compare_pixels[i]; } break; } } } return MagickPass; }