static void update_color (GcalEventWidget *self) { GtkStyleContext *context; GdkRGBA *color; GQuark color_id; gchar *color_str; gchar *css_class; GDateTime *now; gint date_compare; context = gtk_widget_get_style_context (GTK_WIDGET (self)); color = gcal_event_get_color (self->event); now = g_date_time_new_now_local (); date_compare = g_date_time_compare (self->dt_end, now); /* Fades out an event that's earlier than the current date */ gtk_widget_set_opacity (GTK_WIDGET (self), date_compare < 0 ? 0.6 : 1.0); /* Remove the old style class */ if (self->css_class) { gtk_style_context_remove_class (context, self->css_class); g_clear_pointer (&self->css_class, g_free); } color_str = gdk_rgba_to_string (color); color_id = g_quark_from_string (color_str); css_class = g_strdup_printf ("color-%d", color_id); gtk_style_context_add_class (context, css_class); if (INTENSITY (color) > 0.5) { gtk_style_context_remove_class (context, "color-dark"); gtk_style_context_add_class (context, "color-light"); } else { gtk_style_context_remove_class (context, "color-light"); gtk_style_context_add_class (context, "color-dark"); } /* Keep the current style around, so we can remove it later */ self->css_class = css_class; g_clear_pointer (&now, g_date_time_unref); g_free (color_str); }
static GdkPixbuf* grayscale_pixbuf (GdkPixbuf *pixbuf) { GdkPixbuf *gray; guchar *pixels; int rowstride; int pixstride; int row; int n_rows; int width; gray = gdk_pixbuf_copy (pixbuf); rowstride = gdk_pixbuf_get_rowstride (gray); pixstride = gdk_pixbuf_get_has_alpha (gray) ? 4 : 3; pixels = gdk_pixbuf_get_pixels (gray); n_rows = gdk_pixbuf_get_height (gray); width = gdk_pixbuf_get_width (gray); row = 0; while (row < n_rows) { guchar *p = pixels + row * rowstride; guchar *end = p + (pixstride * width); while (p != end) { double v = INTENSITY (p[0], p[1], p[2]); p[0] = (guchar) v; p[1] = (guchar) v; p[2] = (guchar) v; p += pixstride; } ++row; } return gray; }
static GdkPixbuf * colorize_pixbuf (GdkPixbuf *orig, GdkRGBA *new_color) { GdkPixbuf *pixbuf; double intensity; int x, y; const guchar *src; guchar *dest; int orig_rowstride; int dest_rowstride; int width, height; gboolean has_alpha; const guchar *src_pixels; guchar *dest_pixels; pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (orig), gdk_pixbuf_get_has_alpha (orig), gdk_pixbuf_get_bits_per_sample (orig), gdk_pixbuf_get_width (orig), gdk_pixbuf_get_height (orig)); if (pixbuf == NULL) return NULL; orig_rowstride = gdk_pixbuf_get_rowstride (orig); dest_rowstride = gdk_pixbuf_get_rowstride (pixbuf); width = gdk_pixbuf_get_width (pixbuf); height = gdk_pixbuf_get_height (pixbuf); has_alpha = gdk_pixbuf_get_has_alpha (orig); src_pixels = gdk_pixbuf_get_pixels (orig); dest_pixels = gdk_pixbuf_get_pixels (pixbuf); for (y = 0; y < height; y++) { src = src_pixels + y * orig_rowstride; dest = dest_pixels + y * dest_rowstride; for (x = 0; x < width; x++) { double dr, dg, db; intensity = INTENSITY (src[0], src[1], src[2]) / 255.0; if (intensity <= 0.5) { /* Go from black at intensity = 0.0 to new_color at intensity = 0.5 */ dr = new_color->red * intensity * 2.0; dg = new_color->green * intensity * 2.0; db = new_color->blue * intensity * 2.0; } else { /* Go from new_color at intensity = 0.5 to white at intensity = 1.0 */ dr = new_color->red + (1.0 - new_color->red) * (intensity - 0.5) * 2.0; dg = new_color->green + (1.0 - new_color->green) * (intensity - 0.5) * 2.0; db = new_color->blue + (1.0 - new_color->blue) * (intensity - 0.5) * 2.0; } dest[0] = CLAMP_UCHAR (255 * dr); dest[1] = CLAMP_UCHAR (255 * dg); dest[2] = CLAMP_UCHAR (255 * db); if (has_alpha) { dest[3] = src[3]; src += 4; dest += 4; } else { src += 3; dest += 3; } } } return pixbuf; }
void eGrid::display_simple( eCamera* cam, int viewer,bool floor, bool sr_upperSky,bool sr_lowerSky, REAL flooralpha, bool eWalls,bool gameObjects, REAL& zNear){ sr_CheckGLError(); /* static GLfloat S[]={1,0,0,0}; static GLfloat T[]={0,1,0,0}; static GLfloat R[]={0,0,1,0}; static GLfloat Q[]={0,0,0,1}; glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR); glTexGenfv(GL_S,GL_OBJECT_PLANE,S); glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR); glTexGenfv(GL_T,GL_OBJECT_PLANE,T); glTexGeni(GL_R,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR); glTexGenfv(GL_R,GL_OBJECT_PLANE,R); glTexGeni(GL_Q,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR); glTexGenfv(GL_Q,GL_OBJECT_PLANE,Q); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_R); glDisable(GL_TEXTURE_GEN_Q); */ glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); glDisable(GL_CULL_FACE); eCoord camPos = cam->CameraGlancePos(); // eWallRim::Bound( camPos, 10 ); if (sr_upperSky || se_BlackSky()){ if (se_BlackSky()){ //glDisable(GL_TEXTURE); glDisable(GL_TEXTURE_2D); glColor3f(0,0,0); if ( z < lower_height ) infinity_xy_plane(cam->CameraPos(), cam->CameraDir(), lower_height); glEnable(GL_TEXTURE_2D); } else { TexMatrix(); glLoadIdentity(); // glScalef(.25,.25,.25); se_glFloorTexture(); glColor3f(.5,.5,1); if ( z < upper_height ) infinity_xy_plane(cam->CameraPos(), cam->CameraDir(), upper_height); } } if (sr_lowerSky && !sr_highRim){ paint_sr_lowerSky(this, viewer,sr_upperSky, cam); } if (floor){ sr_DepthOffset(false); su_FetchAndStoreSDLInput(); int floorDetail = sr_floorDetail; // no multitexturing without alpha blending if ( !sr_alphaBlend && floorDetail > rFLOOR_TEXTURE ) floorDetail = rFLOOR_TEXTURE; switch(floorDetail){ case rFLOOR_OFF: break; case rFLOOR_GRID: { #define SIDELEN (se_GridSize()) #define EXTENSION 10 eCoord center = cam->CameraPos() + cam->CameraDir() * (SIDELEN * EXTENSION * .8); REAL x=center.x; REAL y=center.y; int xn=static_cast<int>(x/SIDELEN); int yn=static_cast<int>(y/SIDELEN); //glDisable(GL_TEXTURE); glDisable(GL_TEXTURE_2D); #define INTENSITY(x,xx) (1-(((x)-(xx))*((x)-(xx))/(EXTENSION*SIDELEN*EXTENSION*SIDELEN))) BeginLines(); for(int i=xn-EXTENSION;i<=xn+EXTENSION;i++){ REAL intens=INTENSITY(i*SIDELEN,x); if (intens<0) intens=0; se_glFloorColor(intens,intens); glVertex2f(i*SIDELEN,y-SIDELEN*(EXTENSION+1)); glVertex2f(i*SIDELEN,y+SIDELEN*(EXTENSION+1)); } for(int j=yn-EXTENSION;j<=yn+EXTENSION;j++){ REAL intens=INTENSITY(j*SIDELEN,y); if (intens<0) intens=0; se_glFloorColor(intens,intens); glVertex2f(x-(EXTENSION+1)*SIDELEN,j*SIDELEN); glVertex2f(x+(EXTENSION+1)*SIDELEN,j*SIDELEN); } RenderEnd(); } break; case rFLOOR_TEXTURE: TexMatrix(); glLoadIdentity(); glScalef(1/se_GridSize(),1/se_GridSize(),1.); se_glFloorTexture(); se_glFloorColor(flooralpha); infinity_xy_plane( cam->CameraPos(), cam->CameraDir()); /* old way: draw every triangle for(int i=eFace::faces.Len()-1;i>=0;i--){ eFace *f=eFace::faces(i); if (f->visHeight[viewer]<z){ glBegin(GL_TRIANGLES); for(int j=0;j<=2;j++){ glVertex3f(f->p[j]->x,f->p[j]->y,0); } glEnd(); } } */ break; case rFLOOR_TWOTEXTURE: se_glFloorColor(flooralpha); TexMatrix(); glLoadIdentity(); REAL gs = 1/se_GridSize(); glScalef(0.01*gs,gs,1.); se_glFloorTexture_a(); infinity_xy_plane( cam->CameraPos(), cam->CameraDir()); se_glFloorColor(flooralpha); TexMatrix(); glLoadIdentity(); glScalef(gs,.01*gs,1.); se_glFloorTexture_b(); glDepthFunc(GL_LEQUAL); glBlendFunc(GL_SRC_ALPHA,GL_ONE); infinity_xy_plane( cam->CameraPos(), cam->CameraDir() ); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); break; } } glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); TexMatrix(); glLoadIdentity(); ModelMatrix(); // glDisable(GL_TEXTURE_GEN_S); // glDisable(GL_TEXTURE_GEN_T); // glDisable(GL_TEXTURE_GEN_Q); // glDisable(GL_TEXTURE_GEN_R); if(eWalls){ { su_FetchAndStoreSDLInput(); eWallRim::RenderAll( cam ); } if (sr_lowerSky && sr_highRim){ // glEnable(GL_TEXTURE_GEN_S); // glEnable(GL_TEXTURE_GEN_T); // glEnable(GL_TEXTURE_GEN_Q); // glEnable(GL_TEXTURE_GEN_R); paint_sr_lowerSky(this, viewer,sr_upperSky, cam); // glDisable(GL_TEXTURE_GEN_S); // glDisable(GL_TEXTURE_GEN_T); // glDisable(GL_TEXTURE_GEN_Q); // glDisable(GL_TEXTURE_GEN_R); TexMatrix(); glLoadIdentity(); ModelMatrix(); } } sr_CheckGLError(); if (eWalls){ // glDisable(GL_CULL_FACE); // draw_eWall(this,viewer,0,zNear,cam); /* #ifdef DEBUG for(int i=sg_netPlayerWalls.Len()-1;i>=0;i--){ glMatrixMode(GL_MODELVIEW); glPushMatrix(); if (sg_netPlayerWalls(i)->Preliminary()) glTranslatef(0,0,4); else glTranslatef(0,0,8); if (sg_netPlayerWalls(i)->Wall()) sg_netPlayerWalls(i)->Wall()->RenderList(false); glPopMatrix(); } #endif */ /* static int oldlen=0; int newlen=sg_netPlayerWalls.Len(); if (newlen!=oldlen){ con << "Number of player eWalls now " << newlen << '\n'; oldlen=newlen; } */ } sr_CheckGLError(); if (gameObjects) eGameObject::RenderAll(this, cam); eDebugLine::Render(); #ifdef DEBUG ePath::RenderLast(); if (debug_grid){ //glDisable(GL_TEXTURE); glDisable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); BeginLines(); int i; for(i=edges.Len()-1;i>=0;i--){ eHalfEdge *e=edges[i]; if (e->Face()) glColor4f(1,1,1,1); else glColor4f(0,0,1,1); glVertex3f(e->Point()->x,e->Point()->y,10); glVertex3f(e->Point()->x,e->Point()->y,15); glVertex3f(e->Point()->x,e->Point()->y,.1); glVertex3f(e->other->Point()->x,e->other->Point()->y,.1); glVertex3f(e->other->Point()->x,e->other->Point()->y,10); glVertex3f(e->other->Point()->x,e->other->Point()->y,15); } for(i=points.Len()-1;i>=0;i--){ ePoint *p=points[i]; glColor4f(1,0,0,1); glVertex3f(p->x,p->y,0); glVertex3f(p->x,p->y,(p->GetRefcount()+1)*5); } /* for(int i=sg_netPlayerWalls.Len()-1;i>=0;i--){ eEdge *e=sg_netPlayerWalls[i]->Edge(); glColor4f(0,1,0,1); glVertex3f(e->Point()->x,e->Point()->y,5); glVertex3f(e->Point()->x,e->Point()->y,10); glVertex3f(e->Point()->x,e->Point()->y,10); glVertex3f(e->other->Point()->x,e->other->Point()->y,10); glVertex3f(e->other->Point()->x,e->other->Point()->y,10); glVertex3f(e->other->Point()->x,e->other->Point()->y,5); } */ RenderEnd(); } #endif }
/** * gdk_pixbuf_saturate_and_pixelate: * @src: source image * @dest: place to write modified version of @src * @saturation: saturation factor * @pixelate: whether to pixelate * * Modifies saturation and optionally pixelates @src, placing the result in * @dest. @src and @dest may be the same pixbuf with no ill effects. If * @saturation is 1.0 then saturation is not changed. If it's less than 1.0, * saturation is reduced (the image turns toward grayscale); if greater than * 1.0, saturation is increased (the image gets more vivid colors). If @pixelate * is %TRUE, then pixels are faded in a checkerboard pattern to create a * pixelated image. @src and @dest must have the same image format, size, and * rowstride. * **/ void gdk_pixbuf_saturate_and_pixelate(const GdkPixbuf *src, GdkPixbuf *dest, gfloat saturation, gboolean pixelate) { /* NOTE that src and dest MAY be the same pixbuf! */ g_return_if_fail (GDK_IS_PIXBUF (src)); g_return_if_fail (GDK_IS_PIXBUF (dest)); g_return_if_fail (gdk_pixbuf_get_height (src) == gdk_pixbuf_get_height (dest)); g_return_if_fail (gdk_pixbuf_get_width (src) == gdk_pixbuf_get_width (dest)); g_return_if_fail (gdk_pixbuf_get_has_alpha (src) == gdk_pixbuf_get_has_alpha (dest)); g_return_if_fail (gdk_pixbuf_get_colorspace (src) == gdk_pixbuf_get_colorspace (dest)); if (saturation == 1.0 && !pixelate) { if (dest != src) gdk_pixbuf_copy_area (src, 0, 0, gdk_pixbuf_get_width (src), gdk_pixbuf_get_height (src), dest, 0, 0); } else { int i, j, t; int width, height, has_alpha, src_rowstride, dest_rowstride, bytes_per_pixel; const guchar *src_line; guchar *dest_line; const guchar *src_pixel; guchar *dest_pixel; guchar intensity; has_alpha = gdk_pixbuf_get_has_alpha (src); bytes_per_pixel = has_alpha ? 4 : 3; width = gdk_pixbuf_get_width (src); height = gdk_pixbuf_get_height (src); src_rowstride = gdk_pixbuf_get_rowstride (src); dest_rowstride = gdk_pixbuf_get_rowstride (dest); dest_line = gdk_pixbuf_get_pixels (dest); src_line = gdk_pixbuf_read_pixels (src); #define DARK_FACTOR 0.7 #define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11) #define CLAMP_UCHAR(v) (t = (v), CLAMP (t, 0, 255)) #define SATURATE(v) ((1.0 - saturation) * intensity + saturation * (v)) for (i = 0 ; i < height ; i++) { src_pixel = src_line; src_line += src_rowstride; dest_pixel = dest_line; dest_line += dest_rowstride; for (j = 0 ; j < width ; j++) { intensity = INTENSITY (src_pixel[0], src_pixel[1], src_pixel[2]); if (pixelate && (i + j) % 2 == 0) { dest_pixel[0] = intensity / 2 + 127; dest_pixel[1] = intensity / 2 + 127; dest_pixel[2] = intensity / 2 + 127; } else if (pixelate) { dest_pixel[0] = CLAMP_UCHAR ((SATURATE (src_pixel[0])) * DARK_FACTOR); dest_pixel[1] = CLAMP_UCHAR ((SATURATE (src_pixel[1])) * DARK_FACTOR); dest_pixel[2] = CLAMP_UCHAR ((SATURATE (src_pixel[2])) * DARK_FACTOR); } else { dest_pixel[0] = CLAMP_UCHAR (SATURATE (src_pixel[0])); dest_pixel[1] = CLAMP_UCHAR (SATURATE (src_pixel[1])); dest_pixel[2] = CLAMP_UCHAR (SATURATE (src_pixel[2])); } if (has_alpha) dest_pixel[3] = src_pixel[3]; src_pixel += bytes_per_pixel; dest_pixel += bytes_per_pixel; } } } }
void write_array(const char *filename, const char *jpegfile) { FILE *fp; unsigned char *img; int width; int height; int compos; int i, j; int ival; int idx; float *data; float fval; float intensity; fp = fopen(filename, "w"); if (!fp) exit(-1); img = jpeg_load(jpegfile, &width, &height, &compos); if (img == NULL) { printf("can't load jpeg file.\n"); exit(-1); } data = (float *)malloc(sizeof(float) * width * height * 3); if (!data) { printf("muda muda muda!\n"); exit(-1); } for (i = 0; i < width * height; i++) { idx = 3 * i; switch (compos) { case 1: data[idx + 0] = (float)(*img++) / (256.0f); data[idx + 1] = data[idx + 0]; data[idx + 2] = data[idx + 1]; break; case 2: data[idx + 0] = (float)(*img++) / (256.0f); data[idx + 1] = (float)(*img++) / (256.0f); data[idx + 2] = data[idx + 1]; break; case 3: data[idx + 0] = (float)(*img++) / (256.0f); data[idx + 1] = (float)(*img++) / (256.0f); data[idx + 2] = (float)(*img++) / (256.0f); break; } } for (j = height - 1; j >= 0; j--) { for (i = 0; i < width; i++) { intensity = INTENSITY(&data[3 * (j * width + i)]); fprintf(fp, "%f ", intensity); } fprintf(fp, "\n"); } fclose(fp); }
static gboolean swatch_draw (GtkWidget *widget, cairo_t *cr) { GtkColorSwatch *swatch = (GtkColorSwatch*)widget; GtkThemingBackground background; gdouble width, height; GtkStyleContext *context; GtkStateFlags state; GtkIconTheme *theme; GtkIconInfo *icon_info = NULL; theme = gtk_icon_theme_get_default (); context = gtk_widget_get_style_context (widget); state = gtk_widget_get_state_flags (widget); width = gtk_widget_get_allocated_width (widget); height = gtk_widget_get_allocated_height (widget); cairo_save (cr); gtk_style_context_save (context); gtk_style_context_set_state (context, state); _gtk_theming_background_init_from_context (&background, context, 0, 0, width, height, GTK_JUNCTION_NONE); if (swatch->priv->has_color) { cairo_pattern_t *pattern; cairo_matrix_t matrix; if (swatch->priv->use_alpha) { cairo_save (cr); _gtk_rounded_box_path (&background.padding_box, cr); cairo_clip_preserve (cr); cairo_set_source_rgb (cr, 0.33, 0.33, 0.33); cairo_fill_preserve (cr); pattern = _gtk_color_chooser_get_checkered_pattern (); cairo_matrix_init_scale (&matrix, 0.125, 0.125); cairo_pattern_set_matrix (pattern, &matrix); cairo_set_source_rgb (cr, 0.66, 0.66, 0.66); cairo_mask (cr, pattern); cairo_pattern_destroy (pattern); cairo_restore (cr); background.bg_color = swatch->priv->color; } else { background.bg_color = swatch->priv->color; background.bg_color.alpha = 1.0; } _gtk_theming_background_render (&background, cr); } else _gtk_theming_background_render (&background, cr); gtk_render_frame (context, cr, 0, 0, width, height); if (gtk_widget_has_visible_focus (widget)) { cairo_set_line_width (cr, 2); if (swatch->priv->has_color && INTENSITY (swatch->priv->color.red, swatch->priv->color.green, swatch->priv->color.blue) < 0.5) cairo_set_source_rgba (cr, 1., 1., 1., 0.4); else cairo_set_source_rgba (cr, 0., 0., 0., 0.4); _gtk_rounded_box_shrink (&background.padding_box, 3, 3, 3, 3); _gtk_rounded_box_path (&background.padding_box, cr); cairo_stroke (cr); } if (swatch->priv->icon) { icon_info = gtk_icon_theme_lookup_icon (theme, swatch->priv->icon, 16, GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_USE_BUILTIN); } else if ((state & GTK_STATE_FLAG_SELECTED) != 0) { GdkRGBA bg, border; GtkBorder border_width; GIcon *gicon; gtk_style_context_add_class (context, "color-active-badge"); _gtk_theming_background_init_from_context (&background, context, (width - 2 * ACTIVE_BADGE_RADIUS) / 2, (height - 2 * ACTIVE_BADGE_RADIUS) / 2, 2 * ACTIVE_BADGE_RADIUS, 2* ACTIVE_BADGE_RADIUS, GTK_JUNCTION_NONE); if (_gtk_theming_background_has_background_image (&background)) { _gtk_theming_background_render (&background, cr); } else { gtk_style_context_get_background_color (context, state, &bg); gtk_style_context_get_border_color (context, state, &border); gtk_style_context_get_border (context, state, &border_width); cairo_new_sub_path (cr); cairo_arc (cr, width / 2, height / 2, ACTIVE_BADGE_RADIUS, 0, 2 * G_PI); cairo_close_path (cr); gdk_cairo_set_source_rgba (cr, &bg); cairo_fill_preserve (cr); gdk_cairo_set_source_rgba (cr, &border); cairo_set_line_width (cr, border_width.left); cairo_stroke (cr); gicon = g_themed_icon_new ("object-select-symbolic"); /* fallback for themes that don't have object-select-symbolic */ g_themed_icon_append_name (G_THEMED_ICON (gicon), "gtk-apply"); icon_info = gtk_icon_theme_lookup_by_gicon (theme, gicon, 16, GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_USE_BUILTIN); g_object_unref (gicon); } } if (icon_info != NULL) { GdkPixbuf *pixbuf; pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, context, NULL, NULL); if (pixbuf != NULL) { gtk_render_icon (context, cr, pixbuf, (width - gdk_pixbuf_get_width (pixbuf)) / 2, (height - gdk_pixbuf_get_height (pixbuf)) / 2); g_object_unref (pixbuf); } g_object_unref (icon_info); } cairo_restore (cr); gtk_style_context_restore (context); return FALSE; }