1 module dmagick.c.image;
2 
3 import core.stdc.stdio;
4 import core.stdc.time;
5 
6 import dmagick.c.cacheView;
7 import dmagick.c.color;
8 import dmagick.c.colorspace;
9 import dmagick.c.composite;
10 import dmagick.c.compress;
11 import dmagick.c.compress;
12 import dmagick.c.effect;
13 import dmagick.c.exception;
14 import dmagick.c.geometry;
15 import dmagick.c.layer;
16 import dmagick.c.magickType;
17 import dmagick.c.magickVersion;
18 import dmagick.c.monitor;
19 import dmagick.c.pixel;
20 import dmagick.c.profile;
21 import dmagick.c.quantum;
22 import dmagick.c.resample;
23 import dmagick.c.semaphore;
24 import dmagick.c.stream;
25 import dmagick.c.timer;
26 
27 alias ptrdiff_t ssize_t;
28 
29 extern(C)
30 {
31 	/**
32 	 * Used to set a flag on an image indicating whether or not to use
33 	 * existing alpha channel data, to create an alpha channel, or to
34 	 * perform other operations on the alpha channel.
35 	 */
36 	enum AlphaChannelType
37 	{
38 		/** */
39 		UndefinedAlphaChannel,
40 
41 		/**
42 		 * Enable the image's transparency channel. Note normally
43 		 * SetAlphaChannel should be used instead of this, unless you
44 		 * specifically need to preserve existing (but specifically turned
45 		 * Off) transparency channel.
46 		 */
47 		ActivateAlphaChannel,
48 
49 		/**
50 		 * Set any fully-transparent pixel to the background color, while
51 		 * leaving it fully-transparent. This can make some image file
52 		 * formats, such as PNG, smaller as the RGB values of transparent
53 		 * pixels are more uniform, and thus can compress better.
54 		 */
55 		BackgroundAlphaChannel,
56 
57 		/**
58 		 * Turns On the alpha/matte channel, then copies the gray-scale
59 		 * intensity of the image, into the alpha channel, converting a
60 		 * gray-scale mask into a transparent shaped mask ready to be
61 		 * colored appropriately. The color channels are not modified.
62 		 */
63 		CopyAlphaChannel,
64 
65 		/**
66 		 * Disables the image's transparency channel. Does not delete or
67 		 * change the existing data, just turns off the use of that data.
68 		 */
69 		DeactivateAlphaChannel,
70 
71 		/**
72 		 * Copies the alpha channel values into all the color channels and
73 		 * turns 'Off' the the image's transparency, so as to generate a
74 		 * gray-scale mask of the image's shape. The alpha channel data is
75 		 * left intact just deactivated. This is the inverse of
76 		 * CopyAlphaChannel.
77 		 */
78 		ExtractAlphaChannel,
79 
80 		/**
81 		 * Enables the alpha/matte channel and forces it to be fully opaque.
82 		 */
83 		OpaqueAlphaChannel,
84 
85 		/** */
86 		ResetAlphaChannel,
87 
88 		/**
89 		 * Activates the alpha/matte channel. If it was previously turned
90 		 * off then it also resets the channel to opaque. If the image
91 		 * already had the alpha channel turned on, it will have no effect.
92 		 */
93 		SetAlphaChannel,
94 
95 		/**
96 		 * As per CopyAlphaChannel but also colors the resulting shape mask
97 		 * with the current background color. That is the RGB color channels
98 		 * is replaced, with appropriate alpha shape.
99 		 */
100 		ShapeAlphaChannel,
101 
102 		/**
103 		 * Activates the alpha/matte channel and forces it to be fully
104 		 * transparent. This effectively creates a fully transparent image
105 		 * the same size as the original and with all its original RGB data
106 		 * still intact, but fully transparent.
107 		 */
108 		TransparentAlphaChannel,
109 
110 		/**
111 		 * Flatten image pixels over the background pixels.
112 		 * 
113 		 * Since: ImageMagick 6.7.6.
114 		 */
115 		FlattenAlphaChannel,
116 
117 		/** ditto */
118 		RemoveAlphaChannel,
119 
120 		/** */
121 		AssociateAlphaChannel,
122 
123 		/** */
124 		DisassociateAlphaChannel
125 	}
126 
127 	/**
128 	 * Indicate the type classification of the image.
129 	 */
130 	enum ImageType
131 	{
132 		UndefinedType,       /// No type has been specified.
133 		BilevelType,         /// Monochrome image.
134 		GrayscaleType,       /// Grayscale image.
135 		GrayscaleMatteType,  /// Grayscale image with opacity.
136 		PaletteType,         /// Indexed color (palette) image.
137 		PaletteMatteType,    /// Indexed color (palette) image with opacity.
138 		TrueColorType,       /// Truecolor image.
139 		TrueColorMatteType,  /// Truecolor image with opacity.
140 		ColorSeparationType, /// Cyan/Yellow/Magenta/Black (CYMK) image.
141 		ColorSeparationMatteType, /// Cyan/Yellow/Magenta/Black (CYMK) image with opacity.
142 		OptimizeType,        ///
143 		PaletteBilevelMatteType   ///
144 	}
145 
146 	/**
147 	 * Specify the ordering of the red, green, and blue pixel information in
148 	 * the image. Interlacing is usually used to make image information
149 	 * available to the user faster by taking advantage of the space vs
150 	 * time tradeoff. For example, interlacing allows images on the Web to
151 	 * be recognizable sooner and satellite images to accumulate/render with
152 	 * image resolution increasing over time. Use LineInterlace or
153 	 * PlaneInterlace to create an interlaced GIF or progressive JPEG image.
154 	 */
155 	enum InterlaceType
156 	{
157 		/**
158 		 * No interlace type has been specified.
159 		 */
160 		UndefinedInterlace,
161 
162 		/**
163 		 * Don't interlace image (RGBRGBRGBRGBRGBRGB...).
164 		 */
165 		NoInterlace,
166 
167 		/**
168 		 * Use scanline interlacing (RRR...GGG...BBB...RRR...GGG...BBB...).
169 		 */
170 		LineInterlace,
171 
172 		/**
173 		 * Use plane interlacing (RRRRRR...GGGGGG...BBBBBB...).
174 		 */
175 		PlaneInterlace,
176 
177 		/**
178 		 * Similar to plane interlacing except that the different planes are
179 		 * saved to individual files (e.g. image.R, image.G, and image.B)
180 		 */
181 		PartitionInterlace,
182 
183 		/** */
184 		GIFInterlace,
185 
186 		/** */
187 		JPEGInterlace,
188 
189 		/** */
190 		PNGInterlace
191 	}
192 
193 	/**
194 	 * Specify the orientation of the image pixels.
195 	 */
196 	enum OrientationType
197 	{
198 		/**
199 		 * See_Also: $(LINK http://jpegclub.org/exif_orientation.html )
200 		 */
201 		UndefinedOrientation,
202 		TopLeftOrientation,      /// ditto
203 		TopRightOrientation,     /// ditto
204 		BottomRightOrientation,  /// ditto
205 		BottomLeftOrientation,   /// ditto
206 		LeftTopOrientation,      /// ditto
207 		RightTopOrientation,     /// ditto
208 		RightBottomOrientation,  /// ditto
209 		LeftBottomOrientation    /// ditto
210 	}
211 
212 	/**
213 	 * By default, ImageMagick defines resolutions in pixels per inch.
214 	 * ResolutionType provides a means to adjust this.
215 	 */
216 	enum ResolutionType
217 	{
218 		/**
219 		 * No resolution has been specified.
220 		 */
221 		UndefinedResolution,
222 
223 		/**
224 		 * Density specifications are specified in units
225 		 * of pixels per inch (English units).
226 		 */
227 		PixelsPerInchResolution,
228 
229 		/**
230 		 * Density specifications are specified in units
231 		 * of pixels per centimeter (metric units).
232 		 */
233 		PixelsPerCentimeterResolution
234 	}
235 
236 	/** */
237 	struct PrimaryInfo
238 	{
239 		double
240 			x, /// X ordinate.
241 			y, /// Y ordinate.
242 			z; /// Z ordinate. This attribute is always ignored.
243 	}
244 
245 	struct SegmentInfo
246 	{
247 		double
248 			x1,
249 			y1,
250 			x2,
251 			y2;
252 	}
253 
254 	enum TransmitType
255 	{
256 		UndefinedTransmitType,
257 		FileTransmitType,
258 		BlobTransmitType,
259 		StreamTransmitType,
260 		ImageTransmitType
261 	}
262 
263 	/**
264 	 * A Chromaticity object represents chromaticity values.
265 	 */
266 	struct ChromaticityInfo
267 	{
268 		PrimaryInfo
269 			red_primary,   /// Red primary point (e.g. red_primary.x=0.64, red_primary.y=0.33)
270 			green_primary, /// Green primary point (e.g. green_primary.x=0.3, green_primary.y=0.6)
271 			blue_primary,  /// Blue primary point (e.g. blue_primary.x=0.15, blue_primary.y=0.06)
272 			white_point;   /// White point (e.g. white_point.x=0.3127, white_point.y=0.329)
273 	}
274 
275 	struct Image
276 	{
277 		ClassType
278 			storage_class;
279 
280 		ColorspaceType
281 			colorspace;      /* colorspace of image data */
282 
283 		CompressionType
284 			compression;     /* compression of image when read/write */
285 
286 		size_t
287 			quality;         /* compression quality setting, meaning varies */
288 
289 		OrientationType
290 			orientation;     /* photo orientation of image */
291 
292 		MagickBooleanType
293 			taint,           /* has image been modified since reading */
294 			matte;           /* is transparency channel defined and active */
295 
296 		size_t
297 			columns,         /* physical size of image */
298 			rows,
299 			depth,           /* depth of image on read/write */
300 			colors;          /* size of color table on read */
301 
302 		PixelPacket*
303 			colormap;
304 
305 		PixelPacket
306 			background_color, /* current background color attribute */
307 			border_color,     /* current bordercolor attribute */
308 			matte_color;      /* current mattecolor attribute */
309 
310 		double
311 			gamma;
312 
313 		ChromaticityInfo
314 			chromaticity;
315 
316 		RenderingIntent
317 			rendering_intent;
318 
319 		void*
320 			profiles;
321 
322 		ResolutionType
323 			units;           /* resolution/density  ppi or ppc */
324 
325 		char*
326 			montage,
327 			directory,
328 			geometry;
329 
330 		ssize_t
331 			offset;
332 
333 		double
334 			x_resolution,    /* image resolution/density */
335 			y_resolution;
336 
337 		RectangleInfo
338 			page,            /* virtual canvas size and offset of image */
339 			extract_info,
340 			tile_info;       /* deprecated */
341 
342 		double
343 			bias,
344 			blur,            /* deprecated */
345 			fuzz;            /* current color fuzz attribute */
346 
347 		FilterTypes
348 			filter;          /* resize/distort filter to apply */
349 
350 		InterlaceType
351 			interlace;
352 
353 		EndianType
354 			endian;          /* raw data integer ordering on read/write */
355 
356 		GravityType
357 			gravity;         /* Gravity attribute for positioning in image */
358 
359 		CompositeOperator
360 			compose;         /* alpha composition method for layered images */
361 
362 		DisposeType
363 			dispose;         /* GIF animation disposal method */
364 
365 		Image*
366 			clip_mask;
367 
368 		size_t
369 			scene,           /* index of image in multi-image file */
370 			delay;           /* Animation delay time */
371 
372 		ssize_t
373 			ticks_per_second;  /* units for delay time, default 100 for GIF */
374 
375 		size_t
376 			iterations,
377 			total_colors;
378 
379 		ssize_t
380 			start_loop;
381 
382 		ErrorInfo
383 			error;
384 
385 		TimerInfo
386 			timer;
387 
388 		MagickProgressMonitor
389 			progress_monitor;
390 
391 		void*
392 			client_data,
393 			cache,
394 			attributes;      /* deprecated */
395 
396 		Ascii85Info*
397 			ascii85;
398 
399 		BlobInfo*
400 			blob;
401 
402 		char[MaxTextExtent]
403 			filename,        /* images input filename */
404 			magick_filename, /* ditto with coders, and read_mods */
405 			magick;          /* Coder used to decode image */
406 
407 		size_t
408 			magick_columns,
409 			magick_rows;
410 
411 		ExceptionInfo
412 			exception;       /* Error handling report */
413 
414 		MagickBooleanType
415 			ddebug;          /* debug output attribute */
416 
417 		ssize_t
418 			reference_count;
419 
420 		SemaphoreInfo*
421 			semaphore;
422 
423 		ProfileInfo
424 			color_profile,
425 			iptc_profile;
426 
427 		ProfileInfo*
428 			generic_profile;
429 
430 		size_t
431 			generic_profiles;
432 
433 		size_t
434 			signature;
435 
436 		Image*
437 			previous,        /* Image list links */
438 			list,            /* Undo/Redo image processing list (for display) */
439 			next;            /* Image list links */
440 
441 		InterpolatePixelMethod
442 			interpolate;     /* Interpolation of color for between pixel lookups */
443 
444 		MagickBooleanType
445 			black_point_compensation;
446 
447 		PixelPacket
448 			transparent_color; /* color for 'transparent' color index in GIF */
449 
450 		Image*
451 			mask;
452 
453 		RectangleInfo
454 			tile_offset;
455 
456 		void*
457 			properties,      /* per image properities */
458 			artifacts;       /* per image sequence image artifacts */
459 
460 		ImageType
461 			type;
462 
463 		MagickBooleanType
464 			dither;          /* dithering method during color reduction */
465 
466 		MagickSizeType
467 			extent;
468 
469 		static if ( MagickLibVersion >= 0x662 )
470 		{
471 			MagickBooleanType
472 				ping;
473 		}
474 
475 		static if ( MagickLibVersion >= 0x670 )
476 		{
477 			size_t
478 				channels;
479 		}
480 
481 		static if ( MagickLibVersion >= 0x683 )
482 		{
483 			time_t
484 				timestamp;
485 		}
486 
487 		static if ( MagickLibVersion >= 0x684 )
488 		{
489 			PixelIntensityMethod
490 				intensity;      /* method to generate an intensity value from a pixel */
491 		}
492 
493 		static if ( MagickLibVersion >= 0x689 )
494 		{
495 			/** Total animation duration sum(delay*iterations) */
496 			size_t duration;
497 		}
498 
499 		static if ( MagickLibVersion >= 0x693 )
500 		{
501 			long tietz_offset;
502 		}
503 	}
504 
505 	struct ImageInfo
506 	{
507 		CompressionType
508 			compression;
509 
510 		OrientationType
511 			orientation;
512 
513 		MagickBooleanType
514 			temporary,
515 			adjoin,
516 			affirm,
517 			antialias;
518 
519 		char*
520 			size,
521 			extract,
522 			page,
523 			scenes;
524 
525 		size_t
526 			scene,
527 			number_scenes,
528 			depth;
529 
530 		InterlaceType
531 			interlace;
532 
533 		EndianType
534 			endian;
535 
536 		ResolutionType
537 			units;
538 
539 		size_t
540 			quality;
541 
542 		char*
543 			sampling_factor,
544 			server_name,
545 			font,
546 			texture,
547 			density;
548 
549 		double
550 			pointsize,
551 			fuzz;
552 
553 		PixelPacket
554 			background_color,
555 			border_color,
556 			matte_color;
557 
558 		MagickBooleanType
559 			dither,
560 			monochrome;
561 
562 		size_t
563 			colors;
564 
565 		ColorspaceType
566 			colorspace;
567 
568 		ImageType
569 			type;
570 
571 		PreviewType
572 			preview_type;
573 
574 		ssize_t
575 			group;
576 
577 		MagickBooleanType
578 			ping,
579 			verbose;
580 
581 		char*
582 			view,
583 			authenticate;
584 
585 		ChannelType
586 			channel;
587 
588 		Image*
589 			attributes;
590 
591 		void*
592 			options;
593 
594 		MagickProgressMonitor
595 			progress_monitor;
596 
597 		void*
598 			client_data,
599 			cache;
600 
601 		StreamHandler
602 			stream;
603 
604 		FILE*
605 			file;
606 
607 		void*
608 			blob;
609 
610 		size_t
611 			length;
612 
613 		char[MaxTextExtent]
614 			magick,
615 			unique,
616 			zero,
617 			filename;
618 
619 		MagickBooleanType
620 			ddebug;
621 
622 		char*
623 			tile;
624 
625 		size_t
626 			subimage,
627 			subrange;
628 
629 		PixelPacket
630 			pen;
631 
632 		size_t
633 			signature;
634 
635 		VirtualPixelMethod
636 			virtual_pixel_method;
637 
638 		PixelPacket
639 			transparent_color;
640 
641 		void*
642 			profile;
643 
644 		MagickBooleanType
645 			synchronize;
646 	}
647 
648 	ExceptionType CatchImageException(Image*);
649 
650 	FILE* GetImageInfoFile(const(ImageInfo)*);
651 
652 	Image* AcquireImage(const(ImageInfo)*);
653 	Image* AppendImages(const(Image)*, const MagickBooleanType, ExceptionInfo*);
654 	Image* CloneImage(const(Image)*, const size_t, const size_t, const MagickBooleanType, ExceptionInfo*);
655 	Image* DestroyImage(Image*);
656 	Image* GetImageClipMask(const(Image)*, ExceptionInfo*);
657 	Image* GetImageMask(const(Image)*, ExceptionInfo*);
658 	Image* NewMagickImage(const(ImageInfo)*, const size_t, const size_t, const(MagickPixelPacket)*);
659 	Image* ReferenceImage(Image*);
660 
661 	static if ( MagickLibVersion >= 0x668 )
662 	{
663 		Image* SmushImages(const(Image)*, const MagickBooleanType, const ssize_t, ExceptionInfo*);
664 	}
665 
666 	ImageInfo* AcquireImageInfo();
667 	ImageInfo* CloneImageInfo(const(ImageInfo)*);
668 	ImageInfo* DestroyImageInfo(ImageInfo*);
669 
670 	static if (MagickLibVersion < 0x662)
671 	{
672 		MagickBooleanType AcquireImageColormap(Image*, const size_t);
673 	}
674 
675 	MagickBooleanType ClipImage(Image*);
676 	MagickBooleanType ClipImagePath(Image*, const(char)*, const MagickBooleanType);
677 
678 	static if (MagickLibVersion >= 0x692)
679 	{
680 		MagickBooleanType CopyImagePixels(Image*, const(Image)*, const(RectangleInfo)*, const(OffsetInfo)*, ExceptionInfo*);
681 	}
682 
683 	MagickBooleanType IsTaintImage(const(Image)*);
684 	MagickBooleanType IsMagickConflict(const(char)*);
685 	MagickBooleanType IsHighDynamicRangeImage(const(Image)*, ExceptionInfo*);
686 	MagickBooleanType IsImageObject(const(Image)*);
687 	MagickBooleanType ListMagickInfo(FILE*, ExceptionInfo*);
688 	MagickBooleanType ModifyImage(Image**, ExceptionInfo*);
689 	MagickBooleanType ResetImagePage(Image*, const(char)*);
690 	MagickBooleanType SetImageBackgroundColor(Image*);
691 	MagickBooleanType SetImageClipMask(Image*, const(Image)*);
692 
693 	static if (MagickLibVersion >= 0x662)
694 	{
695 		MagickBooleanType SetImageColor(Image*, const(MagickPixelPacket)*);
696 	}
697 
698 	MagickBooleanType SetImageColor(Image*, const(MagickPixelPacket)*);
699 	MagickBooleanType SetImageExtent(Image*, const size_t, const size_t);
700 	MagickBooleanType SetImageInfo(ImageInfo*, const uint, ExceptionInfo*);
701 	MagickBooleanType SetImageMask(Image*, const(Image)*);
702 	MagickBooleanType SetImageOpacity(Image*, const Quantum);
703 
704 	static if ( MagickLibVersion >= 0x670 )
705 	{
706 		MagickBooleanType SetImageChannels(Image*, const size_t);
707 	}
708 
709 	MagickBooleanType SetImageStorageClass(Image*, const ClassType);
710 	MagickBooleanType StripImage(Image*);
711 	MagickBooleanType SyncImage(Image*);
712 	MagickBooleanType SyncImageSettings(const(ImageInfo)*, Image*);
713 	MagickBooleanType SyncImagesSettings(ImageInfo*, Image*);
714 
715 	size_t InterpretImageFilename(const(ImageInfo)*, Image*, const(char)*, int, char*);
716 
717 	ssize_t GetImageReferenceCount(Image*);
718 
719 	static if ( MagickLibVersion >= 0x670 )
720 	{
721 		size_t GetImageChannels(Image*);
722 	}
723 
724 	VirtualPixelMethod GetImageVirtualPixelMethod(const(Image)*);
725 	VirtualPixelMethod SetImageVirtualPixelMethod(const(Image)*, const VirtualPixelMethod);
726 
727 	void AcquireNextImage(const(ImageInfo)*, Image*);
728 	void DestroyImagePixels(Image*);
729 	void DisassociateImageStream(Image*);
730 	void GetImageException(Image*, ExceptionInfo*);
731 	void GetImageInfo(ImageInfo*);
732 	void SetImageInfoBlob(ImageInfo*, const(void)*, const size_t);
733 	void SetImageInfoFile(ImageInfo*, FILE*);
734 }