~ubuntu-branches/ubuntu/trusty/imagination/trusty-updates

« back to all changes in this revision

Viewing changes to transitions/cross_fade.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-05-12 07:19:02 UTC
  • Revision ID: james.westby@ubuntu.com-20090512071902-1qlldhv7rlfktvzl
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (c) 2009 Giuseppe Torelli <colossus73@gmail.com>
 
3
 *
 
4
 *  This program is free software; you can redistribute it and/or modify
 
5
 *  it under the terms of the GNU General Public License as published by
 
6
 *  the Free Software Foundation; either version 2 of the License,or
 
7
 *  (at your option) any later version.
 
8
 *
 
9
 *  This program is distributed in the hope that it will be useful,
 
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *  GNU Library General Public License for more details.
 
13
 *
 
14
 *  You should have received a copy of the GNU General Public License
 
15
 *  along with this program; if not,write to the Free Software
 
16
 *  Foundation,Inc.,59 Temple Place - Suite 330,Boston,MA 02111-1307,USA.
 
17
 *
 
18
 */
 
19
 
 
20
/* This header provides us with image manipulation libraries such
 
21
 * as gdk-pixbuf and cairo. */
 
22
#include <gdk/gdk.h>
 
23
 
 
24
/* This function is part of the mandatory API that each plug-in
 
25
 * must adhere to.
 
26
 *
 
27
 * name parameter of this function is a return location for
 
28
 * plug-in name. You must fill it with unique name, which will
 
29
 * be used to identify transition in transition type combo box. */
 
30
void img_transition_set_name(gchar **name)
 
31
{
 
32
        *name = "Cross Fade";
 
33
}
 
34
 
 
35
/* This function is part of the mandatory API that each plug-in
 
36
 * must adhere to.
 
37
 *
 
38
 * This is the function that does all the transition rendering.
 
39
 * Parameters:
 
40
 *   window             GdkDrawable on which the final product should be drawn
 
41
 *   image_from Starting pixbuf.
 
42
 *   image_to   End pixbuf. Both images are already scaled and transformed
 
43
 *                              to fit into GdkDrawable.
 
44
 *   progress   Value in range [0,1] which tells us how far the transition
 
45
 *                              is (0 means we only started transition, 1 means the
 
46
 *                              transition is finished).
 
47
 *       file_desc      File descriptor for outputting finished image (this file
 
48
 *                              descriptor represents the ffmpeg's stdin, on which we
 
49
 *                              write produced image data). If the file descriptor is < 0,
 
50
 *                              we should draw our produt on GtkDrawable.
 
51
 *
 
52
 * Note: Parts enclosed in SUGGESTED comments should not be changed, since
 
53
 *       most of the transitions will need them.
 
54
 */
 
55
void img_transition_render(GdkDrawable *window, GdkPixbuf *image_from, GdkPixbuf *image_to, gdouble progress, gint file_desc)
 
56
{
 
57
        /* SUGGESTED */
 
58
        cairo_t *cr;
 
59
        cairo_surface_t *surface;
 
60
        gint    width, height;
 
61
 
 
62
        /* With this call we obtain the dimensions of our drawing area.
 
63
         * We don't use these values in this plug-in, but this is really
 
64
         * simple plug-in. */
 
65
        gdk_drawable_get_size(window, &width, &height);
 
66
 
 
67
        /* This is where we check if we need to output our product on the screen
 
68
         * or write it to the file desc. */
 
69
        if(file_desc < 0)
 
70
        {
 
71
                cr = gdk_cairo_create(window);
 
72
        }
 
73
        else
 
74
        {
 
75
                surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height);
 
76
                cr = cairo_create(surface);
 
77
        }
 
78
        /* END SUGGESTED */
 
79
 
 
80
        /* Here we do our own drawing. In this example, we are fading image_to
 
81
         * pixbuf over the image_from pixbuf. The amount of transparency is
 
82
         * determined by the progress value (at the start of the transition,
 
83
         * image_to is fully transparent and at the end fully opaque). */
 
84
        gdk_cairo_set_source_pixbuf(cr,image_from,0,0);
 
85
        cairo_paint(cr);
 
86
 
 
87
        gdk_cairo_set_source_pixbuf(cr,image_to,0,0);
 
88
        cairo_paint_with_alpha(cr,progress);
 
89
        cairo_destroy(cr);
 
90
        
 
91
        /* SUGGESTED */
 
92
        if(file_desc < 0)
 
93
                return;
 
94
 
 
95
        /* This function takes the burden of converting drawing product
 
96
         * to appropriate pixel data from plug-in write's shoulders. */
 
97
        img_export_cairo_to_ppm(surface, file_desc);
 
98
        cairo_surface_destroy(surface);
 
99
        /* END SUGGESTED */
 
100
}