/[gxemul]/upstream/0.4.2/src/devices/fb_include.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /upstream/0.4.2/src/devices/fb_include.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations)
Mon Oct 8 16:20:48 2007 UTC (16 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 7498 byte(s)
0.4.2
1 /*
2 * $Id: fb_include.c,v 1.2 2005/11/30 21:20:42 debug Exp $
3 *
4 * Included from dev_fb.c.
5 *
6 * FB_SCALEDOWN should be defined if d->vfb_scaledown > 1.
7 * FB_BO for d->fb_window->fb_ximage->byte_order non-zero
8 * FB_24 for 24-bit X11 color.
9 * FB_16 for 16-bit X11 color.
10 * FB_15 for 15-bit X11 color.
11 * (Default is to fallback to grayscale.)
12 */
13
14
15 #ifdef macro_put_pixel1
16 #undef macro_put_pixel1
17 #endif
18
19 /* Combine the color into an X11 long and display it: */ \
20 /* TODO: construct color in a more portable way: */ \
21
22 #ifdef FB_24
23 #ifdef FB_BO
24 #define macro_put_pixel1 color = (b << 16) + (g << 8) + r
25 #else
26 #define macro_put_pixel1 color = (r << 16) + (g << 8) + b
27 #endif
28
29 #else /* !24 */
30 #ifdef FB_16
31 #ifdef FB_BO
32 #define macro_put_pixel1 color = ((b >> 3) << 11) + ((g >> 2) << 5) + (r >> 3)
33 #else
34 #define macro_put_pixel1 color = ((r >> 3) << 11) + ((g >> 2) << 5) + (b >> 3)
35 #endif
36
37 #else /* !16 */
38 #ifdef FB_15
39 #ifdef FB_BO
40 #define macro_put_pixel1 color = ((b >> 3) << 10) + ((g >> 3) << 5) + (r >> 3)
41 #else
42 #define macro_put_pixel1 color = ((r >> 3) << 10) + ((g >> 3) << 5) + (b >> 3)
43 #endif
44
45 #else /* !15 */
46 #define macro_put_pixel1 color = d->fb_window->x11_graycolor[15 * \
47 (r + g + b) / (255 * 3)].pixel
48
49 #endif /* !15 */
50
51 #endif /* !16 */
52
53 #endif /* !24 */
54
55
56 #ifdef macro_put_pixel
57 #undef macro_put_pixel
58 #endif
59
60 #define macro_put_pixel macro_put_pixel1; \
61 if (x>=0 && x<d->x11_xsize && y>=0 && y<d->x11_ysize) \
62 XPutPixel(d->fb_window->fb_ximage, x, y, color); \
63
64
65 void REDRAW(struct vfb_data *d, int addr, int len)
66 {
67 int x, y, pixel, npixels;
68 long color_r, color_g, color_b;
69 long color;
70
71 #ifndef FB_SCALEDOWN
72
73 /* Which framebuffer pixel does addr correspond to? */
74 pixel = addr * 8 / d->bit_depth;
75 y = pixel / d->xsize;
76 x = pixel % d->xsize;
77
78 /* How many framebuffer pixels? */
79 npixels = len * 8 / d->bit_depth;
80 if (npixels == 0)
81 npixels = 1;
82
83 if (d->bit_depth < 8) {
84 for (pixel=0; pixel<npixels; pixel++) {
85 int fb_addr, c, r, g, b;
86 color_r = color_g = color_b = 0;
87
88 fb_addr = (y * d->xsize + x) * d->bit_depth;
89 /* fb_addr is now which _bit_ in
90 the framebuffer */
91
92 c = d->framebuffer[fb_addr >> 3];
93 fb_addr &= 7;
94
95 /* HPC is reverse: */
96 if (d->vfb_type == VFB_HPC)
97 fb_addr = 8 - d->bit_depth - fb_addr;
98
99 c = (c >> fb_addr) & ((1<<d->bit_depth) - 1);
100 /* c <<= (8 - d->bit_depth); */
101
102 r = d->rgb_palette[c*3 + 0];
103 g = d->rgb_palette[c*3 + 1];
104 b = d->rgb_palette[c*3 + 2];
105
106 macro_put_pixel;
107 x++;
108 }
109 } else if (d->bit_depth == 8) {
110 for (pixel=0; pixel<npixels; pixel++) {
111 int fb_addr, c, r, g, b;
112 color_r = color_g = color_b = 0;
113
114 fb_addr = y * d->xsize + x;
115 /* fb_addr is now which byte in framebuffer */
116 c = d->framebuffer[fb_addr];
117 r = d->rgb_palette[c*3 + 0];
118 g = d->rgb_palette[c*3 + 1];
119 b = d->rgb_palette[c*3 + 2];
120
121 macro_put_pixel;
122 x++;
123 }
124 } else { /* d->bit_depth > 8 */
125 for (pixel=0; pixel<npixels; pixel++) {
126 int fb_addr, r, g, b;
127 color_r = color_g = color_b = 0;
128
129 fb_addr = (y * d->xsize + x) * d->bit_depth;
130 /* fb_addr is now which byte in framebuffer */
131
132 /* > 8 bits color. */
133 fb_addr >>= 3;
134 switch (d->bit_depth) {
135 case 24:
136 r = d->framebuffer[fb_addr];
137 g = d->framebuffer[fb_addr + 1];
138 b = d->framebuffer[fb_addr + 2];
139 break;
140 /* TODO: copy to the scaledown code below */
141 case 16:
142 if (d->vfb_type == VFB_HPC) {
143 b = d->framebuffer[fb_addr] +
144 (d->framebuffer[fb_addr+1] << 8);
145
146 if (d->color32k) {
147 r = b >> 11;
148 g = b >> 5;
149 r = r & 31;
150 g = (g & 31) * 2;
151 b = b & 31;
152 } else if (d->psp_15bit) {
153 int tmp;
154 r = (b >> 10) & 0x1f;
155 g = (b >> 5) & 0x1f;
156 b = b & 0x1f;
157 g <<= 1;
158 tmp = r; r = b; b = tmp;
159 } else {
160 r = (b >> 11) & 0x1f;
161 g = (b >> 5) & 0x3f;
162 b = b & 0x1f;
163 }
164 } else {
165 r = d->framebuffer[fb_addr] >> 3;
166 /* HUH? TODO: */
167 g = (d->framebuffer[fb_addr] << 5) +
168 (d->framebuffer[fb_addr + 1] >>5);
169 b = d->framebuffer[fb_addr + 1]&31;
170 }
171
172 r *= 8;
173 g *= 4;
174 b *= 8;
175 break;
176 default:
177 r = g = b = random() & 255;
178 }
179
180 macro_put_pixel;
181 x++;
182 }
183 }
184
185 #else /* FB_SCALEDOWN */
186
187 /* scaledown > 1: */
188 int scaledown = d->vfb_scaledown;
189 int scaledownXscaledown = scaledown * scaledown;
190
191 /* Which framebuffer pixel does addr correspond to? */
192 pixel = addr * 8 / d->bit_depth;
193 y = pixel / d->xsize;
194 x = pixel % d->xsize;
195
196 /* How many framebuffer pixels? */
197 npixels = len * 8 / d->bit_depth;
198
199 /* Which x11 pixel? */
200 x /= scaledown;
201 y /= scaledown;
202
203 /* How many x11 pixels: */
204 npixels /= scaledown;
205 if (npixels == 0)
206 npixels = 1;
207
208 if (d->bit_depth < 8) {
209 for (pixel=0; pixel<npixels; pixel++) {
210 int subx, suby, r, g, b;
211 color_r = color_g = color_b = 0;
212 for (suby=0; suby<scaledown; suby++)
213 for (subx=0; subx<scaledown; subx++) {
214 int fb_x, fb_y, fb_addr, c;
215
216 fb_x = x * scaledown + subx;
217 fb_y = y * scaledown + suby;
218 fb_addr = fb_y * d->xsize + fb_x;
219 fb_addr = fb_addr * d->bit_depth;
220 /* fb_addr is now which _bit_ in
221 the framebuffer */
222
223 c = d->framebuffer[fb_addr >> 3];
224 fb_addr &= 7;
225
226 /* HPC is reverse: */
227 if (d->vfb_type == VFB_HPC)
228 fb_addr = 8 - d->bit_depth - fb_addr;
229
230 c = (c >> fb_addr) & ((1<<d->bit_depth) - 1);
231 /* c <<= (8 - d->bit_depth); */
232
233 r = d->rgb_palette[c*3 + 0];
234 g = d->rgb_palette[c*3 + 1];
235 b = d->rgb_palette[c*3 + 2];
236
237 color_r += r;
238 color_g += g;
239 color_b += b;
240 }
241
242 r = color_r / scaledownXscaledown;
243 g = color_g / scaledownXscaledown;
244 b = color_b / scaledownXscaledown;
245 macro_put_pixel;
246 x++;
247 }
248 } else if (d->bit_depth == 8) {
249 for (pixel=0; pixel<npixels; pixel++) {
250 int subx, suby, r, g, b;
251 color_r = color_g = color_b = 0;
252 for (suby=0; suby<scaledown; suby++)
253 for (subx=0; subx<scaledown; subx++) {
254 int fb_x, fb_y, fb_addr, c;
255
256 fb_x = x * scaledown + subx;
257 fb_y = y * scaledown + suby;
258 fb_addr = fb_y * d->xsize + fb_x;
259 /* fb_addr is which _byte_ in framebuffer */
260 c = d->framebuffer[fb_addr] * 3;
261 r = d->rgb_palette[c + 0];
262 g = d->rgb_palette[c + 1];
263 b = d->rgb_palette[c + 2];
264 color_r += r;
265 color_g += g;
266 color_b += b;
267 }
268
269 r = color_r / scaledownXscaledown;
270 g = color_g / scaledownXscaledown;
271 b = color_b / scaledownXscaledown;
272 macro_put_pixel;
273 x++;
274 }
275 } else {
276 /* Generic > 8 bit bit-depth: */
277 for (pixel=0; pixel<npixels; pixel++) {
278 int subx, suby, r, g, b;
279 color_r = color_g = color_b = 0;
280 for (suby=0; suby<scaledown; suby++)
281 for (subx=0; subx<scaledown; subx++) {
282 int fb_x, fb_y, fb_addr;
283
284 fb_x = x * scaledown + subx;
285 fb_y = y * scaledown + suby;
286 fb_addr = fb_y * d->xsize + fb_x;
287 fb_addr = (fb_addr * d->bit_depth) >> 3;
288 /* fb_addr is which _byte_ in framebuffer */
289
290 /* > 8 bits color. */
291 switch (d->bit_depth) {
292 case 24:
293 r = d->framebuffer[fb_addr];
294 g = d->framebuffer[fb_addr + 1];
295 b = d->framebuffer[fb_addr + 2];
296 break;
297 default:
298 r = g = b = random() & 255;
299 }
300 color_r += r;
301 color_g += g;
302 color_b += b;
303 }
304 r = color_r / scaledownXscaledown;
305 g = color_g / scaledownXscaledown;
306 b = color_b / scaledownXscaledown;
307 macro_put_pixel;
308 x++;
309 }
310 }
311 #endif /* FB_SCALEDOWN */
312 }
313

  ViewVC Help
Powered by ViewVC 1.1.26