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

📄 component_mix.c

📁 JPEG2000实现的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
    neg = base->branch_neg_supports[b];
    pos = base->branch_pos_supports[b];
    taps = base->branch_taps[b];
    sp = base->in_buf + (b);
    for(n=(length+1-(b))>>1;n>0;n--,sp+=2,dp++){
      for(sum=0.0F,k=-neg;k<=pos;k++)
    sum += sp[k] * taps[k];
      *dp = sum;
    }
  }
}
/* UofA End */

/* Kodak/SAIC Linear Transform Begin */
/*****************************************************************************/
/* STATIC                        apply_lin_xform                             */
/*****************************************************************************/

static void apply_lin_xform(mixing_component_info_ptr components,
                            float **T_for, int num_components, int width)
     
{
  float *components_in, sum;
  int i, j;
  
  components_in = (float *) local_malloc(MIXING_MEM_KEY, 
                     num_components*sizeof(float));
  for(width--;width>=0;width--){  /* Bug fix by Fred Wheeler */
    for(i=0;i<num_components;i++) {
      components_in[i] = (float) components[i].head->buf[width];
    }
    for(i=0;i<num_components;i++){
      sum = 0;
      for(j=0;j<num_components;j++){
    sum+=components_in[j]*T_for[i][j]; /* Bug fix by Fred Wheeler */
      }
      components[i].head->buf[width] = (ifc_int) (sum + 0.5);
    }
  }
  local_free(components_in);
}
/* Kodak/SAIC Linear Transform End */

/* Begin Aerospace MCT mods (TSW) */
/*****************************************************************************/
/* STATIC                          apply_seg_lin_xform                       */
/*****************************************************************************/

