📄 rwmh.c
字号:
image_mean = 0;
}
else
if (statistics != NULL)
statistics->motion_vector_bits = 0;
if (QccSPIHTEncode(current_frame,
NULL,
output_buffer,
num_levels,
wavelet,
NULL,
start_position + target_bit_cnt,
1,
NULL))
{
QccErrorAddMessage("(QccVIDRWMHEncodeFrame): Error calling QccSPIHTEncode()");
goto Error;
}
if (statistics != NULL)
statistics->intraframe_bits =
output_buffer->bit_cnt - start_position - statistics->motion_vector_bits;
if (QccBitBufferFlush(output_buffer))
{
QccErrorAddMessage("(QccVIDRWMHkEncodeFrame): Error calling QccBitBufferFlush()");
goto Error;
}
if (QccVIDRWMHDecodeFrame(reconstructed_frame,
compensated_frame_rdwt,
reference_frame_rdwt,
num_levels,
blocksize,
subpixel_accuracy,
filter1,
filter2,
filter3,
target_bit_cnt,
wavelet,
input_buffer,
read_motion_vectors,
motion_vector_horizontal,
motion_vector_vertical))
{
QccErrorAddMessage("(QccVIDRWMHEncodeFrame): Error calling QccVIDRWMHDecodeFrame()");
goto Error;
}
return_value = 0;
goto Return;
Error:
return_value = 1;
Return:
QccMatrixFree(compensated_frame, num_rows);
QccWAVWaveletRedundantDWT2DFree(compensated_frame_rdwt,
num_rows, num_levels);
return(return_value);
}
int QccVIDRWMHDecodeHeader(QccBitBuffer *input_buffer,
int *num_rows,
int *num_cols,
int *start_frame_num,
int *end_frame_num,
int *num_levels,
int *blocksize,
int *target_bit_cnt)
{
int val;
if (QccBitBufferGetInt(input_buffer, &val))
{
QccErrorAddMessage("(QccVIDRWMHDecodeHeader): Error calling QccBitBufferGetInt()");
return(1);
}
if (num_rows != NULL)
*num_rows = val;
if (QccBitBufferGetInt(input_buffer, &val))
{
QccErrorAddMessage("(QccVIDRWMHHeader): Error calling QccBitBufferGetInt()");
return(1);
}
if (num_cols != NULL)
*num_cols = val;
if (QccBitBufferGetInt(input_buffer, &val))
{
QccErrorAddMessage("(QccVIDRWMHDecodeHeader): Error calling QccBitBufferGetInt()");
return(1);
}
if (start_frame_num != NULL)
*start_frame_num = val;
if (QccBitBufferGetInt(input_buffer, &val))
{
QccErrorAddMessage("(QccVIDRWMHDecodeHeader): Error calling QccBitBufferGetInt()");
return(1);
}
if (end_frame_num != NULL)
*end_frame_num = val;
if (QccBitBufferGetInt(input_buffer, &val))
{
QccErrorAddMessage("(QccVIDRWMHDecodeHeader): Error calling QccBitBufferGetInt()");
return(1);
}
if (num_levels != NULL)
*num_levels = val;
if (QccBitBufferGetInt(input_buffer, &val))
{
QccErrorAddMessage("(QccVIDRWMHDecodeHeader): Error calling QccBitBufferGetInt()");
return(1);
}
if (blocksize != NULL)
*blocksize = val;
if (QccBitBufferGetInt(input_buffer, &val))
{
QccErrorAddMessage("(QccVIDRWMHDecodeHeader): Error calling QccBitBufferGetInt()");
return(1);
}
if (target_bit_cnt != NULL)
*target_bit_cnt = val;
if (QccBitBufferFlush(input_buffer))
{
QccErrorAddMessage("(QccVIDRWMHDecodeHeader): Error calling QccBitBufferFlush()");
return(1);
}
return(0);
}
static
int QccVIDRWMHDecodeFrame(QccIMGImageComponent *reconstructed_frame,
QccMatrix *compensated_frame_rdwt,
QccMatrix *reference_frame_rdwt,
int num_levels,
int blocksize,
int subpixel_accuracy,
const QccFilter *filter1,
const QccFilter *filter2,
const QccFilter *filter3,
int target_bit_cnt,
const QccWAVWavelet *wavelet,
QccBitBuffer *input_buffer,
int read_motion_vectors,
QccIMGImageComponent *motion_vector_horizontal,
QccIMGImageComponent *motion_vector_vertical)
{
int return_value;
int row, col;
int num_rows, num_cols;
int reference_num_rows, reference_num_cols;
double image_mean;
int max_coefficient_bits;
int arithmetic_coded;
int intraframe;
int start_position;
QccMatrix compensated_frame = NULL;
start_position = input_buffer->bit_cnt;
num_rows = reconstructed_frame->num_rows;
num_cols = reconstructed_frame->num_cols;
if (QccVIDMotionEstimationCalcReferenceFrameSize(num_rows,
num_cols,
&reference_num_rows,
&reference_num_cols,
subpixel_accuracy))
{
QccErrorAddMessage("(QccVIDRWMHDDecodeFrame): Error calling QccVIDMotionEstimationCalcReferenceFrameSize()");
goto Error;
}
if ((compensated_frame = QccMatrixAlloc(num_rows, num_cols)) == NULL)
{
QccErrorAddMessage("(QccVIDRWMHDecodeFrame): Error allocating memory");
goto Error;
}
intraframe =
(motion_vector_horizontal == NULL) || (motion_vector_vertical == NULL);
if (!intraframe)
{
if (!read_motion_vectors)
if (QccVIDMotionVectorsDecode(motion_vector_horizontal,
motion_vector_vertical,
NULL,
subpixel_accuracy,
input_buffer))
{
QccErrorAddMessage("(QccVIDRWMHDecodeFrame): Error calling QccVIDMotionVectorsDecode()");
goto Error;
}
if (QccVIDRWMHMotionCompensation(reference_frame_rdwt,
compensated_frame_rdwt,
num_rows,
num_cols,
reference_num_rows,
reference_num_cols,
num_levels,
blocksize,
subpixel_accuracy,
motion_vector_horizontal,
motion_vector_vertical))
{
QccErrorAddMessage("(QccVIDRWMHDecodeFrame): Error calling QccVIDRWMHMotionCompensation()");
goto Error;
}
if (QccWAVWaveletInverseRedundantDWT2D(compensated_frame_rdwt,
compensated_frame,
num_rows,
num_cols,
num_levels,
wavelet))
{
QccErrorAddMessage("(QccVIDRWMHDecodeFrame): Error calling QccWAVWaveletRedundantDWT2D()");
goto Error;
}
}
if (QccMatrixZero(reconstructed_frame->image,
num_rows, num_cols))
{
QccErrorAddMessage("(QccVIDRWMHDecodeFrame): Error calling QccMatrixZero()");
goto Error;
}
if (QccSPIHTDecodeHeader(input_buffer,
&num_levels,
&num_rows,
&num_cols,
&image_mean,
&max_coefficient_bits,
&arithmetic_coded))
{
QccErrorAddMessage("(QccVIDRWMHDecodeFrame): Error calling QccSPIHTDecodeHeader()");
goto Error;
}
if (QccSPIHTDecode(input_buffer,
reconstructed_frame,
NULL,
num_levels,
wavelet,
NULL,
image_mean,
max_coefficient_bits,
start_position + target_bit_cnt,
arithmetic_coded))
{
QccErrorAddMessage("(QccVIDRWMHDecodeFrame):Error calling QccSPIHTDecode()");
goto Error;
}
if (QccBitBufferFlush(input_buffer))
{
QccErrorAddMessage("(QccVIDRWMHDecodeFrame):Error calling QccBitBufferFlush()");
goto Error;
}
if (!intraframe)
for (row = 0; row < num_rows; row++)
for (col = 0; col < num_cols; col++)
reconstructed_frame->image[row][col] += compensated_frame[row][col];
if (QccVIDRWMHCreateReferenceFrame(reconstructed_frame->image,
compensated_frame_rdwt,
reference_frame_rdwt,
num_rows,
num_cols,
reference_num_rows,
reference_num_cols,
num_levels,
subpixel_accuracy,
filter1,
filter2,
filter3,
wavelet))
{
QccErrorAddMessage("(QccVIDRWMHDecodeFrame): Error calling QccVIDRWMHCreateReferenceFrame()");
goto Error;
}
return_value = 0;
goto Return;
Error:
return_value = 1;
Return:
QccMatrixFree(compensated_frame, num_rows);
return(return_value);
}
int QccVIDRWMHEncode(QccIMGImageSequence *image_sequence,
const QccFilter *filter1,
const QccFilter *filter2,
const QccFilter *filter3,
int subpixel_accuracy,
int blocksize,
QccBitBuffer *output_buffer,
int num_levels,
int target_bit_cnt,
const QccWAVWavelet *wavelet,
const QccString mv_filename,
int read_motion_vectors,
int quiet)
{
int return_value;
QccIMGImageComponent *current_frame;
QccIMGImageComponent reconstructed_frame;
QccMatrix *current_frame_rdwt = NULL;
QccMatrix *reference_frame_rdwt = NULL;
QccIMGImageComponent motion_vector_horizontal;
QccIMGImageComponent motion_vector_vertical;
int frame = 0;
int num_rows, num_cols;
int reference_num_rows, reference_num_cols;
QccBitBuffer input_buffer;
QccVIDRWMHStatistics statistics;
QccBitBufferInitialize(&input_buffer);
QccIMGImageComponentInitialize(&motion_vector_horizontal);
QccIMGImageComponentInitialize(&motion_vector_vertical);
QccIMGImageComponentInitialize(&reconstructed_frame);
if (QccIMGImageSequenceStartRead(image_sequence))
{
QccErrorAddMessage("(QccVIDRWMHEncode): Error calling QccIMGImageSequenceStartRead()");
goto Error;
}
if (QccIMGImageGetSize(&image_sequence->current_frame,
&num_rows, &num_cols))
{
QccErrorAddMessage("(QccVIDRWMHEncode): Error calling QccIMGImageGetSize()");
goto Error;
}
if ((num_rows % blocksize) || (num_cols % blocksize))
{
QccErrorAddMessage("(QccVIDRWMHEncode): Image size is not an integer multiple of block size");
goto Error;
}
current_frame = &image_sequence->current_frame.Y;
motion_vector_horizontal.num_rows =
num_rows / blocksize;
motion_vector_horizontal.num_cols =
num_cols / blocksize;
if (QccIMGImageComponentAlloc(&motion_vector_horizontal))
{
QccErrorAddMessage("(QccVIDRWMHEncode): Error calling QccIMGImageComponentAlloc()");
goto Error;
}
motion_vector_vertical.num_rows =
num_rows / blocksize;
motion_vector_vertical.num_cols =
num_cols / blocksize;
if (QccIMGImageComponentAlloc(&motion_vector_vertical))
{
QccErrorAddMessage("(QccVIDRWMHEncode): Error calling QccIMGImageComponentAlloc()");
goto Error;
}
if (QccVIDMotionEstimationCalcReferenceFrameSize(num_rows,
num_cols,
&reference_num_rows,
&reference_num_cols,
subpixel_accuracy))
{
QccErrorAddMessage("(QccVIDRWMHEncode): Error calling QccVIDMotionEstimationCalcReferenceFrameSize()");
goto Error;
}
reconstructed_frame.num_rows = num_rows;
reconstructed_frame.num_cols = num_cols;
if (QccIMGImageComponentAlloc(&reconstructed_frame))
{
QccErrorAddMessage("(QccVIDRWMHEncode): Error calling QccIMGImageComponentAlloc()");
goto Error;
}
if ((current_frame_rdwt =
QccWAVWaveletRedundantDWT2DAlloc(num_rows,
num_cols,
num_levels)) == NULL)
{
QccErrorAddMessage("(QccVIDRWMHEncode): Error calling QccWAVWaveletRedundantDWT2DAlloc");
goto Error;
}
if ((reference_frame_rdwt =
QccWAVWaveletRedundantDWT2DAlloc(reference_num_rows,
reference_num_cols,
num_levels)) == NULL)
{
QccErrorAddMessage("(QccVIDRWMHEncode): Error calling QccWAVWaveletRedundantDWT2DAlloc");
goto Error;
}
QccStringCopy(input_buffer.filename, output_buffer->filename);
input_buffer.type = QCCBITBUFFER_INPUT;
if (QccBitBufferStart(&input_buffer))
{
QccErrorAddMessage("(QccVIDRWMHEncode): Error calling QccBitBufferStart()");
goto Error;
}
if (QccVIDRWMHEncodeHeader(output_buffer,
num_rows,
num_cols,
image_sequence->start_frame_num,
image_sequence->end_frame_num,
num_levels,
blocksize,
target_bit_cnt))
{
QccErrorAddMessage("(QccVIDRWMHEncode): Error calling QccVIDRWMHEncodeHeader()");
goto Error;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -