Beispiel #1
0
static void
updatesmpreviewprev (void)
{
  gint         x, y;
  static ppm_t nsbuffer;
  guchar       black[3] = {0, 0, 0};
  guchar       gray[3]  = {120, 120, 120};

  if (! PPM_IS_INITED (&nsbuffer))
    {
      ppm_new (&nsbuffer, OMWIDTH, OMHEIGHT);
    }
  fill (&nsbuffer, black);

  for (y = 6; y < OMHEIGHT-4; y += 10)
    {
      for (x = 6; x < OMWIDTH-4; x += 10)
         {
           gdouble siz = 5 * getsiz_from_gui (x / (double)OMWIDTH,
                                              y / (double)OMHEIGHT);
           ppm_drawline (&nsbuffer, x-siz, y-siz, x+siz, y-siz, gray);
           ppm_drawline (&nsbuffer, x+siz, y-siz, x+siz, y+siz, gray);
           ppm_drawline (&nsbuffer, x+siz, y+siz, x-siz, y+siz, gray);
           ppm_drawline (&nsbuffer, x-siz, y+siz, x-siz, y-siz, gray);
         }
    }


  gimp_preview_area_draw (GIMP_PREVIEW_AREA (smpreviewprev),
                          0, 0, OMWIDTH, OMHEIGHT,
                          GIMP_RGB_IMAGE,
                          nsbuffer.col,
                          OMWIDTH * 3);
}
Beispiel #2
0
static void
update_vector_prev (void)
{
  static gint    ok = 0;
  gint           i, x, y;
  gdouble        dir, xo, yo;
  gdouble        val;
  static gdouble last_val = 0.0;
  guchar         gray[3]  = {120, 120, 120};
  guchar         red[3]   = {255, 0, 0};
  guchar         white[3] = {255, 255, 255};

  if (vector_preview_brightness_adjust)
    val = 1.0 - gtk_adjustment_get_value (GTK_ADJUSTMENT (vector_preview_brightness_adjust)) / 100.0;
  else
    val = 0.5;

  if (!ok || (val != last_val))
    {
      infile_copy_to_ppm (&update_vector_preview_backup);
      ppm_apply_brightness (&update_vector_preview_backup, val, 1,1,1);

      if ((update_vector_preview_backup.width != OMWIDTH) ||
          (update_vector_preview_backup.height != OMHEIGHT))
        resize_fast (&update_vector_preview_backup, OMWIDTH, OMHEIGHT);
      ok = 1;
    }
  ppm_copy (&update_vector_preview_backup, &update_vector_preview_buffer);

  for (i = 0; i < num_vectors; i++)
    {
      gdouble s;

      x = vector[i].x * OMWIDTH;
      y = vector[i].y * OMHEIGHT;
      dir = gimp_deg_to_rad (vector[i].dir);
      s = gimp_deg_to_rad (vector[i].str);
      xo = sin (dir) * (6.0+100*s);
      yo = cos (dir) * (6.0+100*s);

      if (i == selectedvector)
        {
          ppm_drawline (&update_vector_preview_buffer,
                        x - xo, y - yo, x + xo, y + yo, red);
        }
      else
        {
          ppm_drawline (&update_vector_preview_buffer,
                        x - xo, y - yo, x + xo, y + yo, gray);
        }
      ppm_put_rgb (&update_vector_preview_buffer, x - xo, y - yo, white);
  }

  gimp_preview_area_draw (GIMP_PREVIEW_AREA (vector_preview),
                          0, 0, OMWIDTH, OMHEIGHT,
                          GIMP_RGB_IMAGE,
                          (guchar *)update_vector_preview_buffer.col,
                          OMWIDTH * 3);
}
/*  Private functions  */
static void draw_preview_area_update(GtkWidget *preview, GimpDrawable *drawable) {
    if(is_3D_preview_active())
    {
        /** Adding all references to preview for second release. */
        if ((local_vals.image_ID != 0) && (drawable != NULL))
        {
            update_preview = 0;
            if (drawable->bpp == 3) {
                GimpPixelRgn amap_rgn;
                gint rowbytes = PREVIEW_SIZE * 3;
                gint nbytes = drawable->width * drawable->height * 3;
                guchar *tmp = g_new(guchar, nbytes);
                guchar dst[PREVIEW_RGB_SIZE];

                gimp_pixel_rgn_init(&amap_rgn, drawable, 0, 0, drawable->width, drawable->height, 0, 0);
                gimp_pixel_rgn_get_rect(&amap_rgn, tmp, 0, 0, drawable->width, drawable->height);

                scale_pixels(dst, PREVIEW_SIZE, PREVIEW_SIZE, tmp, drawable->width, drawable->height, drawable->bpp);

                gimp_preview_area_draw(GIMP_PREVIEW_AREA(preview), 0, 0, PREVIEW_SIZE, PREVIEW_SIZE,
                                       GIMP_RGB_IMAGE, dst, rowbytes);
                gtk_widget_queue_draw (preview);
                g_free (tmp);
                _active = 'w';
            } else if (drawable->bpp == 4) {
                GimpPixelRgn amap_rgn;
                gint rowbytes = PREVIEW_SIZE * 4;
                gint nbytes = drawable->width * drawable->height * 4;
                guchar *tmp = g_new(guchar, nbytes);
                guchar dst[PREVIEW_RGBA_SIZE];

                gimp_pixel_rgn_init(&amap_rgn, drawable, 0, 0, drawable->width, drawable->height, 0, 0);
                gimp_pixel_rgn_get_rect(&amap_rgn, tmp, 0, 0, drawable->width, drawable->height);

                scale_pixels(dst, PREVIEW_SIZE, PREVIEW_SIZE, tmp, drawable->width, drawable->height, drawable->bpp);

                gimp_preview_area_draw(GIMP_PREVIEW_AREA(preview), 0, 0, PREVIEW_SIZE, PREVIEW_SIZE,
                                     GIMP_RGBA_IMAGE, dst, rowbytes);
                
                gtk_widget_queue_draw (preview);
                g_free (tmp);
                _active = 'w';
            }
        }
    }
}
void renderPreview(PlugInVals *vals) {
	gint    y,k,j;
	guchar *imageRow;
	guchar *resultRow;
	guchar *maskRow;
	guchar *stopRow;
	guchar *resultRGBA;
#ifdef DEBUG
	g_warning("renderPreview");
#endif

	resultRGBA = g_new (guchar, 4 * interface_vals.previewWidth *
			interface_vals.previewHeight);

	for (y = 0; y < interface_vals.previewHeight; y++)
	{
		imageRow =
				&(interface_vals.previewImage[  y * interface_vals.previewWidth * 4]);

		maskRow =
				&(interface_vals.previewMask[y * interface_vals.previewWidth  ]);

		stopRow =
				&(interface_vals.previewStopPath[y * interface_vals.previewWidth  ]);

		resultRow =
				&(resultRGBA[  y * interface_vals.previewWidth * 4]);

		for (k = 0, j=0; k < interface_vals.previewWidth; ++k,j+=4) {
			if (maskRow[k] > vals->threshold) {

				resultRow[j] = 0;
				resultRow[j+1] = 0;
				resultRow[j+2] = 0;
				if (stopRow[k] > 0) {
					resultRow[j+3] = 255;
				} else {
					resultRow[j+3] = 0;
				}
			} else {
				resultRow[j] = imageRow[j];
				resultRow[j+1] = imageRow[j+1];
				resultRow[j+2] = imageRow[j+2];
				resultRow[j+3] = imageRow[j+3];;
			}
		}
	}
	gimp_preview_area_draw (GIMP_PREVIEW_AREA (interface_vals.preview_widget),
			0, 0,
			interface_vals.previewWidth,
			interface_vals.previewHeight,
			GIMP_RGBA_IMAGE,
			resultRGBA,
			interface_vals.previewWidth * 4);
	g_free(resultRGBA);
}
Beispiel #5
0
static void
wmf_preview_callback (GtkWidget     *widget,
                      GtkAllocation *allocation,
                      guchar        *pixels)
{
  gimp_preview_area_draw (GIMP_PREVIEW_AREA (widget),
                          0, 0, allocation->width, allocation->height,
                          GIMP_RGBA_IMAGE,
                          pixels, allocation->width * 4);
}
Beispiel #6
0
static void
color_to_alpha_preview (GimpPreview  *preview,
                        GimpDrawable *drawable)
{
  GimpPixelRgn  src_rgn;
  gint          x, y;
  gint          width, height;
  gint          bpp;
  gint          i;
  guchar       *src, *dest;

  bpp = drawable->bpp;
  gimp_preview_get_position (preview, &x, &y);
  gimp_preview_get_size (preview, &width, &height);

  dest = g_new (guchar, width * height * 4);
  src = g_new (guchar, width * height * bpp);

  gimp_pixel_rgn_init (&src_rgn, drawable,
                       x, y, width, height,
                       FALSE, FALSE);
  gimp_pixel_rgn_get_rect (&src_rgn, src, x, y, width, height);

  for (i = 0; i < width * height; i++)
    to_alpha_func (src + i * bpp, dest + i * 4, bpp, NULL);

  g_free (src);

  /* Our code assumes that the drawable has an alpha channel (and adds
   * one later if the effect is actually performed). For that reason
   * we have to take care when drawing the preview.
   */
  if (bpp == 4)
    {
      gimp_preview_draw_buffer (preview, dest, width * 4);
    }
  else
    {
      /* This is not correct because we ignore the selection, but it
       * is the best we can easily do.
       */
      gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview->area),
                              0, 0, width, height,
                              GIMP_RGBA_IMAGE, dest, width * 4);
    }

  g_free (dest);
}
static void
gimp_aspect_preview_draw_buffer (GimpPreview  *preview,
                                 const guchar *buffer,
                                 gint          rowstride)
{
  GimpDrawable *drawable = GIMP_ASPECT_PREVIEW (preview)->drawable;
  gint32        image_id;

  image_id = gimp_item_get_image (drawable->drawable_id);

  if (gimp_selection_is_empty (image_id))
    {
      gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview->area),
                              0, 0,
                              preview->width, preview->height,
                              gimp_drawable_type (drawable->drawable_id),
                              buffer,
                              rowstride);
    }
  else
    {
      guchar *sel;
      guchar *src;
      gint    selection_id;
      gint    width, height;
      gint    bpp;

      selection_id = gimp_image_get_selection (image_id);

      width  = preview->width;
      height = preview->height;

      src = gimp_drawable_get_thumbnail_data (drawable->drawable_id,
                                              &width, &height, &bpp);
      sel = gimp_drawable_get_thumbnail_data (selection_id,
                                              &width, &height, &bpp);

      gimp_preview_area_mask (GIMP_PREVIEW_AREA (preview->area),
                              0, 0, preview->width, preview->height,
                              gimp_drawable_type (drawable->drawable_id),
                              src, width * drawable->bpp,
                              buffer, rowstride,
                              sel, width);

      g_free (sel);
      g_free (src);
    }
}
Beispiel #8
0
static gboolean
area_realize (GimpPreviewArea *area)
{
  GdkPixbuf *pixbuf;

  pixbuf = load_image ("wilber-wizard.png");
  gimp_preview_area_draw (GIMP_PREVIEW_AREA (area), 0, 0,
                          gdk_pixbuf_get_width (pixbuf),
                          gdk_pixbuf_get_height (pixbuf),
                          GIMP_RGBA_IMAGE,
                          gdk_pixbuf_get_pixels (pixbuf),
                          gdk_pixbuf_get_rowstride (pixbuf));
  g_object_unref (pixbuf);

  return FALSE;
}
Beispiel #9
0
static void
render_gray_image(Preview_t *preview_base, GimpPixelRgn *srcrgn)
{
    guchar        *src_row, *dest_buffer, *src, *dest;
    gint          row, col;
    gint          bpp, dwidth, dheight, pwidth, pheight;
    gint          *src_col;
    GtkWidget     *preview = preview_base->preview;

    dwidth  = srcrgn->w;
    dheight = srcrgn->h;
    pwidth = preview_base->widget_width;
    pheight = preview_base->widget_height;
    bpp = srcrgn->bpp;

    src_row = g_new(guchar, dwidth * bpp);
    dest_buffer = g_new(guchar, pwidth * pheight);
    src_col = g_new(gint, pwidth);

    for (col = 0; col < pwidth; col++)
        src_col[col] = (col * dwidth / pwidth) * bpp;

    dest = dest_buffer;

    for (row = 0; row < pheight; row++) {
        gimp_pixel_rgn_get_row(srcrgn, src_row, 0, row * dheight / pheight,
                               dwidth);

        src = src_row;

        for (col = 0; col < pwidth; col++) {
            src = &src_row[src_col[col]];
            *dest++ = *src;
        }
    }
    gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
                            0, 0, pwidth, pheight,
                            GIMP_GRAY_IMAGE,
                            dest_buffer,
                            pwidth);
    g_free(src_col);
    g_free(src_row);
    g_free(dest_buffer);

}
Beispiel #10
0
static void
update_orient_map_preview_prev (void)
{
  int    x, y;
  guchar black[3] = {0, 0, 0};
  guchar gray[3] = {120, 120, 120};
  guchar white[3] = {255, 255, 255};

  if (!PPM_IS_INITED (&update_om_preview_nbuffer))
    ppm_new (&update_om_preview_nbuffer,OMWIDTH,OMHEIGHT);

  fill (&update_om_preview_nbuffer, black);

  for (y = 6; y < OMHEIGHT-4; y += 10)
    for (x = 6; x < OMWIDTH-4; x += 10)
      {
        double dir =
          gimp_deg_to_rad (get_direction (x / (double)OMWIDTH,
                                          y / (double)OMHEIGHT,0));
        double xo = sin (dir) * 4.0;
        double yo = cos (dir) * 4.0;
        ppm_drawline (&update_om_preview_nbuffer,
                      x - xo, y - yo, x + xo, y + yo,
                      gray);
        ppm_put_rgb (&update_om_preview_nbuffer,
                     x - xo, y - yo,
                     white);
      }

  gimp_preview_area_draw (GIMP_PREVIEW_AREA (orient_map_preview_prev),
                          0, 0, OMWIDTH, OMHEIGHT,
                          GIMP_RGB_IMAGE,
                          (guchar *)update_om_preview_nbuffer.col,
                          OMWIDTH * 3);

  gtk_widget_queue_draw (orient_map_preview_prev);

  gtk_widget_set_sensitive (prev_button, (num_vectors > 1));
  gtk_widget_set_sensitive (next_button, (num_vectors > 1));
  gtk_widget_set_sensitive (add_button, (num_vectors < MAXORIENTVECT));
  gtk_widget_set_sensitive (kill_button, (num_vectors > 1));
}
Beispiel #11
0
void
sinus_do_preview (GtkWidget *widget)
{
  static GtkWidget *theWidget = NULL;
  gint              rowsize;
  guchar           *buf;
  params            p;

  if (!do_preview)
    return;

  if (theWidget == NULL)
    {
      theWidget = widget;
    }

  rowsize = thePreview->width * thePreview->bpp;
  buf = g_new (guchar, thePreview->width*thePreview->height*thePreview->bpp);

  p.height = thePreview->height;
  p.width = thePreview->width;

  prepare_coef (&p);

  if (thePreview->bpp == 3) /* [dindinx]: it looks to me that this is always true... */
    compute_block_x (buf, rowsize, 0, 0, thePreview->width, thePreview->height,
                     3, assign_block_3, &p);
  else if (thePreview->bpp == 1)
    {
      compute_block_x (buf, rowsize, 0, 0, thePreview->width,
                       thePreview->height, 1, assign_block_1, &p);
    }

  gimp_preview_area_draw (GIMP_PREVIEW_AREA (theWidget),
                          0, 0, thePreview->width, thePreview->height,
                          GIMP_RGB_IMAGE,
                          buf,
                          rowsize);
  g_free (buf);
}
void
rcm_render_circle (GtkWidget *preview,
		   int        sum,
		   int        margin)
{
  gint i, j;
  gdouble h, s, v;
  guchar *a;

  if (preview == NULL) return;

  a = g_new (guchar, 3*sum*sum);

  for (j = 0; j < sum; j++)
    {
      for (i = 0; i < sum; i++)
        {
          s = sqrt ((SQR (i - sum / 2.0) + SQR (j - sum / 2.0)) / (float) SQR (sum / 2.0 - margin));
          if (s > 1)
            {
              a[(j*sum+i)*3+0] = 255;
              a[(j*sum+i)*3+1] = 255;
              a[(j*sum+i)*3+2] = 255;
            }
          else
            {
              h = arctg (sum / 2.0 - j, i - sum / 2.0) / (2 * G_PI);
              v = 1 - sqrt (s) / 4;
              gimp_hsv_to_rgb4 (&a[(j*sum+i)*3], h, s, v);
            }
        }
    }
  gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
                          0, 0, sum, sum,
                          GIMP_RGB_IMAGE,
                          a,
                          sum * 3);
  g_free (a);
}
Beispiel #13
0
static void
dialog_update_previews (GtkWidget *widget,
                        gpointer   data)
{
  gint i, j;
  guchar buf[PREVIEW_SIZE * PREVIEW_SIZE * 3];

  for (j = 0; j < 9; j++)
    {
      optimize (&info[(j + 5) % 9]);
      for (i = 0; i < PREVIEW_SIZE; i++)
        {
          qbist (&info[(j + 5) % 9], buf + i * PREVIEW_SIZE * 3,
                 0, i, PREVIEW_SIZE, PREVIEW_SIZE, PREVIEW_SIZE, 3, 1);
        }
      gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview[j]),
                              0, 0, PREVIEW_SIZE, PREVIEW_SIZE,
                              GIMP_RGB_IMAGE,
                              buf,
                              PREVIEW_SIZE *3);
    }
}
Beispiel #14
0
static void paper_update_preview (void)
{
  gint     i, j;
  guchar  *buf, *paper_preview_buffer;
  gdouble  sc;
  ppm_t    p = {0, 0, NULL};

  ppm_load (pcvals.selected_paper, &p);
  sc = p.width > p.height ? p.width : p.height;
  sc = 100.0 / sc;
  resize (&p, p.width*sc,p.height*sc);

  paper_preview_buffer = g_new0 (guchar, 100*100);

  for (i = 0, buf = paper_preview_buffer; i < 100; i++, buf += 100)
    {
      gint k = i * p.width * 3;

      if (i < p.height)
        {
          for (j = 0; j < p.width; j++)
            buf[j] = p.col[k + j * 3];
          if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (paper_invert)))
            for (j = 0; j < p.width; j++)
              buf[j] = 255 - buf[j];
        }
    }
  gimp_preview_area_draw (GIMP_PREVIEW_AREA (paper_preview),
                          0, 0, 100, 100,
                          GIMP_GRAY_IMAGE,
                          paper_preview_buffer,
                          100);

  ppm_kill (&p);
  g_free (paper_preview_buffer);

  gtk_widget_queue_draw (paper_preview);
}
/* render before/after preview */
void
rcm_render_preview (GtkWidget *preview)
{
  ReducedImage *reduced;
  gint          version;
  gint          RW, RH, bytes, i, j;
  guchar       *a;
  guchar       *rgb_array;
  gdouble      *hsv_array;
  gfloat        degree;

  g_return_if_fail (preview != NULL);

  version = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (preview), "mode"));

  reduced   = Current_c.reduced;
  RW        = reduced->width;
  RH        = reduced->height;
  bytes     = Current_c.drawable->bpp;
  hsv_array = reduced->hsv;
  rgb_array = reduced->rgb;

  a = g_new (guchar, 4 * RW * RH);

  if (version == CURRENT)
    {
      gdouble H, S, V;
      guchar  rgb[3];

      for (i = 0; i < RH; i++)
        {
          for (j = 0; j < RW; j++)
            {
              gboolean unchanged = FALSE;
              gboolean skip      = FALSE;

              H = hsv_array[i*RW*bytes + j*bytes + 0];
              S = hsv_array[i*RW*bytes + j*bytes + 1];
              V = hsv_array[i*RW*bytes + j*bytes + 2];

              if (rcm_is_gray(S) && (reduced->mask[i*RW+j] != 0))
                {
                  switch (Current_c.Gray_to_from)
                    {
                    case GRAY_FROM:
                      if (rcm_angle_inside_slice (Current_c.Gray->hue,
                                                  Current_c.From->angle) <= 1)
                        {
                          H = Current_c.Gray->hue/TP;
                          S = Current_c.Gray->satur;
                        }
                      else
                        skip = TRUE;
                      break;

                    case GRAY_TO:
                      unchanged = FALSE;
                      skip = TRUE;
                      gimp_hsv_to_rgb4 (rgb,
                                        Current_c.Gray->hue/TP,
                                        Current_c.Gray->satur,
                                        V);
                      break;

                    default:
                      break;
                    }
                }

              if (!skip)
                {
                  unchanged = FALSE;
                  H = rcm_linear (rcm_left_end (Current_c.From->angle),
                                  rcm_right_end (Current_c.From->angle),
                                  rcm_left_end (Current_c.To->angle),
                                  rcm_right_end (Current_c.To->angle),
                                  H * TP);

                  H = angle_mod_2PI(H) / TP;
                  gimp_hsv_to_rgb4 (rgb, H,S,V);
                }

              if (unchanged)
                degree = 0;
              else
                degree = reduced->mask[i*RW+j] / 255.0;

              a[(i*RW+j)*4+0] = (1-degree) * rgb_array[i*RW*bytes + j*bytes + 0] + degree * rgb[0];
              a[(i*RW+j)*4+1] = (1-degree) * rgb_array[i*RW*bytes + j*bytes + 1] + degree * rgb[1];
              a[(i*RW+j)*4+2] = (1-degree) * rgb_array[i*RW*bytes + j*bytes + 2] + degree * rgb[2];

              /* apply transparency */
              if (bytes == 4)
                a[(i*RW+j)*4+3] = rgb_array[i*RW*bytes+j*bytes+3];
              else
                a[(i*RW+j)*4+3] = 255;
            }
        }
    }
  else /* ORIGINAL */
    {
      for (i = 0; i < RH; i++)
        {
          for (j = 0; j < RW; j++)
            {
              a[(i*RW+j)*4+0] = rgb_array[i*RW*bytes + j*bytes + 0];
              a[(i*RW+j)*4+1] = rgb_array[i*RW*bytes + j*bytes + 1];
              a[(i*RW+j)*4+2] = rgb_array[i*RW*bytes + j*bytes + 2];

              if (bytes == 4)
                a[(i*RW+j)*4+3] = rgb_array[i*RW*bytes+j*bytes+3];
              else
                a[(i*RW+j)*4+3] = 255;
            }
        }
    }

  gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
                          0, 0, RW, RH,
                          GIMP_RGBA_IMAGE,
                          a,
                          RW * 4);
  g_free (a);
}
Beispiel #16
0
static void
render_rgb_image(Preview_t *preview_base, GimpPixelRgn *srcrgn)
{
   guchar        *src_row, *dest_buffer, *src, *dest;
   gint          row, col;
   gint          dwidth, dheight, pwidth, pheight;
   gint          *src_col;
   gint          bpp, alpha, has_alpha, b;
   guchar        check;
   gboolean      gray = get_map_info()->show_gray;
   GtkWidget    *preview = preview_base->preview;

   dwidth  = srcrgn->w;
   dheight = srcrgn->h;
   pwidth = preview_base->widget_width;
   pheight = preview_base->widget_height;
   bpp = srcrgn->bpp;
   alpha = bpp;
   has_alpha = gimp_drawable_has_alpha(srcrgn->drawable->drawable_id);
   if (has_alpha)
      alpha--;

   src_row = g_new(guchar, dwidth * bpp);
   dest_buffer = g_new(guchar, pwidth * pheight * bpp);
   src_col = g_new(gint, pwidth);

   for (col = 0; col < pwidth; col++)
      src_col[col] = (col * dwidth / pwidth) * bpp;

   dest = dest_buffer;
   for (row = 0; row < pheight; row++) {
      gimp_pixel_rgn_get_row(srcrgn, src_row, 0, row * dheight / pheight,
                             dwidth);
      for (col = 0; col < pwidth; col++) {
         src = &src_row[src_col[col]];
         if(!has_alpha || src[alpha] == OPAQUE) {
            /* no alpha channel or opaque -- simple way */
            for (b = 0; b < alpha; b++)
               dest[b] = src[b];
         } else {
            /* more or less transparent */
            if( ( col % (CHECKWIDTH*2) < CHECKWIDTH ) ^
                ( row % (CHECKWIDTH*2) < CHECKWIDTH ) )
               check = LIGHTCHECK;
            else
               check = DARKCHECK;

            if (src[alpha] == 0) {
               /* full transparent -- check */
               for (b = 0; b < alpha; b++)
                  dest[b] = check;
            } else {
               /* middlemost transparent -- mix check and src */
               for (b = 0; b < alpha; b++)
                  dest[b] = (src[b] * src[alpha] +
                             check * (OPAQUE - src[alpha])) / OPAQUE;
            }
         }
         if (gray) {
            guchar avg;
            avg = (299 * dest[0] + 587 * dest[1] + 114 * dest[2]) / 1000;
            for (b = 0; b < alpha; b++)
               dest[b] = avg;
         }
         dest += alpha;
      }
   }
   gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
                           0, 0, pwidth, pheight,
                           GIMP_RGB_IMAGE,
                           dest_buffer,
                           pwidth * 3);
   g_free(src_col);
   g_free(src_row);
   g_free(dest_buffer);
}
Beispiel #17
0
static void
render_indexed_image(Preview_t *preview_base, GimpPixelRgn *srcrgn)
{
   guchar        *src_row, *dest_buffer, *src, *dest;
   gint          row, col;
   gint          dwidth, dheight, pwidth, pheight;
   gint          *src_col;
   gint          bpp, alpha, has_alpha;
   guchar        *cmap, *colour;
   gint          ncols;
   gboolean      gray = get_map_info()->show_gray;
   GtkWidget    *preview = preview_base->preview;

   dwidth  = srcrgn->w;
   dheight = srcrgn->h;
   pwidth = preview_base->widget_width;
   pheight = preview_base->widget_height;
   bpp = srcrgn->bpp;
   alpha = bpp;
   has_alpha = gimp_drawable_has_alpha(srcrgn->drawable->drawable_id);
   if (has_alpha)
      alpha--;

   cmap = gimp_image_get_colormap (gimp_item_get_image (srcrgn->drawable->drawable_id),
                                   &ncols);

   src_row = g_new(guchar, dwidth * bpp);
   dest_buffer = g_new(guchar, pwidth * pheight * 3);
   src_col = g_new(gint, pwidth);

   for (col = 0; col < pwidth; col++)
      src_col[col] = (col * dwidth / pwidth) * bpp;

   dest = dest_buffer;
   for (row = 0; row < pheight; row++) {
      gimp_pixel_rgn_get_row(srcrgn, src_row, 0, row * dheight / pheight,
                             dwidth);

      for (col = 0; col < pwidth; col++) {
         src = &src_row[src_col[col]];
         colour = cmap + 3 * (int)(*src);

         if (gray) {
            guchar avg = (299 * colour[0] + 587 * colour[1] +
                          114 * colour[2]) / 1000;
            *dest++ = avg;
            *dest++ = avg;
            *dest++ = avg;
         } else {
            *dest++ = colour[0];
            *dest++ = colour[1];
            *dest++ = colour[2];
         }
      }
   }
   gimp_preview_area_draw(GIMP_PREVIEW_AREA(preview),
                          0, 0, pwidth, pheight,
                          GIMP_RGB_IMAGE,
                          dest_buffer,
                          pwidth * 3);
   g_free(src_col);
   g_free(src_row);
   g_free(dest_buffer);
}
Beispiel #18
0
static void
updatesmvectorprev (void)
{
  static int     ok = 0;
  gint           i, x, y;
  gdouble        val;
  static gdouble last_val = 0.0;
  guchar         gray[3]  = {120, 120, 120};
  guchar         red[3]   = {255, 0, 0};
  guchar         white[3] = {255, 255, 255};

  if (smvectprevbrightadjust)
    val = 1.0 - gtk_adjustment_get_value (GTK_ADJUSTMENT (smvectprevbrightadjust)) / 100.0;
  else
    val = 0.5;

  if (!ok || (val != last_val))
    {
#if 0
      if (!PPM_IS_INITED (&infile))
         updatepreview (NULL, (void *)2); /* Force grabarea () */
      ppm_copy (&infile, &update_vector_preview_backup);
#else
      infile_copy_to_ppm (&update_vector_preview_backup);
#endif
      ppm_apply_brightness (&update_vector_preview_backup, val, 1,1,1);

      if (update_vector_preview_backup.width != OMWIDTH ||
          update_vector_preview_backup.height != OMHEIGHT)
         resize_fast (&update_vector_preview_backup, OMWIDTH, OMHEIGHT);

      ok = 1;
  }
  ppm_copy (&update_vector_preview_backup, &update_vector_preview_sbuffer);

  for (i = 0; i < numsmvect; i++)
    {
      x = smvector[i].x * OMWIDTH;
      y = smvector[i].y * OMHEIGHT;
      if (i == selectedsmvector)
      {
         ppm_drawline (&update_vector_preview_sbuffer, x-5, y, x+5, y, red);
         ppm_drawline (&update_vector_preview_sbuffer, x, y-5, x, y+5, red);
      }
      else
      {
         ppm_drawline (&update_vector_preview_sbuffer, x-5, y, x+5, y, gray);
         ppm_drawline (&update_vector_preview_sbuffer, x, y-5, x, y+5, gray);
      }
      ppm_put_rgb (&update_vector_preview_sbuffer, x, y, white);
  }

  gimp_preview_area_draw (GIMP_PREVIEW_AREA (smvectorprev),
                          0, 0, OMWIDTH, OMHEIGHT,
                          GIMP_RGB_IMAGE,
                          update_vector_preview_sbuffer.col,
                          OMWIDTH * 3);

  gtk_widget_set_sensitive (prev_button, (numsmvect > 1));
  gtk_widget_set_sensitive (next_button, (numsmvect > 1));
  gtk_widget_set_sensitive (add_button, (numsmvect < MAXORIENTVECT));
  gtk_widget_set_sensitive (kill_button, (numsmvect > 1));
}
/* fill our preview image with the color-histogram */
static void
fillPreview (GtkWidget *preview)
{
  guchar  *image, *column, *pixel;
  gint     x, y, rowstride;
  gdouble  histcount, val;

  rowstride = PREWIDTH * 3;

  image = g_new0 (guchar, PREWIDTH * rowstride);

  for (x = 0, column = image; x < PREWIDTH; x++, column += 3)
    {
      /*
       * For every channel, calculate a logarithmic value, scale it,
       * and build a one-pixel bar.
       *  ... in the respective channel, preserving the other ones. --hb
       */
      histcount = hist_red[x] > 1.0 ? hist_red[x] : 1.0;

      val = log (histcount) * (PREHEIGHT / 12);

      if (val > PREHEIGHT)
        val = PREHEIGHT;

      y = PREHEIGHT - 1;
      pixel = column + (y * rowstride);
      for (; y > (PREHEIGHT - val); y--)
        {
          pixel[0] = 255;
          pixel -= rowstride;
        }

      histcount = hist_green[x] > 1.0 ? hist_green[x] : 1.0;

      val = log (histcount) * (PREHEIGHT / 12);

      if (val > PREHEIGHT)
        val = PREHEIGHT;

      y = PREHEIGHT - 1;
      pixel = column + (y * rowstride);
      for (; y > (PREHEIGHT - val); y--)
        {
          pixel[1] = 255;
          pixel -= rowstride;
        }

      histcount = hist_blue[x] > 1.0 ? hist_blue[x] : 1.0;

      val = log (histcount) * (PREHEIGHT / 12);

      if (val > PREHEIGHT)
        val = PREHEIGHT;

      y = PREHEIGHT - 1;
      pixel = column + (y * rowstride);
      for (; y > (PREHEIGHT - val); y--)
        {
          pixel[2] = 255;
          pixel -= rowstride;
        }
    }

  /* move our data into the preview image */
  gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
                          0, 0, PREWIDTH, PREHEIGHT,
                          GIMP_RGB_IMAGE,
                          image,
                          3 * PREWIDTH);

  g_free (image);
}
Beispiel #20
0
static void
update_brush_preview (const gchar *fn)
{
  gint   i, j;
  guchar *preview_image;

  if (fn)
    brush_from_file = 1;

  preview_image = g_new0 (guchar, 100*100);

  if (!fn && brush_from_file)
    {
      /* preview_image is already initialized to our liking. */
    }
  else
    {
      double sc;
      ppm_t  p = {0, 0, NULL};
      guchar gammatable[256];
      int    newheight;

      if (brush_from_file)
        brush_reload (fn, &p);
      else if (PPM_IS_INITED (&brushppm))
        ppm_copy (&brushppm, &p);

      set_colorbrushes (fn);

      sc = gtk_adjustment_get_value (brush_gamma_adjust);
      if (sc != 1.0)
        for (i = 0; i < 256; i++)
          gammatable[i] = pow (i / 255.0, sc) * 255;
      else
        for (i = 0; i < 256; i++)
          gammatable[i] = i;

      newheight = p.height *
        pow (10, gtk_adjustment_get_value (brush_aspect_adjust));

      sc = p.width > newheight ? p.width : newheight;
      sc = 100.0 / sc;
      resize_fast (&p, p.width*sc,newheight*sc);
      padbrush (&p, 100, 100);
      for (i = 0; i < 100; i++)
        {
          int k = i * p.width * 3;
          if (i < p.height)
            for (j = 0; j < p.width; j++)
              preview_image[i*100+j] = gammatable[p.col[k + j * 3]];
        }
      ppm_kill (&p);
    }
  gimp_preview_area_draw (GIMP_PREVIEW_AREA (brush_preview),
                          0, 0, 100, 100,
                          GIMP_GRAY_IMAGE,
                          preview_image,
                          100);

  g_free (preview_image);
}