Пример #1
0
LOCAL           boolean get_sof(j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
/* Process a SOFn marker */
{
	INT32           length;
	int             c, ci;
	jpeg_component_info *compptr;

	INPUT_VARS(cinfo);

	cinfo->progressive_mode = is_prog;
	cinfo->arith_code = is_arith;

	INPUT_2BYTES(cinfo, length, return FALSE);

	INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
	INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
	INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
	INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);

	length -= 8;

	TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker, (int)cinfo->image_width, (int)cinfo->image_height, cinfo->num_components);

	if(cinfo->marker->saw_SOF)
		ERREXIT(cinfo, JERR_SOF_DUPLICATE);

	/* We don't support files in which the image height is initially specified */
	/* as 0 and is later redefined by DNL.  As long as we have to check that,  */
	/* might as well have a general sanity check. */
	if(cinfo->image_height <= 0 || cinfo->image_width <= 0 || cinfo->num_components <= 0)
		ERREXIT(cinfo, JERR_EMPTY_IMAGE);

	if(length != (cinfo->num_components * 3))
		ERREXIT(cinfo, JERR_BAD_LENGTH);

	if(cinfo->comp_info == NULL)	/* do only once, even if suspend */
		cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
			((j_common_ptr) cinfo, JPOOL_IMAGE, cinfo->num_components * SIZEOF(jpeg_component_info));

	for(ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; ci++, compptr++)
	{
		compptr->component_index = ci;
		INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
		INPUT_BYTE(cinfo, c, return FALSE);
		compptr->h_samp_factor = (c >> 4) & 15;
		compptr->v_samp_factor = (c) & 15;
		INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);

		TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
				 compptr->component_id, compptr->h_samp_factor, compptr->v_samp_factor, compptr->quant_tbl_no);
	}

	cinfo->marker->saw_SOF = TRUE;

	INPUT_SYNC(cinfo);
	return TRUE;
}
Пример #2
0
/*LOCAL*/static void create_colormap (j_decompress_ptr cinfo)
{
	my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
	JSAMPARRAY colormap;		/* Created colormap */
	int total_colors;		/* Number of distinct output colors */
	int i, j, k, nci, blksize, blkdist, ptr, val;

	/* Select number of colors for each component */
	total_colors = select_ncolors(cinfo, cquantize->Ncolors);

	/* Report selected color counts */
	if (cinfo->out_color_components == 3)
	{	TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
			 total_colors, cquantize->Ncolors[0],
			 cquantize->Ncolors[1], cquantize->Ncolors[2]);
	}
	else
	{	TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
	}
	/* Allocate and fill in the colormap. */
	/* The colors are ordered in the map in standard row-major order, */
	/* i.e. rightmost (highest-indexed) color changes most rapidly. */

	colormap = (*cinfo->mem->alloc_sarray)
		((j_common_ptr) cinfo, JPOOL_IMAGE,
		 (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);

	/* blksize is number of adjacent repeated entries for a component */
	/* blkdist is distance between groups of identical entries for a component */
	blkdist = total_colors;

	for (i = 0; i < cinfo->out_color_components; i++)
	{
		/* fill in colormap entries for i'th color component */
		nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
		blksize = blkdist / nci;
		for (j = 0; j < nci; j++)
		{
			/* Compute j'th output value (out of nci) for component */
			val = output_value(cinfo, i, j, nci-1);
			/* Fill in all colormap entries that have this value of this component */
			for (ptr = j * blksize; ptr < total_colors; ptr += blkdist)
			{
				/* fill in blksize entries beginning at ptr */
				for (k = 0; k < blksize; k++)
				{	colormap[i][ptr+k] = (JSAMPLE) val; 	}
			}
		}
		blkdist = blksize;		/* blksize of this color is blkdist of next */
	}

	/* Save the colormap in private storage,
	 * where it will survive color quantization mode changes.
	 */
	cquantize->sv_colormap	= colormap;
	cquantize->sv_actual	= total_colors;
}
Пример #3
0
get_sos (j_decompress_ptr cinfo)
/* Process a SOS marker */
{
  INT32 length;
  int i, ci, n, c, cc;
  jpeg_component_info * compptr;
  INPUT_VARS(cinfo);

  if (! cinfo->marker->saw_SOF)
    ERREXIT(cinfo, JERR_SOS_NO_SOF);

  INPUT_2BYTES(cinfo, length, return FALSE);

  INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */

  if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
    ERREXIT(cinfo, JERR_BAD_LENGTH);

  TRACEMS1(cinfo, 1, JTRC_SOS, n);

  cinfo->comps_in_scan = n;

  /* Collect the component-spec parameters */

  for (i = 0; i < n; i++) {
    INPUT_BYTE(cinfo, cc, return FALSE);
    INPUT_BYTE(cinfo, c, return FALSE);
    
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
	 ci++, compptr++) {
      if (cc == compptr->component_id)
	goto id_found;
    }

    ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);

  id_found:

    cinfo->cur_comp_info[i] = compptr;
    compptr->dc_tbl_no = (c >> 4) & 15;
    compptr->ac_tbl_no = (c     ) & 15;
    
    TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
	     compptr->dc_tbl_no, compptr->ac_tbl_no);
  }

  /* Collect the additional scan parameters Ss, Se, Ah/Al. */
  INPUT_BYTE(cinfo, c, return FALSE);
  cinfo->Ss = c;
  INPUT_BYTE(cinfo, c, return FALSE);
  cinfo->Se = c;
  INPUT_BYTE(cinfo, c, return FALSE);
  cinfo->Ah = (c >> 4) & 15;
  cinfo->Al = (c     ) & 15;

  TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
	   cinfo->Ah, cinfo->Al);

  /* Prepare to scan data & restart markers */
  cinfo->marker->next_restart_num = 0;

  /* Count another SOS marker */
  cinfo->input_scan_number++;

  INPUT_SYNC(cinfo);
  return TRUE;
}
Пример #4
0
LOCAL boolean
get_sof (j_decompress_ptr cinfo)
/* Process a SOFn marker */
{
  INT32 length;
  int c, ci;
  jpeg_component_info * compptr;
  INPUT_VARS(cinfo);

  INPUT_2BYTES(cinfo, length, return FALSE);

  INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);

  length -= 8;

  TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
	   (int) cinfo->image_width, (int) cinfo->image_height,
	   cinfo->num_components);

  if (cinfo->marker->saw_SOF)
    ERREXIT(cinfo, JERR_SOF_DUPLICATE);

  /* We don't support files in which the image height is initially specified */
  /* as 0 and is later redefined by DNL.  As long as we have to check that,  */
  /* might as well have a general sanity check. */
  if (cinfo->image_height <= 0 || cinfo->image_width <= 0
      || cinfo->num_components <= 0)
    ERREXIT(cinfo, JERR_EMPTY_IMAGE);

  /* Make sure image isn't bigger than I can handle */
  if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
      (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);

  /* For now, precision must match compiled-in value... */
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);

  /* Check that number of components won't exceed internal array sizes */
  if (cinfo->num_components > MAX_COMPONENTS)
    ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
	     MAX_COMPONENTS);

  if (length != (cinfo->num_components * 3))
    ERREXIT(cinfo, JERR_BAD_LENGTH);

  if (cinfo->comp_info == NULL)	/* do only once, even if suspend */
    cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
			((j_common_ptr) cinfo, JPOOL_IMAGE,
			 cinfo->num_components * SIZEOF(jpeg_component_info));
  
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
       ci++, compptr++) {
    compptr->component_index = ci;
    INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
    INPUT_BYTE(cinfo, c, return FALSE);
    compptr->h_samp_factor = (c >> 4) & 15;
    compptr->v_samp_factor = (c     ) & 15;
    INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);

    TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
	     compptr->component_id, compptr->h_samp_factor,
	     compptr->v_samp_factor, compptr->quant_tbl_no);
  }

  cinfo->marker->saw_SOF = TRUE;

  INPUT_SYNC(cinfo);
  return TRUE;
}
Пример #5
0
/*{{{  read_neurofile(transform_info_ptr tinfo) {*/
METHODDEF DATATYPE *
read_neurofile(transform_info_ptr tinfo) {
 struct read_neurofile_storage *local_arg=(struct read_neurofile_storage *)tinfo->methods->local_storage;
 transform_argument *args=tinfo->methods->arguments;
 array myarray;
 FILE *infile=local_arg->infile;
 Bool not_correct_trigger=FALSE;
 long trigger_point, file_start_point, file_end_point;
 char *innamebuf;
 int channel;
 char *description=NULL;

 if (local_arg->epochs--==0) return NULL;
 tinfo->beforetrig=local_arg->beforetrig;
 tinfo->aftertrig=local_arg->aftertrig;
 tinfo->nr_of_points=local_arg->beforetrig+local_arg->aftertrig;
 tinfo->nr_of_channels=local_arg->nr_of_channels;
 tinfo->nrofaverages=1;
 if (tinfo->nr_of_points<=0) {
  ERREXIT1(tinfo->emethods, "read_neurofile: Invalid nr_of_points %d\n", MSGPARM(tinfo->nr_of_points));
 }

 /*{{{  Find the next window that fits into the actual data*/
 /* This is just for the Continuous option (no trigger file): */
 file_end_point=local_arg->current_point-1;
 do {
  if (args[ARGS_CONTINUOUS].is_set) {
   /* Simulate a trigger at current_point+beforetrig */
   file_start_point=file_end_point+1;
   trigger_point=file_start_point+tinfo->beforetrig;
   file_end_point=trigger_point+tinfo->aftertrig-1;
   if (local_arg->points_in_file>0 && file_end_point>=local_arg->points_in_file) return NULL;
   local_arg->current_trigger++;
   local_arg->current_point+=tinfo->nr_of_points;
   tinfo->condition=0;
  } else 
  do {
   tinfo->condition=read_neurofile_read_trigger(tinfo, &trigger_point, &description);
   if (tinfo->condition==0) return NULL;	/* No more triggers in file */
   file_start_point=trigger_point-tinfo->beforetrig+local_arg->offset;
   file_end_point=trigger_point+tinfo->aftertrig-1-local_arg->offset;
   
   if (local_arg->trigcodes==NULL) {
    not_correct_trigger=FALSE;
   } else {
    int trigno=0;
    not_correct_trigger=TRUE;
    while (local_arg->trigcodes[trigno]!=0) {
     if (local_arg->trigcodes[trigno]==tinfo->condition) {
      not_correct_trigger=FALSE;
      break;
     }
     trigno++;
    }
   }
  } while (not_correct_trigger || file_start_point<0 || (local_arg->points_in_file>0 && file_end_point>=local_arg->points_in_file));
 } while (--local_arg->fromepoch>0);
 if (description==NULL) {
  TRACEMS3(tinfo->emethods, 1, "read_neurofile: Reading around tag %d at %d, condition=%d\n", MSGPARM(local_arg->current_trigger), MSGPARM(trigger_point), MSGPARM(tinfo->condition));
 } else {
  TRACEMS4(tinfo->emethods, 1, "read_neurofile: Reading around tag %d at %d, condition=%d, description=%s\n", MSGPARM(local_arg->current_trigger), MSGPARM(trigger_point), MSGPARM(tinfo->condition), MSGPARM(description));
 }

 /*{{{  Handle triggers within the epoch (option -T)*/
 if (args[ARGS_TRIGTRANSFER].is_set) {
  int trigs_in_epoch, code;
  long trigpoint;
  long const old_current_trigger=local_arg->current_trigger;
  char *thisdescription;

  /* First trigger entry holds file_start_point */
  push_trigger(&tinfo->triggers, file_start_point, -1, NULL);
  read_neurofile_reset_triggerbuffer(tinfo);
  for (trigs_in_epoch=1; (code=read_neurofile_read_trigger(tinfo, &trigpoint, &thisdescription))!=0;) {
   if (trigpoint>=file_start_point && trigpoint<=file_end_point) {
    push_trigger(&tinfo->triggers, trigpoint-file_start_point, code, thisdescription);
    trigs_in_epoch++;
   }
  }
  push_trigger(&tinfo->triggers, 0, 0, NULL); /* End of list */
  local_arg->current_trigger=old_current_trigger;
 }
 /*}}}  */

 fseek(infile, file_start_point*tinfo->nr_of_channels, SEEK_SET);

 /*{{{  Configure myarray*/
 myarray.element_skip=tinfo->itemsize=1;
 tinfo->multiplexed=TRUE;
 myarray.nr_of_elements=tinfo->nr_of_channels;
 myarray.nr_of_vectors=tinfo->nr_of_points;
 if (array_allocate(&myarray)==NULL || 
  (tinfo->channelnames=(char **)malloc(tinfo->nr_of_channels*sizeof(char *)))==NULL ||
  (innamebuf=(char *)malloc(local_arg->stringlength))==NULL ||
  (tinfo->comment=(char *)malloc(strlen((char *)local_arg->seq.comment)+(1+17+1)))==NULL) {
  ERREXIT(tinfo->emethods, "read_neurofile: Error allocating data\n");
 }
 /*}}}  */

 sprintf(tinfo->comment, "%s %02d/%02d/%02d,%02d:%02d:%02d", local_arg->seq.comment, local_arg->seq.month, local_arg->seq.day, local_arg->seq.year, local_arg->seq.hour, local_arg->seq.minute, local_arg->seq.second);
 for (channel=0; channel<tinfo->nr_of_channels; channel++) {
  strcpy(innamebuf, (char *)local_arg->seq.elnam[channel]);
  tinfo->channelnames[channel]=innamebuf;
  innamebuf+=strlen(innamebuf)+1;
 }

 do {
  signed char exponent;
  short delta;
  if (fread(&exponent, sizeof(exponent), 1, infile)!=1) {
   ERREXIT(tinfo->emethods, "read_neurofile: Error reading data\n");
  }
  delta=exponent;
  exponent&=0x03;
  if (exponent==0x03) {
   delta>>=2;
  } else {
   delta=(delta&0xfffc)<<(exponent*2);
  }
  local_arg->last_values[myarray.current_element]+=delta;
  array_write(&myarray, local_arg->last_values[myarray.current_element]*local_arg->factor);
 } while (myarray.message!=ARRAY_ENDOFSCAN);