⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hplx_hor_synthesis_by_convolution.c

📁 JPEG2000实现的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************/
/* Copyright 1998, Hewlett-Packard Company                                   */
/* All rights reserved                                                       */
/* File: "hplx_hor_synthesis_by_convolution.c"                               */
/* Description: Implementation of the `hplx_synthesis_stage' object for      */
/*              horizontal synthesis via convolution.                        */
/* Author: David Taubman                                                     */
/* Affiliation: Hewlett-Packard and                                          */
/*              The University of New South Wales, Australia                 */
/* Acknowledgements: Partly developed in collaboration with                  */
/*                   Christos Chrysafix of HP Labs                           */
/* Version: VM9.0                                                            */
/* Last Revised: 20 April, 2001                                              */
/*****************************************************************************/

/*****************************************************************************/
/* Modifications tagged with comment lines or delimiters involving the       */
/* string, "David T mod" or "mod by David T", have been made by David        */
/* Taubman; they are copyrighted by Hewlett-Packard Company with all rights  */
/* reserved for the modified parts.                                          */
/*****************************************************************************/

/*****************************************************************************/
/* Modifications tagged with comment lines or delimiters involving the       */
/* string "BBDWT mod" have been made to implement the single-sample          */
/* overlap Wavelet transform within the frames paradigm -- this is the       */
/* BBDWT transform proposed by Canon Research France and accepted at the     */
/* meeting in Seoul, Korea.                                                  */
/*****************************************************************************/

/*****************************************************************************/
/* 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.                               */
/*****************************************************************************/

/*****************************************************************************/
/* Modified for general wavelet decompositions.                              */
/* Copyright 2000 Science Applications International Corporation (SAIC).     */
/* Copyright 1995 University of Arizona, Arizona Board of Regents.           */
/* All Rights Reserved for modified parts.                                   */
/*****************************************************************************/

/*****************************************************************************/
/* Modified by Brendt Wohlberg (Los Alamos National Laboratory) to support   */
/* use of even length filters on tiles of arbitrary dimension and offset     */
/* (as per proposal WG1N1842 submitted at WG1 Rochester meeting). All        */
/* modifications are Copyright 2000 University of California.                */
/*****************************************************************************/

/*****************************************************************************/
/* Modified by Jianxin Wei, Australian Defence Force Academy (ADFA)          */
/* to implement the Odd Tile-Size Low-Pass First Convention (OTLPF_CONVENTION)*/
/* Copyright 2000 University of New South Wales, Australia.                  */
/* All rights reserved for modified parts.                                   */
/*****************************************************************************/

#include <local_services.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <ifc.h>
#include "hplx_synthesis_local.h"

/* ========================================================================= */
/* ---------------------- Definition of Extended Object -------------------- */
/* ========================================================================= */

/*****************************************************************************/
/*                            hplx_polyphase_kernel                          */
/*****************************************************************************/

typedef
  struct hplx_polyphase_kernel {
    int neg_support, pos_support;
    float *taps;
  } hplx_polyphase_kernel, *hplx_polyphase_kernel_ptr;
  /* This structure represents a single polyphase operator, of which four
     are required to completely synthesize a 1-D signal from its low- and
     high-pass subbands.  The kernel represents the contribution of one
     of the input subbands to either the even or odd sub-sequence of the
     output.  The kernel taps appear in inner product fashion and have the
     designated region of support.  Note that the `taps' array is dynamically
     allocated and must be destroyed upon termination of the containing
     object. */

/*****************************************************************************/
/*                    hplx_hor_synthesis_by_convolution_obj                  */
/*****************************************************************************/

typedef
  struct hplx_hor_synthesis_by_convolution_obj {
    hplx_synthesis_stage_obj base;
    int tile_width, first_idx;
    float *branch_bufs[2];
    hplx_polyphase_kernel branch_to_even[2];
    hplx_polyphase_kernel branch_to_odd[2];
    int even_taps;
    int extend;
    float *conversion_buf;
  } hplx_hor_synthesis_by_convolution_obj,
    *hplx_hor_synthesis_by_convolution_ref;
    /* Extends the basic `hplx_synthesis_stage' object to implement
       horizontal synthesis by convolution.
           The `tile_width' argument identifies the width of the current
       tile at the input to this function.
           The `first_idx' field identifies the index of the first sample
       on each row of the current tile, relative to the absolute canvas
       coordinate system.
           The `branch_bufs' array holds pointers to buffers into which
       the low- and high-pass subband samples should be written and
       appropriate extended, before applying the synthesis operations.
           The `branch_to_even' array holds two polyphase kernels,
       corresponding to the operators which map the two input branches
       (low- and high-pass subbands) into the even indexed output samples,
       i.e. samples 0,2,4, etc.
           The `branch_to_odd' array holds two polyphase kernels,
       corresponding to the operators which map the two input branches
       (low- and high-pass subbands) into the odd indexed output samples,
       i.e. 1,3,5, etc.
           `even_taps' indicates whether the filter kernels have even or
       odd length.  This affects the type of symmetric extension which
       must be applied.
           The `extend' field holds the amount by which each of the two
       branch buffers must be extended to the left and to the right, in order
       to ensure correct operation of the synthesis operations.  This
       is simply the maximum of the negative and positive extension
       distances identified in the various polyphase kernels; there
       really is no harm in extending too far.  In fact, for odd length
       signals, with even length filters, the high-pass band is extended
       by one extra sample.  This is accounted for in the allocation
       of space for the band buffers, which takes place in the
       `start_tile' function.
           `conversion_buf' points to a buffer which is large enough to
       hold an entire reconstructed row of the image.  It is only
       required by calls to `pull_line_fixed'. */

