OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [mw/] [src/] [drivers/] [fblin24.c] - Blame information for rev 1773

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 * Copyright (c) 2000, 2001 Greg Haerr <greg@censoft.com>
3
 *
4
 * 24bpp Linear Video Driver for Microwindows
5
 */
6
/*#define NDEBUG*/
7
#include <assert.h>
8
#include <string.h>
9
#include "device.h"
10
#include "fb.h"
11
 
12
/* Calc linelen and mmap size, return 0 on fail*/
13
static int
14
linear24_init(PSD psd)
15
{
16
        if (!psd->size) {
17
                psd->size = psd->yres * psd->linelen;
18
                /* convert linelen from byte to pixel len for bpp 16, 24, 32*/
19
                psd->linelen /= 3;
20
        }
21
        return 1;
22
}
23
 
24
/* Set pixel at x, y, to pixelval c*/
25
static void
26
linear24_drawpixel(PSD psd, MWCOORD x, MWCOORD y, MWPIXELVAL c)
27
{
28
        ADDR8   addr = psd->addr;
29
        MWUCHAR r, g, b;
30
 
31
        assert (addr != 0);
32
        assert (x >= 0 && x < psd->xres);
33
        assert (y >= 0 && y < psd->yres);
34
        assert (c < psd->ncolors);
35
 
36
        r = PIXEL888RED(c);
37
        g = PIXEL888GREEN(c);
38
        b = PIXEL888BLUE(c);
39
        addr += (x + y * psd->linelen) * 3;
40
        DRAWON;
41
        if(gr_mode == MWMODE_COPY) {
42
                *addr++ = b;
43
                *addr++ = g;
44
                *addr = r;
45
        } else {
46
                applyOp(gr_mode, b, addr, ADDR8); ++addr;
47
                applyOp(gr_mode, g, addr, ADDR8); ++addr;
48
                applyOp(gr_mode, r, addr, ADDR8);
49
        }
50
        DRAWOFF;
51
}
52
 
53
/* Read pixel at x, y*/
54
static MWPIXELVAL
55
linear24_readpixel(PSD psd, MWCOORD x, MWCOORD y)
56
{
57
        ADDR8   addr = psd->addr;
58
 
59
        assert (addr != 0);
60
        assert (x >= 0 && x < psd->xres);
61
        assert (y >= 0 && y < psd->yres);
62
 
63
        addr += (x + y * psd->linelen) * 3;
64
        return RGB2PIXEL888(addr[2], addr[1], addr[0]);
65
}
66
 
67
/* Draw horizontal line from x1,y to x2,y including final point*/
68
static void
69
linear24_drawhorzline(PSD psd, MWCOORD x1, MWCOORD x2, MWCOORD y, MWPIXELVAL c)
70
{
71
        ADDR8   addr = psd->addr;
72
        MWUCHAR r, g, b;
73
 
74
        assert (addr != 0);
75
        assert (x1 >= 0 && x1 < psd->xres);
76
        assert (x2 >= 0 && x2 < psd->xres);
77
        assert (x2 >= x1);
78
        assert (y >= 0 && y < psd->yres);
79
        assert (c < psd->ncolors);
80
 
81
        r = PIXEL888RED(c);
82
        g = PIXEL888GREEN(c);
83
        b = PIXEL888BLUE(c);
84
        addr += (x1 + y * psd->linelen) * 3;
85
        DRAWON;
86
        if(gr_mode == MWMODE_COPY) {
87
                while(x1++ <= x2) {
88
                        *addr++ = b;
89
                        *addr++ = g;
90
                        *addr++ = r;
91
                }
92
        } else {
93
                while (x1++ <= x2) {
94
                        applyOp(gr_mode, b, addr, ADDR8); ++addr;
95
                        applyOp(gr_mode, g, addr, ADDR8); ++addr;
96
                        applyOp(gr_mode, r, addr, ADDR8); ++addr;
97
                }
98
        }
99
        DRAWOFF;
100
}
101
 
