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

📄 codestream.cpp

📁 JPEG2000的C++实现代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            kd_resolution *res = tc->resolutions + res_idx;            pos = res->current_sequencer_pos;            if ((pos.x >= res->precinct_indices.size.x) ||                (pos.y >= res->precinct_indices.size.y))              continue; // No precincts left in this resolution.            kd_precinct **refs = res->precinct_refs +              pos.x + pos.y*res->precinct_indices.size.x;            if ((*refs == KD_EXPIRED_PRECINCT) ||                ((*refs != NULL) && ((*refs)->next_layer_idx >= layer_lim)))              { // Cannot sequence this one any further.                pos.x++;                if (pos.x >= res->precinct_indices.size.x)                  { pos.x = 0; pos.y++; }                res->current_sequencer_pos = pos;                continue; // Move sequencing loops ahead.              }            int gpos;            gpos = res->precinct_indices.pos.y + pos.y;            gpos *= res->precinct_partition.size.y;            gpos <<= (tc->dwt_levels-res_idx);            gpos *= tc->sub_sampling.y;            gpos += tile->coding_origin.y;            if ((gpos >= grid_min.y) && (gpos != grid_loc.y))              continue;            gpos = res->precinct_indices.pos.x + pos.x;            gpos *= res->precinct_partition.size.x;            gpos <<= (tc->dwt_levels-res_idx);            gpos *= tc->sub_sampling.x;            gpos += tile->coding_origin.x;            if ((gpos >= grid_min.x) && (gpos != grid_loc.x))              continue;            if (*refs == NULL)              new kd_precinct(res,pos);            assert((*refs)->next_layer_idx < layer_lim);            return *refs;          }  return NULL;}/*****************************************************************************//*                    kd_packet_sequencer::next_in_pcrl                      *//*****************************************************************************/kd_precinct *  kd_packet_sequencer::next_in_pcrl(){  if (layer_lim <= 0)    return NULL;  for (; grid_loc.y < grid_lim.y;       grid_loc.y += grid_inc.y, grid_loc.x=grid_min.x)    for (; grid_loc.x < grid_lim.x;         grid_loc.x += grid_inc.x, comp_idx=comp_min)      for (; comp_idx < comp_lim; comp_idx++, res_idx=res_min)        for (; res_idx < res_lim; res_idx++)          {            kd_tile_comp *tc = tile->comps + comp_idx;            if (res_idx > tc->dwt_levels)              break; // Advance to next component.            kd_resolution *res = tc->resolutions + res_idx;            pos = res->current_sequencer_pos;            if ((pos.x >= res->precinct_indices.size.x) ||                (pos.y >= res->precinct_indices.size.y))              continue; // No precincts left in this resolution.            kd_precinct **refs = res->precinct_refs +              pos.x + pos.y*res->precinct_indices.size.x;            if ((*refs == KD_EXPIRED_PRECINCT) ||                ((*refs != NULL) && ((*refs)->next_layer_idx >= layer_lim)))              { // Cannot sequence this one any further.                pos.x++;                if (pos.x >= res->precinct_indices.size.x)                  { pos.x = 0; pos.y++; }                res->current_sequencer_pos = pos;                continue; // Move sequencing loops ahead.              }            int gpos;            gpos = res->precinct_indices.pos.y + pos.y;            gpos *= res->precinct_partition.size.y;            gpos <<= (tc->dwt_levels-res_idx);            gpos *= tc->sub_sampling.y;            gpos += tile->coding_origin.y;            if ((gpos >= grid_min.y) && (gpos != grid_loc.y))              continue;            gpos = res->precinct_indices.pos.x + pos.x;            gpos *= res->precinct_partition.size.x;            gpos <<= (tc->dwt_levels-res_idx);            gpos *= tc->sub_sampling.x;            gpos += tile->coding_origin.x;            if ((gpos >= grid_min.x) && (gpos != grid_loc.x))              continue;            if (*refs == NULL)              new kd_precinct(res,pos);            assert((*refs)->next_layer_idx < layer_lim);            return *refs;          }  return NULL;}/*****************************************************************************//*                    kd_packet_sequencer::next_in_cprl                      *//*****************************************************************************/kd_precinct *  kd_packet_sequencer::next_in_cprl(){  if (layer_lim <= 0)    return NULL;  while (comp_idx < comp_lim)    {      kd_tile_comp *tc = tile->comps + comp_idx;      for (; grid_loc.y < grid_lim.y;           grid_loc.y += grid_inc.y, grid_loc.x=grid_min.x)        for (; grid_loc.x < grid_lim.x;             grid_loc.x += grid_inc.x, res_idx=res_min)          for (; res_idx < res_lim; res_idx++)            {              if (res_idx > tc->dwt_levels)                break; // Advance to next position.              kd_resolution *res = tc->resolutions + res_idx;              pos = res->current_sequencer_pos;              if ((pos.x >= res->precinct_indices.size.x) ||                  (pos.y >= res->precinct_indices.size.y))                continue; // No precincts left in this resolution.              kd_precinct **refs = res->precinct_refs +                pos.x + pos.y*res->precinct_indices.size.x;              if ((*refs == KD_EXPIRED_PRECINCT) ||                  ((*refs != NULL) && ((*refs)->next_layer_idx >= layer_lim)))                { // Cannot sequence this one any further.                  pos.x++;                  if (pos.x >= res->precinct_indices.size.x)                    { pos.x = 0; pos.y++; }                  res->current_sequencer_pos = pos;                  continue; // Move sequencing loops ahead.                }              int gpos;              gpos = res->precinct_indices.pos.y + pos.y;              gpos *= res->precinct_partition.size.y;              gpos <<= (tc->dwt_levels-res_idx);              gpos *= tc->sub_sampling.y;              gpos += tile->coding_origin.y;              if ((gpos >= grid_min.y) && (gpos != grid_loc.y))                continue;              gpos = res->precinct_indices.pos.x + pos.x;              gpos *= res->precinct_partition.size.x;              gpos <<= (tc->dwt_levels-res_idx);              gpos *= tc->sub_sampling.x;              gpos += tile->coding_origin.x;              if ((gpos >= grid_min.x) && (gpos != grid_loc.x))                continue;              if (*refs == NULL)                new kd_precinct(res,pos);              assert((*refs)->next_layer_idx < layer_lim);              return *refs;            }      // Advance component index.      comp_idx++;      if (comp_idx < comp_lim)        { // Install spatial progression parameters for new tile-component.          tc = tile->comps + comp_idx;          grid_min = tc->grid_min;          grid_inc = tc->grid_inc;          grid_loc = grid_min;        }    }  return NULL;}/* ========================================================================= *//*                               kd_codestream                               *//* ========================================================================= *//*****************************************************************************//*                        kd_codestream::construct_common                    *//*****************************************************************************/void kd_codestream::construct_common(){  // Get summary parameters from SIZ object.  siz->finalize();  if (!(siz->get(Scomponents,0,0,num_components) &&        siz->get(Ssize,0,0,canvas.size.y) && // Subtract y_pos later        siz->get(Ssize,0,1,canvas.size.x) && // Subtract x_pos later        siz->get(Sorigin,0,0,canvas.pos.y) &&        siz->get(Sorigin,0,1,canvas.pos.x) &&        siz->get(Stiles,0,0,tile_partition.size.y) &&        siz->get(Stiles,0,1,tile_partition.size.x) &&        siz->get(Stile_origin,0,0,tile_partition.pos.y) &&        siz->get(Stile_origin,0,1,tile_partition.pos.x)))    assert(0);  canvas.size.y -= canvas.pos.y;  canvas.size.x -= canvas.pos.x;  if ((canvas.size.y <= 0) || (canvas.size.x <= 0) ||      (tile_partition.pos.x > canvas.pos.x) ||      (tile_partition.pos.y > canvas.pos.y) ||      ((tile_partition.pos.x+tile_partition.size.x) <= canvas.pos.x) ||      ((tile_partition.pos.y+tile_partition.size.y) <= canvas.pos.y))    { kdu_error e; e << "Illegal canvas coordinates: the first tile is "      "required to have a non-empty intersection with the image on the "      "high resolution grid."; }  int n;  sub_sampling = new kdu_coords[num_components];  crg_x = crg_y = NULL;  precision = new int[num_components];  is_signed = new bool[num_components];  for (n=0; n < num_components; n++)    {      if (!siz->get(Sprecision,n,0,precision[n]))        { kdu_error e; e << "No information available concerning component "          "sample bit-depths (i.e., sample precision)."; }      if (!siz->get(Ssigned,n,0,is_signed[n]))        { kdu_error e; e << "No information available regarding whether "          "components are signed or unsigned."; }      if (!(siz->get(Ssampling,n,0,sub_sampling[n].y) &&            siz->get(Ssampling,n,1,sub_sampling[n].x)))        { kdu_error e; e << "No information available concerning component "          "sub-sampling factors."; }    }  num_tiles.y = ceil_ratio(canvas.size.y+canvas.pos.y-tile_partition.pos.y,                           tile_partition.size.y);  num_tiles.x = ceil_ratio(canvas.size.x+canvas.pos.x-tile_partition.pos.x,                           tile_partition.size.x);  if ((num_tiles.x*num_tiles.y) > 65535)    { kdu_error e; e << "Maximum number of allowable tiles is 65535 for any "      "JPEG2000 code-stream.  You have managed to exceed this number!!"; }  tile_refs = new kd_tile *[num_tiles.y*num_tiles.x];  for (n=0; n < num_tiles.y*num_tiles.x; n++)    tile_refs[n] = NULL;  // Build the parameter structure.  kdu_params *element;  for (n=-1; n < num_tiles.y*num_tiles.x; n++)    {      for (int c=-1; c < num_components; c++)        {          element = new cod_params; element->link(siz,n,c);          element = new qcd_params; element->link(siz,n,c);          element = new rgn_params; element->link(siz,n,c);        }      element = new poc_params; element->link(siz,n,-1);    }  element = new crg_params; element->link(siz,-1,-1);  // Now set up some common services, which we are sure to need.  buf_server = new kd_buf_server;  buf_server->attach();  shared_block = new kdu_block();  // Now some final initialization steps.  if (in != NULL)    {      do {          if (!marker->read())            { kdu_error e;              e << "Code-stream must contain at least one SOT marker!";}          if (marker->get_code() == KDU_PPM)            {              if (ppm_markers == NULL)                ppm_markers = new kd_pp_markers();              ppm_markers->add_marker(*marker);            }          else            siz->translate_marker_segment(marker->get_code(),                                          marker->get_length(),                                          marker->get_bytes(),-1,0);        } while (marker->get_code() != KDU_SOT);    }  region = canvas;  first_apparent_component = 0;  num_apparent_components = num_components;  discard_levels = 0;  max_apparent_layers = 0xFFFF;  max_tile_layers = 1;  tiles_accessed = false;  stats = NULL;  start_time = clock();}/*****************************************************************************//*                        kd_codestream::~kd_codestream                      *//*****************************************************************************/kd_codestream::~kd_codestream(){  if (ppm_markers != NULL)    delete ppm_markers;  if (marker != NULL)    delete marker;  if (in != NULL)    { delete in; in = NULL; }  if (out != NULL)    { delete out; out = NULL; }  if (shared_block != NULL)    delete shared_block;  if (sub_sampling != NULL)    delete[] sub_sampling;  if (crg_x != NULL)    delete[] crg_x;  if (crg_y != NULL)    delete[] crg_y;  if (precision != NULL)    delete[] precision;  if (is_signed != NULL)    delete[] is_signed;  if (tile_refs != NULL)    {      for (int n=0; n < num_tiles.x*num_tiles.y; n++)        if ((tile_refs[n] != NULL) && (tile_refs[n] != KD_EXPIRED_TILE))          delete tile_refs[n]; // Invokes tile destructor.      delete[] tile_refs;    }  if (siz != NULL)    delete siz;  if (buf_server != NULL)    {      buf_server->detach();      if (buf_server->can_destroy())        delete buf_server;    }  if (stats != NULL)    delete stats;}/*****************************************************************************//*                         kd_codestream::create_tile                        *//*****************************************************************************/kd_tile *  kd_codestream::create_tile(int tnum){  kd_tile *tp = tile_refs[tnum];  assert(tp == NULL);  tp = tile_refs[tnum] = new kd_tile(this,tnum);  if ((in != NULL) && (!persistent) && !(tp->dims & region))    delete tp;  else    tp->initialize();  return tp;}/*****************************************************************************//*                   kd_codestream::trim_compressed_data                     *//*****************************************************************************/void  kd_codestream::trim_compressed_data(){  if (stats == NULL)    return;  kdu_uint16 threshold = stats->get_conservative_slope_threshold(true);  if (threshold <= 1)    return;

⌨️ 快捷键说明

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