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

« back to all changes in this revision

Viewing changes to transitions/misc_diagonal_wipe.c

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2009-07-07 09:09:38 UTC
  • mfrom: (2.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090707090938-jvaub13ijh53oawy
Tags: 1.5-1ubuntu1
* Merge with debian unstable (LP: #392874), Ubuntu remaining changes:
  - debian/control:
    + Move libav*-unstripped-* packages to Recommends as suggested by
      upstream.
    + Improve long description.
    + Add watch file.
  - debian/copyright: Replace deprecated symbol (C) with ©.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (c) 2009 Tadej Borovšak   <tadeboro@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
#include "export_to_ppm.h"
 
21
#include <gdk/gdk.h>
 
22
 
 
23
/* Local functions declarations */
 
24
static void
 
25
transition_render( GdkDrawable *window,
 
26
                                   GdkPixbuf   *image_from,
 
27
                                   GdkPixbuf   *image_to,
 
28
                                   gdouble      progress,
 
29
                                   gint         file_desc,
 
30
                                   gint         type );
 
31
 
 
32
/* Plug-in API */
 
33
void
 
34
img_get_plugin_info( gchar  **group,
 
35
                                         gchar ***trans )
 
36
{
 
37
        gint i = 0;
 
38
        *group = "Misc Diagonal Wipe";
 
39
 
 
40
        *trans = g_new( gchar *, 7 );
 
41
        (*trans)[i++] = "Double Barn Door";
 
42
        (*trans)[i++] = "img_barn";
 
43
        (*trans)[i++] = GINT_TO_POINTER( 38 );
 
44
        (*trans)[i++] = "Double Diamond";
 
45
        (*trans)[i++] = "img_diamond";
 
46
        (*trans)[i++] = GINT_TO_POINTER( 39 );
 
47
        (*trans)[i++] = NULL;
 
48
}
 
49
 
 
50
void
 
51
img_barn( GdkDrawable *window,
 
52
          GdkPixbuf   *image_from,
 
53
          GdkPixbuf   *image_to,
 
54
          gdouble      progress,
 
55
          gint         file_desc )
 
56
{
 
57
        transition_render( window, image_from, image_to, progress, file_desc, 1 );
 
58
}
 
59
 
 
60
void
 
61
img_diamond( GdkDrawable *window,
 
62
             GdkPixbuf   *image_from,
 
63
             GdkPixbuf   *image_to,
 
64
             gdouble      progress,
 
65
             gint         file_desc )
 
66
{
 
67
        transition_render( window, image_from, image_to, progress, file_desc, 2 );
 
68
}
 
69
 
 
70
 
 
71
/* Local functions definitions */
 
72
static void
 
73
transition_render( GdkDrawable *window,
 
74
                                   GdkPixbuf   *image_from,
 
75
                                   GdkPixbuf   *image_to,
 
76
                                   gdouble      progress,
 
77
                                   gint         file_desc,
 
78
                                   gint         type )
 
79
{
 
80
        cairo_t         *cr;
 
81
        cairo_surface_t *surface;
 
82
        gint             width, height;
 
83
        gint             w2, h2;
 
84
 
 
85
        gdk_drawable_get_size( window, &width, &height );
 
86
 
 
87
        if( file_desc < 0 )
 
88
        {
 
89
                cr = gdk_cairo_create( window );
 
90
        }
 
91
        else
 
92
        {
 
93
                surface = cairo_image_surface_create( CAIRO_FORMAT_RGB24,
 
94
                                                                                          width, height );
 
95
                cr = cairo_create( surface );
 
96
        }
 
97
 
 
98
        gdk_cairo_set_source_pixbuf( cr, image_from, 0, 0 );
 
99
        cairo_paint( cr );
 
100
 
 
101
        gdk_cairo_set_source_pixbuf( cr, image_to, 0, 0 );
 
102
        w2 = width / 2;
 
103
        h2 = height / 2;
 
104
        switch( type )
 
105
        {
 
106
                case 1:
 
107
                        cairo_move_to( cr, 0, 0 );
 
108
                        cairo_line_to( cr, 0, h2 * progress );
 
109
                        cairo_line_to( cr, w2 * ( 1 - progress ), h2 );
 
110
                        cairo_line_to( cr, 0, h2 * ( 2 - progress ) );
 
111
                        cairo_line_to( cr, 0, height );
 
112
                        cairo_line_to( cr, w2 * progress, height );
 
113
                        cairo_line_to( cr, w2, h2 * ( 1 + progress ) );
 
114
                        cairo_line_to( cr, w2 * ( 2 - progress ), height );
 
115
                        cairo_line_to( cr, width, height );
 
116
                        cairo_line_to( cr, width, h2 * ( 2 - progress ) );
 
117
                        cairo_line_to( cr, w2 * ( 1 + progress ), h2 );
 
118
                        cairo_line_to( cr, width, h2 * progress );
 
119
                        cairo_line_to( cr, width, 0 );
 
120
                        cairo_line_to( cr, w2 * ( 2 - progress ), 0 );
 
121
                        cairo_line_to( cr, w2, h2 * ( 1 - progress ) );
 
122
                        cairo_line_to( cr, w2 * progress, 0 );
 
123
                        cairo_close_path( cr );
 
124
                        break;
 
125
 
 
126
                case 2:
 
127
                        cairo_set_fill_rule( cr, CAIRO_FILL_RULE_EVEN_ODD );
 
128
 
 
129
                        cairo_move_to( cr, 0, h2 * ( 1 - progress ) );
 
130
                        cairo_line_to( cr, 0, h2 * ( 1 + progress ) );
 
131
                        cairo_line_to( cr, w2 * ( 1 - progress ), height );
 
132
                        cairo_line_to( cr, w2 * ( 1 + progress ), height );
 
133
                        cairo_line_to( cr, width, h2 * ( 1 + progress ) );
 
134
                        cairo_line_to( cr, width, h2 * ( 1 - progress ) );
 
135
                        cairo_line_to( cr, w2 * ( 1 + progress ), 0 );
 
136
                        cairo_line_to( cr, w2 * ( 1 - progress ), 0 );
 
137
                        cairo_close_path( cr );
 
138
 
 
139
                        cairo_new_sub_path( cr );
 
140
                        cairo_move_to( cr, w2 * progress, h2 );
 
141
                        cairo_line_to( cr, w2, h2 * ( 2 - progress ) );
 
142
                        cairo_line_to( cr, w2 * ( 2 - progress ), h2 );
 
143
                        cairo_line_to( cr, w2, h2 * progress );
 
144
                        cairo_close_path( cr );
 
145
                        break;
 
146
        }
 
147
        cairo_fill( cr );
 
148
 
 
149
        cairo_destroy( cr );
 
150
 
 
151
        if( file_desc < 0 )
 
152
                return;
 
153
 
 
154
        img_export_cairo_to_ppm( surface, file_desc );
 
155
        cairo_surface_destroy( surface );
 
156
}