1 /* Copyright (C) kaerou 2021.
2 ** Distributed under the Boost Software License, Version 1.0.
3 ** (See accompanying file LICENSE_1_0.txt or copy at
4 ** https://www.boost.org/LICENSE_1_0.txt)
6 module magickd
.core
.c
.image
;
10 import core
.stdc
.config
: c_long
, c_ulong
;
11 import core
.stdc
.stdio
: FILE
;
13 import magickd
.core
.c
.common
;
14 import magickd
.core
.c
.colorspace
;
15 import magickd
.core
.c
.error
;
16 import magickd
.core
.c
.timer
;
19 @nogc @system extern(C
):
21 enum QuantumDepth
= 16;
23 static if (QuantumDepth
== 8)
25 enum MaxColormapSize
= 256U;
28 enum MaxMapFloat
= 255.0f;
29 enum MaxMapDouble
= 255.0;
31 enum MaxRGBFloat
= 255.0f;
32 enum MaxRGBDouble
= 255.0;
33 /* TODO: Scale functions */
34 alias Quantum
= ubyte;
36 else static if (QuantumDepth
== 16)
38 enum MaxColormapSize
= 65536U;
40 enum MaxMapDepth
= 16;
41 enum MaxMapFloat
= 65535.0f;
42 enum MaxMapDouble
= 65535.0;
44 enum MaxRGBFloat
= 65535.0f;
45 enum MaxRGBDouble
= 65535.0;
46 /* TODO: Scale functions */
47 alias Quantum
= ushort;
49 else static if (QuenatumDepth
== 32)
51 enum MaxColormapSize
= 65536U;
52 enum MaxRGB
= 4294967295U;
53 enum MaxRGBFloat
= 4294967295.0f;
54 enum MaxRGBDouble
= 4294967295.0;
55 /* MaxMap defines the maximum index value for algorithms which depend on
56 * lookup tables (e.g. colorspace transformations and normalizations).
57 * When MaxMap is less than MaxRGB it is necessary to downscale samples to
58 * fit the range of MaxMap. The number of bits which are effectively
59 * preserved depend on the size of MaxMap. MaxMap should be a multiple of
60 * 255 and no larger the MaxRGB. Note that tables can become quite large
61 * and as tables grow larger it may take more time to compute the table
62 * than to process the image. */
64 enum MaxMapDepth
= 16;
65 enum MaxMapFloat
= 65535.0f;
66 enum MaxMapDouble
= 65535.0;
68 static if (MaxMap
== 65535U)
70 /* TODO: Scale functions */
74 /* TODO: Scale functions */
80 static assert(false, "Specified value of QuantumDepth is not supported");
84 alias AlphaType
= int;
92 alias ChannelType
= int;
96 RedChannel
, /* RGB Red channel */
97 CyanChannel
, /* CMYK Cyan channel */
98 GreenChannel
, /* RGB Green channel */
99 MagentaChannel
, /* CMYK Magenta channel */
100 BlueChannel
, /* RGB Blue channel */
101 YellowChannel
, /* CMYK Yellow channel */
102 OpacityChannel
, /* Opacity channel */
103 BlackChannel
, /* CMYK Black (K) channel */
104 MatteChannel
, /* Same as Opacity channel (deprecated) */
105 AllChannels
, /* Color channels */
106 GrayChannel
/* Color channels represent an intensity. */
109 /// ClassType enumeration specifies the image storage class.
110 alias ClassType
= int;
115 /// Image is composed of pixels which represent literal color values.
117 /// Image is composed of pixels which specify an index in a color palette.
122 + CompositeOperator is used to select the image composition algorithm used to
123 + compose a "composite image" with an "image".
125 + By default, each of the "composite image" pixels are replaced by the
126 + corresponding "image" tile pixel. Specify CompositeOperator to select a
127 + different algorithm.
129 + The image compositor requires a matte, or alpha channel in the image for
130 + some operations. This extra channel usually defines a mask which
131 + represents a sort of a cookie-cutter for the image. This is the case when
132 + matte is 255 (full coverage) for pixels inside the shape, zero outside, and
133 + between zero and 255 on the boundary. For certain operations, if "image"
134 + does not have a matte channel, it is initialized with `0` for any pixel
135 + matching in color to pixel location `(0, 0)`, otherwise 255 (to work
136 + properly borderWidth must be `0`).
138 alias CompositeOperator
= int;
145 UndefinedCompositeOp
= 0,
147 + The result is the union of the two image shapes with the "composite
148 + image" obscuring the "image" in the region of overlap.
152 + The result is a simply "composite image" cut by the shape of "image".
153 + None of the image data of "image" is included in the result.
157 + The resulting image is "composite image" with the shape of "image" cut
162 + The result is the same shape as "image", with "composite image"
163 + obscuring "image" where the image shapes overlap.
165 + Note that this differs from `OverCompositeOp` because the portion of
166 + "composite image" outside of "image"'s shape does not appear in the
171 + The result is the image data from both "composite image" and "image"
172 + that is outside the overlap region.
174 + The overlap region will be blank.
178 + The result is just the sum of image data.
180 + Output values are cropped to 255 (no overflow). This operation is
181 + independent of the matte channels.
185 + The result of `"composite image" - "image"`, with overflow cropped to
188 + The matte channel is ignored (set to 255, full coverate).
192 + The result of `"composite image" + "image"`, with overflow wrapping
197 + The result of `"composite image" - "image"`, with underflow wrapping
200 + The add and subtract operators can be used to perform reversible
205 + The result of `abs("composite image" - "image")`.
207 + This is useful for comparing two very similar images.
209 DifferenceCompositeOp
,
211 + The result image shaded by "composite image".
215 + The resulting image is "image" replaced with "composite image".
217 + Here the matte information is ignored.
221 + The resulting image is the red layer in "image" replaced with the red
222 + layer in the "composite image".
224 + The othe layers are copied untouched.
228 + The resulting image is the green layer in "image" replaced with the
229 + green layer in the "composite image".
231 + The othe layers are copied untouched.
233 CopyGreenCompositeOp
,
235 + The resulting image is the blue layer in "image" replaced with the blue
236 + layer in the "composite image".
238 + The othe layers are copied untouched.
242 + The resulting image is the matte layer in "image" replaced with the
243 + matte layer in the "composite image".
245 + The othe layers are copied untouched.
247 CopyOpacityCompositeOp
,
249 + Pixels in the region are set to Transparent.
255 + Modulate brightness in HSL space.
258 ThresholdCompositeOp
,
266 + Copy Hue channel (from HSL colorspace)
270 + Copy Saturation channel (from HSL colorspace)
274 + Copy Hue and Saturation channels (from HSL colorspace)
278 + Copy Brightness channel (from HSL colorspace)
281 /// [Not yet implemented]
283 /// [Not yet implemented]
286 + Copy the Cyan channel.
290 + Copy the Magenta channel.
292 CopyMagentaCompositeOp
,
294 + Copy the Yellow channel.
296 CopyYellowCompositeOp
,
298 + Copy the Black channel.
300 CopyBlackCompositeOp
,
302 HardLightCompositeOp
,
303 ExclusionCompositeOp
,
304 ColorDodgeCompositeOp
,
305 ColorBurnCompositeOp
,
306 SoftLightCompositeOp
,
307 LinearBurnCompositeOp
,
308 LinearDodgeCompositeOp
,
309 LinearLightCompositeOp
,
310 VividLightCompositeOp
,
316 + CompressionType is used to express the desired compression type when
319 + Be aware that most image types only support a sub-set of the available
320 + compression types. If the compression type specified is incompatible with
321 + the image, Magick will select a compression type compatible with the image
322 + type, which might be no compression at all.
324 alias CompressionType
= int;
329 UndefinedCompression
,
333 + BZip (Burrows-Wheeler block-sorting text compression algorithm and
334 + Huffman coding) as used by bzip2 utilities.
337 /// CCITT Group 3 FAX compression
339 /// CCITT Group 4 FAX compression (used only for TIFF)
343 /// Lossless JPEG compression
344 LosslessJPEGCompression
,
345 /// Lempel-Ziv-Welch (LZW) compression (caution: patented by Unisys)
347 /// Run-Length encoded (RLE) compression
349 /// Lempel-Ziv compression (LZ77) as used in PKZIP and GNU gzip.
351 /// LZMA - Lempel-Ziv-Markov chain algorithm
353 /// JPEG 2000 - ISO/IEC std 15444-1
355 /// JBIG v1 - ISO/IEC std 11544 / ITU-T rec T.82
357 /// JBIG v2 - ISO/IEC std 14492 / ITU-T rec T.88
359 /// Facebook's Zstandard/Zstd
365 alias DisposeType
= int;
374 alias EndianType
= int;
378 LSBEndian
, /* "little" endian */
379 MSDEndian
, /* "big" endian */
380 NativeEndian
/* native endian */
383 alias FilterTypes
= int;
405 + GravityType specifies positioning of an object (e.g. text, image) within a
406 + bouding region (e.g. an image).
408 + Gravity provides a convenient way to locate objects irrespective of the
409 + size of the bounding region, in other words, you don't need to provide
410 + absolute coordinates in order to position an object. A common default for
411 + gravity is NorthWestGravity.
413 alias GravityType
= int;
417 /// Don't use gravity.
419 /// Position object at top-left of region.
421 /// Position object at top-center of region.
423 /// Position object at top-right of region.
425 /// Position object at left-center of region.
427 /// Position object at center of region.
429 /// Position object at right-center of region.
431 /// Position object at left-bottom of region.
433 /// Position object at bottom-center of region.
435 /// Position object at bottom-right of region.
441 + ImageType indicates the type classification of the image.
443 alias ImageType
= int;
449 /// Monochrome image.
453 /// Grayscale image with opacity
455 /// Indexed color (palette) image.
457 /// Indexed color (palette) image with opacity.
461 /// Truecolor image with opacity.
463 /// Cyan/Yellow/Magenta/Black (CYMK) image
465 /// Cyan/Yellow/Magenta/Black (CYMK) image with opacity.
466 ColorSeparationMatteType
,
471 + InterlaceType specifies the ordering of the red, green, and blue pixel
472 + information in the image.
474 + Interlacing is usually used to make image information available to the user
475 + faster by taking advantage of the space vs. time tradeoff. For example,
476 + interlacing allows images on the Web to be recognizable sooner and
477 + satellite images to accumulate/render with image resolution increasing over
480 + Use `LineInterlace` or `PlaneInterlace` to create an interlace GIF or
481 + progressive JPEG image.
483 alias InterlaceType
= int;
492 + Don't interlace image (RGBRGBRGBRGBRGBRGB...)
496 + Use scanline interlacing (RRR...GGG...BBB...RRR...GGG...BBB)
500 + Use plane interlacing (RRRRRR...GGGGGG...BBBBBB...)
504 + Similar to plane interlacing except that the different planes are
505 + saved to individual files (e.g. image.R, image.G, and image.B)
511 + NoiseType is used as an argument to select the type of noise to be added to
514 alias NoiseType
= int;
520 MultiplicativeGaussianNoise
,
529 + OrientationType specifies the orientation of the image.
531 + Useful for when the image is produced via a different ordinate system, the
532 + camera was turned on its side, or the page was scanned sideways.
534 alias OrientationType
= int;
538 /// Scanline dir: Unknown; Frame dir: Unknown
539 UndefinedOrientation
,
540 /// Scanline dir: Left to Right; Frame dir: Top to Bottom
542 /// Scanline dir: Right to Left; Frame dir: Top to Bottom
544 /// Scanline dir: Right to Left; Frame dir: Bottom to Top
545 BottomRightOrientation
,
546 /// Scanline dir: Left to Right; Frame dir: Bottom to Top
547 BottomLeftOrientation
,
548 /// Scanline dir: Top to Bottom; Frame dir: Left to Right
550 /// Scanline dir: Top to Bottom; Frame dir: Right to Left
552 /// Scanline dir: Bottom to Top; Frame dir: Right to Left
553 RightBottomOrientation
,
554 /// Scanline dir: Bottom to Top; Frame dir: Left to Right
555 LeftBottomOrientation
558 alias PreviewType
= int;
561 UndefinedPreview
= 0,
589 CharcoalDrawingPreview
,
594 + Rendering intent is a concept defined by ICC Spec ICC.1:1998-09, "File
595 + Format for Color Profiles".
597 + GraphicsMagick uses RenderingIntent in order to support ICC Color Profiles.
599 + From the specification:
600 + "Rendering intent specifies the style of reproduction to be used during the
601 + evaluation of this profile in a sequence of profiles. It applies
602 + specifically to that profile in the sequence and not to th entire sequence.
603 + Typically, the user or application will set the rendering intent
604 + dynamically at runtime or embedding time."
606 alias RenderingIntent
= int;
615 + A rendering intent that specifies the saturation of the pixels in the
616 + image is preserved perhaps at the expense of accuracy in hue and
621 + A rendering intent that specifies the full gamut of the image is
622 + compressed or expanded to fill the gamut of the destination device.
624 + Gray balance is preserved but colorimetric accuracy might not be
629 + Absolute colorimetric.
633 + Relative colorimetric
639 + By default, Magick defines resolution pixels per inch.
641 + ResolutionType provides a means to adjust this.
643 alias ResolutionType
= int;
650 + Density specifications are specified in units of pixels per inch
653 PixelsPerInchResolution
,
655 + Density specifications are specified in units of pixels per centimeter
658 PixelsPerCentimeterResolution
663 + --------------------------------------------------------------------------
664 + Structure Definitions
665 + --------------------------------------------------------------------------
687 + The ChromaticityInfo structure is used to represent chromaticity
688 + (colorspace primary coordinates in xy space) values for images in Magick.
690 struct ChromaticityInfo
692 /// Chromaticity red primary point (e.g. x=0.64, y=0.33)
693 PrimaryInfo red_primary
;
694 /// Chromaticity green primary point (e.g. x=3, y=0.6)
695 PrimaryInfo green_primary
;
696 /// Chromaticity blue primary point (e.g. x=0.15, y=0.06)
697 PrimaryInfo blue_primary
;
698 /// Chromaticity white point (e.g. x=0.3127, y=0.329)
699 PrimaryInfo white_point
;
706 // enum MAGICK_PIXELS_RGBA = 1;
713 /* BGRA (as used by Microsoft Windows DIB) */
714 // enum MAGICK_PIXELS_BGRA = 1;
722 struct DoublePixelPacket
730 struct FloatPixelPacket
739 + ErrorInfo is used to record statistical difference (error) information
740 + based on computed Euclidean distance in RGB space.
744 /// Average error per pixel (absolute range).
745 double mean_error_per_pixel
;
746 /// Average error per pixel (normalized to 1.0).
747 double normalized_mean_error
;
748 /// Maximum error encountered (normalized to 1.0).
749 double normalized_maximum_error
;
753 + The RectangleInfo structure is used to represent positioning information
762 /// Rectangle horizontal offset
764 /// Rectangle vertical offset.
771 struct _ThreadViewSet
;
772 struct _ImageAttribute
;
775 struct _SemaphoreInfo
;
778 + The image structure represents a Magick image.
780 + It is initially allocated by AllocateImage() and deallocated by
781 + DestroyImage(). The functions ReadImage(), ReadImages(), BlobToImage,
782 + and CreateImage() return a new Image. Use CloneImage() to copy an image.
783 + An image consists of a structure containing image attributes as well as the
789 + Image storage class.
791 + If DirectClass then the image packets contain valid RGB or CMYK colors.
792 + If PseudoClass then the image has a colormap referenced by pixel's
795 ClassType storage_class
;
797 + Image pixel interpretation.
799 + If the colorspace is RGB the pixels are red, green, blue. If matte is
800 + true, then red, green, blue, and index. If it is CMYK, the pixels are
801 + cyan, yellow, magenta, black. Otherwise, the colorspace is ignored.
803 ColorspaceType colorspace
;
805 + Image compression type.
807 + The default compression type of the specified image file.
809 CompressionType compression
;
811 + Should the image be dithered.
815 + If non-zero, then the index member of pixels represents the alpha
828 + The desired number of colors.
830 + Used by QuantizeImage().
836 + Number of encoding bits per sample. Usually 8 or 16, but sometimes
841 + PseudoColor palette array.
843 PixelPacket
* colormap
;
845 + Image background color.
847 PixelPacket background_color
;
849 + Image border color.
851 PixelPacket border_color
;
853 + Image matte (transparent) color.
855 PixelPacket matte_color
;
857 ChromaticityInfo chromaticity
;
858 OrientationType orientation
;
859 RenderingIntent rendering_intent
;
860 ResolutionType units
;
868 RectangleInfo tile_info
;
872 InterlaceType interlace
;
875 CompositeOperator compose
;
880 c_ulong total_colors
;
885 char[MaxTextExtent
] filename
;
886 char[MaxTextExtent
] magick_filename
;
887 char[MaxTextExtent
] magick
;
888 c_ulong magick_columns
;
890 ExceptionInfo exception
;
905 _ThreadViewSet
* default_views
;
906 _ImageAttribute
* attributes
;
907 _Ascii85Info
* ascii85
;
910 c_long reference_count
;
912 _SemaphoreInfo
* semaphore
;
923 + Image compresion type.
925 + The default is the compression type of the specified image file.
927 CompressionType compression
;
929 + Remove file "filename" once it has been read.
931 MagickBool temporary
;
933 + Join images into a single multi-image file.
937 + Control antialiasing of rendered Postscript and Postscript or TrueType
938 + fonts. Enabled by default.
940 MagickBool antialias
;
942 + Subimage of an image sequence.
946 + Number of images relative to the base image.
950 + Image depth (8 or 16).
954 + Width and height of a raw image (an image which does not support width
955 + and height information).
957 + Size may also be used to affect the image size read from a
958 + multi-resolution format (e.g. Photo CD, JBIG, or JPEG).
966 + Equivalent size of Postscript page.
970 + The type of interlacing scheme (default NoInterlace).
972 + This option is used to specify the type of interlacing scheme for raw
973 + image formats such as RGB or YUV. NoInterlace means to not interlace,
974 + LineInterlace uses scanline interlacing, and PlaneInterlace uses plane
975 + interlacing. PartitionInterlace is like PlaneInterlace except the
976 + different planes are saved to individual files (e.g. image.R, image.G,
977 + and image.B). Use LineInterlace or PlaneInterlace to create an
978 + interlaced GIF or progressive JPEG image.
980 InterlaceType interlace
;
982 + Select MSB/LSB endian output for TIFF format.
986 + Units of image resolution.
988 ResolutionType units
;
990 + JPEG/MIFF/PNG compression level (default 75).
994 + JPEG, MPEG, and YUV chroma downsample factor.
996 char* sampling_factor
;
998 + X11 display to obtain fonts from, or to capture image from.
1002 + Text rendering font.
1004 + If the font is a fully qualified X server font name, the font is
1005 + obtained from an X server. To use a TrueType font, precede the
1006 + TrueType filename with an `@`. Otherwise, specify a Postscript font
1007 + name (e.g. "helvetica").
1011 + Image filename to use as background texture.
1015 + Vertical and horizontal resolution in pixels of the image.
1017 + This option specifies an image density when decoding a Postscript or
1018 + Portable Document page. Often used with page.
1022 + Text rendering font point size.
1026 + Colors within this distance are considered equal.
1028 + A number of algorithms seach for a target color. By default the color
1029 + must be exact. Use this option to match colors that are close to the
1030 + target color in RGB space.
1034 + Stroke or fill color while drawing.
1038 + Image background color
1040 PixelPacket background_color
;
1042 + Image border color.
1044 PixelPacket border_color
;
1046 + Image matte (transparent) color.
1048 PixelPacket matte_color
;
1050 + Apply Floyd/Steinberg error diffusion to the image.
1052 + The basic strategy of dithering is to trade intensity resolution for
1053 + spacial resolution by averaging the intesities of several neighboring
1054 + pixels. Images which suffer from severe contouring when reducing
1055 + colors can be improved with this option. The colors or monochrome
1056 + option must be set for this option to take effect.
1060 + Transform the image to black and white.
1062 MagickBool monochrome
;
1064 + Show progress indication.
1066 MagickBool progress
;
1068 + Image pixel interpretation.
1070 + If the colorspace is RGB the pixels are red, green, blue. If `matte`
1071 + is true, then red, green, blue, and index. If it is CMYK, the pixels
1072 + are cyan, yellow, magenta, black. Otherwise the colorspace is ignored.
1074 ColorspaceType colorspace
;
1076 + Desired image type (used while reading or writing).
1080 + X11 Window group ID
1084 + Print detailed information about the image if True.
1088 + FlashPix viewing parameters.
1092 + Password used to decrypt file.
1096 + User-specified data to pass to coder.
1100 + stdio stream to read image from or write image to.
1102 + If set, Magick will read from or write to the stream rather than
1103 + opening a file. Used by ReadImage() and WriteImage(). The stream is
1104 + closed when the operation completes.
1108 + Image encoding format (e.g. "GIF").
1110 char[MaxTextExtent
] magick
;
1112 + Image file name to read or write.
1114 char[MaxTextExtent
] filename
;
1116 /* private members */
1118 /* private. used to pass image via open cache */
1121 /* private. Map of coder specific options passed by user. */
1128 PreviewType preview
;
1136 char[MaxTextExtent
] unique
;
1137 char[MaxTextExtent
] zero
;
1144 + --------------------------------------------------------------------------
1146 + --------------------------------------------------------------------------
1151 + AccessDefinition() searches the definitions for an entry matching the
1152 + specified magick and key.
1154 + NULL is returned if no matching entry is found.
1157 + image_info = The image info.
1158 + magick = Format ID. This is usually the same as the coder name.
1159 + key = The key to search for.
1161 const(char)* AccessDefinition(const ImageInfo
* image_info
, const char* magick
,
1165 + AddDefinition() adds a key/value definition to the current map of
1166 + definitions in ImageInfo.
1168 + Definitions may be used by coders/decoders that read and write images.
1171 + image_info = The image info.
1172 + magick = Format/classification identifier.
1173 + key = Subidentifier within format/classification.
1174 + value = Definition value
1175 + exception = Errors result in updates to this structure.
1177 MagickPassFail
AddDefinition(ImageInfo
* image_info
, const char* magick
,
1178 const char* key
, const char* value
,
1179 ExceptionInfo
* exception
);
1182 + CloneImageInfo() copies an image and returns the copy as a new image
1185 + If the specified `columns and `rows` is `0`, an exact copy of the image is
1186 + returned, otherwise, the pixel data is undefined and must be initialzed
1187 + with the SetImagePixels() and SyncImagePixels() methods. On failure, a
1188 + NULL image is returned and `exception` describes the reason for failure.
1192 + columns = The number of columns in the cloned image.
1193 + rows = The numbe of rows in the cloned image.
1194 + orphan = With a value other than 0, the cloned image is an orphan. An
1195 + orphan is a stand-alone image that is not associated with an image list.
1196 + In effect, the next and previous members of the cloned image is set to
1198 + exception = Return any errors or warnings to this structure.
1200 Image
* CloneImage(const Image
* image
, const c_ulong columns
,
1201 const c_ulong rows
, const uint orphan
,
1202 ExceptionInfo
* exception
);
1205 + CloneImageInfo() makes a copy of the given `ImageInfo` structure.
1207 + If NULL is specified, a new image info structure is created an initialized
1208 + to default values.
1211 + image_info = The image info
1213 ImageInfo
* CloneImageInfo(const ImageInfo
* image_info
);
1216 + DestroyImage() dereferences an image, deallocating memory associated with
1217 + the image if the reference count becomes zero.
1219 + There is no effect if the image pointer is null.
1221 + In the interest of avoiding dangling pointers or memory leaks, the image
1222 + previous and next pointers should be null when this function is called, and
1223 + no othe image should refer to it. In the future this may be enforced.
1226 + image = The image.
1228 void DestroyImage(Image
* image
);
1231 + DestroyImageInfo() deallocates memory associated with an `ImageInfo`
1235 + image_info = The image info.
1237 void DestroyImageInfo(ImageInfo
* image_info
);