Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
57 pj 1
/* $Id: s_bitmap.c,v 1.1 2003-02-28 11:49:41 pj Exp $ */
2
 
3
/*
4
 * Mesa 3-D graphics library
5
 * Version:  4.1
6
 *
7
 * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
8
 *
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:
15
 *
16
 * The above copyright notice and this permission notice shall be included
17
 * in all copies or substantial portions of the Software.
18
 *
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.
25
 */
26
 
27
/**
28
 * \file swrast/s_bitmap.c
29
 * \brief glBitmap rendering.
30
 * \author Brian Paul
31
 */
32
 
33
#include "glheader.h"
34
#include "image.h"
35
#include "macros.h"
36
#include "mmath.h"
37
#include "pixel.h"
38
 
39
#include "s_context.h"
40
#include "s_span.h"
41
 
42
 
43
 
44
/*
45
 * Render a bitmap.
46
 */
47
void
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 )
52
{
53
   SWcontext *swrast = SWRAST_CONTEXT(ctx);
54
   GLint row, col;
55
   GLuint count = 0;
56
   struct sw_span span;
57
 
58
   ASSERT(ctx->RenderMode == GL_RENDER);
59
   ASSERT(bitmap);
60
 
61
   RENDER_START(swrast,ctx);
62
 
63
   if (SWRAST_CONTEXT(ctx)->NewState)
64
      _swrast_validate_derived( ctx );
65
 
66
   INIT_SPAN(span, GL_BITMAP, width, 0, SPAN_XY);
67
 
68
   if (ctx->Visual.rgbMode) {
69
      span.interpMask |= SPAN_RGBA;
70
      span.red   = FloatToFixed(ctx->Current.RasterColor[0] * CHAN_MAXF);
71
      span.green = FloatToFixed(ctx->Current.RasterColor[1] * CHAN_MAXF);
72
      span.blue  = FloatToFixed(ctx->Current.RasterColor[2] * CHAN_MAXF);
73
      span.alpha = FloatToFixed(ctx->Current.RasterColor[3] * CHAN_MAXF);
74
      span.redStep = span.greenStep = span.blueStep = span.alphaStep = 0;
75
   }
76
   else {
77
      span.interpMask |= SPAN_INDEX;
78
      span.index = ChanToFixed(ctx->Current.RasterIndex);
79
      span.indexStep = 0;
80
   }
81
 
82
   if (ctx->Depth.Test)
83
      _mesa_span_default_z(ctx, &span);
84
   if (ctx->Fog.Enabled)
85
      _mesa_span_default_fog(ctx, &span);
86
 
87
   for (row = 0; row < height; row++, span.y++) {
88
      const GLubyte *src = (const GLubyte *) _mesa_image_address( unpack,
89
                 bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, 0, row, 0 );
90
 
91
      if (unpack->LsbFirst) {
92
         /* Lsb first */
93
         GLubyte mask = 1U << (unpack->SkipPixels & 0x7);
94
         for (col = 0; col < width; col++) {
95
            if (*src & mask) {
96
               span.array->x[count] = px + col;
97
               span.array->y[count] = py + row;
98
               count++;
99
            }
100
            if (mask == 128U) {
101
               src++;
102
               mask = 1U;
103
            }
104
            else {
105
               mask = mask << 1;
106
            }
107
         }
108
 
109
         /* get ready for next row */
110
         if (mask != 1)
111
            src++;
112
      }
113
      else {
114
         /* Msb first */
115
         GLubyte mask = 128U >> (unpack->SkipPixels & 0x7);
116
         for (col = 0; col < width; col++) {
117
            if (*src & mask) {
118
               span.array->x[count] = px + col;
119
               span.array->y[count] = py + row;
120
               count++;
121
            }
122
            if (mask == 1U) {
123
               src++;
124
               mask = 128U;
125
            }
126
            else {
127
               mask = mask >> 1;
128
            }
129
         }
130
 
131
         /* get ready for next row */
132
         if (mask != 128)
133
            src++;
134
      }
135
 
136
      if (count + width >= MAX_WIDTH || row + 1 == height) {
137
         /* flush the span */
138
         span.end = count;
139
         if (ctx->Visual.rgbMode)
140
            _mesa_write_rgba_span(ctx, &span);
141
         else
142
            _mesa_write_index_span(ctx, &span);
143
         span.end = 0;
144
         count = 0;
145
      }
146
   }
147
 
148
   RENDER_FINISH(swrast,ctx);
149
}
150
 
