• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <stdlib.h>
17 #include <string.h>
18 #include <stdio.h>
19 #include <stdbool.h>
20 
21 #include "sample_media_ai.h"
22 #include "ai_infer_process.h"
23 
24 #ifdef __cplusplus
25 #if __cplusplus
26 extern "C" {
27 #endif
28 #endif /* End of #ifdef __cplusplus */
29 
30 /*
31  * 将整数放大到给定的倍数范围
32  * Amplify the integer to the given multiple range
33  */
IntZoomTo(int n,double rate,double rateMin,double rateMax)34 int IntZoomTo(int n, double rate, double rateMin, double rateMax)
35 {
36     HI_ASSERT(rateMin < 1 && rateMax > 1);
37     int ret;
38 
39     if (!rateMin) {
40         HI_ASSERT(rateMin);
41         return n;
42     } else {
43         if (rate > rateMax) {
44             ret = n * (int)rateMax;
45         } else if (rate < rateMin) {
46             ret = n / (int)(1 / rateMin);
47         } else {
48             ret = (int)(n * rate);
49         }
50         return ret < 1 ? 1 : ret;
51     }
52 }
53 
54 /*
55  * 按比例转换坐标
56  * Convert coordinates proportionally
57  */
RectBoxTran(RectBox * box,int srcWidth,int srcHeight,int dstWidth,int dstHeight)58 void RectBoxTran(RectBox* box, int srcWidth, int srcHeight, int dstWidth, int dstHeight)
59 {
60     if (!srcWidth || !srcHeight) {
61         HI_ASSERT(srcWidth && srcHeight);
62     } else {
63         if (srcWidth != 0 && srcHeight != 0) {
64             box->xmin = box->xmin * dstWidth / srcWidth * HI_OVEN_BASE / HI_OVEN_BASE;
65             box->xmax = box->xmax * dstWidth / srcWidth * HI_OVEN_BASE / HI_OVEN_BASE;
66             box->ymin = box->ymin * dstHeight / srcHeight * HI_OVEN_BASE / HI_OVEN_BASE;
67             box->ymax = box->ymax * dstHeight / srcHeight * HI_OVEN_BASE / HI_OVEN_BASE;
68         }
69     }
70 }
71 
72 #ifdef __cplusplus
73 #if __cplusplus
74 }
75 #endif
76 #endif /* End of #ifdef __cplusplus */
77