File: DrawCache.xs

package info (click to toggle)
libgtk2-imageview-perl 0.05-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 224 kB
  • ctags: 36
  • sloc: perl: 457; ansic: 27; makefile: 17
file content (233 lines) | stat: -rw-r--r-- 6,118 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include "gtkimageviewperl.h"

GType
gdk_pixbuf_draw_opts_get_type(void) {
    static GType t = 0;
    if (!t) {
        t = g_boxed_type_register_static("GdkPixbufDrawOpts",
                                         (GBoxedCopyFunc) g_boxed_copy,
                                         (GBoxedFreeFunc) g_boxed_free);
    }
    return t;
}

/*
struct _GdkPixbufDrawOpts {
    gdouble        zoom;
    GdkRectangle   zoom_rect;
    int            widget_x;
    int            widget_y;       
    GdkInterpType  interp;
    GdkPixbuf     *pixbuf;
    int            check_color1;
    int            check_color2;
};
*/

SV *
newSVGdkPixbufDrawOpts (GdkPixbufDrawOpts * opts)
{
  HV * hv = newHV();
  hv_store (hv, "zoom", 4, newSVnv (opts->zoom), 0);
  hv_store (hv, "zoom_rect", 9, newSVGdkRectangle (&opts->zoom_rect), 0);
  hv_store (hv, "widget_x", 8, newSViv (opts->widget_x), 0);
  hv_store (hv, "widget_y", 8, newSViv (opts->widget_y), 0);
  hv_store (hv, "interp", 6, newSVGdkInterpType (opts->interp), 0);
  hv_store (hv, "pixbuf", 6, newSVGdkPixbuf (opts->pixbuf), 0);
  hv_store (hv, "check_color1", 12, newSViv (opts->check_color1), 0);
  hv_store (hv, "check_color2", 12, newSViv (opts->check_color2), 0);
  return newRV_noinc ((SV *) hv);
}

/*
 * returns a pointer to a GdkPixbufDrawOpts you can use until control returns
 * to perl.
 */
GdkPixbufDrawOpts *
SvGdkPixbufDrawOpts (SV * sv)
{
  HV * hv;
  SV ** svp;
  GdkPixbufDrawOpts * opts;

/* Make sure it is what we think it is before we try to
   dereference and parse it */
  if (! gperl_sv_is_hash_ref (sv))
          croak ("Expected a hash reference for Gtk2::Gdk::Pixbuf::Draw::Opts");

  hv = (HV*) SvRV (sv);

  opts = gperl_alloc_temp (sizeof (GdkPixbufDrawOpts));

  svp = hv_fetch (hv, "zoom", 4, FALSE);
  if (svp) opts->zoom = SvNV (*svp);

  svp = hv_fetch (hv, "zoom_rect", 9, FALSE);
  if (svp) opts->zoom_rect = * (GdkRectangle *) SvGdkRectangle (*svp);

  svp = hv_fetch (hv, "widget_x", 8, FALSE);
  if (svp) opts->widget_x = SvIV (*svp);

  svp = hv_fetch (hv, "widget_y", 8, FALSE);
  if (svp) opts->widget_y = SvIV (*svp);

  svp = hv_fetch (hv, "interp", 6, FALSE);
  if (svp) opts->interp = SvGdkInterpType (*svp);

  svp = hv_fetch (hv, "pixbuf", 6, FALSE);
  if (svp) opts->pixbuf = (GdkPixbuf *) SvGdkPixbuf (*svp);

  svp = hv_fetch (hv, "check_color1", 12, FALSE);
  if (svp) opts->check_color1 = SvIV (*svp);

  svp = hv_fetch (hv, "check_color2", 12, FALSE);
  if (svp) opts->check_color2 = SvIV (*svp);

  return opts;
}

GType
gdk_pixbuf_draw_cache_get_type(void) {
    static GType t = 0;
    if (!t) {
        t = g_boxed_type_register_static("GdkPixbufDrawCache",
                                         (GBoxedCopyFunc) g_boxed_copy,
                                         (GBoxedFreeFunc) g_boxed_free);
    }
    return t;
}

/*
struct _GdkPixbufDrawCache
{
    GdkPixbuf         *last_pixbuf;
    GdkPixbufDrawOpts  old;
    int                check_size;
};
*/

