diff --git a/build/kvazaar_lib/kvazaar_lib.vcxproj b/build/kvazaar_lib/kvazaar_lib.vcxproj index 359601df..d0d6878b 100644 --- a/build/kvazaar_lib/kvazaar_lib.vcxproj +++ b/build/kvazaar_lib/kvazaar_lib.vcxproj @@ -211,6 +211,7 @@ + @@ -278,4 +279,4 @@ - + \ No newline at end of file diff --git a/build/kvazaar_lib/kvazaar_lib.vcxproj.filters b/build/kvazaar_lib/kvazaar_lib.vcxproj.filters index 50e71376..8509111a 100644 --- a/build/kvazaar_lib/kvazaar_lib.vcxproj.filters +++ b/build/kvazaar_lib/kvazaar_lib.vcxproj.filters @@ -382,6 +382,7 @@ Bitstream + @@ -394,4 +395,4 @@ Optimization\strategies\x86_asm - + \ No newline at end of file diff --git a/src/Makefile.am b/src/Makefile.am index 9d3bc609..2325b0c1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -70,6 +70,7 @@ libkvazaar_la_SOURCES = \ intra.h \ kvazaar.c \ kvazaar_internal.h \ + kvz_math.h \ nal.c \ nal.h \ rate_control.c \ diff --git a/src/kvz_math.h b/src/kvz_math.h new file mode 100644 index 00000000..f03dad69 --- /dev/null +++ b/src/kvz_math.h @@ -0,0 +1,54 @@ +#ifndef MATH_H_ +#define MATH_H_ +/***************************************************************************** +* This file is part of Kvazaar HEVC encoder. +* +* Copyright (C) 2013-2015 Tampere University of Technology and others (see +* COPYING file). +* +* Kvazaar is free software: you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the +* Free Software Foundation; either version 2.1 of the License, or (at your +* option) any later version. +* +* Kvazaar is distributed in the hope that it will be useful, but WITHOUT ANY +* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along +* with Kvazaar. If not, see . +****************************************************************************/ + +/** +* \file +* Generic math functions +*/ + +#include "global.h" + +static INLINE unsigned kvz_math_floor_log2(unsigned value) +{ + assert(value > 0); + + unsigned result = 0; + + for (int i = 4; i >= 0; --i) { + unsigned bits = 1ull << i; + unsigned shift = value >= (1 << bits) ? bits : 0; + result += shift; + value >>= shift; + } + + return result; +} + +static INLINE unsigned kvz_math_ceil_log2(unsigned value) +{ + assert(value > 0); + + // The ceil_log2 is just floor_log2 + 1, except for exact powers of 2. + return kvz_math_floor_log2(value) + ((value & (value - 1)) ? 1 : 0); +} + +#endif //CHECKPOINT_H_