2014-06-05 07:48:59 +00:00
|
|
|
/*****************************************************************************
|
2021-11-23 06:46:06 +00:00
|
|
|
* This file is part of uvg266 VVC encoder.
|
2014-06-05 07:48:59 +00:00
|
|
|
*
|
2021-10-07 08:32:59 +00:00
|
|
|
* Copyright (c) 2021, Tampere University, ITU/ISO/IEC, project contributors
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
* are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
* other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
|
|
|
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
* INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
|
2014-06-05 07:48:59 +00:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-05 12:54:58 +00:00
|
|
|
#include "imagelist.h"
|
2014-06-05 07:48:59 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2016-04-01 14:14:23 +00:00
|
|
|
|
|
|
|
#include "image.h"
|
|
|
|
#include "threads.h"
|
2014-06-05 07:48:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-06-05 12:54:58 +00:00
|
|
|
* \brief Allocate memory for image_list
|
2014-06-05 07:48:59 +00:00
|
|
|
* \param size initial array size
|
2014-06-05 12:54:58 +00:00
|
|
|
* \return image_list pointer, NULL on failure
|
2014-06-05 07:48:59 +00:00
|
|
|
*/
|
2022-04-28 11:18:09 +00:00
|
|
|
image_list_t * uvg_image_list_alloc(int size)
|
2014-06-05 07:48:59 +00:00
|
|
|
{
|
2015-03-04 14:13:57 +00:00
|
|
|
image_list_t *list = (image_list_t *)malloc(sizeof(image_list_t));
|
2016-06-22 03:51:37 +00:00
|
|
|
list->size = size;
|
2022-04-28 11:18:09 +00:00
|
|
|
list->images = malloc(sizeof(uvg_picture*) * size);
|
2017-08-21 13:34:57 +00:00
|
|
|
list->cu_arrays = malloc(sizeof(cu_array_t*) * size);
|
|
|
|
list->pocs = malloc(sizeof(int32_t) * size);
|
|
|
|
list->ref_LXs = malloc(sizeof(*list->ref_LXs) * size);
|
2014-06-05 07:48:59 +00:00
|
|
|
list->used_size = 0;
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-05 12:54:58 +00:00
|
|
|
* \brief Resize image_list array
|
|
|
|
* \param list image_list pointer
|
2014-06-05 07:48:59 +00:00
|
|
|
* \param size new array size
|
|
|
|
* \return 1 on success, 0 on failure
|
|
|
|
*/
|
2022-04-28 11:18:09 +00:00
|
|
|
int uvg_image_list_resize(image_list_t *list, unsigned size)
|
2014-06-05 07:48:59 +00:00
|
|
|
{
|
2022-04-28 11:18:09 +00:00
|
|
|
list->images = (uvg_picture**)realloc(list->images, sizeof(uvg_picture*) * size);
|
2015-06-17 07:08:45 +00:00
|
|
|
list->cu_arrays = (cu_array_t**)realloc(list->cu_arrays, sizeof(cu_array_t*) * size);
|
2015-07-06 08:58:05 +00:00
|
|
|
list->pocs = realloc(list->pocs, sizeof(int32_t) * size);
|
2017-08-21 13:34:57 +00:00
|
|
|
list->ref_LXs = realloc(list->ref_LXs, sizeof(*list->ref_LXs) * size);
|
2015-06-17 07:08:45 +00:00
|
|
|
list->size = size;
|
|
|
|
return size == 0 || (list->images && list->cu_arrays && list->pocs);
|
2014-06-05 07:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Free memory allocated to the picture_list
|
2014-06-05 12:54:58 +00:00
|
|
|
* \param list image_list pointer
|
2014-06-05 07:48:59 +00:00
|
|
|
* \return 1 on success, 0 on failure
|
|
|
|
*/
|
2022-04-28 11:18:09 +00:00
|
|
|
int uvg_image_list_destroy(image_list_t *list)
|
2014-06-05 07:48:59 +00:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
if (list->used_size > 0) {
|
|
|
|
for (i = 0; i < list->used_size; ++i) {
|
2022-04-28 11:18:09 +00:00
|
|
|
uvg_image_free(list->images[i]);
|
2014-06-05 12:54:58 +00:00
|
|
|
list->images[i] = NULL;
|
2022-04-28 11:18:09 +00:00
|
|
|
uvg_cu_array_free(&list->cu_arrays[i]);
|
2014-06-11 08:08:16 +00:00
|
|
|
list->cu_arrays[i] = NULL;
|
2015-06-17 06:56:53 +00:00
|
|
|
list->pocs[i] = 0;
|
2017-08-21 13:34:57 +00:00
|
|
|
for (int j = 0; j < 16; j++) {
|
|
|
|
list->ref_LXs[i][0][j] = 0;
|
|
|
|
list->ref_LXs[i][1][j] = 0;
|
|
|
|
}
|
2014-06-05 07:48:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list->size > 0) {
|
2014-06-05 12:54:58 +00:00
|
|
|
free(list->images);
|
|
|
|
free(list->cu_arrays);
|
2015-06-17 06:56:53 +00:00
|
|
|
free(list->pocs);
|
2017-08-21 13:34:57 +00:00
|
|
|
free(list->ref_LXs);
|
2014-06-05 07:48:59 +00:00
|
|
|
}
|
2015-06-17 06:56:53 +00:00
|
|
|
list->images = NULL;
|
|
|
|
list->cu_arrays = NULL;
|
|
|
|
list->pocs = NULL;
|
2017-08-21 13:34:57 +00:00
|
|
|
list->ref_LXs = NULL;
|
2014-06-05 07:48:59 +00:00
|
|
|
free(list);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Add picture to the front of the picturelist
|
|
|
|
* \param pic picture pointer to add
|
|
|
|
* \param picture_list list to use
|
|
|
|
* \return 1 on success
|
|
|
|
*/
|
2022-04-28 11:18:09 +00:00
|
|
|
int uvg_image_list_add(image_list_t *list, uvg_picture *im, cu_array_t *cua, int32_t poc, uint8_t ref_LX[2][16])
|
2014-06-05 07:48:59 +00:00
|
|
|
{
|
|
|
|
int i = 0;
|
2022-04-28 11:18:09 +00:00
|
|
|
if (UVG_ATOMIC_INC(&(im->refcount)) == 1) {
|
2014-06-05 07:48:59 +00:00
|
|
|
fprintf(stderr, "Tried to add an unreferenced picture. This is a bug!\n");
|
|
|
|
assert(0); //Stop for debugging
|
|
|
|
return 0;
|
|
|
|
}
|
2014-06-16 06:17:22 +00:00
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
if (UVG_ATOMIC_INC(&(cua->refcount)) == 1) {
|
2014-06-16 06:17:22 +00:00
|
|
|
fprintf(stderr, "Tried to add an unreferenced cu_array. This is a bug!\n");
|
|
|
|
assert(0); //Stop for debugging
|
|
|
|
return 0;
|
|
|
|
}
|
2014-06-05 07:48:59 +00:00
|
|
|
|
|
|
|
if (list->size == list->used_size) {
|
2016-06-22 03:51:37 +00:00
|
|
|
unsigned new_size = MAX(list->size + 1, list->size * 2);
|
2022-04-28 11:18:09 +00:00
|
|
|
if (!uvg_image_list_resize(list, new_size)) return 0;
|
2014-06-05 07:48:59 +00:00
|
|
|
}
|
2016-12-15 10:13:14 +00:00
|
|
|
|
2014-06-05 07:48:59 +00:00
|
|
|
for (i = list->used_size; i > 0; i--) {
|
2014-06-05 12:54:58 +00:00
|
|
|
list->images[i] = list->images[i - 1];
|
|
|
|
list->cu_arrays[i] = list->cu_arrays[i - 1];
|
2015-06-17 06:56:53 +00:00
|
|
|
list->pocs[i] = list->pocs[i - 1];
|
2017-08-21 13:34:57 +00:00
|
|
|
for (int j = 0; j < 16; j++) {
|
|
|
|
list->ref_LXs[i][0][j] = list->ref_LXs[i - 1][0][j];
|
|
|
|
list->ref_LXs[i][1][j] = list->ref_LXs[i - 1][1][j];
|
|
|
|
}
|
2014-06-05 07:48:59 +00:00
|
|
|
}
|
|
|
|
|
2014-06-05 12:54:58 +00:00
|
|
|
list->images[0] = im;
|
2014-06-16 06:17:22 +00:00
|
|
|
list->cu_arrays[0] = cua;
|
2015-06-17 06:56:53 +00:00
|
|
|
list->pocs[0] = poc;
|
2017-08-21 13:34:57 +00:00
|
|
|
for (int j = 0; j < 16; j++) {
|
|
|
|
list->ref_LXs[0][0][j] = ref_LX[0][j];
|
|
|
|
list->ref_LXs[0][1][j] = ref_LX[1][j];
|
|
|
|
}
|
2014-06-16 06:17:22 +00:00
|
|
|
|
2014-06-05 07:48:59 +00:00
|
|
|
list->used_size++;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Remove picture from picturelist
|
|
|
|
* \param list list to use
|
|
|
|
* \param n index to remove
|
|
|
|
* \return 1 on success
|
|
|
|
*/
|
2022-04-28 11:18:09 +00:00
|
|
|
int uvg_image_list_rem(image_list_t * const list, const unsigned n)
|
2014-06-05 07:48:59 +00:00
|
|
|
{
|
|
|
|
// Must be within list boundaries
|
|
|
|
if (n >= list->used_size)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
uvg_image_free(list->images[n]);
|
2015-06-17 08:06:09 +00:00
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
uvg_cu_array_free(&list->cu_arrays[n]);
|
2014-06-05 07:48:59 +00:00
|
|
|
|
|
|
|
// The last item is easy to remove
|
|
|
|
if (n == list->used_size - 1) {
|
2014-06-05 12:54:58 +00:00
|
|
|
list->images[n] = NULL;
|
2014-06-11 08:08:16 +00:00
|
|
|
list->cu_arrays[n] = NULL;
|
2015-06-17 06:56:53 +00:00
|
|
|
list->pocs[n] = 0;
|
2017-08-21 13:34:57 +00:00
|
|
|
for (int j = 0; j < 16; j++) {
|
|
|
|
list->ref_LXs[n][0][j] = 0;
|
|
|
|
list->ref_LXs[n][1][j] = 0;
|
|
|
|
}
|
2014-06-05 07:48:59 +00:00
|
|
|
list->used_size--;
|
|
|
|
} else {
|
2022-06-17 08:27:19 +00:00
|
|
|
uint32_t i = n;
|
2014-06-05 07:48:59 +00:00
|
|
|
// Shift all following pics one backward in the list
|
|
|
|
for (i = n; i < list->used_size - 1; ++i) {
|
2014-06-05 12:54:58 +00:00
|
|
|
list->images[i] = list->images[i + 1];
|
2014-06-11 08:08:16 +00:00
|
|
|
list->cu_arrays[i] = list->cu_arrays[i + 1];
|
2015-06-17 06:56:53 +00:00
|
|
|
list->pocs[i] = list->pocs[i + 1];
|
2022-06-17 08:27:19 +00:00
|
|
|
for (uint32_t j = 0; j < 16; j++) {
|
2017-08-21 13:34:57 +00:00
|
|
|
list->ref_LXs[i][0][j] = list->ref_LXs[i + 1][0][j];
|
|
|
|
list->ref_LXs[i][1][j] = list->ref_LXs[i + 1][1][j];
|
|
|
|
}
|
2014-06-05 07:48:59 +00:00
|
|
|
}
|
2014-06-05 12:54:58 +00:00
|
|
|
list->images[list->used_size - 1] = NULL;
|
2014-06-11 08:08:16 +00:00
|
|
|
list->cu_arrays[list->used_size - 1] = NULL;
|
2015-06-17 06:56:53 +00:00
|
|
|
list->pocs[list->used_size - 1] = 0;
|
2017-08-21 13:34:57 +00:00
|
|
|
for (int j = 0; j < 16; j++) {
|
|
|
|
list->ref_LXs[list->used_size - 1][0][j] = 0;
|
|
|
|
list->ref_LXs[list->used_size - 1][1][j] = 0;
|
|
|
|
}
|
2014-06-05 07:48:59 +00:00
|
|
|
list->used_size--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2014-06-16 06:18:26 +00:00
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
int uvg_image_list_copy_contents(image_list_t *target, image_list_t *source) {
|
2014-06-16 06:18:26 +00:00
|
|
|
int i;
|
|
|
|
while (target->used_size > 0) {
|
2022-04-28 11:18:09 +00:00
|
|
|
uvg_image_list_rem(target, 0);
|
2014-06-16 06:18:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = source->used_size - 1; i >= 0; --i) {
|
2022-04-28 11:18:09 +00:00
|
|
|
uvg_image_list_add(target, source->images[i], source->cu_arrays[i], source->pocs[i], source->ref_LXs[i]);
|
2014-06-16 06:18:26 +00:00
|
|
|
}
|
|
|
|
return 1;
|
2015-06-17 06:56:53 +00:00
|
|
|
}
|