PLplot
5.10.0
|
00001 // 00002 // Color16 is a test program that is part of the CGM Draw Library. 00003 // It Will write out a CGM file that allocates a 16 color pallete 00004 // using the function cdImageColor16. These correspond to the 16 00005 // standard Windows colors. 00006 // 00007 // 00008 // color16.c: test program for the cgmdraw module. 00009 // 00010 // Written by G. Edward Johnson <mailto:lorax@nist.gov> 00011 // Date: April 1996 00012 // Copyright: cd software produced by NIST, an agency of the 00013 // U.S. government, is by statute not subject to copyright 00014 // in the United States. Recipients of this software assume all 00015 // responsibilities associated with its operation, modification 00016 // and maintenance. 00017 // 00018 // 00019 00020 00021 #ifndef NOMALLOCH 00022 #include <malloc.h> 00023 #endif 00024 #include <stdio.h> 00025 #include <math.h> 00026 #include <string.h> 00027 #include <stdlib.h> 00028 #include "defines.h" 00029 #include "cd.h" 00030 00031 00032 int main() 00033 { 00034 cdImagePtr im; 00035 FILE *outf; 00036 00037 00038 // Create an image 500 pixels high by 400 pixels wide 00039 im = cdImageCreate( 400, 500 ); 00040 00041 // allocate the 16 windows colors 00042 if ( -1 == cdImageColor16( im ) ) 00043 return 1; 00044 00045 // Set the fill attributes 00046 // fill=solid, colorindex=0, hatch=no change 00047 if ( !( cdSetShapeFillAttrib( im, 1, 0, 1 ) ) ) 00048 return 1; 00049 00050 // set the text attributes 00051 // font=helvetica, colorindex=1, size=25 00052 if ( !( cdSetTextAttrib( im, 5, 1, 25 ) ) ) 00053 return 1; 00054 00055 // The first color index is white, so lets draw a box around it 00056 // edge=solid, width=1, color=1 (black), visible=yes 00057 cdSetShapeEdgeAttrib( im, 1, 1, 1, 1 ); 00058 00059 00060 // Draw a rectangle (10,450) is upper left, (35,425) is lower right 00061 if ( !( cdRectangle( im, 10, 450, 35, 425 ) ) ) 00062 return 1; 00063 // Label it 00064 if ( !( cdText( im, 40, 425, "Color Index: 0" ) ) ) 00065 return 1; 00066 00067 // Make the edges invisible 00068 if ( !( cdSetEdgeVis( im, 0 ) ) ) 00069 return 1; 00070 00071 00072 // Set the fill color 00073 if ( !( cdSetFillColor( im, 1 ) ) ) 00074 return 1; 00075 // Draw a rectangle 00076 if ( !( cdRectangle( im, 10, 400, 35, 375 ) ) ) 00077 return 1; 00078 // Label it 00079 if ( !( cdText( im, 40, 375, "Color Index: 1" ) ) ) 00080 return 1; 00081 00082 // Set the fill color 00083 if ( !( cdSetFillColor( im, 2 ) ) ) 00084 return 1; 00085 // Draw a rectangle 00086 if ( !( cdRectangle( im, 10, 350, 35, 325 ) ) ) 00087 return 1; 00088 // Label it 00089 if ( !( cdText( im, 40, 325, "Color Index: 2" ) ) ) 00090 return 1; 00091 00092 // Set the fill color 00093 if ( !( cdSetFillColor( im, 3 ) ) ) 00094 return 1; 00095 // Draw a rectangle 00096 if ( !( cdRectangle( im, 10, 300, 35, 275 ) ) ) 00097 return 1; 00098 // Label it 00099 if ( !( cdText( im, 40, 275, "Color Index: 3" ) ) ) 00100 return 1; 00101 00102 // Set the fill color 00103 if ( !( cdSetFillColor( im, 4 ) ) ) 00104 return 1; 00105 // Draw a rectangle 00106 if ( !( cdRectangle( im, 10, 250, 35, 225 ) ) ) 00107 return 1; 00108 // Label it 00109 if ( !( cdText( im, 40, 225, "Color Index: 4" ) ) ) 00110 return 1; 00111 00112 // Set the fill color 00113 if ( !( cdSetFillColor( im, 5 ) ) ) 00114 return 1; 00115 // Draw a rectangle 00116 if ( !( cdRectangle( im, 10, 200, 35, 175 ) ) ) 00117 return 1; 00118 // Label it 00119 if ( !( cdText( im, 40, 175, "Color Index: 5" ) ) ) 00120 return 1; 00121 00122 // Set the fill color 00123 if ( !( cdSetFillColor( im, 6 ) ) ) 00124 return 1; 00125 // Draw a rectangle 00126 if ( !( cdRectangle( im, 10, 150, 35, 125 ) ) ) 00127 return 1; 00128 // Label it 00129 if ( !( cdText( im, 40, 125, "Color Index: 6" ) ) ) 00130 return 1; 00131 00132 // Set the fill color 00133 if ( !( cdSetFillColor( im, 7 ) ) ) 00134 return 1; 00135 // Draw a rectangle 00136 if ( !( cdRectangle( im, 10, 100, 35, 75 ) ) ) 00137 return 1; 00138 // Label it 00139 if ( !( cdText( im, 40, 75, "Color Index: 7" ) ) ) 00140 return 1; 00141 00142 // Set the fill color 00143 if ( !( cdSetFillColor( im, 8 ) ) ) 00144 return 1; 00145 // Draw a rectangle 00146 if ( !( cdRectangle( im, 210, 450, 235, 425 ) ) ) 00147 return 1; 00148 // Label it 00149 if ( !( cdText( im, 240, 425, "Color Index: 8" ) ) ) 00150 return 1; 00151 00152 // Set the fill color 00153 if ( !( cdSetFillColor( im, 9 ) ) ) 00154 return 1; 00155 // Draw a rectangle 00156 if ( !( cdRectangle( im, 210, 400, 235, 375 ) ) ) 00157 return 1; 00158 // Label it 00159 if ( !( cdText( im, 240, 375, "Color Index: 9" ) ) ) 00160 return 1; 00161 00162 // Set the fill color 00163 if ( !( cdSetFillColor( im, 10 ) ) ) 00164 return 1; 00165 // Draw a rectangle 00166 if ( !( cdRectangle( im, 210, 350, 235, 325 ) ) ) 00167 return 1; 00168 // Label it 00169 if ( !( cdText( im, 240, 325, "Color Index: 10" ) ) ) 00170 return 1; 00171 00172 // Set the fill color 00173 if ( !( cdSetFillColor( im, 11 ) ) ) 00174 return 1; 00175 // Draw a rectangle 00176 if ( !( cdRectangle( im, 210, 300, 235, 275 ) ) ) 00177 return 1; 00178 // Label it 00179 if ( !( cdText( im, 240, 275, "Color Index: 11" ) ) ) 00180 return 1; 00181 00182 // Set the fill color 00183 if ( !( cdSetFillColor( im, 12 ) ) ) 00184 return 1; 00185 // Draw a rectangle 00186 if ( !( cdRectangle( im, 210, 250, 235, 225 ) ) ) 00187 return 1; 00188 // Label it 00189 if ( !( cdText( im, 240, 225, "Color Index: 12" ) ) ) 00190 return 1; 00191 00192 // Set the fill color 00193 if ( !( cdSetFillColor( im, 13 ) ) ) 00194 return 1; 00195 // Draw a rectangle 00196 if ( !( cdRectangle( im, 210, 200, 235, 175 ) ) ) 00197 return 1; 00198 // Label it 00199 if ( !( cdText( im, 240, 175, "Color Index: 13" ) ) ) 00200 return 1; 00201 00202 // Set the fill color 00203 if ( !( cdSetFillColor( im, 14 ) ) ) 00204 return 1; 00205 // Draw a rectangle 00206 if ( !( cdRectangle( im, 210, 150, 235, 125 ) ) ) 00207 return 1; 00208 // Label it 00209 if ( !( cdText( im, 240, 125, "Color Index: 14" ) ) ) 00210 return 1; 00211 00212 // Set the fill color 00213 if ( !( cdSetFillColor( im, 15 ) ) ) 00214 return 1; 00215 // Draw a rectangle 00216 if ( !( cdRectangle( im, 210, 100, 235, 75 ) ) ) 00217 return 1; 00218 // Label it 00219 if ( !( cdText( im, 240, 75, "Color Index: 15" ) ) ) 00220 return 1; 00221 00222 // now put a little thing at the bottom of the picture 00223 if ( !cdText( im, 5, 10, "Colors allocated by cdImageColor16" ) ) 00224 return 1; 00225 00226 // now write the file out, lets call it color16.cgm 00227 outf = fopen( "color16.cgm", "wb" ); 00228 if ( !outf ) 00229 return 1; 00230 cdImageCgm( im, outf ); 00231 fclose( outf ); 00232 outf = 0; 00233 00234 // Remember to destroy the image when you are done 00235 cdImageDestroy( im ); 00236 im = 0; 00237 00238 printf( "CGM with 16 color colortable generated as color16.cgm\n" ); 00239 00240 return 0; 00241 }