PLplot  5.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
cd.h
Go to the documentation of this file.
1 #ifndef CD_H
2 #define CD_H 1
3 
4 // cd.h: declarations file for the cgmdraw module.
5 //
6 // Written by G. Edward Johnson <mailto:lorax@nist.gov>
7 // Date: April 1996
8 // Copyright: cd software produced by NIST, an agency of the
9 // U.S. government, is by statute not subject to copyright
10 // in the United States. Recipients of this software assume all
11 // responsibilities associated with its operation, modification
12 // and maintenance.
13 //
14 // Portions of this package are from the gd package written by
15 // Thomas Boutell and are copyright 1994, 1995, Quest Protein
16 // Database Center, Cold Spring Harbor Labs. They are marked in the
17 // source code.
18 //
19 //
20 
21 // #include <prof.h>
22 
23 // stdio is needed for file I/O.
24 #include <stdio.h>
25 #include "cddll.h"
26 // This can not be changed to a value larger than 256, though smaller
27 // values can be used.
28 //
29 
30 #define cdMaxColors 256
31 
32 // If you know you will be working with large pictures, increase the values
33 // of the next two constants.
34 //
35 
36 // The initial size of the element list. When it fills up, we will just
37 // make it bigger. Starting with a larger number reduces the frequency of
38 // the list growing, but increases the memory needed for small pictures
39 //
40 
41 #define CDSTARTLISTSIZE 4096
42 
43 // How much the element list grows by. When the list fills up, we allocate
44 // a new larger list. This number is how much larger. using a larger number
45 // decreases the frequency of the list growing, but if only a small amount
46 // more is needed, it could waste memory
47 //
48 
49 #define CDGROWLISTSIZE 2048
50 
51 // Image type. See functions below; you will not need to change
52 // the elements directly. Use the provided macros to
53 // access sx, sy, the color table, and colorsTotal for
54 // read-only purposes.
55 
56 #if defined ( __cplusplus ) || defined ( c_plusplus )
57 extern "C" {
58 #endif
59 
60 typedef struct cdImageStruct
61 {
62  // Don't mess with these
63  unsigned char * elemlist;
64  short int state;
70  // You can have multiple pictures in the file, this keeps track
71  // of which one you are on
72  int picnum;
73  // these take effect only when the first picture is created.
74  // subsequent changes have no effect
75  unsigned char *desc;
76  unsigned char *fontlist;
77  short int numfonts;
78  FILE *outfile;
79  // these take effect when a new picture is opened. Subsequent
80  // changes are for the next picture
81  int linespec;
82  int edgespec;
84  int sx;
85  int sy;
86  // these take effect immediately
87  // Linetype, line width, line color have a broader scope in CGM
88  int ltype;
89  int lwidth;
90  int lcolor;
91  // interior style [of filled objects] (for me) can be empty, hollow,
92  // solid, hatch [don't do pattern, geometric pattern, interpolated
94  // fill color, color used on inside of closed objects, significant
95  // if interior style is hollow, solid, hatch, or geometric pattern
97  // hatch index, which hatch style to use, 1=horizontal, 2=vertical,
98  // 3=pos.slope, 4=neg.slope, 5=hor/vert.crosshatch,
99  // 6=pos/neg.crosshatch
101  // The edges of filled shapes can have line styles too. They
102  // correspond to the ones for lines. These next few set them.
103  int edgetype;
106  int edgevis; // is the edge visible or invisible
107  // now for the TEXT related attributes, Text Color, Text Height,
108  // and Text font index
109  int textfont;
112  int textpath;
113  // Marker type, Marker size, marker color
114  int mtype;
115  int msize;
116  int mcolor;
117  // the next three are used for maintaining the element list
118  long int bytestoend; // number of bytes to end of the element list
119  long int listlen; // the total length of the element list
120  unsigned char * curelemlist; // where we curently are in the list
121 } cdImage;
122 
123 typedef cdImage * cdImagePtr;
124 
125 
126 // Point type for use in polygon drawing.
127 
128 typedef struct cdPointStruct
129 {
130  int x, y, e;
131 } cdPoint, *cdPointPtr;
132 
133 
134 
135 // Functions to manipulate images.
136 
137 CDDLLIMPEXP cdImagePtr cdImageCreate( int sx, int sy );
138 CDDLLIMPEXP int cdCgmNewPic( cdImagePtr im, int sticky );
139 CDDLLIMPEXP int cdImageCgm( cdImagePtr im, FILE * );
140 CDDLLIMPEXP int cdImageDestroy( cdImagePtr im );
141 
142 // Use cdLine, not cdImageLine
143 CDDLLIMPEXP int cdLine( cdImagePtr im, int x1, int y1, int x2, int y2 );
144 // Corners specified (not width and height). Upper left first, lower right
145 // second.
146 CDDLLIMPEXP int cdRectangle( cdImagePtr im, int x1, int y1, int x2, int y2 );
147 // center x, then center y, then radius of circle
148 CDDLLIMPEXP int cdCircle( cdImagePtr im, int cx, int cy, int r );
149 // start, middle and end of arc
150 CDDLLIMPEXP int cdArc3Pt( cdImagePtr im, int sx, int sy, int ix, int iy, int ex, int ey );
151 // cl is 0 for pie closure, 1 for cord closure
152 CDDLLIMPEXP int cdArc3PtClose( cdImagePtr im, int sx, int sy, int ix, int iy, int ex, int ey, int cl );
153 CDDLLIMPEXP int cdEllipse( cdImagePtr im, int cx, int cy, int d1x, int d1y, int d2x, int d2y );
154 CDDLLIMPEXP int cdMarker( cdImagePtr im, int x, int y );
155 // polyshapes
156 CDDLLIMPEXP int cdPolygon( cdImagePtr im, cdPointPtr p, int n );
157 CDDLLIMPEXP int cdPolygonSet( cdImagePtr im, cdPointPtr p, int n );
158 CDDLLIMPEXP int cdPolyLine( cdImagePtr im, cdPointPtr p, int n );
159 CDDLLIMPEXP int cdPolyMarker( cdImagePtr im, cdPointPtr p, int n );
160 
161 // Functions for Compatibility with gd
162 CDDLLIMPEXP int cdImageLine( cdImagePtr im, int x1, int y1, int x2, int y2, int color );
163 CDDLLIMPEXP int cdImageRectangle( cdImagePtr im, int x1, int y1, int x2, int y2, int color );
164 
165 
166 CDDLLIMPEXP int cdImageBoundsSafe( cdImagePtr im, int x, int y );
167 // These put characters in the picture. CGM can handle fonts
168 // (x,y) is the lower left corner of where the text goes
169 CDDLLIMPEXP int cdText( cdImagePtr im, int x, int y, const char * );
170 
171 
172 // Functions for allocating colors
173 CDDLLIMPEXP int cdImageColorAllocate( cdImagePtr im, int r, int g, int b );
174 CDDLLIMPEXP int cdImageColorClosest( cdImagePtr im, int r, int g, int b );
175 CDDLLIMPEXP int cdImageColorExact( cdImagePtr im, int r, int g, int b );
176 CDDLLIMPEXP int cdImageColorDeallocate( cdImagePtr /* im */, int /* color */ );
177 // wogl: the parameter names are commented to avoid compiler warnings
178 CDDLLIMPEXP int cdImageColor16( cdImagePtr im );
179 
180 // gej: functions that set style attributes
181 CDDLLIMPEXP int cdSetLineAttrib( cdImagePtr im, int lntype, int lnwidth, int lncolor );
182 CDDLLIMPEXP int cdSetShapeFillAttrib( cdImagePtr im, int instyle, int incolor, int inhatch );
183 CDDLLIMPEXP int cdSetShapeEdgeAttrib( cdImagePtr im, int edtype, int edwidth, int edcolor, int edvis );
184 CDDLLIMPEXP int cdSetTextAttrib( cdImagePtr im, int font, int color, int height );
185 CDDLLIMPEXP int cdSetMarkerAttrib( cdImagePtr im, int mtype, int msize, int mcolor );
186 
187 // gej: or if you prefer, set the attributes individually
188 CDDLLIMPEXP int cdSetLineType( cdImagePtr im, int lntype );
189 CDDLLIMPEXP int cdSetLineWidth( cdImagePtr im, int lnwidth );
190 CDDLLIMPEXP int cdSetLineColor( cdImagePtr im, int lncolor );
191 CDDLLIMPEXP int cdSetFillStyle( cdImagePtr im, int instyle );
192 CDDLLIMPEXP int cdSetFillColor( cdImagePtr im, int incolor );
193 CDDLLIMPEXP int cdSetFillHatch( cdImagePtr im, int inhatch );
194 CDDLLIMPEXP int cdSetEdgeType( cdImagePtr im, int edtype );
195 CDDLLIMPEXP int cdSetEdgeWidth( cdImagePtr im, int edwidth );
196 CDDLLIMPEXP int cdSetEdgeColor( cdImagePtr im, int edcolor );
197 CDDLLIMPEXP int cdSetEdgeVis( cdImagePtr im, int edvis );
198 CDDLLIMPEXP int cdSetTextFont( cdImagePtr im, int font );
199 CDDLLIMPEXP int cdSetTextColor( cdImagePtr im, int color );
200 CDDLLIMPEXP int cdSetTextHeight( cdImagePtr im, int height );
201 // geJ: these individual attributes can't be set with a group function
202 CDDLLIMPEXP int cdSetTextPath( cdImagePtr im, int tpath );
203 CDDLLIMPEXP int cdSetTextOrient( cdImagePtr im, int xup, int yup, int xbase, int ybase );
204 CDDLLIMPEXP int cdSetMarkerType( cdImagePtr im, int mtype );
205 CDDLLIMPEXP int cdSetMarkerSize( cdImagePtr im, int msize );
206 CDDLLIMPEXP int cdSetMarkerColor( cdImagePtr im, int mcolor );
207 
208 // EJ: Expert Functions, If you just need more control
209 CDDLLIMPEXP int cdImageSetSize( cdImagePtr im, int x, int y );
210 CDDLLIMPEXP int cdImageSetLineSpec( cdImagePtr im, int specmode );
211 CDDLLIMPEXP int cdImageSetMarkerSpec( cdImagePtr im, int specmode );
212 CDDLLIMPEXP int cdImageSetEdgeSpec( cdImagePtr im, int specmode );
213 CDDLLIMPEXP int cdImageSetOutput( cdImagePtr im, FILE *output );
214 CDDLLIMPEXP int cdImageAddFont( cdImagePtr im, const char *fontname );
215 CDDLLIMPEXP int cdImageClearFonts( cdImagePtr im );
216 CDDLLIMPEXP cdImagePtr cdImageStartCgm();
217 CDDLLIMPEXP int cdCgmHeader( cdImagePtr );
218 CDDLLIMPEXP int cdCgmPic( cdImagePtr, int );
219 CDDLLIMPEXP int cdImageSetDefaults( cdImagePtr im );
220 CDDLLIMPEXP int cdImageEndPic( cdImagePtr im );
221 CDDLLIMPEXP int cdImageEndCgm( cdImagePtr im );
222 
223 // Macros to access information about images. READ ONLY. Changing
224 // these values will NOT have the desired result.
225 #define cdImageSX( im ) ( ( im )->sx )
226 #define cdImageSY( im ) ( ( im )->sy )
227 #define cdImageColorsTotal( im ) ( ( im )->colorsTotal )
228 #define cdImageRed( im, c ) ( ( im )->red[( c )] )
229 #define cdImageGreen( im, c ) ( ( im )->green[( c )] )
230 #define cdImageBlue( im, c ) ( ( im )->blue[( c )] )
231 
232 // Source: Independent JPEG Group
233 // In ANSI C, and indeed any rational implementation, size_t is also the
234 // type returned by sizeof(). However, it seems there are some irrational
235 // implementations out there, in which sizeof() returns an int even though
236 // size_t is defined as long or unsigned long. To ensure consistent results
237 // we always use this SIZEOF() macro in place of using sizeof() directly.
238 //
239 
240 #define SIZEOF( object ) ( (size_t) sizeof ( object ) )
241 
242 // GeJ: these are helper functions I use in cd. That means DON'T call
243 // them from your program. Yes, that means you.
244 CDDLLIMPEXP int cdImageColorClear( cdImagePtr im );
245 
246 #if defined ( __cplusplus ) || defined ( c_plusplus )
247 }
248 #endif
249 
250 
251 #endif