getimages.c
2.93 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* getimages.c:
*
* opens the debug port to the rdpvector app, then reads image data provided
* by the app (which has a command line flag to "dump image data".
*
* We assume that users will have started up rdpvector and given it the "dump
* image" command line flag, so that it will jive with this application.
*/
#include <stdio.h>
#include <errno.h>
#include <PRimage.h>
/*
* The following should be in gl/image.h, but they are commented out
* Also note that the prototype for iopen in image.h is wrong
*/
int iclose(IMAGE *image);
int putrow(IMAGE *image, unsigned short *buffer, unsigned int y,unsigned int z);
#define DUMP_REQUEST 0xdeadbeef
#define DUMP_REPLY 0xbaaddeed
main(int argc, char **argv) /* Host side code */
{
int fd, status;
unsigned int hostBuffer[2];
unsigned char *imageBuf;
unsigned char *p;
unsigned short *rbuf, *gbuf, *bbuf;
IMAGE *img;
int xsize = 320;
int ysize = 240;
int i, j;
/*
* XXX add support for 16 bit framebuffers
* XXX add support for arbitrary x, y size framebuffers
*/
if (argc != 2) {
fprintf(stderr, "usage: %s <.rgb filename>\n", argv[0]);
exit(1);
}
if ((fd = uhOpenGame("/dev/u64")) == -1) {
perror("uhOpenGame");
exit(1);
}
hostBuffer[0] = DUMP_REQUEST;
if (uhWriteGame(fd, hostBuffer, 4) == -1) {
fprintf(stderr, "uhWriteGame %s\n", sys_errlist[errno]);
exit(1);
}
/*
* Read the reply, blocking if necessary.
*/
if (uhReadGame(fd, hostBuffer, 8) == -1) {
fprintf(stderr, "uhReadGame %s\n", sys_errlist[errno]);
exit(1);
}
if (hostBuffer[0] != DUMP_REPLY) {
fprintf(stderr, "unexpected response from game: 0x%x\n", hostBuffer[0]);
exit(1);
}
imageBuf = (unsigned char *)malloc(hostBuffer[1]);
if (imageBuf == NULL) {
fprintf(stderr, "%s: unable to malloc %d bytes.\n",
argv[0], hostBuffer[1]);
}
uhReadGame(fd, imageBuf, hostBuffer[1]);
img = iopen(argv[1], "w", RLE(1), 3, xsize, ysize, 3);
if (img == (IMAGE *)0) {
fprintf(stderr, "%s: couldn't create .rgb file\n", argv[0]);
exit(1);
}
rbuf = (unsigned short *)malloc(sizeof(unsigned short) * xsize);
if (rbuf == NULL)
goto cleanup;
gbuf = (unsigned short *)malloc(sizeof(unsigned short) * xsize);
if (gbuf == NULL)
goto cleanup;
bbuf = (unsigned short *)malloc(sizeof(unsigned short) * xsize);
if (bbuf == NULL)
goto cleanup;
/* read data out of framebuffer into .rgb file */
for ( i = 0; i < ysize; i++) {
p = imageBuf + ((ysize - i - 1) * xsize * 4);
for (j = 0; j < xsize; j++) {
rbuf[j] = *p++;
gbuf[j] = *p++;
bbuf[j] = *p++;
*p++;
}
putrow(img, rbuf, i, 0);
putrow(img, gbuf, i, 1);
putrow(img, bbuf, i, 2);
}
cleanup:
if (rbuf) free(rbuf);
if (gbuf) free(gbuf);
if (bbuf) free(bbuf);
iclose(img);
if (uhCloseGame(fd) != 0) {
perror("uhCloseGame");
exit(1);
}
exit(0);
}