• 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_tile_iterator.cpp#1 $ */
10 /* $DateTime: 2012/05/30 13:28:51 $ */
11 /* $Change: 832332 $ */
12 /* $Author: tknoll $ */
13 
14 /*****************************************************************************/
15 
16 #include "dng_tile_iterator.h"
17 
18 #include "dng_exceptions.h"
19 #include "dng_image.h"
20 #include "dng_pixel_buffer.h"
21 #include "dng_tag_types.h"
22 #include "dng_utils.h"
23 
24 /*****************************************************************************/
25 
dng_tile_iterator(const dng_image & image,const dng_rect & area)26 dng_tile_iterator::dng_tile_iterator (const dng_image &image,
27 									  const dng_rect &area)
28 
29 	:	fArea           ()
30 	,	fTileWidth      (0)
31 	,	fTileHeight     (0)
32 	,	fTileTop        (0)
33 	,	fTileLeft       (0)
34 	,	fRowLeft        (0)
35 	,	fLeftPage       (0)
36 	,	fRightPage      (0)
37 	,	fTopPage        (0)
38 	,	fBottomPage     (0)
39 	,	fHorizontalPage (0)
40 	,	fVerticalPage   (0)
41 
42 	{
43 
44 	Initialize (image.RepeatingTile (),
45 				area & image.Bounds ());
46 
47 	}
48 
49 /*****************************************************************************/
50 
dng_tile_iterator(const dng_point & tileSize,const dng_rect & area)51 dng_tile_iterator::dng_tile_iterator (const dng_point &tileSize,
52 						   			  const dng_rect &area)
53 
54 	:	fArea           ()
55 	,	fTileWidth      (0)
56 	,	fTileHeight     (0)
57 	,	fTileTop        (0)
58 	,	fTileLeft       (0)
59 	,	fRowLeft        (0)
60 	,	fLeftPage       (0)
61 	,	fRightPage      (0)
62 	,	fTopPage        (0)
63 	,	fBottomPage     (0)
64 	,	fHorizontalPage (0)
65 	,	fVerticalPage   (0)
66 
67 	{
68 
69 	dng_rect tile (area);
70 
71 	tile.b = Min_int32 (tile.b, tile.t + tileSize.v);
72 	tile.r = Min_int32 (tile.r, tile.l + tileSize.h);
73 
74 	Initialize (tile,
75 				area);
76 
77 	}
78 
79 /*****************************************************************************/
80 
dng_tile_iterator(const dng_rect & tile,const dng_rect & area)81 dng_tile_iterator::dng_tile_iterator (const dng_rect &tile,
82 						   			  const dng_rect &area)
83 
84 	:	fArea           ()
85 	,	fTileWidth      (0)
86 	,	fTileHeight     (0)
87 	,	fTileTop        (0)
88 	,	fTileLeft       (0)
89 	,	fRowLeft        (0)
90 	,	fLeftPage       (0)
91 	,	fRightPage      (0)
92 	,	fTopPage        (0)
93 	,	fBottomPage     (0)
94 	,	fHorizontalPage (0)
95 	,	fVerticalPage   (0)
96 
97 	{
98 
99 	Initialize (tile,
100 				area);
101 
102 	}
103 
104 /*****************************************************************************/
105 
Initialize(const dng_rect & tile,const dng_rect & area)106 void dng_tile_iterator::Initialize (const dng_rect &tile,
107 						 			const dng_rect &area)
108 	{
109 
110 	fArea = area;
111 
112 	if (area.IsEmpty ())
113 		{
114 
115 		fVerticalPage =  0;
116 		fBottomPage   = -1;
117 
118 		return;
119 
120 		}
121 
122 	int32 vOffset = tile.t;
123 	int32 hOffset = tile.l;
124 
125 	int32 tileHeight = tile.b - vOffset;
126 	int32 tileWidth  = tile.r - hOffset;
127 
128 	fTileHeight = tileHeight;
129 	fTileWidth  = tileWidth;
130 
131 	fLeftPage  = (fArea.l - hOffset    ) / tileWidth;
132 	fRightPage = (fArea.r - hOffset - 1) / tileWidth;
133 
134 	fHorizontalPage = fLeftPage;
135 
136 	fTopPage    = (fArea.t - vOffset    ) / tileHeight;
137 	fBottomPage = (fArea.b - vOffset - 1) / tileHeight;
138 
139 	fVerticalPage = fTopPage;
140 
141 	fTileLeft = fHorizontalPage * tileWidth  + hOffset;
142 	fTileTop  = fVerticalPage   * tileHeight + vOffset;
143 
144 	fRowLeft = fTileLeft;
145 
146 	}
147 
148 /*****************************************************************************/
149 
GetOneTile(dng_rect & tile)150 bool dng_tile_iterator::GetOneTile (dng_rect &tile)
151 	{
152 
153 	if (fVerticalPage > fBottomPage)
154 		{
155 		return false;
156 		}
157 
158 	if (fVerticalPage > fTopPage)
159 		tile.t = fTileTop;
160 	else
161 		tile.t = fArea.t;
162 
163 	if (fVerticalPage < fBottomPage)
164 		tile.b = fTileTop + fTileHeight;
165 	else
166 		tile.b = fArea.b;
167 
168 	if (fHorizontalPage > fLeftPage)
169 		tile.l = fTileLeft;
170 	else
171 		tile.l = fArea.l;
172 
173 	if (fHorizontalPage < fRightPage)
174 		tile.r = fTileLeft + fTileWidth;
175 	else
176 		tile.r = fArea.r;
177 
178 	if (fHorizontalPage < fRightPage)
179 		{
180 		fHorizontalPage++;
181 		fTileLeft += fTileWidth;
182 		}
183 
184 	else
185 		{
186 
187 		fVerticalPage++;
188 		fTileTop += fTileHeight;
189 
190 		fHorizontalPage = fLeftPage;
191 		fTileLeft = fRowLeft;
192 
193 		}
194 
195 	return true;
196 
197 	}
198 
199 /*****************************************************************************/
200