MagickCore  6.9.11
quantize.c File Reference
Include dependency graph for quantize.c:

Go to the source code of this file.

Data Structures

struct  _NodeInfo
struct  _Nodes
struct  _CubeInfo


#define CacheShift   2
#define ErrorQueueLength   16
#define MaxNodes   266817
#define MaxTreeDepth   8
#define NodesInAList   1920
#define AssignImageTag   "Assign/Image"
#define ClassifyImageTag   "Classify/Image"
#define RedShift(pixel)   (((pixel) >> CacheShift) << (0*(8-CacheShift)))
#define GreenShift(pixel)   (((pixel) >> CacheShift) << (1*(8-CacheShift)))
#define BlueShift(pixel)   (((pixel) >> CacheShift) << (2*(8-CacheShift)))
#define AlphaShift(pixel)   (((pixel) >> CacheShift) << (3*(8-CacheShift)))
#define DitherImageTag   "Dither/Image"
#define DitherImageTag   "Dither/Image"
#define PosterizeImageTag   "Posterize/Image"
#define PosterizePixel(pixel)
#define ReduceImageTag   "Reduce/Image"


typedef struct _NodeInfo NodeInfo
typedef struct _Nodes Nodes
typedef struct _CubeInfo CubeInfo


static CubeInfoGetCubeInfo (const QuantizeInfo *, const size_t, const size_t)
static NodeInfoGetNodeInfo (CubeInfo *, const size_t, const size_t, NodeInfo *)
static MagickBooleanType AssignImageColors (Image *, CubeInfo *)
static MagickBooleanType ClassifyImageColors (CubeInfo *, const Image *, ExceptionInfo *)
static MagickBooleanType DitherImage (Image *, CubeInfo *)
static MagickBooleanType SetGrayscaleImage (Image *)
static void ClosestColor (const Image *, CubeInfo *, const NodeInfo *)
static void DefineImageColormap (Image *, CubeInfo *, NodeInfo *)
static void DestroyCubeInfo (CubeInfo *)
static void PruneLevel (CubeInfo *, const NodeInfo *)
static void PruneToCubeDepth (CubeInfo *, const NodeInfo *)
static void ReduceImageColors (const Image *, CubeInfo *)
MagickExport QuantizeInfoAcquireQuantizeInfo (const ImageInfo *image_info)
static void AssociateAlphaPixel (const CubeInfo *cube_info, const PixelPacket *pixel, DoublePixelPacket *alpha_pixel)
static size_t ColorToNodeId (const CubeInfo *cube_info, const DoublePixelPacket *pixel, size_t index)
static MagickBooleanType IsSameColor (const Image *image, const PixelPacket *p, const PixelPacket *q)
static void SetAssociatedAlpha (const Image *image, CubeInfo *cube_info)
MagickExport QuantizeInfoCloneQuantizeInfo (const QuantizeInfo *quantize_info)
MagickExport MagickBooleanType CompressImageColormap (Image *image)
MagickExport QuantizeInfoDestroyQuantizeInfo (QuantizeInfo *quantize_info)
static DoublePixelPacket ** DestroyPixelThreadSet (DoublePixelPacket **pixels)
static DoublePixelPacket ** AcquirePixelThreadSet (const size_t count)
static ssize_t CacheOffset (CubeInfo *cube_info, const DoublePixelPacket *pixel)
static MagickBooleanType FloydSteinbergDither (Image *image, CubeInfo *cube_info)
static MagickBooleanType RiemersmaDither (Image *, CacheView *, CubeInfo *, const unsigned int)
static void Riemersma (Image *image, CacheView *image_view, CubeInfo *cube_info, const size_t level, const unsigned int direction)
MagickExport MagickBooleanType GetImageQuantizeError (Image *image)
MagickExport void GetQuantizeInfo (QuantizeInfo *quantize_info)
static double MagickRound (double x)
MagickExport MagickBooleanType PosterizeImage (Image *image, const size_t levels, const MagickBooleanType dither)
MagickExport MagickBooleanType PosterizeImageChannel (Image *image, const ChannelType channel, const size_t levels, const MagickBooleanType dither)
static void PruneChild (CubeInfo *cube_info, const NodeInfo *node_info)
MagickExport MagickBooleanType QuantizeImage (const QuantizeInfo *quantize_info, Image *image)
MagickExport MagickBooleanType QuantizeImages (const QuantizeInfo *quantize_info, Image *images)
static size_t QuantizeErrorFlatten (const CubeInfo *cube_info, const NodeInfo *node_info, const ssize_t offset, MagickRealType *quantize_error)
static void Reduce (CubeInfo *cube_info, const NodeInfo *node_info)
static int MagickRealTypeCompare (const void *error_p, const void *error_q)
MagickExport MagickBooleanType RemapImage (const QuantizeInfo *quantize_info, Image *image, const Image *remap_image)
MagickExport MagickBooleanType RemapImages (const QuantizeInfo *quantize_info, Image *images, const Image *remap_image)
static int IntensityCompare (const void *x, const void *y)

