forked from arti/vt1200
86 lines
2.1 KiB
C
86 lines
2.1 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "../movie.h"
|
|
|
|
struct ctx {
|
|
int frame;
|
|
int last_tile;
|
|
int have_last;
|
|
};
|
|
|
|
static void report_fill(int x, int y, int w, int h, int color, void *opaque)
|
|
{
|
|
struct ctx *ctx = (struct ctx *)opaque;
|
|
int lx = x / 2;
|
|
int ly = y / 2;
|
|
int lw = w / 2;
|
|
int lh = h / 2;
|
|
int tx = lx / 32;
|
|
int ty = ly / 32;
|
|
int tile = ty * 2 + tx;
|
|
|
|
/* The decoder's first call for a tile is its background. */
|
|
if (!ctx->have_last || tile != ctx->last_tile) {
|
|
ctx->last_tile = tile;
|
|
ctx->have_last = 1;
|
|
return;
|
|
}
|
|
printf("%d %d %d %d %d %d %d\n", ctx->frame, tile, 1 - color,
|
|
lx % 32, ly % 32, lw, lh);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
FILE *file;
|
|
long size;
|
|
unsigned char *data;
|
|
struct movie_header header;
|
|
unsigned int frame;
|
|
struct ctx ctx;
|
|
|
|
if (argc != 2) {
|
|
fprintf(stderr, "usage: %s movie.bin\n", argv[0]);
|
|
return 2;
|
|
}
|
|
file = fopen(argv[1], "rb");
|
|
if (file == 0) {
|
|
fprintf(stderr, "cannot open %s\n", argv[1]);
|
|
return 2;
|
|
}
|
|
fseek(file, 0, SEEK_END);
|
|
size = ftell(file);
|
|
fseek(file, 0, SEEK_SET);
|
|
data = (unsigned char *)malloc((size_t)size);
|
|
if (data == 0) {
|
|
fclose(file);
|
|
return 2;
|
|
}
|
|
if (fread(data, 1, (size_t)size, file) != (size_t)size) {
|
|
fclose(file);
|
|
free(data);
|
|
return 2;
|
|
}
|
|
fclose(file);
|
|
|
|
if (movie_open(data, (unsigned long)size, &header) != 0) {
|
|
fprintf(stderr, "movie_open failed\n");
|
|
free(data);
|
|
return 1;
|
|
}
|
|
printf("frames=%u\n", header.frame_count);
|
|
for (frame = 0; frame < header.frame_count; frame++) {
|
|
ctx.frame = (int)frame;
|
|
ctx.last_tile = -1;
|
|
ctx.have_last = 0;
|
|
if (movie_decode_frame(data, (unsigned long)size, frame, &header,
|
|
report_fill, &ctx) != 0) {
|
|
fprintf(stderr, "decode failed at frame %u\n", frame);
|
|
free(data);
|
|
return 1;
|
|
}
|
|
}
|
|
free(data);
|
|
return 0;
|
|
}
|