Skip to content

Commit 5cc93dc

Browse files
committedSep 5, 2024·
Merge branch '10bit_fixes'
2 parents 2f9a214 + 9e61ac3 commit 5cc93dc

File tree

5 files changed

+54
-38
lines changed

5 files changed

+54
-38
lines changed
 

‎src/image.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ unsigned kvz_image_calc_satd(const kvz_picture *pic,
472472
pic_data,
473473
pic->stride,
474474
ref_data,
475-
ref->stride) >> (KVZ_BIT_DEPTH - 8);
475+
ref->stride);
476476
} else {
477477
// Extrapolate pixels from outside the frame.
478478

@@ -514,7 +514,7 @@ unsigned kvz_image_calc_satd(const kvz_picture *pic,
514514
pic_data,
515515
pic->stride,
516516
ext_origin,
517-
ext_s) >> (KVZ_BIT_DEPTH - 8);
517+
ext_s);
518518

519519
return satd;
520520
}

‎src/rate_control.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ static double qp_to_lambda(encoder_state_t* const state, int qp)
716716
alpha = -state->frame->c_para[index] * state->frame->k_para[index];
717717
beta = state->frame->k_para[index] - 1;
718718
}
719-
719+
alpha *= (double)(1 << (KVZ_BIT_DEPTH - 8));
720720
double est_lambda;
721721
int est_qp;
722722
if (state->frame->is_irap && encoder->cfg.intra_bit_allocation) {

‎src/strategies/avx2/dct-avx2.c

+13-16
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
#if COMPILE_INTEL_AVX2
4040
#include "kvazaar.h"
41-
#if KVZ_BIT_DEPTH == 8
4241
#include <immintrin.h>
4342

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

941-
#endif // KVZ_BIT_DEPTH == 8
940+
942941
#endif //COMPILE_INTEL_AVX2
943942

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

952-
success &= kvz_strategyselector_register(opaque, "dct_4x4", "avx2", 40, &matrix_dct_4x4_avx2);
953-
success &= kvz_strategyselector_register(opaque, "dct_8x8", "avx2", 40, &matrix_dct_8x8_avx2);
954-
success &= kvz_strategyselector_register(opaque, "dct_16x16", "avx2", 40, &matrix_dct_16x16_avx2);
955-
success &= kvz_strategyselector_register(opaque, "dct_32x32", "avx2", 40, &matrix_dct_32x32_avx2);
950+
success &= kvz_strategyselector_register(opaque, "dct_4x4", "avx2", 40, &matrix_dct_4x4_avx2);
951+
success &= kvz_strategyselector_register(opaque, "dct_8x8", "avx2", 40, &matrix_dct_8x8_avx2);
952+
success &= kvz_strategyselector_register(opaque, "dct_16x16", "avx2", 40, &matrix_dct_16x16_avx2);
953+
success &= kvz_strategyselector_register(opaque, "dct_32x32", "avx2", 40, &matrix_dct_32x32_avx2);
956954

957-
success &= kvz_strategyselector_register(opaque, "fast_inverse_dst_4x4", "avx2", 40, &matrix_idst_4x4_avx2);
955+
success &= kvz_strategyselector_register(opaque, "fast_inverse_dst_4x4", "avx2", 40, &matrix_idst_4x4_avx2);
958956

959-
success &= kvz_strategyselector_register(opaque, "idct_4x4", "avx2", 40, &matrix_idct_4x4_avx2);
960-
success &= kvz_strategyselector_register(opaque, "idct_8x8", "avx2", 40, &matrix_idct_8x8_avx2);
961-
success &= kvz_strategyselector_register(opaque, "idct_16x16", "avx2", 40, &matrix_idct_16x16_avx2);
962-
success &= kvz_strategyselector_register(opaque, "idct_32x32", "avx2", 40, &matrix_idct_32x32_avx2);
963-
}
964-
#endif // KVZ_BIT_DEPTH == 8
957+
success &= kvz_strategyselector_register(opaque, "idct_4x4", "avx2", 40, &matrix_idct_4x4_avx2);
958+
success &= kvz_strategyselector_register(opaque, "idct_8x8", "avx2", 40, &matrix_idct_8x8_avx2);
959+
success &= kvz_strategyselector_register(opaque, "idct_16x16", "avx2", 40, &matrix_idct_16x16_avx2);
960+
success &= kvz_strategyselector_register(opaque, "idct_32x32", "avx2", 40, &matrix_idct_32x32_avx2);
961+
965962
#endif //COMPILE_INTEL_AVX2
966963
return success;
967964
}

