Exemplo n.º 1
0
static int get_fig_colour(at_color this_colour, at_exception_type * exp)
{
  int hash, i, this_ind;

  hash = fig_col_hash(this_colour);

/*  Special case: black _IS_ zero: */
  if ((hash == 0) && (at_color_equal(&(fig_colour_map[0].c), &this_colour))) {
    return (0);
  }

  if (fig_hash[hash].colour == 0) {
    fig_hash[hash].colour = LAST_FIG_COLOUR;
    fig_colour_map[LAST_FIG_COLOUR].c.r = this_colour.r;
    fig_colour_map[LAST_FIG_COLOUR].c.g = this_colour.g;
    fig_colour_map[LAST_FIG_COLOUR].c.b = this_colour.b;
    LAST_FIG_COLOUR++;
    if (LAST_FIG_COLOUR >= MAX_FIG_COLOUR) {
      LOG("Output-Fig: too many colours: %d", LAST_FIG_COLOUR);
      at_exception_fatal(exp, "Output-Fig: too many colours");
      return 0;
    }
    return (fig_hash[hash].colour);
  } else {
    i = 0;
    this_ind = fig_hash[hash].colour;
figcolloop:
    /* If colour match return current colour */
    if (at_color_equal(&(fig_colour_map[this_ind].c), &this_colour)) {
      return (this_ind);
    }
    /* If next colour zero - set it, return */
    if (fig_colour_map[this_ind].alternate == 0) {
      fig_colour_map[this_ind].alternate = LAST_FIG_COLOUR;
      fig_colour_map[LAST_FIG_COLOUR].c.r = this_colour.r;
      fig_colour_map[LAST_FIG_COLOUR].c.g = this_colour.g;
      fig_colour_map[LAST_FIG_COLOUR].c.b = this_colour.b;
      LAST_FIG_COLOUR++;
      if (LAST_FIG_COLOUR >= MAX_FIG_COLOUR) {
        LOG("Output-Fig: too many colours: %d", LAST_FIG_COLOUR);
        at_exception_fatal(exp, "Output-Fig: too many colours");
        return 0;
      }
      return (fig_colour_map[this_ind].alternate);
    }
    /* Else get next colour */
    this_ind = fig_colour_map[this_ind].alternate;
    /* Sanity check ... if colour too big - abort */
    if (i++ > MAX_FIG_COLOUR) {
      LOG("Output-Fig: too many colours (loop): %d", i);
      at_exception_fatal(exp, "Output-Fig: too many colours (loop)");
      return 0;
    }
    /* Else loop top */
    goto figcolloop;
  }
}
Exemplo n.º 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;
}
Exemplo n.º 3
0
static void handle_error(png_structp png, const gchar* message) {
	LOG1("PNG error: %s", message);
	at_exception_fatal((at_exception_type *)png->error_ptr,
			   message);
	/* at_exception_fatal((at_exception_type *)at_png->error_ptr,
	   "PNG error"); */
	
}
Exemplo n.º 4
0
at_bitmap input_png_reader(gchar* filename, at_input_opts_type * opts,
				at_msg_func msg_func, gpointer msg_data,
				gpointer user_data) {
	FILE *stream;
	at_bitmap image = at_bitmap_init(0, 0, 0, 1);
	at_exception_type exp = at_exception_new(msg_func, msg_data);

	stream = fopen(filename, "rb");
	if (!stream)
	  {
	    LOG1("Can't open \"%s\"\n", filename);
	    at_exception_fatal(&exp, "Cannot open input png file");
	    return image;
	  }

	load_image(&image, stream, opts, &exp);
	fclose(stream);

	return image;
}
Exemplo n.º 5
0
static float
acos_d (float v, at_exception_type * excep)
{
  float a;

  if (epsilon_equal (v, 1.0))
    v = 1.0;
  else if (epsilon_equal (v, -1.0))
    v = -1.0;

  errno = 0;
  a = (float) acos (v);
  if (errno == ERANGE || errno == EDOM)
    {
      at_exception_fatal(excep, strerror(errno));
      return 0.0;
    }
  
  
  return a * (float) 180.0 / (float) M_PI;
}
Exemplo n.º 6
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;
    }

}
Exemplo n.º 7
0
void
thin_image(bitmap_type *image, bool bgSpec, pixel bg,
           at_exception_type * exp)
{ 
    /* This is nasty as we need to call thin once for each  
     * colour in the image the way I do this is to keep a second  
     * copy of the bitmap and to use this to keep 
     * track of which colours have not yet been processed, 
     * trades time for pathological case memory.....*/ 
    long m, n, num_pixels;
    bitmap_type bm; 
    unsigned int const spp = image->np;
	unsigned int const width = image->width;
	unsigned int const height = image->height;

    if (bgSpec)
        background = bg;
    else 
        PPM_ASSIGN(background, 255, 255, 255);

    /* Clone the image */
    bm.height = image->height;
    bm.width = image->width;
    bm.np = image->np;
    MALLOCARRAY(bm.bitmap, height * width * spp); 
    if (bm.bitmap == NULL)
        pm_error("Unable to get memory for thin image bitmap clone");
    memcpy(bm.bitmap, image->bitmap, height * width * spp); 

    num_pixels = height * width;
    switch (spp)
    {
	case 3:
	{
	    Pixel *ptr = (Pixel*)bm.bitmap;
	    Pixel bg_color;
	    bg_color[0] = PPM_GETR(background);
	    bg_color[1] = PPM_GETG(background);
	    bg_color[2] = PPM_GETB(background);

	    for (n = num_pixels - 1; n >= 0L; --n)
	    {
		Pixel p;

		PIXEL_SET(p, ptr[n]);
		if (!PIXEL_EQUAL(p, bg_color))
		{ 
		    /* we have a new colour in the image */ 
		    LOG3("Thinning colour (%x, %x, %x)\n", p[0], p[1], p[2]);
		    for (m = n - 1; m >= 0L; --m)
		    {
			if (PIXEL_EQUAL(ptr[m], p))
			    PIXEL_SET(ptr[m], bg_color);
		    }
		    thin3(image, p); 
		} 
	    } 
	    break;
	} 

	case 1:
	{
	    unsigned char * const ptr = bm.bitmap;
	    unsigned char bg_color;

	    if (PPM_ISGRAY(background))
            bg_color = PPM_GETR(background);
	    else
            bg_color = PPM_LUMIN(background);

	    for (n = num_pixels - 1; n >= 0L; --n)
	    {
		unsigned char c = ptr[n];
		if (c != bg_color)
		{ 
		    LOG1 ("Thinning colour %x\n", c);
		    for (m = n - 1; m >= 0L; --m)
			if (ptr[m] == c) ptr[m] = bg_color;
		    thin1(image, c); 
		} 
	    } 
	    break;
	} 

	default:
	{
	  LOG1 ("thin_image: %u-plane images are not supported", spp);
	  at_exception_fatal(exp, "thin_image: wrong plane images are passed");
	  goto cleanup;
	}
    }
 cleanup:
    free (bm.bitmap); 
}