static gboolean
sel2path (gint32 image_ID)
{
  gint32                   selection_ID;
  pixel_outline_list_type  olt;
  spline_list_array_type   splines;

  gimp_selection_bounds (image_ID, &has_sel,
                         &sel_x1, &sel_y1, &sel_x2, &sel_y2);

  sel_width  = sel_x2 - sel_x1;
  sel_height = sel_y2 - sel_y1;

  /* Now get the selection channel */

  selection_ID = gimp_image_get_selection (image_ID);

  if (selection_ID < 0)
    return FALSE;

  sel_buffer = gimp_drawable_get_buffer (selection_ID);

  olt = find_outline_pixels ();

  splines = fitted_splines (olt);

  do_points (splines, image_ID);

  g_object_unref (sel_buffer);

  gimp_displays_flush ();

  return TRUE;
}
static gboolean
sel2path (gint32 image_ID)
{
  gint32                   selection_ID;
  GimpDrawable            *sel_drawable;
  pixel_outline_list_type  olt;
  spline_list_array_type   splines;

  gimp_selection_bounds (image_ID, &has_sel,
                         &sel_x1, &sel_y1, &sel_x2, &sel_y2);

  sel_width  = sel_x2 - sel_x1;
  sel_height = sel_y2 - sel_y1;

  /* Now get the selection channel */

  selection_ID = gimp_image_get_selection (image_ID);

  if (selection_ID < 0)
    return FALSE;

  sel_drawable = gimp_drawable_get (selection_ID);

  if (gimp_drawable_bpp (selection_ID) != 1)
    {
      g_warning ("Internal error. Selection bpp > 1");
      return FALSE;
    }

  gimp_pixel_rgn_init (&selection_rgn, sel_drawable,
                       sel_x1, sel_y1, sel_width, sel_height,
                       FALSE, FALSE);

  gimp_tile_cache_ntiles (2 * (sel_drawable->width + gimp_tile_width () - 1) /
                          gimp_tile_width ());

  olt = find_outline_pixels ();

  splines = fitted_splines (olt);

  do_points (splines, image_ID);

  gimp_drawable_detach (sel_drawable);

  gimp_displays_flush ();

  return TRUE;
}
Example #3
0
void
main (int argc, string argv[])
{
  int code;
  string font_name = read_command_line (argc, argv);
  bitmap_font_type f = get_bitmap_font (font_name, atou (dpi));
  string font_basename = basename (font_name);

  /* Initializing the display might involve forking a process.  We
     wouldn't want that process to get copies of open output files,
     since then when it exited, random stuff might get written to the
     end of the file.  */
  init_display (f);

  if (logging)
    log_file = xfopen (concat (font_basename, ".log"), "w");

  if (strlen (BITMAP_FONT_COMMENT (f)) > 0)
    REPORT1 ("{%s}\n", BITMAP_FONT_COMMENT (f));

  if (output_name == NULL)
    output_name = font_basename;

  bzr_start_output (output_name, f);

  /* The main loop: for each character, find the outline of the shape,
     then fit the splines to it.  */
  for (code = starting_char; code <= ending_char; code++)
    {
      pixel_outline_list_type pixels;
      spline_list_array_type splines;
      char_info_type *c = get_char (font_name, code);
    
      if (c == NULL) continue;

      REPORT1 ("[%u ", code);
      if (logging)
	{
	  LOG ("\n\n\f");
	  print_char (log_file, *c);
	}

      x_start_char (*c);
      pixels = find_outline_pixels (*c);
      /* `find_outline_pixels' uses corners as the coordinates, instead
         of the pixel centers.  So we have to increase the bounding box.  */
      CHAR_MIN_COL (*c)--; CHAR_MAX_COL (*c)++;
      CHAR_MIN_ROW (*c)--; CHAR_MAX_ROW (*c)++;

      REPORT ("|");
      splines = fitted_splines (pixels);

      bzr_output_char (*c, splines);
      
      /* Flush output before displaying the character, in case the user
         is interested in looking at it and the online version
         simultaneously.  */
      flush_log_output ();

      x_output_char (*c, splines);
      REPORT ("]\n");

      /* If the character was empty, it won't have a bitmap.  */
      if (BITMAP_BITS (CHAR_BITMAP (*c)) != NULL)
        free_bitmap (&CHAR_BITMAP (*c));

      free_pixel_outline_list (&pixels);
      free_spline_list_array (&splines);
    }

  bzr_finish_output ();
  close_display ();

  close_font (font_name);

  exit (0);
}
Example #4
0
/* at_splines_new_full modify its argument: BITMAP
   when despeckle, quantize and/or thin_image are invoked. */