‎src/strategies/generic/sao_shared_generics.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ static int sao_edge_ddistortion_generic(const kvz_pixel *orig_data,
6767
uint32_t a_pos = (y + a_ofs.y) * block_width + x + a_ofs.x;
6868
uint32_t b_pos = (y + b_ofs.y) * block_width + x + b_ofs.x;
6969

70-
uint8_t a = rec_data[a_pos];
71-
uint8_t b = rec_data[b_pos];
72-
uint8_t c = rec_data[c_pos];
73-
uint8_t orig = orig_data[c_pos];
70+
kvz_pixel a = rec_data[a_pos];
71+
kvz_pixel b = rec_data[b_pos];
72+
kvz_pixel c = rec_data[c_pos];
73+
kvz_pixel orig = orig_data[c_pos];
7474

7575
int32_t eo_cat = sao_calc_eo_cat(a, b, c);
7676
int32_t offset = offsets[eo_cat];

‎src/yuv_io.c

+34-15
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,43 @@ static int read_and_fill_frame_data(FILE *file,
5757
unsigned width, unsigned height, unsigned bytes_per_sample,
5858
unsigned array_width, kvz_pixel *data)
5959
{
60-
kvz_pixel* p = data;
61-
kvz_pixel* end = data + array_width * height;
62-
kvz_pixel fill_char;
63-
unsigned i;
6460

65-
while (p < end) {
66-
// Read the beginning of the line from input.
67-
if (width != fread(p, bytes_per_sample, width, file))
68-
return 0;
69-
70-
// Fill the rest with the last pixel value.
71-
fill_char = p[width - 1];
61+
unsigned i;
62+
// Handle separately the case where we use KVZ_BIT_DEPTH 10+ but the input is 8-bit.
63+
if (bytes_per_sample != sizeof(kvz_pixel)) {
64+
uint8_t* p = (uint8_t*)data;
65+
uint8_t* end = (uint8_t*)data + array_width * height;
66+
uint8_t fill_char;
67+
while (p < end) {
68+
// Read the beginning of the line from input.
69+
if (width != fread(p, bytes_per_sample, width, file)) return 0;
70+
// Fill the rest with the last pixel value.
71+
// Fill the rest with the last pixel value.
72+
fill_char = p[width - 1];
73+
74+
for (i = width; i < array_width; ++i) {
75+
p[i] = fill_char;
76+
}
7277

73-
for (i = width; i < array_width; ++i) {
74-
p[i] = fill_char;
78+
p += array_width;
7579
}
80+
}
81+
else {
82+
kvz_pixel* p = data;
83+
kvz_pixel* end = data + array_width * height;
84+
kvz_pixel fill_char;
85+
while (p < end) {
86+
// Read the beginning of the line from input.
87+
if (width != fread(p, bytes_per_sample, width, file)) return 0;
88+
// Fill the rest with the last pixel value.
89+
fill_char = p[width - 1];
90+
91+
for (i = width; i < array_width; ++i) {
92+
p[i] = fill_char;
93+
}
7694

77-
p += array_width;
95+
p += array_width;
96+
}
7897
}
7998
return 1;
8099
}
@@ -313,7 +332,7 @@ int yuv_io_seek(FILE* file, unsigned frames,
313332

314333
// Seek failed. Skip data by reading.
315334
error = 0;
316-
unsigned char* tmp[4096];
335+
unsigned char tmp[4096];
317336
size_t bytes_left = skip_bytes;
318337
while (bytes_left > 0 && !error) {
319338
const size_t skip = MIN(4096, bytes_left);

0 commit comments

Comments
 (0)
Please sign in to comment.