swrast: Remove unnecessary header from s_bitmap.c.
[mesa.git] / src / mesa / swrast / s_bitmap.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.1
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25 /**
26 * \file swrast/s_bitmap.c
27 * \brief glBitmap rendering.
28 * \author Brian Paul
29 */
30
31 #include "main/glheader.h"
32 #include "main/bufferobj.h"
33 #include "main/image.h"
34 #include "main/macros.h"
35
36 #include "s_context.h"
37 #include "s_span.h"
38
39
40
41 /**
42 * Render a bitmap.
43 * Called via ctx->Driver.Bitmap()
44 * All parameter error checking will have been done before this is called.
45 */
46 void
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 )
51 {
52 GLint row, col;
53 GLuint count = 0;
54 SWspan span;
55
56 ASSERT(ctx->RenderMode == GL_RENDER);
57
58 bitmap = (const GLubyte *) _mesa_map_pbo_source(ctx, unpack, bitmap);
59 if (!bitmap)
60 return;
61
62 swrast_render_start(ctx);
63
64 if (SWRAST_CONTEXT(ctx)->NewState)
65 _swrast_validate_derived( ctx );
66
67 INIT_SPAN(span, GL_BITMAP);
68 span.end = width;
69 span.arrayMask = SPAN_XY;
70 _swrast_span_default_attribs(ctx, &span);
71
72 for (row = 0; row < height; row++) {
73 const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack,
74 bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0);
75
76 if (unpack->LsbFirst) {
77 /* Lsb first */
78 GLubyte mask = 1U << (unpack->SkipPixels & 0x7);
79 for (col = 0; col < width; col++) {
80 if (*src & mask) {
81 span.array->x[count] = px + col;
82 span.array->y[count] = py + row;
83 count++;
84 }
85 if (mask == 128U) {
86 src++;
87 mask = 1U;
88 }
89 else {
90 mask = mask << 1;
91 }
92 }
93
94 /* get ready for next row */
95 if (mask != 1)
96 src++;
97 }
98 else {
99 /* Msb first */
100 GLubyte mask = 128U >> (unpack->SkipPixels & 0x7);
101 for (col = 0; col < width; col++) {
102 if (*src & mask) {
103 span.array->x[count] = px + col;
104 span.array->y[count] = py + row;
105 count++;
106 }
107 if (mask == 1U) {
108 src++;
109 mask = 128U;
110 }
111 else {
112 mask = mask >> 1;
113 }
114 }
115
116 /* get ready for next row */
117 if (mask != 128)
118 src++;
119 }
120
121 if (count + width >= MAX_WIDTH || row + 1 == height) {
122 /* flush the span */
123 span.end = count;
124 if (ctx->Visual.rgbMode)
125 _swrast_write_rgba_span(ctx, &span);
126 else
127 _swrast_write_index_span(ctx, &span);
128 span.end = 0;
129 count = 0;
130 }
131 }
132
133 swrast_render_finish(ctx);
134
135 _mesa_unmap_pbo_source(ctx, unpack);
136 }
137
138
139 #if 0
140 /*
141 * XXX this is another way to implement Bitmap. Use horizontal runs of
142 * fragments, initializing the mask array to indicate which fragments to
143 * draw or skip.
144 */
145 void
146 _swrast_Bitmap( GLcontext *ctx, GLint px, GLint py,
147 GLsizei width, GLsizei height,
148 const struct gl_pixelstore_attrib *unpack,
149 const GLubyte *bitmap )
150 {
151 SWcontext *swrast = SWRAST_CONTEXT(ctx);
152 GLint row, col;
153 SWspan span;
154
155 ASSERT(ctx->RenderMode == GL_RENDER);
156 ASSERT(bitmap);
157
158 swrast_render_start(ctx);
159
160 if (SWRAST_CONTEXT(ctx)->NewState)
161 _swrast_validate_derived( ctx );
162
163 INIT_SPAN(span, GL_BITMAP);
164 span.end = width;
165 span.arrayMask = SPAN_MASK;
166 _swrast_span_default_attribs(ctx, &span);
167
168 /*span.arrayMask |= SPAN_MASK;*/ /* we'll init span.mask[] */
169 span.x = px;
170 span.y = py;
171 /*span.end = width;*/
172
173 for (row=0; row<height; row++, span.y++) {
174 const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack,
175 bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0);
176
177 if (unpack->LsbFirst) {
178 /* Lsb first */
179 GLubyte mask = 1U << (unpack->SkipPixels & 0x7);
180 for (col=0; col<width; col++) {
181 span.array->mask[col] = (*src & mask) ? GL_TRUE : GL_FALSE;
182 if (mask == 128U) {
183 src++;
184 mask = 1U;
185 }
186 else {
187 mask = mask << 1;
188 }
189 }
190
191 if (ctx->Visual.rgbMode)
192 _swrast_write_rgba_span(ctx, &span);
193 else
194 _swrast_write_index_span(ctx, &span);
195
196 /* get ready for next row */
197 if (mask != 1)
198 src++;
199 }
200 else {
201 /* Msb first */
202 GLubyte mask = 128U >> (unpack->SkipPixels & 0x7);
203 for (col=0; col<width; col++) {
204 span.array->mask[col] = (*src & mask) ? GL_TRUE : GL_FALSE;
205 if (mask == 1U) {
206 src++;
207 mask = 128U;
208 }
209 else {
210 mask = mask >> 1;
211 }
212 }
213
214 if (ctx->Visual.rgbMode)
215 _swrast_write_rgba_span(ctx, &span);
216 else
217 _swrast_write_index_span(ctx, &span);
218
219 /* get ready for next row */
220 if (mask != 128)
221 src++;
222 }
223 }
224
225 swrast_render_finish(ctx);
226 }
227 #endif