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