media/libvpx/vp9/common/vp9_common.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial