vertex program check-in
[mesa.git] / src / mesa / swrast / s_bitmap.c
1 /* $Id: s_bitmap.c,v 1.13 2001/12/14 02:50:57 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 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 #include "glheader.h"
29 #include "image.h"
30 #include "macros.h"
31 #include "pixel.h"
32
33 #include "s_context.h"
34 #include "s_fog.h"
35 #include "s_pb.h"
36
37
38
39 /*
40 * Render a bitmap.
41 */
42 void
43 _swrast_Bitmap( GLcontext *ctx, GLint px, GLint py,
44 GLsizei width, GLsizei height,
45 const struct gl_pixelstore_attrib *unpack,
46 const GLubyte *bitmap )
47 {
48 SWcontext *swrast = SWRAST_CONTEXT(ctx);
49 struct pixel_buffer *PB = swrast->PB;
50 GLint row, col;
51 GLdepth fragZ;
52 GLfloat fog;
53
54 ASSERT(ctx->RenderMode == GL_RENDER);
55 ASSERT(bitmap);
56
57 RENDER_START(swrast,ctx);
58
59 if (SWRAST_CONTEXT(ctx)->NewState)
60 _swrast_validate_derived( ctx );
61
62 /* Set bitmap drawing color */
63 if (ctx->Visual.rgbMode) {
64 GLint r, g, b, a;
65 r = (GLint) (ctx->Current.RasterColor[0] * CHAN_MAXF);
66 g = (GLint) (ctx->Current.RasterColor[1] * CHAN_MAXF);
67 b = (GLint) (ctx->Current.RasterColor[2] * CHAN_MAXF);
68 a = (GLint) (ctx->Current.RasterColor[3] * CHAN_MAXF);
69 PB_SET_COLOR( PB, r, g, b, a );
70 }
71 else {
72 PB_SET_INDEX( PB, ctx->Current.RasterIndex );
73 }
74
75 fragZ = (GLdepth) ( ctx->Current.RasterPos[2] * ctx->DepthMaxF);
76
77 if (ctx->Fog.Enabled) {
78 if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
79 fog = _mesa_z_to_fogfactor(ctx, ctx->Current.Attrib[VERT_ATTRIB_FOG][0]);
80 else
81 fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
82 }
83 else {
84 fog = 0.0;
85 }
86
87 for (row=0; row<height; row++) {
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 PB_WRITE_PIXEL( PB, px+col, py+row, fragZ, fog );
97 }
98 if (mask == 128U) {
99 src++;
100 mask = 1U;
101 }
102 else {
103 mask = mask << 1;
104 }
105 }
106
107 PB_CHECK_FLUSH( ctx, PB );
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 PB_WRITE_PIXEL( PB, px+col, py+row, fragZ, fog );
119 }
120 if (mask == 1U) {
121 src++;
122 mask = 128U;
123 }
124 else {
125 mask = mask >> 1;
126 }
127 }
128
129 PB_CHECK_FLUSH( ctx, PB );
130
131 /* get ready for next row */
132 if (mask != 128)
133 src++;
134 }
135 }
136
137 _mesa_flush_pb(ctx);
138
139 RENDER_FINISH(swrast,ctx);
140 }