本文整理汇总了C++中cairo_scale函数的典型用法代码示例。如果您正苦于以下问题:C++ cairo_scale函数的具体用法?C++ cairo_scale怎么用?C++ cairo_scale使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cairo_scale函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: dt_iop_zonesystem_bar_expose
static gboolean
dt_iop_zonesystem_bar_expose (GtkWidget *widget, GdkEventExpose *event, dt_iop_module_t *self)
{
dt_iop_zonesystem_gui_data_t *g = (dt_iop_zonesystem_gui_data_t *)self->gui_data;
dt_iop_zonesystem_params_t *p = (dt_iop_zonesystem_params_t *)self->params;
const int inset = DT_ZONESYSTEM_INSET;
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
int width = allocation.width, height = allocation.height;
cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cairo_t *cr = cairo_create(cst);
/* clear background */
cairo_set_source_rgb (cr, .15, .15, .15);
cairo_paint(cr);
/* translate and scale */
width-=2*inset;
height-=2*inset;
cairo_save(cr);
cairo_translate(cr, inset, inset);
cairo_scale(cr,width,height);
/* render the bars */
float zonemap[MAX_ZONE_SYSTEM_SIZE]= {0};
_iop_zonesystem_calculate_zonemap (p, zonemap);
float s=(1./(p->size-2));
cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
for(int i=0; i<p->size-1; i++)
{
/* draw the reference zone */
float z=s*i;
cairo_rectangle (cr,(1./(p->size-1))*i,0,(1./(p->size-1)),DT_ZONESYSTEM_REFERENCE_SPLIT-DT_ZONESYSTEM_BAR_SPLIT_WIDTH);
cairo_set_source_rgb (cr, z, z, z);
cairo_fill (cr);
/* draw zone mappings */
cairo_rectangle (cr,
zonemap[i],DT_ZONESYSTEM_REFERENCE_SPLIT+DT_ZONESYSTEM_BAR_SPLIT_WIDTH,
(zonemap[i+1]-zonemap[i]),1.0-DT_ZONESYSTEM_REFERENCE_SPLIT);
cairo_set_source_rgb (cr, z, z, z);
cairo_fill (cr);
}
cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT);
cairo_restore (cr);
/* render zonebar control lines */
cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
cairo_set_line_width (cr, 1.);
cairo_rectangle (cr,inset,inset,width,height);
cairo_set_source_rgb (cr, .1,.1,.1);
cairo_stroke (cr);
cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT);
/* render control points handles */
cairo_set_source_rgb (cr, 0.6, 0.6, 0.6);
cairo_set_line_width (cr, DT_PIXEL_APPLY_DPI(1.));
const float arrw = DT_PIXEL_APPLY_DPI(7.0f);
for (int k=1; k<p->size-1; k++)
{
float nzw=zonemap[k+1]-zonemap[k];
float pzw=zonemap[k]-zonemap[k-1];
if (
( ((g->mouse_x/width) > (zonemap[k]-(pzw/2.0))) &&
((g->mouse_x/width) < (zonemap[k]+(nzw/2.0))) ) ||
p->zone[k] != -1)
{
gboolean is_under_mouse = ((width*zonemap[k]) - arrw*.5f < g->mouse_x && (width*zonemap[k]) + arrw*.5f > g->mouse_x);
cairo_move_to(cr, inset+(width*zonemap[k]), height+(2*inset)-1);
cairo_rel_line_to(cr, -arrw*.5f, 0);
cairo_rel_line_to(cr, arrw*.5f, -arrw);
cairo_rel_line_to(cr, arrw*.5f, arrw);
cairo_close_path(cr);
if ( is_under_mouse )
cairo_fill(cr);
else
cairo_stroke(cr);
}
}
/* push mem surface into widget */
cairo_destroy (cr);
cairo_t *cr_pixmap = gdk_cairo_create (gtk_widget_get_window (widget));
cairo_set_source_surface (cr_pixmap, cst, 0, 0);
cairo_paint (cr_pixmap);
cairo_destroy (cr_pixmap);
cairo_surface_destroy (cst);
return TRUE;
}
开发者ID:PolarFox,项目名称:darktable,代码行数:97,代码来源:zonesystem.c
示例2: __guac_terminal_set
/**
* Sends the given character to the terminal at the given row and column,
* rendering the character immediately. This bypasses the guac_terminal_display
* mechanism and is intended for flushing of updates only.
*/
int __guac_terminal_set(guac_terminal_display* display, int row, int col, int codepoint) {
int width;
int bytes;
char utf8[4];
/* Use foreground color */
const guac_terminal_color* color = &display->glyph_foreground;
/* Use background color */
const guac_terminal_color* background = &display->glyph_background;
cairo_surface_t* surface;
cairo_t* cairo;
int surface_width, surface_height;
PangoLayout* layout;
int layout_width, layout_height;
int ideal_layout_width, ideal_layout_height;
/* Calculate width in columns */
width = wcwidth(codepoint);
if (width < 0)
width = 1;
/* Do nothing if glyph is empty */
if (width == 0)
return 0;
/* Convert to UTF-8 */
bytes = guac_terminal_encode_utf8(codepoint, utf8);
surface_width = width * display->char_width;
surface_height = display->char_height;
ideal_layout_width = surface_width * PANGO_SCALE;
ideal_layout_height = surface_height * PANGO_SCALE;
/* Prepare surface */
surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24,
surface_width, surface_height);
cairo = cairo_create(surface);
/* Fill background */
cairo_set_source_rgb(cairo,
background->red / 255.0,
background->green / 255.0,
background->blue / 255.0);
cairo_rectangle(cairo, 0, 0, surface_width, surface_height);
cairo_fill(cairo);
/* Get layout */
layout = pango_cairo_create_layout(cairo);
pango_layout_set_font_description(layout, display->font_desc);
pango_layout_set_text(layout, utf8, bytes);
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
pango_layout_get_size(layout, &layout_width, &layout_height);
/* If layout bigger than available space, scale it back */
if (layout_width > ideal_layout_width || layout_height > ideal_layout_height) {
double scale = fmin(ideal_layout_width / (double) layout_width,
ideal_layout_height / (double) layout_height);
cairo_scale(cairo, scale, scale);
/* Update layout to reflect scaled surface */
pango_layout_set_width(layout, ideal_layout_width / scale);
pango_layout_set_height(layout, ideal_layout_height / scale);
pango_cairo_update_layout(cairo, layout);
}
/* Draw */
cairo_set_source_rgb(cairo,
color->red / 255.0,
color->green / 255.0,
color->blue / 255.0);
cairo_move_to(cairo, 0.0, 0.0);
pango_cairo_show_layout(cairo, layout);
/* Draw */
guac_common_surface_draw(display->display_surface,
display->char_width * col,
display->char_height * row,
surface);
/* Free all */
g_object_unref(layout);
cairo_destroy(cairo);
cairo_surface_destroy(surface);
//.........这里部分代码省略.........
开发者ID:jamesshew,项目名称:guacamole-server,代码行数:101,代码来源:display.c
示例3: setup_tile
void
setup_tile (gint w, gint h)
{
cairo_status_t status;
cairo_t* cr = NULL;
cairo_surface_t* cr_surf = NULL;
cairo_surface_t* tmp = NULL;
cairo_surface_t* dummy_surf = NULL;
cairo_surface_t* norm_surf = NULL;
cairo_surface_t* blur_surf = NULL;
gdouble width = (gdouble) w;
gdouble height = (gdouble) h;
raico_blur_t* blur = NULL;
cr_surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
3 * BUBBLE_SHADOW_SIZE,
3 * BUBBLE_SHADOW_SIZE);
status = cairo_surface_status (cr_surf);
if (status != CAIRO_STATUS_SUCCESS)
g_print ("Error: \"%s\"\n", cairo_status_to_string (status));
cr = cairo_create (cr_surf);
status = cairo_status (cr);
if (status != CAIRO_STATUS_SUCCESS)
{
cairo_surface_destroy (cr_surf);
g_print ("Error: \"%s\"\n", cairo_status_to_string (status));
}
// clear and render drop-shadow and bubble-background
cairo_scale (cr, 1.0f, 1.0f);
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
cairo_paint (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
if (g_composited)
{
draw_shadow (cr,
width,
height,
BUBBLE_SHADOW_SIZE,
CORNER_RADIUS);
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
draw_round_rect (cr,
1.0f,
(gdouble) BUBBLE_SHADOW_SIZE,
(gdouble) BUBBLE_SHADOW_SIZE,
(gdouble) CORNER_RADIUS,
(gdouble) (width - 2.0f * BUBBLE_SHADOW_SIZE),
(gdouble) (height - 2.0f* BUBBLE_SHADOW_SIZE));
cairo_fill (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
cairo_set_source_rgba (cr,
BUBBLE_BG_COLOR_R,
BUBBLE_BG_COLOR_G,
BUBBLE_BG_COLOR_B,
0.95f);
}
else
cairo_set_source_rgb (cr,
BUBBLE_BG_COLOR_R,
BUBBLE_BG_COLOR_G,
BUBBLE_BG_COLOR_B);
draw_round_rect (cr,
1.0f,
BUBBLE_SHADOW_SIZE,
BUBBLE_SHADOW_SIZE,
CORNER_RADIUS,
(gdouble) (width - 2.0f * BUBBLE_SHADOW_SIZE),
(gdouble) (height - 2.0f * BUBBLE_SHADOW_SIZE));
cairo_fill (cr);
tmp = cairo_image_surface_create_for_data (
cairo_image_surface_get_data (cr_surf),
cairo_image_surface_get_format (cr_surf),
3 * BUBBLE_SHADOW_SIZE,
3 * BUBBLE_SHADOW_SIZE,
cairo_image_surface_get_stride (cr_surf));
dummy_surf = copy_surface (tmp);
cairo_surface_destroy (tmp);
tmp = cairo_image_surface_create_for_data (
cairo_image_surface_get_data (dummy_surf),
cairo_image_surface_get_format (dummy_surf),
2 * BUBBLE_SHADOW_SIZE,
2 * BUBBLE_SHADOW_SIZE,
cairo_image_surface_get_stride (dummy_surf));
norm_surf = copy_surface (tmp);
cairo_surface_destroy (tmp);
blur = raico_blur_create (RAICO_BLUR_QUALITY_LOW);
raico_blur_set_radius (blur, 6);
raico_blur_apply (blur, dummy_surf);
raico_blur_destroy (blur);
tmp = cairo_image_surface_create_for_data (
cairo_image_surface_get_data (dummy_surf),
cairo_image_surface_get_format (dummy_surf),
2 * BUBBLE_SHADOW_SIZE,
2 * BUBBLE_SHADOW_SIZE,
//.........这里部分代码省略.........
开发者ID:chappyhome,项目名称:notify-osd-customizable,代码行数:101,代码来源:test-grow-bubble.c
示例4: render_text_to_surface
cairo_surface_t*
render_text_to_surface (gchar* text,
gint width,
gint height,
const cairo_font_options_t* font_opts,
gdouble dpi)
{
cairo_surface_t* surface;
cairo_t* cr;
PangoFontDescription* desc;
PangoLayout* layout;
// sanity check
if (!text ||
width <= 0 ||
height <= 0)
return NULL;
// create surface
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
width,
height);
if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
return NULL;
// create context
cr = cairo_create (surface);
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
{
cairo_surface_destroy (surface);
return NULL;
}
// clear context
cairo_scale (cr, 1.0f, 1.0f);
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
cairo_paint (cr);
//
layout = pango_cairo_create_layout (cr);
desc = pango_font_description_new ();
pango_font_description_set_size (desc, 12 * PANGO_SCALE);
pango_font_description_set_family_static (desc, "Candara");
pango_font_description_set_weight (desc, PANGO_WEIGHT_NORMAL);
pango_font_description_set_style (desc, PANGO_STYLE_NORMAL);
pango_layout_set_wrap (layout, PANGO_WRAP_WORD);
pango_layout_set_font_description (layout, desc);
pango_font_description_free (desc);
pango_layout_set_width (layout, width * PANGO_SCALE);
pango_layout_set_height (layout, height * PANGO_SCALE);
pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
// print and layout string (pango-wise)
pango_layout_set_text (layout, text, -1);
// make sure system-wide font-options like hinting, antialiasing etc.
// are taken into account
pango_cairo_context_set_font_options (pango_layout_get_context (layout),
font_opts);
pango_cairo_context_set_resolution (pango_layout_get_context (layout),
dpi);
pango_layout_context_changed (layout);
// draw pango-text to our cairo-context
cairo_move_to (cr, 0.0f, 0.0f);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f);
// this call leaks 3803 bytes, I've no idea how to fix that
pango_cairo_show_layout (cr, layout);
// clean up
g_object_unref (layout);
cairo_destroy (cr);
return surface;
}
开发者ID:chappyhome,项目名称:notify-osd-customizable,代码行数:80,代码来源:test-scroll-text.c
示例5: setup_tile
void
setup_tile (gint w, gint h)
{
cairo_status_t status;
cairo_t* cr = NULL;
cairo_surface_t* cr_surf = NULL;
gdouble width = (gdouble) w;
gdouble height = (gdouble) h;
cairo_surface_t* tmp = NULL;
cairo_surface_t* dummy_surf = NULL;
cairo_surface_t* norm_surf = NULL;
cairo_surface_t* blur_surf = NULL;
raico_blur_t* blur = NULL;
tile_t* tile = NULL;
// create tmp. surface for scratch
cr_surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
3 * BUBBLE_SHADOW_SIZE,
3 * BUBBLE_SHADOW_SIZE);
status = cairo_surface_status (cr_surf);
if (status != CAIRO_STATUS_SUCCESS)
g_print ("Error: \"%s\"\n", cairo_status_to_string (status));
// create context for that tmp. scratch surface
cr = cairo_create (cr_surf);
status = cairo_status (cr);
if (status != CAIRO_STATUS_SUCCESS)
{
cairo_surface_destroy (cr_surf);
g_print ("Error: \"%s\"\n", cairo_status_to_string (status));
}
// clear, render drop-shadow and bubble-background in scratch-surface
cairo_scale (cr, 1.0f, 1.0f);
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
cairo_paint (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
if (g_composited)
{
draw_shadow (cr,
width,
height,
BUBBLE_SHADOW_SIZE,
CORNER_RADIUS);
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
draw_round_rect (cr,
1.0f,
(gdouble) BUBBLE_SHADOW_SIZE,
(gdouble) BUBBLE_SHADOW_SIZE,
(gdouble) CORNER_RADIUS,
(gdouble) (width - 2.0f * BUBBLE_SHADOW_SIZE),
(gdouble) (height - 2.0f* BUBBLE_SHADOW_SIZE));
cairo_fill (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
cairo_set_source_rgba (cr,
BUBBLE_BG_COLOR_R,
BUBBLE_BG_COLOR_G,
BUBBLE_BG_COLOR_B,
0.95f);
}
else
cairo_set_source_rgb (cr,
BUBBLE_BG_COLOR_R,
BUBBLE_BG_COLOR_G,
BUBBLE_BG_COLOR_B);
draw_round_rect (cr,
1.0f,
BUBBLE_SHADOW_SIZE,
BUBBLE_SHADOW_SIZE,
CORNER_RADIUS,
(gdouble) (width - 2.0f * BUBBLE_SHADOW_SIZE),
(gdouble) (height - 2.0f * BUBBLE_SHADOW_SIZE));
cairo_fill (cr);
// create tmp. copy of scratch-surface
tmp = cairo_image_surface_create_for_data (
cairo_image_surface_get_data (cr_surf),
cairo_image_surface_get_format (cr_surf),
3 * BUBBLE_SHADOW_SIZE,
3 * BUBBLE_SHADOW_SIZE,
cairo_image_surface_get_stride (cr_surf));
dummy_surf = copy_surface (tmp);
cairo_surface_destroy (tmp);
// create normal-state surface for tile from copy of scratch-surface
tmp = cairo_image_surface_create_for_data (
cairo_image_surface_get_data (dummy_surf),
cairo_image_surface_get_format (dummy_surf),
2 * BUBBLE_SHADOW_SIZE,
2 * BUBBLE_SHADOW_SIZE,
cairo_image_surface_get_stride (dummy_surf));
norm_surf = copy_surface (tmp);
cairo_surface_destroy (tmp);
// blur tmp. copy of scratch-surface
blur = raico_blur_create (RAICO_BLUR_QUALITY_LOW);
raico_blur_set_radius (blur, 6);
raico_blur_apply (blur, dummy_surf);
//.........这里部分代码省略.........
开发者ID:chappyhome,项目名称:notify-osd-customizable,代码行数:101,代码来源:test-scroll-text.c
示例6: Initialize_Graphics
void Initialize_Graphics(cairo_t *cr)
{
// int Height,OldMaxX;
// int t,t1; // t is unused
// int t1;
int x,dx;
MaxX = WINDOW_WIDTH;
MaxY = WINDOW_WIDTH;
#ifdef GUI_INTERFACE
cairo_scale(SF_rgb_context, 1, 1);
#endif
#ifdef GUI
cairo_scale(cr, 1, 1);
#else
cairo_scale(cr, 1.0/SCALE_F, 1.0/SCALE_F);
#endif
cairo_set_antialias(cr, CAIRO_ANTIALIAS_BEST);
cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE);
cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
if(cairo_surface_get_type(cairo_get_target(cr)) == CAIRO_SURFACE_TYPE_XLIB)
{
// Supply a value VAL between 100.0 and 240.0 (as a double)
cairo_set_line_width(cr, (435.0 * 1) / ((double) MaxY * 1));
}
else if(cairo_surface_get_type(cairo_get_target(cr)) == CAIRO_SURFACE_TYPE_IMAGE)
{
#ifdef __APPLE__
cairo_set_line_width(cr, DEFAULT_LINE_WIDTH);
#else
cairo_set_line_width(cr, DEFAULT_LINE_WIDTH);
#endif
}
else // Mostly quartz?
{
cairo_set_line_width(cr, (390.1 * 1) / ((double) MaxY * 1)); // for image_surf use 239
}
// cairo_set_line_width(cr, (90.1 * 1) / ((double) MaxY * 1));
//// Cairo uses a different coordinate system than graphics.h, so we reflect Cairo's through
//// the x-asis to make it equal to that of graphics.h.
//// cairo_matrix_t x_reflection_matrix;
// Reflecting it however means that text will also be reflected. We therefore also use a
// reflection matrix for drawing fonts to reflect text back.
// cairo_matrix_t font_reflection_matrix;
// We need the options to turn off font anti-aliasing
cairo_font_options_t *font_options = cairo_font_options_create();
// cairo_matrix_init_identity(&x_reflection_matrix);
// x_reflection_matrix.yy = -1.0;
// cairo_set_matrix(cr, &x_reflection_matrix);
cairo_set_font_size(cr, POINTS_FONT_SIZE);
// cairo_set_font_size(cr, 5.9);
// cairo_get_font_matrix(cr, &font_reflection_matrix);
// font_reflection_matrix.yy = font_reflection_matrix.yy * -1;
// font_reflection_matrix.x0 += side_panel_size; // see (1)
// cairo_set_font_matrix(cr, &font_reflection_matrix);
// Translate negative height down because the reflection draws on top of the drawing surface
// (i.e. out of frame, directly on top of the frame)
// (1) Also translate the matrix over the x-axis to emulate the fact that DOS places the SF
// square in the middle.
// cairo_translate(cr, side_panel_size, -MaxY);
// cairo_translate(cr, 0, -MaxY);
// Turning off anti-alaising
cairo_get_font_options(cr, font_options);
cairo_font_options_set_antialias(font_options, CAIRO_ANTIALIAS_BEST);
cairo_set_font_options(cr, font_options);
cairo_select_font_face(cr,"DriodSans",CAIRO_FONT_SLANT_NORMAL,CAIRO_FONT_WEIGHT_NORMAL);
cairo_font_options_destroy(font_options);
// Sets all the values in the array to the empty path
// Gives a vague warning, probably because this only works for types with the size of an int
// (source: SO)
// memset(PrevMissile, empty_path, MAX_NO_OF_MISSILES);
// PrevMissile = {empty_path};
// Attemps above don't work, so we initialize manually
// clears the screen, probably the dos screen, and sets the current graphics write
// pointer to (0,0)
// cleardevice();
// The "textheight" function returns the height of a string in pixels.
// Height=textheight("H"); /* Get basic text height */
// Height = TEXT_HEIGHT;
//
// OldMaxX=MaxX;
// t1=4*Height;
//
// Panel_Y_End=MaxY;
//.........这里部分代码省略.........
开发者ID:LucasvBerkel,项目名称:TweedejaarsProject,代码行数:101,代码来源:DE_Minimal.c
示例7: gui_post_expose
void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, int32_t height,
int32_t pointerx, int32_t pointery)
{
dt_develop_t *dev = self->dev;
dt_iop_graduatednd_gui_data_t *g = (dt_iop_graduatednd_gui_data_t *)self->gui_data;
dt_iop_graduatednd_params_t *p = (dt_iop_graduatednd_params_t *)self->params;
float wd = dev->preview_pipe->backbuf_width;
float ht = dev->preview_pipe->backbuf_height;
float zoom_y = dt_control_get_dev_zoom_y();
float zoom_x = dt_control_get_dev_zoom_x();
dt_dev_zoom_t zoom = dt_control_get_dev_zoom();
int closeup = dt_control_get_dev_closeup();
float zoom_scale = dt_dev_get_zoom_scale(dev, zoom, closeup ? 2 : 1, 1);
cairo_translate(cr, width / 2.0, height / 2.0f);
cairo_scale(cr, zoom_scale, zoom_scale);
cairo_translate(cr, -.5f * wd - zoom_x * wd, -.5f * ht - zoom_y * ht);
// we get the extremities of the line
if(g->define == 0)
{
if(!set_points_from_grad(self, &g->xa, &g->ya, &g->xb, &g->yb, p->rotation, p->offset)) return;
g->define = 1;
}
float xa = g->xa * wd, xb = g->xb * wd, ya = g->ya * ht, yb = g->yb * ht;
// the lines
cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
if(g->selected == 3 || g->dragging == 3)
cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(5.0) / zoom_scale);
else
cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(3.0) / zoom_scale);
cairo_set_source_rgba(cr, .3, .3, .3, .8);
cairo_move_to(cr, xa, ya);
cairo_line_to(cr, xb, yb);
cairo_stroke(cr);
if(g->selected == 3 || g->dragging == 3)
cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(2.0) / zoom_scale);
else
cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(1.0) / zoom_scale);
cairo_set_source_rgba(cr, .8, .8, .8, .8);
cairo_move_to(cr, xa, ya);
cairo_line_to(cr, xb, yb);
cairo_stroke(cr);
// the extremities
float x1, y1, x2, y2;
float l = sqrt((xb - xa) * (xb - xa) + (yb - ya) * (yb - ya));
const float ext = wd * 0.01f / zoom_scale;
x1 = xa + (xb - xa) * ext / l;
y1 = ya + (yb - ya) * ext / l;
x2 = (xa + x1) / 2.0;
y2 = (ya + y1) / 2.0;
y2 += (x1 - xa);
x2 -= (y1 - ya);
cairo_move_to(cr, xa, ya);
cairo_line_to(cr, x1, y1);
cairo_line_to(cr, x2, y2);
cairo_close_path(cr);
cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(1.0) / zoom_scale);
if(g->selected == 1 || g->dragging == 1)
cairo_set_source_rgba(cr, .8, .8, .8, 1.0);
else
cairo_set_source_rgba(cr, .8, .8, .8, .5);
cairo_fill_preserve(cr);
if(g->selected == 1 || g->dragging == 1)
cairo_set_source_rgba(cr, .3, .3, .3, 1.0);
else
cairo_set_source_rgba(cr, .3, .3, .3, .5);
cairo_stroke(cr);
x1 = xb - (xb - xa) * ext / l;
y1 = yb - (yb - ya) * ext / l;
x2 = (xb + x1) / 2.0;
y2 = (yb + y1) / 2.0;
y2 += (xb - x1);
x2 -= (yb - y1);
cairo_move_to(cr, xb, yb);
cairo_line_to(cr, x1, y1);
cairo_line_to(cr, x2, y2);
cairo_close_path(cr);
cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(1.0) / zoom_scale);
if(g->selected == 2 || g->dragging == 2)
cairo_set_source_rgba(cr, .8, .8, .8, 1.0);
else
cairo_set_source_rgba(cr, .8, .8, .8, .5);
cairo_fill_preserve(cr);
if(g->selected == 2 || g->dragging == 2)
cairo_set_source_rgba(cr, .3, .3, .3, 1.0);
else
cairo_set_source_rgba(cr, .3, .3, .3, .5);
cairo_stroke(cr);
}
开发者ID:avsmal,项目名称:darktable,代码行数:96,代码来源:graduatednd.c
示例8: paint_darker_background
static void
paint_darker_background (GthImageRotator *self,
cairo_t *cr)
{
cairo_rectangle_int_t crop_region;
GtkAllocation allocation;
cairo_save (cr);
cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5);
gtk_widget_get_allocation (GTK_WIDGET (self->priv->viewer), &allocation);
switch (self->priv->resize) {
case GTH_TRANSFORM_RESIZE_BOUNDING_BOX:
case GTH_TRANSFORM_RESIZE_CLIP:
crop_region = self->priv->clip_area;
break;
case GTH_TRANSFORM_RESIZE_CROP:
/* the crop_region is not zoomed the clip_area is already zoomed */
cairo_scale (cr, self->priv->preview_zoom, self->priv->preview_zoom);
crop_region = self->priv->crop_region;
crop_region.x += self->priv->clip_area.x / self->priv->preview_zoom;
crop_region.y += self->priv->clip_area.y / self->priv->preview_zoom;
allocation.width /= self->priv->preview_zoom;
allocation.height /= self->priv->preview_zoom;
break;
}
/* left side */
cairo_rectangle (cr,
0,
0,
crop_region.x,
allocation.height);
/* right side */
cairo_rectangle (cr,
crop_region.x + crop_region.width,
0,
allocation.width - crop_region.x - crop_region.width,
allocation.height);
/* top */
cairo_rectangle (cr,
crop_region.x,
0,
crop_region.width,
crop_region.y);
/* bottom */
cairo_rectangle (cr,
crop_region.x,
crop_region.y + crop_region.height,
crop_region.width,
allocation.height - crop_region.y - crop_region.height);
cairo_fill (cr);
cairo_restore (cr);
}
开发者ID:KapTmaN,项目名称:gthumb,代码行数:64,代码来源:gth-image-rotator.c
示例9: XOJ_CHECK_TYPE
void PreviewJob::run() {
XOJ_CHECK_TYPE(PreviewJob);
GtkAllocation alloc;
gtk_widget_get_allocation(this->sidebarPreview->widget, &alloc);
cairo_surface_t * crBuffer = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, alloc.width, alloc.height);
double zoom = this->sidebarPreview->sidebar->getZoom();
cairo_t * cr2 = cairo_create(crBuffer);
cairo_matrix_t defaultMatrix = { 0 };
cairo_get_matrix(cr2, &defaultMatrix);
cairo_translate(cr2, Shadow::getShadowTopLeftSize() + 2, Shadow::getShadowTopLeftSize() + 2);
cairo_scale(cr2, zoom, zoom);
Document * doc = this->sidebarPreview->sidebar->getDocument();
doc->lock();
if (this->sidebarPreview->page.getBackgroundType() == BACKGROUND_TYPE_PDF) {
int pgNo = this->sidebarPreview->page.getPdfPageNr();
XojPopplerPage * popplerPage = doc->getPdfPage(pgNo);
PdfView::drawPage(this->sidebarPreview->sidebar->getCache(), popplerPage, cr2, zoom, this->sidebarPreview->page.getWidth(), this->sidebarPreview->page.getHeight());
}
DocumentView view;
view.drawPage(this->sidebarPreview->page, cr2, true);
cairo_set_matrix(cr2, &defaultMatrix);
cairo_set_operator(cr2, CAIRO_OPERATOR_SOURCE);
cairo_set_source_rgb(cr2, 1, 1, 1);
cairo_rectangle(cr2, 0, 0, Shadow::getShadowTopLeftSize() + 2, alloc.height);
cairo_rectangle(cr2, 0, 0, alloc.height, Shadow::getShadowTopLeftSize() + 2);
cairo_rectangle(cr2, alloc.width - Shadow::getShadowBottomRightSize() - 2, 0, Shadow::getShadowBottomRightSize() + 2, alloc.height);
cairo_rectangle(cr2, 0, alloc.height - Shadow::getShadowBottomRightSize() - 2, alloc.width, Shadow::getShadowBottomRightSize() + 2);
cairo_fill(cr2);
cairo_destroy(cr2);
doc->unlock();
g_mutex_lock(this->sidebarPreview->drawingMutex);
if (this->sidebarPreview->crBuffer) {
cairo_surface_destroy(this->sidebarPreview->crBuffer);
}
this->sidebarPreview->crBuffer = crBuffer;
gdk_threads_enter();
gtk_widget_queue_draw(this->sidebarPreview->widget);
gdk_threads_leave();
g_mutex_unlock(this->sidebarPreview->drawingMutex);
}
开发者ID:wbrenna,项目名称:xournalpp,代码行数:61,代码来源:PreviewJob.cpp
示例10: gst_rsvg_decode_image
static GstFlowReturn
gst_rsvg_decode_image (GstRsvgDec * rsvg, GstBuffer * buffer,
GstVideoCodecFrame * frame)
{
GstVideoDecoder *decoder = GST_VIDEO_DECODER (rsvg);
GstFlowReturn ret = GST_FLOW_OK;
cairo_t *cr;
cairo_surface_t *surface;
RsvgHandle *handle;
GError *error = NULL;
RsvgDimensionData dimension;
gdouble scalex, scaley;
GstMapInfo minfo;
GstVideoFrame vframe;
GstVideoCodecState *output_state;
GST_LOG_OBJECT (rsvg, "parsing svg");
if (!gst_buffer_map (buffer, &minfo, GST_MAP_READ)) {
GST_ERROR_OBJECT (rsvg, "Failed to get SVG image");
return GST_FLOW_ERROR;
}
handle = rsvg_handle_new_from_data (minfo.data, minfo.size, &error);
if (!handle) {
GST_ERROR_OBJECT (rsvg, "Failed to parse SVG image: %s", error->message);
g_error_free (error);
return GST_FLOW_ERROR;
}
rsvg_handle_get_dimensions (handle, &dimension);
output_state = gst_video_decoder_get_output_state (decoder);
if ((output_state == NULL)
|| GST_VIDEO_INFO_WIDTH (&output_state->info) != dimension.width
|| GST_VIDEO_INFO_HEIGHT (&output_state->info) != dimension.height) {
/* Create the output state */
gst_video_decoder_set_output_state (decoder, GST_RSVG_VIDEO_FORMAT,
dimension.width, dimension.height, rsvg->input_state);
if (output_state)
gst_video_codec_state_unref (output_state);
output_state = gst_video_decoder_get_output_state (decoder);
}
ret = gst_video_decoder_allocate_output_frame (decoder, frame);
if (ret != GST_FLOW_OK) {
g_object_unref (handle);
GST_ERROR_OBJECT (rsvg, "Buffer allocation failed %s",
gst_flow_get_name (ret));
return ret;
}
GST_LOG_OBJECT (rsvg, "render image at %d x %d",
GST_VIDEO_INFO_HEIGHT (&output_state->info),
GST_VIDEO_INFO_WIDTH (&output_state->info));
if (!gst_video_frame_map (&vframe,
&gst_video_decoder_get_output_state (decoder)->info,
frame->output_buffer, GST_MAP_READWRITE)) {
GST_ERROR_OBJECT (rsvg, "Failed to get SVG image");
return GST_FLOW_ERROR;
}
surface =
cairo_image_surface_create_for_data (GST_VIDEO_FRAME_PLANE_DATA (&vframe,
0), CAIRO_FORMAT_ARGB32, GST_VIDEO_FRAME_WIDTH (&vframe),
GST_VIDEO_FRAME_HEIGHT (&vframe), GST_VIDEO_FRAME_PLANE_STRIDE (&vframe,
0));
cr = cairo_create (surface);
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0);
cairo_paint (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
scalex = scaley = 1.0;
if (GST_VIDEO_INFO_WIDTH (&output_state->info) != dimension.width) {
scalex =
((gdouble) GST_VIDEO_INFO_WIDTH (&output_state->info)) /
((gdouble) dimension.width);
}
if (GST_VIDEO_INFO_HEIGHT (&output_state->info) != dimension.height) {
scaley =
((gdouble) GST_VIDEO_INFO_HEIGHT (&output_state->info)) /
((gdouble) dimension.height);
}
cairo_scale (cr, scalex, scaley);
rsvg_handle_render_cairo (handle, cr);
g_object_unref (handle);
cairo_destroy (cr);
cairo_surface_destroy (surface);
/* Now unpremultiply Cairo's ARGB to match GStreamer's */
gst_rsvg_decode_unpremultiply (GST_VIDEO_FRAME_PLANE_DATA (&vframe, 0),
GST_VIDEO_FRAME_WIDTH (&vframe), GST_VIDEO_FRAME_HEIGHT (&vframe));
gst_video_codec_state_unref (output_state);
//.........这里部分代码省略.........
开发者ID:cbetz421,项目名称:gst-plugins-bad,代码行数:101,代码来源:gstrsvgdec.c
示例11: _call_invalidaterect_ptac
//.........这里部分代码省略.........
pp_i->graphics_ccb = callback;
pp_i->graphics_in_progress = 1;
pthread_mutex_unlock(&pp_i->lock);
while (g2d->task_list) {
GList *link = g_list_first(g2d->task_list);
struct g2d_paint_task_s *pt = link->data;
struct pp_image_data_s *id;
cairo_t *cr;
g2d->task_list = g_list_delete_link(g2d->task_list, link);
switch (pt->type) {
case gpt_paint_id:
id = pp_resource_acquire(pt->image_data, PP_RESOURCE_IMAGE_DATA);
if (!id)
break;
cairo_surface_mark_dirty(g2d->cairo_surf);
cr = cairo_create(g2d->cairo_surf);
cairo_set_source_surface(cr, id->cairo_surf, pt->ofs.x, pt->ofs.y);
if (pt->src_is_set) {
cairo_rectangle(cr, pt->src.point.x + pt->ofs.x, pt->src.point.y + pt->ofs.y,
pt->src.size.width, pt->src.size.height);
cairo_fill(cr);
} else {
cairo_paint(cr);
}
cairo_surface_flush(g2d->cairo_surf);
cairo_destroy(cr);
pp_resource_release(pt->image_data);
pp_resource_unref(pt->image_data);
break;
case gpt_replace_contents:
id = pp_resource_acquire(pt->image_data, PP_RESOURCE_IMAGE_DATA);
if (!id)
break;
if (id->width == g2d->width || id->height == g2d->height) {
void *tmp;
cairo_surface_t *tmp_surf;
cairo_surface_flush(id->cairo_surf);
cairo_surface_flush(g2d->cairo_surf);
tmp = g2d->data;
g2d->data = id->data;
id->data = tmp;
tmp_surf = g2d->cairo_surf;
g2d->cairo_surf = id->cairo_surf;
id->cairo_surf = tmp_surf;
}
pp_resource_release(pt->image_data);
pp_resource_unref(pt->image_data);
break;
}
g_slice_free(struct g2d_paint_task_s, pt);
}
// scale image
{
cairo_surface_t *surf;
surf = cairo_image_surface_create_for_data((unsigned char *)g2d->second_buffer,
CAIRO_FORMAT_ARGB32, g2d->scaled_width, g2d->scaled_height, g2d->scaled_stride);
cairo_t *cr = cairo_create(surf);
cairo_scale(cr, g2d->scale, g2d->scale);
cairo_set_source_surface(cr, g2d->cairo_surf, 0, 0);
cairo_paint(cr);
cairo_destroy(cr);
cairo_surface_destroy(surf);
}
pp_resource_release(graphics_2d);
pthread_mutex_lock(&pp_i->lock);
if (!callback.func)
pthread_barrier_init(&pp_i->graphics_barrier, NULL, 2);
if (pp_i->is_fullscreen) {
XGraphicsExposeEvent ev = {
.type = GraphicsExpose,
.drawable = pp_i->fs_wnd,
.width = pp_i->width,
.height = pp_i->height
};
XSendEvent(pp_i->dpy, pp_i->fs_wnd, True, ExposureMask, (void *)&ev);
XFlush(pp_i->dpy);
pthread_mutex_unlock(&pp_i->lock);
} else {
pthread_mutex_unlock(&pp_i->lock);
ppb_core_call_on_browser_thread(_call_invalidaterect_ptac, pp_i);
}
if (callback.func)
return PP_OK_COMPLETIONPENDING;
pthread_barrier_wait(&pp_i->graphics_barrier);
return PP_OK;
}
开发者ID:Jalakas,项目名称:freshplayerplugin,代码行数:101,代码来源:ppb_graphics2d.c
示例12: draw_image
/*
* Draws global image with fill color onto a pixmap with the given
* resolution and returns it.
*
*/
xcb_pixmap_t draw_image(uint32_t *resolution) {
xcb_pixmap_t bg_pixmap = XCB_NONE;
int button_diameter_physical = ceil(scaling_factor() * BUTTON_DIAMETER);
DEBUG("scaling_factor is %.f, physical diameter is %d px\n",
scaling_factor(), button_diameter_physical);
if (!vistype)
vistype = get_root_visual_type(screen);
bg_pixmap = create_bg_pixmap(conn, screen, resolution, color);
/* Initialize cairo: Create one in-memory surface to render the unlock
* indicator on, create one XCB surface to actually draw (one or more,
* depending on the amount of screens) unlock indicators on. */
cairo_surface_t *output = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, resolution[0], resolution[1]);
cairo_t *ctx = cairo_create(output);
cairo_surface_t *xcb_output = cairo_xcb_surface_create(conn, bg_pixmap, vistype, resolution[0], resolution[1]);
cairo_t *xcb_ctx = cairo_create(xcb_output);
if (img) {
if (!tile) {
cairo_set_source_surface(xcb_ctx, img, 0, 0);
cairo_paint(xcb_ctx);
} else {
/* create a pattern and fill a rectangle as big as the screen */
cairo_pattern_t *pattern;
pattern = cairo_pattern_create_for_surface(img);
cairo_set_source(xcb_ctx, pattern);
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
cairo_rectangle(xcb_ctx, 0, 0, resolution[0], resolution[1]);
cairo_fill(xcb_ctx);
cairo_pattern_destroy(pattern);
}
} else {
char strgroups[3][3] = {{color[0], color[1], '\0'},
{color[2], color[3], '\0'},
{color[4], color[5], '\0'}};
uint32_t rgb16[3] = {(strtol(strgroups[0], NULL, 16)),
(strtol(strgroups[1], NULL, 16)),
(strtol(strgroups[2], NULL, 16))};
cairo_set_source_rgb(xcb_ctx, rgb16[0] / 255.0, rgb16[1] / 255.0, rgb16[2] / 255.0);
cairo_rectangle(xcb_ctx, 0, 0, resolution[0], resolution[1]);
cairo_fill(xcb_ctx);
}
if (unlock_indicator) {
cairo_scale(ctx, scaling_factor(), scaling_factor());
cairo_set_source_rgb(ctx, 1, 1, 1);
cairo_set_font_size(ctx, 60.0);
cairo_select_font_face(ctx, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
if (pam_state == STATE_PAM_VERIFY) {
passwdlength = 0;
}
if (unlock_state == STATE_KEY_ACTIVE) {
passwdlength = passwdlength + 1;
} else if (unlock_state == STATE_BACKSPACE_ACTIVE && passwdlength > 0){
passwdlength = passwdlength - 1;
} else if (unlock_state == STATE_ESCAPE_ACTIVE) {
passwdlength = 0;
}
char passwd[passwdlength + 1];
for (int i = 0; i < passwdlength; ++i) {
passwd[i] = '*';
}
passwd[passwdlength] = '\0';
cairo_text_extents_t extents;
double x, y;
cairo_text_extents(ctx, passwd, &extents);
x = BUTTON_RADIUS - ((extents.width / 2) + extents.x_bearing);
y = BUTTON_RADIUS - ((extents.height / 2) + extents.y_bearing);
cairo_move_to(ctx, x, y);
/* cairo_show_text(ctx, passwd); */
cairo_text_path(ctx, passwd);
cairo_fill_preserve(ctx);
cairo_set_source_rgb(ctx, 0, 0, 0);
cairo_set_line_width(ctx, 1.0);
cairo_stroke(ctx);
cairo_close_path(ctx);
}
if (xr_screens > 0) {
/* Composite the unlock indicator in the middle of each screen. */
for (int screen = 0; screen < xr_screens; screen++) {
int x = (xr_resolutions[screen].x + ((xr_resolutions[screen].width / 2) - (button_diameter_physical / 2)));
int y = (xr_resolutions[screen].y + ((xr_resolutions[screen].height / 2) - (button_diameter_physical / 2)));
cairo_set_source_surface(xcb_ctx, output, x, y);
cairo_rectangle(xcb_ctx, x, y, button_diameter_physical, button_diameter_physical);
cairo_fill(xcb_ctx);
//.........这里部分代码省略.........
开发者ID:muldvang,项目名称:i3lock,代码行数:101,代码来源:unlock_indicator.c
示例13: msRenderSVGToPixmap
int msRenderSVGToPixmap(symbolObj *symbol, symbolStyleObj *style) {
#ifdef USE_SVG_CAIRO
unsigned int svg_width, svg_height;
svg_cairo_status_t status;
cairo_t *cr;
svg_cairo_t *svgc;
cairo_surface_t *surface;
unsigned char *pb;
rasterBufferObj *rb;
//rendering_buffer *rc;
int width, height, surface_w, surface_h,row;
double scale;
//already rendered at the right size and scale? return
if (symbol->pixmap_buffer) {
if (style->scale == symbol->pixmap_buffer->scale &&
style->rotation == symbol->pixmap_buffer->rotation) {
return MS_SUCCESS;
} else {
if(symbol->renderer!=NULL)
symbol->renderer->freeSymbol(symbol);
msFreeRasterBuffer(symbol->pixmap_buffer);
}
}
if (!symbol->svg_cairo_surface )
msPreloadSVGSymbol(symbol);
if (!symbol->svg_cairo_surface)
return MS_FAILURE;
//set up raster
svgc =symbol->svg_cairo_surface;
svg_cairo_get_size (svgc, &svg_width, &svg_height);
width = surface_w = svg_width;
height = surface_h = svg_height;
//scale such that the SVG is rendered at the desired size in pixels
scale = style->scale; /*MS_MIN(style->scale / (double) svg_width,
style->scale / (double) svg_height);*/
//increase pixmap size to accomodate scaling/rotation
if (scale != 1.0 && style->scale != 1.0) {
width = surface_w = (svg_width * scale + 0.5);
height = surface_h = (svg_height * scale + 0.5);
}
if (style->rotation != 0) {
surface_w = MS_NINT(width * 1.415);
surface_h = MS_NINT(height * 1.415);
}
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, surface_w, surface_h);
cr = cairo_create(surface);
if (style->rotation != 0) {
cairo_translate (cr, surface_w/2, surface_h/2);
cairo_rotate(cr, -style->rotation);
cairo_translate (cr, -width/2, -height/2);
}
if (style->scale != 1.0) {
cairo_scale(cr,scale,scale);
}
status = svg_cairo_render(svgc, cr);
pb = cairo_image_surface_get_data(surface);
//set up raster
symbol->pixmap_buffer = (rasterBufferObj*)calloc(1,sizeof(rasterBufferObj));
MS_CHECK_ALLOC(symbol->pixmap_buffer, sizeof(rasterBufferObj), MS_FAILURE);
initializeRasterBufferCairo(symbol->pixmap_buffer, surface_w, surface_h, 0);
rb = symbol->pixmap_buffer;
memcpy(rb->data.rgba.pixels, pb, surface_w * surface_h * 4 * sizeof(unsigned char));
/* unpremultiply the data */
for(row=0; row<rb->height; row++) {
int col;
unsigned char *a,*r,*g,*b;
r=rb->data.rgba.r+row*rb->data.rgba.row_step;
g=rb->data.rgba.g+row*rb->data.rgba.row_step;
b=rb->data.rgba.b+row*rb->data.rgba.row_step;
a=rb->data.rgba.a+row*rb->data.rgba.row_step;
for(col=0; col<rb->width; col++) {
if(*a && *a < 255) {
double da = *a/255.0;
*r/=da;
*g/=da;
*b/=da;
}
a+=rb->data.rgba.pixel_step;
r+=rb->data.rgba.pixel_step;
g+=rb->data.rgba.pixel_step;
b+=rb->data.rgba.pixel_step;
}
}
rb->scale = style->scale;
//.........这里部分代码省略.........
开发者ID:netconstructor,项目名称:mapserver,代码行数:101,代码来源:mapcairo.c
示例14: dt_iop_zonesystem_preview_expose
static gboolean
dt_iop_zonesystem_preview_expose (GtkWidget *widget, GdkEventExpose *event, dt_iop_module_t *self)
{
const int inset = DT_PIXEL_APPLY_DPI(2);
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
int width = allocation.width, height = allocation.height;
dt_iop_zonesystem_gui_data_t *g = (dt_iop_zonesystem_gui_data_t *)self->gui_data;
dt_iop_zonesystem_params_t *p = (dt_iop_zonesystem_params_t *)self->params;
cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cairo_t *cr = cairo_create(cst);
/* clear background */
GtkStateType state = gtk_widget_get_state(self->expander);
GtkStyle *style = gtk_widget_get_style(self->expander);
float bg_red = style->bg[state].red/65535.0,
bg_green = style->bg[state].green/65535.0,
bg_blue = style->bg[state].blue/65535.0;
cairo_set_source_rgb (cr, bg_red, bg_green, bg_blue);
cairo_paint (cr);
width -= 2*inset;
height -= 2*inset;
cairo_translate(cr, inset, inset);
dt_pthread_mutex_lock(&g->lock);
if( g->in_preview_buffer && g->out_preview_buffer && self->enabled)
{
/* calculate the zonemap */
float zonemap[MAX_ZONE_SYSTEM_SIZE]= {-1};
_iop_zonesystem_calculate_zonemap (p,zonemap);
/* let's generate a pixbuf from pixel zone buffer */
guchar *image = g_malloc_n((size_t)4*g->preview_width*g->preview_height, sizeof(guchar));
guchar *buffer = g->mouse_over_output_zones ? g->out_preview_buffer : g->in_preview_buffer;
for (int k=0; k<g->preview_width*g->preview_height; k++)
{
int zone = 255*CLIP (((1.0/(p->size-1))*buffer[k]));
image[4*k+2] = (g->hilite_zone && buffer[k]==g->zone_under_mouse)?255:zone;
image[4*k+1] = (g->hilite_zone && buffer[k]==g->zone_under_mouse)?255:zone;
image[4*k+0] = (g->hilite_zone && buffer[k]==g->zone_under_mouse)?0:zone;
}
dt_pthread_mutex_unlock(&g->lock);
const int wd = g->preview_width, ht = g->preview_height;
const float scale = fminf(width/(float)wd, height/(float)ht);
const int stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, wd);
cairo_surface_t *surface = cairo_image_surface_create_for_data (image, CAIRO_FORMAT_RGB24, wd, ht, stride);
cairo_translate(cr, width/2.0, height/2.0f);
cairo_scale(cr, scale, scale);
cairo_translate(cr, -.5f*wd, -.5f*ht);
cairo_rectangle(cr, DT_PIXEL_APPLY_DPI(1), DT_PIXEL_APPLY_DPI(1), wd-DT_PIXEL_APPLY_DPI(2), ht-DT_PIXEL_APPLY_DPI(2));
cairo_set_source_surface (cr, surface, 0, 0);
cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_GOOD);
cairo_fill_preserve(cr);
cairo_surface_destroy (surface);
cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(1.0));
cairo_set_source_rgb(cr, .1, .1, .1);
cairo_stroke(cr);
g_free(image);
}
else
{
dt_pthread_mutex_unlock(&g->lock);
// draw a big, subdued dt logo
if(g->image)
{
cairo_set_source_surface(cr, g->image, (width - g->image_width) * 0.5, (height - g->image_height) * 0.5);
cairo_rectangle(cr, 0, 0, width, height);
cairo_set_operator(cr, CAIRO_OPERATOR_HSL_LUMINOSITY);
cairo_fill_preserve(cr);
cairo_set_operator(cr, CAIRO_OPERATOR_DARKEN);
cairo_set_source_rgb(cr, bg_red + 0.02, bg_green + 0.02, bg_blue+ 0.02);
cairo_fill_preserve(cr);
cairo_set_operator(cr, CAIRO_OPERATOR_LIGHTEN);
cairo_set_source_rgb(cr, bg_red - 0.02, bg_green - 0.02, bg_blue- 0.02);
cairo_fill(cr);
}
}
cairo_destroy(cr);
cairo_t *cr_pixmap = gdk_ca
|
请发表评论