return new_image;
}
-#ifdef PLY_IMAGE_ENABLE_TEST
-
-#include "ply-frame-buffer.h"
-
-#include <math.h>
-#include <signal.h>
-#include <stdio.h>
-#include <sys/ioctl.h>
-#include <sys/time.h>
-#include <values.h>
-
-#include <linux/kd.h>
-
-#ifndef FRAMES_PER_SECOND
-#define FRAMES_PER_SECOND 50
-#endif
-
-static int console_fd;
-
-static bool
-hide_cursor (void)
-{
- static const char invisible_cursor[] = "\033[?25l\033[?1c";
-
- if (write (STDOUT_FILENO, invisible_cursor,
- sizeof (invisible_cursor) - 1) != sizeof (invisible_cursor) - 1)
- return false;
-
- return true;
-}
-
-static double
-get_current_time (void)
-{
- const double microseconds_per_second = 1000000.0;
- double timestamp;
- struct timeval now = { 0L, /* zero-filled */ };
-
- gettimeofday (&now, NULL);
- timestamp = ((microseconds_per_second * now.tv_sec) + now.tv_usec) /
- microseconds_per_second;
-
- return timestamp;
-}
-
-double start_time = 0.0;
-int num_frames = 0;
-
-static void
-animate_at_time (ply_frame_buffer_t *buffer,
- ply_image_t *image,
- double time)
-{
- ply_frame_buffer_area_t area;
- uint32_t *data;
- long width, height;
- static double last_opacity = 0.0;
- double opacity = 0.0;
-
- data = ply_image_get_data (image);
- width = ply_image_get_width (image);
- height = ply_image_get_height (image);
-
- ply_frame_buffer_get_size (buffer, &area);
- area.x = (area.width / 2) - (width / 2);
- area.y = (area.height / 2) - (height / 2);
- area.width = width;
- area.height = height;
-
- opacity = .5 * sin ((time / 4) * (2 * M_PI)) + .8;
- opacity = CLAMP (opacity, 0, 1.0);
-
- num_frames++;
- if (fabs (opacity - last_opacity) <= DBL_MIN)
- return;
-
- last_opacity = opacity;
-
- ply_frame_buffer_pause_updates (buffer);
- ply_frame_buffer_fill_with_color (buffer, &area, 0.1, 0.1, .7, 1.0);
- ply_frame_buffer_fill_with_argb32_data_at_opacity (buffer, &area,
- 0, 0, data, opacity);
- ply_frame_buffer_unpause_updates (buffer);
-
- if (time > 10.0)
- ioctl (console_fd, KDSETMODE, KD_TEXT);
-}
-
-int
-main (int argc,
- char **argv)
-{
- ply_image_t *image;
- ply_frame_buffer_t *buffer;
- int exit_code;
-
- exit_code = 0;
-
- hide_cursor ();
-
- if (argc == 1)
- image = ply_image_new ("booting.png");
- else
- image = ply_image_new (argv[1]);
-
- if (!ply_image_load (image))
- {
- exit_code = errno;
- perror ("could not load image");
- return exit_code;
- }
-
- console_fd = open ("/dev/tty0", O_RDWR);
-
- buffer = ply_frame_buffer_new (NULL);
-
- if (!ply_frame_buffer_open (buffer))
- {
- exit_code = errno;
- perror ("could not open framebuffer");
- return exit_code;
- }
-
- start_time = get_current_time ();
- ply_frame_buffer_fill_with_color (buffer, NULL, 0.1, 0.1, .7, 1.0);
- while ("we want to see ad-hoc animations")
- {
- long sleep_time;
- double now;
-
- now = get_current_time ();
- animate_at_time (buffer, image, now - start_time);
- sleep_time = 1000000 / FRAMES_PER_SECOND;
- sleep_time = MAX (sleep_time - ((get_current_time () - now) / 1000000),
- 10000);
- usleep (sleep_time);
- }
- ply_frame_buffer_close (buffer);
- ply_frame_buffer_free (buffer);
-
- ply_image_free (image);
-
- return exit_code;
-}
-
-#endif /* PLY_IMAGE_ENABLE_TEST */
/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */