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
= _swrast_validate_pbo_access(unpack
, width
, height
, 1,
58 GL_COLOR_INDEX
, GL_BITMAP
,
61 /* XXX GL_INVALID_OPERATION? */
65 RENDER_START(swrast
,ctx
);
67 if (SWRAST_CONTEXT(ctx
)->NewState
)
68 _swrast_validate_derived( ctx
);
70 INIT_SPAN(span
, GL_BITMAP
, width
, 0, SPAN_XY
);
72 if (ctx
->Visual
.rgbMode
) {
73 span
.interpMask
|= SPAN_RGBA
;
74 span
.red
= FloatToFixed(ctx
->Current
.RasterColor
[0] * CHAN_MAXF
);
75 span
.green
= FloatToFixed(ctx
->Current
.RasterColor
[1] * CHAN_MAXF
);
76 span
.blue
= FloatToFixed(ctx
->Current
.RasterColor
[2] * CHAN_MAXF
);
77 span
.alpha
= FloatToFixed(ctx
->Current
.RasterColor
[3] * CHAN_MAXF
);
78 span
.redStep
= span
.greenStep
= span
.blueStep
= span
.alphaStep
= 0;
81 span
.interpMask
|= SPAN_INDEX
;
82 span
.index
= FloatToFixed(ctx
->Current
.RasterIndex
);
87 _swrast_span_default_z(ctx
, &span
);
89 _swrast_span_default_fog(ctx
, &span
);
90 if (ctx
->Texture
._EnabledCoordUnits
)
91 _swrast_span_default_texcoords(ctx
, &span
);
93 for (row
= 0; row
< height
; row
++, span
.y
++) {
94 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address( unpack
,
95 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
97 if (unpack
->LsbFirst
) {
99 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
100 for (col
= 0; col
< width
; col
++) {
102 span
.array
->x
[count
] = px
+ col
;
103 span
.array
->y
[count
] = py
+ row
;
115 /* get ready for next row */
121 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
122 for (col
= 0; col
< width
; col
++) {
124 span
.array
->x
[count
] = px
+ col
;
125 span
.array
->y
[count
] = py
+ row
;
137 /* get ready for next row */
142 if (count
+ width
>= MAX_WIDTH
|| row
+ 1 == height
) {
145 if (ctx
->Visual
.rgbMode
)
146 _swrast_write_rgba_span(ctx
, &span
);
148 _swrast_write_index_span(ctx
, &span
);
154 RENDER_FINISH(swrast
,ctx
);
160 * XXX this is another way to implement Bitmap. Use horizontal runs of
161 * fragments, initializing the mask array to indicate which fragmens to
165 _swrast_Bitmap( GLcontext
*ctx
, GLint px
, GLint py
,
166 GLsizei width
, GLsizei height
,
167 const struct gl_pixelstore_attrib
*unpack
,
168 const GLubyte
*bitmap
)
170 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
174 ASSERT(ctx
->RenderMode
== GL_RENDER
);
177 RENDER_START(swrast
,ctx
);
179 if (SWRAST_CONTEXT(ctx
)->NewState
)
180 _swrast_validate_derived( ctx
);
182 INIT_SPAN(span
, GL_BITMAP
, width
, 0, SPAN_MASK
);
184 /*span.arrayMask |= SPAN_MASK;*/ /* we'll init span.mask[] */
187 /*span.end = width;*/
188 if (ctx
->Visual
.rgbMode
) {
189 span
.interpMask
|= SPAN_RGBA
;
190 span
.red
= FloatToFixed(ctx
->Current
.RasterColor
[0] * CHAN_MAXF
);
191 span
.green
= FloatToFixed(ctx
->Current
.RasterColor
[1] * CHAN_MAXF
);
192 span
.blue
= FloatToFixed(ctx
->Current
.RasterColor
[2] * CHAN_MAXF
);
193 span
.alpha
= FloatToFixed(ctx
->Current
.RasterColor
[3] * CHAN_MAXF
);
194 span
.redStep
= span
.greenStep
= span
.blueStep
= span
.alphaStep
= 0;
197 span
.interpMask
|= SPAN_INDEX
;
198 span
.index
= FloatToFixed(ctx
->Current
.RasterIndex
);
203 _swrast_span_default_z(ctx
, &span
);
204 if (ctx
->Fog
.Enabled
)
205 _swrast_span_default_fog(ctx
, &span
);
206 if (ctx
->Texture
._EnabledCoordUnits
)
207 _swrast_span_default_texcoords(ctx
, &span
);
209 for (row
=0; row
<height
; row
++, span
.y
++) {
210 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address( unpack
,
211 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
213 if (unpack
->LsbFirst
) {
215 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
216 for (col
=0; col
<width
; col
++) {
217 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
227 if (ctx
->Visual
.rgbMode
)
228 _swrast_write_rgba_span(ctx
, &span
);
230 _swrast_write_index_span(ctx
, &span
);
232 /* get ready for next row */
238 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
239 for (col
=0; col
<width
; col
++) {
240 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
250 if (ctx
->Visual
.rgbMode
)
251 _swrast_write_rgba_span(ctx
, &span
);
253 _swrast_write_index_span(ctx
, &span
);
255 /* get ready for next row */
261 RENDER_FINISH(swrast
,ctx
);