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
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* e-shell-corba-icon-utils.c
*
* Copyright (C) 2002 Ximian, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: Ettore Perazzoli
*/
#include "e-shell-corba-icon-utils.h"
/**
* e_store_corba_icon_from_pixbuf:
* @pixbuf:
* @icon_return:
*
* Store a CORBA Evolution::Icon in *@icon_return. @icon_return is not
* supposed to point to allocated memory, so all of its pointers are just
* overwritten.
**/
void
e_store_corba_icon_from_pixbuf (GdkPixbuf *pixbuf,
GNOME_Evolution_Icon *icon_return)
{
const char *sp;
CORBA_octet *dp;
int width, height, total_width, rowstride;
int i, j;
gboolean has_alpha;
if (pixbuf == NULL) {
icon_return->width = 0;
icon_return->height = 0;
icon_return->hasAlpha = FALSE;
icon_return->rgbaData._length = 0;
icon_return->rgbaData._maximum = 0;
icon_return->rgbaData._buffer = NULL;
return;
}
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
if (has_alpha)
total_width = 4 * width;
else
total_width = 3 * width;
icon_return->width = width;
icon_return->height = height;
icon_return->hasAlpha = has_alpha;
icon_return->rgbaData._length = icon_return->height * total_width;
icon_return->rgbaData._maximum = icon_return->rgbaData._length;
icon_return->rgbaData._buffer = CORBA_sequence_CORBA_octet_allocbuf (icon_return->rgbaData._maximum);
sp = gdk_pixbuf_get_pixels (pixbuf);
dp = icon_return->rgbaData._buffer;
for (i = 0; i < height; i ++) {
for (j = 0; j < total_width; j++)
*(dp ++) = sp[j];
sp += rowstride;
}
CORBA_sequence_set_release (& icon_return->rgbaData, TRUE);
}
/**
* e_new_corba_icon_from_pixbuf:
* @pixbuf:
*
* Create a CORBA Evolution::Icon from the specified @pixbuf.
*
* Return value: The new Evolution::Icon.
**/
GNOME_Evolution_Icon *
e_new_corba_icon_from_pixbuf (GdkPixbuf *pixbuf)
{
GNOME_Evolution_Icon *icon;
icon = GNOME_Evolution_Icon__alloc ();
e_store_corba_icon_from_pixbuf (pixbuf, icon);
return icon;
}
/**
* e_new_corba_animated_icon_from_pixbuf_array:
* @pixbuf_array:
*
* Generate a CORBA Evolution::AnimatedIcon from a NULL-terminated
* @pixbuf_array.
*
* Return value: The new Evolution::AnimatedIcon.
**/
GNOME_Evolution_AnimatedIcon *
e_new_corba_animated_icon_from_pixbuf_array (GdkPixbuf **pixbuf_array)
{
GNOME_Evolution_AnimatedIcon *animated_icon;
GdkPixbuf **p;
int num_frames;
int i;
g_return_val_if_fail (pixbuf_array != NULL, NULL);
num_frames = 0;
for (p = pixbuf_array; *p != NULL; p++)
num_frames++;
if (num_frames == 0)
return NULL;
animated_icon = GNOME_Evolution_AnimatedIcon__alloc ();
animated_icon->_length = num_frames;
animated_icon->_maximum = num_frames;
animated_icon->_buffer = CORBA_sequence_GNOME_Evolution_Icon_allocbuf (animated_icon->_maximum);
for (i = 0; i < num_frames; i++)
e_store_corba_icon_from_pixbuf (pixbuf_array[i], & animated_icon->_buffer[i]);
CORBA_sequence_set_release (animated_icon, TRUE);
return animated_icon;
}
|