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

📄 ebcot_decoder.c

📁 关于视频压缩的jpeg2000压缩算法,C编写
💻 C
📖 第 1 页 / 共 5 页
字号:
/*****************************************************************************//* Copyright 1998, Hewlett-Packard Company                                   *//* All rights reserved                                                       *//* File: "ebcot_decoder.h"                                                   *//* Description: Central source file for EBCOT decoder                        *//* Author: David Taubman                                                     *//* Affiliation: Hewlett-Packard and                                          *//*              The University of New South Wales, Australia                 *//* Version: VM6.0                                                            *//* Last Revised: 28 January, 2000                                            *//*****************************************************************************//*****************************************************************************//* Modified to incorporate MQ-coder by Mitsubishi Electric Corp.             *//* Copyright 1999, Mitsubishi Electric Corp.                                 *//* All rights reserved for modified parts                                    *//*****************************************************************************//*****************************************************************************//* Modified to incorporate optional entropy coder                            *//* Copyright 1999 Science Applications International Corporation (SAIC).     *//* All Rights Reservedi for modified parts.                                  *//*****************************************************************************//*****************************************************************************//* 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.                                          *//*****************************************************************************//*****************************************************************************//* Modified by David Taubman to support new termination methods for parallel *//* coding options, to enable more efficient implementations and to support   *//* error resilience.  Copyright 1999 by Hewlett-Packard Company with all     *//* rights reserved for the modified parts.                                   *//*****************************************************************************//*****************************************************************************//* Modified to combine entropy coders                                        *//* Copyright 1999 Science Applications International Corporation (SAIC).     *//* Copyright 1999 University of Arizona, Arizona Board of Regents.           *//* All Rights Reservedi for modified parts.                                  *//*****************************************************************************//*****************************************************************************//* Modified to include TCQ                                                   *//* Copyright 1999 Science Applications International Corporation (SAIC).     *//* Copyright 1995 University of Arizona, Arizona Board of Regents.           *//* All Rights Reservedi for modified parts.                                  *//*****************************************************************************//*****************************************************************************//* 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, packet partitions, rich packet sequencing conventions and 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 <stdlib.h>#include <stdio.h>#include <string.h>#include <math.h>#include <assert.h>#include <time.h>#include <ifc.h>#include <markers.h>#include "ebcot_common.h"#include "ebcot_decoder.h"#include "ebcot_receive_bits.h"static void  retrieve_packet(ebcot_decoder_ref self, ebcot_tile_ptr tile,                  int last_packet_sequence_idx); /* Forward declaration. *//* ========================================================================= *//* ----------------------------- Utility Functions ------------------------- *//* ========================================================================= *//*****************************************************************************//* STATIC                          is_power_of_2                             *//*****************************************************************************/static int  is_power_of_2(int val){  if (val == 0)    return(0);  while (!(val & 1))    val>>=1;  return(val == 1);}/*****************************************************************************//* STATIC                       start_symbol_log                             *//*****************************************************************************/#ifdef DST_LOG_SYMBOLSstatic FILE *  start_symbol_log(ebcot_band_info_ptr band, ebcot_block_info_ptr block){  FILE *fp;  char fname[81];  if (band->tnum != 0)    local_error("Symbol logging is permitted only on single tile images!");  sprintf(fname,"s_%d_%d_%d",band->level_idx,band->band_idx,          (int)(block-band->blocks));  fp = fopen(fname,"rb");  assert(fp != NULL);  return(fp);}#endif /* DST_LOG_SYMBOLS *//*****************************************************************************//* STATIC              convert_dimension_from_level_to_band                  *//*****************************************************************************/static int  convert_dimension_from_level_to_band(int dim, int is_vertical,                                       int hp_descent, int band_idx){  int d, orient, v;  v = (is_vertical)?1:0;  if (hp_descent == 0)    assert(band_idx == LL_BAND);  for (d=hp_descent-1; d >= 0; d--)    {      assert(band_idx != LL_BAND);      orient = (band_idx >> (d+d)) & 3;      switch (orient) {        case LL_BAND: dim = (dim+1)>>1; break;        case HL_BAND: dim = (dim+v)>>1; break;        case LH_BAND: dim = (dim+1-v)>>1; break;        case HH_BAND: dim = dim >> 1; break;        default: assert(0);      }    }  return(dim);}/* ========================================================================= *//* --------------------------- Decoding Functions -------------------------- *//* ========================================================================= *//*****************************************************************************//* STATIC                   undo_roi_boost_using_mask                        *//*****************************************************************************/static void  undo_roi_boost_using_mask(ifc_int *sample_buffer, int rows, int cols,                            int row_gap, int boost_delta,                            std_byte **boost_mask) /* This function is called after decoding a block for which the ROI boost    values differ for different samples in the block in a manner which    cannot be deduced implicitly simply by looling at the amplitudes of    the different non-zero samples.  The `boost_delta' argument identifies the    differences between the minimum and maximum boost for samples within the    block, while the `boost_mask' argument points to a two-dimensional array    of values indicating the amount by which the actual boost for each    sample exceeds the minimum boost.  The less significant samples have    their magnitudes shifted up by `boost_delta' - `boost_mask[r][c]', where    [r,c] is the index of the relevant sample within the code block. */{  ifc_int *sp, val, shift;  std_byte *bp;  int r, c;  for (r=rows; r > 0; r--, boost_mask++, sample_buffer+=row_gap)    for (sp=sample_buffer, bp=*boost_mask, c=cols; c > 0; c--, sp++, bp++)      {        shift = ((ifc_int) boost_delta) - ((ifc_int)(*bp));        if (shift)          {            assert((shift >= 0) && (shift <= (ifc_int) boost_delta));            val = *sp;            val = (val & MIN_IFC_INT) | ((val & MAX_IFC_INT) << shift);            *sp = val;          }      }}/*****************************************************************************//* STATIC              undo_roi_boost_using_implicit_mask                    *//*****************************************************************************/static void  undo_roi_boost_using_implicit_mask(ifc_int *sample_buffer, int rows,                                     int cols, int row_gap, int boost_delta) /* This function performs the same task as `undo_roi_boost_using_mask',    except that the boosted samples are distinguished from those which    have not been boosted implicitly by inspecting the sample magnitudes.    Samples which have not been boosted must have the most significant    `boost_delta' magnitude bits of their sign-magnitude representation    equal to zero. */{  ifc_int *sp, val, shift, mask;  int r, c;  if ((boost_delta+1) >= IMPLEMENTATION_PRECISION)    return; /* Background is too small to have been decoded at all with               current implementation precision. */  mask = (ifc_int)((-1) << (IMPLEMENTATION_PRECISION - (boost_delta+1)));  mask &= MAX_IFC_INT; /* Remove sign bit. */  shift = (ifc_int) boost_delta;  for (r=rows; r > 0; r--, sample_buffer+=row_gap)    for (sp=sample_buffer, c=cols; c > 0; c--, sp++)      {        val = *sp;        if ((val & mask) == 0)          { /* Must be a background sample. */            val = (val & MIN_IFC_INT) | ((val & MAX_IFC_INT) << shift);            *sp = val;          }      }}/*****************************************************************************//* STATIC                  deinterleave_sample_buffer                        *//*****************************************************************************/static void  deinterleave_sample_buffer(block_master_ptr master, ifc_int *sample_buffer) /* Transfers the contents of the interleaved sample buffer to the    supplied non-interleaved buffer, whose rows are separated by    `master->sample_row_gap' array entries. */{  int cols, rows, r, c, stripe_r, row_gap;  ifc_int *sp, *dp, *spp, *dpp;  dpp = sample_buffer;  spp = master->interleaved_sample_buffer;  cols = master->width;  rows = master->height;  row_gap = master->sample_row_gap;  for (stripe_r=4, r=rows; r > 0; r--, dpp+=row_gap, spp++, stripe_r--)    {      if (stripe_r == 0)        { stripe_r=4; spp += master->interleaved_row_gap - 4; }      for (sp=spp, dp=dpp, c=cols; c > 0; c--, sp+=4, dp++)        *dp = *sp;    }}/*****************************************************************************//* STATIC                     reset_block_contexts                           *//*****************************************************************************/static void  reset_block_contexts(block_master_ptr master) /* Sets most context words to 0, except those corresponding to samples    which might be accessed by the "slack" control loops in    "ebcot_lite_decode_passes.c", which are explicitly marked here as    being OUT_OF_BOUNDS.  This allows for somewhat faster execution of    the decoding routines except on partial code-blocks which can only    occur at image boundaries. */{  int rows, cols, c, d_gap;  std_short *cp;  std_int *dcp, *dcpp, dbl_out_of_bounds;  rows = master->height;  cols = master->width;  dcpp = (std_int *)(master->interleaved_context_buffer);  assert((master->interleaved_row_gap & 3) == 0);  d_gap = master->interleaved_row_gap >> 1;  dbl_out_of_bounds = (1<<OUT_OF_BOUNDS_POS);  dbl_out_of_bounds <<= 16;  dbl_out_of_bounds |= (1<<OUT_OF_BOUNDS_POS);  for (; rows > 0; rows -= 4, dcpp+=d_gap)    {      for (dcp=dcpp, c=cols; c > 0; c--)        { *(dcp++) = 0; *(dcp++) = 0; }      for (c=8; c > 0; c--)        { *(dcp++) = dbl_out_of_bounds; *(dcp++) = dbl_out_of_bounds; }    }  if (rows < 0)    { /* One or more rows in the final stripe is out of bounds. */      dcpp -= d_gap;      for (; rows < 0; rows++)        {          cp = ((std_short *) dcpp) + (4+rows);          for (c=cols; c > 0; c--, cp+=4)            *cp = OUT_OF_BOUNDS;        }    }}/*****************************************************************************//* STATIC                    prepare_speedup_buffer                          *//*****************************************************************************/static void  prepare_speedup_buffer(block_master_ptr master){  int whole_stripes, partial_stripe, r, gap;  int internal_words, extra_words, c;  std_int *sup, *supp, boundary_word;  whole_stripes = master->stripes;  partial_stripe = 0;  if (master->height & 3)    { whole_stripes--; partial_stripe = 1; }  internal_words = master->width >> 3;  c = master->width - (internal_words<<3);  boundary_word = ((-1)<<(c+9)) & 0x0000FF00;  extra_words = 2; /* Beyond the boundary word. */  gap = master->speed_up_row_gap;  if ((internal_words+extra_words+1) > gap)    extra_words--;  assert((internal_words+extra_words+1) <= gap);  for (supp=master->speed_up_buffer, r=whole_stripes; r > 0; r--, supp+=gap)    {      for (sup=supp, c=internal_words; c > 0; c--)        *(sup++) = 0;      *(sup++) = boundary_word;      for (c=extra_words; c > 0; c--)        *(sup++) = 0x0000FF00;    }  if (partial_stripe)    for (sup=supp, c=internal_words+extra_words+1; c > 0; c--)

⌨️ 快捷键说明

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