📄 hplx_vert_lifting.c
字号:
/*****************************************************************************/
/* Copyright 1998, Hewlett-Packard Company */
/* All rights reserved */
/* File: "hplx_vert_lifting.c" */
/* Description: Common buffer management tools for vertical lifting */
/* implementations. */
/* Author: David Taubman */
/* Affiliation: Hewlett-Packard and */
/* The University of New South Wales, Australia */
/* Acknowledgements: Partly developed in collaboration with */
/* Christos Chrysafis of HP Labs */
/* Version: VM6.0 */
/* Last Revised: 19 January, 2000 */
/*****************************************************************************/
/*****************************************************************************/
/* Modified by David Taubman to support arbitrary reference points for the */
/* transform and the various regular partitions, so as to facilitate */
/* cropping and geometric transformations in the compressed domain and to */
/* enable full support for CRF's single-sample overlap Wavelet transform, */
/* as originally documented in Seoul. Changes are too numerous to flag */
/* individually within the code. Changes copyrighted by HP with all rights */
/* reserved for the modified parts. */
/*****************************************************************************/
/*****************************************************************************/
/* Modified by David Taubman to support interface modifications, arbitrary */
/* changes in coding parameters from component to component and from tile */
/* to tile, to support the full generality of PART-1 of the JPEG2000 */
/* standard, and to support most anticipated generality of PART-2. Changes */
/* are too numerous to flag individually within the code, which in some */
/* places has been completely rewritten. All changes copyrighted by HP with */
/* all rights reserved for the modified parts. */
/*****************************************************************************/
#include <local_services.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <ifc.h>
#include "hplx_vert_lifting.h"
/* ========================================================================= */
/* ------------------------ Exported Utility Functions --------------------- */
/* ========================================================================= */
/*****************************************************************************/
/* EXTERN hplx_lift_heap__get_buffer */
/*****************************************************************************/
hplx_row_buffer_state_ptr
hplx_lift_heap__get_buffer(hplx_row_buffer_heap_ptr heap)
{
hplx_row_buffer_state_ptr buf;
buf = heap->head;
if (buf == NULL)
{
buf = (hplx_row_buffer_state_ptr)
local_malloc(XFORM_MEM_KEY,sizeof(hplx_row_buffer_state));
buf->remaining_users = 0;
buf->float_buf = NULL;
buf->int_buf = NULL;
buf->next = NULL;
if (heap->use_floats)
buf->float_buf = (float *)
local_malloc(XFORM_VBUF_KEY,sizeof(float)*heap->buffer_length);
else
buf->int_buf = (ifc_int *)
local_malloc(XFORM_VBUF_KEY,sizeof(ifc_int)*heap->buffer_length);
}
heap->head = buf->next;
buf->next = NULL;
return(buf);
}
/*****************************************************************************/
/* EXTERN hplx_lift_heap__return_buffer */
/*****************************************************************************/
void
hplx_lift_heap__return_buffer(hplx_row_buffer_heap_ptr heap,
hplx_row_buffer_state_ptr buf)
{
buf->next = heap->head;
heap->head = buf;
}
/*****************************************************************************/
/* EXTERN hplx_lift_heap__get_tmp_buffer */
/*****************************************************************************/
hplx_row_buffer_state_ptr
hplx_lift_heap__get_tmp_buffer(hplx_row_buffer_heap_ptr heap)
{
hplx_row_buffer_state_ptr buf;
buf = heap->head;
if (buf == NULL)
{
buf = (hplx_row_buffer_state_ptr)
local_malloc(XFORM_MEM_KEY,sizeof(hplx_row_buffer_state));
buf->remaining_users = 0;
buf->float_buf = NULL;
buf->int_buf = NULL;
buf->next = NULL;
if (heap->use_floats)
buf->float_buf = (float *)
local_malloc(XFORM_VBUF_KEY,sizeof(float)*heap->buffer_length);
else
buf->int_buf = (ifc_int *)
local_malloc(XFORM_VBUF_KEY,sizeof(ifc_int)*heap->buffer_length);
}
return(buf);
}
/*****************************************************************************/
/* EXTERN hplx_lift_stage__add_row */
/*****************************************************************************/
hplx_row_buffer_state_ptr
hplx_lift_stage__add_row(hplx_buffering_stage_ptr stage)
{
hplx_row_buffer_state_ptr buf;
int buffer_idx;
assert((stage->next_row_idx < stage->rows) &&
(stage->min_row_idx <= stage->next_row_idx));
buffer_idx = stage->next_row_idx - stage->min_row_idx;
if (buffer_idx >= stage->max_buffered_rows)
{
stage->max_buffered_rows += buffer_idx + 1;
stage->row_buffers = (hplx_row_buffer_state_ptr *)
local_realloc(stage->row_buffers,sizeof(hplx_row_buffer_state_ptr)*
stage->max_buffered_rows);
}
stage->row_buffers[buffer_idx] = buf =
hplx_lift_heap__get_buffer(stage->heap);
stage->next_row_idx++;
buf->remaining_users = stage->num_users;
return(buf);
}
/*****************************************************************************/
/* EXTERN hplx_lift_stage__release_row */
/*****************************************************************************/
void
hplx_lift_stage__release_row(hplx_buffering_stage_ptr stage, int row_idx)
{
hplx_row_buffer_state_ptr buf;
int offset, num_buffers;
if (row_idx >= stage->rows)
return;
offset = row_idx - stage->min_row_idx;
if (offset < 0)
return; /* This row was synthesized by symmetric extension. */
num_buffers = stage->next_row_idx - stage->min_row_idx;
assert(offset < num_buffers);
buf = stage->row_buffers[offset];
assert(buf->remaining_users > 0);
buf->remaining_users--;
if (buf->remaining_users == 0)
{
assert(offset == 0);
hplx_lift_heap__return_buffer(stage->heap,buf);
stage->min_row_idx++;
num_buffers--;
for (offset=0; offset < num_buffers; offset++)
stage->row_buffers[offset] = stage->row_buffers[offset+1];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -