frame_buf.c
2.92 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <stdio.h>
#include <string.h>
#ifdef __sgi__
#include <bstring.h>
#include <gl/gl.h>
#include <gl/device.h>
#include <gl/image.h>
#else
#include <PR/PRimage.h>
#endif
#include "image.h"
#include "acc_user.h"
#include "vcsuser.h"
#define TAB_LINE_SIZE 2048
static s_setval_value value_s = { accHexStrVal };
static s_setval_delay delay_s = { { accRealTime, 0, 0, 0 }, accNoDelay };
static Image FrameBuf;
/*
* save_image -- save 32b RGBA frame buffer in 24b .rgb format
*
*
*/
static void
save_image(char *name, Image *image)
{
IMAGE *img;
unsigned short *cb;
unsigned char *fb;
int x, xl, y, xsize, ysize;
xsize = image->xsize;
ysize = image->ysize;
img = iopen(name, "w", RLE(1), 3, xsize, ysize, 3);
if (img == (IMAGE *)0) {
fprintf(stderr, "error in creating image %s\n", name);
return;
}
cb = (unsigned short *)calloc(sizeof(unsigned short), xsize);
fb = image->base;
for (y = 0; y < ysize; y++, fb += image->lsize) {
for (xl = 0, x = 0; xl < xsize; x += 4, xl++) cb[xl] = fb[x];
putrow(img, cb, y, 0);
for (xl = 0, x = 1; xl < xsize; x += 4, xl++) cb[xl] = fb[x];
putrow(img, cb, y, 1);
for (xl = 0, x = 2; xl < xsize; x += 4, xl++) cb[xl] = fb[x];
putrow(img, cb, y, 2);
}
free(cb);
iclose(img);
}
void
open_frame_buffer(void)
{
int x, y;
acc_initialize();
acc_configure(accDevelopmentVersion, "1.6");
if (tf_nump() != 2)
{
tf_error("illegal number of arguments") ;
tf_putp(0, -1);
}
else
{
if (((x = tf_getp(1)) == 0) ||
((y = tf_getp(2)) == 0))
{
tf_putp(0, -1);
}
else
{
FrameBuf.xsize = x;
FrameBuf.ysize = y;
FrameBuf.lsize = x * 4; /* 32 bit pixels */
FrameBuf.base = (unsigned char *)
calloc(FrameBuf.ysize * FrameBuf.lsize, sizeof(unsigned char));
tf_putp(0, 0);
}
}
}
void
write_frame_buffer(void)
{
char *fb_file;
acc_initialize();
acc_configure(accDevelopmentVersion, "1.6");
if (((fb_file = tf_getcstringp(1)) == NULL))
{
tf_putp(0, -1);
}
else
{
save_image(fb_file, &FrameBuf);
tf_putp(0, 0);
}
}
void
put_pixel(void)
{
int x, y, r, g, b, a;
unsigned char *pixel;
acc_initialize();
acc_configure(accDevelopmentVersion, "1.6");
if (tf_nump() != 6)
{
tf_error("illegal number of arguments") ;
tf_putp(0, -1);
}
else
{
x = tf_getp(1);
y = tf_getp(2);
r = tf_getp(3);
g = tf_getp(4);
b = tf_getp(5);
a = tf_getp(6);
if((x >= FrameBuf.xsize) || (y >= FrameBuf.ysize))
{
fprintf(stderr,"Error, x(%d) or y(%d) > max x,y(%d,%d)\n",
x, y, FrameBuf.xsize, FrameBuf.ysize);
tf_putp(0, -1);
}
else
{
pixel = FrameBuf.base + y * FrameBuf.lsize + x * 4;
pixel[0] = (unsigned char) r;
pixel[1] = (unsigned char) g;
pixel[2] = (unsigned char) b;
pixel[3] = (unsigned char) a;
tf_putp(0, 0);
}
}
}