1 module dmagick.c.morphology; 2 3 import dmagick.c.exception; 4 import dmagick.c.geometry; 5 import dmagick.c.image; 6 import dmagick.c.magickType; 7 import dmagick.c.magickVersion; 8 9 alias ptrdiff_t ssize_t; 10 11 extern(C) 12 { 13 mixin( 14 { 15 string info = "enum KernelInfoType 16 { 17 UndefinedKernel, /* equivelent to UnityKernel */"; 18 19 static if ( MagickLibVersion >= 0x662 ) 20 { 21 info ~= "UnityKernel, /* The no-op or 'original image' kernel */"; 22 } 23 24 info ~= "GaussianKernel, /* Convolution Kernels, Gaussian Based */"; 25 26 static if ( MagickLibVersion >= 0x662 ) 27 { 28 info ~= "DoGKernel, 29 LoGKernel,"; 30 } 31 32 info ~= "BlurKernel,"; 33 34 static if ( MagickLibVersion == 0x662 ) 35 { 36 info ~= "DOBKernel,"; 37 } 38 39 info ~= "CometKernel, 40 LaplacianKernel, /* Convolution Kernels, by Name */"; 41 42 static if ( MagickLibVersion < 0x662 ) 43 { 44 info ~= "DoGKernel, 45 LoGKernel, 46 RectangleKernel /* Shape Kernels */, 47 SquareKernel, 48 DiamondKernel,"; 49 } 50 51 static if ( MagickLibVersion >= 0x662 ) 52 { 53 info ~= "SobelKernel, 54 FreiChenKernel, 55 RobertsKernel, 56 PrewittKernel, 57 CompassKernel, 58 KirschKernel, 59 DiamondKernel, /* Shape Kernels */ 60 SquareKernel, 61 RectangleKernel,"; 62 } 63 64 static if ( MagickLibVersion >= 0x670 ) 65 { 66 info ~= "OctagonKernel,"; 67 } 68 69 info ~= "DiskKernel, 70 PlusKernel,"; 71 72 static if ( MagickLibVersion >= 0x662 ) 73 { 74 info ~= "CrossKernel, 75 RingKernel, 76 PeaksKernel, /* Hit And Miss Kernels */ 77 EdgesKernel, 78 CornersKernel,"; 79 } 80 81 static if ( MagickLibVersion < 0x663 ) 82 { 83 info ~= "RidgesKernel"; 84 } 85 static if ( MagickLibVersion >= 0x663 ) 86 { 87 info ~= "ThinDiagonalsKernel,"; 88 } 89 90 static if ( MagickLibVersion >= 0x662 ) 91 { 92 info ~= "LineEndsKernel, 93 LineJunctionsKernel,"; 94 } 95 96 static if ( MagickLibVersion >= 0x663 ) 97 { 98 info ~= "RidgesKernel,"; 99 } 100 101 static if ( MagickLibVersion >= 0x662 ) 102 { 103 info ~= "ConvexHullKernel, 104 SkeletonKernel,"; 105 } 106 107 info ~= "ChebyshevKernel, /* Distance Measuring Kernels */ 108 ManhattanKernel, 109 EuclideanKernel, 110 UserDefinedKernel, /* User Specified Kernel Array */"; 111 112 static if ( MagickLibVersion >= 0x679 ) 113 { 114 info ~= "BinomialKernel"; 115 } 116 info ~= "}"; 117 118 return info; 119 }()); 120 121 mixin( 122 { 123 string method = "enum MorphologyMethod 124 { 125 UndefinedMorphology, 126 127 /* Convolve / Correlate weighted sums */ 128 ConvolveMorphology, /* Weighted Sum with reflected kernel */ 129 CorrelateMorphology, /* Weighted Sum using a sliding window */ 130 131 /* Low-level Morphology methods */ 132 ErodeMorphology, /* Minimum Value in Neighbourhood */ 133 DilateMorphology, /* Maximum Value in Neighbourhood */ 134 ErodeIntensityMorphology, /* Pixel Pick using GreyScale Erode */ 135 DilateIntensityMorphology, /* Pixel Pick using GreyScale Dialate */ 136 DistanceMorphology, /* Add Kernel Value, take Minimum */ 137 138 /* Second-level Morphology methods */ 139 OpenMorphology, /* Dilate then Erode */ 140 CloseMorphology, /* Erode then Dilate */ 141 OpenIntensityMorphology, /* Pixel Pick using GreyScale Open */ 142 CloseIntensityMorphology, /* Pixel Pick using GreyScale Close */"; 143 144 static if ( MagickLibVersion >= 0x662 ) 145 { 146 method ~= "SmoothMorphology, /* Open then Close */"; 147 } 148 149 method ~= " 150 /* Difference Morphology methods */ 151 EdgeInMorphology, /* Dilate difference from Original */ 152 EdgeOutMorphology, /* Erode difference from Original */ 153 EdgeMorphology, /* Dilate difference with Erode */ 154 TopHatMorphology, /* Close difference from Original */ 155 BottomHatMorphology, /* Open difference from Original */ 156 157 /* Recursive Morphology methods */ 158 HitAndMissMorphology, /* Foreground/Background pattern matching */ 159 ThinningMorphology, /* Remove matching pixels from image */ 160 ThickenMorphology, /* Add matching pixels from image */ 161 162 /* Experimental Morphology methods */ 163 VoronoiMorphology, /* distance matte channel copy nearest color */ 164 IterativeDistanceMorphology /* Add Kernel Value, take Minimum */ 165 }"; 166 167 return method; 168 }()); 169 170 struct KernelInfo 171 { 172 KernelInfoType 173 type; 174 175 size_t 176 width, 177 height; 178 179 ssize_t 180 x, 181 y; 182 183 double* values; 184 185 double 186 minimum, 187 maximum, 188 negative_range, 189 positive_range; 190 191 static if ( MagickLibVersion >= 0x662 ) 192 { 193 double 194 angle; 195 196 KernelInfo* 197 next; 198 } 199 200 size_t 201 signature; 202 } 203 204 205 KernelInfo* AcquireKernelInfo(const(char)*); 206 KernelInfo* AcquireKernelBuiltIn(const KernelInfoType, const(GeometryInfo)*); 207 208 static if ( MagickLibVersion >= 0x661 ) 209 { 210 KernelInfo* CloneKernelInfo(const(KernelInfo)*); 211 } 212 213 KernelInfo* DestroyKernelInfo(KernelInfo*); 214 215 Image* MorphologyImage(const(Image)*, const MorphologyMethod, const ssize_t, const(KernelInfo)*, ExceptionInfo*); 216 Image* MorphologyImageChannel(const(Image)*, const ChannelType, const MorphologyMethod, const ssize_t, const(KernelInfo)*, ExceptionInfo*); 217 218 static if ( MagickLibVersion >= 0x662 ) 219 { 220 void ScaleGeometryKernelInfo(KernelInfo*, const(char)*); 221 } 222 else static if ( MagickLibVersion == 0x661 ) 223 { 224 void ScaleKernelInfo(KernelInfo*, const double, const GeometryFlags); 225 } 226 227 void ShowKernelInfo(const(KernelInfo)*); 228 }