Index: Makefile.am =================================================================== RCS file: /mirrors/freedesktop/xapps/fdclock/Makefile.am,v retrieving revision 1.1 diff -u -p -r1.1 Makefile.am --- Makefile.am 25 Mar 2004 00:53:42 -0000 1.1 +++ Makefile.am 20 Jun 2005 16:40:03 -0000 @@ -7,7 +7,7 @@ fdclock_SOURCES = \ $(COMMON_SRCS) fdfacepng_SOURCES = \ - fdfacepng.c write_png.c \ + fdfacepng.c \ $(COMMON_SRCS) bin_PROGRAMS = fdclock fdfacepng Index: fdclock.c =================================================================== RCS file: /mirrors/freedesktop/xapps/fdclock/fdclock.c,v retrieving revision 1.10 diff -u -p -r1.10 fdclock.c --- fdclock.c 18 Jun 2004 11:02:34 -0000 1.10 +++ fdclock.c 20 Jun 2005 16:35:38 -0000 @@ -23,10 +23,13 @@ */ #include +#include #include #include #include #include +#include +#include #include #include "fdface.h" #include "fdhand.h" @@ -39,28 +42,29 @@ static void clear (cairo_t *cr, double width, double height, double alpha) { cairo_save (cr); - cairo_set_rgb_color (cr, 1, 1, 1); - cairo_set_alpha (cr, alpha); - cairo_set_operator (cr, CAIRO_OPERATOR_SRC); + cairo_set_source_rgba (cr, 1, 1, 1, alpha); + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_rectangle (cr, 0, 0, width, height); cairo_fill (cr); cairo_restore (cr); } -Pixmap +static Pixmap make_background (Display *dpy, Window root, int width, int height, int depth, Visual *visual, Colormap cmap, Bool opaque) { - cairo_t *cr = cairo_create (); + cairo_t *cr; cairo_surface_t *back_surface; cairo_surface_t *temp_surface = 0; + cairo_surface_t *target_surface; Pixmap background; /* * Background pixmap */ background = XCreatePixmap (dpy, root, width, height, depth); - back_surface = cairo_xlib_surface_create (dpy, background, visual, 0, cmap); + back_surface = cairo_xlib_surface_create (dpy, background, visual, width, height); + target_surface = back_surface; if (depth == 32) { @@ -71,10 +75,9 @@ make_background (Display *dpy, Window ro * draw the background to the temporary surface */ - cairo_set_target_surface (cr, temp_surface); + target_surface = temp_surface; } - else - cairo_set_target_surface (cr, back_surface); + cr = cairo_create (target_surface); clear (cr, width, height, temp_surface ? 0 : 1); @@ -82,8 +85,7 @@ make_background (Display *dpy, Window ro { cairo_save (cr); { - cairo_set_rgb_color (cr, 1, 1, 1); - cairo_set_alpha (cr, opaque ? 1 : 0.5); + cairo_set_source_rgba (cr, 1, 1, 1, opaque ? 1 : 0.5); cairo_scale (cr, width, height); cairo_translate (cr, 0.5, 0.5); cairo_arc (cr, 0, 0, 0.5, 0, 2 * M_PI); @@ -96,13 +98,15 @@ make_background (Display *dpy, Window ro if (temp_surface) { - cairo_set_target_surface (cr, back_surface); + cairo_t *cr2; - clear (cr, width, height, 0); + cr2 = cairo_create (back_surface); - cairo_set_alpha (cr, opaque ? 1 : 0.8); + clear (cr2, width, height, 0); - cairo_show_surface (cr, temp_surface, width, height); + cairo_set_source_surface (cr2, temp_surface, 0, 0); + cairo_paint_with_alpha (cr2, opaque ? 1 : 0.8); + cairo_destroy (cr2); cairo_surface_destroy (temp_surface); } cairo_surface_destroy (back_surface); @@ -110,14 +114,14 @@ make_background (Display *dpy, Window ro return background; } -void +static void main_x (char *dpy_name, char *geom, Bool seconds, Bool translucent, Bool square, Bool opaque) { Display *dpy; int scr; int x = 0, y = 0; - int width = CLOCK_WIDTH, height = CLOCK_HEIGHT; + unsigned int width = CLOCK_WIDTH, height = CLOCK_HEIGHT; Window root; Visual *visual; XWMHints *wmhints; @@ -135,7 +139,7 @@ main_x (char *dpy_name, char *geom, Bool XEvent ev; Bool paint = False; int timeout; - cairo_t *cr = cairo_create (); + cairo_t *cr; dpy = XOpenDisplay (dpy_name); if (!dpy) @@ -265,12 +269,13 @@ main_x (char *dpy_name, char *geom, Bool u_width, u_height, depth); buffer_surface = cairo_xlib_surface_create (dpy, buffer, visual, 0, cmap); - cairo_set_target_surface (cr, buffer_surface); + cr = cairo_create (buffer_surface); XCopyArea (dpy, background, buffer, gc, 0, 0, u_width, u_height, 0, 0); fdhand_draw_now (cr, u_width, u_height, seconds); XCopyArea (dpy, buffer, w, gc, 0, 0, u_width, u_height, x_off, y_off); + cairo_destroy (cr); cairo_surface_destroy (buffer_surface); XFreePixmap (dpy, buffer); paint = False; Index: fdface.c =================================================================== RCS file: /mirrors/freedesktop/xapps/fdclock/fdface.c,v retrieving revision 1.2 diff -u -p -r1.2 fdface.c --- fdface.c 18 Jun 2004 11:02:34 -0000 1.2 +++ fdface.c 20 Jun 2005 16:27:09 -0000 @@ -29,9 +29,9 @@ draw_fancy_tick (cairo_t *cr, double rad { cairo_save (cr); cairo_arc (cr, 0, 0, radius, 0, 2 * M_PI); - cairo_set_rgb_color (cr, 0.231, 0.502, 0.682); + cairo_set_source_rgb (cr, 0.231, 0.502, 0.682); cairo_fill (cr); - cairo_set_rgb_color (cr, 0.73, 0.73, 0.73); + cairo_set_source_rgb (cr, 0.73, 0.73, 0.73); cairo_set_line_width (cr, radius * 2 / 3); cairo_arc (cr, 0, 0, radius * 2, 0, 2 * M_PI); cairo_stroke (cr); @@ -43,7 +43,7 @@ draw_plain_tick (cairo_t *cr, double rad { cairo_save (cr); cairo_arc (cr, 0, 0, radius, 0, 2 * M_PI); - cairo_set_rgb_color (cr, 0.73, 0.73, 0.73); + cairo_set_source_rgb (cr, 0.73, 0.73, 0.73); cairo_fill (cr); cairo_restore (cr); } @@ -51,8 +51,6 @@ draw_plain_tick (cairo_t *cr, double rad void fdface_draw (cairo_t *cr, double width, double height) { - double x_off, y_off; - double size; int minute; cairo_save (cr); Index: fdfacepng.c =================================================================== RCS file: /mirrors/freedesktop/xapps/fdclock/fdfacepng.c,v retrieving revision 1.1 diff -u -p -r1.1 fdfacepng.c --- fdfacepng.c 2 Dec 2003 03:04:46 -0000 1.1 +++ fdfacepng.c 20 Jun 2005 16:40:18 -0000 @@ -22,29 +22,30 @@ * PERFORMANCE OF THIS SOFTWARE. */ +#include #include #include "fdface.h" static int dump_png (int width, int height) { - int stride = width * 4; - cairo_t *cr = cairo_create ();; - char *image = calloc (stride * height, 1); + cairo_t *cr; + cairo_surface_t *surface; char out[1024]; - cairo_set_target_image (cr, image, CAIRO_FORMAT_ARGB32, - width, height, stride); + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, + width, height); + cr = cairo_create (surface); cairo_move_to (cr, 0, 0); cairo_line_to (cr, width, 0); cairo_line_to (cr, width, height); cairo_line_to (cr, 0, height); cairo_close_path (cr); - cairo_set_rgb_color (cr, 1, 1, 1); + cairo_set_source_rgb (cr, 1, 1, 1); cairo_fill (cr); fdface_draw (cr, width, height); sprintf (out, "freedesktop-clock-%d.png", width); - write_png_argb32 (image, out, width, height, stride); + cairo_surface_write_to_png (surface, out); cairo_destroy (cr); return 0; Index: fdhand.c =================================================================== RCS file: /mirrors/freedesktop/xapps/fdclock/fdhand.c,v retrieving revision 1.4 diff -u -p -r1.4 fdhand.c --- fdhand.c 18 Jun 2004 11:02:34 -0000 1.4 +++ fdhand.c 20 Jun 2005 16:23:37 -0000 @@ -74,15 +74,14 @@ static void draw_hand (cairo_t *cr, double noon_deg, double width, double length, double alt, void (*draw) (cairo_t *cr, double width, double length)) { - cairo_matrix_t *m = cairo_matrix_create (); - cairo_current_matrix (cr, m); + cairo_matrix_t m; + cairo_get_matrix (cr, &m); { cairo_translate (cr, alt/2, alt); cairo_rotate (cr, noon_deg * M_PI / 180.0 - M_PI_2); (*draw) (cr, width, length); } - cairo_set_matrix (cr, m); - cairo_matrix_destroy (m); + cairo_set_matrix (cr, &m); } #define HOUR_WIDTH 0.03 @@ -120,12 +119,10 @@ draw_time (cairo_t *cr, double width, do if (seconds) draw_hand (cr, second_angle, SECOND_WIDTH, SECOND_LENGTH, SECOND_ALT, draw_second); - cairo_set_rgb_color (cr, 0, 0, 0); - cairo_set_alpha (cr, 0.3); + cairo_set_source_rgba (cr, 0, 0, 0, 0.3); cairo_fill (cr); - cairo_set_rgb_color (cr, 0, 0, 0); - cairo_set_alpha (cr, 1); + cairo_set_source_rgba (cr, 0, 0, 0, 1); draw_hand (cr, hour_angle, HOUR_WIDTH, HOUR_LENGTH, 0.0, draw_hour); cairo_fill (cr); @@ -144,8 +141,7 @@ void fdhand_draw_now (cairo_t *cr, double width, double height, int seconds) { struct timeval tv; - struct timezone tz; - gettimeofday (&tv, &tz); + gettimeofday (&tv, NULL); draw_time (cr, width, height, &tv, seconds); } Index: fdlogo.c =================================================================== RCS file: /mirrors/freedesktop/xapps/fdclock/fdlogo.c,v retrieving revision 1.1 diff -u -p -r1.1 fdlogo.c --- fdlogo.c 2 Dec 2003 03:04:47 -0000 1.1 +++ fdlogo.c 20 Jun 2005 16:27:02 -0000 @@ -56,7 +56,7 @@ draw_boundary (cairo_t *cr) static void draw_outline (cairo_t *cr) { - cairo_set_rgb_color (cr, 0.73, 0.73, 0.73); + cairo_set_source_rgb (cr, 0.73, 0.73, 0.73); cairo_set_line_width (cr, 2); draw_boundary (cr); cairo_stroke (cr); @@ -66,7 +66,7 @@ static void draw_background (cairo_t *cr) { cairo_save (cr); - cairo_set_rgb_color (cr, 0.231, 0.502, 0.682); + cairo_set_source_rgb (cr, 0.231, 0.502, 0.682); cairo_translate (cr, 3.5, 3.5); cairo_scale (cr, 0.887, 0.848); draw_boundary (cr); @@ -115,18 +115,18 @@ draw_window_at (cairo_t *cr, double x, d draw_window (cr); cairo_save (cr); { - cairo_set_rgb_color (cr, 1, 1, 1); + cairo_set_source_rgb (cr, 1, 1, 1); cairo_fill (cr); } cairo_restore (cr); - cairo_set_rgb_color (cr, 0.231, 0.502, 0.682); + cairo_set_source_rgb (cr, 0.231, 0.502, 0.682); cairo_scale (cr, 1/scale, 1/scale); cairo_stroke (cr); } cairo_restore (cr); } -void +static void draw_windows (cairo_t *cr) { cairo_save (cr); @@ -135,8 +135,7 @@ draw_windows (cairo_t *cr) cairo_line_to (cr, 48.25, 20.375); cairo_line_to (cr, 30.25, 35.825); cairo_close_path (cr); - cairo_set_rgb_color (cr, 1, 1, 1); - cairo_set_alpha (cr, 0.5); + cairo_set_source_rgba (cr, 1, 1, 1, 0.5); cairo_stroke (cr); } cairo_restore (cr); Index: write_png.c =================================================================== RCS file: write_png.c diff -N write_png.c --- write_png.c 1 Dec 2003 20:43:51 -0000 1.1.1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,186 +0,0 @@ -#include -#include -#include - -#include "write_png.h" - -static void -unpremultiply_data (png_structp png, png_row_infop row_info, png_bytep data) -{ - int i; - - for (i = 0; i < row_info->rowbytes; i += 4) { - unsigned char *b = &data[i]; - unsigned char alpha = b[3]; - unsigned long pixel; - unsigned long *p; - if (alpha == 0) - pixel = 0; - else - pixel = ((((b[0] * 255) / alpha) << 0) | - (((b[1] * 255) / alpha) << 8) | - (((b[2] * 255) / alpha) << 16) | - (alpha << 24)); - p = (unsigned long *) b; - *p = pixel; - } -} - -static void -premultiply_data (png_structp png, png_row_infop row_info, png_bytep data) -{ - int i; - - for (i = 0; i < row_info->rowbytes; i += 4) { - unsigned char *base = &data[i]; - unsigned char blue = base[0]; - unsigned char green = base[1]; - unsigned char red = base[2]; - unsigned char alpha = base[3]; - unsigned long p; - - red = (unsigned) red * (unsigned) alpha / 255; - green = (unsigned) green * (unsigned) alpha / 255; - blue = (unsigned) blue * (unsigned) alpha / 255; - p = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0); - memcpy (base, &p, sizeof (unsigned long)); - } -} - -void -write_png_argb32 (char *buffer, char* filename, - int width, int height, int stride) -{ - FILE* f; - png_struct* png; - png_info* info; - png_byte** rows; - int i; - png_color_16 white; - - f = fopen (filename, "w"); - rows = malloc (height*sizeof (png_byte*)); - - for (i=0;ijmpbuf)) - { - png_destroy_read_struct (&png, &info, NULL); - return NULL; - } - f = fopen (filename, "rb"); - if (f == NULL) - { - png_destroy_read_struct (&png, &info, NULL); - return NULL; - } - png_init_io (png, f); - png_read_info (png, info); - png_get_IHDR (png, info, &width, &height, &depth, &color, &interlace, - NULL, NULL); - - if (color == PNG_COLOR_TYPE_PALETTE && depth <= 8) - png_set_expand (png); - - if (color == PNG_COLOR_TYPE_GRAY && depth < 8) - png_set_expand (png); - - if (png_get_valid (png, info, PNG_INFO_tRNS)) - png_set_expand (png); - - if (depth == 16) - png_set_strip_16 (png); - - if (depth < 8) - png_set_packing (png); - - if (color == PNG_COLOR_TYPE_GRAY || color == PNG_COLOR_TYPE_GRAY_ALPHA) - png_set_gray_to_rgb (png); - - if (interlace != PNG_INTERLACE_NONE) - png_set_interlace_handling (png); - - png_set_bgr (png); - png_set_filler (png, 255, PNG_FILLER_AFTER); - - png_set_read_user_transform_fn (png, premultiply_data); - - png_read_update_info (png, info); - - stride = width * 4; - buffer = malloc (stride * height); - - rows = malloc (sizeof (png_bytep) * height); - - for (i = 0; i < height; i++) - rows[i] = (png_bytep) (buffer + i * stride); - - png_read_image (png, rows); - png_read_end (png, info); - - free (rows); - fclose (f); - png_destroy_read_struct (&png, &info, NULL); - - *widthp = (int) width; - *heightp = (int) height; - *stridep = (int) stride; - - return buffer; -} - - Index: write_png.h =================================================================== RCS file: write_png.h diff -N write_png.h --- write_png.h 1 Dec 2003 20:43:51 -0000 1.1.1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,12 +0,0 @@ -#ifndef WRITE_PNG_H -#define WRITE_PNG_H - -void -write_png_argb32 (char *buffer, char* filename, - int width, int height, int stride); - -char * -read_png_argb32 (char *filename, - int *width, int *height, int *stride); - -#endif