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

📄 ebcot_decoder.c

📁 JPEG2000实现的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
  new_packets = 0;
  for (n=min_level; n < max_levels; n++)
    for (layer=0; layer < max_layers; layer++)
      for (c=min_component; c < max_components; c++)
        {
          comp_info = tile->components + c;
          if (n > comp_info->num_levels)
            continue;
          lev = comp_info->levels + n;
          for (p=0; p < lev->total_precincts; p++)
            {
              precinct = lev->precincts + p;
              if (precinct->sequenced_layers > layer)
                continue;
              assert(precinct->sequenced_layers == layer);
              precinct->sequenced_layers++;
              seq->layer_idx = layer;
              seq->precinct = precinct;
              new_packets++;
              seq++;
            }
        }
  return(new_packets);
}

/*****************************************************************************/
/* STATIC          construct_resolution_position_progression                 */
/*****************************************************************************/

static int
  construct_resolution_position_progression(ebcot_tile_ptr tile,
                                            ebcot_sequence_ptr seq,
                                            int min_level, int min_component,
                                            int max_layers, int max_levels,
                                            int max_components)
{
  ebcot_component_info_ptr comp_info;
  ebcot_level_info_ptr lev;
  ebcot_precinct_info_ptr precinct;
  canvas_dims dims;
  int new_packets;
  int n, c, p;
  int x_inc, y_inc, inc, x0, x1, y0, y1, x, y;

  /* Reset `next_precinct_idx' fields. */

  for (c=min_component; c < tile->num_components; c++)
    {
      comp_info = tile->components + c;
      for (n=min_level; n <= comp_info->num_levels; n++)
        {
          lev = comp_info->levels +n;
          lev->next_precinct_idx = 0;
        }
    }

  new_packets = 0;
  for (n=min_level; n < max_levels; n++)
    {
      /* Determine spatial progression parameters. */

      x_inc = y_inc = 0;
      for (c=min_component; c < max_components; c++)
        {
          comp_info = tile->components + c;
          if (n > comp_info->num_levels)
            continue;
          lev = comp_info->levels + n;
          if ((!is_power_of_2(comp_info->hor_subsampling)) ||
              (!is_power_of_2(comp_info->vert_subsampling)))
            local_error("Cannot use packet progressions where spatial "
                        "progression dominates component progression unless "
                        "component sub-sampling factors are exact "
                        "powers of 2!");
          if (lev->ppx >= 0)
            {
              /* SAIC General Decomp. Begin mods */
              int xfact = 0;
              int l;

              for (l=comp_info->num_levels; l>n; l--) {
                switch(comp_info->levels[l].decomp_sequence[0]) {
                  case 1:
                    xfact++;
                    break;
                  case 2:
                    xfact++;
                    break;
                  case 3:
                    break;
                }
              }
              inc = comp_info->hor_subsampling;
              inc <<= lev->ppx + xfact;
              /* SAIC General Decomp. End mods */

              if ((x_inc == 0) || (inc < x_inc))
                x_inc = inc;
            }
          if (lev->ppy >= 0)
            {
              /* SAIC General Decomp. Begin mods */
              int yfact = 0;
              int l;

              for (l=comp_info->num_levels; l>n; l--) {
                switch(comp_info->levels[l].decomp_sequence[0]) {
                  case 1:
                    yfact++;
                    break;
                  case 2:
                    break;
                  case 3:
                    yfact++;
                    break;
                }
              }
              inc = comp_info->vert_subsampling;
              inc <<= lev->ppy + yfact;
              /* SAIC General Decomp. End mods */

              if ((y_inc == 0) || (inc < y_inc))
                y_inc = inc;
            }
        }
      dims = tile->reference_dims;
      if (tile->overlapped)
        local_error("Spatially oriented packet progressions not defined "
                    "for overlapping tiles!");
      if (x_inc == 0)
        { /* Only one precinct horizontally. */
          x0 = 0; x1 = x_inc = 1;
        }
      else
        {
          x0 = dims.left_col; x1 = x0 + dims.cols;
          x0 &= ~(x_inc-1); /* Start on integer multiple of x_inc. */
        }
      if (y_inc == 0)
        { /* Only one precinct vertically. */
          y0 = 0; y1 = y_inc = 1;
        }
      else
        {
          y0 = dims.top_row; y1 = y0 + dims.rows;
          y0 &= ~(y_inc-1); /* Start on integer multiple of y_inc. */
        }

      /* Now walk through the progression. */

      for (y=y0; y < y1; y += y_inc)
        for (x=x0; x < x1; x += x_inc)
          for (c=min_component; c < max_components; c++)
            {
              comp_info = tile->components + c;
              if (n > comp_info->num_levels)
                continue;
              lev = comp_info->levels + n;
              p = lev->next_precinct_idx;
              precinct = lev->precincts + p;
              if ((p < lev->total_precincts) &&
                  ((y==y0) || (y==precinct->yref)) &&
                  ((x==x0) || (x==precinct->xref)))
                {
                  lev->next_precinct_idx++;
                  while (precinct->sequenced_layers < max_layers)
                    {
                      seq->layer_idx = precinct->sequenced_layers;
                      seq->precinct = precinct;
                      new_packets++;
                      seq++;
                      precinct->sequenced_layers++;
                    }
                }
            }
    }
  return(new_packets);
}

