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

📄 ebcot_encoder.c

📁 关于视频压缩的jpeg2000压缩算法,C编写
💻 C
📖 第 1 页 / 共 5 页
字号:
            if ((info->passes[n].rd_slope == 1) ||                (info->passes[n].cumulative_bytes ==                 info->passes[pass_idx-1].cumulative_bytes))              {                info->passes[pass_idx-1].rd_slope = info->passes[n].rd_slope;                info->passes[n].rd_slope = 0;              }            break;          }    }  /* SAIC TCQ end mods */  for (; pass_idx < info->max_passes; pass_idx++)    {      info->passes[pass_idx].cumulative_bytes = last_bytes;      info->passes[pass_idx].rd_slope = -1;    }  band->heap_tail = master->coder_state.heap;  band->next_heap_pos = master->coder_state.next_heap_pos;  /* End of timed section. */  if (self->cpu_time >= 0)    self->cpu_time += (std_int)(clock()-cpu_time);  /* See if code word byte order needs to be reversed. */  msb_first = 1; *((std_byte *)(&msb_first)) = 0;  if (!msb_first)    { /* Least significant byte appears first in each code word.  Need to         reverse this to allow the word buffers to be written out as byte         buffers later when we generate the bit-stream. */      std_int word, *wp;      int heap_remnant;      wp = heap->words + heap_pos;      heap_remnant = DST_HEAP_WORDS - heap_pos;      assert(heap_remnant > 0);      for (n=master->coder_state.saved_words; n > 0; n--)        {          word = *wp;          word = ((word >> 24) & 0x000000FF) | ((word >>  8) & 0x0000FF00) |                 ((word <<  8) & 0x00FF0000) | ((word << 24) & 0xFF000000);          *(wp++) = word;          if ((--heap_remnant) == 0)            { heap_remnant = DST_HEAP_WORDS; heap=heap->next; wp=heap->words; }        }    }}/* ========================================================================= *//* ---------------------- Layer Construction Functions --------------------- *//* ========================================================================= *//*****************************************************************************//* STATIC                      get_layer_specs                               *//*****************************************************************************/static void  get_layer_specs(ebcot_encoder_ref self, cmdl_ref cmdl,                  int max_bytes, int rows, int cols) /* This function determines the total number of bit-stream layers, based    on information supplied via the `-Clayers' argument, if any, and uses    this information to construct an initial `layer_info' array for the    object referenced by `self'.  The contents of this array may change    and the number of layers may be reduced when the    `complete_quality_layers' function is called.    For the moment, the `max_cumulative_bytes' field of each    `ebcot_layer_info' record will be set to the total number of bytes    for the entire code-stream which should be devoted to the relevant layer,    plus all previous layers and the global header itself.  During the call    to `complete_quality_layers', the global header size    will be subtracted from the `max_cumulative_bytes' field of each    `ebcot_layer_info' record. */{  double rate;  char **params;  int p, extra_layers, n, last_max_bytes;  self->num_layers = 1;  self->layer_info = (ebcot_layer_info_ptr)    local_malloc(EBCOT_MEM_KEY,sizeof(ebcot_layer_info)*2);  if ((p = cmdl->extract(cmdl,"-Clayers",-1,&params)) < 0)    { /* Install only one layer. */      self->layer_info->max_cumulative_bytes = max_bytes;      self->layer_info->actual_cumulative_bytes = 0;      self->layer_info->optimize = 1;      self->layer_info->rd_threshold = 0;      return;    }  if (p == 0)    { /* Install default SNR scalable rate specs. */      self->num_layers = 60;      self->layer_info = (ebcot_layer_info_ptr)        local_realloc(self->layer_info,                      sizeof(ebcot_layer_info)*self->num_layers);      memset(self->layer_info,0,             sizeof(ebcot_layer_info)*(size_t)(self->num_layers));      rate = 0.015;      self->layer_info[0].max_cumulative_bytes = (int)        (rate * 0.125 * (double)(rows*cols));      self->layer_info[0].optimize = 1;      rate = 2.0;      self->layer_info[49].max_cumulative_bytes = (int)        (rate * 0.125 * (double)(rows*cols));      self->layer_info[49].optimize = 1;    }  else    {      if ((sscanf(*params,"%lf",&rate) == 0) || (rate <= 0.0))        local_error("The `-Clayers' argument must have zero or more "                    "specification blocks, each starting with a valid "                    "positive bit-rate parameter; found \"%s\" instead!",                    *params);      params++; p--;      last_max_bytes = 0; n = 0;      do {        extra_layers = 0;        if ((p > 0) && ((*params)[0] == '+'))          {            if ((sscanf((*params)+1,"%d",&extra_layers)==0) ||                (extra_layers < 0))              local_error("The `-Clayers' argument contains an "                          "incorrectly formatted parameter identifying "                          "extra bit-stream layers!");            params++; p--;          }        self->num_layers += 1 + extra_layers;        self->layer_info = (ebcot_layer_info_ptr)          local_realloc(self->layer_info,                        sizeof(ebcot_layer_info)*self->num_layers);        self->layer_info[n].max_cumulative_bytes = (int)          (rate * 0.125 * (double)(rows*cols));        if (self->layer_info[n].max_cumulative_bytes <= 0)          self->layer_info[n].max_cumulative_bytes = 1; /* Keep it legal. */        if (last_max_bytes >= self->layer_info[n].max_cumulative_bytes)          local_error("The bit-rates supplied to `-Clayers' must appear "                      "in increasing order!");        last_max_bytes = self->layer_info[n].max_cumulative_bytes;        self->layer_info[n].actual_cumulative_bytes = 0;        self->layer_info[n].optimize = 1;        self->layer_info[n].rd_threshold = 0;        n++;        for (; extra_layers > 0; extra_layers--, n++)          {            self->layer_info[n].max_cumulative_bytes = 0;              /* Fill in true value in `complete_bit_stream_layers'. */            self->layer_info[n].actual_cumulative_bytes = 0;            self->layer_info[n].optimize = 0;            self->layer_info[n].rd_threshold = 0;          }      } while (((p--) > 0) && (sscanf(*(params++),"%lf",&rate) == 1));    }  n = self->num_layers - 1;  self->layer_info[n].max_cumulative_bytes = max_bytes;  self->layer_info[n].actual_cumulative_bytes = 0;  self->layer_info[n].optimize = 1;  self->layer_info[n].rd_threshold = 0;}/*****************************************************************************//* STATIC                   complete_quality_layers                          *//*****************************************************************************/static void  complete_quality_layers(ebcot_encoder_ref self, int header_size) /* See the comments appearing with `get_layer_specs' to understand the    role played by this function. */{  int tnum, c;  ebcot_tile_ptr tile;  ebcot_component_info_ptr comp_info;  int min_layer_bytes, diff_bytes, max_bytes, min_layer_bytes_adjusted;  int from_idx, to_idx, n;  ebcot_layer_info_ptr info;  double from_log, to_log;  min_layer_bytes = 0;  for (tnum=0; tnum < self->num_tiles; tnum++)    {      tile = self->tiles + tnum;      for (c=0; c < tile->num_components; c++)        {          comp_info = tile->components + c;          for (n=0; n <= comp_info->num_levels; n++)            min_layer_bytes += comp_info->levels[n].total_packets * 32;        }    }  info = self->layer_info;  max_bytes = info[self->num_layers-1].max_cumulative_bytes;  min_layer_bytes_adjusted = 0;  from_idx = 0;  while (from_idx < (self->num_layers-1))    {      assert(info[from_idx].optimize); /* Must have a specified bit-rate. */      for (to_idx=from_idx+1; to_idx < self->num_layers; to_idx++)        if (info[to_idx].optimize)          break;      assert((to_idx < self->num_layers) &&             (info[from_idx].max_cumulative_bytes > 0) &&             (info[to_idx].max_cumulative_bytes > 0));      from_log = log((double)(info[from_idx].max_cumulative_bytes));      to_log = log((double)(info[to_idx].max_cumulative_bytes));      while (from_idx < to_idx)        {          info[from_idx].max_cumulative_bytes =            ((int) exp(from_log)) - header_size;          from_log += (to_log - from_log) / ((double)(to_idx-from_idx));          diff_bytes = info[from_idx].max_cumulative_bytes -            ((from_idx == 0)?0:(info[from_idx-1].max_cumulative_bytes));          if (diff_bytes < min_layer_bytes)            { /* Skip this layer. */              self->num_layers--;              for (n=from_idx; n < self->num_layers; n++)                info[n] = info[n+1];              to_idx--;              continue;            }          if ((info[from_idx].max_cumulative_bytes > max_bytes) &&              !min_layer_bytes_adjusted)            {              min_layer_bytes = diff_bytes;              min_layer_bytes_adjusted = 1;            }          from_idx++;        }    }  /* Now work on the last layer. */  info[from_idx].max_cumulative_bytes -= header_size;  diff_bytes = info[from_idx].max_cumulative_bytes -    ((from_idx == 0)?0:(info[from_idx-1].max_cumulative_bytes));  while (diff_bytes < min_layer_bytes)    {      if (from_idx == 0)        {          if (diff_bytes <= 0)            local_error("Requested target bit-rate is probably too small "                        "to accommodate the global header, let alone "                        "any coded subband samples!");          else            break;        }      /* Discard previous layer. */      info[from_idx-1] = info[from_idx];      from_idx--;      self->num_layers--;      diff_bytes = info[from_idx].max_cumulative_bytes -        ((from_idx == 0)?0:(info[from_idx-1].max_cumulative_bytes));    }  /* Finally, make sure that the first layer has the `optimize' flag set. */  self->layer_info[0].optimize = 1;}/* ========================================================================= *//* ---------------------- Structure Management Functions ------------------- *//* ========================================================================= *//*****************************************************************************//* STATIC                  construct_layer_progression                       *//*****************************************************************************/static int  construct_layer_progression(ebcot_tile_ptr tile,                              ebcot_sequence_ptr seq,                              int max_layers, int max_levels,                              int max_components){  ebcot_component_info_ptr comp_info;  ebcot_level_info_ptr lev;  ebcot_packet_info_ptr packet;  int new_packets;  int layer, n, c, p;  new_packets = 0;  for (layer=0; layer < max_layers; layer++)    for (n=0; n < max_levels; n++)      for (c=0; 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_packets; p++)            {              packet = lev->packets + p;              if (packet->included_layers > layer)                continue;              assert(packet->included_layers == layer);              packet->included_layers++;              seq->layer_idx = layer;              seq->packet = packet;              new_packets++;              seq++;            }        }  return(new_packets);}/*****************************************************************************//* STATIC             construct_resolution_layer_progression                 *//*****************************************************************************/static int  construct_resolution_layer_progression(ebcot_tile_ptr tile,                                         ebcot_sequence_ptr seq,                                         int max_layers, int max_levels,                                         int max_components){  ebcot_component_info_ptr comp_info;  ebcot_level_info_ptr lev;  ebcot_packet_info_ptr packet;  int new_packets;  int layer, n, c, p;  new_packets = 0;  for (n=0; n < max_levels; n++)    for (layer=0; layer < max_layers; layer++)      for (c=0; c < max_components; c++)        {          comp_info = tile->components + c;          if (n > comp_info->num_levels)

⌨️ 快捷键说明

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