mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-24 02:24:07 +00:00
Move picture_list to its own module
This commit is contained in:
parent
7372f9244d
commit
821b71910b
|
@ -53,7 +53,7 @@ CC = gcc
|
|||
CCFLAGS = $(DFLAGS) -I. -Wall -Wtype-limits
|
||||
LDFLAGS += -lm
|
||||
LD = gcc -pthread -lrt
|
||||
OBJS = interface_main.o encmain.o bitstream.o cabac.o config.o context.o encoder.o encoderstate.o filter.o inter.o intra.o nal.o picture.o rdo.o sao.o scalinglist.o search.o strategyselector.o tables.o threadqueue.o transform.o encoder_state-bitstream.o encoder_state-ctors_dtors.o encoder_state-geometry.o
|
||||
OBJS = interface_main.o encmain.o bitstream.o cabac.o config.o context.o encoder.o encoderstate.o filter.o inter.o intra.o nal.o picture.o picturelist.o rdo.o sao.o scalinglist.o search.o strategyselector.o tables.o threadqueue.o transform.o encoder_state-bitstream.o encoder_state-ctors_dtors.o encoder_state-geometry.o
|
||||
PROG = ./kvazaar
|
||||
PROGS = $(PROG)
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "tables.h"
|
||||
#include "scalinglist.h"
|
||||
#include "threadqueue.h"
|
||||
#include "picturelist.h"
|
||||
|
||||
|
||||
// Submodules
|
||||
|
|
140
src/picture.c
140
src/picture.c
|
@ -100,146 +100,6 @@ void picture_blit_coeffs(const coefficient * const orig, coefficient * const dst
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Allocate memory for picture_list
|
||||
* \param size initial array size
|
||||
* \return picture_list pointer, NULL on failure
|
||||
*/
|
||||
picture_list * picture_list_init(int size)
|
||||
{
|
||||
picture_list *list = (picture_list *)malloc(sizeof(picture_list));
|
||||
list->size = size;
|
||||
if (size > 0) {
|
||||
list->pics = (picture**)malloc(sizeof(picture*) * size);
|
||||
}
|
||||
|
||||
list->used_size = 0;
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Resize picture_list array
|
||||
* \param list picture_list pointer
|
||||
* \param size new array size
|
||||
* \return 1 on success, 0 on failure
|
||||
*/
|
||||
int picture_list_resize(picture_list *list, unsigned size)
|
||||
{
|
||||
unsigned int i;
|
||||
picture** old_pics = NULL;
|
||||
|
||||
// No need to do anything when resizing to same size
|
||||
if (size == list->size) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Save the old list
|
||||
if (list->used_size > 0) {
|
||||
old_pics = list->pics;
|
||||
}
|
||||
|
||||
// allocate space for the new list
|
||||
list->pics = (picture**)malloc(sizeof(picture*)*size);
|
||||
|
||||
// Copy everything from the old list to the new if needed.
|
||||
if (old_pics != NULL) {
|
||||
for (i = 0; i < list->used_size; ++i) {
|
||||
list->pics[i] = old_pics[i];
|
||||
}
|
||||
|
||||
free(old_pics);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Free memory allocated to the picture_list
|
||||
* \param list picture_list pointer
|
||||
* \return 1 on success, 0 on failure
|
||||
*/
|
||||
int picture_list_destroy(picture_list *list)
|
||||
{
|
||||
unsigned int i;
|
||||
if (list->used_size > 0) {
|
||||
for (i = 0; i < list->used_size; ++i) {
|
||||
picture_free(list->pics[i]);
|
||||
list->pics[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (list->size > 0) {
|
||||
free(list->pics);
|
||||
}
|
||||
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
|
||||
*/
|
||||
int picture_list_add(picture_list *list,picture* pic)
|
||||
{
|
||||
int i = 0;
|
||||
if (ATOMIC_INC(&(pic->refcount)) == 1) {
|
||||
fprintf(stderr, "Tried to add an unreferenced picture. This is a bug!\n");
|
||||
assert(0); //Stop for debugging
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (list->size == list->used_size) {
|
||||
if (!picture_list_resize(list, list->size*2)) return 0;
|
||||
}
|
||||
|
||||
for (i = list->used_size; i > 0; i--) {
|
||||
list->pics[i] = list->pics[i - 1];
|
||||
}
|
||||
|
||||
list->pics[0] = pic;
|
||||
list->used_size++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Add picture to picturelist
|
||||
* \param pic picture pointer to add
|
||||
* \param picture_list list to use
|
||||
* \return 1 on success
|
||||
*/
|
||||
int picture_list_rem(picture_list * const list, const unsigned n)
|
||||
{
|
||||
// Must be within list boundaries
|
||||
if (n >= list->used_size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!picture_free(list->pics[n])) {
|
||||
fprintf(stderr, "Could not free picture!\n");
|
||||
assert(0); //Stop here
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The last item is easy to remove
|
||||
if (n == list->used_size - 1) {
|
||||
list->pics[n] = NULL;
|
||||
list->used_size--;
|
||||
} else {
|
||||
int i = n;
|
||||
// Shift all following pics one backward in the list
|
||||
for (i = n; i < list->used_size - 1; ++i) {
|
||||
list->pics[i] = list->pics[i + 1];
|
||||
}
|
||||
list->pics[list->used_size - 1] = NULL;
|
||||
list->used_size--;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Allocate new picture
|
||||
|
|
|
@ -103,7 +103,7 @@ typedef struct
|
|||
/**
|
||||
* \brief Struct which contains all picture data
|
||||
*/
|
||||
typedef struct picture_struct
|
||||
typedef struct picture
|
||||
{
|
||||
pixel* y_data; //!< \brief Pointer to luma pixel array.
|
||||
pixel* u_data; //!< \brief Pointer to chroma U pixel array.
|
||||
|
@ -131,17 +131,6 @@ typedef struct picture_struct
|
|||
int32_t poc; //!< \brief Picture order count
|
||||
} picture;
|
||||
|
||||
/**
|
||||
* \brief Struct which contains array of picture structs
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
picture** pics; //!< \brief Pointer to array of picture pointers.
|
||||
uint32_t size; //!< \brief Array size.
|
||||
uint32_t used_size;
|
||||
} picture_list;
|
||||
|
||||
|
||||
|
||||
#define SUB_SCU_BIT_MASK (64 - 1)
|
||||
#define SUB_SCU(xy) (xy & SUB_SCU_BIT_MASK)
|
||||
|
@ -252,11 +241,6 @@ void picture_blit_coeffs(const coefficient *orig, coefficient *dst,
|
|||
unsigned width, unsigned height,
|
||||
unsigned orig_stride, unsigned dst_stride);
|
||||
|
||||
picture_list * picture_list_init(int size);
|
||||
int picture_list_resize(picture_list *list, unsigned size);
|
||||
int picture_list_destroy(picture_list *list);
|
||||
int picture_list_add(picture_list *list, picture *pic);
|
||||
int picture_list_rem(picture_list *list, unsigned n);
|
||||
|
||||
typedef unsigned (*cost_16bit_nxn_func)(const pixel *block1, const pixel *block2);
|
||||
|
||||
|
|
176
src/picturelist.c
Normal file
176
src/picturelist.c
Normal file
|
@ -0,0 +1,176 @@
|
|||
/*****************************************************************************
|
||||
* This file is part of Kvazaar HEVC encoder.
|
||||
*
|
||||
* Copyright (C) 2013-2014 Tampere University of Technology and others (see
|
||||
* COPYING file).
|
||||
*
|
||||
* Kvazaar is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Kvazaar. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* \file
|
||||
*/
|
||||
|
||||
#include "threads.h"
|
||||
#include "picturelist.h"
|
||||
#include "strategyselector.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "sao.h"
|
||||
|
||||
|
||||
/**
|
||||
* \brief Allocate memory for picture_list
|
||||
* \param size initial array size
|
||||
* \return picture_list pointer, NULL on failure
|
||||
*/
|
||||
picture_list * picture_list_init(int size)
|
||||
{
|
||||
picture_list *list = (picture_list *)malloc(sizeof(picture_list));
|
||||
list->size = size;
|
||||
if (size > 0) {
|
||||
list->pics = (picture**)malloc(sizeof(picture*) * size);
|
||||
}
|
||||
|
||||
list->used_size = 0;
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Resize picture_list array
|
||||
* \param list picture_list pointer
|
||||
* \param size new array size
|
||||
* \return 1 on success, 0 on failure
|
||||
*/
|
||||
int picture_list_resize(picture_list *list, unsigned size)
|
||||
{
|
||||
unsigned int i;
|
||||
picture** old_pics = NULL;
|
||||
|
||||
// No need to do anything when resizing to same size
|
||||
if (size == list->size) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Save the old list
|
||||
if (list->used_size > 0) {
|
||||
old_pics = list->pics;
|
||||
}
|
||||
|
||||
// allocate space for the new list
|
||||
list->pics = (picture**)malloc(sizeof(picture*)*size);
|
||||
|
||||
// Copy everything from the old list to the new if needed.
|
||||
if (old_pics != NULL) {
|
||||
for (i = 0; i < list->used_size; ++i) {
|
||||
list->pics[i] = old_pics[i];
|
||||
}
|
||||
|
||||
free(old_pics);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Free memory allocated to the picture_list
|
||||
* \param list picture_list pointer
|
||||
* \return 1 on success, 0 on failure
|
||||
*/
|
||||
int picture_list_destroy(picture_list *list)
|
||||
{
|
||||
unsigned int i;
|
||||
if (list->used_size > 0) {
|
||||
for (i = 0; i < list->used_size; ++i) {
|
||||
picture_free(list->pics[i]);
|
||||
list->pics[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (list->size > 0) {
|
||||
free(list->pics);
|
||||
}
|
||||
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
|
||||
*/
|
||||
int picture_list_add(picture_list *list, picture* pic)
|
||||
{
|
||||
int i = 0;
|
||||
if (ATOMIC_INC(&(pic->refcount)) == 1) {
|
||||
fprintf(stderr, "Tried to add an unreferenced picture. This is a bug!\n");
|
||||
assert(0); //Stop for debugging
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (list->size == list->used_size) {
|
||||
if (!picture_list_resize(list, list->size*2)) return 0;
|
||||
}
|
||||
|
||||
for (i = list->used_size; i > 0; i--) {
|
||||
list->pics[i] = list->pics[i - 1];
|
||||
}
|
||||
|
||||
list->pics[0] = pic;
|
||||
list->used_size++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Remove picture from picturelist
|
||||
* \param list list to use
|
||||
* \param n index to remove
|
||||
* \return 1 on success
|
||||
*/
|
||||
int picture_list_rem(picture_list * const list, const unsigned n)
|
||||
{
|
||||
// Must be within list boundaries
|
||||
if (n >= list->used_size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!picture_free(list->pics[n])) {
|
||||
fprintf(stderr, "Could not free picture!\n");
|
||||
assert(0); //Stop here
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The last item is easy to remove
|
||||
if (n == list->used_size - 1) {
|
||||
list->pics[n] = NULL;
|
||||
list->used_size--;
|
||||
} else {
|
||||
int i = n;
|
||||
// Shift all following pics one backward in the list
|
||||
for (i = n; i < list->used_size - 1; ++i) {
|
||||
list->pics[i] = list->pics[i + 1];
|
||||
}
|
||||
list->pics[list->used_size - 1] = NULL;
|
||||
list->used_size--;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
45
src/picturelist.h
Normal file
45
src/picturelist.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
#ifndef PICTURE_LIST_H_
|
||||
#define PICTURE_LIST_H_
|
||||
/*****************************************************************************
|
||||
* This file is part of Kvazaar HEVC encoder.
|
||||
*
|
||||
* Copyright (C) 2013-2014 Tampere University of Technology and others (see
|
||||
* COPYING file).
|
||||
*
|
||||
* Kvazaar is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Kvazaar. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* \file
|
||||
* \brief Coding Unit (CU) and picture data related functions.
|
||||
*/
|
||||
|
||||
#include "picture.h"
|
||||
|
||||
/**
|
||||
* \brief Struct which contains array of picture structs
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
struct picture** pics; //!< \brief Pointer to array of picture pointers.
|
||||
uint32_t size; //!< \brief Array size.
|
||||
uint32_t used_size;
|
||||
} picture_list;
|
||||
|
||||
picture_list * picture_list_init(int size);
|
||||
int picture_list_resize(picture_list *list, unsigned size);
|
||||
int picture_list_destroy(picture_list *list);
|
||||
int picture_list_add(picture_list *list, picture *pic);
|
||||
int picture_list_rem(picture_list *list, unsigned n);
|
||||
|
||||
#endif //PICTURE_LIST_H_
|
Loading…
Reference in a new issue