* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include <errno.h>
#include <SDL.h>
#include <SDL_image.h>
Uint32 time_start;
Uint32 time_end;
- if (argc != 2) {
- fprintf(stderr, "usage: %s <image>\n", argv[0]);
+ int output_fd = -1;
+
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s <image> [<output file>]\n", argv[0]);
return -EINVAL;
}
goto out;
}
+ /* Set up the output file */
+ if (argc >= 3) {
+ if (strncmp(argv[2], "-", 1) == 0) {
+ output_fd = STDOUT_FILENO;
+ } else {
+ output_fd = open(argv[2], O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
+ if (output_fd < 0) {
+ perror("open");
+ ret = output_fd;
+ goto out;
+ }
+ }
+ }
+
lastframe_limit = (map->h - HEIGHT);
if (SDL_NumJoysticks() > 0)
SDL_BlitSurface(map, &viewport, screen, NULL);
SDL_Flip(screen);
+ if (output_fd >= 0) {
+ int len = screen->w * screen->h * screen->format->BytesPerPixel;
+
+ ret = write(output_fd, screen->pixels, len);
+ if (ret != len) {
+ fprintf(stderr, "invalid write\n");
+ running = 0;
+ }
+ }
+
time_end = SDL_GetTicks();
if (time_end - time_start < 1000 / FPS)
SDL_Delay((1000 / FPS) - (time_end - time_start));
ret = 0;
+ if (output_fd >= 0)
+ close(output_fd);
+
if (SDL_JoystickOpened(0))
SDL_JoystickClose(joystick);