void draw_composite(cairo_blend_instance_t* inst, unsigned char* out, unsigned char* dst, unsigned char* src, double time) { int w = inst->width; int h = inst->height; int stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, w); cairo_surface_t* out_image = cairo_image_surface_create_for_data (out, CAIRO_FORMAT_ARGB32, w, h, stride); cairo_t* cr = cairo_create (out_image); cairo_surface_t* dst_image = cairo_image_surface_create_for_data (dst, CAIRO_FORMAT_ARGB32, w, h, stride); cairo_surface_t* src_image = cairo_image_surface_create_for_data ((unsigned char*)src, CAIRO_FORMAT_ARGB32, w, h, stride); // Draw bg on surface cairo_set_source_surface (cr, dst_image, 0, 0); cairo_paint (cr); // Set source, blen mode and draw with current opacity frei0r_cairo_set_operator(cr, inst->blend_mode); cairo_set_source_surface (cr, src_image, 0, 0); cairo_paint_with_alpha (cr, inst->opacity); cairo_surface_destroy (out_image); cairo_surface_destroy (src_image); cairo_surface_destroy (dst_image); cairo_destroy (cr); }
void draw_composite(cairo_affineblend_instance_t* inst, unsigned char* out, unsigned char* dst, unsigned char* src, double time) { int w = inst->width; int h = inst->height; int stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, w); cairo_surface_t* out_image = cairo_image_surface_create_for_data (out, CAIRO_FORMAT_ARGB32, w, h, stride); cairo_t* cr = cairo_create (out_image); cairo_surface_t* dst_image = cairo_image_surface_create_for_data (dst, CAIRO_FORMAT_ARGB32, w, h, stride); cairo_surface_t* src_image = cairo_image_surface_create_for_data ((unsigned char*)src, CAIRO_FORMAT_ARGB32, w, h, stride); // Draw bg on surface cairo_set_source_surface (cr, dst_image, 0, 0); cairo_paint (cr); double x_scale = frei0r_cairo_get_scale (inst->x_scale); double y_scale = frei0r_cairo_get_scale (inst->y_scale); //--- Get scaled and rotated anchor offsets. double anchorX = -(x_scale * inst->anchor_x * inst->width); double anchorY = -(y_scale * inst->anchor_y * inst->height); double angleRad = inst->rotation * 360.0 * PI/180.0; double sinVal = sin (angleRad); double cosVal = cos (angleRad); double anchor_rot_x = anchorX * cosVal - anchorY * sinVal; double anchor_rot_y = anchorX * sinVal + anchorY * cosVal; // Get interpreted x and y translation double x_trans = frei0r_cairo_get_pixel_position (inst->x, inst->width); double y_trans = frei0r_cairo_get_pixel_position (inst->y, inst->height); //--- Get total translation to image tot left with scaling and rotation. double x_trans_tot = x_trans + anchor_rot_x; double y_trans_tot = y_trans + anchor_rot_y; cairo_translate (cr, x_trans_tot, y_trans_tot); cairo_rotate (cr, inst->rotation * 360.0 * PI/180.0); cairo_scale (cr, x_scale, y_scale); frei0r_cairo_set_operator(cr, inst->blend_mode); // Set source and draw with current mix cairo_set_source_surface (cr, src_image, 0, 0); cairo_paint_with_alpha (cr, inst->mix); cairo_surface_destroy (out_image); cairo_surface_destroy (src_image); cairo_surface_destroy (dst_image); cairo_destroy (cr); }