102
/* Draw a vertical line from x,y1 to x,y2 including final point*/
103
static void
104
linear24_drawvertline(PSD psd, MWCOORD x, MWCOORD y1, MWCOORD y2, MWPIXELVAL c)
105
{
106
        ADDR8   addr = psd->addr;
107
        int     linelen = psd->linelen * 3;
108
        MWUCHAR r, g, b;
109
 
110
        assert (addr != 0);
111
        assert (x >= 0 && x < psd->xres);
112
        assert (y1 >= 0 && y1 < psd->yres);
113
        assert (y2 >= 0 && y2 < psd->yres);
114
        assert (y2 >= y1);
115
        assert (c < psd->ncolors);
116
 
117
        r = PIXEL888RED(c);
118
        g = PIXEL888GREEN(c);
119
        b = PIXEL888BLUE(c);
120
        addr += (x + y1 * psd->linelen) * 3;
121
        DRAWON;
122
        if(gr_mode == MWMODE_COPY) {
123
                while(y1++ <= y2) {
124
                        addr[0] = b;
125
                        addr[1] = g;
126
                        addr[2] = r;
127
                        addr += linelen;
128
                }
129
        } else {
130
                while (y1++ <= y2) {
131
                        applyOp(gr_mode, b, &addr[0], ADDR8);
132
                        applyOp(gr_mode, g, &addr[1], ADDR8);
133
                        applyOp(gr_mode, r, &addr[2], ADDR8);
134
                        addr += linelen;
135
                }
136
        }
137
        DRAWOFF;
138
}
139
 
140
/* srccopy bitblt, opcode is currently ignored*/
141
static void
142
linear24_blit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD w, MWCOORD h,
143
        PSD srcpsd, MWCOORD srcx, MWCOORD srcy, long op)
144
{
145
        ADDR8   dst = dstpsd->addr;
146
        ADDR8   src = srcpsd->addr;
147
        int     i;
148
        int     dlinelen = dstpsd->linelen * 3;
149
        int     slinelen = srcpsd->linelen * 3;
150
        int     dlinelen_minus_w = (dstpsd->linelen - w) * 3;
151
        int     slinelen_minus_w = (srcpsd->linelen - w) * 3;
152
#if ALPHABLEND
153
        unsigned int alpha;
154
#endif
155
 
156
        assert (dst != 0);
157
        assert (dstx >= 0 && dstx < dstpsd->xres);
158
        assert (dsty >= 0 && dsty < dstpsd->yres);
159
        assert (w > 0);
160
        assert (h > 0);
161
        assert (src != 0);
162
        assert (srcx >= 0 && srcx < srcpsd->xres);
163
        assert (srcy >= 0 && srcy < srcpsd->yres);
164
        assert (dstx+w <= dstpsd->xres);
165
        assert (dsty+h <= dstpsd->yres);
166
        assert (srcx+w <= srcpsd->xres);
167
        assert (srcy+h <= srcpsd->yres);
168
 
169
        DRAWON;
170
        dst += (dstx + dsty * dstpsd->linelen) * 3;
171
        src += (srcx + srcy * srcpsd->linelen) * 3;
172
 
173
#if ALPHABLEND
174
        if((op & MWROP_EXTENSION) != MWROP_BLENDCONSTANT)
175
                goto stdblit;
176
        alpha = op & 0xff;
177
 
178
        while(--h >= 0) {
179
                for(i=0; i<w; ++i) {
180
                        unsigned long s = *src++;
181
                        unsigned long d = *dst;
182
                        *dst++ = (unsigned char)(((s - d)*alpha)>>8) + d;
183
                        s = *src++;
184
                        d = *dst;
185
                        *dst++ = (unsigned char)(((s - d)*alpha)>>8) + d;
186
                        s = *src++;
187
                        d = *dst;
188
                        *dst++ = (unsigned char)(((s - d)*alpha)>>8) + d;
189
                }
190
                dst += dlinelen_minus_w;
191
                src += slinelen_minus_w;
192
        }
193
        DRAWOFF;
194
        return;
195
stdblit:
196
#endif
197
 
198
        if (op == MWROP_COPY) {
199
                /* copy from bottom up if dst in src rectangle*/
200
                /* memmove is used to handle x case*/
201
                if (srcy < dsty) {
202
                        src += (h-1) * slinelen;
203
                        dst += (h-1) * dlinelen;
204
                        slinelen *= -1;
205
                        dlinelen *= -1;
206
                }
207
                while(--h >= 0) {
208
                        /* a _fast_ memcpy is a _must_ in this routine*/
209
                        memmove(dst, src, w*3);
210
                        dst += dlinelen;
211
                        src += slinelen;
212
                }
213
        } else {
214
                for(i=w*3; i>=0; --i) {
215
                        applyOp(MWROP_TO_MODE(op), *src, dst, ADDR8);
216
                        ++src;
217
                        ++dst;
218
                }
219
                dst += dlinelen_minus_w;
220
                src += slinelen_minus_w;
221
        }
222
        DRAWOFF;
223
}
224
 
