media/libvpx/vp9/common/vp9_common.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:e20613676318
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #ifndef VP9_COMMON_VP9_COMMON_H_
12 #define VP9_COMMON_VP9_COMMON_H_
13
14 /* Interface header for common constant data structures and lookup tables */
15
16 #include <assert.h>
17
18 #include "./vpx_config.h"
19 #include "vpx_mem/vpx_mem.h"
20 #include "vpx/vpx_integer.h"
21
22 #define MIN(x, y) (((x) < (y)) ? (x) : (y))
23 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
24
25 #define ROUND_POWER_OF_TWO(value, n) \
26 (((value) + (1 << ((n) - 1))) >> (n))
27
28 #define ALIGN_POWER_OF_TWO(value, n) \
29 (((value) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1))
30
31 // Only need this for fixed-size arrays, for structs just assign.
32 #define vp9_copy(dest, src) { \
33 assert(sizeof(dest) == sizeof(src)); \
34 vpx_memcpy(dest, src, sizeof(src)); \
35 }
36
37 // Use this for variably-sized arrays.
38 #define vp9_copy_array(dest, src, n) { \
39 assert(sizeof(*dest) == sizeof(*src)); \
40 vpx_memcpy(dest, src, n * sizeof(*src)); \
41 }
42
43 #define vp9_zero(dest) vpx_memset(&dest, 0, sizeof(dest))
44 #define vp9_zero_array(dest, n) vpx_memset(dest, 0, n * sizeof(*dest))
45
46 static INLINE uint8_t clip_pixel(int val) {
47 return (val > 255) ? 255u : (val < 0) ? 0u : val;
48 }
49
50 static INLINE int clamp(int value, int low, int high) {
51 return value < low ? low : (value > high ? high : value);
52 }
53
54 static INLINE double fclamp(double value, double low, double high) {
55 return value < low ? low : (value > high ? high : value);
56 }
57
58 static int get_unsigned_bits(unsigned int num_values) {
59 int cat = 0;
60 if (num_values <= 1)
61 return 0;
62 num_values--;
63 while (num_values > 0) {
64 cat++;
65 num_values >>= 1;
66 }
67 return cat;
68 }
69
70 #if CONFIG_DEBUG
71 #define CHECK_MEM_ERROR(cm, lval, expr) do { \
72 lval = (expr); \
73 if (!lval) \
74 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, \
75 "Failed to allocate "#lval" at %s:%d", \
76 __FILE__, __LINE__); \
77 } while (0)
78 #else
79 #define CHECK_MEM_ERROR(cm, lval, expr) do { \
80 lval = (expr); \
81 if (!lval) \
82 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, \
83 "Failed to allocate "#lval); \
84 } while (0)
85 #endif
86
87 #define VP9_SYNC_CODE_0 0x49
88 #define VP9_SYNC_CODE_1 0x83
89 #define VP9_SYNC_CODE_2 0x42
90
91 #define VP9_FRAME_MARKER 0x2
92
93
94 #endif // VP9_COMMON_VP9_COMMON_H_

mercurial