]> icculus.org git repositories - taylor/freespace2.git/blob - src/graphics/gradient.cpp
Screenshot function filled, will output into ~/.freespace(2)/Data
[taylor/freespace2.git] / src / graphics / gradient.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Graphics/Gradient.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Routines to draw rectangular gradients.
16  *
17  * $Log$
18  * Revision 1.2  2002/06/09 04:41:17  relnev
19  * added copyright header
20  *
21  * Revision 1.1.1.1  2002/05/03 03:28:09  root
22  * Initial import.
23  *
24  * 
25  * 3     12/02/98 5:47p Dave
26  * Put in interface xstr code. Converted barracks screen to new format.
27  * 
28  * 2     10/07/98 10:52a Dave
29  * Initial checkin.
30  * 
31  * 1     10/07/98 10:49a Dave
32  * 
33  * 17    5/06/98 5:30p John
34  * Removed unused cfilearchiver.  Removed/replaced some unused/little used
35  * graphics functions, namely gradient_h and _v and pixel_sp.   Put in new
36  * DirectX header files and libs that fixed the Direct3D alpha blending
37  * problems.
38  * 
39  * 16    3/10/98 4:18p John
40  * Cleaned up graphics lib.  Took out most unused gr functions.   Made D3D
41  * & Glide have popups and print screen.  Took out all >8bpp software
42  * support.  Made Fred zbuffer.  Made zbuffer allocate dynamically to
43  * support Fred.  Made zbuffering key off of functions rather than one
44  * global variable.
45  * 
46  * 15    1/19/98 6:15p John
47  * Fixed all my Optimized Build compiler warnings
48  * 
49  * 14    11/30/97 4:04p John
50  * 
51  * 13    11/30/97 12:18p John
52  * added more 24 & 32-bpp primitives
53  * 
54  * 12    10/19/97 12:55p John
55  * new code to lock / unlock surfaces for smooth directx integration.
56  * 
57  * 11    10/14/97 4:50p John
58  * more 16 bpp stuff.
59  * 
60  * 10    10/14/97 8:08a John
61  * added a bunch more 16 bit support
62  * 
63  * 9     10/09/97 5:23p John
64  * Added support for more 16-bpp functions
65  * 
66  * 8     6/11/97 1:12p John
67  * Started fixing all the text colors in the game.
68  * 
69  * 7     5/12/97 12:27p John
70  * Restructured Graphics Library to add support for multiple renderers.
71  * 
72  * 6     12/12/96 4:59p Lawrance
73  * made clipping for horizontal and vertical gradient lines right
74  * 
75  * 5     11/19/96 2:46p Allender
76  * fix up gradient support for 15bpp
77  * 
78  * 4     11/18/96 4:34p Allender
79  * new 16 bit gradient functions
80  * 
81  * 3     10/27/96 1:21a Lawrance
82  * added check to avoid divide by zero when calculating gradients
83  * 
84  * 2     10/26/96 2:56p John
85  * Got gradient code working.
86  * 
87  * 1     10/26/96 1:45p John
88  * Initial skeletion code.
89  *
90  * $NoKeywords: $
91  */
92
93 #ifndef PLAT_UNIX
94 #include <windows.h>
95 #include <windowsx.h>
96 #endif
97
98 #include "2d.h"
99 #include "grinternal.h"
100 #include "gradient.h"
101 #include "floating.h"
102 #include "line.h"
103 #include "palman.h"
104                 
105 void gr8_gradient(int x1,int y1,int x2,int y2)
106 {
107 #ifndef HARDWARE_ONLY
108         int i;
109    int xstep,ystep;
110         int clipped = 0, swapped=0;
111         ubyte *xlat_table;
112
113         int l=0, dl=0;
114
115         if (!Current_alphacolor) {
116                 gr_line( x1, y1, x2, y2 );
117                 return;
118         }
119
120         INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,gr_screen.clip_right,gr_screen.clip_bottom,return,clipped=1,swapped=1);
121
122    int dy=y2-y1;
123    int dx=x2-x1;
124    int error_term=0;
125
126         if ( dx==0 && dy==0 )   {
127                 return;
128         }
129
130         gr_lock();
131
132         ubyte *dptr = GR_SCREEN_PTR(ubyte,x1,y1);
133
134         xlat_table = (ubyte *)&Current_alphacolor->table.lookup[0][0];
135
136         
137         if(dy<0)        {
138                 dy=-dy;
139       ystep=-gr_screen.rowsize / gr_screen.bytes_per_pixel;
140         }       else    {
141       ystep=gr_screen.rowsize / gr_screen.bytes_per_pixel;
142         }
143
144    if(dx<0)     {
145       dx=-dx;
146       xstep=-1;
147    } else {
148       xstep=1;
149         }
150
151         if(dx>dy)       {
152
153                 if (!swapped)   {
154                         l = 14<<8;
155                         dl = (-14<<8) / dx;
156                 } else {
157                         l = 0;
158                         dl = (14<<8) / dx;
159                 }       
160
161                 for(i=0;i<dx;i++) {
162                         *dptr = xlat_table[(l&0xF00)|*dptr];
163                         l += dl;
164                         dptr += xstep;
165          error_term+=dy;
166
167          if(error_term>dx)      {
168                                 error_term-=dx;
169             dptr+=ystep;
170          }
171       }
172                 *dptr = xlat_table[(l&0xF00)|*dptr];
173
174    } else {
175
176                 if (!swapped)   {
177                         l = 14<<8;
178                         dl = (-14<<8) / dy;
179                 } else {
180                         l = 0;
181                         dl = (14<<8) / dy;
182                 }       
183
184       for(i=0;i<dy;i++) {
185                         *dptr = xlat_table[(l&0xF00)|*dptr];
186                         l += dl;
187                         dptr += ystep;
188          error_term+=dx;
189          if(error_term>0)       {
190             error_term-=dy;
191             dptr+=xstep;
192          }
193
194       }
195                 *dptr = xlat_table[(l&0xF00)|*dptr];
196
197    }
198         gr_unlock();
199 #else 
200         Int3();
201 #endif
202 }
203
204
205                 
206
207