at_splines_type *
at_splines_new_full (at_bitmap * bitmap,
                     at_fitting_opts_type * opts,
                     at_msg_func msg_func,
                     gpointer msg_data,
                     at_progress_func notify_progress,
                     gpointer progress_data,
                     at_testcancel_func test_cancel,
                     gpointer testcancel_data)
{
    image_header_type image_header;
    at_splines_type * splines = NULL;
    pixel_outline_list_type pixels;
    QuantizeObj *myQuant = NULL; /* curently not used */
    at_exception_type exp     = at_exception_new(msg_func, msg_data);
    at_distance_map dist_map, *dist = NULL;

#define CANCELP (test_cancel && test_cancel(testcancel_data))
#define FATALP  (at_exception_got_fatal(&exp))
#define FREE_SPLINE() do {if (splines) {at_splines_free(splines); splines = NULL;}} while(0)

#define CANCEL_THEN_CLEANUP_DIST() if (CANCELP) goto cleanup_dist;
#define CANCEL_THEN_CLEANUP_PIXELS() if (CANCELP) {FREE_SPLINE(); goto cleanup_pixels;}

#define FATAL_THEN_RETURN() if (FATALP) return splines;
#define FATAL_THEN_CLEANUP_DIST() if (FATALP) goto cleanup_dist;
#define FATAL_THEN_CLEANUP_PIXELS() if (FATALP) {FREE_SPLINE(); goto cleanup_pixels;}

    if (opts->despeckle_level > 0)
    {
        despeckle (bitmap,
                   opts->despeckle_level,
                   opts->despeckle_tightness,
                   opts->noise_removal,
                   &exp);
        FATAL_THEN_RETURN();
    }

    image_header.width = at_bitmap_get_width(bitmap);
    image_header.height = at_bitmap_get_height(bitmap);

    if (opts->color_count > 0)
    {
        quantize (bitmap, opts->color_count, opts->background_color, &myQuant, &exp);
        if (myQuant)
            quantize_object_free(myQuant); /* curently not used */
        FATAL_THEN_RETURN();
    }

    if (opts->centerline)
    {
        if (opts->preserve_width)
        {
            /* Preserve line width prior to thinning. */
            dist_map = new_distance_map(bitmap, 255, /*padded=*/TRUE, &exp);
            dist = &dist_map;
            FATAL_THEN_RETURN();
        }
        /* Hereafter, dist is allocated. dist must be freed if
        the execution is canceled or exception is raised;
         use FATAL_THEN_CLEANUP_DIST. */
        thin_image (bitmap, opts->background_color, &exp);
        FATAL_THEN_CLEANUP_DIST()
    }

    /* Hereafter, pixels is allocated. pixels must be freed if
       the execution is canceled; use CANCEL_THEN_CLEANUP_PIXELS. */
    if (opts->centerline)
    {
        at_color background_color = { 0xff, 0xff, 0xff };
        if (opts->background_color)
            background_color = *opts->background_color;

        pixels = find_centerline_pixels(bitmap, background_color,
                                        notify_progress, progress_data,
                                        test_cancel, testcancel_data, &exp);
    }
    else
        pixels = find_outline_pixels(bitmap, opts->background_color,
                                     notify_progress, progress_data,
                                     test_cancel, testcancel_data, &exp);
    FATAL_THEN_CLEANUP_DIST();
    CANCEL_THEN_CLEANUP_DIST();

    XMALLOC(splines, sizeof(at_splines_type));
    *splines = fitted_splines (pixels, opts, dist,
                               image_header.width,
                               image_header.height,
                               &exp,
                               notify_progress, progress_data,
                               test_cancel, testcancel_data);
    FATAL_THEN_CLEANUP_PIXELS();
    CANCEL_THEN_CLEANUP_PIXELS();

    if (notify_progress)
        notify_progress(1.0, progress_data);

cleanup_pixels:
    free_pixel_outline_list (&pixels);
cleanup_dist:
    if (dist)
        free_distance_map (dist);
    return splines;
#undef CANCELP
#undef FATALP
#undef FREE_SPLINE
#undef CANCEL_THEN_CLEANUP_DIST
#undef CANCEL_THEN_CLEANUP_PIXELS

#undef FATAL_THEN_RETURN
#undef FATAL_THEN_CLEANUP_DIST
#undef FATAL_THEN_CLEANUP_PIXELS

}