1 /* $Id: s_bitmap.c,v 1.22 2003/03/25 02:23:45 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.
38 #include "s_context.h"
47 _swrast_Bitmap( GLcontext
*ctx
, GLint px
, GLint py
,
48 GLsizei width
, GLsizei height
,
49 const struct gl_pixelstore_attrib
*unpack
,
50 const GLubyte
*bitmap
)
52 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
57 ASSERT(ctx
->RenderMode
== GL_RENDER
);
60 RENDER_START(swrast
,ctx
);
62 if (SWRAST_CONTEXT(ctx
)->NewState
)
63 _swrast_validate_derived( ctx
);
65 INIT_SPAN(span
, GL_BITMAP
, width
, 0, SPAN_XY
);
67 if (ctx
->Visual
.rgbMode
) {
68 span
.interpMask
|= SPAN_RGBA
;
69 span
.red
= FloatToFixed(ctx
->Current
.RasterColor
[0] * CHAN_MAXF
);
70 span
.green
= FloatToFixed(ctx
->Current
.RasterColor
[1] * CHAN_MAXF
);
71 span
.blue
= FloatToFixed(ctx
->Current
.RasterColor
[2] * CHAN_MAXF
);
72 span
.alpha
= FloatToFixed(ctx
->Current
.RasterColor
[3] * CHAN_MAXF
);
73 span
.redStep
= span
.greenStep
= span
.blueStep
= span
.alphaStep
= 0;
76 span
.interpMask
|= SPAN_INDEX
;
77 span
.index
= ChanToFixed(ctx
->Current
.RasterIndex
);
82 _swrast_span_default_z(ctx
, &span
);
84 _swrast_span_default_fog(ctx
, &span
);
85 if (ctx
->Texture
._EnabledUnits
)
86 _swrast_span_default_texcoords(ctx
, &span
);
88 for (row
= 0; row
< height
; row
++, span
.y
++) {
89 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address( unpack
,
90 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
92 if (unpack
->LsbFirst
) {
94 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
95 for (col
= 0; col
< width
; col
++) {
97 span
.array
->x
[count
] = px
+ col
;
98 span
.array
->y
[count
] = py
+ row
;
110 /* get ready for next row */
116 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
117 for (col
= 0; col
< width
; col
++) {
119 span
.array
->x
[count
] = px
+ col
;
120 span
.array
->y
[count
] = py
+ row
;
132 /* get ready for next row */
137 if (count
+ width
>= MAX_WIDTH
|| row
+ 1 == height
) {
140 if (ctx
->Visual
.rgbMode
)
141 _swrast_write_rgba_span(ctx
, &span
);
143 _swrast_write_index_span(ctx
, &span
);
149 RENDER_FINISH(swrast
,ctx
);
155 * XXX this is another way to implement Bitmap. Use horizontal runs of
156 * fragments, initializing the mask array to indicate which fragmens to
160 _swrast_Bitmap( GLcontext
*ctx
, GLint px
, GLint py
,
161 GLsizei width
, GLsizei height
,
162 const struct gl_pixelstore_attrib
*unpack
,
163 const GLubyte
*bitmap
)
165 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
169 ASSERT(ctx
->RenderMode
== GL_RENDER
);
172 RENDER_START(swrast
,ctx
);
174 if (SWRAST_CONTEXT(ctx
)->NewState
)
175 _swrast_validate_derived( ctx
);
177 INIT_SPAN(span
, GL_BITMAP
, width
, 0, SPAN_MASK
);
179 /*span.arrayMask |= SPAN_MASK;*/ /* we'll init span.mask[] */
182 /*span.end = width;*/
183 if (ctx
->Visual
.rgbMode
) {
184 span
.interpMask
|= SPAN_RGBA
;
185 span
.red
= FloatToFixed(ctx
->Current
.RasterColor
[0] * CHAN_MAXF
);
186 span
.green
= FloatToFixed(ctx
->Current
.RasterColor
[1] * CHAN_MAXF
);
187 span
.blue
= FloatToFixed(ctx
->Current
.RasterColor
[2] * CHAN_MAXF
);
188 span
.alpha
= FloatToFixed(ctx
->Current
.RasterColor
[3] * CHAN_MAXF
);
189 span
.redStep
= span
.greenStep
= span
.blueStep
= span
.alphaStep
= 0;
192 span
.interpMask
|= SPAN_INDEX
;
193 span
.index
= ChanToFixed(ctx
->Current
.RasterIndex
);
198 _swrast_span_default_z(ctx
, &span
);
199 if (ctx
->Fog
.Enabled
)
200 _swrast_span_default_fog(ctx
, &span
);
201 if (ctx
->Texture
._EnabledUnits
)
202 _swrast_span_default_texcoords(ctx
, &span
);
204 for (row
=0; row
<height
; row
++, span
.y
++) {
205 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address( unpack
,
206 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
208 if (unpack
->LsbFirst
) {
210 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
211 for (col
=0; col
<width
; col
++) {
212 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
222 if (ctx
->Visual
.rgbMode
)
223 _swrast_write_rgba_span(ctx
, &span
);
225 _swrast_write_index_span(ctx
, &span
);
227 /* get ready for next row */
233 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
234 for (col
=0; col
<width
; col
++) {
235 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
245 if (ctx
->Visual
.rgbMode
)
246 _swrast_write_rgba_span(ctx
, &span
);
248 _swrast_write_index_span(ctx
, &span
);
250 /* get ready for next row */
256 RENDER_FINISH(swrast
,ctx
);