-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowframes.c
106 lines (80 loc) · 1.71 KB
/
showframes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#define BITSPERBYTE 8
#define HEADERBYTES 2
#define NUMFRAMES 256
void drawbin(const unsigned char *data)
{
unsigned char mask=0x80;
while (mask>0)
{
printf("%c", (((*data)&mask)>0)?'#':' ');
printf("%c", (((*data)&mask)>0)?'#':' ');
mask>>=1;
}
}
void drawbin_width(const unsigned char *data, const unsigned char width)
{
unsigned char done=0;
printf("|");
while ((done*8)<width)
{
drawbin(&data[done]);
done++;
}
printf("|\n");
}
int main()
{
FILE *rd;
struct stat fs;
uint8_t *framedata;
rd=fopen("frames.bin", "rb");
if (rd==NULL) return 1;
fstat(fileno(rd), &fs);
framedata=malloc(fs.st_size);
if (framedata!=NULL)
{
int frame;
fread(framedata, fs.st_size, 1, rd);
fclose(rd);
// Process it
for (frame=0; frame<(NUMFRAMES-1); frame++)
{
int start;
start=(framedata[frame*2]);
start=((framedata[(frame*2)+1]<<8)+start);
// Check for valid pointer
if (start<0xff00)
{
int width, height;
int offs;
int y;
printf("%d [%.2x] : 0x%.4x", frame, frame, start);
width=framedata[(NUMFRAMES*2)+start]*4;
height=framedata[(NUMFRAMES*2)+start+1];
printf(" (%dx%d)\n", width, height);
// Decode the framedata
offs=0;
for (y=0; y<height; y++)
{
drawbin_width(&framedata[(NUMFRAMES*2)+start+HEADERBYTES+offs], width);
offs+=(width/8);
}
printf("\n");
}
}
free(framedata);
}
else
{
fclose(rd);
return 1;
}
return 0;
}