@@ -125,8 +125,8 @@ stm32ipl_err_t STM32Ipl_Resize(const image_t *src, image_t *dst, const rectangle
125125 int32_t srcH ;
126126 int32_t dstW ;
127127 int32_t dstH ;
128- float wRatio ;
129- float hRatio ;
128+ int32_t wRatio ;
129+ int32_t hRatio ;
130130
131131 STM32IPL_CHECK_VALID_IMAGE (src )
132132 STM32IPL_CHECK_VALID_IMAGE (dst )
@@ -153,50 +153,50 @@ stm32ipl_err_t STM32Ipl_Resize(const image_t *src, image_t *dst, const rectangle
153153 STM32Ipl_RectCopy ((rectangle_t * )roi , & srcRoi );
154154 }
155155
156- wRatio = (float ) srcRoi . w / dstW ;
157- hRatio = (float ) srcRoi . h / dstH ;
156+ wRatio = (int32_t ) (( roi -> w << 16 ) / dst -> w ) + 1 ;
157+ hRatio = (int32_t ) (( roi -> h << 16 ) / dst -> h ) + 1 ;
158158
159159 switch (src -> bpp ) {
160160 case IMAGE_BPP_BINARY :
161161 for (uint32_t y = 0 ; y < dstH ; y ++ ) {
162- uint32_t * srcRow = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR (src , fast_floorf ( y * hRatio ) + srcRoi .y );
162+ uint32_t * srcRow = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR (src , (( y * hRatio ) >> 16 ) + srcRoi .y );
163163 uint32_t * dstRow = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR (dst , y );
164164
165165 for (uint32_t x = 0 ; x < dstW ; x ++ )
166166 IMAGE_PUT_BINARY_PIXEL_FAST (dstRow , x ,
167- IMAGE_GET_BINARY_PIXEL_FAST (srcRow , fast_floorf ( x * wRatio ) + srcRoi .x ));
167+ IMAGE_GET_BINARY_PIXEL_FAST (srcRow , (( x * wRatio ) >> 16 ) + srcRoi .x ));
168168 }
169169 break ;
170170
171171 case IMAGE_BPP_GRAYSCALE :
172172 for (uint32_t y = 0 ; y < dstH ; y ++ ) {
173- uint8_t * srcRow = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR (src , fast_floorf ( y * hRatio ) + srcRoi .y );
173+ uint8_t * srcRow = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR (src , (( y * hRatio ) >> 16 ) + srcRoi .y );
174174 uint8_t * dstRow = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR (dst , y );
175175
176176 for (uint32_t x = 0 ; x < dstW ; x ++ )
177177 IMAGE_PUT_GRAYSCALE_PIXEL_FAST (dstRow , x ,
178- IMAGE_GET_GRAYSCALE_PIXEL_FAST (srcRow , fast_floorf ( x * wRatio ) + srcRoi .x ));
178+ IMAGE_GET_GRAYSCALE_PIXEL_FAST (srcRow , (( x * wRatio ) >> 16 ) + srcRoi .x ));
179179 }
180180 break ;
181181
182182 case IMAGE_BPP_RGB565 :
183183 for (uint32_t y = 0 ; y < dstH ; y ++ ) {
184- uint16_t * srcRow = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR (src , fast_floorf ( y * hRatio ) + srcRoi .y );
184+ uint16_t * srcRow = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR (src , (( y * hRatio ) >> 16 ) + srcRoi .y );
185185 uint16_t * dstRow = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR (dst , y );
186186
187187 for (uint32_t x = 0 ; x < dstW ; x ++ )
188188 IMAGE_PUT_RGB565_PIXEL_FAST (dstRow , x ,
189- IMAGE_GET_RGB565_PIXEL_FAST (srcRow , fast_floorf ( x * wRatio ) + srcRoi .x ));
189+ IMAGE_GET_RGB565_PIXEL_FAST (srcRow , (( x * wRatio ) >> 16 ) + srcRoi .x ));
190190 }
191191 break ;
192192
193193 case IMAGE_BPP_RGB888 :
194194 for (uint32_t y = 0 ; y < dstH ; y ++ ) {
195- rgb888_t * srcRow = IMAGE_COMPUTE_RGB888_PIXEL_ROW_PTR (src , fast_floorf ( y * hRatio ) + srcRoi .y );
195+ rgb888_t * srcRow = IMAGE_COMPUTE_RGB888_PIXEL_ROW_PTR (src , (( y * hRatio ) >> 16 ) + srcRoi .y );
196196 rgb888_t * dstRow = IMAGE_COMPUTE_RGB888_PIXEL_ROW_PTR (dst , y );
197197 for (uint32_t x = 0 ; x < dstW ; x ++ )
198198 IMAGE_PUT_RGB888_PIXEL_FAST (dstRow , x ,
199- IMAGE_GET_RGB888_PIXEL_FAST (srcRow , fast_floorf ( x * wRatio ) + srcRoi .x ));
199+ IMAGE_GET_RGB888_PIXEL_FAST (srcRow , (( x * wRatio ) >> 16 ) + srcRoi .x ));
200200 }
201201 break ;
202202
@@ -223,8 +223,8 @@ stm32ipl_err_t STM32Ipl_Downscale(const image_t *src, image_t *dst, bool reverse
223223{
224224 int32_t dstW ;
225225 int32_t dstH ;
226- float wRatio ;
227- float hRatio ;
226+ int32_t wRatio ;
227+ int32_t hRatio ;
228228
229229 STM32IPL_CHECK_VALID_IMAGE (src )
230230 STM32IPL_CHECK_VALID_IMAGE (dst )
@@ -237,53 +237,53 @@ stm32ipl_err_t STM32Ipl_Downscale(const image_t *src, image_t *dst, bool reverse
237237 dstW = dst -> w ;
238238 dstH = dst -> h ;
239239
240- wRatio = (float ) src -> w / dstW ;
241- hRatio = (float ) src -> h / dstH ;
240+ wRatio = (int32_t ) (( src -> w << 16 ) / dst -> w ) + 1 ;
241+ hRatio = (int32_t ) (( src -> h << 16 ) / dst -> h ) + 1 ;
242242
243243 if (reversed ) {
244244 switch (src -> bpp ) {
245245 case IMAGE_BPP_BINARY :
246246 for (int32_t y = dstH - 1 ; y >= 0 ; y -- ) {
247- uint32_t * srcRow = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR (src , fast_floorf (y * hRatio ));
247+ uint32_t * srcRow = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR (src , (y * hRatio ) >> 16 );
248248 uint32_t * dstRow = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR (dst , y );
249249
250250 for (int32_t x = dstW - 1 ; x >= 0 ; x -- )
251251 IMAGE_PUT_BINARY_PIXEL_FAST (dstRow , x ,
252- IMAGE_GET_BINARY_PIXEL_FAST (srcRow , fast_floorf (x * wRatio )));
252+ IMAGE_GET_BINARY_PIXEL_FAST (srcRow , (x * wRatio ) >> 16 ));
253253 }
254254 break ;
255255
256256 case IMAGE_BPP_GRAYSCALE :
257257 for (int32_t y = dstH - 1 ; y >= 0 ; y -- ) {
258- uint8_t * srcRow = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR (src , fast_floorf (y * hRatio ));
258+ uint8_t * srcRow = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR (src , (y * hRatio ) >> 16 );
259259 uint8_t * dstRow = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR (dst , y );
260260
261261 for (int32_t x = dstW - 1 ; x >= 0 ; x -- )
262262 IMAGE_PUT_GRAYSCALE_PIXEL_FAST (dstRow , x ,
263- IMAGE_GET_GRAYSCALE_PIXEL_FAST (srcRow , fast_floorf (x * wRatio )));
263+ IMAGE_GET_GRAYSCALE_PIXEL_FAST (srcRow , (x * wRatio )) >> 16 );
264264 }
265265 break ;
266266
267267 case IMAGE_BPP_RGB565 :
268268 for (int32_t y = dstH - 1 ; y >= 0 ; y -- ) {
269- uint16_t * srcRow = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR (src , fast_floorf (y * hRatio ));
269+ uint16_t * srcRow = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR (src , (y * hRatio ) >> 16 );
270270 uint16_t * dstRow = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR (dst , y );
271271
272272 for (int x = dstW - 1 ; x >= 0 ; x -- )
273273 IMAGE_PUT_RGB565_PIXEL_FAST (dstRow , x ,
274- IMAGE_GET_RGB565_PIXEL_FAST (srcRow , fast_floorf (x * wRatio )));
274+ IMAGE_GET_RGB565_PIXEL_FAST (srcRow , (x * wRatio ) >> 16 ));
275275 }
276276
277277 break ;
278278
279279 case IMAGE_BPP_RGB888 :
280280 for (int32_t y = dstH - 1 ; y >= 0 ; y -- ) {
281- rgb888_t * srcRow = IMAGE_COMPUTE_RGB888_PIXEL_ROW_PTR (src , fast_floorf (y * hRatio ));
281+ rgb888_t * srcRow = IMAGE_COMPUTE_RGB888_PIXEL_ROW_PTR (src , (y * hRatio ) >> 16 );
282282 rgb888_t * dstRow = IMAGE_COMPUTE_RGB888_PIXEL_ROW_PTR (dst , y );
283283
284284 for (int x = dstW - 1 ; x >= 0 ; x -- )
285285 IMAGE_PUT_RGB888_PIXEL_FAST (dstRow , x ,
286- IMAGE_GET_RGB888_PIXEL_FAST (srcRow , fast_floorf (x * wRatio )));
286+ IMAGE_GET_RGB888_PIXEL_FAST (srcRow , (x * wRatio ) >> 16 ));
287287 }
288288 break ;
289289
@@ -294,46 +294,46 @@ stm32ipl_err_t STM32Ipl_Downscale(const image_t *src, image_t *dst, bool reverse
294294 switch (src -> bpp ) {
295295 case IMAGE_BPP_BINARY :
296296 for (int32_t y = 0 ; y < dstH ; y ++ ) {
297- uint32_t * srcRow = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR (src , fast_floorf (y * hRatio ));
297+ uint32_t * srcRow = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR (src , (y * hRatio ) >> 16 );
298298 uint32_t * dstRow = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR (dst , y );
299299
300300 for (int32_t x = 0 ; x < dstW ; x ++ )
301301 IMAGE_PUT_BINARY_PIXEL_FAST (dstRow , x ,
302- IMAGE_GET_BINARY_PIXEL_FAST (srcRow , fast_floorf (x * wRatio )));
302+ IMAGE_GET_BINARY_PIXEL_FAST (srcRow , (x * wRatio ) >> 16 ));
303303 }
304304 break ;
305305
306306 case IMAGE_BPP_GRAYSCALE :
307307 for (int32_t y = 0 ; y < dstH ; y ++ ) {
308- uint8_t * srcRow = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR (src , fast_floorf (y * hRatio ));
308+ uint8_t * srcRow = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR (src , (y * hRatio ) >> 16 );
309309 uint8_t * dstRow = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR (dst , y );
310310
311311 for (int32_t x = 0 ; x < dstW ; x ++ )
312312 IMAGE_PUT_GRAYSCALE_PIXEL_FAST (dstRow , x ,
313- IMAGE_GET_GRAYSCALE_PIXEL_FAST (srcRow , fast_floorf (x * wRatio )));
313+ IMAGE_GET_GRAYSCALE_PIXEL_FAST (srcRow , (x * wRatio ) >> 16 ));
314314 }
315315 break ;
316316
317317 case IMAGE_BPP_RGB565 :
318318 for (int32_t y = 0 ; y < dstH ; y ++ ) {
319- uint16_t * srcRow = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR (src , fast_floorf (y * hRatio ));
319+ uint16_t * srcRow = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR (src , (y * hRatio ) >> 16 );
320320 uint16_t * dstRow = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR (dst , y );
321321
322322 for (int32_t x = 0 ; x < dstW ; x ++ )
323323 IMAGE_PUT_RGB565_PIXEL_FAST (dstRow , x ,
324- IMAGE_GET_RGB565_PIXEL_FAST (srcRow , fast_floorf (x * wRatio )));
324+ IMAGE_GET_RGB565_PIXEL_FAST (srcRow , (x * wRatio ) >> 16 ));
325325 }
326326
327327 break ;
328328
329329 case IMAGE_BPP_RGB888 :
330330 for (int32_t y = 0 ; y < dstH ; y ++ ) {
331- rgb888_t * srcRow = IMAGE_COMPUTE_RGB888_PIXEL_ROW_PTR (src , fast_floorf (y * hRatio ));
331+ rgb888_t * srcRow = IMAGE_COMPUTE_RGB888_PIXEL_ROW_PTR (src , (y * hRatio ) >> 16 );
332332 rgb888_t * dstRow = IMAGE_COMPUTE_RGB888_PIXEL_ROW_PTR (dst , y );
333333
334334 for (int32_t x = 0 ; x < dstW ; x ++ )
335335 IMAGE_PUT_RGB888_PIXEL_FAST (dstRow , x ,
336- IMAGE_GET_RGB888_PIXEL_FAST (srcRow , fast_floorf (x * wRatio )));
336+ IMAGE_GET_RGB888_PIXEL_FAST (srcRow , (x * wRatio ) >> 16 ));
337337 }
338338 break ;
339339
0 commit comments