2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 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.
31 #include "main/glheader.h"
32 #include "main/bufferobj.h"
33 #include "main/image.h"
34 #include "main/macros.h"
35 #include "main/pixel.h"
37 #include "s_context.h"
44 * Called via ctx->Driver.Bitmap()
45 * All parameter error checking will have been done before this is called.
48 _swrast_Bitmap( GLcontext
*ctx
, GLint px
, GLint py
,
49 GLsizei width
, GLsizei height
,
50 const struct gl_pixelstore_attrib
*unpack
,
51 const GLubyte
*bitmap
)
57 ASSERT(ctx
->RenderMode
== GL_RENDER
);
59 bitmap
= _mesa_map_bitmap_pbo(ctx
, unpack
, bitmap
);
63 swrast_render_start(ctx
);
65 if (SWRAST_CONTEXT(ctx
)->NewState
)
66 _swrast_validate_derived( ctx
);
68 INIT_SPAN(span
, GL_BITMAP
);
70 span
.arrayMask
= SPAN_XY
;
71 _swrast_span_default_attribs(ctx
, &span
);
73 for (row
= 0; row
< height
; row
++) {
74 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address2d(unpack
,
75 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
77 if (unpack
->LsbFirst
) {
79 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
80 for (col
= 0; col
< width
; col
++) {
82 span
.array
->x
[count
] = px
+ col
;
83 span
.array
->y
[count
] = py
+ row
;
95 /* get ready for next row */
101 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
102 for (col
= 0; col
< width
; col
++) {
104 span
.array
->x
[count
] = px
+ col
;
105 span
.array
->y
[count
] = py
+ row
;
117 /* get ready for next row */
122 if (count
+ width
>= MAX_WIDTH
|| row
+ 1 == height
) {
125 if (ctx
->Visual
.rgbMode
)
126 _swrast_write_rgba_span(ctx
, &span
);
128 _swrast_write_index_span(ctx
, &span
);
134 swrast_render_finish(ctx
);
136 _mesa_unmap_bitmap_pbo(ctx
, unpack
);
142 * XXX this is another way to implement Bitmap. Use horizontal runs of
143 * fragments, initializing the mask array to indicate which fragments to
147 _swrast_Bitmap( GLcontext
*ctx
, GLint px
, GLint py
,
148 GLsizei width
, GLsizei height
,
149 const struct gl_pixelstore_attrib
*unpack
,
150 const GLubyte
*bitmap
)
152 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
156 ASSERT(ctx
->RenderMode
== GL_RENDER
);
159 swrast_render_start(ctx
);
161 if (SWRAST_CONTEXT(ctx
)->NewState
)
162 _swrast_validate_derived( ctx
);
164 INIT_SPAN(span
, GL_BITMAP
);
166 span
.arrayMask
= SPAN_MASK
;
167 _swrast_span_default_attribs(ctx
, &span
);
169 /*span.arrayMask |= SPAN_MASK;*/ /* we'll init span.mask[] */
172 /*span.end = width;*/
174 for (row
=0; row
<height
; row
++, span
.y
++) {
175 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address2d(unpack
,
176 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
178 if (unpack
->LsbFirst
) {
180 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
181 for (col
=0; col
<width
; col
++) {
182 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
192 if (ctx
->Visual
.rgbMode
)
193 _swrast_write_rgba_span(ctx
, &span
);
195 _swrast_write_index_span(ctx
, &span
);
197 /* get ready for next row */
203 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
204 for (col
=0; col
<width
; col
++) {
205 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
215 if (ctx
->Visual
.rgbMode
)
216 _swrast_write_rgba_span(ctx
, &span
);
218 _swrast_write_index_span(ctx
, &span
);
220 /* get ready for next row */
226 swrast_render_finish(ctx
);