Debian Codegraph @

core/libs/dngwriter/extra/dng_sdk/dng_image.h

raw
1 /*****************************************************************************/
2 // Copyright 2006-2019 Adobe Systems Incorporated
3 // All Rights Reserved.
4 //
5 // NOTICE: Adobe permits you to use, modify, and distribute this file in
6 // accordance with the terms of the Adobe license agreement accompanying it.
7 /*****************************************************************************/
8
9 /** \file
10 * Support for working with image data in DNG SDK.
11 */
12
13 /*****************************************************************************/
14
15 #ifndef __dng_image__
16 #define __dng_image__
17
18 /*****************************************************************************/
19
20 #include "dng_assertions.h"
21 #include "dng_classes.h"
22 #include "dng_pixel_buffer.h"
23 #include "dng_point.h"
24 #include "dng_rect.h"
25 #include "dng_tag_types.h"
26 #include "dng_types.h"
27 #include "dng_uncopyable.h"
28
29 /*****************************************************************************/
30
31 /// @brief Class to get resource acquisition is instantiation behavior for tile
32 /// buffers. Can be dirty or constant tile access.
33
34 class dng_tile_buffer: public dng_pixel_buffer,
35 private dng_uncopyable
36 {
37
38 protected:
39
40 const dng_image &fImage;
41
42 void *fRefData;
43
44 protected:
45
46 /// Obtain a tile from an image.
47 /// \param image Image tile will come from.
48 /// \param tile Rectangle denoting extent of tile.
49 /// \param dirty Flag indicating whether this is read-only or read-write acesss.
50
51 dng_tile_buffer (const dng_image &image,
52 const dng_rect &tile,
53 bool dirty);
54
55 virtual ~dng_tile_buffer ();
56
57 public:
58
59 void SetRefData (void *refData)
60 {
61 fRefData = refData;
62 }
63
64 void * GetRefData () const
65 {
66 return fRefData;
67 }
68
69 };
70
71 /*****************************************************************************/
72
73 /// @brief Class to get resource acquisition is instantiation behavior for
74 /// constant (read-only) tile buffers.
75
76 class dng_const_tile_buffer: public dng_tile_buffer
77 {
78
79 public:
80
81 /// Obtain a read-only tile from an image.
82 /// \param image Image tile will come from.
83 /// \param tile Rectangle denoting extent of tile.
84
85 dng_const_tile_buffer (const dng_image &image,
86 const dng_rect &tile);
87
88 virtual ~dng_const_tile_buffer ();
89
90 };
91
92 /*****************************************************************************/
93
94 /// @brief Class to get resource acquisition is instantiation behavior for
95 /// dirty (writable) tile buffers.
96
97 class dng_dirty_tile_buffer: public dng_tile_buffer
98 {
99
100 public:
101
102 /// Obtain a writable tile from an image.
103 /// \param image Image tile will come from.
104 /// \param tile Rectangle denoting extent of tile.
105
106 dng_dirty_tile_buffer (dng_image &image,
107 const dng_rect &tile);
108
109 virtual ~dng_dirty_tile_buffer ();
110
111 };
112
113 /*****************************************************************************/
114
115 /// @brief Base class for holding image data in DNG SDK. See dng_simple_image
116 /// for derived class most often used in DNG SDK.
117
118 class dng_image
119 {
120
121 friend class dng_tile_buffer;
122
123 protected:
124
125 // Bounds for this image.
126
127 dng_rect fBounds;
128
129 // Number of image planes.
130
131 uint32 fPlanes;
132
133 // Basic pixel type (TIFF tag type code).
134
135 uint32 fPixelType;
136
137 public:
138
139 /// How to handle requests to get image areas outside the image bounds.
140
141 enum edge_option
142 {
143
144 /// Leave edge pixels unchanged.
145
146 edge_none,
147
148 /// Pad with zeros.
149
150 edge_zero,
151
152 /// Repeat edge pixels.
153
154 edge_repeat,
155
156 /// Repeat edge pixels, except for last plane which is zero padded.
157
158 edge_repeat_zero_last,
159
160 /// Wrap edge pixels horizontally, repeat edge pixels vertically.
161
162 edge_wrap_horizontal,
163
164 /// Wrap edge pixels vertically, repeat edge pixels horizontally.
165
166 edge_wrap_vertical,
167
168 /// Wrap edge pixels in all directions (horizontal, vertical,
169 /// diagonal).
170
171 edge_wrap_all
172
173 };
174
175 protected:
176
177 dng_image (const dng_rect &bounds,
178 uint32 planes,
179 uint32 pixelType);
180
181 public:
182
183 virtual ~dng_image ();
184
185 virtual dng_image * Clone () const;
186
187 /// Getter method for bounds of an image.
188
189 const dng_rect & Bounds () const
190 {
191 return fBounds;
192 }
193
194 /// Getter method for size of an image.
195
196 dng_point Size () const
197 {
198 return Bounds ().Size ();
199 }
200
201 /// Getter method for width of an image.
202
203 uint32 Width () const
204 {
205 return Bounds ().W ();
206 }
207
208 /// Getter method for height of an image.
209
210 uint32 Height () const
211 {
212 return Bounds ().H ();
213 }
214
215 /// Getter method for number of planes in an image.
216
217 uint32 Planes () const
218 {
219 return fPlanes;
220 }
221
222 /// Getter for pixel type.
223 /// \retval See dng_tagtypes.h . Valid values are ttByte, ttShort, ttSShort,
224 /// ttLong, ttFloat .
225
226 uint32 PixelType () const
227 {
228 return fPixelType;
229 }
230
231 /// Setter for pixel type.
232 /// \param pixelType The new pixel type .
233
234 virtual void SetPixelType (uint32 pixelType);
235
236 /// Getter for pixel size.
237 /// \retval Size, in bytes, of pixel type for this image .
238
239 uint32 PixelSize () const;
240
241 /// Getter for pixel range.
242 /// For unsigned types, range is 0 to return value.
243 /// For signed types, range is return value - 0x8000U.
244 /// For ttFloat type, pixel range is 0.0 to 1.0 and this routine returns 1.
245
246 uint32 PixelRange () const;
247
248 /// Getter for best "tile stride" for accessing image.
249
250 virtual dng_rect RepeatingTile () const;
251
252 /// Get a pixel buffer of data on image with proper edge padding.
253 /// \param buffer Receives resulting pixel buffer.
254 /// \param edgeOption edge_option describing how to pad edges.
255 /// \param repeatV Amount of repeated padding needed in vertical for
256 /// edge_repeat, edge_repeat_zero_last, and edge_wrap_horizontal
257 /// edgeOption cases.
258 /// \param repeatH Amount of repeated padding needed in horizontal for
259 /// edge_repeat, edge_repeat_zero_last, and edge_wrap_vertical
260 /// edgeOption cases.
261
262 void Get (dng_pixel_buffer &buffer,
263 edge_option edgeOption = edge_none,
264 uint32 repeatV = 1,
265 uint32 repeatH = 1) const;
266
267 /// Put a pixel buffer into image.
268 /// \param buffer Pixel buffer to copy from.
269
270 void Put (const dng_pixel_buffer &buffer);
271
272 /// Shrink bounds of image to given rectangle.
273 /// \param r Rectangle to crop to.
274
275 virtual void Trim (const dng_rect &r);
276
277 /// Rotate image to reflect given orientation change.
278 /// \param orientation Directive to rotate image in a certain way.
279
280 virtual void Rotate (const dng_orientation &orientation);
281
282 /// Offset image.
283 /// \param offset Offset amount.
284
285 virtual void Offset (const dng_point &offset);
286
287 /// Copy image data from an area of one image to same area of another.
288 /// \param src Image to copy from.
289 /// \param area Rectangle of images to copy.
290 /// \param srcPlane Plane to start copying in src.
291 /// \param dstPlane Plane to start copying in this.
292 /// \param planes Number of planes to copy.
293
294 void CopyArea (const dng_image &src,
295 const dng_rect &area,
296 uint32 srcPlane,
297 uint32 dstPlane,
298 uint32 planes)
299 {
300
301 DoCopyArea (src, area, srcPlane, dstPlane, planes);
302
303 }
304
305 /// Copy image data from an area of one image to same area of another.
306 /// \param src Image to copy from.
307 /// \param area Rectangle of images to copy.
308 /// \param plane Plane to start copying in src and this.
309 /// \param planes Number of planes to copy.
310
311 void CopyArea (const dng_image &src,
312 const dng_rect &area,
313 uint32 plane,
314 uint32 planes)
315 {
316
317 DoCopyArea (src, area, plane, plane, planes);
318
319 }
320
321 /// Return true if the contents of an area of the image are the same as those of another.
322 /// \param rhs Image to compare against.
323 /// \param area Rectangle of image to test.
324 /// \param plane Plane to start comparing.
325 /// \param planes Number of planes to compare.
326
327 virtual bool EqualArea (const dng_image &rhs,
328 const dng_rect &area,
329 uint32 plane,
330 uint32 planes) const;
331
332 // Routines to set the entire image to a constant value.
333
334 void SetConstant_uint8 (uint8 value,
335 const dng_rect &area)
336 {
337
338 DNG_ASSERT (fPixelType == ttByte, "Mismatched pixel type");
339
340 SetConstant ((uint32) value, area);
341
342 }
343
344 void SetConstant_uint8 (uint8 value)
345 {
346 SetConstant (value, Bounds ());
347 }
348
349 void SetConstant_uint16 (uint16 value,
350 const dng_rect &area)
351 {
352
353 DNG_ASSERT (fPixelType == ttShort, "Mismatched pixel type");
354
355 SetConstant ((uint32) value, area);
356
357 }
358
359 void SetConstant_uint16 (uint16 value)
360 {
361 SetConstant_uint16 (value, Bounds ());
362 }
363
364 void SetConstant_int16 (int16 value,
365 const dng_rect &area)
366 {
367
368 DNG_ASSERT (fPixelType == ttSShort, "Mismatched pixel type");
369
370 SetConstant ((uint32) (uint16) value, area);
371
372 }
373
374 void SetConstant_int16 (int16 value)
375 {
376 SetConstant_int16 (value, Bounds ());
377 }
378
379 void SetConstant_uint32 (uint32 value,
380 const dng_rect &area)
381 {
382
383 DNG_ASSERT (fPixelType == ttLong, "Mismatched pixel type");
384
385 SetConstant (value, area);
386
387 }
388
389 void SetConstant_uint32 (uint32 value)
390 {
391 SetConstant_uint32 (value, Bounds ());
392 }
393
394 void SetConstant_real32 (real32 value,
395 const dng_rect &area)
396 {
397
398 DNG_ASSERT (fPixelType == ttFloat, "Mismatched pixel type");
399
400 union
401 {
402 uint32 i;
403 real32 f;
404 } x;
405
406 x.f = value;
407
408 SetConstant (x.i, area);
409
410 }
411
412 void SetConstant_real32 (real32 value)
413 {
414 SetConstant_real32 (value, Bounds ());
415 }
416
417 void SetZero (const dng_rect &area)
418 {
419 SetConstant (0, area);
420 }
421
422 virtual void GetRepeat (dng_pixel_buffer &buffer,
423 const dng_rect &srcArea,
424 const dng_rect &dstArea) const;
425
426 protected:
427
428 virtual void AcquireTileBuffer (dng_tile_buffer &buffer,
429 const dng_rect &area,
430 bool dirty) const;
431
432 virtual void ReleaseTileBuffer (dng_tile_buffer &buffer) const;
433
434 virtual void DoGet (dng_pixel_buffer &buffer) const;
435
436 virtual void DoPut (const dng_pixel_buffer &buffer);
437
438 virtual void DoCopyArea (const dng_image &src,
439 const dng_rect &area,
440 uint32 srcPlane,
441 uint32 dstPlane,
442 uint32 planes);
443
444 void GetEdge (dng_pixel_buffer &buffer,
445 edge_option edgeOption,
446 const dng_rect &srcArea,
447 const dng_rect &dstArea) const;
448
449 virtual void SetConstant (uint32 value,
450 const dng_rect &area);
451
452 };
453
454 /*****************************************************************************/
455
456 #endif
457
458 /*****************************************************************************/