예제 #1
0
void
at_bitmap_free (at_bitmap * bitmap)
{
    if (AT_BITMAP_BITS (bitmap) != NULL)
        free (AT_BITMAP_BITS (bitmap));
    free(bitmap);
}
예제 #2
0
at_bitmap input_gf_reader (gchar* filename, at_input_opts_type *opts,
				at_msg_func msg_func, gpointer msg_data, gpointer user_data)
{
	at_exception_type exp = at_exception_new (msg_func, msg_data);
	at_bitmap bitmap = at_bitmap_init (NULL, 0, 0, 0);
	gf_font_t fontdata, *font = &fontdata;
	gf_char_t chardata, *sym = &chardata;
	unsigned int i, j, ptr;

	if (! gf_open (font, filename)) {
		at_exception_fatal (&exp, "Cannot open input GF file");
		return bitmap;
        }
	if (opts->charcode == 0) {
		/* Find a first character in font file. */
		for (i=0; i<256; ++i)
			if (font->char_loc[i].char_pointer != -1)
				break;
		if (i >= 256) {
			at_exception_fatal (&exp, "No characters in input GF file");
			return bitmap;
		}
		opts->charcode = i;
	}
	if (! gf_get_char (font, sym, (unsigned char) opts->charcode)) {
		fclose (font->input_file);
		at_exception_fatal (&exp, "Error reading character from GF file");
		return bitmap;
	}

	ugs_design_pixels = font->design_size * font->v_pixels_per_point + 0.5;
	ugs_charcode = opts->charcode;
	ugs_advance_width = sym->h_escapement;
	ugs_left_bearing = sym->bbox_min_col;
	ugs_descend = sym->bbox_min_row;
	ugs_max_col = sym->bbox_max_col;
	ugs_max_row = sym->bbox_max_row;

	bitmap = at_bitmap_init (NULL, sym->width, sym->height, 1);
	for (j=0, ptr=0; j<sym->height; j++) {
		for (i=0; i<sym->width; i++) {
		  AT_BITMAP_BITS (&bitmap) [ptr++] = PIXEL (sym, j, i);
		}
	}
	if (sym->bitmap)
		free (sym->bitmap);
	fclose (font->input_file);
	return bitmap;
}
예제 #3
0
void
despeckle (/* in/out */            at_bitmap *bitmap,
           /* in */                int          level,
           /* in */                gfloat      tightness,
           /* in */                gfloat      noise_removal,
	   /* exception handling */ at_exception_type * excep)
{
  int i, planes, max_level;
  short width, height;
  unsigned char *bits;
  double noise_max, adaptive_tightness;

  planes = AT_BITMAP_PLANES (bitmap);
  noise_max = noise_removal * 255.0;
  width = AT_BITMAP_WIDTH (bitmap);
  height = AT_BITMAP_HEIGHT (bitmap);
  bits = AT_BITMAP_BITS(bitmap);
  max_level = (int) (log (width * height) / log (2.0) - 0.5);
  if (level > max_level)
    level = max_level;
  adaptive_tightness = (noise_removal * (1.0 + tightness * level) - 1.0) / level;

  if (planes == 3)
    {
      for (i = 0; i < level; i++)
        despeckle_iteration (i, adaptive_tightness, noise_max, width, height, bits);
    }
  else if (planes == 1)
    {
      for (i = 0; i < level; i++)
        despeckle_iteration_8 (i, adaptive_tightness, noise_max, width, height, bits);
    }
  else
    {
      LOG1 ("despeckle: %u-plane images are not supported", planes);
      at_exception_fatal(excep, "despeckle: wrong plane images are passed");
      return;
    }

}
예제 #4
0
static at_bitmap_type
input_magick_reader(at_string filename,
		    at_input_opts_type * opts,
		    at_msg_func msg_func, 
		    at_address msg_data,
		    at_address user_data)
{
  Image *image = NULL;
  ImageInfo *image_info;
  ImageType image_type;
  unsigned int i,j,point,np,runcount;
  at_bitmap_type bitmap;
  PixelPacket p;
  PixelPacket *pixel=&p;
  ExceptionInfo exception;
#if (MagickLibVersion < 0x0538)
  MagickIncarnate("");
#else
//  InitializeMagick("");
  MagickCoreGenesis("",MagickFalse);
#endif
  GetExceptionInfo(&exception);
  image_info=CloneImageInfo((ImageInfo *) NULL);
  (void) strcpy(image_info->filename,filename);
  image_info->antialias = 0;

  image=ReadImage(image_info,&exception);
  if (image == (Image *) NULL) {
#if (MagickLibVersion <= 0x0525)
    /* MagickError(exception.severity,exception.message,exception.qualifier); */
    if (msg_func)
      msg_func (exception.qualifier, AT_MSG_FATAL, msg_data);
    goto cleanup;
#else
    /* MagickError(exception.severity,exception.reason,exception.description); */
    if (msg_func)
      msg_func (exception.reason, AT_MSG_FATAL, msg_data);
    goto cleanup;
#endif
  }
#if (MagickLibVersion < 0x0540)
  image_type=GetImageType(image);
#else
  image_type=GetImageType(image, &exception);
#endif
  if(image_type == BilevelType || image_type == GrayscaleType)
    np=1;
  else
    np=3;

  bitmap = at_bitmap_init(NULL, image->columns, image->rows, np);

  for(j=0,runcount=0,point=0;j<image->rows;j++)
    for(i=0;i<image->columns;i++) {
      //p=GetOnePixel(image,i,j);
      GetOneAuthenticPixel(image,i,j,&p,&image->exception);

      AT_BITMAP_BITS(bitmap)[point++]=pixel->red; /* if gray: red=green=blue */
      if(np==3) {
        AT_BITMAP_BITS(bitmap)[point++]=pixel->green;
        AT_BITMAP_BITS(bitmap)[point++]=pixel->blue;
      }
    }

  DestroyImage(image);
 cleanup:
  DestroyImageInfo(image_info);  
  return(bitmap);
}