4
#include "video-utils.h"
6
#include <glib/gi18n.h>
18
* transcode Copyright (C) Thomas Oestreich - June 2001
19
* enix enix.berlios.de
22
void yuy2toyv12 (guint8 *y, guint8 *u, guint8 *v, guint8 *input,
23
int width, int height) {
28
for (i = 0; i < height; i += 2) {
29
for (j = 0; j < w2; j++) {
30
/* packed YUV 422 is: Y[i] U[i] Y[i+1] V[i] */
38
for (j = 0; j < w2; j++) {
39
/* skip every second line for U and V */
48
#define clip_8_bit(val) \
53
if (val > 255) val = 255; \
56
guint8 * yv12torgb (guint8 *src_y, guint8 *src_u, guint8 *src_v,
57
int width, int height) {
66
int uv_width, uv_height;
71
uv_height = height / 2;
73
rgb = (guchar *) malloc (width * height * 3);
77
for (i = 0; i < height; ++i) {
78
/* calculate u & v rows */
79
sub_i_uv = ((i * uv_height) / height);
81
for (j = 0; j < width; ++j) {
82
/* calculate u & v columns */
83
sub_j_uv = ((j * uv_width) / width);
85
/***************************************************
86
* Colour conversion from
87
* http://www.inforamp.net/~poynton/notes/colour_and_gamma/ColorFAQ.html#RTFToC30
89
* Thanks to Billy Biggs <vektor@dumbterm.net>
90
* for the pointer and the following conversion.
92
* R' = [ 1.1644 0 1.5960 ] ([ Y' ] [ 16 ])
93
* G' = [ 1.1644 -0.3918 -0.8130 ] * ([ Cb ] - [ 128 ])
94
* B' = [ 1.1644 2.0172 0 ] ([ Cr ] [ 128 ])
96
* Where in xine the above values are represented as
101
***************************************************/
103
y = src_y[(i * width) + j] - 16;
104
u = src_u[(sub_i_uv * uv_width) + sub_j_uv] - 128;
105
v = src_v[(sub_i_uv * uv_width) + sub_j_uv] - 128;
107
r = (1.1644 * y) + (1.5960 * v);
108
g = (1.1644 * y) - (0.3918 * u) - (0.8130 * v);
109
b = (1.1644 * y) + (2.0172 * u);
115
rgb[(i * width + j) * 3 + 0] = r;
116
rgb[(i * width + j) * 3 + 1] = g;
117
rgb[(i * width + j) * 3 + 2] = b;
124
/* Stolen from GDK */
126
gdk_wmspec_change_state (gboolean add,
131
GdkDisplay *display = gdk_screen_get_display (gdk_drawable_get_screen (GDK_DRAWABLE (window)));
134
#define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
135
#define _NET_WM_STATE_ADD 1 /* add/set property */
136
#define _NET_WM_STATE_TOGGLE 2 /* toggle property */
138
xev.xclient.type = ClientMessage;
139
xev.xclient.serial = 0;
140
xev.xclient.send_event = True;
141
xev.xclient.window = GDK_WINDOW_XID (window);
142
xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
143
xev.xclient.format = 32;
144
xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
145
xev.xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
146
xev.xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
148
XSendEvent (GDK_WINDOW_XDISPLAY (window),
149
GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (gdk_drawable_get_screen (GDK_DRAWABLE (window)))),
150
False, SubstructureRedirectMask | SubstructureNotifyMask,
155
totem_gdk_window_set_always_on_top (GdkWindow *window, gboolean setting)
157
gdk_wmspec_change_state (setting, window, gdk_atom_intern ("_NET_WM_STATE_ABOVE", FALSE), 0);
161
eel_gdk_window_set_invisible_cursor (GdkWindow *window)
163
GdkBitmap *empty_bitmap;
166
char invisible_cursor_bits[] = { 0x0 };
168
useless.red = useless.green = useless.blue = 0;
171
empty_bitmap = gdk_bitmap_create_from_data (window,
172
invisible_cursor_bits,
175
cursor = gdk_cursor_new_from_pixmap (empty_bitmap,
180
gdk_window_set_cursor (window, cursor);
182
gdk_cursor_unref (cursor);
184
g_object_unref (empty_bitmap);
187
void totem_create_symlinks (const char *orig, const char *dest)
192
dir = g_dir_open (orig, 0, NULL);
196
if (g_file_test (dest, G_FILE_TEST_IS_DIR) == FALSE)
199
name = g_dir_read_name (dir);
202
char *orig_full, *dest_full;
204
orig_full = g_build_path (G_DIR_SEPARATOR_S, orig, name, NULL);
205
dest_full = g_build_path (G_DIR_SEPARATOR_S, dest, name, NULL);
207
/* We don't check the return value, that's normal,
208
* we're very silent people */
209
symlink (orig_full, dest_full);
214
name = g_dir_read_name (dir);
220
gboolean totem_display_is_local (void)
222
const char *name, *work;
224
gboolean has_hostname;
226
name = gdk_display_get_name (gdk_display_get_default ());
230
work = strstr (name, ":");
234
has_hostname = (work - name) > 0;
236
/* Get to the character after the colon */
241
if (sscanf (work, "%d.%d", &display, &screen) != 2)
244
if (has_hostname == FALSE)
254
totem_pixbuf_mirror (GdkPixbuf *pixbuf)
256
int i, j, rowstride, offset, right;
258
int width, height, size;
261
pixels = gdk_pixbuf_get_pixels (pixbuf);
262
g_return_if_fail (pixels != NULL);
264
width = gdk_pixbuf_get_width (pixbuf);
265
height = gdk_pixbuf_get_height (pixbuf);
266
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
267
size = height * width * sizeof (guint32);
269
for (i = 0; i < size; i += rowstride)
271
for (j = 0; j < rowstride; j += sizeof(guint32))
274
right = i + (((width - 1) * sizeof(guint32)) - j);
279
memcpy (&tmp, pixels + offset, sizeof(guint32));
280
memcpy (pixels + offset, pixels + right,
282
memcpy (pixels + right, &tmp, sizeof(guint32));
288
totem_time_to_string (gint64 msecs)
290
int sec, min, hour, time;
292
time = (int) (msecs / 1000);
295
min = (time % (60*60)) / 60;
296
time = time - (min * 60);
297
hour = time / (60*60);
301
/* hour:minutes:seconds */
302
return g_strdup_printf ("%d:%02d:%02d", hour, min, sec);
304
/* minutes:seconds */
305
return g_strdup_printf ("%d:%02d", min, sec);
312
totem_time_to_string_text (gint64 msecs)
314
char *secs, *mins, *hours, *string;
315
int sec, min, hour, time;
317
time = (int) (msecs / 1000);
320
min = (time % (60*60)) / 60;
321
time = time - (min * 60);
322
hour = time / (60*60);
324
hours = g_strdup_printf (ngettext ("%d hour", "%d hours", hour), hour);
326
mins = g_strdup_printf (ngettext ("%d minute",
327
"%d minutes", min), min);
329
secs = g_strdup_printf (ngettext ("%d second",
330
"%d seconds", sec), sec);
334
/* hour:minutes:seconds */
335
string = g_strdup_printf (_("%s %s %s"), hours, mins, secs);
336
} else if (min > 0) {
337
/* minutes:seconds */
338
string = g_strdup_printf (_("%s %s"), mins, secs);
339
} else if (sec > 0) {
341
string = g_strdup_printf (_("%s"), secs);
344
string = g_strdup (_("0 seconds"));
354
typedef struct _TotemPrefSize {
360
cb_unset_size (gpointer data)
362
GtkWidget *widget = data;
364
gtk_widget_queue_resize_no_redraw (widget);
370
cb_set_preferred_size (GtkWidget *widget, GtkRequisition *req,
373
TotemPrefSize *size = data;
375
req->width = size->width;
376
req->height = size->height;
378
g_signal_handler_disconnect (widget, size->sig_id);
380
g_idle_add (cb_unset_size, widget);
384
totem_widget_set_preferred_size (GtkWidget *widget, gint width,
387
TotemPrefSize *size = g_new (TotemPrefSize, 1);
390
size->height = height;
391
size->sig_id = g_signal_connect (widget, "size-request",
392
G_CALLBACK (cb_set_preferred_size),
395
gtk_widget_queue_resize (widget);
399
totem_ratio_fits_screen (GdkWindow *video_window, int video_width,
400
int video_height, gfloat ratio)
402
GdkRectangle fullscreen_rect;
405
if (video_width <= 0 || video_height <= 0)
408
new_w = video_width * ratio;
409
new_h = video_height * ratio;
411
gdk_screen_get_monitor_geometry (gdk_screen_get_default (),
412
gdk_screen_get_monitor_at_window
413
(gdk_screen_get_default (),
417
if (new_w > (fullscreen_rect.width - 128) ||
418
new_h > (fullscreen_rect.height - 128))