mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-24 02:24:07 +00:00
Merge branch 'log2'
This commit is contained in:
commit
df9a958ef2
|
@ -211,6 +211,7 @@
|
||||||
<ClCompile Include="..\..\src\transform.c" />
|
<ClCompile Include="..\..\src\transform.c" />
|
||||||
<ClInclude Include="..\..\src\input_frame_buffer.h" />
|
<ClInclude Include="..\..\src\input_frame_buffer.h" />
|
||||||
<ClInclude Include="..\..\src\kvazaar_internal.h" />
|
<ClInclude Include="..\..\src\kvazaar_internal.h" />
|
||||||
|
<ClInclude Include="..\..\src\kvz_math.h" />
|
||||||
<ClInclude Include="..\..\src\search_inter.h" />
|
<ClInclude Include="..\..\src\search_inter.h" />
|
||||||
<ClInclude Include="..\..\src\search_intra.h" />
|
<ClInclude Include="..\..\src\search_intra.h" />
|
||||||
<ClInclude Include="..\..\src\strategies\avx2\intra-avx2.h" />
|
<ClInclude Include="..\..\src\strategies\avx2\intra-avx2.h" />
|
||||||
|
@ -278,4 +279,4 @@
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
<Import Project="..\yasm\vsyasm.targets" />
|
<Import Project="..\yasm\vsyasm.targets" />
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -382,6 +382,7 @@
|
||||||
<ClInclude Include="..\..\src\encoder_state-bitstream.h">
|
<ClInclude Include="..\..\src\encoder_state-bitstream.h">
|
||||||
<Filter>Bitstream</Filter>
|
<Filter>Bitstream</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\kvz_math.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<YASM Include="..\..\src\extras\x86inc.asm">
|
<YASM Include="..\..\src\extras\x86inc.asm">
|
||||||
|
@ -394,4 +395,4 @@
|
||||||
<Filter>Optimization\strategies\x86_asm</Filter>
|
<Filter>Optimization\strategies\x86_asm</Filter>
|
||||||
</YASM>
|
</YASM>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -71,6 +71,7 @@ libkvazaar_la_SOURCES = \
|
||||||
intra.h \
|
intra.h \
|
||||||
kvazaar.c \
|
kvazaar.c \
|
||||||
kvazaar_internal.h \
|
kvazaar_internal.h \
|
||||||
|
kvz_math.h \
|
||||||
nal.c \
|
nal.c \
|
||||||
nal.h \
|
nal.h \
|
||||||
rate_control.c \
|
rate_control.c \
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "kvz_math.h"
|
||||||
|
|
||||||
const uint32_t kvz_bit_set_mask[] =
|
const uint32_t kvz_bit_set_mask[] =
|
||||||
{
|
{
|
||||||
0x00000001,0x00000002,0x00000004,0x00000008,
|
0x00000001,0x00000002,0x00000004,0x00000008,
|
||||||
|
@ -57,19 +59,6 @@ void printf_bitstream(char *msg, ...)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int floor_log2(unsigned int n)
|
|
||||||
{
|
|
||||||
assert(n != 0);
|
|
||||||
|
|
||||||
int pos = 0;
|
|
||||||
if (n >= 1<<16) { n >>= 16; pos += 16; }
|
|
||||||
if (n >= 1<< 8) { n >>= 8; pos += 8; }
|
|
||||||
if (n >= 1<< 4) { n >>= 4; pos += 4; }
|
|
||||||
if (n >= 1<< 2) { n >>= 2; pos += 2; }
|
|
||||||
if (n >= 1<< 1) { pos += 1; }
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Initialize the Exp Golomb code table.
|
* \brief Initialize the Exp Golomb code table.
|
||||||
*
|
*
|
||||||
|
@ -84,7 +73,7 @@ void kvz_init_exp_golomb()
|
||||||
uint8_t M;
|
uint8_t M;
|
||||||
uint32_t info;
|
uint32_t info;
|
||||||
for (code_num = 0; code_num < EXP_GOLOMB_TABLE_SIZE; code_num++) {
|
for (code_num = 0; code_num < EXP_GOLOMB_TABLE_SIZE; code_num++) {
|
||||||
M = (uint8_t)floor_log2(code_num + 1);
|
M = kvz_math_floor_log2(code_num + 1);
|
||||||
info = code_num + 1 - (uint32_t)pow(2, M);
|
info = code_num + 1 - (uint32_t)pow(2, M);
|
||||||
kvz_g_exp_table[code_num].len = M * 2 + 1;
|
kvz_g_exp_table[code_num].len = M * 2 + 1;
|
||||||
kvz_g_exp_table[code_num].value = (1<<M) | info;
|
kvz_g_exp_table[code_num].value = (1<<M) | info;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include "checkpoint.h"
|
#include "checkpoint.h"
|
||||||
#include "encoderstate.h"
|
#include "encoderstate.h"
|
||||||
|
#include "kvz_math.h"
|
||||||
#include "nal.h"
|
#include "nal.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -630,16 +631,6 @@ static void encoder_state_write_bitstream_entry_points_write(bitstream_t * const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int num_bitcount(unsigned int n) {
|
|
||||||
int pos = 0;
|
|
||||||
if (n >= 1<<16) { n >>= 16; pos += 16; }
|
|
||||||
if (n >= 1<< 8) { n >>= 8; pos += 8; }
|
|
||||||
if (n >= 1<< 4) { n >>= 4; pos += 4; }
|
|
||||||
if (n >= 1<< 2) { n >>= 2; pos += 2; }
|
|
||||||
if (n >= 1<< 1) { pos += 1; }
|
|
||||||
return ((n == 0) ? (-1) : pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
void kvz_encoder_state_write_bitstream_slice_header(encoder_state_t * const state)
|
void kvz_encoder_state_write_bitstream_slice_header(encoder_state_t * const state)
|
||||||
{
|
{
|
||||||
const encoder_control_t * const encoder = state->encoder_control;
|
const encoder_control_t * const encoder = state->encoder_control;
|
||||||
|
@ -777,7 +768,7 @@ void kvz_encoder_state_write_bitstream_slice_header(encoder_state_t * const stat
|
||||||
WRITE_UE(stream, num_entry_points - 1, "num_entry_point_offsets");
|
WRITE_UE(stream, num_entry_points - 1, "num_entry_point_offsets");
|
||||||
if (num_entry_points > 0) {
|
if (num_entry_points > 0) {
|
||||||
int entry_points_written = 0;
|
int entry_points_written = 0;
|
||||||
int offset_len = num_bitcount(max_length_seen) + 1;
|
int offset_len = kvz_math_floor_log2(max_length_seen) + 1;
|
||||||
WRITE_UE(stream, offset_len - 1, "offset_len_minus1");
|
WRITE_UE(stream, offset_len - 1, "offset_len_minus1");
|
||||||
encoder_state_write_bitstream_entry_points_write(stream, state, num_entry_points, offset_len, &entry_points_written);
|
encoder_state_write_bitstream_entry_points_write(stream, state, num_entry_points, offset_len, &entry_points_written);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "rdo.h"
|
#include "rdo.h"
|
||||||
#include "rate_control.h"
|
#include "rate_control.h"
|
||||||
#include "strategies/strategies-picture.h"
|
#include "strategies/strategies-picture.h"
|
||||||
|
#include "kvz_math.h"
|
||||||
|
|
||||||
int kvz_encoder_state_match_children_of_previous_frame(encoder_state_t * const state) {
|
int kvz_encoder_state_match_children_of_previous_frame(encoder_state_t * const state) {
|
||||||
int i;
|
int i;
|
||||||
|
@ -1946,8 +1947,9 @@ void kvz_encode_last_significant_xy(encoder_state_t * const state,
|
||||||
uint8_t type, uint8_t scan)
|
uint8_t type, uint8_t scan)
|
||||||
{
|
{
|
||||||
cabac_data_t * const cabac = &state->cabac;
|
cabac_data_t * const cabac = &state->cabac;
|
||||||
uint8_t offset_x = type?0:((TOBITS(width)*3) + ((TOBITS(width)+1)>>2)),offset_y = offset_x;
|
int index = kvz_math_floor_log2(width) - 2;
|
||||||
uint8_t shift_x = type?(TOBITS(width)):((TOBITS(width)+3)>>2), shift_y = shift_x;
|
uint8_t offset_x = type?0:((index*3) + ((index+1)>>2)),offset_y = offset_x;
|
||||||
|
uint8_t shift_x = type?(index):((index+3)>>2), shift_y = shift_x;
|
||||||
int group_idx_x;
|
int group_idx_x;
|
||||||
int group_idx_y;
|
int group_idx_y;
|
||||||
int last_x,last_y,i;
|
int last_x,last_y,i;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "encoder.h"
|
#include "encoder.h"
|
||||||
|
#include "kvz_math.h"
|
||||||
#include "transform.h"
|
#include "transform.h"
|
||||||
#include "strategies/strategies-intra.h"
|
#include "strategies/strategies-intra.h"
|
||||||
#include "strategies/strategies-picture.h"
|
#include "strategies/strategies-picture.h"
|
||||||
|
@ -227,7 +228,7 @@ void kvz_intra_predict(
|
||||||
// Angular modes use smoothed reference pixels, unless the mode is close
|
// Angular modes use smoothed reference pixels, unless the mode is close
|
||||||
// to being either vertical or horizontal.
|
// to being either vertical or horizontal.
|
||||||
static const int kvz_intra_hor_ver_dist_thres[5] = { 0, 7, 1, 0, 0 };
|
static const int kvz_intra_hor_ver_dist_thres[5] = { 0, 7, 1, 0, 0 };
|
||||||
int filter_threshold = kvz_intra_hor_ver_dist_thres[g_to_bits[width]];
|
int filter_threshold = kvz_intra_hor_ver_dist_thres[kvz_math_floor_log2(width) - 2];
|
||||||
int dist_from_vert_or_hor = MIN(abs(mode - 26), abs(mode - 10));
|
int dist_from_vert_or_hor = MIN(abs(mode - 26), abs(mode - 10));
|
||||||
if (dist_from_vert_or_hor > filter_threshold) {
|
if (dist_from_vert_or_hor > filter_threshold) {
|
||||||
used_ref = &refs->filtered_ref;
|
used_ref = &refs->filtered_ref;
|
||||||
|
|
54
src/kvz_math.h
Normal file
54
src/kvz_math.h
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \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_
|
15
src/tables.h
15
src/tables.h
|
@ -28,21 +28,6 @@
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
//4 8 16 32 64 128
|
|
||||||
//0 1 2 3 4 5
|
|
||||||
static const uint8_t g_to_bits[129] =
|
|
||||||
{
|
|
||||||
0,
|
|
||||||
0,0,0,0,
|
|
||||||
0,0,0,1,
|
|
||||||
0,0,0,0,0,0,0,2,
|
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,
|
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
|
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5
|
|
||||||
};
|
|
||||||
#define TOBITS(len) g_to_bits[len]
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* List of indices for 4x4 coefficient groups within 8x8 transform block.
|
* List of indices for 4x4 coefficient groups within 8x8 transform block.
|
||||||
* First index: 0 = diagonal, 1 = vertical, 2 horizontal scan pattern.
|
* First index: 0 = diagonal, 1 = vertical, 2 horizontal scan pattern.
|
||||||
|
|
Loading…
Reference in a new issue