exynos: add libion dependencies
[GitHub/LineageOS/android_hardware_samsung_slsi_exynos.git] / libhwjpeg / hwjpeg-internal.h
1 /*
2 * Copyright Samsung Electronics Co.,LTD.
3 * Copyright (C) 2015 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 #ifndef __HWJPEG_INTERNAL_H__
19 #define __HWJPEG_INTERNAL_H__
20
21 #ifndef LOG_TAG
22 #error "LOG_TAG is not defined!"
23 #endif
24
25 #include <cerrno>
26 #include <cstring>
27
28 #include <cutils/log.h>
29
30 #ifdef __GNUC__
31 # define __UNUSED__ __attribute__((__unused__))
32 #else
33 # define __UNUSED__
34 #endif
35
36 #ifndef ALOGERR
37 #define ALOGERR(fmt, args...) ((void)ALOG(LOG_ERROR, LOG_TAG, fmt " [%s]", ##args, strerror(errno)))
38 #endif
39
40 #define V4L2_CID_JPEG_SEC_COMP_QUALITY (V4L2_CID_JPEG_CLASS_BASE + 20)
41 #define V4L2_CID_JPEG_QTABLES2 (V4L2_CID_JPEG_CLASS_BASE + 22)
42 #define V4L2_CID_JPEG_HWFC_ENABLE (V4L2_CID_JPEG_CLASS_BASE + 25)
43
44 #define TO_MAIN_SIZE(val) ((val) & 0xFFFF)
45 #define TO_THUMB_SIZE(val) (((val) & 0xFFFF) << 16)
46 #define TO_IMAGE_SIZE(main, thumb) (TO_MAIN_SIZE(main) | TO_THUMB_SIZE(thumb))
47
48 #define PTR_TO_ULONG(ptr) reinterpret_cast<unsigned long>(ptr)
49 #define PTR_DIFF(ptr1, ptr2) (reinterpret_cast<size_t>(ptr2) - reinterpret_cast<size_t>(ptr1))
50
51 #define ARRSIZE(v) (sizeof(v) / sizeof(v[0]))
52
53 #ifndef min
54 template <typename T>
55 static inline T min(T val1, T val2) {
56 return (val1 > val2) ? val2 : val1;
57 }
58 #endif
59
60 #ifndef max
61 template <typename T>
62 static inline T max(T val1, T val2) {
63 return (val1 < val2) ? val2 : val1;
64 }
65 #endif
66
67 // H/W requires 16-byte alignment
68 #define HW_BASE_ALIGN_BITS 4
69 #define HW_BASE_ALIGN_SIZE (1 << HW_BASE_ALIGN_BITS)
70 #define HW_BASE_ALIGN_MASK ~(HW_BASE_ALIGN_SIZE - 1)
71
72 class CStopWatch {
73 timespec m_tBegin;
74 public:
75 CStopWatch(bool start = false) {
76 if (start)
77 Start();
78 }
79 bool Start();
80 unsigned long GetElapsed();
81 unsigned long GetElapsedUpdate();
82 };
83
84 bool WriteToFile(const char *path, const char *data, size_t len);
85 bool WriteToFile(const char *path, int dmabuf, size_t len);
86 #endif //__HWJPEG_INTERNAL_H__