static SV *
newSVGdkPixbufDrawCache (GdkPixbufDrawCache * cache)
{
  HV * hv = newHV();
  hv_store (hv, "last_pixbuf", 11, newSVGdkPixbuf (cache->last_pixbuf), 0);
  hv_store (hv, "old", 3, newSVGdkPixbufDrawOpts (&cache->old), 0);
  hv_store (hv, "check_size", 10, newSViv (cache->check_size), 0);
  return newRV_noinc ((SV *) hv);
}

/*
 * returns a pointer to a GdkPixbufDrawCache you can use until control returns
 * to perl.
 */
static GdkPixbufDrawCache *
SvGdkPixbufDrawCache (SV * sv)
{
  HV * hv;
  SV ** svp;
  GdkPixbufDrawCache * cache;

/* Make sure it is what we think it is before we try to
   dereference and parse it */
  if (! gperl_sv_is_hash_ref (sv))
          croak ("Expected a hash reference for Gtk2::Gdk::Pixbuf::Draw::Cache");

  hv = (HV*) SvRV (sv);

  cache = gperl_alloc_temp (sizeof (GdkPixbufDrawCache));

  svp = hv_fetch (hv, "last_pixbuf", 11, FALSE);
  if (svp) cache->last_pixbuf = (GdkPixbuf *) SvGdkPixbuf (*svp);

  svp = hv_fetch (hv, "old", 3, FALSE);
  if (svp) cache->old = * (GdkPixbufDrawOpts *) SvGdkPixbufDrawOpts (*svp);

  svp = hv_fetch (hv, "check_size", 10, FALSE);
  if (svp) cache->check_size = SvIV (*svp);

  return cache;
}



MODULE = Gtk2::Gdk::Pixbuf::Draw::Cache  PACKAGE = Gtk2::Gdk::Pixbuf::Draw::Cache  PREFIX = gdk_pixbuf_draw_cache_

=for object Gtk2::Gdk::Pixbuf::Draw::Cache Cache for drawing scaled pixbufs
=cut

=for position DESCRIPTION

=head1 DESCRIPTION

Gtk2::Gdk::Pixbuf::Draw::Cache provides a cache that should be used by the
Gtk2::ImageView::Tool when redrawing the Gtk2::ImageView.

=cut

=for apidoc
Returns a new pixbuf draw cache.
=cut
GdkPixbufDrawCache *
gdk_pixbuf_draw_cache_new (class)
	C_ARGS:
		/*void*/


=for apidoc
Deallocates a pixbuf draw cache and all its data.

=cut
void
gdk_pixbuf_draw_cache_free (cache)
	GdkPixbufDrawCache *	cache


=for apidoc
Force the pixbuf draw cache to scale the pixbuf at the next draw.

Gtk2::Gdk::Pixbuf::Draw::Cache tries to minimize the number of scale operations
needed by caching the last drawn pixbuf. It would be inefficient to check the
individual pixels inside the pixbuf so it assumes that if the memory address of
the pixbuf has not changed, then the cache is good to use.

However, when the image data is modified, this assumtion breaks, which is why
this method must be used to tell draw cache about it.

=cut
void
gdk_pixbuf_draw_cache_invalidate (cache)
	GdkPixbufDrawCache *	cache


=for apidoc
Redraws the area specified in the pixbuf draw options in an efficient way by
using caching.

=over

=item cache : a GdkPixbufDrawCache

=item opts : the Gtk2::Gdk::Pixbuf::Draw::Opts to use in this draw

=item drawable : a GdkDrawable to draw on

=back

=cut
void
gdk_pixbuf_draw_cache_draw (cache, opts, drawable)
	GdkPixbufDrawCache *	cache
	GdkPixbufDrawOpts *	opts
	GdkDrawable *		drawable


=for apidoc
Gets the fastest method to draw the specified draw options. old is assumed to be
the last PixbufDrawOpts used and new is the one to use this time.
=cut
GdkPixbufDrawMethod
gdk_pixbuf_draw_cache_get_method (class, old, new)
		GdkPixbufDrawOpts *	old
		GdkPixbufDrawOpts *	new
	C_ARGS:
		old, new