ronnie
2022-10-14 1504bb53e29d3d46222c0b3ea994fc494b48e153
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*****************************************************************************/
// Copyright 2006 Adobe Systems Incorporated
// All Rights Reserved.
//
// NOTICE:  Adobe permits you to use, modify, and distribute this file in
// accordance with the terms of the Adobe license agreement accompanying it.
/*****************************************************************************/
 
/* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_filter_task.cpp#1 $ */ 
/* $DateTime: 2012/05/30 13:28:51 $ */
/* $Change: 832332 $ */
/* $Author: tknoll $ */
 
/*****************************************************************************/
 
#include "dng_filter_task.h"
 
#include "dng_bottlenecks.h"
#include "dng_exceptions.h"
#include "dng_image.h"
#include "dng_memory.h"
#include "dng_tag_types.h"
#include "dng_tag_values.h"
#include "dng_utils.h"
 
/*****************************************************************************/
 
dng_filter_task::dng_filter_task (const dng_image &srcImage,
                                  dng_image &dstImage)
   
   :    fSrcImage     (srcImage)
   ,    fDstImage     (dstImage)
   
   ,    fSrcPlane     (0                    )
   ,    fSrcPlanes    (srcImage.Planes    ())
   ,    fSrcPixelType (srcImage.PixelType ())
   
   ,    fDstPlane     (0                    )
   ,    fDstPlanes    (dstImage.Planes    ())
   ,    fDstPixelType (dstImage.PixelType ())
   
   ,    fSrcRepeat    (1, 1)
   ,    fSrcTileSize  (0, 0)
   
   {
 
   }
                             
/*****************************************************************************/
 
dng_filter_task::~dng_filter_task ()
   {
   
   }
       
/*****************************************************************************/
 
void dng_filter_task::Start (uint32 threadCount,
                            const dng_point &tileSize,
                            dng_memory_allocator *allocator,
                            dng_abort_sniffer * /* sniffer */)
   {
   
   fSrcTileSize = SrcTileSize (tileSize);
       
       uint32 srcBufferSize = ComputeBufferSize(fSrcPixelType, fSrcTileSize,
                                                fSrcPlanes, pad16Bytes);
       uint32 dstBufferSize = ComputeBufferSize(fDstPixelType, tileSize,
                                                fDstPlanes, pad16Bytes);
       
       for (uint32 threadIndex = 0; threadIndex < threadCount; threadIndex++)
       {
       
       fSrcBuffer [threadIndex] . Reset (allocator->Allocate (srcBufferSize));
       
       fDstBuffer [threadIndex] . Reset (allocator->Allocate (dstBufferSize));
       
       // Zero buffers so any pad bytes have defined values.
       
       DoZeroBytes (fSrcBuffer [threadIndex]->Buffer      (),
                    fSrcBuffer [threadIndex]->LogicalSize ());
       
       DoZeroBytes (fDstBuffer [threadIndex]->Buffer      (),
                    fDstBuffer [threadIndex]->LogicalSize ());
       
       }
       
   }
 
/*****************************************************************************/
 
void dng_filter_task::Process (uint32 threadIndex,
                              const dng_rect &area,
                              dng_abort_sniffer * /* sniffer */)
   {
   
   // Find source area for this destination area.
   
   dng_rect srcArea = SrcArea (area);
   
   int32 src_area_w;
   int32 src_area_h;
   if (!ConvertUint32ToInt32 (srcArea.W (), &src_area_w) || !ConvertUint32ToInt32 (srcArea.H (), &src_area_h) || src_area_w > fSrcTileSize.h || src_area_h > fSrcTileSize.v)
       {
       
       ThrowMemoryFull("Area exceeds tile size.");
       
       }
                     
   // Setup srcBuffer.
   
   dng_pixel_buffer srcBuffer(srcArea, fSrcPlane, fSrcPlanes, fSrcPixelType,
                              pcRowInterleavedAlign16,
                              fSrcBuffer [threadIndex]->Buffer ());
   
   // Setup dstBuffer.
   
   dng_pixel_buffer dstBuffer(area, fDstPlane, fDstPlanes, fDstPixelType,
                              pcRowInterleavedAlign16,
                              fDstBuffer [threadIndex]->Buffer ());
   
   // Get source pixels.
   
   fSrcImage.Get (srcBuffer,
                  dng_image::edge_repeat,
                  fSrcRepeat.v,
                  fSrcRepeat.h);
                  
   // Process area.
   
   ProcessArea (threadIndex,
                srcBuffer,
                dstBuffer);
 
   // Save result pixels.
   
   fDstImage.Put (dstBuffer);
   
   }
 
/*****************************************************************************/