static VALUE rb_gimp_rgb_luminance_uchar (VALUE self) { guchar result; result = gimp_rgb_luminance_uchar(rb2GimpRGBPtr(self)); return FIX2INT(result); }
void get_colors (GimpDrawable *drawable, guint8 *fg, guint8 *bg) { GimpRGB foreground; GimpRGB background; gimp_context_get_foreground (&foreground); gimp_context_get_background (&background); fg[0] = fg[1] = fg[2] = fg[3] = 255; bg[0] = bg[1] = bg[2] = bg[3] = 255; switch (gimp_drawable_type (drawable->drawable_id)) { case GIMP_RGB_IMAGE: case GIMP_RGBA_IMAGE: gimp_rgb_get_uchar (&foreground, &fg[0], &fg[1], &fg[2]); gimp_rgb_get_uchar (&background, &bg[0], &bg[1], &bg[2]); break; case GIMP_GRAYA_IMAGE: case GIMP_GRAY_IMAGE: fg[0] = gimp_rgb_luminance_uchar (&foreground); bg[0] = gimp_rgb_luminance_uchar (&background); break; case GIMP_INDEXEDA_IMAGE: case GIMP_INDEXED_IMAGE: /* FIXME: Should use current fg/bg colors. */ g_warning("maze: get_colors: Indexed image. Using colors 15 and 0.\n"); fg[0] = 15; /* As a plugin, I protest. *I* shouldn't be the */ bg[0] = 0; /* one who has to deal with this colormapcrap. */ break; default: break; } }
void gimp_drawable_get_color_uchar (gint32 drawable_ID, const GimpRGB *color, guchar *color_uchar) { g_return_if_fail (color != NULL); g_return_if_fail (color_uchar != NULL); switch (gimp_drawable_type (drawable_ID)) { case GIMP_RGB_IMAGE: gimp_rgb_get_uchar (color, &color_uchar[0], &color_uchar[1], &color_uchar[2]); color_uchar[3] = 255; break; case GIMP_RGBA_IMAGE: gimp_rgba_get_uchar (color, &color_uchar[0], &color_uchar[1], &color_uchar[2], &color_uchar[3]); break; case GIMP_GRAY_IMAGE: color_uchar[0] = gimp_rgb_luminance_uchar (color); color_uchar[1] = 255; break; case GIMP_GRAYA_IMAGE: color_uchar[0] = gimp_rgb_luminance_uchar (color); gimp_rgba_get_uchar (color, NULL, NULL, NULL, &color_uchar[1]); break; default: break; } }
static void grid (gint32 image_ID, GimpDrawable *drawable, GimpPreview *preview) { GimpPixelRgn srcPR, destPR; gint bytes; gint x_offset, y_offset; guchar *dest, *buffer = NULL; gint x, y; gboolean alpha; gboolean blend; guchar hcolor[4]; guchar vcolor[4]; guchar icolor[4]; guchar *cmap; gint ncolors; gimp_rgba_get_uchar (&grid_cfg.hcolor, hcolor, hcolor + 1, hcolor + 2, hcolor + 3); gimp_rgba_get_uchar (&grid_cfg.vcolor, vcolor, vcolor + 1, vcolor + 2, vcolor + 3); gimp_rgba_get_uchar (&grid_cfg.icolor, icolor, icolor + 1, icolor + 2, icolor + 3); switch (gimp_image_base_type (image_ID)) { case GIMP_RGB: blend = TRUE; break; case GIMP_GRAY: hcolor[0] = gimp_rgb_luminance_uchar (&grid_cfg.hcolor); vcolor[0] = gimp_rgb_luminance_uchar (&grid_cfg.vcolor); icolor[0] = gimp_rgb_luminance_uchar (&grid_cfg.icolor); blend = TRUE; break; case GIMP_INDEXED: cmap = gimp_image_get_colormap (image_ID, &ncolors); hcolor[0] = best_cmap_match (cmap, ncolors, &grid_cfg.hcolor); vcolor[0] = best_cmap_match (cmap, ncolors, &grid_cfg.vcolor); icolor[0] = best_cmap_match (cmap, ncolors, &grid_cfg.icolor); g_free (cmap); blend = FALSE; break; default: g_assert_not_reached (); blend = FALSE; } bytes = drawable->bpp; alpha = gimp_drawable_has_alpha (drawable->drawable_id); if (preview) { gimp_preview_get_position (preview, &sx1, &sy1); gimp_preview_get_size (preview, &sx2, &sy2); buffer = g_new (guchar, bytes * sx2 * sy2); sx2 += sx1; sy2 += sy1; } else { gimp_drawable_mask_bounds (drawable->drawable_id, &sx1, &sy1, &sx2, &sy2); gimp_pixel_rgn_init (&destPR, drawable, 0, 0, sx2 - sx1, sy2 - sy1, TRUE, TRUE); } gimp_pixel_rgn_init (&srcPR, drawable, 0, 0, sx2 - sx1, sy2 - sy1, FALSE, FALSE); dest = g_new (guchar, (sx2 - sx1) * bytes); for (y = sy1; y < sy2; y++) { gimp_pixel_rgn_get_row (&srcPR, dest, sx1, y, (sx2 - sx1)); y_offset = y - grid_cfg.hoffset; while (y_offset < 0) y_offset += grid_cfg.hspace; if ((y_offset + (grid_cfg.hwidth / 2)) % grid_cfg.hspace < grid_cfg.hwidth) { for (x = sx1; x < sx2; x++) { pix_composite (&dest[(x-sx1) * bytes], hcolor, bytes, blend, alpha); } } for (x = sx1; x < sx2; x++) { x_offset = grid_cfg.vspace + x - grid_cfg.voffset; while (x_offset < 0) x_offset += grid_cfg.vspace; if ((x_offset + (grid_cfg.vwidth / 2)) % grid_cfg.vspace < grid_cfg.vwidth) { pix_composite (&dest[(x-sx1) * bytes], vcolor, bytes, blend, alpha); } if ((x_offset + (grid_cfg.iwidth / 2)) % grid_cfg.vspace < grid_cfg.iwidth && ((y_offset % grid_cfg.hspace >= grid_cfg.ispace && y_offset % grid_cfg.hspace < grid_cfg.ioffset) || (grid_cfg.hspace - (y_offset % grid_cfg.hspace) >= grid_cfg.ispace && grid_cfg.hspace - (y_offset % grid_cfg.hspace) < grid_cfg.ioffset))) { pix_composite (&dest[(x-sx1) * bytes], icolor, bytes, blend, alpha); } } if ((y_offset + (grid_cfg.iwidth / 2)) % grid_cfg.hspace < grid_cfg.iwidth) { for (x = sx1; x < sx2; x++) { x_offset = grid_cfg.vspace + x - grid_cfg.voffset; while (x_offset < 0) x_offset += grid_cfg.vspace; if ((x_offset % grid_cfg.vspace >= grid_cfg.ispace && x_offset % grid_cfg.vspace < grid_cfg.ioffset) || (grid_cfg.vspace - (x_offset % grid_cfg.vspace) >= grid_cfg.ispace && grid_cfg.vspace - (x_offset % grid_cfg.vspace) < grid_cfg.ioffset)) { pix_composite (&dest[(x-sx1) * bytes], icolor, bytes, blend, alpha); } } } if (preview) { memcpy (buffer + (y - sy1) * (sx2 - sx1) * bytes, dest, (sx2 - sx1) * bytes); } else { gimp_pixel_rgn_set_row (&destPR, dest, sx1, y, (sx2 - sx1)); if (y % 16 == 0) gimp_progress_update ((gdouble) y / (gdouble) (sy2 - sy1)); } } g_free (dest); if (preview) { gimp_preview_draw_buffer (preview, buffer, bytes * (sx2 - sx1)); g_free (buffer); } else { gimp_progress_update (1.0); gimp_drawable_flush (drawable); gimp_drawable_merge_shadow (drawable->drawable_id, TRUE); gimp_drawable_update (drawable->drawable_id, sx1, sy1, sx2 - sx1, sy2 - sy1); } }