Macro Definition Documentation

◆ AlphaShift

#define AlphaShift (   pixel)    (((pixel) >> CacheShift) << (3*(8-CacheShift)))

Referenced by CacheOffset().

◆ AssignImageTag

#define AssignImageTag   "Assign/Image"

◆ BlueShift

#define BlueShift (   pixel)    (((pixel) >> CacheShift) << (2*(8-CacheShift)))

Referenced by CacheOffset().

◆ CacheShift

#define CacheShift   2

Definition at line 208 of file quantize.c.

Referenced by GetCubeInfo().

◆ ClassifyImageTag

#define ClassifyImageTag   "Classify/Image"

Referenced by ClassifyImageColors().

◆ DitherImageTag [1/2]

#define DitherImageTag   "Dither/Image"

◆ DitherImageTag [2/2]

#define DitherImageTag   "Dither/Image"

◆ ErrorQueueLength

#define ErrorQueueLength   16

Definition at line 212 of file quantize.c.

Referenced by DitherImage(), GetCubeInfo(), and RiemersmaDither().

◆ GreenShift

#define GreenShift (   pixel)    (((pixel) >> CacheShift) << (1*(8-CacheShift)))

Referenced by CacheOffset().

◆ MaxNodes

#define MaxNodes   266817

Definition at line 213 of file quantize.c.

Referenced by ClassifyImageColors().

◆ MaxTreeDepth

◆ NodesInAList

#define NodesInAList   1920

Definition at line 215 of file quantize.c.

Referenced by GetNodeInfo().

◆ PosterizeImageTag

#define PosterizeImageTag   "Posterize/Image"

Referenced by PosterizeImageChannel().

◆ PosterizePixel

#define PosterizePixel (   pixel)
MagickRound(QuantumScale*pixel*(levels-1)))/MagickMax((ssize_t) levels-1,1))
MagickDoubleType MagickRealType
Definition: magick-type.h:129
static Quantum ClampToQuantum(const MagickRealType quantum)
Definition: quantum.h:88
static double MagickRound(double x)
Definition: quantize.c:2277
#define QuantumScale
Definition: magick-type.h:124
#define MagickMax(x, y)
Definition: image-private.h:36
#define QuantumRange
Definition: magick-type.h:90

Referenced by PosterizeImageChannel().

◆ RedShift

#define RedShift (   pixel)    (((pixel) >> CacheShift) << (0*(8-CacheShift)))

Referenced by CacheOffset().

◆ ReduceImageTag

#define ReduceImageTag   "Reduce/Image"

Referenced by ReduceImageColors().

Typedef Documentation

◆ CubeInfo

typedef struct _CubeInfo CubeInfo

◆ NodeInfo

typedef struct _NodeInfo NodeInfo

◆ Nodes

typedef struct _Nodes Nodes

Function Documentation

◆ AcquirePixelThreadSet()

static DoublePixelPacket** AcquirePixelThreadSet ( const size_t  count)

◆ AcquireQuantizeInfo()

◆ AssignImageColors()

