@@ -117,8 +117,21 @@ def get_tile(self, level, address):
117
117
address: the address of the tile within the level as a (col, row)
118
118
tuple."""
119
119
120
- t_location = address
120
+ # Read tile
121
+ args , z_size = self ._get_tile_info (level , address )
122
+ tile = self ._osr .read_region (* args )
121
123
124
+ # Apply on solid background
125
+ bg = Image .new ('RGB' , tile .size , self ._bg_color )
126
+ tile = Image .composite (tile , bg , tile )
127
+
128
+ # Scale to the correct size
129
+ if tile .size != z_size :
130
+ tile .thumbnail (z_size , Image .ANTIALIAS )
131
+
132
+ return tile
133
+
134
+ def _get_tile_info (self , level , t_location ):
122
135
# Check parameters
123
136
if level < 0 or level >= self ._levels :
124
137
raise ValueError ("Invalid level" )
@@ -135,14 +148,14 @@ def get_tile(self, level, address):
135
148
z_overlap_br = tuple (self ._z_overlap * int (t != t_lim - 1 )
136
149
for t , t_lim in zip (t_location , self .level_tiles [level ]))
137
150
138
- # Get final size of this tile
151
+ # Get final size of the tile
139
152
z_size = tuple (min (self ._z_t_downsample ,
140
153
z_lim - self ._z_t_downsample * t ) + z_tl + z_br
141
154
for t , z_lim , z_tl , z_br in
142
155
zip (t_location , self ._z_dimensions [level ], z_overlap_tl ,
143
156
z_overlap_br ))
144
157
145
- # Obtain the region
158
+ # Obtain the region coordinates
146
159
z_location = [self ._z_from_t (t ) for t in t_location ]
147
160
l_location = [self ._l_from_z (level , z ) - z_tl
148
161
for z , z_tl in zip (z_location , z_overlap_tl )]
@@ -152,17 +165,9 @@ def get_tile(self, level, address):
152
165
l_lim - math .ceil (l )))
153
166
for l , dz , l_lim in
154
167
zip (l_location , z_size , self ._l_dimensions [layer ])]
155
- tile = self ._osr .read_region (l0_location , layer , l_size )
156
168
157
- # Apply on solid background
158
- bg = Image .new ('RGB' , tile .size , self ._bg_color )
159
- tile = Image .composite (tile , bg , tile )
160
-
161
- # Scale to the correct size
162
- if tile .size != z_size :
163
- tile .thumbnail (z_size , Image .ANTIALIAS )
164
-
165
- return tile
169
+ # Return read_region() parameters plus tile size for final scaling
170
+ return ((l0_location , layer , l_size ), z_size )
166
171
167
172
def _l0_from_l (self , layer , l ):
168
173
return self ._l0_l_downsamples [layer ] * l
0 commit comments