Пример #1
0
static void
nova_center_update (GtkWidget  *widget,
                    NovaCenter *center,
                    gint        x,
                    gint        y)
{
  gint tx, ty;


  GimpPreviewArea *area = GIMP_PREVIEW_AREA (center->preview->area);
  GtkAllocation    allocation;

  gtk_widget_get_allocation (GTK_WIDGET (area), &allocation);

  x -= (allocation.width  - area->width)  / 2;
  y -= (allocation.height - area->height) / 2;

  gimp_preview_untransform (center->preview, x, y, &tx, &ty);

  g_signal_handlers_block_by_func (center->coords,
                                   nova_center_coords_update,
                                   center);

  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (center->coords), 0, tx);
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (center->coords), 1, ty);

  g_signal_handlers_unblock_by_func (center->coords,
                                     nova_center_coords_update,
                                     center);

  nova_center_coords_update (GIMP_SIZE_ENTRY (center->coords), center);

  gtk_widget_queue_draw (center->preview->area);
}
Пример #2
0
static gboolean
nova_center_update (GtkWidget  *widget,
                    NovaCenter *center,
                    gint        x,
                    gint        y)
{
  gint tx, ty;

  gimp_preview_untransform (center->preview, x, y, &tx, &ty);

  nova_center_cursor_draw (center);

  g_signal_handlers_block_by_func (center->coords,
                                   nova_center_coords_update,
                                   center);

  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (center->coords), 0, tx);
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (center->coords), 1, ty);

  g_signal_handlers_unblock_by_func (center->coords,
                                     nova_center_coords_update,
                                     center);

  nova_center_coords_update (GIMP_SIZE_ENTRY (center->coords), center);

  return TRUE;
}
Пример #3
0
static void
lens_distort_preview (GimpDrawable *drawable,
                      GimpPreview  *preview)
{
  guchar               *dest;
  guchar               *pixel;
  gint                  width, height, bpp;
  gint                  x, y;
  GimpPixelFetcher     *pft;
  GimpRGB               background;

  pft = gimp_pixel_fetcher_new (drawable, FALSE);

  gimp_context_get_background (&background);
  gimp_rgb_set_alpha (&background, 0.0);
  gimp_pixel_fetcher_set_bg_color (pft, &background);
  gimp_pixel_fetcher_set_edge_mode (pft, GIMP_PIXEL_FETCHER_EDGE_BACKGROUND);

  lens_setup_calc (drawable->width, drawable->height);

  dest = gimp_zoom_preview_get_source (GIMP_ZOOM_PREVIEW (preview),
                                       &width, &height, &bpp);
  pixel = dest;

  for (y = 0; y < height; y++)
    {
      for (x = 0; x < width; x++)
        {
          gint sx, sy;

          gimp_preview_untransform (preview, x, y, &sx, &sy);

          lens_distort_func (sx, sy, pixel, bpp, pft);

          pixel += bpp;
        }
    }

  gimp_pixel_fetcher_destroy (pft);

  gimp_preview_draw_buffer (preview, dest, width * bpp);
  g_free (dest);
}
Пример #4
0
static void
dialog_update_preview (GimpDrawable *drawable,
                       GimpPreview  *preview)
{
  gdouble               cx, cy;
  gint                  x, y;
  gint                  sx, sy;
  gint                  width, height;
  guchar               *pixel;
  guchar                outside[4];
  GimpRGB               background;
  guchar               *dest;
  gint                  j;
  gint                  bpp;
  GimpPixelFetcher     *pft;
  guchar                in_pixels[4][4];
  guchar               *in_values[4];

  for (j = 0; j < 4; j++)
    in_values[j] = in_pixels[j];

  pft = gimp_pixel_fetcher_new (drawable, FALSE);

  gimp_context_get_background (&background);
  gimp_rgb_set_alpha (&background, 0.0);
  gimp_drawable_get_color_uchar (drawable->drawable_id, &background, outside);
  gimp_pixel_fetcher_set_bg_color (pft, &background);
  gimp_pixel_fetcher_set_edge_mode (pft, GIMP_PIXEL_FETCHER_EDGE_SMEAR);

  dest = gimp_zoom_preview_get_source (GIMP_ZOOM_PREVIEW (preview),
                                       &width, &height, &bpp);
  pixel = dest;

  for (y = 0; y < height; y++)
    {
      for (x = 0; x < width; x++)
        {
          gimp_preview_untransform (preview, x, y, &sx, &sy);
          if (calc_undistorted_coords ((gdouble)sx, (gdouble)sy,
                                       &cx, &cy))
            {

              gimp_pixel_fetcher_get_pixel (pft, cx, cy, in_pixels[0]);
              gimp_pixel_fetcher_get_pixel (pft, cx + 1, cy, in_pixels[1]);
              gimp_pixel_fetcher_get_pixel (pft, cx, cy + 1, in_pixels[2]);
              gimp_pixel_fetcher_get_pixel (pft, cx + 1, cy + 1, in_pixels[3]);

              gimp_bilinear_pixels_8 (pixel, cx, cy, bpp,
                                      img_has_alpha, in_values);
            }
          else
            {
              for (j = 0; j < bpp; j++)
                pixel[j] = outside[j];
            }

          pixel += bpp;
        }
    }

  gimp_pixel_fetcher_destroy (pft);

  gimp_preview_draw_buffer (preview, dest, width * bpp);
  g_free (dest);
}