static MagickBooleanType AssignImageColors ( Image image,
CubeInfo cube_info 

Definition at line 477 of file quantize.c.

References AcquireAuthenticCacheView(), AcquireImageColormap(), AssignImageTag, _CubeInfo::associate_alpha, AssociateAlphaPixel(), _PixelPacket::blue, _NodeInfo::child, ClosestColor(), _CubeInfo::color_number, _Image::colormap, _CubeInfo::colors, _Image::colors, _QuantizeInfo::colorspace, _Image::colorspace, ColorToNodeId(), _Image::columns, DefineImageColormap(), DestroyCacheView(), _CubeInfo::distance, _QuantizeInfo::dither, _QuantizeInfo::dither_method, DitherImage(), _Image::exception, _Image::filename, GetCacheViewAuthenticIndexQueue(), GetCacheViewAuthenticPixels(), GetImageQuantizeError(), GetPixelLuma(), GRAYColorspace, _PixelPacket::green, IsSameColor(), IssRGBCompatibleColorspace(), LinearGRAYColorspace, magick_restrict, MagickFalse, MagickMax, MagickTrue, _CubeInfo::maximum_colors, MaxTreeDepth, _QuantizeInfo::measure_error, NoDitherMethod, _QuantizeInfo::number_colors, _PixelPacket::opacity, _NodeInfo::parent, _Image::progress_monitor, PseudoClass, _CubeInfo::quantize_info, QuantumRange, _PixelPacket::red, ResourceLimitError, _CubeInfo::root, _Image::rows, SetImageProgress(), SetPixelIndex, SetPixelOpacity, SetPixelRgb, _Image::storage_class, SyncCacheViewAuthenticPixels(), SyncImage(), _CubeInfo::target, ThrowBinaryImageException, TransformImageColorspace(), _CubeInfo::transparent_index, _CubeInfo::transparent_pixels, and UndefinedColorspace.

Referenced by QuantizeImage(), QuantizeImages(), RemapImage(), and RemapImages().

◆ AssociateAlphaPixel()

◆ CacheOffset()

◆ ClassifyImageColors()

◆ CloneQuantizeInfo()

◆ ClosestColor()

◆ ColorToNodeId()

static size_t ColorToNodeId ( const CubeInfo cube_info,
const DoublePixelPacket pixel,
size_t  index 

◆ CompressImageColormap()

◆ DefineImageColormap()

◆ DestroyCubeInfo()

◆ DestroyPixelThreadSet()

static DoublePixelPacket** DestroyPixelThreadSet ( DoublePixelPacket **  pixels)

◆ DestroyQuantizeInfo()

◆ DitherImage()

◆ FloydSteinbergDither()

◆ GetCubeInfo()

◆ GetImageQuantizeError()

◆ GetNodeInfo()

static NodeInfo * GetNodeInfo ( CubeInfo cube_info,
const size_t  id,
const size_t  level,
NodeInfo parent 

◆ GetQuantizeInfo()

◆ IntensityCompare()

static int IntensityCompare ( const void *  x,
const void *  y 

Definition at line 3206 of file quantize.c.

References PixelPacketIntensity().

Referenced by SetGrayscaleImage().

◆ IsSameColor()

static MagickBooleanType IsSameColor ( const Image image,
const PixelPacket p,
const PixelPacket q 

◆ MagickRealTypeCompare()

static int MagickRealTypeCompare ( const void *  error_p,
const void *  error_q 

Definition at line 2969 of file quantize.c.

References MagickEpsilon.

Referenced by ReduceImageColors().

◆ MagickRound()

static double MagickRound ( double  x)

Definition at line 2277 of file quantize.c.

◆ PosterizeImage()

MagickExport MagickBooleanType PosterizeImage ( Image image,
const size_t  levels,
const MagickBooleanType  dither 

Definition at line 2287 of file quantize.c.

References DefaultChannels, and PosterizeImageChannel().

◆ PosterizeImageChannel()

◆ PruneChild()

◆ PruneLevel()

static void PruneLevel ( CubeInfo cube_info,
const NodeInfo node_info 

◆ PruneToCubeDepth()

static void PruneToCubeDepth ( CubeInfo cube_info,
const NodeInfo node_info 

◆ QuantizeErrorFlatten()

static size_t QuantizeErrorFlatten ( const CubeInfo cube_info,
const NodeInfo node_info,
const ssize_t  offset,
MagickRealType quantize_error 

◆ QuantizeImage()

◆ QuantizeImages()

◆ Reduce()

◆ ReduceImageColors()

◆ RemapImage()

◆ RemapImages()

◆ Riemersma()

static void Riemersma ( Image image,
CacheView image_view,
CubeInfo cube_info,
const size_t  level,
const unsigned int  direction 

Definition at line 1653 of file quantize.c.

References EastGravity, NorthGravity, RiemersmaDither(), SouthGravity, and WestGravity.

Referenced by DitherImage().

◆ RiemersmaDither()

◆ SetAssociatedAlpha()

static void SetAssociatedAlpha ( const Image image,
CubeInfo cube_info 

◆ SetGrayscaleImage()