/* ========================================================================= */
/* ---------------------------- Internal Functions ------------------------- */
/* ========================================================================= */

/* LANL Even Length Begin */
/*****************************************************************************/
/* STATIC                      synthesis_end_filter                          */
/*****************************************************************************/

/* Implementation of (L',H') -> (L,L) preprocessing */
static void synthesis_end_filter(float* spL, float* spH, float* dp) {
  float dp0, dp1;
 
  dp0 = (*spL + (*spH)/2.0F);
  dp1 = (*spL - (*spH)/2.0F);
  dp[0] = dp0;
  dp[1] = dp1;
  *spH = 0.0;
}
/* LANL Even Length End */

/*****************************************************************************/
/* STATIC                    create_polyphase_kernel                         */
/*****************************************************************************/

static void
  create_polyphase_kernel(hplx_polyphase_kernel_ptr kernel,
                          int input_odd, int output_odd,
                          int neg_support, int pos_support, float *taps)

 /* This function fills out the contents of the polyphase kernel structure
    referenced by `kernel', by reversing and sub-sampling the impulse
    response supplied via `taps', which may be indexed as `taps'[k] where
    k ranges from -`neg_support' to +`pos_support'.  The `input_odd'
    argument identifies whether this impulse response is notionally
    centred on even (low-pass) or odd (high-pass) samples, while the
    `output_odd' argument identifies whether the polyphase kernel is to
    generate the even or odd sub-sequence of the reconstructed signal. */

{
  int displacement, n;

  if (output_odd)
    output_odd = 1; /* Make sure. */
  if (input_odd)
    input_odd = 1; /* Make sure. */
  displacement = output_odd - input_odd;
  kernel->pos_support = (displacement + neg_support)>>1;
  kernel->neg_support = (pos_support - displacement)>>1;
  if ((kernel->neg_support < 0) || (kernel->pos_support < 0))
    return;
  kernel->taps = (float *)
    local_malloc(XFORM_MEM_KEY,
                 sizeof(float)*(kernel->neg_support+kernel->pos_support+1));
  kernel->taps += kernel->neg_support;
  for (n=-kernel->neg_support; n <= kernel->pos_support; n++)
    kernel->taps[n] = taps[displacement - 2*n];
}

/*****************************************************************************/
/* STATIC                      perform_1d_synthesis                          */
/*****************************************************************************/

static void
  perform_1d_synthesis(hplx_hor_synthesis_by_convolution_ref self,
                       float *out_buf, float *branch_bufs[], int width,
                       int first_sample_odd)

 /* This function does most of the work of `__pull_line_float' and
    `__pull_line_fixed'.  It symmetrically extends the two input subband
    buffers in the `branch_bufs' array as necessary and writes the
    synthesized sequence into the buffer pointed to by `out_buf'. */

{
  hplx_synthesis_stage_ref base = (hplx_synthesis_stage_ref)self;
  int b, n;
  float *sp, *dp;

  /* LANL Even Length Begin */
  /* Flags indicating input length and offset parity. Required for
     even length filters */
  int oddevencase = 0;
  int evenevencase = 0;
  /* LANL Even Length End */

  /* LANL Even Length Begin */
  /* Preprocessing to undo (L,L) -> (L',H') postprocessing at right end of
     output */
  if (self->even_taps) {
    if (width%2 && first_sample_odd) /* Odd length, odd offset case */
      synthesis_end_filter(&branch_bufs[0][(width-1)/2-1],
                           &branch_bufs[1][(width-1)/2],
                           &branch_bufs[0][(width-1)/2-1]);
    if (!(width%2) && !first_sample_odd) /* Even length, even offset case */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -