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

📄 mcraw_image_reader.c

📁 JPEG2000实现的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* STATIC                         __get_usage                                */
/*****************************************************************************/

static char **
  __get_usage(image_reader_ref base)
{
   static char *args[] = {
      /* EKC mct begin */
      "-i <mcraw image file>",
        "Mandatory argument, identifying a multi-component raw image file. "
        "File extensions that are recognized include \".img\", \".nrm\", "
        "\".bil\", \".raw\", \".bsq\", \".bip\".",
      /* EKC mct end */
      "-rcb <rows cols bands> (*MCRAW INPUT ONLY*)",
        "Mandatory argument with `-i', specifying the number of rows, "
        "cols, and components (or bands) in the image.  Enter as three "
        "numbers separated by spaces.",
      "-dt <data type> (default = \"short\") (*MCRAW INPUT ONLY*)",
        "Optional argument for `-i', specifying the data type of the "
        "image values.  Valid inputs are \"uchar\", \"char\", \"ushort\", "
        "\"short\", \"ulong\", \"long\".",
      "-bps <bits per sample> (default = from data type) (*MCRAW INPUT ONLY*)",
        "Optional argument for `-i', specifying the bit depth of the "
        "image values.  The input can be a text file or a single number.  For "
        "text file input, two columns (bitdepth and is_signed) of info are "
        "expected, one for each component.  The text file name must not start "
        "with a digit (0-9).  If the input is a single number, then this "
        "value is assumed for all components.",
      "-do <data organization> (default = \"bil\") (*MCRAW INPUT ONLY*)",
        "Optional argument for `-i', specifying the data organization of "
        "the file.  Valid inputs are \"bsq\", \"bil\", \"bip\".",
      "-skip <skip bytes> (default = 0) (*MCRAW INPUT ONLY*)",
        "Optional argument for `-i', specifying the number of header "
        "bytes to skip.",
      "-swap (default = no swapping) (*MCRAW INPUT ONLY*)",
        "Optional argument for `-i', indicating that the byte order of "
        "each sample should be swapped.",
      NULL};

   return(args);
}

/*****************************************************************************/
/* STATIC                         __get_dims                                 */
/*****************************************************************************/

static void
  __get_dims(image_reader_ref base, int component_idx, canvas_dims_ptr dims)
{
   mcraw_image_reader_ref self = (mcraw_image_reader_ref) base;

   assert(component_idx < self->num_components);
   dims->rows = self->rows;
   dims->cols = self->cols;
}

/*****************************************************************************/
/* STATIC                      __get_dynamic_range                           */
/*****************************************************************************/

static int
  __get_dynamic_range(image_reader_ref base, int component_idx)
{
   mcraw_image_reader_ref self = (mcraw_image_reader_ref) base;
   int result;

   assert(component_idx < self->num_components);
   result = self->bitdepths[component_idx];
   if (self->is_signed[component_idx])
      result = -result;
   return(result);
}

/*****************************************************************************/
/* STATIC                         __pull_line                                */
/*****************************************************************************/

