• 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 /* Amplify the integer to the given multiple range */
IntZoomTo(int n,double rate,double rateMin,double rateMax)31 int IntZoomTo(int n, double rate, double rateMin, double rateMax)
32 {
33     HI_ASSERT(rateMin < 1 && rateMax > 1);
34     int ret;
35 
36     if (!rateMin) {
37         HI_ASSERT(rateMin);
38         return n;
39     } else {
40         if (rate > rateMax) {
41             ret = n * (int)rateMax;
42         } else if (rate < rateMin) {
43             ret = n / (int)(1 / rateMin);
44         } else {
45             ret = (int)(n * rate);
46         }
47         return ret < 1 ? 1 : ret;
48     }
49 }
50 
51 /* Convert coordinates proportionally */
RectBoxTran(RectBox * box,int srcWidth,int srcHeight,int dstWidth,int dstHeight)52 void RectBoxTran(RectBox* box, int srcWidth, int srcHeight, int dstWidth, int dstHeight)
53 {
54     if (!srcWidth || !srcHeight) {
55         HI_ASSERT(srcWidth && srcHeight);
56     } else {
57         if (srcWidth != 0 && srcHeight != 0) {
58             box->xmin = box->xmin * dstWidth / srcWidth * HI_OVEN_BASE / HI_OVEN_BASE;
59             box->xmax = box->xmax * dstWidth / srcWidth * HI_OVEN_BASE / HI_OVEN_BASE;
60             box->ymin = box->ymin * dstHeight / srcHeight * HI_OVEN_BASE / HI_OVEN_BASE;
61             box->ymax = box->ymax * dstHeight / srcHeight * HI_OVEN_BASE / HI_OVEN_BASE;
62         }
63     }
64 }
65 
66 #ifdef __cplusplus
67 #if __cplusplus
68 }
69 #endif
70 #endif /* End of #ifdef __cplusplus */
71