1 /*
2 * Copyright 2020 Rockchip Electronics Co. LTD
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define MODULE_TAG "hal_jpege_base"
18
19 #include <string.h>
20
21 #include "mpp_mem.h"
22 #include "mpp_common.h"
23
24 #include "hal_jpege_debug.h"
25 #include "hal_jpege_base.h"
26
27 const RK_U32 qp_reorder_table[64] = {
28 0, 8, 16, 24, 1, 9, 17, 25, 32, 40, 48, 56, 33, 41, 49, 57,
29 2, 10, 18, 26, 3, 11, 19, 27, 34, 42, 50, 58, 35, 43, 51, 59,
30 4, 12, 20, 28, 5, 13, 21, 29, 36, 44, 52, 60, 37, 45, 53, 61,
31 6, 14, 22, 30, 7, 15, 23, 31, 38, 46, 54, 62, 39, 47, 55, 63
32 };
33
34 const RK_U16 jpege_restart_marker[8] = {
35 0xFFD0, 0xFFD1, 0xFFD2, 0xFFD3,
36 0xFFD4, 0xFFD5, 0xFFD6, 0xFFD7,
37 };
38
get_msb_lsb_at_pos(RK_U32 * msb,RK_U32 * lsb,RK_U8 * buf,RK_U32 bytepos)39 void get_msb_lsb_at_pos(RK_U32 *msb, RK_U32 *lsb, RK_U8 *buf, RK_U32 bytepos)
40 {
41 RK_U32 val32;
42 RK_S32 left_byte = bytepos & 0x7;
43 RK_U8 *tmp = buf + (bytepos & (~0x7));
44
45 // clear the rest bytes in 64bit
46 if (left_byte) {
47 RK_U32 i;
48
49 for (i = left_byte; i < 8; i++)
50 tmp[i] = 0;
51 }
52
53 val32 = (tmp[0] << 24) |
54 (tmp[1] << 16) |
55 (tmp[2] << 8) |
56 (tmp[3] << 0);
57
58 *msb = val32;
59
60 if (left_byte > 4) {
61 val32 = (tmp[4] << 24) |
62 (tmp[5] << 16) |
63 (tmp[6] << 8);
64 } else
65 val32 = 0;
66
67 *lsb = val32;
68 }
69