% MagickCore Methods to Export Quantum Pixels %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% October 1998 %
% %
% %
-% Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
%
% size_t ExportQuantumPixels(const Image *image,CacheView *image_view,
% QuantumInfo *quantum_info,const QuantumType quantum_type,
-% unsigned char *pixels,ExceptionInfo *exception)
+% unsigned char *restrict pixels,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
*/
static inline unsigned char *PopDoublePixel(QuantumInfo *quantum_info,
- const double pixel,unsigned char *pixels)
+ const double pixel,unsigned char *restrict pixels)
{
double
*p;
unsigned char
quantum[8];
+ (void) ResetMagickMemory(quantum,0,sizeof(quantum));
p=(double *) quantum;
*p=(double) (pixel*quantum_info->state.inverse_scale+quantum_info->minimum);
- if (quantum_info->endian != LSBEndian)
+ if (quantum_info->endian == LSBEndian)
{
- *pixels++=quantum[7];
- *pixels++=quantum[6];
- *pixels++=quantum[5];
- *pixels++=quantum[4];
- *pixels++=quantum[3];
- *pixels++=quantum[2];
- *pixels++=quantum[1];
*pixels++=quantum[0];
+ *pixels++=quantum[1];
+ *pixels++=quantum[2];
+ *pixels++=quantum[3];
+ *pixels++=quantum[4];
+ *pixels++=quantum[5];
+ *pixels++=quantum[6];
+ *pixels++=quantum[7];
return(pixels);
}
- *pixels++=quantum[0];
- *pixels++=quantum[1];
- *pixels++=quantum[2];
- *pixels++=quantum[3];
- *pixels++=quantum[4];
- *pixels++=quantum[5];
- *pixels++=quantum[6];
*pixels++=quantum[7];
+ *pixels++=quantum[6];
+ *pixels++=quantum[5];
+ *pixels++=quantum[4];
+ *pixels++=quantum[3];
+ *pixels++=quantum[2];
+ *pixels++=quantum[1];
+ *pixels++=quantum[0];
return(pixels);
}
static inline unsigned char *PopFloatPixel(QuantumInfo *quantum_info,
- const float pixel,unsigned char *pixels)
+ const float pixel,unsigned char *restrict pixels)
{
float
*p;
unsigned char
quantum[4];
+ (void) ResetMagickMemory(quantum,0,sizeof(quantum));
p=(float *) quantum;
*p=(float) ((double) pixel*quantum_info->state.inverse_scale+
quantum_info->minimum);
- if (quantum_info->endian != LSBEndian)
+ if (quantum_info->endian == LSBEndian)
{
- *pixels++=quantum[3];
- *pixels++=quantum[2];
- *pixels++=quantum[1];
*pixels++=quantum[0];
+ *pixels++=quantum[1];
+ *pixels++=quantum[2];
+ *pixels++=quantum[3];
return(pixels);
}
- *pixels++=quantum[0];
- *pixels++=quantum[1];
- *pixels++=quantum[2];
*pixels++=quantum[3];
+ *pixels++=quantum[2];
+ *pixels++=quantum[1];
+ *pixels++=quantum[0];
return(pixels);
}
static inline unsigned char *PopQuantumPixel(QuantumInfo *quantum_info,
- const QuantumAny pixel,unsigned char *pixels)
+ const QuantumAny pixel,unsigned char *restrict pixels)
{
register ssize_t
i;
if (quantum_bits > quantum_info->state.bits)
quantum_bits=quantum_info->state.bits;
i-=(ssize_t) quantum_bits;
+ if (i < 0)
+ i=0;
if (quantum_info->state.bits == 8UL)
*pixels='\0';
quantum_info->state.bits-=quantum_bits;
}
static inline unsigned char *PopQuantumLongPixel(QuantumInfo *quantum_info,
- const size_t pixel,unsigned char *pixels)
+ const size_t pixel,unsigned char *restrict pixels)
{
register ssize_t
i;
register ssize_t
x;
+ assert(exception != (ExceptionInfo *) NULL);
+ assert(exception->signature == MagickSignature);
switch (quantum_info->depth)
{
case 8:
ssize_t
bit;
+ assert(exception != (ExceptionInfo *) NULL);
+ assert(exception->signature == MagickSignature);
switch (quantum_info->depth)
{
case 8:
register ssize_t
x;
+ assert(exception != (ExceptionInfo *) NULL);
+ assert(exception->signature == MagickSignature);
switch (quantum_info->depth)
{
case 8:
if (image->colorspace != CMYKColorspace)
{
(void) ThrowMagickException(exception,GetMagickModule(),ImageError,
- "ColorSeparatedImageRequired","'%s'",image->filename);
+ "ColorSeparatedImageRequired","`%s'",image->filename);
return;
}
switch (quantum_info->depth)
register ssize_t
x;
+ assert(exception != (ExceptionInfo *) NULL);
+ assert(exception->signature == MagickSignature);
switch (quantum_info->depth)
{
case 8:
ssize_t
n;
+ assert(exception != (ExceptionInfo *) NULL);
+ assert(exception->signature == MagickSignature);
n=0;
quantum=0;
switch (quantum_info->depth)
if (image->colorspace != CMYKColorspace)
{
(void) ThrowMagickException(exception,GetMagickModule(),ImageError,
- "ColorSeparatedImageRequired","'%s'",image->filename);
+ "ColorSeparatedImageRequired","`%s'",image->filename);
return;
}
switch (quantum_info->depth)
if (image->colorspace != CMYKColorspace)
{
(void) ThrowMagickException(exception,GetMagickModule(),ImageError,
- "ColorSeparatedImageRequired","'%s'",image->filename);
+ "ColorSeparatedImageRequired","`%s'",image->filename);
return;
}
switch (quantum_info->depth)
register ssize_t
x;
+ assert(exception != (ExceptionInfo *) NULL);
+ assert(exception->signature == MagickSignature);
switch (quantum_info->depth)
{
case 1:
{
- register Quantum
+ register double
threshold;
register unsigned char
black=0x01;
white=0x00;
}
- threshold=(Quantum) (QuantumRange/2);
+ threshold=QuantumRange/2.0;
for (x=((ssize_t) number_pixels-7); x > 0; x-=8)
{
*q='\0';
- *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 7;
+ *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 7;
p+=GetPixelChannels(image);
- *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 6;
+ *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 6;
p+=GetPixelChannels(image);
- *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 5;
+ *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 5;
p+=GetPixelChannels(image);
- *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 4;
+ *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 4;
p+=GetPixelChannels(image);
- *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 3;
+ *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 3;
p+=GetPixelChannels(image);
- *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 2;
+ *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 2;
p+=GetPixelChannels(image);
- *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 1;
+ *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 1;
p+=GetPixelChannels(image);
- *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 0;
+ *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 0;
p+=GetPixelChannels(image);
q++;
}
*q='\0';
for (bit=7; bit >= (ssize_t) (8-(number_pixels % 8)); bit--)
{
- *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << bit;
+ *q|=(GetPixelLuma(image,p) < threshold ? black : white) << bit;
p+=GetPixelChannels(image);
}
q++;
for (x=0; x < (ssize_t) (number_pixels-1) ; x+=2)
{
- pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
+ pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p)));
*q=(((pixel >> 4) & 0xf) << 4);
p+=GetPixelChannels(image);
- pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
+ pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p)));
*q|=pixel >> 4;
p+=GetPixelChannels(image);
q++;
}
if ((number_pixels % 2) != 0)
{
- pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
+ pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p)));
*q=(((pixel >> 4) & 0xf) << 4);
p+=GetPixelChannels(image);
q++;
for (x=0; x < (ssize_t) number_pixels; x++)
{
- pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
+ pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p)));
q=PopCharPixel(pixel,q);
p+=GetPixelChannels(image);
q+=quantum_info->pad;
for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
{
- pixel=(unsigned int) (ScaleQuantumToAny(GetPixelIntensity(image,
- p+2*GetPixelChannels(image)),range) << 22 | ScaleQuantumToAny(
- GetPixelIntensity(image,p+GetPixelChannels(image)),range) << 12 |
- ScaleQuantumToAny(GetPixelIntensity(image,p),range) << 2);
+ pixel=(unsigned int) (ScaleQuantumToAny(ClampToQuantum(
+ GetPixelLuma(image,p+2*GetPixelChannels(image))),range) << 22 |
+ ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(image,p+
+ GetPixelChannels(image))),range) << 12 | ScaleQuantumToAny(
+ ClampToQuantum(GetPixelLuma(image,p)),range) << 2);
q=PopLongPixel(quantum_info->endian,pixel,q);
p+=3*GetPixelChannels(image);
q+=quantum_info->pad;
{
pixel=0U;
if (x++ < (ssize_t) (number_pixels-1))
- pixel|=ScaleQuantumToAny(GetPixelIntensity(image,p+
- GetPixelChannels(image)),range) << 12;
+ pixel|=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(image,p+
+ GetPixelChannels(image))),range) << 12;
if (x++ < (ssize_t) number_pixels)
- pixel|=ScaleQuantumToAny(GetPixelIntensity(image,p),range) << 2;
+ pixel|=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(image,p)),
+ range) << 2;
q=PopLongPixel(quantum_info->endian,pixel,q);
}
break;
}
for (x=0; x < (ssize_t) number_pixels; x++)
{
- q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(
- GetPixelIntensity(image,p),range),q);
+ q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(ClampToQuantum(
+ GetPixelLuma(image,p)),range),q);
p+=GetPixelChannels(image);
q+=quantum_info->pad;
}
{
for (x=0; x < (ssize_t) number_pixels; x++)
{
- pixel=ScaleQuantumToShort(GetPixelIntensity(image,p));
+ pixel=ScaleQuantumToShort(ClampToQuantum(GetPixelLuma(image,p)));
q=PopShortPixel(quantum_info->endian,(unsigned short) (pixel >> 4),
q);
p+=GetPixelChannels(image);
}
for (x=0; x < (ssize_t) number_pixels; x++)
{
- q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(
- GetPixelIntensity(image,p),range),q);
+ q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(ClampToQuantum(
+ GetPixelLuma(image,p)),range),q);
p+=GetPixelChannels(image);
q+=quantum_info->pad;
}
{
for (x=0; x < (ssize_t) number_pixels; x++)
{
- pixel=SinglePrecisionToHalf(QuantumScale*
- GetPixelIntensity(image,p));
+ pixel=SinglePrecisionToHalf(QuantumScale*GetPixelLuma(image,p));
q=PopShortPixel(quantum_info->endian,pixel,q);
p+=GetPixelChannels(image);
q+=quantum_info->pad;
}
for (x=0; x < (ssize_t) number_pixels; x++)
{
- pixel=ScaleQuantumToShort(GetPixelIntensity(image,p));
+ pixel=ScaleQuantumToShort(ClampToQuantum(GetPixelLuma(image,p)));
q=PopShortPixel(quantum_info->endian,pixel,q);
p+=GetPixelChannels(image);
q+=quantum_info->pad;
float
pixel;
- pixel=(float) GetPixelIntensity(image,p);
+ pixel=(float) GetPixelLuma(image,p);
q=PopFloatPixel(quantum_info,pixel,q);
p+=GetPixelChannels(image);
q+=quantum_info->pad;
}
for (x=0; x < (ssize_t) number_pixels; x++)
{
- pixel=ScaleQuantumToLong(GetPixelIntensity(image,p));
+ pixel=ScaleQuantumToLong(ClampToQuantum(GetPixelLuma(image,p)));
q=PopLongPixel(quantum_info->endian,pixel,q);
p+=GetPixelChannels(image);
q+=quantum_info->pad;
double
pixel;
- pixel=(double) GetPixelIntensity(image,p);
+ pixel=GetPixelLuma(image,p);
q=PopDoublePixel(quantum_info,pixel,q);
p+=GetPixelChannels(image);
q+=quantum_info->pad;
range=GetQuantumRange(quantum_info->depth);
for (x=0; x < (ssize_t) number_pixels; x++)
{
- q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(
- GetPixelIntensity(image,p),range),q);
+ q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(ClampToQuantum(
+ GetPixelLuma(image,p)),range),q);
p+=GetPixelChannels(image);
q+=quantum_info->pad;
}
register ssize_t
x;
+ assert(exception != (ExceptionInfo *) NULL);
+ assert(exception->signature == MagickSignature);
switch (quantum_info->depth)
{
case 1:
{
- register Quantum
+ register double
threshold;
register unsigned char
black=0x01;
white=0x00;
}
- threshold=(Quantum) (QuantumRange/2);
+ threshold=QuantumRange/2.0;
for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
{
*q='\0';
- *q|=(GetPixelIntensity(image,p) > threshold ? black : white) << 7;
+ *q|=(GetPixelLuma(image,p) > threshold ? black : white) << 7;
pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
0x00 : 0x01);
*q|=(((int) pixel != 0 ? 0x00 : 0x01) << 6);
p+=GetPixelChannels(image);
- *q|=(GetPixelIntensity(image,p) > threshold ? black : white) << 5;
+ *q|=(GetPixelLuma(image,p) > threshold ? black : white) << 5;
pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
0x00 : 0x01);
*q|=(((int) pixel != 0 ? 0x00 : 0x01) << 4);
p+=GetPixelChannels(image);
- *q|=(GetPixelIntensity(image,p) > threshold ? black : white) << 3;
+ *q|=(GetPixelLuma(image,p) > threshold ? black : white) << 3;
pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
0x00 : 0x01);
*q|=(((int) pixel != 0 ? 0x00 : 0x01) << 2);
p+=GetPixelChannels(image);
- *q|=(GetPixelIntensity(image,p) > threshold ? black : white) << 1;
+ *q|=(GetPixelLuma(image,p) > threshold ? black : white) << 1;
pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
0x00 : 0x01);
*q|=(((int) pixel != 0 ? 0x00 : 0x01) << 0);
*q='\0';
for (bit=0; bit <= (ssize_t) (number_pixels % 4); bit+=2)
{
- *q|=(GetPixelIntensity(image,p) > threshold ? black : white) <<
+ *q|=(GetPixelLuma(image,p) > threshold ? black : white) <<
(7-bit);
pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
0x00 : 0x01);
for (x=0; x < (ssize_t) number_pixels ; x++)
{
- pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
+ pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p)));
*q=(((pixel >> 4) & 0xf) << 4);
pixel=(unsigned char) (16*QuantumScale*GetPixelAlpha(image,p)+0.5);
*q|=pixel & 0xf;
for (x=0; x < (ssize_t) number_pixels; x++)
{
- pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
+ pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p)));
q=PopCharPixel(pixel,q);
pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
q=PopCharPixel(pixel,q);
{
for (x=0; x < (ssize_t) number_pixels; x++)
{
- pixel=SinglePrecisionToHalf(QuantumScale*
- GetPixelIntensity(image,p));
+ pixel=SinglePrecisionToHalf(QuantumScale*GetPixelLuma(image,p));
q=PopShortPixel(quantum_info->endian,pixel,q);
pixel=SinglePrecisionToHalf(QuantumScale*GetPixelAlpha(image,p));
q=PopShortPixel(quantum_info->endian,pixel,q);
}
for (x=0; x < (ssize_t) number_pixels; x++)
{
- pixel=ScaleQuantumToShort(GetPixelIntensity(image,p));
+ pixel=ScaleQuantumToShort(ClampToQuantum(GetPixelLuma(image,p)));
q=PopShortPixel(quantum_info->endian,pixel,q);
pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
q=PopShortPixel(quantum_info->endian,pixel,q);
float
pixel;
- pixel=(float) GetPixelIntensity(image,p);
+ pixel=(float) GetPixelLuma(image,p);
q=PopFloatPixel(quantum_info,pixel,q);
pixel=(float) (GetPixelAlpha(image,p));
q=PopFloatPixel(quantum_info,pixel,q);
}
for (x=0; x < (ssize_t) number_pixels; x++)
{
- pixel=ScaleQuantumToLong(GetPixelIntensity(image,p));
+ pixel=ScaleQuantumToLong(ClampToQuantum(GetPixelLuma(image,p)));
q=PopLongPixel(quantum_info->endian,pixel,q);
pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
q=PopLongPixel(quantum_info->endian,pixel,q);
double
pixel;
- pixel=(double) GetPixelIntensity(image,p);
+ pixel=GetPixelLuma(image,p);
q=PopDoublePixel(quantum_info,pixel,q);
pixel=(double) (GetPixelAlpha(image,p));
q=PopDoublePixel(quantum_info,pixel,q);
range=GetQuantumRange(quantum_info->depth);
for (x=0; x < (ssize_t) number_pixels; x++)
{
- q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(
- GetPixelIntensity(image,p),range),q);
+ q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(ClampToQuantum(
+ GetPixelLuma(image,p)),range),q);
q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelAlpha(image,p),
range),q);
p+=GetPixelChannels(image);
register ssize_t
x;
+ assert(exception != (ExceptionInfo *) NULL);
+ assert(exception->signature == MagickSignature);
switch (quantum_info->depth)
{
case 8:
if (image->storage_class != PseudoClass)
{
(void) ThrowMagickException(exception,GetMagickModule(),ImageError,
- "ColormappedImageRequired","'%s'",image->filename);
+ "ColormappedImageRequired","`%s'",image->filename);
return;
}
switch (quantum_info->depth)
if (image->storage_class != PseudoClass)
{
(void) ThrowMagickException(exception,GetMagickModule(),ImageError,
- "ColormappedImageRequired","'%s'",image->filename);
+ "ColormappedImageRequired","`%s'",image->filename);
return;
}
switch (quantum_info->depth)
register ssize_t
x;
+ assert(exception != (ExceptionInfo *) NULL);
+ assert(exception->signature == MagickSignature);
switch (quantum_info->depth)
{
case 8:
register ssize_t
x;
+ assert(exception != (ExceptionInfo *) NULL);
+ assert(exception->signature == MagickSignature);
switch (quantum_info->depth)
{
case 8:
ssize_t
bit;
+ assert(exception != (ExceptionInfo *) NULL);
+ assert(exception->signature == MagickSignature);
switch (quantum_info->depth)
{
case 8:
register ssize_t
x;
+ assert(exception != (ExceptionInfo *) NULL);
+ assert(exception->signature == MagickSignature);
switch (quantum_info->depth)
{
case 8:
MagickExport size_t ExportQuantumPixels(const Image *image,
CacheView *image_view,QuantumInfo *quantum_info,
- const QuantumType quantum_type,unsigned char *pixels,ExceptionInfo *exception)
+ const QuantumType quantum_type,unsigned char *restrict pixels,
+ ExceptionInfo *exception)
{
MagickSizeType
number_pixels;
register ssize_t
i;
- if (GetPixelMask(image,q) != 0)
+ if (GetPixelReadMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
Sa=QuantumScale*GetPixelAlpha(image,q);
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
- PixelChannel
- channel;
-
- PixelTrait
- traits;
-
- channel=GetPixelChannelMapChannel(image,i);
- traits=GetPixelChannelMapTraits(image,channel);
+ PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelTrait traits=GetPixelChannelTraits(image,channel);
if ((traits & UpdatePixelTrait) == 0)
continue;
q[i]=ClampToQuantum(Sa*q[i]);