mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-23 18:14:06 +00:00
Change kvz_cu_array_alloc to use pixel dimensions.
Changes function kvz_cu_array_alloc to take width and height parameters in pixels instead of SCUs.
This commit is contained in:
parent
b276a347c0
commit
2c85a00a55
39
src/cu.c
39
src/cu.c
|
@ -120,27 +120,38 @@ unsigned kvz_coefficients_calc_abs(const coeff_t *const buf, const int buf_strid
|
|||
return sum;
|
||||
}
|
||||
|
||||
cu_array_t * kvz_cu_array_alloc(const int width_in_scu, const int height_in_scu) {
|
||||
unsigned cu_array_size = height_in_scu * width_in_scu;
|
||||
cu_array_t *cua;
|
||||
cua = MALLOC(cu_array_t, 1);
|
||||
cua->data = (cu_info_t*)malloc(sizeof(cu_info_t) * cu_array_size);
|
||||
cua->width = width_in_scu << 3;
|
||||
cua->height = height_in_scu << 3;
|
||||
/**
|
||||
* \brief Allocate a CU array.
|
||||
*
|
||||
* \param width width of the array in luma pixels
|
||||
* \param height height of the array in luma pixels
|
||||
*/
|
||||
cu_array_t * kvz_cu_array_alloc(const int width, const int height) {
|
||||
cu_array_t *cua = MALLOC(cu_array_t, 1);
|
||||
|
||||
const int width_scu = (width + 7) >> 3;
|
||||
const int height_scu = (height + 7) >> 3;
|
||||
assert(width_scu * 8 >= width);
|
||||
assert(height_scu * 8 >= height);
|
||||
const unsigned cu_array_size = width_scu * height_scu;
|
||||
cua->data = calloc(cu_array_size, sizeof(cu_info_t));
|
||||
cua->width = width_scu << 3;
|
||||
cua->height = height_scu << 3;
|
||||
cua->refcount = 1;
|
||||
FILL_ARRAY(cua->data, 0, cu_array_size);
|
||||
|
||||
return cua;
|
||||
}
|
||||
|
||||
|
||||
int kvz_cu_array_free(cu_array_t * const cua)
|
||||
{
|
||||
int32_t new_refcount;
|
||||
if (!cua) return 1;
|
||||
|
||||
|
||||
new_refcount = KVZ_ATOMIC_DEC(&(cua->refcount));
|
||||
//Still we have some references, do nothing
|
||||
if (new_refcount > 0) return 1;
|
||||
|
||||
|
||||
FREE_POINTER(cua->data);
|
||||
free(cua);
|
||||
|
||||
|
@ -175,6 +186,14 @@ void kvz_cu_array_copy(cu_array_t* dst, int dst_x, int dst_y,
|
|||
// Number of bytes to copy per row.
|
||||
const size_t row_size = sizeof(cu_info_t) * (width >> 3);
|
||||
|
||||
width = MIN(width, MIN(src->width - src_x, dst->width - dst_x));
|
||||
height = MIN(height, MIN(src->height - src_y, dst->height - dst_y));
|
||||
|
||||
assert(src_x + width <= src->width);
|
||||
assert(src_y + height <= src->height);
|
||||
assert(dst_x + width <= dst->width);
|
||||
assert(dst_y + height <= dst->height);
|
||||
|
||||
for (int i = 0; i < (height >> 3); ++i) {
|
||||
memcpy(dst_ptr, src_ptr, row_size);
|
||||
src_ptr += src_stride;
|
||||
|
|
2
src/cu.h
2
src/cu.h
|
@ -184,7 +184,7 @@ typedef struct {
|
|||
int32_t refcount; //!< \brief number of references to this cu_array
|
||||
} cu_array_t;
|
||||
|
||||
cu_array_t * kvz_cu_array_alloc(int width_in_scu, int height_in_scu);
|
||||
cu_array_t * kvz_cu_array_alloc(int width, int height);
|
||||
int kvz_cu_array_free(cu_array_t *cua);
|
||||
void kvz_cu_array_copy(cu_array_t* dst, int dst_x, int dst_y,
|
||||
const cu_array_t* src, int src_x, int src_y,
|
||||
|
|
|
@ -956,10 +956,9 @@ void kvz_encoder_next_frame(encoder_state_t *state)
|
|||
state->tile->frame->rec = kvz_image_alloc(state->tile->frame->width, state->tile->frame->height);
|
||||
assert(state->tile->frame->rec);
|
||||
{
|
||||
// Allocate height_in_scu x width_in_scu x sizeof(CU_info)
|
||||
unsigned height_in_scu = state->tile->frame->height_in_lcu << MAX_DEPTH;
|
||||
unsigned width_in_scu = state->tile->frame->width_in_lcu << MAX_DEPTH;
|
||||
state->tile->frame->cu_array = kvz_cu_array_alloc(width_in_scu, height_in_scu);
|
||||
unsigned width = state->tile->frame->width_in_lcu * LCU_WIDTH;
|
||||
unsigned height = state->tile->frame->height_in_lcu * LCU_WIDTH;
|
||||
state->tile->frame->cu_array = kvz_cu_array_alloc(width, height);
|
||||
}
|
||||
kvz_videoframe_set_poc(state->tile->frame, state->global->poc);
|
||||
kvz_image_list_copy_contents(state->global->ref, prev_state->global->ref);
|
||||
|
|
|
@ -46,10 +46,9 @@ videoframe_t *kvz_videoframe_alloc(const int32_t width, const int32_t height, co
|
|||
if (frame->height_in_lcu * LCU_WIDTH < frame->height) frame->height_in_lcu++;
|
||||
|
||||
{
|
||||
// Allocate height_in_scu x width_in_scu x sizeof(CU_info)
|
||||
unsigned height_in_scu = frame->height_in_lcu << MAX_DEPTH;
|
||||
unsigned width_in_scu = frame->width_in_lcu << MAX_DEPTH;
|
||||
frame->cu_array = kvz_cu_array_alloc(width_in_scu, height_in_scu);
|
||||
unsigned cu_array_width = frame->width_in_lcu * LCU_WIDTH;
|
||||
unsigned cu_array_height = frame->height_in_lcu * LCU_WIDTH;
|
||||
frame->cu_array = kvz_cu_array_alloc(cu_array_width, cu_array_height);
|
||||
}
|
||||
|
||||
frame->coeff_y = NULL; frame->coeff_u = NULL; frame->coeff_v = NULL;
|
||||
|
|
Loading…
Reference in a new issue