2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * \file swrast/s_bitmap.c
27 * \brief glBitmap rendering.
36 #include "s_context.h"
45 _swrast_Bitmap( GLcontext
*ctx
, GLint px
, GLint py
,
46 GLsizei width
, GLsizei height
,
47 const struct gl_pixelstore_attrib
*unpack
,
48 const GLubyte
*bitmap
)
50 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
55 ASSERT(ctx
->RenderMode
== GL_RENDER
);
57 bitmap
= (const GLubyte
*) _swrast_validate_pbo_access(unpack
, width
,
59 GL_COLOR_INDEX
, GL_BITMAP
,
62 /* XXX GL_INVALID_OPERATION? */
66 RENDER_START(swrast
,ctx
);
68 if (SWRAST_CONTEXT(ctx
)->NewState
)
69 _swrast_validate_derived( ctx
);
71 INIT_SPAN(span
, GL_BITMAP
, width
, 0, SPAN_XY
);
73 if (ctx
->Visual
.rgbMode
) {
74 span
.interpMask
|= SPAN_RGBA
;
75 span
.red
= FloatToFixed(ctx
->Current
.RasterColor
[0] * CHAN_MAXF
);
76 span
.green
= FloatToFixed(ctx
->Current
.RasterColor
[1] * CHAN_MAXF
);
77 span
.blue
= FloatToFixed(ctx
->Current
.RasterColor
[2] * CHAN_MAXF
);
78 span
.alpha
= FloatToFixed(ctx
->Current
.RasterColor
[3] * CHAN_MAXF
);
79 span
.redStep
= span
.greenStep
= span
.blueStep
= span
.alphaStep
= 0;
82 span
.interpMask
|= SPAN_INDEX
;
83 span
.index
= FloatToFixed(ctx
->Current
.RasterIndex
);
88 _swrast_span_default_z(ctx
, &span
);
90 _swrast_span_default_fog(ctx
, &span
);
91 if (ctx
->Texture
._EnabledCoordUnits
)
92 _swrast_span_default_texcoords(ctx
, &span
);
94 for (row
= 0; row
< height
; row
++, span
.y
++) {
95 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address( unpack
,
96 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
98 if (unpack
->LsbFirst
) {
100 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
101 for (col
= 0; col
< width
; col
++) {
103 span
.array
->x
[count
] = px
+ col
;
104 span
.array
->y
[count
] = py
+ row
;
116 /* get ready for next row */
122 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
123 for (col
= 0; col
< width
; col
++) {
125 span
.array
->x
[count
] = px
+ col
;
126 span
.array
->y
[count
] = py
+ row
;
138 /* get ready for next row */
143 if (count
+ width
>= MAX_WIDTH
|| row
+ 1 == height
) {
146 if (ctx
->Visual
.rgbMode
)
147 _swrast_write_rgba_span(ctx
, &span
);
149 _swrast_write_index_span(ctx
, &span
);
155 RENDER_FINISH(swrast
,ctx
);
161 * XXX this is another way to implement Bitmap. Use horizontal runs of
162 * fragments, initializing the mask array to indicate which fragmens to
166 _swrast_Bitmap( GLcontext
*ctx
, GLint px
, GLint py
,
167 GLsizei width
, GLsizei height
,
168 const struct gl_pixelstore_attrib
*unpack
,
169 const GLubyte
*bitmap
)
171 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
175 ASSERT(ctx
->RenderMode
== GL_RENDER
);
178 RENDER_START(swrast
,ctx
);
180 if (SWRAST_CONTEXT(ctx
)->NewState
)
181 _swrast_validate_derived( ctx
);
183 INIT_SPAN(span
, GL_BITMAP
, width
, 0, SPAN_MASK
);
185 /*span.arrayMask |= SPAN_MASK;*/ /* we'll init span.mask[] */
188 /*span.end = width;*/
189 if (ctx
->Visual
.rgbMode
) {
190 span
.interpMask
|= SPAN_RGBA
;
191 span
.red
= FloatToFixed(ctx
->Current
.RasterColor
[0] * CHAN_MAXF
);
192 span
.green
= FloatToFixed(ctx
->Current
.RasterColor
[1] * CHAN_MAXF
);
193 span
.blue
= FloatToFixed(ctx
->Current
.RasterColor
[2] * CHAN_MAXF
);
194 span
.alpha
= FloatToFixed(ctx
->Current
.RasterColor
[3] * CHAN_MAXF
);
195 span
.redStep
= span
.greenStep
= span
.blueStep
= span
.alphaStep
= 0;
198 span
.interpMask
|= SPAN_INDEX
;
199 span
.index
= FloatToFixed(ctx
->Current
.RasterIndex
);
204 _swrast_span_default_z(ctx
, &span
);
205 if (ctx
->Fog
.Enabled
)
206 _swrast_span_default_fog(ctx
, &span
);
207 if (ctx
->Texture
._EnabledCoordUnits
)
208 _swrast_span_default_texcoords(ctx
, &span
);
210 for (row
=0; row
<height
; row
++, span
.y
++) {
211 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address( unpack
,
212 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
214 if (unpack
->LsbFirst
) {
216 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
217 for (col
=0; col
<width
; col
++) {
218 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
228 if (ctx
->Visual
.rgbMode
)
229 _swrast_write_rgba_span(ctx
, &span
);
231 _swrast_write_index_span(ctx
, &span
);
233 /* get ready for next row */
239 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
240 for (col
=0; col
<width
; col
++) {
241 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
251 if (ctx
->Visual
.rgbMode
)
252 _swrast_write_rgba_span(ctx
, &span
);
254 _swrast_write_index_span(ctx
, &span
);
256 /* get ready for next row */
262 RENDER_FINISH(swrast
,ctx
);