This source file includes following definitions.
- AcquireQuantumInfo
- AcquireQuantumPixels
- DestroyQuantumInfo
- DestroyQuantumPixels
- GetQuantumExtent
- GetQuantumEndian
- GetQuantumFormat
- GetQuantumInfo
- GetQuantumPixels
- GetQuantumType
- ResetQuantumState
- SetQuantumAlphaType
- SetQuantumDepth
- SetQuantumEndian
- SetQuantumFormat
- SetQuantumImageType
- SetQuantumPack
- SetQuantumPad
- SetQuantumMinIsWhite
- SetQuantumQuantum
- SetQuantumScale
#include "magick/studio.h"
#include "magick/attribute.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/color-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/cache.h"
#include "magick/cache-private.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/constitute.h"
#include "magick/delegate.h"
#include "magick/geometry.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/monitor.h"
#include "magick/option.h"
#include "magick/pixel.h"
#include "magick/pixel-private.h"
#include "magick/property.h"
#include "magick/quantum.h"
#include "magick/quantum-private.h"
#include "magick/resource_.h"
#include "magick/semaphore.h"
#include "magick/statistic.h"
#include "magick/stream.h"
#include "magick/string_.h"
#include "magick/string-private.h"
#include "magick/thread-private.h"
#include "magick/utility.h"
#define QuantumSignature 0xab
static void
DestroyQuantumPixels(QuantumInfo *);
MagickExport QuantumInfo *AcquireQuantumInfo(const ImageInfo *image_info,
Image *image)
{
MagickBooleanType
status;
QuantumInfo
*quantum_info;
quantum_info=(QuantumInfo *) AcquireMagickMemory(sizeof(*quantum_info));
if (quantum_info == (QuantumInfo *) NULL)
ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
quantum_info->signature=MagickSignature;
GetQuantumInfo(image_info,quantum_info);
if (image == (const Image *) NULL)
return(quantum_info);
status=SetQuantumDepth(image,quantum_info,image->depth);
quantum_info->endian=image->endian;
if (status == MagickFalse)
quantum_info=DestroyQuantumInfo(quantum_info);
return(quantum_info);
}
static MagickBooleanType AcquireQuantumPixels(QuantumInfo *quantum_info,
const size_t extent)
{
register ssize_t
i;
assert(quantum_info != (QuantumInfo *) NULL);
assert(quantum_info->signature == MagickSignature);
quantum_info->number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
quantum_info->pixels=(unsigned char **) AcquireQuantumMemory(
quantum_info->number_threads,sizeof(*quantum_info->pixels));
if (quantum_info->pixels == (unsigned char **) NULL)
return(MagickFalse);
quantum_info->extent=extent;
(void) ResetMagickMemory(quantum_info->pixels,0,quantum_info->number_threads*
sizeof(*quantum_info->pixels));
for (i=0; i < (ssize_t) quantum_info->number_threads; i++)
{
quantum_info->pixels[i]=(unsigned char *) AcquireQuantumMemory(extent+1,
sizeof(**quantum_info->pixels));
if (quantum_info->pixels[i] == (unsigned char *) NULL)
{
while (--i >= 0)
quantum_info->pixels[i]=(unsigned char *) RelinquishMagickMemory(
quantum_info->pixels[i]);
return(MagickFalse);
}
(void) ResetMagickMemory(quantum_info->pixels[i],0,(extent+1)*
sizeof(**quantum_info->pixels));
quantum_info->pixels[i][extent]=QuantumSignature;
}
return(MagickTrue);
}
MagickExport QuantumInfo *DestroyQuantumInfo(QuantumInfo *quantum_info)
{
assert(quantum_info != (QuantumInfo *) NULL);
assert(quantum_info->signature == MagickSignature);
if (quantum_info->pixels != (unsigned char **) NULL)
DestroyQuantumPixels(quantum_info);
if (quantum_info->semaphore != (SemaphoreInfo *) NULL)
DestroySemaphoreInfo(&quantum_info->semaphore);
quantum_info->signature=(~MagickSignature);
quantum_info=(QuantumInfo *) RelinquishMagickMemory(quantum_info);
return(quantum_info);
}
static void DestroyQuantumPixels(QuantumInfo *quantum_info)
{
register ssize_t
i;
ssize_t
extent;
assert(quantum_info != (QuantumInfo *) NULL);
assert(quantum_info->signature == MagickSignature);
assert(quantum_info->pixels != (unsigned char **) NULL);
extent=(ssize_t) quantum_info->extent;
for (i=0; i < (ssize_t) quantum_info->number_threads; i++)
if (quantum_info->pixels[i] != (unsigned char *) NULL)
{
assert(quantum_info->pixels[i][extent] == QuantumSignature);
quantum_info->pixels[i]=(unsigned char *) RelinquishMagickMemory(
quantum_info->pixels[i]);
}
quantum_info->pixels=(unsigned char **) RelinquishMagickMemory(
quantum_info->pixels);
}
MagickExport size_t GetQuantumExtent(const Image *image,
const QuantumInfo *quantum_info,const QuantumType quantum_type)
{
size_t
packet_size;
assert(quantum_info != (QuantumInfo *) NULL);
assert(quantum_info->signature == MagickSignature);
packet_size=1;
switch (quantum_type)
{
case GrayAlphaQuantum: packet_size=2; break;
case IndexAlphaQuantum: packet_size=2; break;
case RGBQuantum: packet_size=3; break;
case BGRQuantum: packet_size=3; break;
case RGBAQuantum: packet_size=4; break;
case RGBOQuantum: packet_size=4; break;
case BGRAQuantum: packet_size=4; break;
case CMYKQuantum: packet_size=4; break;
case CMYKAQuantum: packet_size=5; break;
default: break;
}
if (quantum_info->pack == MagickFalse)
return((size_t) (packet_size*image->columns*((quantum_info->depth+7)/8)));
return((size_t) ((packet_size*image->columns*quantum_info->depth+7)/8));
}
MagickExport EndianType GetQuantumEndian(const QuantumInfo *quantum_info)
{
assert(quantum_info != (QuantumInfo *) NULL);
assert(quantum_info->signature == MagickSignature);
return(quantum_info->endian);
}
MagickExport QuantumFormatType GetQuantumFormat(const QuantumInfo *quantum_info)
{
assert(quantum_info != (QuantumInfo *) NULL);
assert(quantum_info->signature == MagickSignature);
return(quantum_info->format);
}
MagickExport void GetQuantumInfo(const ImageInfo *image_info,
QuantumInfo *quantum_info)
{
const char
*option;
assert(quantum_info != (QuantumInfo *) NULL);
(void) ResetMagickMemory(quantum_info,0,sizeof(*quantum_info));
quantum_info->quantum=8;
quantum_info->maximum=1.0;
quantum_info->scale=QuantumRange;
quantum_info->pack=MagickTrue;
quantum_info->semaphore=AllocateSemaphoreInfo();
quantum_info->signature=MagickSignature;
if (image_info == (const ImageInfo *) NULL)
return;
option=GetImageOption(image_info,"quantum:format");
if (option != (char *) NULL)
quantum_info->format=(QuantumFormatType) ParseCommandOption(
MagickQuantumFormatOptions,MagickFalse,option);
option=GetImageOption(image_info,"quantum:minimum");
if (option != (char *) NULL)
quantum_info->minimum=StringToDouble(option,(char **) NULL);
option=GetImageOption(image_info,"quantum:maximum");
if (option != (char *) NULL)
quantum_info->maximum=StringToDouble(option,(char **) NULL);
if ((quantum_info->minimum == 0.0) && (quantum_info->maximum == 0.0))
quantum_info->scale=0.0;
else
if (quantum_info->minimum == quantum_info->maximum)
{
quantum_info->scale=(MagickRealType) QuantumRange/quantum_info->minimum;
quantum_info->minimum=0.0;
}
else
quantum_info->scale=(MagickRealType) QuantumRange/(quantum_info->maximum-
quantum_info->minimum);
option=GetImageOption(image_info,"quantum:scale");
if (option != (char *) NULL)
quantum_info->scale=StringToDouble(option,(char **) NULL);
option=GetImageOption(image_info,"quantum:polarity");
if (option != (char *) NULL)
quantum_info->min_is_white=LocaleCompare(option,"min-is-white") == 0 ?
MagickTrue : MagickFalse;
quantum_info->endian=image_info->endian;
ResetQuantumState(quantum_info);
}
MagickExport unsigned char *GetQuantumPixels(const QuantumInfo *quantum_info)
{
const int
id = GetOpenMPThreadId();
assert(quantum_info != (QuantumInfo *) NULL);
assert(quantum_info->signature == MagickSignature);
return(quantum_info->pixels[id]);
}
MagickExport QuantumType GetQuantumType(Image *image,ExceptionInfo *exception)
{
QuantumType
quantum_type;
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
(void) exception;
quantum_type=RGBQuantum;
if (image->matte != MagickFalse)
quantum_type=RGBAQuantum;
if (image->colorspace == CMYKColorspace)
{
quantum_type=CMYKQuantum;
if (image->matte != MagickFalse)
quantum_type=CMYKAQuantum;
}
if (IsGrayColorspace(image->colorspace) != MagickFalse)
{
quantum_type=GrayQuantum;
if (image->matte != MagickFalse)
quantum_type=GrayAlphaQuantum;
}
if (image->storage_class == PseudoClass)
{
quantum_type=IndexQuantum;
if (image->matte != MagickFalse)
quantum_type=IndexAlphaQuantum;
}
return(quantum_type);
}
MagickPrivate void ResetQuantumState(QuantumInfo *quantum_info)
{
static const unsigned int mask[32] =
{
0x00000000U, 0x00000001U, 0x00000003U, 0x00000007U, 0x0000000fU,
0x0000001fU, 0x0000003fU, 0x0000007fU, 0x000000ffU, 0x000001ffU,
0x000003ffU, 0x000007ffU, 0x00000fffU, 0x00001fffU, 0x00003fffU,
0x00007fffU, 0x0000ffffU, 0x0001ffffU, 0x0003ffffU, 0x0007ffffU,
0x000fffffU, 0x001fffffU, 0x003fffffU, 0x007fffffU, 0x00ffffffU,
0x01ffffffU, 0x03ffffffU, 0x07ffffffU, 0x0fffffffU, 0x1fffffffU,
0x3fffffffU, 0x7fffffffU
};
assert(quantum_info != (QuantumInfo *) NULL);
assert(quantum_info->signature == MagickSignature);
quantum_info->state.inverse_scale=1.0;
if (fabs(quantum_info->scale) >= MagickEpsilon)
quantum_info->state.inverse_scale/=quantum_info->scale;
quantum_info->state.pixel=0U;
quantum_info->state.bits=0U;
quantum_info->state.mask=mask;
}
MagickExport void SetQuantumAlphaType(QuantumInfo *quantum_info,
const QuantumAlphaType type)
{
assert(quantum_info != (QuantumInfo *) NULL);
assert(quantum_info->signature == MagickSignature);
quantum_info->alpha_type=type;
}
MagickExport MagickBooleanType SetQuantumDepth(const Image *image,
QuantumInfo *quantum_info,const size_t depth)
{
size_t
extent,
quantum;
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(quantum_info != (QuantumInfo *) NULL);
assert(quantum_info->signature == MagickSignature);
quantum_info->depth=depth;
if (quantum_info->format == FloatingPointQuantumFormat)
{
if (quantum_info->depth > 32)
quantum_info->depth=64;
else
if (quantum_info->depth > 16)
quantum_info->depth=32;
else
quantum_info->depth=16;
}
if (quantum_info->pixels != (unsigned char **) NULL)
DestroyQuantumPixels(quantum_info);
quantum=(quantum_info->pad+6)*(quantum_info->depth+7)/8;
extent=image->columns*quantum;
if (quantum != (extent/image->columns))
return(MagickFalse);
return(AcquireQuantumPixels(quantum_info,extent));
}
MagickExport MagickBooleanType SetQuantumEndian(const Image *image,
QuantumInfo *quantum_info,const EndianType endian)
{
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(quantum_info != (QuantumInfo *) NULL);
assert(quantum_info->signature == MagickSignature);
quantum_info->endian=endian;
return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
}
MagickExport MagickBooleanType SetQuantumFormat(const Image *image,
QuantumInfo *quantum_info,const QuantumFormatType format)
{
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(quantum_info != (QuantumInfo *) NULL);
assert(quantum_info->signature == MagickSignature);
quantum_info->format=format;
return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
}
MagickExport void SetQuantumImageType(Image *image,
const QuantumType quantum_type)
{
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
switch (quantum_type)
{
case IndexQuantum:
case IndexAlphaQuantum:
{
image->type=PaletteType;
break;
}
case GrayQuantum:
case GrayAlphaQuantum:
{
image->type=GrayscaleType;
if (image->depth == 1)
image->type=BilevelType;
break;
}
case CyanQuantum:
case MagentaQuantum:
case YellowQuantum:
case BlackQuantum:
case CMYKQuantum:
case CMYKAQuantum:
{
image->type=ColorSeparationType;
break;
}
default:
{
image->type=TrueColorType;
break;
}
}
}
MagickExport void SetQuantumPack(QuantumInfo *quantum_info,
const MagickBooleanType pack)
{
assert(quantum_info != (QuantumInfo *) NULL);
assert(quantum_info->signature == MagickSignature);
quantum_info->pack=pack;
}
MagickExport MagickBooleanType SetQuantumPad(const Image *image,
QuantumInfo *quantum_info,const size_t pad)
{
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(quantum_info != (QuantumInfo *) NULL);
assert(quantum_info->signature == MagickSignature);
quantum_info->pad=pad;
return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
}
MagickExport void SetQuantumMinIsWhite(QuantumInfo *quantum_info,
const MagickBooleanType min_is_white)
{
assert(quantum_info != (QuantumInfo *) NULL);
assert(quantum_info->signature == MagickSignature);
quantum_info->min_is_white=min_is_white;
}
MagickExport void SetQuantumQuantum(QuantumInfo *quantum_info,
const size_t quantum)
{
assert(quantum_info != (QuantumInfo *) NULL);
assert(quantum_info->signature == MagickSignature);
quantum_info->quantum=quantum;
}
MagickExport void SetQuantumScale(QuantumInfo *quantum_info,const double scale)
{
assert(quantum_info != (QuantumInfo *) NULL);
assert(quantum_info->signature == MagickSignature);
quantum_info->scale=scale;
}