static void apply_seg_lin_xform(mixing_component_info_ptr components,
                int num_components, int width, 
                component_xfms_ref transforms,
                collection_ref seg_collection)
{
  /* This module allows for the number of input and output components
     to be different. It also handles specification of null matrices
     in the collection segments.*/
  
  float *interm_components, sum, **interm_ptr, **xform_mat, *offset_vec; 
  int i, j, k, l, n_in, n_out;
  ifc_int **comp_ptr;
  segment seg;
  
  interm_components = (float *) local_malloc(MIXING_MEM_KEY, 
                         num_components*width*sizeof(float));
  comp_ptr = (ifc_int **) local_malloc(MIXING_MEM_KEY, 
                       num_components*sizeof(ifc_int *));
  interm_ptr = (float **) local_malloc(MIXING_MEM_KEY, 
                       num_components*sizeof(float *));

  /* first do all of the dependency transforms */
  for(i=0;i<seg_collection->n_intermed_segments;i++){
    seg = seg_collection->intermed_segment[i];
    n_in = seg.n_input_components;
    for( j = 0; j < n_in; j++ )
      comp_ptr[j] = components[seg.input_components[j]].head->buf;
    n_out = seg.n_output_components;
    for( j = 0; j < n_out; j++ )
      interm_ptr[j]=interm_components+seg.output_components[j]*width;
    if (seg.xfm_matrix > 0) 
      xform_mat = transforms->depend_xfms[seg.xfm_matrix].matrix_values;
    if (seg.off_vector > 0)
      offset_vec =  transforms->depend_offs[seg.off_vector].vector_values;
    
    /* It is probably most efficient to deal with null transform matrices here
       by using 4 different pieces of code for the 4 possible cases, otherwise
       much time will be spent allocating and deallocating memory */

    if((seg.xfm_matrix>0) && (seg.off_vector>0)){
      for(j=0;j<width;j++){
    for(k=0;k<n_out;k++){
      *interm_ptr[k] = ((float) *comp_ptr[k]) - offset_vec[k];
      for(l=0;l<k;l++)
        *interm_ptr[k] -= 
          (((float) *comp_ptr[l])*xform_mat[k][l]);
    }
    for(l=0;l<n_out;l++){
      interm_ptr[l]++;
      comp_ptr[l]++;
    }
      }
    }
    else if ((seg.xfm_matrix>0) && (seg.off_vector==0)){
      for(j=0;j<width;j++){
    for(k=0;k<n_out;k++){
      *interm_ptr[k] = ((float) *comp_ptr[k]);
      for(l=0;l<k;l++)
        *interm_ptr[k]-=
          (((float) *comp_ptr[l])*xform_mat[k][l]);
    }
    for(l=0;l<n_out;l++){
      interm_ptr[l]++;
      comp_ptr[l]++;
    }
      }
    }
    else if(seg.off_vector>0){ /* At least dependency transform is null */
      for(j=0;j<width;j++)
    for(k=0;k<n_out;k++)
      *(interm_ptr[k]++) =
        ((float) *(comp_ptr[k]++))-offset_vec[k];
    }
    else{ /* Both are null */
      for(j=0;j<width;j++)
    for(k=0;k<n_out;k++)
      *(interm_ptr[k]++) = ((float) *(comp_ptr[k]++));
    }
  }
  
  /* then do all of the decorrelation transforms, putting the result back
     into the line buffers */
  for(i=0;i<seg_collection->n_comp_segments;i++){
    seg = seg_collection->comp_segment[i];
    n_in = seg.n_input_components;
    for(j=0;j<n_in;j++)
      interm_ptr[j] = interm_components+seg.input_components[j]*width;
    n_out = seg.n_output_components;
    for(j=0;j<n_out;j++)
      comp_ptr[j] = components[seg.output_components[j]].head->buf;
    if (seg.xfm_matrix > 0)
      xform_mat = transforms->decorrel_xfms[seg.xfm_matrix].matrix_values;
    if (seg.off_vector > 0)
      offset_vec = transforms->decorrel_offs[seg.off_vector].vector_values;
    
    /* It is probably most efficient to deal with null transform matrices here
       by using 4 different pieces of code for the 4 possible cases, otherwise
       much time will be spent allocating and deallocating memory */

    if ((seg.xfm_matrix>0) && (seg.off_vector>0)){
      for(j=0;j<width;j++){
    for(k=0;k<n_out;k++){
      sum = 0;
      for(l=0;l<n_in;l++)
        sum+=((*interm_ptr[l]-offset_vec[l])*xform_mat[k][l]);
      *(comp_ptr[k]++) = (ifc_int) (sum + 0.5);
    }
    for(l=0;l<n_in;l++)
      interm_ptr[l]++;
      }
    }
    else if((seg.xfm_matrix>0) && (seg.off_vector==0)){
      for(j=0;j<width;j++){
    for(k=0;k<n_out;k++){
      sum = 0;
      for(l=0;l<n_in;l++)
        sum += ((*interm_ptr[l])*xform_mat[k][l]);
      *(comp_ptr[k]++) = (ifc_int) (sum + 0.5);
    }
    for(l=0;l<n_in;l++)
      interm_ptr[l]++;
      }
    }
    else if(seg.off_vector>0){ /* The decorrel transform matrix is the identity */
      for(j=0;j<width;j++){
    for(k=0;k<n_out;k++)
      *(comp_ptr[k]++) = 
        (ifc_int) (*(interm_ptr[k]++)-offset_vec[k]+0.5);
      }
    }
    else{ /* Offset vector is also null */
      for(j=0;j<width;j++){
    for(k=0;k<n_out;k++)
      *(comp_ptr[k]++) = (ifc_int) (*(interm_ptr[k]++)+0.5);
      }
    }
  }

  /* free up the allocated space */
  local_free(comp_ptr);
  local_free(interm_ptr);
  local_free(interm_components);
}

/* Begin Aerospace Mods (JHK) */

/*****************************************************************************
 * STATIC                    read_in_the_transforms                          *
 *****************************************************************************/
/* This function serves as a front end to the component collection transform */
/* file reading routines found in the file xccxct.c. Rather than move the */
/* function read_ct_file into this file, the new component collection code */
/* has been kept together in xccxct.c. Besides, at some point in the future */
/* we will allow component collection transform files to be specified on a per */
/* tile basis (what a grand day that will be). Then this function could be */
/* made to handle the tile-based aspects. */
static void read_in_the_transforms(char *filename, the_component_mix_ref self)
{
  self->transforms = read_ct_file(filename);
}

