aboutsummaryrefslogtreecommitdiffstats
path: root/src/cd/color16.c
blob: ca7e4545ff502601ae5b3984696aba62927576a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* 
 * Color16 is a test program that is part of the CGM Draw Library.
 * It Will write out a CGM file that allocates a 16 color pallete
 * using the function cdImageColor16.  These correspond to the 16
 * standard Windows colors.
 *

 color16.c: test program for the cgmdraw module.

        Written by G. Edward Johnson <mailto:lorax@nist.gov>
        Date: April 1996
        Copyright: cd software produced by NIST, an agency of the 
	U.S. government, is by statute not subject to copyright
	in the United States. Recipients of this software assume all 
	responsibilities associated with its operation, modification
	and maintenance.

*/


#include <malloc.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include "defines.h"
#include "cd.h"


int main () {
	cdImagePtr im;
	FILE *outf;


	/* Create an image 500 pixels high by 400 pixels wide */
	im = cdImageCreate(400, 500);

	/* allocate the 16 windows colors */
	if (!(cdImageColor16(im))) return 0;

	/* Set the fill attributes */
	/* fill=solid, colorindex=0, hatch=no change */
	if (!(cdSetShapeFillAttrib(im, 1, 0, -1))) return 0;

	/* set the text attributes */
	/* font=helvetica, colorindex=1, size=25 */
	if (!(cdSetTextAttrib(im, 5, 1, 25))) return 0;

	/* The first color index is white, so lets draw a box around it */
	/* edge=solid, width=1, color=1 (black), visible=yes */
	cdSetShapeEdgeAttrib(im, 1, 1, 1, 1);


	/* Draw a rectangle (10,450) is upper left, (35,425) is lower right */
	if (!(cdRectangle(im, 10, 450, 35, 425))) return 0;
	/* Label it */
	if (!(cdText(im, 40, 425, "Color Index: 0"))) return 0;

	/* Make the edges invisible */
	if (!(cdSetEdgeVis(im, 0))) return 0;


	/* Set the fill color */
	if (!(cdSetFillColor(im, 1))) return 0;
	/* Draw a rectangle */
	if (!(cdRectangle(im, 10, 400, 35, 375))) return 0;
	/* Label it */
	if (!(cdText(im, 40, 375, "Color Index: 1"))) return 0;

	/* Set the fill color */
	if (!(cdSetFillColor(im, 2))) return 0;
	/* Draw a rectangle */
	if (!(cdRectangle(im, 10, 350, 35, 325))) return 0;
	/* Label it */
	if (!(cdText(im, 40, 325, "Color Index: 2"))) return 0;

	/* Set the fill color */
	if (!(cdSetFillColor(im, 3))) return 0;
	/* Draw a rectangle */
	if (!(cdRectangle(im, 10, 300, 35, 275))) return 0;
	/* Label it */
	if (!(cdText(im, 40, 275, "Color Index: 3"))) return 0;

	/* Set the fill color */
	if (!(cdSetFillColor(im, 4))) return 0;
	/* Draw a rectangle */
	if (!(cdRectangle(im, 10, 250, 35, 225))) return 0;
	/* Label it */
	if (!(cdText(im, 40, 225, "Color Index: 4"))) return 0;

	/* Set the fill color */
	if (!(cdSetFillColor(im, 5))) return 0;
	/* Draw a rectangle */
	if (!(cdRectangle(im, 10, 200, 35, 175))) return 0;
	/* Label it */
	if (!(cdText(im, 40, 175, "Color Index: 5"))) return 0;

	/* Set the fill color */
	if (!(cdSetFillColor(im, 6))) return 0;
	/* Draw a rectangle */
	if (!(cdRectangle(im, 10, 150, 35, 125))) return 0;
	/* Label it */
	if (!(cdText(im, 40, 125, "Color Index: 6"))) return 0;

	/* Set the fill color */
	if (!(cdSetFillColor(im, 7))) return 0;
	/* Draw a rectangle */
	if (!(cdRectangle(im, 10, 100, 35, 75))) return 0;
	/* Label it */
	if (!(cdText(im, 40, 75, "Color Index: 7"))) return 0;

	/* Set the fill color */
	if (!(cdSetFillColor(im, 8))) return 0;
	/* Draw a rectangle */
	if (!(cdRectangle(im, 210, 450, 235, 425))) return 0;
	/* Label it */
	if (!(cdText(im, 240, 425, "Color Index: 8"))) return 0;

	/* Set the fill color */
	if (!(cdSetFillColor(im, 9))) return 0;
	/* Draw a rectangle */
	if (!(cdRectangle(im, 210, 400, 235, 375))) return 0;
	/* Label it */
	if (!(cdText(im, 240, 375, "Color Index: 9"))) return 0;

	/* Set the fill color */
	if (!(cdSetFillColor(im, 10))) return 0;
	/* Draw a rectangle */
	if (!(cdRectangle(im, 210, 350, 235, 325))) return 0;
	/* Label it */
	if (!(cdText(im, 240, 325, "Color Index: 10"))) return 0;

	/* Set the fill color */
	if (!(cdSetFillColor(im, 11))) return 0;
	/* Draw a rectangle */
	if (!(cdRectangle(im, 210, 300, 235, 275))) return 0;
	/* Label it */
	if (!(cdText(im, 240, 275, "Color Index: 11"))) return 0;

	/* Set the fill color */
	if (!(cdSetFillColor(im, 12))) return 0;
	/* Draw a rectangle */
	if (!(cdRectangle(im, 210, 250, 235, 225))) return 0;
	/* Label it */
	if (!(cdText(im, 240, 225, "Color Index: 12"))) return 0;

	/* Set the fill color */
	if (!(cdSetFillColor(im, 13))) return 0;
	/* Draw a rectangle */
	if (!(cdRectangle(im, 210, 200, 235, 175))) return 0;
	/* Label it */
	if (!(cdText(im, 240, 175, "Color Index: 13"))) return 0;

	/* Set the fill color */
	if (!(cdSetFillColor(im, 14))) return 0;
	/* Draw a rectangle */
	if (!(cdRectangle(im, 210, 150, 235, 125))) return 0;
	/* Label it */
	if (!(cdText(im, 240, 125, "Color Index: 14"))) return 0;

	/* Set the fill color */
	if (!(cdSetFillColor(im, 15))) return 0;
	/* Draw a rectangle */
	if (!(cdRectangle(im, 210, 100, 235, 75))) return 0;
	/* Label it */
	if (!(cdText(im, 240, 75, "Color Index: 15"))) return 0;

	/* now put a little thing at the bottom of the picture */
	if (!cdText(im, 5, 10, "Colors allocated by cdImageColor16")) return 0;

	/* now write the file out, lets call it color16.cgm */
	outf = fopen("color16.cgm", "wb");
	if (!outf) return 0;
	cdImageCgm(im, outf);
	fclose(outf);
	outf = 0;

	/* Remember to destroy the image when you are done */
	cdImageDestroy(im);
	im = 0;

	printf("CGM with 16 color colortable generated as color16.cgm\n");

	return 1;

}