MagickCore 7.1.0
Convert, Edit, Or Compose Bitmap Images
quantize.c File Reference
Include dependency graph for quantize.c:

Go to the source code of this file.

Data Structures

struct  _DoublePixelPacket
 
struct  _NodeInfo
 
struct  _Nodes
 
struct  _CubeInfo
 
struct  _KmeansInfo
 

Macros

#define CacheShift   2
 
#define ErrorQueueLength   16
 
#define ErrorRelativeWeight   PerceptibleReciprocal(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 KmeansImageTag   "Kmeans/Image"
 
#define RandomColorComponent(info)   (QuantumRange*GetPseudoRandomValue(info))
 
#define PosterizeImageTag   "Posterize/Image"
 
#define PosterizePixel(pixel)
 
#define ReduceImageTag   "Reduce/Image"
 

Typedefs

typedef struct _DoublePixelPacket DoublePixelPacket
 
typedef struct _NodeInfo NodeInfo
 
typedef struct _Nodes Nodes
 
typedef struct _CubeInfo CubeInfo
 
typedef struct _KmeansInfo KmeansInfo
 

Functions

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 *, ExceptionInfo *)
 
static MagickBooleanType ClassifyImageColors (CubeInfo *, const Image *, ExceptionInfo *)
 
static MagickBooleanType DitherImage (Image *, CubeInfo *, ExceptionInfo *)
 
static MagickBooleanType SetGrayscaleImage (Image *, ExceptionInfo *)
 
static MagickBooleanType SetImageColormap (Image *, CubeInfo *, ExceptionInfo *)
 
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 Image *image, const CubeInfo *cube_info, const Quantum *pixel, DoublePixelPacket *alpha_pixel)
 
static void AssociateAlphaPixelInfo (const CubeInfo *cube_info, const PixelInfo *pixel, DoublePixelPacket *alpha_pixel)
 
static size_t ColorToNodeId (const CubeInfo *cube_info, const DoublePixelPacket *pixel, size_t index)
 
static void SetAssociatedAlpha (const Image *image, CubeInfo *cube_info)
 
MagickExport QuantizeInfoCloneQuantizeInfo (const QuantizeInfo *quantize_info)
 
MagickExport MagickBooleanType CompressImageColormap (Image *image, ExceptionInfo *exception)
 
MagickExport QuantizeInfoDestroyQuantizeInfo (QuantizeInfo *quantize_info)
 
static DoublePixelPacket ** DestroyPixelTLS (DoublePixelPacket **pixels)
 
static DoublePixelPacket ** AcquirePixelTLS (const size_t count)
 
static ssize_t CacheOffset (CubeInfo *cube_info, const DoublePixelPacket *pixel)
 
static MagickBooleanType FloydSteinbergDither (Image *image, CubeInfo *cube_info, ExceptionInfo *exception)
 
static MagickBooleanType RiemersmaDither (Image *image, CacheView *image_view, CubeInfo *cube_info, const unsigned int direction, ExceptionInfo *exception)
 
static MagickBooleanType Riemersma (Image *image, CacheView *image_view, CubeInfo *cube_info, const size_t level, const unsigned int direction, ExceptionInfo *exception)
 
MagickExport MagickBooleanType GetImageQuantizeError (Image *image, ExceptionInfo *exception)
 
MagickExport void GetQuantizeInfo (QuantizeInfo *quantize_info)
 
static KmeansInfo ** DestroyKmeansTLS (KmeansInfo **kmeans_info)
 
static int DominantColorCompare (const void *x, const void *y)
 
static KmeansInfo ** AcquireKmeansTLS (const size_t number_colors)
 
static double KmeansMetric (const Image *magick_restrict image, const Quantum *magick_restrict p, const PixelInfo *magick_restrict q)
 
MagickExport MagickBooleanType KmeansImage (Image *image, const size_t number_colors, const size_t max_iterations, const double tolerance, ExceptionInfo *exception)
 
static double MagickRound (double x)
 
MagickExport MagickBooleanType PosterizeImage (Image *image, const size_t levels, const DitherMethod dither_method, ExceptionInfo *exception)
 
static void PruneChild (CubeInfo *cube_info, const NodeInfo *node_info)
 
MagickExport MagickBooleanType QuantizeImage (const QuantizeInfo *quantize_info, Image *image, ExceptionInfo *exception)
 
MagickExport MagickBooleanType QuantizeImages (const QuantizeInfo *quantize_info, Image *images, ExceptionInfo *exception)
 
static size_t QuantizeErrorFlatten (const CubeInfo *cube_info, const NodeInfo *node_info, const ssize_t offset, double *quantize_error)
 
