1 /*
2   Copyright 1999-2021 ImageMagick Studio LLC, a non-profit organization
3   dedicated to making software imaging solutions freely available.
4 
5   You may not use this file except in compliance with the License.  You may
6   obtain a copy of the License at
7 
8     https://imagemagick.org/script/license.php
9 
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15 
16   MagickCore image pixel methods.
17 */
18 #ifndef MAGICKCORE_PIXEL_H
19 #define MAGICKCORE_PIXEL_H
20 
21 #include "MagickCore/colorspace.h"
22 
23 #if defined(__cplusplus) || defined(c_plusplus)
24 extern "C" {
25 #endif
26 
27 #define MaxPixelChannels  64
28 #undef index
29 
30 /*
31   Pixel enum declarations.
32 */
33 typedef enum
34 {
35   UndefinedChannel = 0x0000,
36   RedChannel = 0x0001,
37   GrayChannel = 0x0001,
38   CyanChannel = 0x0001,
39   LChannel = 0x0001,
40   GreenChannel = 0x0002,
41   MagentaChannel = 0x0002,
42   aChannel = 0x0002,
43   BlueChannel = 0x0004,
44   bChannel = 0x0002,
45   YellowChannel = 0x0004,
46   BlackChannel = 0x0008,
47   AlphaChannel = 0x0010,
48   OpacityChannel = 0x0010,
49   IndexChannel = 0x0020,             /* Color Index Table? */
50   ReadMaskChannel = 0x0040,          /* Pixel is Not Readable? */
51   WriteMaskChannel = 0x0080,         /* Pixel is Write Protected? */
52   MetaChannel = 0x0100,              /* not used */
53   CompositeMaskChannel = 0x0200,     /* SVG mask */
54   CompositeChannels = 0x001F,
55   AllChannels = 0x7ffffff,
56   /*
57     Special purpose channel types.
58     FUTURE: are these needed any more - they are more like hacks
59     SyncChannels for example is NOT a real channel but a 'flag'
60     It really says -- "User has not defined channels"
61     Though it does have extra meaning in the "-auto-level" operator
62   */
63   TrueAlphaChannel = 0x0100, /* extract actual alpha channel from opacity */
64   RGBChannels = 0x0200,      /* set alpha from grayscale mask in RGB */
65   GrayChannels = 0x0400,
66   SyncChannels = 0x20000,    /* channels modified as a single unit */
67   DefaultChannels = AllChannels
68 } ChannelType;  /* must correspond to PixelChannel */
69 
70 typedef enum
71 {
72   UndefinedPixelChannel = 0,
73   RedPixelChannel = 0,
74   CyanPixelChannel = 0,
75   GrayPixelChannel = 0,
76   LPixelChannel = 0,
77   LabelPixelChannel = 0,
78   YPixelChannel = 0,
79   aPixelChannel = 1,
80   GreenPixelChannel = 1,
81   MagentaPixelChannel = 1,
82   CbPixelChannel = 1,
83   bPixelChannel = 2,
84   BluePixelChannel = 2,
85   YellowPixelChannel = 2,
86   CrPixelChannel = 2,
87   BlackPixelChannel = 3,
88   AlphaPixelChannel = 4,
89   IndexPixelChannel = 5,
90   ReadMaskPixelChannel = 6,
91   WriteMaskPixelChannel = 7,
92   MetaPixelChannel = 8,
93   CompositeMaskPixelChannel = 9,
94   IntensityPixelChannel = MaxPixelChannels,  /* ???? */
95   CompositePixelChannel = MaxPixelChannels,  /* ???? */
96   SyncPixelChannel = MaxPixelChannels+1      /* not a real channel */
97 } PixelChannel;  /* must correspond to ChannelType */
98 
99 typedef enum
100 {
101   UndefinedPixelIntensityMethod = 0,
102   AveragePixelIntensityMethod,
103   BrightnessPixelIntensityMethod,
104   LightnessPixelIntensityMethod,
105   MSPixelIntensityMethod,
106   Rec601LumaPixelIntensityMethod,
107   Rec601LuminancePixelIntensityMethod,
108   Rec709LumaPixelIntensityMethod,
109   Rec709LuminancePixelIntensityMethod,
110   RMSPixelIntensityMethod
111 } PixelIntensityMethod;
112 
113 typedef enum
114 {
115   UndefinedInterpolatePixel,
116   AverageInterpolatePixel,    /* Average 4 nearest neighbours */
117   Average9InterpolatePixel,   /* Average 9 nearest neighbours */
118   Average16InterpolatePixel,  /* Average 16 nearest neighbours */
119   BackgroundInterpolatePixel, /* Just return background color */
120   BilinearInterpolatePixel,   /* Triangular filter interpolation */
121   BlendInterpolatePixel,      /* blend of nearest 1, 2 or 4 pixels */
122   CatromInterpolatePixel,     /* Catmull-Rom interpolation */
123   IntegerInterpolatePixel,    /* Integer (floor) interpolation */
124   MeshInterpolatePixel,       /* Triangular Mesh interpolation */
125   NearestInterpolatePixel,    /* Nearest Neighbour Only */
126   SplineInterpolatePixel      /* Cubic Spline (blurred) interpolation */
127 } PixelInterpolateMethod;
128 
129 typedef enum
130 {
131   UndefinedPixelMask = 0x000000,
132   ReadPixelMask = 0x000001,
133   WritePixelMask = 0x000002,
134   CompositePixelMask = 0x000004
135 } PixelMask;
136 
137 typedef enum
138 {
139   UndefinedPixelTrait = 0x000000,
140   CopyPixelTrait = 0x000001,
141   UpdatePixelTrait = 0x000002,
142   BlendPixelTrait = 0x000004
143 } PixelTrait;
144 
145 typedef enum
146 {
147   UndefinedPixel,
148   CharPixel,
149   DoublePixel,
150   FloatPixel,
151   LongPixel,
152   LongLongPixel,
153   QuantumPixel,
154   ShortPixel
155 } StorageType;
156 
157 /*
158   Pixel typedef declarations.
159 */
160 typedef struct _PixelChannelMap
161 {
162   PixelChannel
163     channel;
164 
165   PixelTrait
166     traits;
167 
168   ssize_t
169     offset;
170 } PixelChannelMap;
171 
172 typedef struct _PixelInfo
173 {
174   ClassType
175     storage_class;
176 
177   ColorspaceType
178     colorspace;
179 
180   PixelTrait
181     alpha_trait;
182 
183   double
184     fuzz;
185 
186   size_t
187     depth;
188 
189   MagickSizeType
190     count;
191 
192   MagickRealType
193     red,
194     green,
195     blue,
196     black,
197     alpha,
198     index;
199 } PixelInfo;
200 
201 typedef struct _PixelPacket
202 {
203   unsigned int
204     red,
205     green,
206     blue,
207     alpha,
208     black;
209 } PixelPacket;
210 
211 typedef struct _CacheView
212   CacheView_;
213 
214 /*
215   Pixel method declarations.
216 */
217 extern MagickExport ChannelType
218   SetPixelChannelMask(Image *,const ChannelType);
219 
220 extern MagickExport MagickBooleanType
221   ExportImagePixels(const Image *,const ssize_t,const ssize_t,const size_t,
222     const size_t,const char *,const StorageType,void *,ExceptionInfo *),
223   ImportImagePixels(Image *,const ssize_t,const ssize_t,const size_t,
224     const size_t,const char *,const StorageType,const void *,ExceptionInfo *),
225   InterpolatePixelChannel(const Image *magick_restrict,const CacheView_ *,
226     const PixelChannel,const PixelInterpolateMethod,const double,const double,
227     double *,ExceptionInfo *),
228   InterpolatePixelChannels(const Image *magick_restrict,const CacheView_ *,
229     const Image * magick_restrict,const PixelInterpolateMethod,const double,
230     const double,Quantum *,ExceptionInfo *),
231   InterpolatePixelInfo(const Image *,const CacheView_ *,
232     const PixelInterpolateMethod,const double,const double,PixelInfo *,
233     ExceptionInfo *),
234   IsFuzzyEquivalencePixel(const Image *,const Quantum *,const Image *,
235     const Quantum *) magick_attribute((__pure__)),
236   IsFuzzyEquivalencePixelInfo(const PixelInfo *,const PixelInfo *)
237     magick_attribute((__pure__)),
238   SetPixelMetaChannels(Image *,const size_t,ExceptionInfo *),
239   SortImagePixels(Image *,ExceptionInfo *);
240 
241 extern MagickExport MagickRealType
242   GetPixelInfoIntensity(const Image *magick_restrict,
243     const PixelInfo *magick_restrict) magick_hot_spot,
244   GetPixelIntensity(const Image *magick_restrict,
245     const Quantum *magick_restrict) magick_hot_spot;
246 
247 extern MagickExport PixelChannelMap
248   *AcquirePixelChannelMap(void),
249   *ClonePixelChannelMap(PixelChannelMap *),
250   *DestroyPixelChannelMap(PixelChannelMap *);
251 
252 extern MagickExport PixelInfo
253   *ClonePixelInfo(const PixelInfo *);
254 
255 extern MagickExport MagickRealType
256   DecodePixelGamma(const MagickRealType) magick_hot_spot,
257   EncodePixelGamma(const MagickRealType) magick_hot_spot;
258 
259 extern MagickExport void
260   ConformPixelInfo(Image *,const PixelInfo *,PixelInfo *,ExceptionInfo *),
261   GetPixelInfo(const Image *,PixelInfo *),
262   InitializePixelChannelMap(Image *);
263 
264 #if defined(__cplusplus) || defined(c_plusplus)
265 }
266 #endif
267 
268 #endif
269