ea148797b5d85c694aa6494f43f3eb76e792aa66
1 /* $Id: s_bitmap.c,v 1.15 2002/02/15 03:41:00 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"
49 _swrast_Bitmap( GLcontext
*ctx
, GLint px
, GLint py
,
50 GLsizei width
, GLsizei height
,
51 const struct gl_pixelstore_attrib
*unpack
,
52 const GLubyte
*bitmap
)
54 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
59 ASSERT(ctx
->RenderMode
== GL_RENDER
);
62 RENDER_START(swrast
,ctx
);
64 if (SWRAST_CONTEXT(ctx
)->NewState
)
65 _swrast_validate_derived( ctx
);
68 span
.arrayMask
|= SPAN_XY
;
70 if (ctx
->Visual
.rgbMode
) {
71 span
.interpMask
|= SPAN_RGBA
;
72 span
.red
= FloatToFixed(ctx
->Current
.RasterColor
[0] * CHAN_MAXF
);
73 span
.green
= FloatToFixed(ctx
->Current
.RasterColor
[1] * CHAN_MAXF
);
74 span
.blue
= FloatToFixed(ctx
->Current
.RasterColor
[2] * CHAN_MAXF
);
75 span
.alpha
= FloatToFixed(ctx
->Current
.RasterColor
[3] * CHAN_MAXF
);
76 span
.redStep
= span
.greenStep
= span
.blueStep
= span
.alphaStep
= 0;
79 span
.interpMask
|= SPAN_INDEX
;
80 span
.index
= ChanToFixed(ctx
->Current
.RasterIndex
);
85 _mesa_span_default_z(ctx
, &span
);
87 _mesa_span_default_fog(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
.xArray
[count
] = px
+ col
;
99 span
.yArray
[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
.xArray
[count
] = px
+ col
;
121 span
.yArray
[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
, GL_BITMAP
);
144 _mesa_write_index_span(ctx
, &span
, GL_BITMAP
);
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
162 _swrast_Bitmap( GLcontext
*ctx
, GLint px
, GLint py
,
163 GLsizei width
, GLsizei height
,
164 const struct gl_pixelstore_attrib
*unpack
,
165 const GLubyte
*bitmap
)
167 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
171 ASSERT(ctx
->RenderMode
== GL_RENDER
);
174 RENDER_START(swrast
,ctx
);
176 if (SWRAST_CONTEXT(ctx
)->NewState
)
177 _swrast_validate_derived( ctx
);
180 span
.arrayMask
|= SPAN_MASK
; /* we'll init span.mask[] */
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
);
203 for (row
=0; row
<height
; row
++, span
.y
++) {
204 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address( unpack
,
205 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
207 if (unpack
->LsbFirst
) {
209 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
210 for (col
=0; col
<width
; col
++) {
211 span
.mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
221 if (ctx
->Visual
.rgbMode
)
222 _mesa_write_rgba_span(ctx
, &span
, GL_BITMAP
);
224 _mesa_write_index_span(ctx
, &span
, GL_BITMAP
);
226 /* get ready for next row */
232 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
233 for (col
=0; col
<width
; col
++) {
234 span
.mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
244 if (ctx
->Visual
.rgbMode
)
245 _mesa_write_rgba_span(ctx
, &span
, GL_BITMAP
);
247 _mesa_write_index_span(ctx
, &span
, GL_BITMAP
);
249 /* get ready for next row */
255 RENDER_FINISH(swrast
,ctx
);