vpx/vp9/common/vp9_common.h
Ronald S. Bultje 4d0ec7aacd Consistently use get_prob(), clip_prob() and newly added clip_pixel().
Add a function clip_pixel() to clip a pixel value to the [0,255] range
of allowed values, and use this where-ever appropriate (e.g. prediction,
reconstruction). Likewise, consistently use the recently added function
clip_prob(), which calculates a binary probability in the [1,255] range.
If possible, try to use get_prob() or its sister get_binary_prob() to
calculate binary probabilities, for consistency.

Since in some places, this means that binary probability calculations
are changed (we use {255,256}*count0/(total) in a range of places,
and all of these are now changed to use 256*count0+(total>>1)/total),
this changes the encoding result, so this patch warrants some extensive
testing.

Change-Id: Ibeeff8d886496839b8e0c0ace9ccc552351f7628
2012-12-12 10:01:19 -08:00

46 lines
1.3 KiB
C

/*
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef VP9_COMMON_VP9_COMMON_H_
#define VP9_COMMON_VP9_COMMON_H_
#include <assert.h>
#include "vpx_config.h"
/* Interface header for common constant data structures and lookup tables */
#include "vpx_mem/vpx_mem.h"
#include "vpx/vpx_integer.h"
#include "vp9/common/vp9_common_types.h"
/* Only need this for fixed-size arrays, for structs just assign. */
#define vp9_copy( Dest, Src) { \
assert( sizeof( Dest) == sizeof( Src)); \
vpx_memcpy( Dest, Src, sizeof( Src)); \
}
/* Use this for variably-sized arrays. */
#define vp9_copy_array( Dest, Src, N) { \
assert( sizeof( *Dest) == sizeof( *Src)); \
vpx_memcpy( Dest, Src, N * sizeof( *Src)); \
}
#define vp9_zero( Dest) vpx_memset( &Dest, 0, sizeof( Dest));
#define vp9_zero_array( Dest, N) vpx_memset( Dest, 0, N * sizeof( *Dest));
static __inline uint8_t clip_pixel(int val) {
return (val > 255) ? 255u : (val < 0) ? 0u : val;
}
#endif /* common_h */