151
 
152
#if 0
153
/*
154
 * XXX this is another way to implement Bitmap.  Use horizontal runs of
155
 * fragments, initializing the mask array to indicate which fragmens to
156
 * draw or skip.
157
 */
158
void
159
_swrast_Bitmap( GLcontext *ctx, GLint px, GLint py,
160
                GLsizei width, GLsizei height,
161
                const struct gl_pixelstore_attrib *unpack,
162
                const GLubyte *bitmap )
163
{
164
   SWcontext *swrast = SWRAST_CONTEXT(ctx);
165
   GLint row, col;
166
   struct sw_span span;
167
 
168
   ASSERT(ctx->RenderMode == GL_RENDER);
169
   ASSERT(bitmap);
170
 
171
   RENDER_START(swrast,ctx);
172
 
173
   if (SWRAST_CONTEXT(ctx)->NewState)
174
      _swrast_validate_derived( ctx );
175
 
176
   INIT_SPAN(span, GL_BITMAP, width, 0, SPAN_MASK);
177
 
178
   /*span.arrayMask |= SPAN_MASK;*/  /* we'll init span.mask[] */
179
   span.x = px;
180
   span.y = py;
181
   /*span.end = width;*/
182
   if (ctx->Visual.rgbMode) {
183
      span.interpMask |= SPAN_RGBA;
184
      span.red   = FloatToFixed(ctx->Current.RasterColor[0] * CHAN_MAXF);
185
      span.green = FloatToFixed(ctx->Current.RasterColor[1] * CHAN_MAXF);
186
      span.blue  = FloatToFixed(ctx->Current.RasterColor[2] * CHAN_MAXF);
187
      span.alpha = FloatToFixed(ctx->Current.RasterColor[3] * CHAN_MAXF);
188
      span.redStep = span.greenStep = span.blueStep = span.alphaStep = 0;
189
   }
190
   else {
191
      span.interpMask |= SPAN_INDEX;
192
      span.index = ChanToFixed(ctx->Current.RasterIndex);
193
      span.indexStep = 0;
194
   }
195
 
196
   if (ctx->Depth.Test)
197
      _mesa_span_default_z(ctx, &span);
198
   if (ctx->Fog.Enabled)
199
      _mesa_span_default_fog(ctx, &span);
200
 
201
   for (row=0; row<height; row++, span.y++) {
202
      const GLubyte *src = (const GLubyte *) _mesa_image_address( unpack,
203
                 bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, 0, row, 0 );
204
 
205
      if (unpack->LsbFirst) {
206
         /* Lsb first */
207
         GLubyte mask = 1U << (unpack->SkipPixels & 0x7);
208
         for (col=0; col<width; col++) {
209
            span.array->mask[col] = (*src & mask) ? GL_TRUE : GL_FALSE;
210
            if (mask == 128U) {
211
               src++;
212
               mask = 1U;
213
            }
214
            else {
215
               mask = mask << 1;
216
            }
217
         }
218
 
219
         if (ctx->Visual.rgbMode)
220
            _mesa_write_rgba_span(ctx, &span);
221
         else
222
            _mesa_write_index_span(ctx, &span);
223
 
224
         /* get ready for next row */
225
         if (mask != 1)
226
            src++;
227
      }
228
      else {
229
         /* Msb first */
230
         GLubyte mask = 128U >> (unpack->SkipPixels & 0x7);
231
         for (col=0; col<width; col++) {
232
            span.array->mask[col] = (*src & mask) ? GL_TRUE : GL_FALSE;
233
            if (mask == 1U) {
234
               src++;
235
               mask = 128U;
236
            }
237
            else {
238
               mask = mask >> 1;
239
            }
240
         }
241
 
242
         if (ctx->Visual.rgbMode)
243
            _mesa_write_rgba_span(ctx, &span);
244
         else
245
            _mesa_write_index_span(ctx, &span);
246
 
247
         /* get ready for next row */
248
         if (mask != 128)
249
            src++;
250
      }
251
   }
252
 
253
   RENDER_FINISH(swrast,ctx);
254
}
255
#endif