OSDN Git Service

mesa/swrast: Respect mfeatures.h.
[android-x86/external-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 #include "main/pixel.h"
36
37 #include "s_context.h"
38 #include "s_span.h"
39
40
41 #if FEATURE_drawpix
42
43
44 /**
45  * Render a bitmap.
46  * Called via ctx->Driver.Bitmap()
47  * All parameter error checking will have been done before this is called.
48  */
49 void
50 _swrast_Bitmap( GLcontext *ctx, GLint px, GLint py,
51                 GLsizei width, GLsizei height,
52                 const struct gl_pixelstore_attrib *unpack,
53                 const GLubyte *bitmap )
54 {
55    GLint row, col;
56    GLuint count = 0;
57    SWspan span;
58
59    ASSERT(ctx->RenderMode == GL_RENDER);
60
61    bitmap = (const GLubyte *) _mesa_map_pbo_source(ctx, unpack, bitmap);
62    if (!bitmap)
63       return;
64
65    swrast_render_start(ctx);
66
67    if (SWRAST_CONTEXT(ctx)->NewState)
68       _swrast_validate_derived( ctx );
69
70    INIT_SPAN(span, GL_BITMAP);
71    span.end = width;
72    span.arrayMask = SPAN_XY;
73    _swrast_span_default_attribs(ctx, &span);
74
75    for (row = 0; row < height; row++) {
76       const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack,
77                  bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0);
78
79       if (unpack->LsbFirst) {
80          /* Lsb first */
81          GLubyte mask = 1U << (unpack->SkipPixels & 0x7);
82          for (col = 0; col < width; col++) {
83             if (*src & mask) {
84                span.array->x[count] = px + col;
85                span.array->y[count] = py + row;
86                count++;
87             }
88             if (mask == 128U) {
89                src++;
90                mask = 1U;
91             }
92             else {
93                mask = mask << 1;
94             }
95          }
96
97          /* get ready for next row */
98          if (mask != 1)
99             src++;
100       }
101       else {
102          /* Msb first */
103          GLubyte mask = 128U >> (unpack->SkipPixels & 0x7);
104          for (col = 0; col < width; col++) {
105             if (*src & mask) {
106                span.array->x[count] = px + col;
107                span.array->y[count] = py + row;
108                count++;
109             }
110             if (mask == 1U) {
111                src++;
112                mask = 128U;
113             }
114             else {
115                mask = mask >> 1;
116             }
117          }
118
119          /* get ready for next row */
120          if (mask != 128)
121             src++;
122       }
123
124       if (count + width >= MAX_WIDTH || row + 1 == height) {
125          /* flush the span */
126          span.end = count;
127          if (ctx->Visual.rgbMode)
128             _swrast_write_rgba_span(ctx, &span);
129          else
130             _swrast_write_index_span(ctx, &span);
131          span.end = 0;
132          count = 0;
133       }
134    }
135
136    swrast_render_finish(ctx);
137
138    _mesa_unmap_pbo_source(ctx, unpack);
139 }
140
141
142 #if 0
143 /*
144  * XXX this is another way to implement Bitmap.  Use horizontal runs of
145  * fragments, initializing the mask array to indicate which fragments to
146  * draw or skip.
147  */
148 void
149 _swrast_Bitmap( GLcontext *ctx, GLint px, GLint py,
150                 GLsizei width, GLsizei height,
151                 const struct gl_pixelstore_attrib *unpack,
152                 const GLubyte *bitmap )
153 {
154    SWcontext *swrast = SWRAST_CONTEXT(ctx);
155    GLint row, col;
156    SWspan span;
157
158    ASSERT(ctx->RenderMode == GL_RENDER);
159    ASSERT(bitmap);
160
161    swrast_render_start(ctx);
162
163    if (SWRAST_CONTEXT(ctx)->NewState)
164       _swrast_validate_derived( ctx );
165
166    INIT_SPAN(span, GL_BITMAP);
167    span.end = width;
168    span.arrayMask = SPAN_MASK;
169    _swrast_span_default_attribs(ctx, &span);
170
171    /*span.arrayMask |= SPAN_MASK;*/  /* we'll init span.mask[] */
172    span.x = px;
173    span.y = py;
174    /*span.end = width;*/
175
176    for (row=0; row<height; row++, span.y++) {
177       const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack,
178                  bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0);
179
180       if (unpack->LsbFirst) {
181          /* Lsb first */
182          GLubyte mask = 1U << (unpack->SkipPixels & 0x7);
183          for (col=0; col<width; col++) {
184             span.array->mask[col] = (*src & mask) ? GL_TRUE : GL_FALSE;
185             if (mask == 128U) {
186                src++;
187                mask = 1U;
188             }
189             else {
190                mask = mask << 1;
191             }
192          }
193
194          if (ctx->Visual.rgbMode)
195             _swrast_write_rgba_span(ctx, &span);
196          else
197             _swrast_write_index_span(ctx, &span);
198
199          /* get ready for next row */
200          if (mask != 1)
201             src++;
202       }
203       else {
204          /* Msb first */
205          GLubyte mask = 128U >> (unpack->SkipPixels & 0x7);
206          for (col=0; col<width; col++) {
207             span.array->mask[col] = (*src & mask) ? GL_TRUE : GL_FALSE;
208             if (mask == 1U) {
209                src++;
210                mask = 128U;
211             }
212             else {
213                mask = mask >> 1;
214             }
215          }
216
217          if (ctx->Visual.rgbMode)
218             _swrast_write_rgba_span(ctx, &span);
219          else
220             _swrast_write_index_span(ctx, &span);
221
222          /* get ready for next row */
223          if (mask != 128)
224             src++;
225       }
226    }
227
228    swrast_render_finish(ctx);
229 }
230 #endif
231
232
233 #endif /* FEATURE_drawpix */