2014-06-05 12:08:31 +00:00
|
|
|
/*****************************************************************************
|
2021-11-23 06:46:06 +00:00
|
|
|
* This file is part of uvg266 VVC encoder.
|
2014-06-05 12:08:31 +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 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
|
|
|
|
*/
|
2022-04-28 11:18:09 +00:00
|
|
|
videoframe_t * uvg_videoframe_alloc(int32_t width,
|
2016-08-25 13:05:46 +00:00
|
|
|
int32_t height,
|
2022-04-28 11:18:09 +00:00
|
|
|
enum uvg_chroma_format chroma_format,
|
|
|
|
enum uvg_alf alf_type, bool cclm)
|
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);
|
2022-04-28 11:18:09 +00:00
|
|
|
if (chroma_format != UVG_CSP_400) {
|
2016-08-25 13:05:46 +00:00
|
|
|
frame->sao_chroma = MALLOC(sao_info_t, frame->width_in_lcu * frame->height_in_lcu);
|
2021-11-19 09:54:51 +00:00
|
|
|
if (cclm) {
|
2022-04-28 11:18:09 +00:00
|
|
|
assert(chroma_format == UVG_CSP_420);
|
|
|
|
frame->cclm_luma_rec = MALLOC(uvg_pixel, (((width + 7) & ~7) + FRAME_PADDING_LUMA) * (((height + 7) & ~7) + FRAME_PADDING_LUMA) / 4);
|
|
|
|
frame->cclm_luma_rec_top_line = MALLOC(uvg_pixel, (((width + 7) & ~7) + FRAME_PADDING_LUMA) / 2 * CEILDIV(height, 64));
|
2021-11-19 09:54:51 +00:00
|
|
|
}
|
2016-08-25 13:05:46 +00:00
|
|
|
}
|
2021-11-19 09:54:51 +00:00
|
|
|
|
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
|
|
|
|
*/
|
2022-04-28 11:18:09 +00:00
|
|
|
int uvg_videoframe_free(videoframe_t * const frame)
|
2014-06-05 12:08:31 +00:00
|
|
|
{
|
2021-05-25 11:27:21 +00:00
|
|
|
if (frame->source_lmcs_mapped) {
|
2022-04-28 11:18:09 +00:00
|
|
|
uvg_image_free(frame->source_lmcs);
|
|
|
|
uvg_image_free(frame->rec_lmcs);
|
2021-05-06 10:15:39 +00:00
|
|
|
frame->source_lmcs_mapped = false;
|
2021-05-05 10:28:39 +00:00
|
|
|
}
|
2021-11-19 09:54:51 +00:00
|
|
|
if(frame->cclm_luma_rec) {
|
|
|
|
FREE_POINTER(frame->cclm_luma_rec);
|
|
|
|
}
|
2021-11-24 06:46:08 +00:00
|
|
|
if(frame->cclm_luma_rec_top_line) {
|
|
|
|
FREE_POINTER(frame->cclm_luma_rec_top_line);
|
|
|
|
}
|
2021-05-05 10:28:39 +00:00
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
uvg_image_free(frame->source);
|
2015-06-17 08:06:09 +00:00
|
|
|
frame->source = NULL;
|
2022-04-28 11:18:09 +00:00
|
|
|
uvg_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;
|
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
uvg_cu_array_free(&frame->cu_array);
|
2022-06-08 07:26:56 +00:00
|
|
|
uvg_cu_array_free(&frame->chroma_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
|
|
|
|
2014-06-05 12:08:31 +00:00
|
|
|
free(frame);
|
|
|
|
|
2023-06-22 18:44:49 +00:00
|
|
|
|
|
|
|
|
2014-06-05 12:08:31 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
void uvg_videoframe_set_poc(videoframe_t * const frame, const int32_t poc) {
|
2014-06-11 08:09:38 +00:00
|
|
|
frame->poc = poc;
|
|
|
|
}
|