1 module dmagick.c.quantum; 2 3 import dmagick.c.cacheView; 4 import dmagick.c.exception; 5 import dmagick.c.image; 6 import dmagick.c.magickType; 7 import dmagick.c.magickVersion; 8 9 extern(C) 10 { 11 /** 12 * The endianess of the image when reading the image file. 13 */ 14 enum EndianType 15 { 16 UndefinedEndian, /// Not defined (default). 17 LSBEndian, /// Little Endian. 18 MSBEndian /// Big Endian. 19 } 20 21 enum QuantumAlphaType 22 { 23 UndefinedQuantumAlpha, 24 AssociatedQuantumAlpha, 25 DisassociatedQuantumAlpha 26 } 27 28 enum QuantumFormatType 29 { 30 UndefinedQuantumFormat, 31 FloatingPointQuantumFormat, 32 SignedQuantumFormat, 33 UnsignedQuantumFormat 34 } 35 36 enum QuantumType 37 { 38 UndefinedQuantum, 39 AlphaQuantum, 40 BlackQuantum, 41 BlueQuantum, 42 CMYKAQuantum, 43 CMYKQuantum, 44 CyanQuantum, 45 GrayAlphaQuantum, 46 GrayQuantum, 47 GreenQuantum, 48 IndexAlphaQuantum, 49 IndexQuantum, 50 MagentaQuantum, 51 OpacityQuantum, 52 RedQuantum, 53 RGBAQuantum, 54 BGRAQuantum, 55 RGBOQuantum, 56 RGBQuantum, 57 YellowQuantum, 58 GrayPadQuantum, 59 RGBPadQuantum, 60 CbYCrYQuantum, 61 CbYCrQuantum, 62 CbYCrAQuantum, 63 CMYKOQuantum, 64 BGRQuantum, 65 BGROQuantum 66 } 67 68 struct QuantumInfo {} 69 70 alias ClampToQuantum RoundToQuantum; 71 static pure nothrow Quantum ClampToQuantum(const MagickRealType value) 72 { 73 version(MagickCore_HDRI) 74 { 75 return value; 76 } 77 else 78 { 79 if (value <= 0.0) 80 return(cast(Quantum) 0); 81 if (value >= cast(MagickRealType) QuantumRange) 82 return(cast(Quantum) QuantumRange); 83 return(cast(Quantum) (value+0.5)); 84 } 85 } 86 87 static pure nothrow ubyte ScaleQuantumToChar(const Quantum quantum) 88 { 89 version(MagickCore_HDRI) 90 { 91 if ( quantum <= 0 ) 92 return 0; 93 static if ( MagickQuantumDepth == 8 ) 94 { 95 if ( quantum >= 255 ) 96 return 255; 97 return cast(ubyte)(quantum+0.5); 98 } 99 else static if ( MagickQuantumDepth == 16 ) 100 { 101 if ( quantum/257 >= 255) 102 return 255; 103 return cast(ubyte)(quantum/257+0.5); 104 } 105 else static if ( MagickQuantumDepth == 32 ) 106 { 107 if ( quantum/16843009 >= 255) 108 return 255; 109 return cast(ubyte)(quantum/16843009+0.5); 110 } 111 else 112 { 113 if ( quantum/72340172838076673 >= 255) 114 return 255; 115 return cast(ubyte)(quantum/72340172838076673+0.5); 116 } 117 } 118 else 119 { 120 static if ( MagickQuantumDepth == 8 ) 121 return quantum; 122 else static if ( MagickQuantumDepth == 16 ) 123 return cast(ubyte) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8); 124 else static if ( MagickQuantumDepth == 32 ) 125 return cast(ubyte) (quantum+8421504UL/16843009UL ); 126 else 127 return cast(ubyte) (quantum/72340172838076673.0+0.5); 128 } 129 } 130 131 static pure nothrow Quantum ScaleCharToQuantum(ubyte value) 132 { 133 enum Quantum factor = QuantumRange/255; 134 135 return cast(Quantum)(factor*value); 136 } 137 138 static if ( MagickLibVersion >= 0x681 ) 139 { 140 EndianType GetQuantumEndian(const(QuantumInfo)*); 141 } 142 143 MagickBooleanType SetQuantumDepth(const(Image)*, QuantumInfo*, const size_t); 144 145 static if ( MagickLibVersion >= 0x681 ) 146 { 147 MagickBooleanType SetQuantumEndian(const(Image)*, QuantumInfo*, const EndianType); 148 } 149 150 MagickBooleanType SetQuantumFormat(const(Image)*, QuantumInfo*, const QuantumFormatType); 151 MagickBooleanType SetQuantumPad(const(Image)*, QuantumInfo*, const size_t); 152 153 static if ( MagickLibVersion >= 0x674 ) 154 { 155 QuantumFormatType GetQuantumFormat(const(QuantumInfo)*); 156 } 157 158 QuantumInfo* AcquireQuantumInfo(const(ImageInfo)*, Image*); 159 QuantumInfo* DestroyQuantumInfo(QuantumInfo*); 160 161 QuantumType GetQuantumType(Image*, ExceptionInfo*); 162 163 size_t ExportQuantumPixels(const(Image)*, const(CacheView)*, const(QuantumInfo)*, const QuantumType, ubyte*, ExceptionInfo*); 164 size_t GetQuantumExtent(const(Image)*, const(QuantumInfo)*, const QuantumType); 165 size_t ImportQuantumPixels(Image*, CacheView*, const(QuantumInfo)*, const QuantumType, const(ubyte)*, ExceptionInfo*); 166 167 ubyte* GetQuantumPixels(const(QuantumInfo)*); 168 169 void GetQuantumInfo(const(ImageInfo)*, QuantumInfo*); 170 void SetQuantumAlphaType(QuantumInfo*, const QuantumAlphaType); 171 void SetQuantumImageType(Image*, const QuantumType); 172 void SetQuantumMinIsWhite(QuantumInfo*, const MagickBooleanType); 173 void SetQuantumPack(QuantumInfo*, const MagickBooleanType); 174 void SetQuantumQuantum(QuantumInfo*, const size_t); 175 void SetQuantumScale(QuantumInfo*, const double); 176 }