static void
  __pull_line(image_reader_ref base, ifc_int *line_buf, int component_idx,
	      int width)
{
   mcraw_image_reader_ref self = (mcraw_image_reader_ref) base;
   ifc_int *dp, offset, mask, val;
   int n;
   char *status;
  
   assert((component_idx < self->num_components) &&
	  (width == self->cols) && (self->current_row_idx < self->rows));

   if (self->comp_read_so_far == self->num_components) {

      /* This signals that a new page should be read into memory */

      /* We read one image line at a time in order, so increment the 
	 row counter now */
      
      self->current_row_idx++;

      if ((status = readBxP(self->line_buf, self->rows, self->cols, self->num_components,
			   self->pack_bytes, self->data_org, self->skip_bytes, 
			   self->current_row_idx, self->fp))) {
	 local_error(status);
      }
      self->comp_read_so_far = 0;
   }      

   /* Copy the *packed* line of data to the return buffer */

   memcpy((void *)line_buf, 
	  (void *)self->line_buf[component_idx], 
	  (self->cols * self->pack_bytes));
   self->comp_read_so_far++;

   /* See if we need to reverse the byte order. */

   if (self->reverse_byte_order)
   {
      if (self->pack_bytes == 2)
      {
	 std_short *sp, val;

	 for (sp=(std_short *) line_buf, n=width; n > 0; n--)
	 {
	    val = *sp;
	    val = ((val >> 8) & 0x00FF) | (val << 8);
	    *(sp++) = val;
	 }
      }
      else if (self->pack_bytes == 4)
      {
	 std_int *sp, val;

	 for (sp=(std_int *) line_buf, n=width; n > 0; n--)
	 {
	    val = *sp;
	    val = ((val>>24) & 0x000000FF) | ((val>>8) & 0x0000FF00) |
	       ((val<<8)  & 0x00FF0000) | (val<<24);
	    *(sp++) = val;
	 }
      }
   }

   /* Unpack and sign extend source words. */

   offset = 0;
   mask = -1; 
   if (self->bitdepths[component_idx] < 32) {
      mask <<= (ifc_int)(self->bitdepths[component_idx]);
      mask = ~mask;
   }
   if (self->is_signed[component_idx])
   {
      offset = 1;
      offset <<= (self->bitdepths[component_idx]-1);
      /* Add offset to input words, mask off unused MSB's and subract
	 offset again to get correct signed representation, regardless
	 of what the most significant bits used to be. */
   }

   switch (self->pack_bytes) {
      case 1:
	 {
	    std_byte *sp;

	    for (dp=line_buf, sp=(std_byte *) dp, n=width, sp+=n, dp+=n; n>0; n--)
	    {
	       val = (ifc_int)(*(--sp));
	       val += offset;
	       val &= mask;
	       val -= offset;
	       *(--dp) = val;
	    }
	 } 
	 break;
      case 2:
	 {
	    std_short *sp;

	    for (dp=line_buf, sp=(std_short *) dp, n=width, sp+=n, dp+=n; n>0; n--)
	    {
	       val = (ifc_int)(*(--sp));
	       val += offset;
	       val &= mask;
	       val -= offset;
	       *(--dp) = val;
	    }
	 } 
	 break;
#if (IMPLEMENTATION_PRECISION >= 32)
      case 4:
	 {
	    std_int *sp;

	    for (dp=line_buf, sp=(std_int *) dp, n=width, sp+=n, dp+=n; n>0; n--)
	    {
	       val = (ifc_int)(*(--sp));
	       val += offset;
	       val &= mask;
	       val -= offset;
	       *(--dp) = val;
	    }
	 } 
	 break;
#endif /* IMPLEMENTATION_PRECISION >= 32 */
      default:
      assert(0);
   }
}

/*****************************************************************************/
/* STATIC                         __terminate                                */
/*****************************************************************************/

static void
  __terminate(image_reader_ref base)
{
   mcraw_image_reader_ref self = (mcraw_image_reader_ref) base;

   if (self->filename != NULL) {
      local_free((void *)self->filename);
   }
   if (self->fp != NULL) {
      fclose(self->fp);
   }
   if (self->bitdepths != NULL) {
      local_free((void *)self->bitdepths);
   }
   if (self->is_signed != NULL) {
      local_free((void *)self->is_signed);
   }
   if (self->line_buf != NULL) {
      local_free((void *)self->line_buf[0]);
      local_free((void *)self->line_buf);
   }
   local_free(self);
}

/*****************************************************************************/
/* EXTERN                   create_mcraw_image_reader                       */
/*****************************************************************************/

image_reader_ref
  create_mcraw_image_reader(void)
{
   mcraw_image_reader_ref result;

   result = (mcraw_image_reader_ref)
      local_malloc(IMAGE_IO_MEM_KEY,sizeof(mcraw_image_reader_obj));
   memset(result,0,sizeof(mcraw_image_reader_obj));
   result->base.initialize = __initialize;
   result->base.get_usage = __get_usage;
   result->base.get_dims = __get_dims;
   result->base.get_dynamic_range = __get_dynamic_range;
   result->base.pull_line = __pull_line;
   result->base.terminate = __terminate;
   return((image_reader_ref) result);
}

⌨️ 快捷键说明

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