/*****************************************************************************/
/* STATIC          construct_position_component_progression                  */
/*****************************************************************************/

static int
  construct_position_component_progression(ebcot_tile_ptr tile,
                                           ebcot_sequence_ptr seq,
                                           int first_level,
                                           int first_component,
                                           int max_layers, int max_levels,
                                           int max_components)
{
  ebcot_component_info_ptr comp_info;
  ebcot_level_info_ptr lev;
  ebcot_precinct_info_ptr precinct;
  canvas_dims dims;
  int new_packets;
  int n, c, p;
  int x_inc, y_inc, inc, x0, x1, y0, y1, x, y;

  /* Reset `next_precinct_idx' fields. */

  for (c=first_component; c < tile->num_components; c++)
    {
      comp_info = tile->components + c;
      for (n=first_level; n <= comp_info->num_levels; n++)
        {
          lev = comp_info->levels +n;
          lev->next_precinct_idx = 0;
        }
    }

  /* Determine spatial progression parameters. */

  x_inc = y_inc = 0;
  for (c=first_component; c < max_components; c++)
    {
      comp_info = tile->components + c;
      if ((!is_power_of_2(comp_info->hor_subsampling)) ||
          (!is_power_of_2(comp_info->vert_subsampling)))
        local_error("Cannot use packet progressions where spatial "
                    "progression dominates component progression unless "
                    "component sub-sampling factors are exact powers of 2!");
      for (n=first_level; n < max_levels; n++)
        {
          lev = comp_info->levels + n;
          if (lev->ppx >= 0)
            {
              /* SAIC General Decomp. Begin mods */
              int xfact = 0;
              int l;

              for (l=comp_info->num_levels; l>n; l--) {
                switch(comp_info->levels[l].decomp_sequence[0]) {
                  case 1:
                    xfact++;
                    break;
                  case 2:
                    xfact++;
                    break;
                  case 3:
                    break;
                }
              }
              inc = comp_info->hor_subsampling;
              inc <<= lev->ppx + xfact;
              /* SAIC General Decomp. End mods */

              if ((x_inc == 0) || (inc < x_inc))
                x_inc = inc;
            }
          if (lev->ppy >= 0)
            {
              /* SAIC General Decomp. Begin mods */
              int yfact = 0;
              int l;

              for (l=comp_info->num_levels; l>n; l--) {
                switch(comp_info->levels[l].decomp_sequence[0]) {
                  case 1:
                    yfact++;
                    break;
                  case 2:
                    break;
                  case 3:
                    yfact++;
                    break;
                }
              }
              inc = comp_info->vert_subsampling;
              inc <<= lev->ppy + yfact;
              /* SAIC General Decomp. End mods */

              if ((y_inc == 0) || (inc < y_inc))
                y_inc = inc;
            }
        }
    }
  dims = tile->reference_dims;
  if (tile->overlapped)
    local_error("Spatially oriented packet progressions not defined "
                "for overlapping tiles!");
  if (x_inc == 0)
    { /* Only one precinct horizontally. */
      x0 = 0; x1 = x_inc = 1;
    }
  else
    {
      x0 = dims.left_col; x1 = x0 + dims.cols;
      x0 &= ~(x_inc-1); /* Start on integer multiple of x_inc. */
    }
  if (y_inc == 0)
    { /* Only one precinct vertically. */
      y0 = 0; y1 = y_inc = 1;
    }
  else
    {
      y0 = dims.top_row; y1 = y0 + dims.rows;
      y0 &= ~(y_inc-1); /* Start on integer multiple of y_inc. */
    }

  /* Now walk through the progression. */

  new_packets = 0;
  for (y=y0; y < y1; y += y_inc)
    for (x=x0; x < x1; x += x_inc)
      for (c=first_component; c < max_components; c++)
        for (n=first_level; n < max_levels; n++)
          {
            comp_info = tile->components + c;
            if (n > comp_info->num_levels)
              continue;
            lev = comp_info->levels + n;
            p = lev->next_precinct_idx;
            precinct = lev->precincts + p;
            if ((p < lev->total_precincts) &&
                ((y==y0) || (y==precinct->yref)) &&
                ((x==x0) || (x==precinct->xref)))
              {
                lev->next_precinct_idx++;
                while (precinct->sequenced_layers < max_layers)
                  {
                    seq->layer_idx = precinct->sequenced_layers;
                    seq->precinct = precinct;
                    new_packets++;
                    seq++;
                    precinct->sequenced_layers++;
                  }
              }
          }
  return(new_packets);
}

/*****************************************************************************/
/* STATIC          construct_component_position_progression                  */
/*****************************************************************************/

⌨️ 快捷键说明

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