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