ReactOS 0.4.15-dev-7889-g76290a6
bitmap.c
Go to the documentation of this file.
1/* $Id: bitmap.c,v 1.9 1998/02/03 23:45:02 brianp Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version: 2.5
6 * Copyright (C) 1995-1997 Brian Paul
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23
24/*
25 * $Log: bitmap.c,v $
26 * Revision 1.9 1998/02/03 23:45:02 brianp
27 * added casts to prevent warnings with Amiga StormC compiler
28 *
29 * Revision 1.8 1997/10/02 03:06:42 brianp
30 * added #include <assert.h>
31 *
32 * Revision 1.7 1997/09/27 00:15:39 brianp
33 * changed parameters to gl_unpack_image()
34 *
35 * Revision 1.6 1997/07/24 01:24:45 brianp
36 * changed precompiled header symbol from PCH to PC_HEADER
37 *
38 * Revision 1.5 1997/06/20 02:18:09 brianp
39 * replaced Current.IntColor with Current.ByteColor
40 *
41 * Revision 1.4 1997/05/28 03:23:48 brianp
42 * added precompiled header (PCH) support
43 *
44 * Revision 1.3 1996/11/06 04:23:18 brianp
45 * replaced 0 with GL_COLOR_INDEX in gl_unpack_bitmap()
46 *
47 * Revision 1.2 1996/09/15 14:18:10 brianp
48 * now use GLframebuffer and GLvisual
49 *
50 * Revision 1.1 1996/09/13 01:38:16 brianp
51 * Initial revision
52 *
53 */
54
55
56#ifdef PC_HEADER
57#include "all.h"
58#else
59#include <assert.h>
60#include <stdlib.h>
61#include <string.h>
62#include "bitmap.h"
63#include "context.h"
64#include "feedback.h"
65#include "image.h"
66#include "macros.h"
67#include "pb.h"
68#include "types.h"
69#endif
70
71
72
73/*
74 * Unpack a bitmap image
75 */
78 const GLubyte *bitmap )
79{
82}
83
84
85
86
87/*
88 * Do actual rendering of a bitmap.
89 */
92 GLfloat xorig, GLfloat yorig,
93 GLfloat xmove, GLfloat ymove,
94 const struct gl_image *bitmap )
95{
96 struct pixel_buffer *PB = ctx->PB;
97 GLint bx, by; /* bitmap position */
98 GLint px, py, pz; /* pixel position */
99 GLubyte *ptr;
100
101 assert(bitmap);
102 assert(bitmap->Type == GL_BITMAP);
103 assert(bitmap->Format == GL_COLOR_INDEX);
104
105 if (ctx->NewState) {
107 PB_INIT( PB, GL_BITMAP );
108 }
109
110 if (ctx->Visual->RGBAflag) {
111 GLint r, g, b, a;
112 r = (GLint) (ctx->Current.RasterColor[0] * ctx->Visual->RedScale);
113 g = (GLint) (ctx->Current.RasterColor[1] * ctx->Visual->GreenScale);
114 b = (GLint) (ctx->Current.RasterColor[2] * ctx->Visual->BlueScale);
115 a = (GLint) (ctx->Current.RasterColor[3] * ctx->Visual->AlphaScale);
116 PB_SET_COLOR( ctx, PB, r, g, b, a );
117 }
118 else {
119 PB_SET_INDEX( ctx, PB, ctx->Current.RasterIndex );
120 }
121
122 px = (GLint) ( (ctx->Current.RasterPos[0] - xorig) + 0.0F );
123 py = (GLint) ( (ctx->Current.RasterPos[1] - yorig) + 0.0F );
124 pz = (GLint) ( ctx->Current.RasterPos[2] * DEPTH_SCALE );
125 ptr = (GLubyte *) bitmap->Data;
126
127 for (by=0;by<height;by++) {
128 GLubyte bitmask;
129
130 /* do a row */
131 bitmask = 128;
132 for (bx=0;bx<width;bx++) {
133 if (*ptr&bitmask) {
134 PB_WRITE_PIXEL( PB, px+bx, py+by, pz );
135 }
136 bitmask = bitmask >> 1;
137 if (bitmask==0) {
138 ptr++;
139 bitmask = 128;
140 }
141 }
142
144
145 /* get ready for next row */
146 if (bitmask!=128) ptr++;
147 }
148
150}
151
152
153
154
155/*
156 * Execute a glBitmap command:
157 * 1. check for errors
158 * 2. feedback/render/select
159 * 3. advance raster position
160 */
163 GLfloat xorig, GLfloat yorig,
164 GLfloat xmove, GLfloat ymove,
165 const struct gl_image *bitmap )
166{
167 if (width<0 || height<0) {
168 gl_error( ctx, GL_INVALID_VALUE, "glBitmap" );
169 return;
170 }
171 if (INSIDE_BEGIN_END(ctx)) {
172 gl_error( ctx, GL_INVALID_OPERATION, "glBitmap" );
173 return;
174 }
175 if (ctx->Current.RasterPosValid==GL_FALSE) {
176 /* do nothing */
177 return;
178 }
179
180 if (ctx->RenderMode==GL_RENDER) {
181 GLboolean completed = GL_FALSE;
182 if (ctx->Driver.Bitmap) {
183 /* let device driver try to render the bitmap */
184 completed = (*ctx->Driver.Bitmap)( ctx, width, height, xorig, yorig,
185 xmove, ymove, bitmap );
186 }
187 if (!completed) {
188 /* use generic function */
189 gl_render_bitmap( ctx, width, height, xorig, yorig,
190 xmove, ymove, bitmap );
191 }
192 }
193 else if (ctx->RenderMode==GL_FEEDBACK) {
194 GLfloat color[4], texcoord[4], invq;
195 color[0] = ctx->Current.ByteColor[0] * ctx->Visual->InvRedScale;
196 color[1] = ctx->Current.ByteColor[1] * ctx->Visual->InvGreenScale;
197 color[2] = ctx->Current.ByteColor[2] * ctx->Visual->InvBlueScale;
198 color[3] = ctx->Current.ByteColor[3] * ctx->Visual->InvAlphaScale;
199 invq = 1.0F / ctx->Current.TexCoord[3];
200 texcoord[0] = ctx->Current.TexCoord[0] * invq;
201 texcoord[1] = ctx->Current.TexCoord[1] * invq;
202 texcoord[2] = ctx->Current.TexCoord[2] * invq;
203 texcoord[3] = ctx->Current.TexCoord[3];
205 /* TODO: Verify XYZW values are correct: */
206 gl_feedback_vertex( ctx, ctx->Current.RasterPos[0] - xorig,
207 ctx->Current.RasterPos[1] - yorig,
208 ctx->Current.RasterPos[2],
209 ctx->Current.RasterPos[3],
210 color, ctx->Current.Index, texcoord );
211 }
212 else if (ctx->RenderMode==GL_SELECT) {
213 /* Bitmaps don't generate selection hits. See appendix B of 1.1 spec. */
214 }
215
216 /* update raster position */
217 ctx->Current.RasterPos[0] += xmove;
218 ctx->Current.RasterPos[1] += ymove;
219}
220
221
void gl_Bitmap(GLcontext *ctx, GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const struct gl_image *bitmap)
Definition: bitmap.c:161
void gl_render_bitmap(GLcontext *ctx, GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const struct gl_image *bitmap)
Definition: bitmap.c:90
struct gl_image * gl_unpack_bitmap(GLcontext *ctx, GLsizei width, GLsizei height, const GLubyte *bitmap)
Definition: bitmap.c:76
#define DEPTH_SCALE
Definition: config.h:146
void gl_error(GLcontext *ctx, GLenum error, const char *s)
Definition: context.c:1421
void gl_update_state(GLcontext *ctx)
Definition: context.c:1749
struct gl_image * gl_unpack_image(GLcontext *ctx, GLint width, GLint height, GLenum srcFormat, GLenum srcType, const GLvoid *pixels)
Definition: image.c:314
#define PB
#define assert(x)
Definition: debug.h:53
void gl_feedback_vertex(GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z, GLfloat w, const GLfloat color[4], GLfloat index, const GLfloat texcoord[4])
Definition: feedback.c:161
#define FEEDBACK_TOKEN(CTX, T)
Definition: feedback.h:39
unsigned char GLubyte
Definition: gl.h:157
#define GL_RENDER
Definition: gl.h:388
#define GL_INVALID_VALUE
Definition: gl.h:695
float GLfloat
Definition: gl.h:161
#define GL_INVALID_OPERATION
Definition: gl.h:696
#define GL_SELECT
Definition: gl.h:389
#define GL_FEEDBACK
Definition: gl.h:387
#define GL_BITMAP
Definition: gl.h:497
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
#define GL_COLOR_INDEX
Definition: gl.h:479
#define GL_FALSE
Definition: gl.h:173
#define GL_BITMAP_TOKEN
Definition: gl.h:401
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
int GLsizei
Definition: gl.h:160
int GLint
Definition: gl.h:156
GLint GLint GLsizei width
Definition: gl.h:1546
unsigned char GLboolean
Definition: gl.h:151
GLuint color
Definition: glext.h:6243
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean g
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLbyte by
Definition: glext.h:8766
#define a
Definition: ke_i.h:78
#define b
Definition: ke_i.h:79
#define INSIDE_BEGIN_END(CTX)
Definition: macros.h:135
#define for
Definition: utility.h:88
static PVOID ptr
Definition: dispmode.c:27
void gl_flush_pb(GLcontext *ctx)
Definition: pb.c:136
#define PB_SET_INDEX(CTX, PB, I)
Definition: pb.h:105
#define PB_WRITE_PIXEL(PB, X, Y, Z)
Definition: pb.h:116
#define PB_CHECK_FLUSH(CTX, PB)
Definition: pb.h:167
#define PB_INIT(PB, PRIM)
Definition: pb.h:79
#define PB_SET_COLOR(CTX, PB, R, G, B, A)
Definition: pb.h:89
Definition: uimain.c:89