1 /* $Id: s_bitmap.c,v 1.19 2002/08/07 00:45:07 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * \file swrast/s_bitmap.c
29 * \brief glBitmap rendering.
39 #include "s_context.h"
48 _swrast_Bitmap( GLcontext
*ctx
, GLint px
, GLint py
,
49 GLsizei width
, GLsizei height
,
50 const struct gl_pixelstore_attrib
*unpack
,
51 const GLubyte
*bitmap
)
53 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
58 ASSERT(ctx
->RenderMode
== GL_RENDER
);
61 RENDER_START(swrast
,ctx
);
63 if (SWRAST_CONTEXT(ctx
)->NewState
)
64 _swrast_validate_derived( ctx
);
66 INIT_SPAN(span
, GL_BITMAP
, width
, 0, SPAN_XY
);
68 if (ctx
->Visual
.rgbMode
) {
69 span
.interpMask
|= SPAN_RGBA
;
70 span
.red
= FloatToFixed(ctx
->Current
.RasterColor
[0] * CHAN_MAXF
);
71 span
.green
= FloatToFixed(ctx
->Current
.RasterColor
[1] * CHAN_MAXF
);
72 span
.blue
= FloatToFixed(ctx
->Current
.RasterColor
[2] * CHAN_MAXF
);
73 span
.alpha
= FloatToFixed(ctx
->Current
.RasterColor
[3] * CHAN_MAXF
);
74 span
.redStep
= span
.greenStep
= span
.blueStep
= span
.alphaStep
= 0;
77 span
.interpMask
|= SPAN_INDEX
;
78 span
.index
= ChanToFixed(ctx
->Current
.RasterIndex
);
83 _mesa_span_default_z(ctx
, &span
);
85 _mesa_span_default_fog(ctx
, &span
);
87 for (row
= 0; row
< height
; row
++, span
.y
++) {
88 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address( unpack
,
89 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
91 if (unpack
->LsbFirst
) {
93 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
94 for (col
= 0; col
< width
; col
++) {
96 span
.array
->x
[count
] = px
+ col
;
97 span
.array
->y
[count
] = py
+ row
;
109 /* get ready for next row */
115 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
116 for (col
= 0; col
< width
; col
++) {
118 span
.array
->x
[count
] = px
+ col
;
119 span
.array
->y
[count
] = py
+ row
;
131 /* get ready for next row */
136 if (count
+ width
>= MAX_WIDTH
|| row
+ 1 == height
) {
139 if (ctx
->Visual
.rgbMode
)
140 _mesa_write_rgba_span(ctx
, &span
);
142 _mesa_write_index_span(ctx
, &span
);
148 RENDER_FINISH(swrast
,ctx
);
154 * XXX this is another way to implement Bitmap. Use horizontal runs of
155 * fragments, initializing the mask array to indicate which fragmens to
159 _swrast_Bitmap( GLcontext
*ctx
, GLint px
, GLint py
,
160 GLsizei width
, GLsizei height
,
161 const struct gl_pixelstore_attrib
*unpack
,
162 const GLubyte
*bitmap
)
164 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
168 ASSERT(ctx
->RenderMode
== GL_RENDER
);
171 RENDER_START(swrast
,ctx
);
173 if (SWRAST_CONTEXT(ctx
)->NewState
)
174 _swrast_validate_derived( ctx
);
176 INIT_SPAN(span
, GL_BITMAP
, width
, 0, SPAN_MASK
);
178 /*span.arrayMask |= SPAN_MASK;*/ /* we'll init span.mask[] */
181 /*span.end = width;*/
182 if (ctx
->Visual
.rgbMode
) {
183 span
.interpMask
|= SPAN_RGBA
;
184 span
.red
= FloatToFixed(ctx
->Current
.RasterColor
[0] * CHAN_MAXF
);
185 span
.green
= FloatToFixed(ctx
->Current
.RasterColor
[1] * CHAN_MAXF
);
186 span
.blue
= FloatToFixed(ctx
->Current
.RasterColor
[2] * CHAN_MAXF
);
187 span
.alpha
= FloatToFixed(ctx
->Current
.RasterColor
[3] * CHAN_MAXF
);
188 span
.redStep
= span
.greenStep
= span
.blueStep
= span
.alphaStep
= 0;
191 span
.interpMask
|= SPAN_INDEX
;
192 span
.index
= ChanToFixed(ctx
->Current
.RasterIndex
);
197 _mesa_span_default_z(ctx
, &span
);
198 if (ctx
->Fog
.Enabled
)
199 _mesa_span_default_fog(ctx
, &span
);
201 for (row
=0; row
<height
; row
++, span
.y
++) {
202 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address( unpack
,
203 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
205 if (unpack
->LsbFirst
) {
207 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
208 for (col
=0; col
<width
; col
++) {
209 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
219 if (ctx
->Visual
.rgbMode
)
220 _mesa_write_rgba_span(ctx
, &span
);
222 _mesa_write_index_span(ctx
, &span
);
224 /* get ready for next row */
230 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
231 for (col
=0; col
<width
; col
++) {
232 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
242 if (ctx
->Visual
.rgbMode
)
243 _mesa_write_rgba_span(ctx
, &span
);
245 _mesa_write_index_span(ctx
, &span
);
247 /* get ready for next row */
253 RENDER_FINISH(swrast
,ctx
);