• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*****************************************************************************/
2 // Copyright 2006 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 /* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_filter_task.h#2 $ */
10 /* $DateTime: 2012/07/11 10:36:56 $ */
11 /* $Change: 838485 $ */
12 /* $Author: tknoll $ */
13 
14 /** \file
15  * Specialization of dng_area_task for processing an area from one dng_image to an
16  * area of another.
17  */
18 
19 /*****************************************************************************/
20 
21 #ifndef __dng_filter_task__
22 #define __dng_filter_task__
23 
24 /*****************************************************************************/
25 
26 #include "dng_area_task.h"
27 #include "dng_auto_ptr.h"
28 #include "dng_point.h"
29 #include "dng_rect.h"
30 #include "dng_sdk_limits.h"
31 
32 /*****************************************************************************/
33 
34 /// \brief Represents a task which filters an area of a source dng_image to an area
35 /// of a destination dng_image.
36 
37 class dng_filter_task: public dng_area_task
38 	{
39 
40 	protected:
41 
42 		const dng_image &fSrcImage;
43 
44 		dng_image &fDstImage;
45 
46 		uint32 fSrcPlane;
47 		uint32 fSrcPlanes;
48 		uint32 fSrcPixelType;
49 
50 		uint32 fDstPlane;
51 		uint32 fDstPlanes;
52 		uint32 fDstPixelType;
53 
54 		dng_point fSrcRepeat;
55 		dng_point fSrcTileSize;
56 
57 		AutoPtr<dng_memory_block> fSrcBuffer [kMaxMPThreads];
58 		AutoPtr<dng_memory_block> fDstBuffer [kMaxMPThreads];
59 
60 	public:
61 
62 		/// Construct a filter task given a source and destination images.
63 		/// \param srcImage Image from which source pixels are read.
64 		/// \param dstImage Image to which result pixels are written.
65 
66 		dng_filter_task (const dng_image &srcImage,
67 						 dng_image &dstImage);
68 
69 		virtual ~dng_filter_task ();
70 
71 		/// Compute the source area needed for a given destination area. Default
72 		/// implementation assumes destination area is equal to source area for all
73 		/// cases.
74 		///
75 		/// \param dstArea Area to for which pixels will be computed.
76 		///
77 		/// \retval The source area needed as input to calculate the requested
78 		/// destination area.
79 
SrcArea(const dng_rect & dstArea)80 		virtual dng_rect SrcArea (const dng_rect &dstArea)
81 			{
82 			return dstArea;
83 			}
84 
85 		/// Given a destination tile size, calculate input tile size. Simlar to
86 		/// SrcArea, and should seldom be overridden.
87 		///
88 		/// \param dstTileSize The destination tile size that is targeted for output.
89 		///
90 		/// \retval The source tile size needed to compute a tile of the destination
91 		/// size.
92 
SrcTileSize(const dng_point & dstTileSize)93 		virtual dng_point SrcTileSize (const dng_point &dstTileSize)
94 			{
95 			return SrcArea (dng_rect (dstTileSize)).Size ();
96 			}
97 
98 		/// Implements filtering operation from one buffer to another. Source and
99 		/// destination pixels are set up in member fields of this class. Ideally, no
100 		/// allocation should be done in this routine.
101 		///
102 		/// \param threadIndex The thread on which this routine is being called,
103 		/// between 0 and threadCount - 1 for the threadCount passed to Start method.
104 		///
105 		/// \param srcBuffer Input area and source pixels.
106 		///
107 		/// \param dstBuffer Output area and destination pixels.
108 
109 		virtual void ProcessArea (uint32 threadIndex,
110 								  dng_pixel_buffer &srcBuffer,
111 								  dng_pixel_buffer &dstBuffer) = 0;
112 
113 		/// Called prior to processing on specific threads. Can be used to allocate
114 		/// per-thread memory buffers, etc.
115 		///
116 		/// \param threadCount Total number of threads that will be used for
117 		/// processing. Less than or equal to MaxThreads of dng_area_task.
118 		///
119 		/// \param tileSize Size of source tiles which will be processed. (Not all
120 		/// tiles will be this size due to edge conditions.)
121 		///
122 		/// \param allocator dng_memory_allocator to use for allocating temporary
123 		/// buffers, etc.
124 		///
125 		/// \param sniffer Sniffer to test for user cancellation and to set up
126 		/// progress.
127 
128 		virtual void Start (uint32 threadCount,
129 							const dng_point &tileSize,
130 							dng_memory_allocator *allocator,
131 							dng_abort_sniffer *sniffer);
132 
133 		/// Process one tile or partitioned area. Should not be overridden. Instead,
134 		/// override ProcessArea, which is where to implement filter processing for a
135 		/// specific type of dng_filter_task. There is no allocator parameter as all
136 		/// allocation should be done in Start.
137 		///
138 		/// \param threadIndex 0 to threadCount - 1 index indicating which thread
139 		/// this is. (Can be used to get a thread-specific buffer allocated in the
140 		/// Start method.)
141 		///
142 		/// \param area Size of tiles to be used for sizing buffers, etc. (Edges of
143 		/// processing can be smaller.)
144 		///
145 		/// \param sniffer dng_abort_sniffer to use to check for user cancellation
146 		/// and progress updates.
147 
148 		virtual void Process (uint32 threadIndex,
149 							  const dng_rect &area,
150 							  dng_abort_sniffer *sniffer);
151 
152 	};
153 
154 /*****************************************************************************/
155 
156 #endif
157 
158 /*****************************************************************************/
159