/*****************************************************************************
 * STATIC                     destroy_transforms                             *
 *****************************************************************************/
/* This function releases all of the memory associated with the storage of the */
/* component collection transformation matrices and vectors. */
static void destroy_transforms(the_component_mix_ref self)
{
  int i;
  
  if (self->transforms == NULL)
    return;
  
  if (self->transforms->decorrel_xfms != NULL){
    for(i=1;i<=self->transforms->n_decorrel_xfm;i++){
      local_free(self->transforms->decorrel_xfms[i].matrix_values[0]);
      local_free(self->transforms->decorrel_xfms[i].matrix_values);
    }
    local_free(self->transforms->decorrel_xfms);
  }
  
  if (self->transforms->depend_xfms != NULL){
    for(i=1;i<=self->transforms->n_depend_xfm;i++){
      local_free(self->transforms->depend_xfms[i].matrix_values[0]);
      local_free(self->transforms->depend_xfms[i].matrix_values);
    }
    local_free(self->transforms->depend_xfms);
  }
  
  if (self->transforms->decorrel_offs != NULL){
    for(i=1;i<=self->transforms->n_decorrel_off;i++){
      local_free(self->transforms->decorrel_offs[i].vector_values);
    }
    local_free(self->transforms->decorrel_offs);
  }
  
  if (self->transforms->depend_offs != NULL){
    for(i=1;i<=self->transforms->n_depend_off;i++){
      local_free(self->transforms->depend_offs[i].vector_values);
    }
    local_free(self->transforms->depend_offs);
  }
  
  local_free(self->transforms);
  self->transforms = NULL;
}

/*****************************************************************************
 * STATIC                    read_in_the_collections                         *
 *****************************************************************************/
/* This function serves as a front end to the component collection file */
/* reading routines found in the file xccxct.c. Rather than move the function */
/* read_cc_file into this file, the new component collection code has been */
/* kept together in xccxct.c. When we allow component collections to be */
/* specified on a per tile basis. This function will handle the tile-based */
/* aspects. */
static void read_in_the_collections(char *filename,the_component_mix_ref self,
                    int default_flag)
{
  if (default_flag == 1)
    self->default_collection = read_cc_file(filename);
  else
    self->tile_collection = read_cc_file(filename);
}

/*****************************************************************************
 * STATIC                      destroy_collections                           *
 *****************************************************************************/
/* This function releases all of the memory associated with the storage of the */
/* component collection transformation matrices and vectors. */
static void destroy_collections(the_component_mix_ref self,int default_flag)
{
  collection_ref cptr;
  int i;
  
  if(default_flag == 1) 
    cptr = self->default_collection;
  else
    cptr = self->tile_collection;
  
  if(cptr == NULL)
    return;
  
  if(cptr->comp_segment != NULL){
    for(i=0;i<cptr->n_comp_segments;i++){
      if (cptr->comp_segment[i].input_components != NULL)
    local_free(cptr->comp_segment[i].input_components);
      if (cptr->comp_segment[i].output_components != NULL)
    local_free(cptr->comp_segment[i].output_components);
    }
    if (cptr->comp_segment != NULL)
      local_free(cptr->comp_segment);
  }
  
  if(cptr->intermed_segment!=NULL){
    for(i=0;i<cptr->n_intermed_segments;i++){
      if (cptr->intermed_segment[i].input_components != NULL)
    local_free(cptr->intermed_segment[i].input_components);
      if (cptr->intermed_segment[i].output_components != NULL)
    local_free(cptr->intermed_segment[i].output_components);
    }
    if (cptr->intermed_segment != NULL)
      local_free(cptr->intermed_segment);
  }
  
  local_free(cptr);
  
  if (default_flag == 1)
    self->default_collection = NULL;
  else
    self->tile_collection = NULL;
}
/* End Aerospace MCT mods (JHK) */


/*****************************************************************************/
/* STATIC               find_number_of_codestream_components                 */
/*****************************************************************************/

static void find_number_of_codestream_components(collection_ref col)
{
  int i, j, max_c_number = -1;
  
  for(i=0;i<col->n_intermed_segments;i++)

⌨️ 快捷键说明

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