16fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org/*
26fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
36fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *
46fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  Use of this source code is governed by a BSD-style license
56fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  that can be found in the LICENSE file in the root of the source
66fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  tree. An additional intellectual property rights grant can be found
76fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  in the file PATENTS.  All contributing project authors may
86fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  be found in the AUTHORS file in the root of the source tree.
96fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org */
106fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
116fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org#ifndef VP9_COMMON_VP9_MV_H_
126fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org#define VP9_COMMON_VP9_MV_H_
13d348b8d765c019ee7250075d663a83db00c65c08tomfinegan@chromium.org
146fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org#include "vpx/vpx_integer.h"
156fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
1653a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org#include "vp9/common/vp9_common.h"
1753a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org
18dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#ifdef __cplusplus
19dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.orgextern "C" {
20dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#endif
21dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
22d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.orgtypedef struct mv {
23d348b8d765c019ee7250075d663a83db00c65c08tomfinegan@chromium.org  int16_t row;
24d348b8d765c019ee7250075d663a83db00c65c08tomfinegan@chromium.org  int16_t col;
256fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org} MV;
266fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
276fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.orgtypedef union int_mv {
286fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  uint32_t as_int;
296fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  MV as_mv;
306fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org} int_mv; /* facilitates faster equality tests and copies */
316fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
32d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.orgtypedef struct mv32 {
331958a6b43506c5fdf713554177fdd12c3b255c54johannkoenig@chromium.org  int32_t row;
341958a6b43506c5fdf713554177fdd12c3b255c54johannkoenig@chromium.org  int32_t col;
3547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org} MV32;
361958a6b43506c5fdf713554177fdd12c3b255c54johannkoenig@chromium.org
37d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.orgstatic INLINE int is_zero_mv(const MV *mv) {
38d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org  return *((const uint32_t *)mv) == 0;
39d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org}
40d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org
41d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.orgstatic INLINE int is_equal_mv(const MV *a, const MV *b) {
42d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org  return  *((const uint32_t *)a) == *((const uint32_t *)b);
43d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org}
44d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org
4576e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.orgstatic INLINE void clamp_mv(MV *mv, int min_col, int max_col,
4676e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org                            int min_row, int max_row) {
4753a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  mv->col = clamp(mv->col, min_col, max_col);
4853a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  mv->row = clamp(mv->row, min_row, max_row);
4953a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org}
5053a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org
51dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#ifdef __cplusplus
52dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org}  // extern "C"
53dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#endif
54dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
55d348b8d765c019ee7250075d663a83db00c65c08tomfinegan@chromium.org#endif  // VP9_COMMON_VP9_MV_H_
56