]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/services/gfx/mw/v2_0/src/drivers/fblin12.c
Initial revision
[karo-tx-redboot.git] / packages / services / gfx / mw / v2_0 / src / drivers / fblin12.c
1 /* by julian schroeder <detemp1@germany.cirrus.com>
2  * for Cirrus Logic  based on fblin24.c
3  *
4  * Copyright (c) 2000 Greg Haerr <greg@censoft.com>
5  *
6  * 12bpp Linear Video Driver for Microwindows
7  *
8  * UNDER CONSTRUCTION
9  */
10 /*#define NDEBUG*/
11 #include <assert.h>
12 #include <string.h>
13 #include "device.h"
14 #include "fb.h"
15
16 int gr_mode=MWMODE_XOR;
17
18 /* Calc linelen and mmap size, return 0 on fail*/
19 static int
20 linear12_init(PSD psd)
21 {
22         if (!psd->size) {
23                 psd->size = 960*240/2;
24                 /* convert linelen from byte to pixel len for bpp 16, 24, 32*/
25                 psd->linelen *= 2;
26                 psd->linelen /= 3; /* /1.5*/
27         }
28         return 1;
29 }
30
31 static inline void setpix(char *cptr,int x, int y, char c)
32 {
33 long adr;
34
35 adr=(x>>1) + (y*480);  /* change, julian*/
36
37 if(gr_mode == MWMODE_XOR) 
38   {
39   if(x & 0x01) cptr[adr]^=((c << 4) & 0xf0);
40   else cptr[adr]^=(c & 0x0f);
41   }    
42 else 
43   {
44   if(x & 0x01) 
45     {
46     cptr[adr]&=0x0f;
47     cptr[adr]|=((c << 4) & 0xf0);
48     }
49   else
50     { 
51     cptr[adr]&=0xf0;
52     cptr[adr]|=(c & 0x0f);
53     }
54   }
55 }
56
57 static inline char getpix(char *cptr,int x, int y)
58 {
59 long adr;
60 adr=(x>>1) + (y*480);  /* change, julian*/
61
62 if(x & 0x01) return (cptr[adr] >> 4) & 0x0f;
63 return cptr[adr] & 0x0f;
64 }
65
66
67 /* Set pixel at x, y, to pixelval c*/
68 static void
69 linear12_drawpixel(PSD psd, MWCOORD x, MWCOORD y, MWPIXELVAL c)
70 {
71         ADDR8   addr = psd->addr;
72         MWUCHAR r, g, b;
73
74         assert (addr != 0);
75         assert (x >= 0 && x < psd->xres);
76         assert (y >= 0 && y < psd->yres);
77         assert (c < psd->ncolors);
78
79         r = PIXEL444RED(c);
80         g = PIXEL444GREEN(c);
81         b = PIXEL444BLUE(c);
82         x=x+(x<<1);
83         DRAWON;
84         setpix(addr,x,y,r);
85         setpix(addr,x+1,y,g);
86         setpix(addr,x+2,y,b);
87         DRAWOFF;
88 }
89
90 /* Read pixel at x, y*/
91 static MWPIXELVAL
92 linear12_readpixel(PSD psd, MWCOORD x, MWCOORD y)
93 {
94         ADDR8   addr = psd->addr;
95
96         assert (addr != 0);
97         assert (x >= 0 && x < psd->xres);
98         assert (y >= 0 && y < psd->yres);
99         x=x+(x<<1);
100         return RGB2PIXEL444(getpix(addr,x,y),getpix(addr,x+1,y),getpix(addr,x+2,y));
101 }
102
103 /* Draw horizontal line from x1,y to x2,y including final point*/
104 static void
105 linear12_drawhorzline(PSD psd, MWCOORD x1, MWCOORD x2, MWCOORD y, MWPIXELVAL c)
106 {
107         ADDR8   addr = psd->addr;
108         MWUCHAR r, g, b;
109
110         assert (addr != 0);
111         assert (x1 >= 0 && x1 < psd->xres);
112         assert (x2 >= 0 && x2 < psd->xres);
113         assert (x2 >= x1);
114         assert (y >= 0 && y < psd->yres);
115         assert (c < psd->ncolors);
116
117         r = PIXEL444RED(c);
118         g = PIXEL444GREEN(c);
119         b = PIXEL444BLUE(c);
120         DRAWON;
121                 x1*=3;
122                 x2*=3;
123                 while((x1+=3) <= x2) {
124                 setpix(addr,x1,y,r);
125                 setpix(addr,x1+1,y,g);
126                 setpix(addr,x1+2,y,b);
127                 }
128         DRAWOFF;
129 }
130
131 /* Draw a vertical line from x,y1 to x,y2 including final point*/
132 static void
133 linear12_drawvertline(PSD psd, MWCOORD x, MWCOORD y1, MWCOORD y2, MWPIXELVAL c)
134 {
135         ADDR8   addr = psd->addr;
136         int     linelen = psd->linelen * 3;
137         MWUCHAR r, g, b;
138         linelen/=2;
139         assert (addr != 0);
140         assert (x >= 0 && x < psd->xres);
141         assert (y1 >= 0 && y1 < psd->yres);
142         assert (y2 >= 0 && y2 < psd->yres);
143         assert (y2 >= y1);
144         assert (c < psd->ncolors);
145         x=x+(x<<1);
146         r = PIXEL444RED(c);
147         g = PIXEL444GREEN(c);
148         b = PIXEL444BLUE(c);
149         
150         DRAWON;
151                 while(y1++ <= y2) 
152                 {
153                 setpix(addr,x,y1,r);
154                 setpix(addr,x+1,y1,g);
155                 setpix(addr,x+2,y1,b);
156                 }               
157         DRAWOFF;
158 }
159
160 #if 0
161 /* srccopy bitblt, opcode is currently ignored*/
162 static void
163 xlinear12_blit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD w, MWCOORD h,
164         PSD srcpsd, MWCOORD srcx, MWCOORD srcy, long op)
165 {
166         ADDR8   dst = dstpsd->addr;
167         ADDR8   src = srcpsd->addr;
168         int     i;
169         int     dlinelen = dstpsd->linelen * 3;
170         int     slinelen = srcpsd->linelen * 3;
171         int     dlinelen_minus_w = (dstpsd->linelen - w) * 3;
172         int     slinelen_minus_w = (srcpsd->linelen - w) * 3;
173 #if ALPHABLEND
174         unsigned int alpha;
175 #endif
176
177         assert (dst != 0);
178         assert (dstx >= 0 && dstx < dstpsd->xres);
179         assert (dsty >= 0 && dsty < dstpsd->yres);
180         assert (w > 0);
181         assert (h > 0);
182         assert (src != 0);
183         assert (srcx >= 0 && srcx < srcpsd->xres);
184         assert (srcy >= 0 && srcy < srcpsd->yres);
185         assert (dstx+w <= dstpsd->xres);
186         assert (dsty+h <= dstpsd->yres);
187         assert (srcx+w <= srcpsd->xres);
188         assert (srcy+h <= srcpsd->yres);
189
190         DRAWON;
191         dst += (dstx + dsty * dstpsd->linelen) * 3;
192         src += (srcx + srcy * srcpsd->linelen) * 3;
193
194 #if ALPHABLEND
195         if((op & MWROP_EXTENSION) != MWROP_BLENDCONSTANT)
196                 goto stdblit;
197         alpha = op & 0xff;
198
199         while(--h >= 0) {
200                 for(i=0; i<w; ++i) {
201                         unsigned long s = *src++;
202                         unsigned long d = *dst;
203                         *dst++ = (unsigned char)(((s - d)*alpha)>>8) + d;
204                         s = *src++;
205                         d = *dst;
206                         *dst++ = (unsigned char)(((s - d)*alpha)>>8) + d;
207                         s = *src++;
208                         d = *dst;
209                         *dst++ = (unsigned char)(((s - d)*alpha)>>8) + d;
210                 }
211                 dst += dlinelen_minus_w;
212                 src += slinelen_minus_w;
213         }
214         DRAWOFF;
215         return;
216 stdblit:
217 #endif
218         while(--h >= 0) {
219 #if 1
220                 /* a _fast_ memcpy is a _must_ in this routine*/
221                 memcpy(dst, src, w*3);
222                 dst += dlinelen;
223                 src += slinelen;
224 #else
225                 for(i=0; i<w; ++i) {
226                         *dst++ = *src++;
227                         *dst++ = *src++;
228                         *dst++ = *src++;
229                 }
230                 dst += dlinelen_minus_w;
231                 src += slinelen_minus_w;
232 #endif
233         }
234         DRAWOFF;
235 }
236 #endif
237
238 /* srccopy bitblt, opcode is currently ignored*/
239 static void
240 linear12_blit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD w, MWCOORD h,
241         PSD srcpsd, MWCOORD srcx, MWCOORD srcy, long op)
242 {
243         ADDR8   dst = dstpsd->addr;
244         ADDR8   src = srcpsd->addr;
245
246         /*if ((srcx & 0x01) || (dstx & 0x01))*/
247         /* FIXME where is this if supposed to end?? */
248
249         DRAWON;
250         dst+=((dstx*3+1)/2)+480*dsty;
251         src+=((srcx*3+1)/2)+480*srcx;
252
253         assert (dst != 0);
254         assert (dstx >= 0 && dstx < dstpsd->xres);
255         assert (dsty >= 0 && dsty < dstpsd->yres);
256         assert (w > 0);
257         assert (h > 0);
258         assert (src != 0);
259         assert (srcx >= 0 && srcx < srcpsd->xres);
260         assert (srcy >= 0 && srcy < srcpsd->yres);
261         assert (dstx+w <= dstpsd->xres);
262         assert (dsty+h <= dstpsd->yres);
263         assert (srcx+w <= srcpsd->xres);
264         assert (srcy+h <= srcpsd->yres);
265
266
267         if((srcx & 0x01) && !(dstx & 0x01))
268           {
269           src+=1;
270           /*w-=1;*/
271           }
272
273         if(!(srcx & 0x01) && (dstx & 0x01))
274           {
275           dst+=1;
276           /*w-=1;*/
277           }
278
279         if((srcx & 0x01) && (dstx & 0x01))
280           {
281           /*w-=1;*/
282           }
283
284
285         while(--h >= 0) {
286                 /* a _fast_ memcpy is a _must_ in this routine*/
287                 memcpy(dst, src, (w*3+1)/2);
288                 dst += 480;
289                 src += 480;
290         }
291         DRAWOFF;
292 }
293
294
295 SUBDRIVER fblinear12 = {
296         linear12_init,
297         linear12_drawpixel,
298         linear12_readpixel,
299         linear12_drawhorzline,
300         linear12_drawvertline,
301         gen_fillrect,
302         linear12_blit
303 };