225
/* srccopy stretchblt*/
226
static void
227
linear24_stretchblit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD dstw,
228
        MWCOORD dsth, PSD srcpsd, MWCOORD srcx, MWCOORD srcy, MWCOORD srcw,
229
        MWCOORD srch, long op)
230
{
231
        ADDR8   dst;
232
        ADDR8   src;
233
        int     dlinelen = dstpsd->linelen;
234
        int     slinelen = srcpsd->linelen;
235
        int     i, ymax;
236
        int     row_pos, row_inc;
237
        int     col_pos, col_inc;
238
        unsigned char r = 0;
239
        unsigned char g = 0;
240
        unsigned char b = 0;
241
 
242
        assert (dstpsd->addr != 0);
243
        assert (dstx >= 0 && dstx < dstpsd->xres);
244
        assert (dsty >= 0 && dsty < dstpsd->yres);
245
        assert (dstw > 0);
246
        assert (dsth > 0);
247
        assert (srcpsd->addr != 0);
248
        assert (srcx >= 0 && srcx < srcpsd->xres);
249
        assert (srcy >= 0 && srcy < srcpsd->yres);
250
        assert (srcw > 0);
251
        assert (srch > 0);
252
        assert (dstx+dstw <= dstpsd->xres);
253
        assert (dsty+dsth <= dstpsd->yres);
254
        assert (srcx+srcw <= srcpsd->xres);
255
        assert (srcy+srch <= srcpsd->yres);
256
 
257
        DRAWON;
258
        row_pos = 0x10000;
259
        row_inc = (srch << 16) / dsth;
260
 
261
        /* stretch blit using integer ratio between src/dst height/width*/
262
        for (ymax = dsty+dsth; dsty<ymax; ++dsty) {
263
 
264
                /* find source y position*/
265
                while (row_pos >= 0x10000L) {
266
                        ++srcy;
267
                        row_pos -= 0x10000L;
268
                }
269
 
270
                dst = dstpsd->addr + (dstx + dsty*dlinelen) * 3;
271
                src = srcpsd->addr + (srcx + (srcy-1)*slinelen) * 3;
272
 
273
                /* copy a row of pixels*/
274
                col_pos = 0x10000;
275
                col_inc = (srcw << 16) / dstw;
276
                for (i=0; i<dstw; ++i) {
277
                        /* get source x pixel*/
278
                        while (col_pos >= 0x10000L) {
279
                                b = *src++;
280
                                g = *src++;
281
                                r = *src++;
282
                                col_pos -= 0x10000L;
283
                        }
284
                        *dst++ = b;
285
                        *dst++ = g;
286
                        *dst++ = r;
287
                        col_pos += col_inc;
288
                }
289
 
290
                row_pos += row_inc;
291
        }
292
        DRAWOFF;
293
}
294
 
295
SUBDRIVER fblinear24 = {
296
        linear24_init,
297
        linear24_drawpixel,
298
        linear24_readpixel,
299
        linear24_drawhorzline,
300
        linear24_drawvertline,
301
        gen_fillrect,
302
        linear24_blit,
303
        NULL,
304
        linear24_stretchblit
305
};

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.