fb_include.cc Source File

Back to the index.

fb_include.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003-2018 Anders Gavare. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  *
28  * Included from dev_fb.c.
29  *
30  * FB_SCALEDOWN should be defined if d->vfb_scaledown > 1.
31  * FB_BO for d->fb_window->fb_ximage->byte_order non-zero
32  * FB_24 for 24-bit X11 color.
33  * FB_16 for 16-bit X11 color.
34  * FB_15 for 15-bit X11 color.
35  * (Default is to fallback to grayscale.)
36  */
37 
38 
39 #ifdef macro_put_pixel1
40 #undef macro_put_pixel1
41 #endif
42 
43 /* Combine the color into an X11 long and display it: */ \
44 /* TODO: construct color in a more portable way: */ \
45 
46 #ifdef FB_24
47 #ifdef FB_BO
48 #define macro_put_pixel1 color = (b << 16) + (g << 8) + r
49 #else
50 #define macro_put_pixel1 color = (r << 16) + (g << 8) + b
51 #endif
52 
53 #else /* !24 */
54 #ifdef FB_16
55 #ifdef FB_BO
56 #define macro_put_pixel1 color = ((b >> 3) << 11) + ((g >> 2) << 5) + (r >> 3)
57 #else
58 #define macro_put_pixel1 color = ((r >> 3) << 11) + ((g >> 2) << 5) + (b >> 3)
59 #endif
60 
61 #else /* !16 */
62 #ifdef FB_15
63 #ifdef FB_BO
64 #define macro_put_pixel1 color = ((b >> 3) << 10) + ((g >> 3) << 5) + (r >> 3)
65 #else
66 #define macro_put_pixel1 color = ((r >> 3) << 10) + ((g >> 3) << 5) + (b >> 3)
67 #endif
68 
69 #else /* !15 */
70 #define macro_put_pixel1 color = d->fb_window->x11_graycolor[15 * \
71  (r + g + b) / (255 * 3)].pixel
72 
73 #endif /* !15 */
74 
75 #endif /* !16 */
76 
77 #endif /* !24 */
78 
79 
80 #ifdef macro_put_pixel
81 #undef macro_put_pixel
82 #endif
83 
84 #define macro_put_pixel macro_put_pixel1; \
85  if (x>=0 && x<d->x11_xsize && y>=0 && y<d->x11_ysize) \
86  XPutPixel(d->fb_window->fb_ximage, x, y, color); \
87 
88 
89 void REDRAW(struct vfb_data *d, int addr, int len)
90 {
91  int x, y, pixel, npixels;
92  long color_r, color_g, color_b;
93  long color;
94 
95 #ifndef FB_SCALEDOWN
96 
97  /* Which framebuffer pixel does addr correspond to? */
98  pixel = addr * 8 / d->bit_depth;
99  y = pixel / d->xsize;
100  x = pixel % d->xsize;
101 
102  /* How many framebuffer pixels? */
103  npixels = len * 8 / d->bit_depth;
104  if (npixels == 0)
105  npixels = 1;
106 
107  if (d->bit_depth < 8) {
108  for (pixel=0; pixel<npixels; pixel++) {
109  int fb_addr, c, r, g, b;
110  color_r = color_g = color_b = 0;
111 
112  fb_addr = (y * d->xsize + x) * d->bit_depth;
113  /* fb_addr is now which _bit_ in
114  the framebuffer */
115 
116  c = d->framebuffer[fb_addr >> 3];
117  fb_addr &= 7;
118 
119  /* HPC is reverse: */
120  if (d->vfb_type == VFB_HPC)
121  fb_addr = 8 - d->bit_depth - fb_addr;
122 
123  c = (c >> fb_addr) & ((1<<d->bit_depth) - 1);
124  /* c <<= (8 - d->bit_depth); */
125 
126  r = d->rgb_palette[c*3 + 0];
127  g = d->rgb_palette[c*3 + 1];
128  b = d->rgb_palette[c*3 + 2];
129 
131  x++;
132  }
133  } else if (d->bit_depth == 8) {
134  for (pixel=0; pixel<npixels; pixel++) {
135  int fb_addr, c, r, g, b;
136  color_r = color_g = color_b = 0;
137 
138  fb_addr = y * d->xsize + x;
139  /* fb_addr is now which byte in framebuffer */
140  c = d->framebuffer[fb_addr];
141  r = d->rgb_palette[c*3 + 0];
142  g = d->rgb_palette[c*3 + 1];
143  b = d->rgb_palette[c*3 + 2];
144 
146  x++;
147  }
148  } else { /* d->bit_depth > 8 */
149  for (pixel=0; pixel<npixels; pixel++) {
150  int fb_addr, r, g, b;
151  color_r = color_g = color_b = 0;
152 
153  fb_addr = (y * d->xsize + x) * d->bit_depth;
154  /* fb_addr is now which byte in framebuffer */
155 
156  /* > 8 bits color. */
157  fb_addr >>= 3;
158  switch (d->bit_depth) {
159  case 24:
160  case 32:
161  r = d->framebuffer[fb_addr];
162  g = d->framebuffer[fb_addr + 1];
163  b = d->framebuffer[fb_addr + 2];
164  break;
165  case 16:
166  if (d->vfb_type == VFB_HPC) {
167  b = d->framebuffer[fb_addr] +
168  (d->framebuffer[fb_addr+1] << 8);
169 
170  if (d->color32k) {
171  r = b >> 11;
172  g = b >> 5;
173  r = r & 31;
174  g = (g & 31) * 2;
175  b = b & 31;
176  } else if (d->psp_15bit) {
177  int tmp;
178  r = (b >> 10) & 0x1f;
179  g = (b >> 5) & 0x1f;
180  b = b & 0x1f;
181  g <<= 1;
182  tmp = r; r = b; b = tmp;
183  } else {
184  r = (b >> 11) & 0x1f;
185  g = (b >> 5) & 0x3f;
186  b = b & 0x1f;
187  }
188  } else {
189  r = d->framebuffer[fb_addr] >> 3;
190 /* HUH? TODO: */
191  g = (d->framebuffer[fb_addr] << 5) +
192  (d->framebuffer[fb_addr + 1] >>5);
193  b = d->framebuffer[fb_addr + 1]&31;
194  }
195 
196  r *= 8;
197  g *= 4;
198  b *= 8;
199  break;
200  default:
201  r = g = b = random() & 255;
202  }
203 
205  x++;
206  }
207  }
208 
209 #else /* FB_SCALEDOWN */
210 
211  /* scaledown > 1: */
212  int scaledown = d->vfb_scaledown;
213  int scaledownXscaledown = scaledown * scaledown;
214 
215  /* Which framebuffer pixel does addr correspond to? */
216  pixel = addr * 8 / d->bit_depth;
217  y = pixel / d->xsize;
218  x = pixel % d->xsize;
219 
220  /* How many framebuffer pixels? */
221  npixels = len * 8 / d->bit_depth;
222 
223  /* Which x11 pixel? */
224  x /= scaledown;
225  y /= scaledown;
226 
227  /* How many x11 pixels: */
228  npixels /= scaledown;
229  if (npixels == 0)
230  npixels = 1;
231 
232  if (d->bit_depth < 8) {
233  for (pixel=0; pixel<npixels; pixel++) {
234  int subx, suby, r, g, b;
235  color_r = color_g = color_b = 0;
236  for (suby=0; suby<scaledown; suby++)
237  for (subx=0; subx<scaledown; subx++) {
238  int fb_x, fb_y, fb_addr, c;
239 
240  fb_x = x * scaledown + subx;
241  fb_y = y * scaledown + suby;
242  fb_addr = fb_y * d->xsize + fb_x;
243  fb_addr = fb_addr * d->bit_depth;
244  /* fb_addr is now which _bit_ in
245  the framebuffer */
246 
247  c = d->framebuffer[fb_addr >> 3];
248  fb_addr &= 7;
249 
250  /* HPC is reverse: */
251  if (d->vfb_type == VFB_HPC)
252  fb_addr = 8 - d->bit_depth - fb_addr;
253 
254  c = (c >> fb_addr) & ((1<<d->bit_depth) - 1);
255  /* c <<= (8 - d->bit_depth); */
256 
257  r = d->rgb_palette[c*3 + 0];
258  g = d->rgb_palette[c*3 + 1];
259  b = d->rgb_palette[c*3 + 2];
260 
261  color_r += r;
262  color_g += g;
263  color_b += b;
264  }
265 
266  r = color_r / scaledownXscaledown;
267  g = color_g / scaledownXscaledown;
268  b = color_b / scaledownXscaledown;
270  x++;
271  }
272  } else if (d->bit_depth == 8) {
273  for (pixel=0; pixel<npixels; pixel++) {
274  int subx, suby, r, g, b;
275  color_r = color_g = color_b = 0;
276  for (suby=0; suby<scaledown; suby++)
277  for (subx=0; subx<scaledown; subx++) {
278  int fb_x, fb_y, fb_addr, c;
279 
280  fb_x = x * scaledown + subx;
281  fb_y = y * scaledown + suby;
282  fb_addr = fb_y * d->xsize + fb_x;
283  /* fb_addr is which _byte_ in framebuffer */
284  c = d->framebuffer[fb_addr] * 3;
285  r = d->rgb_palette[c + 0];
286  g = d->rgb_palette[c + 1];
287  b = d->rgb_palette[c + 2];
288  color_r += r;
289  color_g += g;
290  color_b += b;
291  }
292 
293  r = color_r / scaledownXscaledown;
294  g = color_g / scaledownXscaledown;
295  b = color_b / scaledownXscaledown;
297  x++;
298  }
299  } else {
300  /* Generic > 8 bit bit-depth: */
301  for (pixel=0; pixel<npixels; pixel++) {
302  int subx, suby, r, g, b;
303  color_r = color_g = color_b = 0;
304  for (suby=0; suby<scaledown; suby++)
305  for (subx=0; subx<scaledown; subx++) {
306  int fb_x, fb_y, fb_addr;
307 
308  fb_x = x * scaledown + subx;
309  fb_y = y * scaledown + suby;
310  fb_addr = fb_y * d->xsize + fb_x;
311  fb_addr = (fb_addr * d->bit_depth) >> 3;
312  /* fb_addr is which _byte_ in framebuffer */
313 
314  /* > 8 bits color. */
315  switch (d->bit_depth) {
316  case 24:
317  case 32:
318  r = d->framebuffer[fb_addr];
319  g = d->framebuffer[fb_addr + 1];
320  b = d->framebuffer[fb_addr + 2];
321  break;
322  case 16:
323  if (d->vfb_type == VFB_HPC) {
324  b = d->framebuffer[fb_addr] +
325  (d->framebuffer[fb_addr+1] << 8);
326 
327  if (d->color32k) {
328  r = b >> 11;
329  g = b >> 5;
330  r = r & 31;
331  g = (g & 31) * 2;
332  b = b & 31;
333  } else if (d->psp_15bit) {
334  int tmp;
335  r = (b >> 10) & 0x1f;
336  g = (b >> 5) & 0x1f;
337  b = b & 0x1f;
338  g <<= 1;
339  tmp = r; r = b; b = tmp;
340  } else {
341  r = (b >> 11) & 0x1f;
342  g = (b >> 5) & 0x3f;
343  b = b & 0x1f;
344  }
345  } else {
346  r = d->framebuffer[fb_addr] >> 3;
347 /* HUH? TODO: */
348  g = (d->framebuffer[fb_addr] << 5) +
349  (d->framebuffer[fb_addr + 1] >>5);
350  b = d->framebuffer[fb_addr + 1]&31;
351  }
352 
353  r *= 8;
354  g *= 4;
355  b *= 8;
356  break;
357  default:
358  r = g = b = random() & 255;
359  }
360  color_r += r;
361  color_g += g;
362  color_b += b;
363  }
364  r = color_r / scaledownXscaledown;
365  g = color_g / scaledownXscaledown;
366  b = color_b / scaledownXscaledown;
368  x++;
369  }
370  }
371 #endif /* FB_SCALEDOWN */
372 }
373 
macro_put_pixel
#define macro_put_pixel
Definition: fb_include.cc:84
vfb_data::rgb_palette
unsigned char rgb_palette[256 *3]
Definition: devices.h:223
if
addr & if(addr >=0x24 &&page !=NULL)
Definition: tmp_arm_multi.cc:56
vfb_data::xsize
int xsize
Definition: devices.h:204
addr
uint32_t addr
Definition: tmp_arm_multi.cc:52
vfb_data::vfb_scaledown
int vfb_scaledown
Definition: devices.h:202
vfb_data::vfb_type
int vfb_type
Definition: devices.h:200
vfb_data::framebuffer
unsigned char * framebuffer
Definition: devices.h:231
vfb_data::psp_15bit
int psp_15bit
Definition: devices.h:208
vfb_data::color32k
int color32k
Definition: devices.h:207
VFB_HPC
#define VFB_HPC
Definition: devices.h:191
REDRAW
void REDRAW(struct vfb_data *d, int addr, int len)
Definition: fb_include.cc:89
vfb_data
Definition: devices.h:198
vfb_data::bit_depth
int bit_depth
Definition: devices.h:206

Generated on Tue Aug 25 2020 19:25:06 for GXemul by doxygen 1.8.18