646081b83e1a1abf7ccaad39975ce4b3e489d440
[mesa.git] / src / mesa / swrast / s_bitmap.c
1 /* $Id: s_bitmap.c,v 1.1 2000/10/31 18:00:04 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.3
6 *
7 * Copyright (C) 1999 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_fog.h"
34 #include "s_pb.h"
35
36
37
38 /*
39 * Render a bitmap.
40 */
41 void
42 _swrast_Bitmap( GLcontext *ctx, GLint px, GLint py,
43 GLsizei width, GLsizei height,
44 const struct gl_pixelstore_attrib *unpack,
45 const GLubyte *bitmap )
46 {
47 struct pixel_buffer *PB = ctx->PB;
48 GLint row, col;
49 GLdepth fragZ;
50 GLfixed fogCoord;
51
52 ASSERT(ctx->RenderMode == GL_RENDER);
53 ASSERT(bitmap);
54
55 if (ctx->PB->primitive != GL_BITMAP) {
56 gl_flush_pb( ctx );
57 ctx->PB->primitive = GL_BITMAP;
58 }
59
60 /* Set bitmap drawing color */
61 if (ctx->Visual.RGBAflag) {
62 GLint r, g, b, a;
63 r = (GLint) (ctx->Current.RasterColor[0] * CHAN_MAXF);
64 g = (GLint) (ctx->Current.RasterColor[1] * CHAN_MAXF);
65 b = (GLint) (ctx->Current.RasterColor[2] * CHAN_MAXF);
66 a = (GLint) (ctx->Current.RasterColor[3] * CHAN_MAXF);
67 PB_SET_COLOR( PB, r, g, b, a );
68 }
69 else {
70 PB_SET_INDEX( PB, ctx->Current.RasterIndex );
71 }
72
73 fragZ = (GLdepth) ( ctx->Current.RasterPos[2] * ctx->Visual.DepthMaxF);
74
75 _mesa_win_fog_coords_from_z( ctx, 1, &fragZ, &fogCoord );
76
77 for (row=0; row<height; row++) {
78 const GLubyte *src = (const GLubyte *) _mesa_image_address( unpack,
79 bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, 0, row, 0 );
80
81 if (unpack->LsbFirst) {
82 /* Lsb first */
83 GLubyte mask = 1U << (unpack->SkipPixels & 0x7);
84 for (col=0; col<width; col++) {
85 if (*src & mask) {
86 PB_WRITE_PIXEL( PB, px+col, py+row, fragZ, fogCoord );
87 }
88 if (mask == 128U) {
89 src++;
90 mask = 1U;
91 }
92 else {
93 mask = mask << 1;
94 }
95 }
96
97 PB_CHECK_FLUSH( ctx, PB );
98
99 /* get ready for next row */
100 if (mask != 1)
101 src++;
102 }
103 else {
104 /* Msb first */
105 GLubyte mask = 128U >> (unpack->SkipPixels & 0x7);
106 for (col=0; col<width; col++) {
107 if (*src & mask) {
108 PB_WRITE_PIXEL( PB, px+col, py+row, fragZ, fogCoord );
109 }
110 if (mask == 1U) {
111 src++;
112 mask = 128U;
113 }
114 else {
115 mask = mask >> 1;
116 }
117 }
118
119 PB_CHECK_FLUSH( ctx, PB );
120
121 /* get ready for next row */
122 if (mask != 128)
123 src++;
124 }
125 }
126
127 gl_flush_pb(ctx);
128 }
129
130
131