Debian Codegraph @

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

raw
1 /*****************************************************************************/
2 // Copyright 2008-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 * Opcodes to fix defective pixels, including individual pixels and regions (such as
11 * defective rows and columns).
12 */
13
14 /*****************************************************************************/
15
16 #ifndef __dng_bad_pixels__
17 #define __dng_bad_pixels__
18
19 /*****************************************************************************/
20
21 #include "dng_memory.h"
22 #include "dng_opcodes.h"
23
24 #include <vector>
25
26 /*****************************************************************************/
27
28 /// @brief An opcode to fix individual bad pixels that are marked with a constant
29 /// value (e.g., 0) in a Bayer image.
30
31 class dng_opcode_FixBadPixelsConstant: public dng_filter_opcode
32 {
33
34 private:
35
36 uint32 fConstant;
37
38 uint32 fBayerPhase;
39
40 public:
41
42 /// Construct an opcode to fix an individual bad pixels that are marked with
43 /// a constant value in a Bayer image.
44 /// \param constant The constant value that indicates a bad pixel.
45 /// \param bayerPhase The phase of the Bayer mosaic pattern (0, 1, 2, 3).
46
47 dng_opcode_FixBadPixelsConstant (uint32 constant,
48 uint32 bayerPhase);
49
50 dng_opcode_FixBadPixelsConstant (dng_stream &stream);
51
52 virtual void PutData (dng_stream &stream) const;
53
54 virtual dng_point SrcRepeat ();
55
56 virtual dng_rect SrcArea (const dng_rect &dstArea,
57 const dng_rect &imageBounds);
58
59 virtual void Prepare (dng_negative &negative,
60 uint32 threadCount,
61 const dng_point &tileSize,
62 const dng_rect &imageBounds,
63 uint32 imagePlanes,
64 uint32 bufferPixelType,
65 dng_memory_allocator &allocator);
66
67 virtual void ProcessArea (dng_negative &negative,
68 uint32 threadIndex,
69 dng_pixel_buffer &srcBuffer,
70 dng_pixel_buffer &dstBuffer,
71 const dng_rect &dstArea,
72 const dng_rect &imageBounds);
73
74 protected:
75
76 #if defined(__clang__) && defined(__has_attribute)
77 #if __has_attribute(no_sanitize)
78 __attribute__((no_sanitize("unsigned-integer-overflow")))
79 #endif
80 #endif
81 bool IsGreen (int32 row, int32 col) const
82 {
83 return (((uint32) row + (uint32) col + fBayerPhase + (fBayerPhase >> 1)) & 1) == 0;
84 }
85
86 };
87
88 /*****************************************************************************/
89
90 /// @brief A list of bad pixels and rectangles (usually single rows or columns).
91
92 class dng_bad_pixel_list
93 {
94
95 public:
96
97 enum
98 {
99 kNoIndex = 0xFFFFFFFF
100 };
101
102 private:
103
104 // List of bad single pixels.
105
106 dng_std_vector<dng_point> fBadPoints;
107
108 // List of bad rectangles (usually single rows or columns).
109
110 dng_std_vector<dng_rect> fBadRects;
111
112 public:
113
114 /// Create an empty bad pixel list.
115
116 dng_bad_pixel_list ();
117
118 /// Returns the number of bad single pixels.
119
120 uint32 PointCount () const
121 {
122 return (uint32) fBadPoints.size ();
123 }
124
125 /// Retrieves the bad single pixel coordinate via the specified list index.
126 ///
127 /// \param index The list index from which to retrieve the bad single pixel
128 /// coordinate.
129
130 const dng_point & Point (uint32 index) const
131 {
132 return fBadPoints [index];
133 }
134
135 /// Returns the number of bad rectangles.
136
137 uint32 RectCount () const
138 {
139 return (uint32) fBadRects.size ();
140 }
141
142 /// Retrieves the bad rectangle via the specified list index.
143 ///
144 /// \param index The list index from which to retrieve the bad rectangle
145 /// coordinates.
146
147 const dng_rect & Rect (uint32 index) const
148 {
149 return fBadRects [index];
150 }
151
152 /// Returns true iff there are zero bad single pixels and zero bad
153 /// rectangles.
154
155 bool IsEmpty () const
156 {
157 return PointCount () == 0 &&
158 RectCount () == 0;
159 }
160
161 /// Returns true iff there is at least one bad single pixel or at least one
162 /// bad rectangle.
163
164 bool NotEmpty () const
165 {
166 return !IsEmpty ();
167 }
168
169 /// Add the specified coordinate to the list of bad single pixels.
170 ///
171 /// \param pt The bad single pixel to add.
172
173 void AddPoint (const dng_point &pt);
174
175 /// Add the specified rectangle to the list of bad rectangles.
176 ///
177 /// \param r The bad rectangle to add.
178
179 void AddRect (const dng_rect &r);
180
181 /// Sort the bad single pixels and bad rectangles by coordinates (top to
182 /// bottom, then left to right).
183
184 void Sort ();
185
186 /// Returns true iff the specified bad single pixel is isolated, i.e., there
187 /// is no other bad single pixel or bad rectangle that lies within radius
188 /// pixels of this bad single pixel.
189 ///
190 /// \param index The index of the bad single pixel to test.
191 /// \param radius The pixel radius to test for isolation.
192
193 bool IsPointIsolated (uint32 index,
194 uint32 radius) const;
195
196 /// Returns true iff the specified bad rectangle is isolated, i.e., there
197 /// is no other bad single pixel or bad rectangle that lies within radius
198 /// pixels of this bad rectangle.
199 ///
200 /// \param index The index of the bad rectangle to test.
201 /// \param radius The pixel radius to test for isolation.
202
203 bool IsRectIsolated (uint32 index,
204 uint32 radius) const;
205
206 /// Returns true iff the specified point is valid, i.e., lies within the
207 /// specified image bounds, is different from all other bad single pixels,
208 /// and is not contained in any bad rectangle. The second and third
209 /// conditions are only checked if provided with a starting search index.
210 ///
211 /// \param pt The point to test for validity.
212 /// \param imageBounds The pt must lie within imageBounds to be valid.
213 /// \index The search index to use (or kNoIndex, to avoid a search) for
214 /// checking for validity.
215
216 bool IsPointValid (const dng_point &pt,
217 const dng_rect &imageBounds,
218 uint32 index = kNoIndex) const;
219
220 };
221
222 /*****************************************************************************/
223
224 /// @brief An opcode to fix lists of bad pixels (indicated by position) in a Bayer
225 /// image.
226
227 class dng_opcode_FixBadPixelsList: public dng_filter_opcode
228 {
229
230 protected:
231
232 enum
233 {
234 kBadPointPadding = 2,
235 kBadRectPadding = 4
236 };
237
238 private:
239
240 AutoPtr<dng_bad_pixel_list> fList;
241
242 uint32 fBayerPhase;
243
244 public:
245
246 /// Construct an opcode to fix lists of bad pixels (indicated by position) in
247 /// a Bayer image.
248 /// \param list The list of bad pixels to fix.
249 /// \param bayerPhase The phase of the Bayer mosaic pattern (0, 1, 2, 3).
250
251 dng_opcode_FixBadPixelsList (AutoPtr<dng_bad_pixel_list> &list,
252 uint32 bayerPhase);
253
254 dng_opcode_FixBadPixelsList (dng_stream &stream);
255
256 virtual void PutData (dng_stream &stream) const;
257
258 virtual dng_point SrcRepeat ();
259
260 virtual dng_rect SrcArea (const dng_rect &dstArea,
261 const dng_rect &imageBounds);
262
263 virtual void Prepare (dng_negative &negative,
264 uint32 threadCount,
265 const dng_point &tileSize,
266 const dng_rect &imageBounds,
267 uint32 imagePlanes,
268 uint32 bufferPixelType,
269 dng_memory_allocator &allocator);
270
271 virtual void ProcessArea (dng_negative &negative,
272 uint32 threadIndex,
273 dng_pixel_buffer &srcBuffer,
274 dng_pixel_buffer &dstBuffer,
275 const dng_rect &dstArea,
276 const dng_rect &imageBounds);
277
278 protected:
279
280 bool IsGreen (int32 row, int32 col) const
281 {
282 return ((row + col + fBayerPhase + (fBayerPhase >> 1)) & 1) == 0;
283 }
284
285 virtual void FixIsolatedPixel (dng_pixel_buffer &buffer,
286 dng_point &badPoint);
287
288 virtual void FixClusteredPixel (dng_pixel_buffer &buffer,
289 uint32 pointIndex,
290 const dng_rect &imageBounds);
291
292 virtual void FixSingleColumn (dng_pixel_buffer &buffer,
293 const dng_rect &badRect);
294
295 virtual void FixSingleRow (dng_pixel_buffer &buffer,
296 const dng_rect &badRect);
297
298 virtual void FixClusteredRect (dng_pixel_buffer &buffer,
299 const dng_rect &badRect,
300 const dng_rect &imageBounds);
301
302 };
303
304 /*****************************************************************************/
305
306 #endif
307
308 /*****************************************************************************/