2014-06-05 12:08:31 +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 12:08:31 +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 12:08:31 +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 12:08:31 +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 12:08:31 +00:00
|
|
|
****************************************************************************/
|
|
|
|
|
2016-04-01 14:14:23 +00:00
|
|
|
#include "videoframe.h"
|
|
|
|
|
2014-06-05 12:08:31 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2016-04-01 14:14:23 +00:00
|
|
|
#include "image.h"
|
2014-06-05 12:08:31 +00:00
|
|
|
#include "sao.h"
|
2019-08-15 08:01:38 +00:00
|
|
|
#include "alf.h"
|
2016-04-01 14:14:23 +00:00
|
|
|
|
2014-06-05 12:08:31 +00:00
|
|
|
/**
|
|
|
|
* \brief Allocate new frame
|
|
|
|
* \param pic picture pointer
|
|
|
|
* \return picture pointer
|
|
|
|
*/
|
2016-08-25 13:05:46 +00:00
|
|
|
videoframe_t * kvz_videoframe_alloc(int32_t width,
|
|
|
|
int32_t height,
|
2020-12-02 16:19:49 +00:00
|
|
|
enum kvz_chroma_format chroma_format,
|
|
|
|
enum kvz_alf alf_type)
|
2016-08-25 13:05:46 +00:00
|
|
|
{
|
2017-07-27 13:37:02 +00:00
|
|
|
videoframe_t *frame = calloc(1, sizeof(videoframe_t));
|
2014-06-05 12:08:31 +00:00
|
|
|
if (!frame) return 0;
|
|
|
|
|
|
|
|
frame->width = width;
|
|
|
|
frame->height = height;
|
2017-07-27 13:37:02 +00:00
|
|
|
frame->width_in_lcu = CEILDIV(frame->width, LCU_WIDTH);
|
|
|
|
frame->height_in_lcu = CEILDIV(frame->height, LCU_WIDTH);
|
2014-06-05 12:08:31 +00:00
|
|
|
|
2015-03-04 14:32:38 +00:00
|
|
|
frame->sao_luma = MALLOC(sao_info_t, frame->width_in_lcu * frame->height_in_lcu);
|
2016-08-25 13:05:46 +00:00
|
|
|
if (chroma_format != KVZ_CSP_400) {
|
|
|
|
frame->sao_chroma = MALLOC(sao_info_t, frame->width_in_lcu * frame->height_in_lcu);
|
|
|
|
}
|
2014-06-05 12:08:31 +00:00
|
|
|
|
2020-12-02 16:19:49 +00:00
|
|
|
if (alf_type) {
|
|
|
|
frame->alf_info = MALLOC(alf_info_t, 1);
|
|
|
|
kvz_alf_create(frame, chroma_format);
|
|
|
|
}
|
|
|
|
|
2014-06-05 12:08:31 +00:00
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Free memory allocated to frame
|
|
|
|
* \param pic picture pointer
|
|
|
|
* \return 1 on success, 0 on failure
|
|
|
|
*/
|
2015-08-26 08:50:27 +00:00
|
|
|
int kvz_videoframe_free(videoframe_t * const frame)
|
2014-06-05 12:08:31 +00:00
|
|
|
{
|
2021-05-06 10:15:39 +00:00
|
|
|
if (frame->source_lmcs_mapped) {
|
2021-05-24 19:23:45 +00:00
|
|
|
if(frame->source != frame->source_lmcs) FREE_POINTER(frame->source_lmcs);
|
|
|
|
if (frame->rec != frame->rec_lmcs) FREE_POINTER(frame->rec_lmcs);
|
2021-05-06 10:15:39 +00:00
|
|
|
frame->source_lmcs_mapped = false;
|
2021-05-05 10:28:39 +00:00
|
|
|
}
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_image_free(frame->source);
|
2015-06-17 08:06:09 +00:00
|
|
|
frame->source = NULL;
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_image_free(frame->rec);
|
2015-06-17 08:06:09 +00:00
|
|
|
frame->rec = NULL;
|
2014-06-05 12:08:31 +00:00
|
|
|
|
2021-05-06 10:15:39 +00:00
|
|
|
frame->source_lmcs = NULL;
|
|
|
|
frame->rec_lmcs = NULL;
|
|
|
|
|
2017-07-27 13:37:02 +00:00
|
|
|
kvz_cu_array_free(&frame->cu_array);
|
2014-06-05 12:08:31 +00:00
|
|
|
|
|
|
|
FREE_POINTER(frame->sao_luma);
|
|
|
|
FREE_POINTER(frame->sao_chroma);
|
2019-10-22 14:29:12 +00:00
|
|
|
|
2020-12-02 16:19:49 +00:00
|
|
|
if (frame->alf_info)
|
|
|
|
{
|
|
|
|
kvz_alf_destroy(frame);
|
|
|
|
FREE_POINTER(frame->alf_info);
|
|
|
|
}
|
|
|
|
|
2014-06-05 12:08:31 +00:00
|
|
|
free(frame);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
void kvz_videoframe_set_poc(videoframe_t * const frame, const int32_t poc) {
|
2014-06-11 08:09:38 +00:00
|
|
|
frame->poc = poc;
|
|
|
|
}
|