static void Reduce (CubeInfo *cube_info, const NodeInfo *node_info)
 
static int QuantizeErrorCompare (const void *error_p, const void *error_q)
 
MagickExport MagickBooleanType RemapImage (const QuantizeInfo *quantize_info, Image *image, const Image *remap_image, ExceptionInfo *exception)
 
MagickExport MagickBooleanType RemapImages (const QuantizeInfo *quantize_info, Image *images, const Image *remap_image, ExceptionInfo *exception)
 
static int IntensityCompare (const void *x, const void *y)
 

Macro Definition Documentation

◆ AlphaShift

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

◆ AssignImageTag

#define AssignImageTag   "Assign/Image"

◆ BlueShift

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

◆ CacheShift

#define CacheShift   2

Definition at line 213 of file quantize.c.

◆ ClassifyImageTag

#define ClassifyImageTag   "Classify/Image"

◆ DitherImageTag [1/2]

#define DitherImageTag   "Dither/Image"

◆ DitherImageTag [2/2]

#define DitherImageTag   "Dither/Image"

◆ ErrorQueueLength

#define ErrorQueueLength   16

Definition at line 217 of file quantize.c.

◆ ErrorRelativeWeight

#define ErrorRelativeWeight   PerceptibleReciprocal(16)

Definition at line 218 of file quantize.c.

◆ GreenShift

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

◆ KmeansImageTag

#define KmeansImageTag   "Kmeans/Image"

◆ MaxNodes

#define MaxNodes   266817

Definition at line 219 of file quantize.c.

◆ MaxTreeDepth

#define MaxTreeDepth   8

Definition at line 220 of file quantize.c.

◆ NodesInAList

#define NodesInAList   1920

Definition at line 221 of file quantize.c.

◆ PosterizeImageTag

#define PosterizeImageTag   "Posterize/Image"

◆ PosterizePixel

#define PosterizePixel (   pixel)
Value:
MagickRound(QuantumScale*pixel*(levels-1)))/MagickMax((ssize_t) levels-1,1))
#define MagickMax(x, y)
Definition: image-private.h:38
MagickDoubleType MagickRealType
Definition: magick-type.h:124
#define QuantumRange
Definition: magick-type.h:87
#define QuantumScale
Definition: magick-type.h:119
static double MagickRound(double x)
Definition: quantize.c:2818
static Quantum ClampToQuantum(const MagickRealType quantum)
Definition: quantum.h:86

◆ RandomColorComponent

#define RandomColorComponent (   info)    (QuantumRange*GetPseudoRandomValue(info))

◆ RedShift

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

◆ ReduceImageTag

#define ReduceImageTag   "Reduce/Image"

Typedef Documentation

◆ CubeInfo

typedef struct _CubeInfo CubeInfo

◆ DoublePixelPacket

◆ KmeansInfo

typedef struct _KmeansInfo KmeansInfo

◆ NodeInfo

typedef struct _NodeInfo NodeInfo

◆ Nodes

typedef struct _Nodes Nodes

Function Documentation

◆ AcquireKmeansTLS()

static KmeansInfo ** AcquireKmeansTLS ( const size_t  number_colors)
static

Definition at line 2395 of file quantize.c.

References AcquireQuantumMemory(), DestroyKmeansTLS(), GetMagickResourceLimit(), and ThreadResource.

Referenced by KmeansImage().

◆ AcquirePixelTLS()

static DoublePixelPacket ** AcquirePixelTLS ( const size_t  count)
static

◆ AcquireQuantizeInfo()

◆ AssignImageColors()

◆ AssociateAlphaPixel()

◆ AssociateAlphaPixelInfo()

◆ CacheOffset()

◆ ClassifyImageColors()

◆ CloneQuantizeInfo()

◆ ClosestColor()

◆ ColorToNodeId()

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

◆ CompressImageColormap()

◆ DefineImageColormap()

◆ DestroyCubeInfo()

◆ DestroyKmeansTLS()

static KmeansInfo ** DestroyKmeansTLS ( KmeansInfo **  kmeans_info)
static

Definition at line 2371 of file quantize.c.

References GetMagickResourceLimit(), RelinquishMagickMemory(), and ThreadResource.

Referenced by AcquireKmeansTLS(), and KmeansImage().

◆ DestroyPixelTLS()

static DoublePixelPacket ** DestroyPixelTLS ( DoublePixelPacket **  pixels)
static

◆ DestroyQuantizeInfo()

◆ DitherImage()

◆ DominantColorCompare()

static int DominantColorCompare ( const void *  x,
const void *  y 
)
static

Definition at line 2384 of file quantize.c.

