2014-06-05 07:48:59 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* This file is part of Kvazaar HEVC encoder.
|
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* Copyright (C) 2013-2015 Tampere University of Technology and others (see
|
2014-06-05 07:48:59 +00:00
|
|
|
* COPYING file).
|
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* 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.
|
2014-06-05 07:48:59 +00:00
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* 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.
|
2014-06-05 07:48:59 +00:00
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with Kvazaar. If not, see <http://www.gnu.org/licenses/>.
|
2014-06-05 07:48:59 +00:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-05 12:54:58 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2014-06-05 07:48:59 +00:00
|
|
|
|
2014-06-05 12:54:58 +00:00
|
|
|
#include "cu.h"
|
2014-06-16 06:17:22 +00:00
|
|
|
#include "threads.h"
|
2014-06-05 12:54:58 +00:00
|
|
|
|
2016-04-01 14:14:23 +00:00
|
|
|
|
2015-09-16 09:58:27 +00:00
|
|
|
/**
|
|
|
|
* \brief Number of PUs in a CU.
|
|
|
|
*
|
|
|
|
* Indexed by part_mode_t values.
|
|
|
|
*/
|
|
|
|
const uint8_t kvz_part_mode_num_parts[] = {
|
|
|
|
1, // 2Nx2N
|
|
|
|
2, // 2NxN
|
|
|
|
2, // Nx2N
|
|
|
|
4, // NxN
|
|
|
|
2, // 2NxnU
|
|
|
|
2, // 2NxnD
|
|
|
|
2, // nLx2N
|
|
|
|
2, // nRx2N
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief PU offsets.
|
|
|
|
*
|
|
|
|
* Indexed by [part mode][PU number][axis].
|
|
|
|
*
|
|
|
|
* Units are 1/4 of the width of the CU.
|
|
|
|
*/
|
|
|
|
const uint8_t kvz_part_mode_offsets[][4][2] = {
|
|
|
|
{ {0, 0} }, // 2Nx2N
|
|
|
|
{ {0, 0}, {0, 2} }, // 2NxN
|
|
|
|
{ {0, 0}, {2, 0} }, // Nx2N
|
|
|
|
{ {0, 0}, {2, 0}, {0, 2}, {2, 2} }, // NxN
|
|
|
|
{ {0, 0}, {0, 1} }, // 2NxnU
|
|
|
|
{ {0, 0}, {0, 3} }, // 2NxnD
|
|
|
|
{ {0, 0}, {1, 0} }, // nLx2N
|
|
|
|
{ {0, 0}, {3, 0} }, // nRx2N
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief PU sizes.
|
|
|
|
*
|
|
|
|
* Indexed by [part mode][PU number][axis].
|
|
|
|
*
|
|
|
|
* Units are 1/4 of the width of the CU.
|
|
|
|
*/
|
|
|
|
const uint8_t kvz_part_mode_sizes[][4][2] = {
|
|
|
|
{ {4, 4} }, // 2Nx2N
|
|
|
|
{ {4, 2}, {4, 2} }, // 2NxN
|
|
|
|
{ {2, 4}, {2, 4} }, // Nx2N
|
|
|
|
{ {2, 2}, {2, 2}, {2, 2}, {2, 2} }, // NxN
|
|
|
|
{ {4, 1}, {4, 3} }, // 2NxnU
|
|
|
|
{ {4, 3}, {4, 1} }, // 2NxnD
|
|
|
|
{ {1, 4}, {3, 4} }, // nLx2N
|
|
|
|
{ {3, 4}, {1, 4} }, // nRx2N
|
|
|
|
};
|
2014-06-05 12:54:58 +00:00
|
|
|
|
2016-04-06 15:03:00 +00:00
|
|
|
|
|
|
|
#define BLIT_COEFF_CASE(n) case n:\
|
|
|
|
for (y = 0; y < n; ++y) {\
|
|
|
|
memcpy(&dst[y*dst_stride], &orig[y*orig_stride], n * sizeof(coeff_t));\
|
|
|
|
}\
|
|
|
|
break;
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
void kvz_coefficients_blit(const coeff_t * const orig, coeff_t * const dst,
|
2014-06-05 12:54:58 +00:00
|
|
|
const unsigned width, const unsigned height,
|
|
|
|
const unsigned orig_stride, const unsigned dst_stride)
|
|
|
|
{
|
|
|
|
unsigned y;
|
2016-01-13 17:27:45 +00:00
|
|
|
|
|
|
|
int nxn_width = (width == height) ? width : 0;
|
|
|
|
switch (nxn_width) {
|
2016-04-06 15:03:00 +00:00
|
|
|
BLIT_COEFF_CASE(4)
|
|
|
|
BLIT_COEFF_CASE(8)
|
|
|
|
BLIT_COEFF_CASE(16)
|
|
|
|
BLIT_COEFF_CASE(32)
|
|
|
|
BLIT_COEFF_CASE(64)
|
2016-01-13 17:27:45 +00:00
|
|
|
default:
|
|
|
|
for (y = 0; y < height; ++y) {
|
|
|
|
memcpy(&dst[y*dst_stride], &orig[y*orig_stride], width * sizeof(coeff_t));
|
|
|
|
}
|
|
|
|
break;
|
2014-06-05 12:54:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
unsigned kvz_coefficients_calc_abs(const coeff_t *const buf, const int buf_stride,
|
2014-06-05 12:54:58 +00:00
|
|
|
const int width)
|
2014-06-05 07:48:59 +00:00
|
|
|
{
|
2014-06-05 12:54:58 +00:00
|
|
|
int sum = 0;
|
|
|
|
int y, x;
|
|
|
|
|
|
|
|
for (y = 0; y < width; ++y) {
|
|
|
|
for (x = 0; x < width; ++x) {
|
|
|
|
sum += abs(buf[x + y * buf_stride]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sum;
|
2014-06-16 06:17:22 +00:00
|
|
|
}
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
cu_array_t * kvz_cu_array_alloc(const int width_in_scu, const int height_in_scu) {
|
2014-06-16 06:17:22 +00:00
|
|
|
unsigned cu_array_size = height_in_scu * width_in_scu;
|
2015-03-04 10:52:49 +00:00
|
|
|
cu_array_t *cua;
|
|
|
|
cua = MALLOC(cu_array_t, 1);
|
2015-03-04 11:15:45 +00:00
|
|
|
cua->data = (cu_info_t*)malloc(sizeof(cu_info_t) * cu_array_size);
|
2014-06-16 06:17:22 +00:00
|
|
|
cua->refcount = 1;
|
2015-02-13 09:56:55 +00:00
|
|
|
FILL_ARRAY(cua->data, 0, cu_array_size);
|
2014-06-16 06:17:22 +00:00
|
|
|
return cua;
|
|
|
|
}
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
int kvz_cu_array_free(cu_array_t * const cua)
|
2014-06-16 06:17:22 +00:00
|
|
|
{
|
2014-06-16 08:42:28 +00:00
|
|
|
int32_t new_refcount;
|
|
|
|
if (!cua) return 1;
|
|
|
|
|
2015-11-13 20:46:32 +00:00
|
|
|
new_refcount = KVZ_ATOMIC_DEC(&(cua->refcount));
|
2014-06-16 06:17:22 +00:00
|
|
|
//Still we have some references, do nothing
|
|
|
|
if (new_refcount > 0) return 1;
|
|
|
|
|
|
|
|
FREE_POINTER(cua->data);
|
|
|
|
free(cua);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2015-09-16 09:58:27 +00:00
|
|
|
|