Skip to content

Commit

Permalink
Merge branch '10bit_fixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
fador committed Sep 5, 2024
2 parents 2f9a214 + 9e61ac3 commit 5cc93dc
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ unsigned kvz_image_calc_satd(const kvz_picture *pic,
pic_data,
pic->stride,
ref_data,
ref->stride) >> (KVZ_BIT_DEPTH - 8);
ref->stride);
} else {
// Extrapolate pixels from outside the frame.

Expand Down Expand Up @@ -514,7 +514,7 @@ unsigned kvz_image_calc_satd(const kvz_picture *pic,
pic_data,
pic->stride,
ext_origin,
ext_s) >> (KVZ_BIT_DEPTH - 8);
ext_s);

return satd;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rate_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ static double qp_to_lambda(encoder_state_t* const state, int qp)
alpha = -state->frame->c_para[index] * state->frame->k_para[index];
beta = state->frame->k_para[index] - 1;
}

alpha *= (double)(1 << (KVZ_BIT_DEPTH - 8));
double est_lambda;
int est_qp;
if (state->frame->is_irap && encoder->cfg.intra_bit_allocation) {
Expand Down
29 changes: 13 additions & 16 deletions src/strategies/avx2/dct-avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

#if COMPILE_INTEL_AVX2
#include "kvazaar.h"
#if KVZ_BIT_DEPTH == 8
#include <immintrin.h>

#include "strategyselector.h"
Expand Down Expand Up @@ -938,30 +937,28 @@ static void matrix_i ## type ## _## n ## x ## n ## _avx2(int8_t bitdepth, const
TRANSFORM(dct, 32);
ITRANSFORM(dct, 32);

#endif // KVZ_BIT_DEPTH == 8

#endif //COMPILE_INTEL_AVX2

int kvz_strategy_register_dct_avx2(void* opaque, uint8_t bitdepth)
{
bool success = true;
#if COMPILE_INTEL_AVX2
#if KVZ_BIT_DEPTH == 8
if (bitdepth == 8){
success &= kvz_strategyselector_register(opaque, "fast_forward_dst_4x4", "avx2", 40, &matrix_dst_4x4_avx2);
// Coefficients are the same for all bitdepths, no need to disable for 10-bit
success &= kvz_strategyselector_register(opaque, "fast_forward_dst_4x4", "avx2", 40, &matrix_dst_4x4_avx2);

success &= kvz_strategyselector_register(opaque, "dct_4x4", "avx2", 40, &matrix_dct_4x4_avx2);
success &= kvz_strategyselector_register(opaque, "dct_8x8", "avx2", 40, &matrix_dct_8x8_avx2);
success &= kvz_strategyselector_register(opaque, "dct_16x16", "avx2", 40, &matrix_dct_16x16_avx2);
success &= kvz_strategyselector_register(opaque, "dct_32x32", "avx2", 40, &matrix_dct_32x32_avx2);
success &= kvz_strategyselector_register(opaque, "dct_4x4", "avx2", 40, &matrix_dct_4x4_avx2);
success &= kvz_strategyselector_register(opaque, "dct_8x8", "avx2", 40, &matrix_dct_8x8_avx2);
success &= kvz_strategyselector_register(opaque, "dct_16x16", "avx2", 40, &matrix_dct_16x16_avx2);
success &= kvz_strategyselector_register(opaque, "dct_32x32", "avx2", 40, &matrix_dct_32x32_avx2);

success &= kvz_strategyselector_register(opaque, "fast_inverse_dst_4x4", "avx2", 40, &matrix_idst_4x4_avx2);
success &= kvz_strategyselector_register(opaque, "fast_inverse_dst_4x4", "avx2", 40, &matrix_idst_4x4_avx2);

success &= kvz_strategyselector_register(opaque, "idct_4x4", "avx2", 40, &matrix_idct_4x4_avx2);
success &= kvz_strategyselector_register(opaque, "idct_8x8", "avx2", 40, &matrix_idct_8x8_avx2);
success &= kvz_strategyselector_register(opaque, "idct_16x16", "avx2", 40, &matrix_idct_16x16_avx2);
success &= kvz_strategyselector_register(opaque, "idct_32x32", "avx2", 40, &matrix_idct_32x32_avx2);
}
#endif // KVZ_BIT_DEPTH == 8
success &= kvz_strategyselector_register(opaque, "idct_4x4", "avx2", 40, &matrix_idct_4x4_avx2);
success &= kvz_strategyselector_register(opaque, "idct_8x8", "avx2", 40, &matrix_idct_8x8_avx2);
success &= kvz_strategyselector_register(opaque, "idct_16x16", "avx2", 40, &matrix_idct_16x16_avx2);
success &= kvz_strategyselector_register(opaque, "idct_32x32", "avx2", 40, &matrix_idct_32x32_avx2);

#endif //COMPILE_INTEL_AVX2
return success;
}
8 changes: 4 additions & 4 deletions src/strategies/generic/sao_shared_generics.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ static int sao_edge_ddistortion_generic(const kvz_pixel *orig_data,
uint32_t a_pos = (y + a_ofs.y) * block_width + x + a_ofs.x;
uint32_t b_pos = (y + b_ofs.y) * block_width + x + b_ofs.x;

uint8_t a = rec_data[a_pos];
uint8_t b = rec_data[b_pos];
uint8_t c = rec_data[c_pos];
uint8_t orig = orig_data[c_pos];
kvz_pixel a = rec_data[a_pos];
kvz_pixel b = rec_data[b_pos];
kvz_pixel c = rec_data[c_pos];
kvz_pixel orig = orig_data[c_pos];

int32_t eo_cat = sao_calc_eo_cat(a, b, c);
int32_t offset = offsets[eo_cat];
Expand Down
49 changes: 34 additions & 15 deletions src/yuv_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,43 @@ static int read_and_fill_frame_data(FILE *file,
unsigned width, unsigned height, unsigned bytes_per_sample,
unsigned array_width, kvz_pixel *data)
{
kvz_pixel* p = data;
kvz_pixel* end = data + array_width * height;
kvz_pixel fill_char;
unsigned i;

while (p < end) {
// Read the beginning of the line from input.
if (width != fread(p, bytes_per_sample, width, file))
return 0;

// Fill the rest with the last pixel value.
fill_char = p[width - 1];
unsigned i;
// Handle separately the case where we use KVZ_BIT_DEPTH 10+ but the input is 8-bit.
if (bytes_per_sample != sizeof(kvz_pixel)) {
uint8_t* p = (uint8_t*)data;
uint8_t* end = (uint8_t*)data + array_width * height;
uint8_t fill_char;
while (p < end) {
// Read the beginning of the line from input.
if (width != fread(p, bytes_per_sample, width, file)) return 0;
// Fill the rest with the last pixel value.
// Fill the rest with the last pixel value.
fill_char = p[width - 1];

for (i = width; i < array_width; ++i) {
p[i] = fill_char;
}

for (i = width; i < array_width; ++i) {
p[i] = fill_char;
p += array_width;
}
}
else {
kvz_pixel* p = data;
kvz_pixel* end = data + array_width * height;
kvz_pixel fill_char;
while (p < end) {
// Read the beginning of the line from input.
if (width != fread(p, bytes_per_sample, width, file)) return 0;
// Fill the rest with the last pixel value.
fill_char = p[width - 1];

for (i = width; i < array_width; ++i) {
p[i] = fill_char;
}

p += array_width;
p += array_width;
}
}
return 1;
}
Expand Down Expand Up @@ -313,7 +332,7 @@ int yuv_io_seek(FILE* file, unsigned frames,

// Seek failed. Skip data by reading.
error = 0;
unsigned char* tmp[4096];
unsigned char tmp[4096];
size_t bytes_left = skip_bytes;
while (bytes_left > 0 && !error) {
const size_t skip = MIN(4096, bytes_left);
Expand Down

0 comments on commit 5cc93dc

Please sign in to comment.