Просмотр исходного кода

* Implemented a proof-of-concept cacaplay program that can redisplay a

single frame that was saved by the raw driver.
tags/v0.99.beta14
Sam Hocevar sam 18 лет назад
Родитель
Сommit
2542a4cff4
3 измененных файлов: 98 добавлений и 6 удалений
  1. +13
    -5
      caca/driver_raw.c
  2. +4
    -1
      src/Makefile.am
  3. +81
    -0
      src/cacaplay.c

+ 13
- 5
caca/driver_raw.c Просмотреть файл

@@ -57,18 +57,26 @@ static void raw_display(caca_t *kk)
{
uint8_t *attr = kk->qq->attr;
uint32_t *chars = kk->qq->chars;
int n;
uint32_t w, h;
unsigned int n;

w = kk->qq->width;
h = kk->qq->height;

fprintf(stdout, "CACA%c%c%c%c%c%c%c%c",
(w >> 24), (w >> 16) & 0xff, (w >> 8) & 0xff, w & 0xff,
(h >> 24), (h >> 16) & 0xff, (h >> 8) & 0xff, h & 0xff);

fprintf(stdout, "CACA %i %i\n", kk->qq->width, kk->qq->height);
for(n = kk->qq->height * kk->qq->width; n--; )
{
uint32_t c = *chars++;
uint8_t a = *attr++;

fprintf(stdout, "%c%c%c%c %c", (c >> 24), (c >> 16) & 0xff,
(c >> 8) & 0xff, c & 0xff, a);
fprintf(stdout, "%c%c%c%c%c", (c >> 24), (c >> 16) & 0xff,
(c >> 8) & 0xff, c & 0xff, a);
}
fprintf(stdout, "ACAC\n");

fprintf(stdout, "ACAC");
fflush(stdout);
}



+ 4
- 1
src/Makefile.am Просмотреть файл

@@ -5,7 +5,7 @@ pkgdata_DATA = caca.txt
EXTRA_DIST = caca.txt
AM_CPPFLAGS = -I$(top_srcdir)/cucul -I$(top_srcdir)/caca -DLIBCACA=1 -DX_DISPLAY_MISSING=1

bin_PROGRAMS = cacafire cacaball cacaplas cacaview cacamoir
bin_PROGRAMS = cacafire cacaball cacaplas cacaview cacamoir cacaplay

cacafire_SOURCES = aafire.c
cacafire_LDADD = ../caca/libcaca.la ../cucul/libcucul.la @CACA_LIBS@
@@ -29,3 +29,6 @@ cacaview_CFLAGS =
cacaview_LDFLAGS =
endif

cacaplay_SOURCES = cacaplay.c
cacaplay_LDADD = ../caca/libcaca.la ../cucul/libcucul.la @CACA_LIBS@


+ 81
- 0
src/cacaplay.c Просмотреть файл

@@ -0,0 +1,81 @@
/*
* cacaplay caca file player
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id$
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Do What The Fuck You Want To
* Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/

#include "config.h"

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>

#include "cucul.h"
#include "caca.h"

int main(int argc, char **argv)
{
struct stat statbuf;
struct caca_event ev;
cucul_t *qq;
caca_t *kk;
void *buffer;
int fd;

if(argc < 2)
{
fprintf(stderr, "%s: missing argument (filename).\n", argv[0]);
return 1;
}

fd = open(argv[1], O_RDONLY);
if(!fd)
{
fprintf(stderr, "%s: could not open %s.\n", argv[0], argv[1]);
return 1;
}

if(fstat(fd, &statbuf))
{
fprintf(stderr, "%s: could not stat %s.\n", argv[0], argv[1]);
return 1;
}

buffer = malloc(statbuf.st_size);
read(fd, buffer, statbuf.st_size);
qq = cucul_load(buffer, statbuf.st_size);
free(buffer);

if(!qq)
{
fprintf(stderr, "%s: invalid caca file %s.\n", argv[0], argv[1]);
return 1;
}

kk = caca_attach(qq);

caca_display(kk);

while(caca_wait_event(kk, CACA_EVENT_KEY_PRESS, &ev))
{
if(ev.data.key.c == CACA_KEY_ESCAPE)
break;
}

/* Clean up */
caca_detach(kk);
cucul_free(qq);

return 0;
}


Загрузка…
Отмена
Сохранить