void MathOperatorProcess<View>::processImagePow( OfxRectI& procWindowOutput, const OfxRectI& procWindowRoW, const boost::gil::rgba32f_pixel_t& values, const boost::gil::rgba8_pixel_t& processChannel ) { boost::gil::rgba32f_pixel_t wpix; for( int y = procWindowOutput.y1; y < procWindowOutput.y2; ++y ) { typename View::x_iterator src_it = this->_srcView.x_at( procWindowOutput.x1, y ); typename View::x_iterator dst_it = this->_dstView.x_at( procWindowOutput.x1, y ); for( int x = procWindowOutput.x1; x < procWindowOutput.x2; ++x, ++src_it, ++dst_it ) { color_convert( *src_it, wpix ); if( processChannel[ 0 ] == 1.0 ) wpix[ 0 ] = std::pow( wpix[ 0 ], values[ 0 ] ) ; if( processChannel[ 1 ] == 1.0 ) wpix[ 1 ] = std::pow( wpix[ 1 ], values[ 1 ] ) ; if( processChannel[ 2 ] == 1.0 ) wpix[ 2 ] = std::pow( wpix[ 2 ], values[ 2 ] ) ; if( processChannel[ 3 ] == 1.0 ) wpix[ 3 ] = std::pow( wpix[ 3 ], values[ 3 ] ) ; color_convert( wpix, *dst_it ); } if( this->progressForward() ) return; } }
/** Convert Dia color objects into GDK color objects. * If the highlight color is set, that will be used instead. This allows * rendering of an object to do highlight rendering. * @param renderer The renderer to check for highlight color. * @param col A color object to convert. * @param gdk_col Resulting GDK convert. */ static void renderer_color_convert(DiaGdkRenderer *renderer, Color *col, GdkColor *gdk_col) { if (renderer->highlight_color != NULL) { color_convert(renderer->highlight_color, gdk_col); } else { color_convert(col, gdk_col); } if (col->alpha != renderer->current_alpha) { if (col->alpha == 1.0) gdk_gc_set_fill(renderer->gc, GDK_SOLID); else { static gchar bits[9][4] = { { 0x00, 0x00, 0x00, 0x00 }, /* 0% */ { 0x20, 0x02, 0x20, 0x02 }, { 0x22, 0x88, 0x22, 0x88 }, /* 25% */ { 0x4A, 0xA4, 0x4A, 0xA4 }, { 0x5A, 0xA5, 0x5A, 0xA5 }, /* 50% */ { 0x57, 0xBA, 0x57, 0xBA }, { 0xBE, 0xEB, 0xBE, 0xEB }, /* 75% */ { 0xEF, 0xFE, 0xEF, 0xFE }, { 0xFF, 0xFF, 0xFF, 0xFF }, /* 100% */ }; GdkBitmap *stipple = gdk_bitmap_create_from_data (NULL, bits[(int)(9*col->alpha+.49)], 4, 4); gdk_gc_set_stipple (renderer->gc, stipple); g_object_unref (stipple); gdk_gc_set_fill(renderer->gc, GDK_STIPPLED); } renderer->current_alpha = col->alpha; } }
void color_init(void) { GdkVisual *visual = gtk_widget_get_default_visual(); GdkColormap *colormap = gtk_widget_get_default_colormap(); color_context = gdk_color_context_new(visual, colormap); color_convert(&color_black, &color_gdk_black); color_convert(&color_white, &color_gdk_white); }
/** Convert Dia color objects into GDK color objects. * If the highlight color is set, that will be used instead. This allows * rendering of an object to do highlight rendering. * @param renderer The renderer to check for highlight color. * @param col A color object to convert. * @param gdk_col Resulting GDK convert. */ static void renderer_color_convert(DiaGdkRenderer *renderer, Color *col, GdkColor *gdk_col) { if (renderer->highlight_color != NULL) { color_convert(renderer->highlight_color, gdk_col); } else { color_convert(col, gdk_col); } }
/** Initialize color access (gdk) and set up default colors. */ void color_init(void) { if (!_color_initialized) { GdkVisual *visual = gtk_widget_get_default_visual(); colormap = gdk_colormap_new (visual, FALSE); _color_initialized = TRUE; color_convert(&color_black, &color_gdk_black); color_convert(&color_white, &color_gdk_white); } }
void wolf3d_player_draw(t_env *env) { int i; int j; j = 0; while (j < PLAYER_SIZE) { i = -1; while (++i < PLAYER_SIZE) { img_putline(env, (t_2d_pnt){env->player.pos.x + i, env->player.pos.y + j}, (t_2d_pnt){env->player.pos.x + env->player.view_dir.x + i, env->player.pos.y + env->player.view_dir.y + j}, color_convert(color_get(255, 0, 255, 0))); img_putpixel(env, env->player.pos.x + i, env->player.pos.y + j, 0xffffff); img_putpixel(env, (env->player.pos.x + env->player.view_dir.x) + i, (env->player.pos.y + env->player.view_dir.y) + j, 0xff00ff); } ++j; } }
Pixel operator()(const point_t& p) const { double x = scale * p.x - 0.5; double y = scale * p.y - 0.5; if(std::abs(x) > 0.5 || std::abs(y) > 0.5) { Pixel pixel; numeric::pixel_zeros_t<Pixel>()(pixel); return pixel; } size_t cubeStep = sqrt((float)step); Pixel pixel; float red = 0.0; float green = 0.0; float blue = 0.0; float xStep = floor(scale * p.x * cubeStep); float yStep = floor(scale * p.y * cubeStep); red = floor(scale * p.x * step * cubeStep) / (step - 1) - xStep - xStep * 1 / (step - 1); green = floor(scale * p.y * step * cubeStep) / (step - 1) - yStep - yStep * 1 / (step - 1); blue = xStep / (step - 1) + cubeStep * yStep / (step - 1); color_convert(rgba32f_pixel_t(red, green, blue, 1), pixel); return pixel; }
static void draw_pixel_line(DiaRenderer *object, int x1, int y1, int x2, int y2, Color *color) { DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object); GdkGC *gc = renderer->gc; GdkColor gdkcolor; int target_width, target_height; dia_gdk_renderer_set_dashes(renderer, x1+y1); gdk_drawable_get_size (GDK_DRAWABLE (renderer->pixmap), &target_width, &target_height); if ( (x1 < 0 && x2 < 0) || (y1 < 0 && y2 < 0) || (x1 > target_width && x2 > target_width) || (y1 > target_height && y2 > target_height)) return; /* clip early rather than failing in Gdk */ color_convert(color, &gdkcolor); gdk_gc_set_foreground(gc, &gdkcolor); /* reset stippling (alpha emulation) */ gdk_gc_set_fill(gc, GDK_SOLID); renderer->current_alpha = 1.0; gdk_draw_line(renderer->pixmap, gc, x1, y1, x2, y2); }
static void fill_pixel_rect(DiaRenderer *object, int x, int y, int width, int height, Color *color) { #if 1 /* if we do it with cairo there is something wrong with the clipping? */ DiaCairoInteractiveRenderer *renderer = DIA_CAIRO_INTERACTIVE_RENDERER (object); GdkGC *gc = renderer->gc; GdkColor gdkcolor; color_convert(color, &gdkcolor); gdk_gc_set_foreground(gc, &gdkcolor); gdk_draw_rectangle (renderer->pixmap, gc, TRUE, x, y, width, height); #else DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (object); double x1u = x + .5, y1u = y + .5, x2u = x + width + .5, y2u = y + height + .5; double lw[2]; lw[0] = 1; lw[1] = 0; cairo_device_to_user_distance (renderer->cr, &lw[0], &lw[1]); cairo_set_line_width (renderer->cr, lw[0]); cairo_device_to_user (renderer->cr, &x1u, &y1u); cairo_device_to_user (renderer->cr, &x2u, &y2u); cairo_set_source_rgba (renderer->cr, color->red, color->green, color->blue, 1.0); cairo_rectangle (renderer->cr, x1u, y1u, x2u - x1u, y2u - y1u); cairo_fill (renderer->cr); #endif }
/** * display the hue indicator (openGL) * @param size size of the source clip * @param precisionHueIndicator number of step of the indicator */ void displayHueIndicator(const OfxPointI size, int precisionHueIndicator) { static const float length = 360.0; const double heightIndicator = size.y*0.07; const double width = size.x; glPushMatrix(); glTranslated(0.0f,-20.0f,0.0f); glBegin( GL_QUAD_STRIP); const float ratio = length / (float)(kPrecisionHueIndicator-1.0); float hue = 0.0f; for( std::ssize_t i = 0; i < precisionHueIndicator; ++i ) { boost::gil::hsv32f_pixel_t hsl_pix; //declare a HSL pixel boost::gil::rgb32f_pixel_t pix(0,0,0); //declare a RGB pixel (don't need alpha) hsl_pix[0] = (float)(hue/length); //fill up HSL pixel hsl_pix[1] = (float)(1.0); hsl_pix[2] = (float)(1.0); color_convert(hsl_pix, pix); //convert HSL=>RGB for OpenGl glColor3f(pix[0],pix[1],pix[2]); //generate openGL color glVertex2f(hue*(width/length),-0.0f); glVertex2f(hue*(width/length),(float)(-heightIndicator)); //draw quad hue+=ratio; } glEnd(); glPopMatrix(); }
static void fill_pixel_rect(DiaRenderer *object, int x, int y, int width, int height, Color *color) { DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object); GdkGC *gc = renderer->gc; GdkColor gdkcolor; int target_width, target_height; gdk_drawable_get_size (GDK_DRAWABLE (renderer->pixmap), &target_width, &target_height); if (x + width < 0 || y + height < 0 || x > target_width || y > target_height) return; /* clip early rather than failing in Gdk */ color_convert(color, &gdkcolor); gdk_gc_set_foreground(gc, &gdkcolor); /* reset stippling (alpha emulation) */ gdk_gc_set_fill(gc, GDK_SOLID); renderer->current_alpha = 1.0; gdk_draw_rectangle (renderer->pixmap, gc, TRUE, x, y, width, height); }
// Models MappingFunctionConcept void resample_pixels_progress( const SrcView& src_view, const DstView& dst_view, const MapFn& dst_to_src, const OfxRectI& procWindow, tuttle::plugin::IProgress* p, Sampler sampler = Sampler() ) { typename DstView::point_t dst_p; typename DstView::value_type black; color_convert( boost::gil::rgba32f_pixel_t( 0.0, 0.0, 0.0, 0.0 ), black ); for( dst_p.y = procWindow.y1; dst_p.y < procWindow.y2; ++dst_p.y ) { typename DstView::x_iterator xit = dst_view.row_begin( dst_p.y ); for( dst_p.x = procWindow.x1; dst_p.x < procWindow.x2; ++dst_p.x ) { if( !boost::gil::sample( sampler, src_view, transform( dst_to_src, dst_p ), xit[dst_p.x] ) ) { xit[dst_p.x] = black; // if it is outside of the source image } } if( p->progressForward() ) return; } }
bool sample(bilinear_sampler, const SrcView& src, const point2<F>& p, DstP& result) { typedef typename SrcView::value_type SrcP; ///modif point2<std::ptrdiff_t> p0(ifloor(p)); // the closest integer coordinate top left from p point2<F> frac(p.x-p0.x, p.y-p0.y); if (p0.x < 0 || p0.y < 0 || p0.x>=src.width() || p0.y>=src.height()) return false; pixel<F,devicen_layout_t<num_channels<SrcView>::value> > mp(0); // suboptimal typename SrcView::xy_locator loc=src.xy_at(p0.x,p0.y); if (p0.x+1<src.width()) { if (p0.y+1<src.height()) { // most common case - inside the image, not on the last row or column detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(*loc, (1-frac.x)*(1-frac.y),mp); detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(loc.x()[1], frac.x *(1-frac.y),mp); ++loc.y(); detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(*loc, (1-frac.x)* frac.y ,mp); detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(loc.x()[1], frac.x * frac.y ,mp); } else { // on the last row, but not the bottom-right corner pixel detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(*loc, (1-frac.x),mp); detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(loc.x()[1], frac.x ,mp); } } else { if (p0.y+1<src.height()) { // on the last column, but not the bottom-right corner pixel detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(*loc, (1-frac.y),mp); ++loc.y(); detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(*loc, frac.y ,mp); } else { // the bottom-right corner pixel detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(*loc,1,mp); } } // Convert from floating point average value to the source type SrcP src_result; cast_pixel(mp,src_result); color_convert(src_result, result); return true; }
static void draw_pixel_rect(DiaRenderer *object, int x, int y, int width, int height, Color *color) { DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object); GdkGC *gc = renderer->gc; GdkColor gdkcolor; int target_width, target_height; dia_gdk_renderer_set_dashes(renderer, x+y); gdk_drawable_get_size (GDK_DRAWABLE (renderer->pixmap), &target_width, &target_height); if (x + width < 0 || y + height < 0 || x > target_width || y > target_height) return; /* clip early rather than failing in Gdk */ color_convert(color, &gdkcolor); gdk_gc_set_foreground(gc, &gdkcolor); gdk_draw_rectangle (renderer->pixmap, gc, FALSE, x, y, width, height); }
static gboolean export_data(DiagramData *data, DiaContext *ctx, const gchar *filename, const gchar *diafilename, void* user_data) { DiaCairoRenderer *renderer; GdkColor color; int width, height; GdkPixbuf* pixbuf = NULL; GError* error = NULL; Rectangle rect; real zoom = 1.0; cairo_t *cctx; const char* format = (const char*)user_data; rect.left = data->extents.left; rect.top = data->extents.top; rect.right = data->extents.right; rect.bottom = data->extents.bottom; /* quite arbitrary */ zoom = 20.0 * data->paper.scaling; /* Adding a bit of padding to account for rounding errors. Better to * pad than to clip. See bug #413275 */ width = ceil((rect.right - rect.left) * zoom) + 1; height = ceil((rect.bottom - rect.top) * zoom) + 1; renderer = g_object_new (dia_cairo_renderer_get_type(), NULL); renderer->scale = zoom; renderer->surface = cairo_surface_reference (cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height)); cctx = cairo_create (renderer->surface); /* draw background */ color_convert (&data->bg_color, &color); gdk_cairo_set_source_color (cctx, &color); cairo_rectangle (cctx, 0, 0, width, height); cairo_fill (cctx); data_render (data, DIA_RENDERER (renderer), NULL, NULL, NULL); #if GTK_CHECK_VERSION(3,0,0) pixbuf = gdk_pixbuf_get_from_surface (renderer->surface, 0, 0, width, height); #else { GdkPixmap *pixmap; cairo_t *cr; pixmap = gdk_pixmap_new (NULL, width, height, 24); cr = gdk_cairo_create (pixmap); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_surface (cr, renderer->surface, 0, 0); cairo_paint (cr); pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, gdk_colormap_get_system (), 0, 0, 0, 0, width, height); } #endif if (pixbuf) { gdk_pixbuf_save (pixbuf, filename, format, &error, NULL); g_object_unref (pixbuf); } else { dia_context_add_message(ctx, _("Failed to create pixbuf from drawable.")); } if (error) { dia_context_add_message(ctx, _("Could not save file:\n%s\n%s"), dia_context_get_filename(ctx), error->message); g_error_free (error); } g_object_unref (renderer); return TRUE; }
static void color_area_draw () { Color col; GdkColor *win_bg; GdkColor fg, bg, bd; gint rect_w, rect_h; gint width, height; gint def_width, def_height; gint swap_width, swap_height; GdkColor mask_pattern; /* Check we haven't gotten initial expose yet, * no point in drawing anything */ if (!color_area_pixmap || !color_area_gc) return; gdk_drawable_get_size (color_area_pixmap, &width, &height); win_bg = &(color_area->style->bg[GTK_STATE_NORMAL]); col = attributes_get_foreground(); color_convert(&col, &fg); col = attributes_get_background(); color_convert(&col, &bg); bd = color_gdk_black; rect_w = width * 0.65; rect_h = height * 0.65; /* initialize the mask to transparent */ mask_pattern.pixel = 0; gdk_gc_set_foreground (mask_gc, &mask_pattern); gdk_draw_rectangle (color_area_mask, mask_gc, TRUE, 0, 0, -1, -1); /* set the mask's gc to opaque */ mask_pattern.pixel = 1; gdk_gc_set_foreground (mask_gc, &mask_pattern); gdk_gc_set_foreground (color_area_gc, win_bg); gdk_draw_rectangle (color_area_pixmap, color_area_gc, 1, 0, 0, width, height); gdk_gc_set_foreground (color_area_gc, &bg); gdk_draw_rectangle (color_area_pixmap, color_area_gc, 1, (width - rect_w), (height - rect_h), rect_w, rect_h); gdk_draw_rectangle (color_area_mask, mask_gc, TRUE, (width - rect_w), (height - rect_h), rect_w, rect_h); if (active_color == FOREGROUND) gtk_paint_shadow (color_area->style, color_area_pixmap, GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, color_area, NULL, (width - rect_w), (height - rect_h), rect_w, rect_h); else gtk_paint_shadow (color_area->style, color_area_pixmap, GTK_STATE_NORMAL, GTK_SHADOW_IN, NULL, color_area, NULL, (width - rect_w), (height - rect_h), rect_w, rect_h); gdk_gc_set_foreground (color_area_gc, &fg); gdk_draw_rectangle (color_area_pixmap, color_area_gc, 1, 0, 0, rect_w, rect_h); gdk_draw_rectangle (color_area_mask, mask_gc, TRUE, 0, 0, rect_w, rect_h); if (active_color == FOREGROUND) gtk_paint_shadow (color_area->style, color_area_pixmap, GTK_STATE_NORMAL, GTK_SHADOW_IN, NULL, color_area, NULL, 0, 0, rect_w, rect_h); else gtk_paint_shadow (color_area->style, color_area_pixmap, GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, color_area, NULL, 0, 0, rect_w, rect_h); /* draw the default pixmap */ gdk_drawable_get_size (default_pixmap, &def_width, &def_height); gdk_draw_drawable (color_area_pixmap, color_area_gc, default_pixmap, 0, 0, 0, height - def_height, def_width, def_height); gdk_draw_drawable (color_area_mask, mask_gc, default_mask, 0, 0, 0, height - def_height, def_width, def_height); /* draw the swap pixmap */ gdk_drawable_get_size (swap_pixmap, &swap_width, &swap_height); gdk_draw_drawable (color_area_pixmap, color_area_gc, swap_pixmap, 0, 0, width - swap_width, 0, swap_width, swap_height); gdk_draw_drawable (color_area_mask, mask_gc, swap_mask, 0, 0, width - swap_width, 0, swap_width, swap_height); /* draw the widget */ gdk_gc_set_clip_mask (color_area_gc, color_area_mask); gdk_gc_set_clip_origin (color_area_gc, 0, 0); gdk_draw_drawable (color_area->window, color_area_gc, color_area_pixmap, 0, 0, 0, 0, width, height); /* reset the clip mask */ gdk_gc_set_clip_mask (color_area_gc, NULL); }
void constraints() { gil_function_requires<PixelConcept<SrcP>>(); gil_function_requires<MutablePixelConcept<DstP>>(); color_convert(src, dst); }