0e20a20d7fbfd129178687b9043cebaae894bbae
2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 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
);
58 RENDER_START(swrast
,ctx
);
60 if (SWRAST_CONTEXT(ctx
)->NewState
)
61 _swrast_validate_derived( ctx
);
63 INIT_SPAN(span
, GL_BITMAP
, width
, 0, SPAN_XY
);
65 if (ctx
->Visual
.rgbMode
) {
66 span
.interpMask
|= SPAN_RGBA
;
67 span
.red
= FloatToFixed(ctx
->Current
.RasterColor
[0] * CHAN_MAXF
);
68 span
.green
= FloatToFixed(ctx
->Current
.RasterColor
[1] * CHAN_MAXF
);
69 span
.blue
= FloatToFixed(ctx
->Current
.RasterColor
[2] * CHAN_MAXF
);
70 span
.alpha
= FloatToFixed(ctx
->Current
.RasterColor
[3] * CHAN_MAXF
);
71 span
.redStep
= span
.greenStep
= span
.blueStep
= span
.alphaStep
= 0;
74 span
.interpMask
|= SPAN_INDEX
;
75 span
.index
= ChanToFixed(ctx
->Current
.RasterIndex
);
80 _swrast_span_default_z(ctx
, &span
);
82 _swrast_span_default_fog(ctx
, &span
);
83 if (ctx
->Texture
._EnabledCoordUnits
)
84 _swrast_span_default_texcoords(ctx
, &span
);
86 for (row
= 0; row
< height
; row
++, span
.y
++) {
87 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address( unpack
,
88 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
90 if (unpack
->LsbFirst
) {
92 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
93 for (col
= 0; col
< width
; col
++) {
95 span
.array
->x
[count
] = px
+ col
;
96 span
.array
->y
[count
] = py
+ row
;
108 /* get ready for next row */
114 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
115 for (col
= 0; col
< width
; col
++) {
117 span
.array
->x
[count
] = px
+ col
;
118 span
.array
->y
[count
] = py
+ row
;
130 /* get ready for next row */
135 if (count
+ width
>= MAX_WIDTH
|| row
+ 1 == height
) {
138 if (ctx
->Visual
.rgbMode
)
139 _swrast_write_rgba_span(ctx
, &span
);
141 _swrast_write_index_span(ctx
, &span
);
147 RENDER_FINISH(swrast
,ctx
);
153 * XXX this is another way to implement Bitmap. Use horizontal runs of
154 * fragments, initializing the mask array to indicate which fragmens to
158 _swrast_Bitmap( GLcontext
*ctx
, GLint px
, GLint py
,
159 GLsizei width
, GLsizei height
,
160 const struct gl_pixelstore_attrib
*unpack
,
161 const GLubyte
*bitmap
)
163 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
167 ASSERT(ctx
->RenderMode
== GL_RENDER
);
170 RENDER_START(swrast
,ctx
);
172 if (SWRAST_CONTEXT(ctx
)->NewState
)
173 _swrast_validate_derived( ctx
);
175 INIT_SPAN(span
, GL_BITMAP
, width
, 0, SPAN_MASK
);
177 /*span.arrayMask |= SPAN_MASK;*/ /* we'll init span.mask[] */
180 /*span.end = width;*/
181 if (ctx
->Visual
.rgbMode
) {
182 span
.interpMask
|= SPAN_RGBA
;
183 span
.red
= FloatToFixed(ctx
->Current
.RasterColor
[0] * CHAN_MAXF
);
184 span
.green
= FloatToFixed(ctx
->Current
.RasterColor
[1] * CHAN_MAXF
);
185 span
.blue
= FloatToFixed(ctx
->Current
.RasterColor
[2] * CHAN_MAXF
);
186 span
.alpha
= FloatToFixed(ctx
->Current
.RasterColor
[3] * CHAN_MAXF
);
187 span
.redStep
= span
.greenStep
= span
.blueStep
= span
.alphaStep
= 0;
190 span
.interpMask
|= SPAN_INDEX
;
191 span
.index
= ChanToFixed(ctx
->Current
.RasterIndex
);
196 _swrast_span_default_z(ctx
, &span
);
197 if (ctx
->Fog
.Enabled
)
198 _swrast_span_default_fog(ctx
, &span
);
199 if (ctx
->Texture
._EnabledCoordUnits
)
200 _swrast_span_default_texcoords(ctx
, &span
);
202 for (row
=0; row
<height
; row
++, span
.y
++) {
203 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address( unpack
,
204 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
206 if (unpack
->LsbFirst
) {
208 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
209 for (col
=0; col
<width
; col
++) {
210 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
220 if (ctx
->Visual
.rgbMode
)
221 _swrast_write_rgba_span(ctx
, &span
);
223 _swrast_write_index_span(ctx
, &span
);
225 /* get ready for next row */
231 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
232 for (col
=0; col
<width
; col
++) {
233 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
243 if (ctx
->Visual
.rgbMode
)
244 _swrast_write_rgba_span(ctx
, &span
);
246 _swrast_write_index_span(ctx
, &span
);
248 /* get ready for next row */
254 RENDER_FINISH(swrast
,ctx
);