1 /* $Id: s_bitmap.c,v 1.20 2002/11/25 20:26:59 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
);
86 if (ctx
->Texture
._EnabledUnits
)
87 _mesa_span_default_texcoords(ctx
, &span
);
89 for (row
= 0; row
< height
; row
++, span
.y
++) {
90 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address( unpack
,
91 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
93 if (unpack
->LsbFirst
) {
95 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
96 for (col
= 0; col
< width
; col
++) {
98 span
.array
->x
[count
] = px
+ col
;
99 span
.array
->y
[count
] = py
+ row
;
111 /* get ready for next row */
117 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
118 for (col
= 0; col
< width
; col
++) {
120 span
.array
->x
[count
] = px
+ col
;
121 span
.array
->y
[count
] = py
+ row
;
133 /* get ready for next row */
138 if (count
+ width
>= MAX_WIDTH
|| row
+ 1 == height
) {
141 if (ctx
->Visual
.rgbMode
)
142 _mesa_write_rgba_span(ctx
, &span
);
144 _mesa_write_index_span(ctx
, &span
);
150 RENDER_FINISH(swrast
,ctx
);
156 * XXX this is another way to implement Bitmap. Use horizontal runs of
157 * fragments, initializing the mask array to indicate which fragmens to
161 _swrast_Bitmap( GLcontext
*ctx
, GLint px
, GLint py
,
162 GLsizei width
, GLsizei height
,
163 const struct gl_pixelstore_attrib
*unpack
,
164 const GLubyte
*bitmap
)
166 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
170 ASSERT(ctx
->RenderMode
== GL_RENDER
);
173 RENDER_START(swrast
,ctx
);
175 if (SWRAST_CONTEXT(ctx
)->NewState
)
176 _swrast_validate_derived( ctx
);
178 INIT_SPAN(span
, GL_BITMAP
, width
, 0, SPAN_MASK
);
180 /*span.arrayMask |= SPAN_MASK;*/ /* we'll init span.mask[] */
183 /*span.end = width;*/
184 if (ctx
->Visual
.rgbMode
) {
185 span
.interpMask
|= SPAN_RGBA
;
186 span
.red
= FloatToFixed(ctx
->Current
.RasterColor
[0] * CHAN_MAXF
);
187 span
.green
= FloatToFixed(ctx
->Current
.RasterColor
[1] * CHAN_MAXF
);
188 span
.blue
= FloatToFixed(ctx
->Current
.RasterColor
[2] * CHAN_MAXF
);
189 span
.alpha
= FloatToFixed(ctx
->Current
.RasterColor
[3] * CHAN_MAXF
);
190 span
.redStep
= span
.greenStep
= span
.blueStep
= span
.alphaStep
= 0;
193 span
.interpMask
|= SPAN_INDEX
;
194 span
.index
= ChanToFixed(ctx
->Current
.RasterIndex
);
199 _mesa_span_default_z(ctx
, &span
);
200 if (ctx
->Fog
.Enabled
)
201 _mesa_span_default_fog(ctx
, &span
);
202 if (ctx
->Texture
._EnabledUnits
)
203 _mesa_span_default_texcoords(ctx
, &span
);
205 for (row
=0; row
<height
; row
++, span
.y
++) {
206 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address( unpack
,
207 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
209 if (unpack
->LsbFirst
) {
211 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
212 for (col
=0; col
<width
; col
++) {
213 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
223 if (ctx
->Visual
.rgbMode
)
224 _mesa_write_rgba_span(ctx
, &span
);
226 _mesa_write_index_span(ctx
, &span
);
228 /* get ready for next row */
234 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
235 for (col
=0; col
<width
; col
++) {
236 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
246 if (ctx
->Visual
.rgbMode
)
247 _mesa_write_rgba_span(ctx
, &span
);
249 _mesa_write_index_span(ctx
, &span
);
251 /* get ready for next row */
257 RENDER_FINISH(swrast
,ctx
);