References _PixelInfo::count.

Referenced by KmeansImage().

◆ FloydSteinbergDither()

◆ GetCubeInfo()

◆ GetImageQuantizeError()

◆ GetNodeInfo()

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

◆ GetQuantizeInfo()

◆ IntensityCompare()

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

Definition at line 3756 of file quantize.c.

References GetPixelInfoIntensity().

Referenced by SetGrayscaleImage().

◆ KmeansImage()

MagickExport MagickBooleanType KmeansImage ( Image image,
const size_t  number_colors,
const size_t  max_iterations,
const double  tolerance,
ExceptionInfo exception 
)

Definition at line 2466 of file quantize.c.

References AcquireAuthenticCacheView(), AcquireImageColormap(), AcquireKmeansTLS(), AcquireQuantizeInfo(), AcquireRandomInfo(), AllCompliance, _PixelInfo::alpha, _KmeansInfo::alpha, _Image::alpha_trait, _PixelInfo::black, _KmeansInfo::black, _PixelInfo::blue, _KmeansInfo::blue, ClassifyImageColors(), CloneImage(), CMYKColorspace, _Image::colormap, _CubeInfo::colors, _Image::colors, _Image::colorspace, _QuantizeInfo::colorspace, _Image::columns, CopyMagickString(), _PixelInfo::count, _KmeansInfo::count, _Image::debug, DestroyCacheView(), DestroyCubeInfo(), DestroyImage(), DestroyKmeansTLS(), DestroyQuantizeInfo(), DestroyRandomInfo(), _KmeansInfo::distortion, _QuantizeInfo::dither_method, DominantColorCompare(), _Image::filename, FormatLocaleFile(), GetCacheViewAuthenticPixels(), GetColorTuple(), GetCubeInfo(), GetImageArtifact(), GetMagickModule, GetMagickPrecision(), GetMagickResourceLimit(), GetOpenMPThreadId(), GetPixelAlpha(), GetPixelBlack(), GetPixelBlue(), GetPixelChannels(), GetPixelGreen(), GetPixelRed(), _PixelInfo::green, _KmeansInfo::green, ImageEvent, IsEventLogging(), IsStringTrue(), KmeansImageTag, KmeansMetric(), LogMagickEvent(), magick_restrict, MagickCoreSignature, MagickEpsilon, MagickFalse, MagickMin, MagickPathExtent, MagickTrue, _CubeInfo::maximum_colors, NoDitherMethod, _QuantizeInfo::number_colors, PerceptibleReciprocal(), _Image::progress_monitor, QuantumRange, QuantumScale, QueryColorCompliance(), random_info, RandomColorComponent, _PixelInfo::red, _KmeansInfo::red, ReduceImageColors(), ResourceLimitError, _Image::rows, SetImageColormap(), SetImageProgress(), SetImageProperty(), SetPixelIndex(), _ExceptionInfo::signature, _Image::signature, SyncCacheViewAuthenticPixels(), SyncImage(), ThreadResource, ThrowBinaryException, TraceEvent, and UndefinedPixelTrait.

◆ KmeansMetric()

◆ MagickRound()

static double MagickRound ( double  x)
inlinestatic

Definition at line 2818 of file quantize.c.

◆ PosterizeImage()

◆ PruneChild()

◆ PruneLevel()

static void PruneLevel ( CubeInfo cube_info,
const NodeInfo node_info 
)

◆ PruneToCubeDepth()

static void PruneToCubeDepth ( CubeInfo cube_info,
const NodeInfo node_info 
)

◆ QuantizeErrorCompare()

static int QuantizeErrorCompare ( const void *  error_p,
const void *  error_q 
)
static

Definition at line 3509 of file quantize.c.

References MagickEpsilon.

Referenced by ReduceImageColors().

◆ QuantizeErrorFlatten()

static size_t QuantizeErrorFlatten ( const CubeInfo cube_info,
const NodeInfo node_info,
const ssize_t  offset,
double *  quantize_error 
)
static

◆ QuantizeImage()

◆ QuantizeImages()

◆ Reduce()

◆ ReduceImageColors()

◆ RemapImage()

◆ RemapImages()

◆ Riemersma()

static MagickBooleanType Riemersma ( Image image,
CacheView image_view,
CubeInfo cube_info,
const size_t  level,
const unsigned int  direction,
ExceptionInfo exception 
)
static

◆ RiemersmaDither()

◆ SetAssociatedAlpha()

static void SetAssociatedAlpha ( const Image image,
CubeInfo cube_info 
)
inlinestatic

◆ SetGrayscaleImage()

◆ SetImageColormap()