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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* CdkPixbuf library - animated gdip support
*
* Copyright (C) 1999 The Free Software Foundation
*
* Authors: Jonathan Blandford <jrb@redhat.com>
* Havoc Pennington <hp@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include "io-gdip-native.h"
#include "io-gdip-animation.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static void cdk_pixbuf_gdip_anim_finalize (GObject *object);
static gboolean cdk_pixbuf_gdip_anim_is_static_image (CdkPixbufAnimation *animation);
static CdkPixbuf* cdk_pixbuf_gdip_anim_get_static_image (CdkPixbufAnimation *animation);
static void cdk_pixbuf_gdip_anim_get_size (CdkPixbufAnimation *anim,
int *width,
int *height);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static CdkPixbufAnimationIter* cdk_pixbuf_gdip_anim_get_iter (CdkPixbufAnimation *anim,
const GTimeVal *start_time);
G_GNUC_END_IGNORE_DEPRECATIONS
G_DEFINE_TYPE (CdkPixbufGdipAnim, cdk_pixbuf_gdip_anim, CDK_TYPE_PIXBUF_ANIMATION);
static void
cdk_pixbuf_gdip_anim_init (CdkPixbufGdipAnim *anim)<--- Parameter 'anim' can be declared as pointer to const
{
}
static void
cdk_pixbuf_gdip_anim_class_init (CdkPixbufGdipAnimClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
CdkPixbufAnimationClass *anim_class = CDK_PIXBUF_ANIMATION_CLASS (klass);
object_class->finalize = cdk_pixbuf_gdip_anim_finalize;
anim_class->is_static_image = cdk_pixbuf_gdip_anim_is_static_image;
anim_class->get_static_image = cdk_pixbuf_gdip_anim_get_static_image;
anim_class->get_size = cdk_pixbuf_gdip_anim_get_size;
anim_class->get_iter = cdk_pixbuf_gdip_anim_get_iter;
}
static void
cdk_pixbuf_gdip_anim_finalize (GObject *object)
{
CdkPixbufGdipAnim *gdip_anim = CDK_PIXBUF_GDIP_ANIM (object);
GList *l;
CdkPixbufFrame *frame;<--- The scope of the variable 'frame' can be reduced. [+]The scope of the variable 'frame' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
for (l = gdip_anim->frames; l; l = l->next) {
frame = l->data;
g_object_unref (frame->pixbuf);
g_free (frame);
}
g_list_free (gdip_anim->frames);
G_OBJECT_CLASS (cdk_pixbuf_gdip_anim_parent_class)->finalize (object);
}
static gboolean
cdk_pixbuf_gdip_anim_is_static_image (CdkPixbufAnimation *animation)
{
CdkPixbufGdipAnim *gdip_anim;
gdip_anim = CDK_PIXBUF_GDIP_ANIM (animation);
return (gdip_anim->frames != NULL &&
gdip_anim->frames->next == NULL);
}
static CdkPixbuf*
cdk_pixbuf_gdip_anim_get_static_image (CdkPixbufAnimation *animation)
{
CdkPixbufGdipAnim *gdip_anim;
gdip_anim = CDK_PIXBUF_GDIP_ANIM (animation);
if (gdip_anim->frames == NULL)
return NULL;
else
return CDK_PIXBUF (((CdkPixbufFrame*)gdip_anim->frames->data)->pixbuf);
}
static void
cdk_pixbuf_gdip_anim_get_size (CdkPixbufAnimation *anim,
int *width,
int *height)
{
CdkPixbufGdipAnim *gdip_anim;<--- Variable 'gdip_anim' can be declared as pointer to const
gdip_anim = CDK_PIXBUF_GDIP_ANIM (anim);
if (width)
*width = gdip_anim->width;
if (height)
*height = gdip_anim->height;
}
static void
iter_clear (CdkPixbufGdipAnimIter *iter)
{
iter->current_frame = NULL;
}
static void
iter_restart (CdkPixbufGdipAnimIter *iter)
{
iter_clear (iter);
iter->current_frame = iter->gdip_anim->frames;
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static CdkPixbufAnimationIter*
cdk_pixbuf_gdip_anim_get_iter (CdkPixbufAnimation *anim,
const GTimeVal *start_time)
{
CdkPixbufGdipAnimIter *iter;
iter = g_object_new (CDK_TYPE_PIXBUF_GDIP_ANIM_ITER, NULL);
iter->gdip_anim = CDK_PIXBUF_GDIP_ANIM (anim);
g_object_ref (iter->gdip_anim);
iter_restart (iter);
iter->start_time = *start_time;
iter->current_time = *start_time;
iter->first_loop_slowness = 0;
return CDK_PIXBUF_ANIMATION_ITER (iter);
}
G_GNUC_END_IGNORE_DEPRECATIONS
static void cdk_pixbuf_gdip_anim_iter_finalize (GObject *object);
static int cdk_pixbuf_gdip_anim_iter_get_delay_time (CdkPixbufAnimationIter *iter);
static CdkPixbuf* cdk_pixbuf_gdip_anim_iter_get_pixbuf (CdkPixbufAnimationIter *iter);
static gboolean cdk_pixbuf_gdip_anim_iter_on_currently_loading_frame (CdkPixbufAnimationIter *iter);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static gboolean cdk_pixbuf_gdip_anim_iter_advance (CdkPixbufAnimationIter *iter,
const GTimeVal *current_time);
G_GNUC_END_IGNORE_DEPRECATIONS
G_DEFINE_TYPE (CdkPixbufGdipAnimIter, cdk_pixbuf_gdip_anim_iter, CDK_TYPE_PIXBUF_ANIMATION_ITER);
static void
cdk_pixbuf_gdip_anim_iter_init (CdkPixbufGdipAnimIter *iter)<--- Parameter 'iter' can be declared as pointer to const
{
}
static void
cdk_pixbuf_gdip_anim_iter_class_init (CdkPixbufGdipAnimIterClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
CdkPixbufAnimationIterClass *anim_iter_class =
CDK_PIXBUF_ANIMATION_ITER_CLASS (klass);
object_class->finalize = cdk_pixbuf_gdip_anim_iter_finalize;
anim_iter_class->get_delay_time = cdk_pixbuf_gdip_anim_iter_get_delay_time;
anim_iter_class->get_pixbuf = cdk_pixbuf_gdip_anim_iter_get_pixbuf;
anim_iter_class->on_currently_loading_frame = cdk_pixbuf_gdip_anim_iter_on_currently_loading_frame;
anim_iter_class->advance = cdk_pixbuf_gdip_anim_iter_advance;
}
static void
cdk_pixbuf_gdip_anim_iter_finalize (GObject *object)
{
CdkPixbufGdipAnimIter *iter = CDK_PIXBUF_GDIP_ANIM_ITER (object);
iter_clear (iter);
g_object_unref (iter->gdip_anim);
G_OBJECT_CLASS (cdk_pixbuf_gdip_anim_iter_parent_class)->finalize (object);
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static gboolean
cdk_pixbuf_gdip_anim_iter_advance (CdkPixbufAnimationIter *anim_iter,
const GTimeVal *current_time)
{
CdkPixbufGdipAnimIter *iter;
gint elapsed;
gint loop;
GList *tmp;
GList *old;<--- Variable 'old' can be declared as pointer to const
iter = CDK_PIXBUF_GDIP_ANIM_ITER (anim_iter);
iter->current_time = *current_time;
/* We use milliseconds for all times */
elapsed =
(((iter->current_time.tv_sec - iter->start_time.tv_sec) * G_USEC_PER_SEC +
iter->current_time.tv_usec - iter->start_time.tv_usec)) / 1000;
if (elapsed < 0) {
/* Try to compensate; probably the system clock
* was set backwards
*/
iter->start_time = iter->current_time;
elapsed = 0;
}
g_assert (iter->gdip_anim->total_time > 0);
/* See how many times we've already played the full animation,
* and subtract time for that.
*/
if (iter->gdip_anim->loading)
loop = 0;
else {
/* If current_frame is NULL at this point, we have loaded the
* animation from a source which fell behind the speed of the
* display. We remember how much slower the first loop was due
* to this and correct the position calculation in order to not
* jump in the middle of the second loop.
*/
if (iter->current_frame == NULL)
iter->first_loop_slowness = MAX(0, elapsed - iter->gdip_anim->total_time);
loop = (elapsed - iter->first_loop_slowness) / iter->gdip_anim->total_time;
elapsed = (elapsed - iter->first_loop_slowness) % iter->gdip_anim->total_time;
}
iter->position = elapsed;
/* Now move to the proper frame */
if (iter->gdip_anim->loop == 0 || loop < iter->gdip_anim->loop)
tmp = iter->gdip_anim->frames;
else
tmp = NULL;
while (tmp != NULL) {
CdkPixbufFrame *frame = tmp->data;<--- Variable 'frame' can be declared as pointer to const
if (iter->position >= frame->elapsed &&
iter->position < (frame->elapsed + frame->delay_time))
break;
tmp = tmp->next;
}
old = iter->current_frame;
iter->current_frame = tmp;
return iter->current_frame != old;
}
G_GNUC_END_IGNORE_DEPRECATIONS
int
cdk_pixbuf_gdip_anim_iter_get_delay_time (CdkPixbufAnimationIter *anim_iter)
{
CdkPixbufFrame *frame;<--- Variable 'frame' can be declared as pointer to const
CdkPixbufGdipAnimIter *iter;
iter = CDK_PIXBUF_GDIP_ANIM_ITER (anim_iter);
if (iter->current_frame) {
frame = iter->current_frame->data;
#if 0
g_print ("frame start: %d pos: %d frame len: %d frame remaining: %d\n",
frame->elapsed,
iter->position,
frame->delay_time,
frame->delay_time - (iter->position - frame->elapsed));
#endif
return frame->delay_time - (iter->position - frame->elapsed);
} else
return -1; /* show last frame forever */
}
CdkPixbuf*
cdk_pixbuf_gdip_anim_iter_get_pixbuf (CdkPixbufAnimationIter *anim_iter)
{
CdkPixbufGdipAnimIter *iter;
CdkPixbufFrame *frame;<--- Variable 'frame' can be declared as pointer to const
iter = CDK_PIXBUF_GDIP_ANIM_ITER (anim_iter);
frame = iter->current_frame ? iter->current_frame->data : g_list_last (iter->gdip_anim->frames)->data;
#if 0
if (FALSE && frame)
g_print ("current frame %d dispose mode %d %d x %d\n",
g_list_index (iter->gdip_anim->frames,
frame),
frame->action,
cdk_pixbuf_get_width (frame->pixbuf),
cdk_pixbuf_get_height (frame->pixbuf));
#endif
if (frame == NULL)
return NULL;
return frame->pixbuf;
}
static gboolean
cdk_pixbuf_gdip_anim_iter_on_currently_loading_frame (CdkPixbufAnimationIter *anim_iter)
{
CdkPixbufGdipAnimIter *iter;
iter = CDK_PIXBUF_GDIP_ANIM_ITER (anim_iter);
return iter->current_frame == NULL || iter->current_frame->next == NULL;
}
|