/src/libhevc/encoder/convert_float_to_fix.c
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Copyright (C) 2018 The Android Open Source Project |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at: |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | * |
17 | | ***************************************************************************** |
18 | | * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore |
19 | | */ |
20 | | /*! |
21 | | ****************************************************************************** |
22 | | * \file convert_float_to_fix.c |
23 | | * |
24 | | * \brief |
25 | | * This file contain float to fix and fix to float conversion function |
26 | | * |
27 | | * \date |
28 | | * |
29 | | * \author |
30 | | * ittiam |
31 | | * |
32 | | ****************************************************************************** |
33 | | */ |
34 | | /*****************************************************************************/ |
35 | | /* File Includes */ |
36 | | /*****************************************************************************/ |
37 | | /* System include files */ |
38 | | #include <stdio.h> |
39 | | #include <stdlib.h> |
40 | | #include <math.h> |
41 | | #include <time.h> |
42 | | #include <string.h> |
43 | | |
44 | | /* User include files */ |
45 | | #include "ia_type_def.h" |
46 | | /* #include "num_struct.h" */ |
47 | | #include "var_q_operator.h" |
48 | | |
49 | 0 | #define ABS(x) (((x) > 0) ? (x) : (-(x))) |
50 | | |
51 | | void convert_float_to_fix(float a_f, number_t *a) |
52 | 0 | { |
53 | 0 | double log_a_f; |
54 | 0 | if(a_f != 0) |
55 | 0 | { |
56 | 0 | log_a_f = log(ABS(a_f)) / log(2); |
57 | |
|
58 | 0 | a->e = 30 - (WORD32)ceil(log_a_f); |
59 | 0 | a->sm = (WORD32)(a_f * pow(2, a->e)); |
60 | 0 | } |
61 | 0 | else |
62 | 0 | { |
63 | 0 | a->e = 0; |
64 | 0 | a->sm = 0; |
65 | 0 | } |
66 | 0 | } |
67 | | |
68 | | void convert_fix_to_float(number_t a, float *a_f) |
69 | 0 | { |
70 | 0 | *a_f = (float)(a.sm / pow(2, a.e)); |
71 | 0 | } |
72 | | |
73 | | #ifdef ITT_C6678 |
74 | | #pragma CODE_SECTION(convert_fix_to_float, "itt_varq_l1pram"); |
75 | | #pragma CODE_SECTION(convert_float_to_fix, "itt_varq_l1pram"); |
76 | | #endif |