00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <stdio.h>
00035 #include <math.h>
00036 #include <string.h>
00037
00038 #ifdef __STDC__
00039 #include <stdlib.h>
00040 #else
00041 extern char *getenv();
00042 #endif
00043
00044 #include "math_graphics.h"
00045 #include "periGif.h"
00046 #include "color.h"
00047 #include "sciprint.h"
00048 #include "../../src/gd/gd.h"
00049 #include "bcg.h"
00050
00051 #include "MALLOC.h"
00052
00053 #include "prompt.h"
00054 #include "Xcall1.h"
00055 #include "periScreen.h"
00056
00057
00058 #if defined(_MSC_VER)
00059 #define CoordModePrevious 1
00060 #define CoordModeOrigin 0
00061 #define GXclear 0
00062 #define GXand 1
00063 #define GXandReverse 2
00064 #define GXcopy 3
00065 #define GXandInverted 4
00066 #define GXnoop 5
00067 #define GXxor 6
00068 #define GXor 7
00069 #define GXnor 8
00070 #define GXequiv 9
00071 #define GXinvert 10
00072 #define GXorReverse 11
00073 #define GXcopyInverted 12
00074 #define GXorInverted 13
00075 #define GXnand 14
00076 #define GXset 15
00077 #endif
00078
00079 #define COLORMAP_WARNING "Warning: with GIF and PPM drivers, the size of colormaps should be less than %d. The resulting output may be inaccurate.\n"
00080
00081
00082 #define Char2Int(x) ( x & 0x000000ff )
00083 #if defined(__GNUC__) || defined(_MSC_VER)|| defined(__EDG__)
00084 static FILE *file= (FILE *) 0;
00085 #define FPRINTF(x) ( file != (FILE*) 0) ? fprintf x : 0
00086 #else
00087 #define FPRINTF(x) fprintf x
00088 static FILE *file= stdout ;
00089 #endif
00090
00091
00092
00093
00094 void C2F(WriteGeneric1Gif)();
00095 void C2F(xgetmarkGif)(integer *verbose, integer *symb, integer *narg, double *dummy);
00096 void C2F(xsetmarkGif)(integer *number, integer *size, integer *v3, integer *v4);
00097 void C2F(xgetfontGif)(integer *verbose, integer *font, integer *nargs, double *dummy);
00098 void C2F(xsetfontGif)(integer *fontid, integer *fontsize, integer *v3, integer *v4);
00099 void C2F(setdashstyleGif)(integer *value, integer *xx, integer *n);
00100 void C2F(Write2VectGif)();
00101 void C2F(WriteGenericGif)(char *string, integer nobj, integer sizeobj, integer *vx, integer *vy, integer sizev, integer flag, integer *fvect);
00102 void C2F(InitScilabGCGif)(integer *v1, integer *v2, integer *v3, integer *v4);
00103 void C2F(setforegroundGif)(integer *num, integer *v2, integer *v3, integer *v4);
00104 void C2F(ScilabGCGetorSetGif)(char *str, integer flag, integer *verbose, integer *x1, integer *x2, integer *x3, integer *x4, integer *x5, integer *x6, double *dx1);
00105 void C2F(setbackgroundGif)(integer *num, integer *v2, integer *v3, integer *v4);
00106 void C2F(set_cGif)(integer i);
00107 void C2F(idfromnameGif) (char *name1, integer *num);
00108 void C2F(getdashGif)(integer *verbose, integer *value, integer *narg, double *dummy);
00109
00110
00111 void C2F(setscilabFigureGif)(integer *v1,integer *v2,integer *v3,integer *v4,integer *v5,integer *v6,double *figure);
00112 void C2F(getscilabFigureGif)(integer *verbose, integer *x,integer *narg, double *figure);
00113 void C2F(setscilabVersionGif)(integer *vers, integer *v2, integer *v3, integer *v4);
00114 void C2F(getscilabVersionGif)(integer *verbose, integer *vers, integer *narg, double *dummy);
00115 void C2F(setscilabxgcGif)(integer *v1, integer *v2, integer *v3, integer *v4);
00116 void C2F(getscilabxgcGif)(integer *verbose, integer *x,integer *narg, double *dummy);
00117
00118
00119
00120
00121 static void C2F(displaysymbolsGif)(char *str, integer *n, integer *vx, integer *vy);
00122 extern int ReadbdfFont();
00123 extern void C2F(nues1)();
00124 extern int CheckScilabXgc();
00125
00126 static double *vdouble = 0;
00127
00128 static gdImagePtr GifIm = (gdImagePtr)0;
00129 static gdFontPtr GifFont;
00130 static int GifDashes[50], nGifDashes;
00131 static int col_white;
00132 static void FileInitGif __PARAMS((void));
00133 static void FileInitFromScreenGif __PARAMS((void));
00134 static int GifLineColor __PARAMS((void));
00135 static int GifPatternColor __PARAMS((int pat));
00136 static void LoadFontsGif(void);
00137 static void ColorInitGif(void);
00138 integer GetAluGif(void);
00139 void GetDriverName(char *DriverName);
00140 void C2F(set_dash_or_color_Gif)(integer *value, integer *v2, integer *v3, integer *v4);
00141 void C2F(set_line_style_Gif)(integer *value, integer *v2, integer *v3, integer *v4);
00142 void C2F(get_dash_or_color_Gif)(integer *verbose, integer *value, integer *narg, double *dummy);
00143 void C2F(get_dash_and_color_Gif)(integer *verbose, integer *value, integer *narg, double *dummy);
00144 void C2F(getcolormapsizeGif)(integer *v1, integer *v2, integer *v3, double *val);
00145 void C2F(setwwhowGif)(integer *verbose, integer *v2, integer *v3, integer *v4);
00146 void C2F(DispStringAngleGif)(integer *x0, integer *yy0, char *string, double *angle);
00147
00148 static void C2F(getcolormapGif) __PARAMS((integer *v1, integer *v2, integer *v3, double *val));
00149 static void C2F(setgccolormapGif) __PARAMS((struct BCG *Xgc,integer m, double *a, integer *v3));
00150
00151 extern int gdImageSymb(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color);
00154 struct BCG ScilabGCGif ;
00155
00156 static int col_index[gdMaxColors];
00157 static int fillpolylines_closeflag = 0;
00158
00159 extern char *getSCIpath();
00160
00161
00162
00163
00164
00167 void C2F(xselgraphicGif)(char *v1, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00168 {
00169 if (file != stdout && file != 0 ) {
00170 fclose(file);
00171 file=stdout;
00172 }
00173 if (GifIm != (gdImagePtr)0) {
00174 gdImageDestroy(GifIm);
00175 GifIm = (gdImagePtr)0;
00176 }
00177 }
00178
00181 void GetDriverName(char *DriverName)
00182 { integer *v2 = NULL;
00183 integer *v3 = NULL;
00184 integer *v4 = NULL;
00185 integer *v5 = NULL;
00186 integer *v6 = NULL;
00187 integer *v7 = NULL;
00188 double *dv1 = NULL;
00189 double *dv2 = NULL;
00190 double *dv3 = NULL;
00191 double *dv4 = NULL;
00192 GetDriver1(DriverName, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4);
00193 }
00194
00195 void C2F(xendgraphicGif)(void)
00196 {
00197 char DriverName[10];
00198 integer num;
00199 if (file != stdout && file != (FILE*) 0 && GifIm != (gdImagePtr)0) {
00200 num = ScilabGCGif.NumBackground;
00201 gdImageChangeColor(GifIm,col_white,col_index[num]);
00202 gdSetBackground(GifIm,col_index[num] );
00203 GetDriverName(DriverName);
00204 if (strcmp(DriverName,"GIF")==0)
00205 gdImageGif(GifIm, file);
00206 else if (strcmp(DriverName,"PPM")==0)
00207 gdImagePPM(GifIm, file);
00208 fclose(file);
00209 gdImageDestroy(GifIm);
00210 GifIm = (gdImagePtr)0;
00211 file=stdout;
00212 }
00213 }
00214
00215 void C2F(xendGif)(char *v1, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00216 {
00217 C2F(xendgraphicGif)();
00218 }
00219
00220
00224 void C2F(clearwindowGif)(char *v1, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00225 {
00226
00227
00228 int zero = 0;
00229 int color_white = col_index[ScilabGCGif.Numcolors+1];
00230
00231 if (GifIm == (gdImagePtr)0 ) {
00232 sciprint(" 1 xinit must be called before any action \r\n");
00233 return;
00234 }
00235
00236 gdImageFilledRectangle(GifIm, zero, zero, ScilabGCGif.CWindowWidth, ScilabGCGif.CWindowHeight,
00237 color_white);
00238
00240
00241 }
00242
00245 void C2F(xclickGif)(char *str, integer *ibutton, integer *xx1, integer *yy1, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00246 { }
00247
00248 void C2F(xclick_anyGif)(char *str, integer *ibutton, integer *xx1, integer *yy1, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00249 { }
00250
00251 void C2F(xgetmouseGif)(char *str, integer *ibutton, integer *xx1, integer *yy1, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00252 { }
00253
00256 void C2F(clearareaGif)(char *str, integer *x, integer *y, integer *w, integer *h, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00257 {
00258
00259 }
00260
00261
00262
00263
00264
00265
00266
00269 void C2F(getwindowposGif)(integer *verbose, integer *x, integer *narg, double *dummy)
00270 {
00271 *narg = 2;
00272 x[0]= x[1]=0;
00273 if (*verbose == 1)
00274 sciprint("\n CWindow position :%d,%d\r\n",(int)x[0],(int)x[1]);
00275 }
00276
00279 void C2F(setwindowposGif)(integer *x, integer *y, integer *v3, integer *v4)
00280 {
00281 }
00282
00285 void C2F(getwindowdimGif)(integer *verbose, integer *x, integer *narg, double *dummy)
00286 {
00287 *narg = 2;
00288 x[0]= ScilabGCGif.CWindowWidth;
00289 x[1]= ScilabGCGif.CWindowHeight;
00290 if (*verbose == 1)
00291 sciprint("\n CWindow dim :%d,%d\r\n",(int)x[0],(int)x[1]);
00292 }
00293
00296 void C2F(setwindowdimGif)(integer *x, integer *y, integer *v3, integer *v4)
00297 {
00298 integer x2[2],verbose,narg;
00299 integer old_num;
00300 integer i,j,col,v;
00301 double *val = NULL;
00302
00303
00304 gdImagePtr GifImOld = GifIm;
00305
00306 if (GifIm == (gdImagePtr)0 ) {
00307 sciprint(" 2 xinit must be called before any action \r\n");
00308 return;
00309 }
00310 GifIm = gdImageCreate(*x, *y);
00311
00312
00313
00314
00315
00316
00317 old_num = ScilabGCGif.Numcolors;
00318
00319 if((val=MALLOC((old_num*3)*sizeof(double)))==NULL)
00320 {
00321 sciprint("Error: can not allocate temporary coloramp\n");
00322 return;
00323 }
00324
00325 C2F(getcolormapGif)(&v,&v,&v,val);
00326
00327
00328 verbose = 0;
00329 C2F(getwindowdimGif)(&verbose,x2,&narg,vdouble);
00330
00331 ColorInitGif();
00332
00333 InitScilabGCGif(PI0,PI0,PI0,PI0);
00334
00335 ScilabGCGif.IDLastPattern = GREYNUMBER-1;
00336 ScilabGCGif.CurLineWidth=0 ;
00337 i=1;
00338 C2F(setthicknessGif)(&i,PI0,PI0,PI0);
00339 C2F(setalufunctionGif)("GXcopy");
00341 i=j= -1;
00342 C2F(unsetclipGif)(PI0,PI0,PI0,PI0);
00343 C2F(xsetfontGif)((i=2,&i),(j=1,&j),PI0,PI0);
00344 C2F(xsetmarkGif)((i=0,&i),(j=0,&j),PI0,PI0);
00346 ScilabGCGif.CurVectorStyle = CoordModeOrigin ;
00347
00348 ScilabGCGif.CurColorStatus =0;
00349 C2F(setpatternGif)((i=1,&i),PI0,PI0,PI0);
00350 C2F(setdashGif)((i=1,&i),PI0,PI0,PI0);
00351
00352
00353 ScilabGCGif.CurColorStatus = 1 ;
00354 C2F(setpatternGif)((i=1,&i),PI0,PI0,PI0);
00355 C2F(setforegroundGif)((i=ScilabGCGif.NumForeground+1,&i),PI0,PI0,PI0);
00356 C2F(setbackgroundGif)((i=ScilabGCGif.NumForeground+2,&i),PI0,PI0,PI0);
00357 C2F(sethidden3dGif)((i=4,&i),PI0,PI0,PI0);
00358
00359 getcolordef(&col);
00364 ScilabGCGif.CurColorStatus = (col == 1) ? 0: 1;
00365 C2F(usecolorGif)(&col,PI0,PI0,PI0);
00366 if (col == 1) ScilabGCGif.IDLastPattern = ScilabGCGif.Numcolors - 1;
00367 strcpy(ScilabGCGif.CurNumberDispFormat,"%-5.2g");
00368
00369 C2F(setpatternGif)((i=ScilabGCGif.NumForeground+1,&i),PI0,PI0,PI0);
00370 if (ScilabGCGif.CurColorStatus == 1)
00371 {
00372 ScilabGCGif.IDLastPattern = ScilabGCGif.Numcolors - 1;
00373 }
00374
00375
00376 C2F(setgccolormapGif)(&ScilabGCGif,old_num, val, &v);
00377
00378 FREE(val); val = (double *) NULL;
00379
00380
00381 gdImageFilledRectangle(GifIm, 0, 0, (*x) - 1, (*y) - 1, col_white);
00382
00383 gdImageCopyResized(GifIm, GifImOld, 0, 0, 0, 0, *x, *y,
00384 ScilabGCGif.CWindowWidth,
00385 ScilabGCGif.CWindowHeight);
00386 gdImageDestroy(GifImOld);
00387 ScilabGCGif.CWindowWidth = *x;
00388 ScilabGCGif.CWindowHeight = *y;
00389 }
00390
00393 void C2F(setcurwinGif)(integer *intnum, integer *v2, integer *v3, integer *v4)
00394 {
00395 ScilabGCGif.CurWindow = *intnum;
00396 }
00397
00400 void C2F(getcurwinGif)(integer *verbose, integer *intnum, integer *narg, double *dummy)
00401 {
00402 *narg =1 ;
00403 *intnum = ScilabGCGif.CurWindow ;
00404 if (*verbose == 1)
00405 sciprint("\nJust one graphic page at a time ");
00406 }
00407
00410 void C2F(setclipGif)(integer *x, integer *y, integer *w, integer *h)
00411 {
00412 if (GifIm == (gdImagePtr)0 ) {
00413 sciprint(" 3 xinit must be called before any action \r\n");
00414 return;
00415 }
00416 ScilabGCGif.ClipRegionSet = 1;
00417 ScilabGCGif.CurClipRegion[0]= *x;
00418 ScilabGCGif.CurClipRegion[1]= *y;
00419 ScilabGCGif.CurClipRegion[2]= *w;
00420 ScilabGCGif.CurClipRegion[3]= *h;
00421 gdSetClipping(GifIm,*x,*y,*x+*w,*y+*h);
00422
00423 }
00424
00427 void C2F(unsetclipGif)(integer *v1, integer *v2, integer *v3, integer *v4)
00428 {
00429 if (GifIm == (gdImagePtr)0 ) {
00430 sciprint(" 4 xinit must be called before any action \r\n");
00431 return;
00432 }
00433 ScilabGCGif.ClipRegionSet = 0;
00434 ScilabGCGif.CurClipRegion[0]= -1;
00435 ScilabGCGif.CurClipRegion[1]= -1;
00436 ScilabGCGif.CurClipRegion[2]= 200000;
00437 ScilabGCGif.CurClipRegion[3]= 200000;
00438 gdUnsetClipping(GifIm);
00439
00440 }
00441
00444 void C2F(getclipGif)(integer *verbose, integer *x, integer *narg, double *dummy)
00445 {
00446 x[0] = ScilabGCGif.ClipRegionSet;
00447 if ( x[0] == 1)
00448 {
00449 *narg = 5;
00450 x[1] =ScilabGCGif.CurClipRegion[0];
00451 x[2] =ScilabGCGif.CurClipRegion[1];
00452 x[3] =ScilabGCGif.CurClipRegion[2];
00453 x[4] =ScilabGCGif.CurClipRegion[3];
00454 }
00455 else *narg = 1;
00456 if (*verbose == 1)
00457 {
00458 if (ScilabGCGif.ClipRegionSet == 1)
00459 sciprint("\nThere's a Clip Region :x:%d,y:%d,w:%d,h:%d\r\n",
00460 ScilabGCGif.CurClipRegion[0],
00461 ScilabGCGif.CurClipRegion[1],
00462 ScilabGCGif.CurClipRegion[2],
00463 ScilabGCGif.CurClipRegion[3]);
00464 else
00465 sciprint("\nNo Clip Region");
00466 }
00467 }
00468
00469
00470
00471
00472
00473
00474
00475
00476 void C2F(setabsourelGif)(integer *num, integer *v2, integer *v3, integer *v4)
00477 {
00478 if (*num == CoordModeOrigin )
00479 ScilabGCGif.CurVectorStyle = CoordModeOrigin;
00480 else
00481 ScilabGCGif.CurVectorStyle = CoordModePrevious ;
00482 }
00483
00486 void C2F(getabsourelGif)(integer *verbose, integer *num, integer *narg, double *dummy)
00487 {
00488 *narg = 1;
00489 *num = ScilabGCGif.CurVectorStyle ;
00490 if (*verbose == 1)
00491 {
00492 if (ScilabGCGif.CurVectorStyle == CoordModeOrigin)
00493 sciprint("\nTrace Absolu");
00494 else
00495 sciprint("\nTrace Relatif");
00496 }
00497 }
00498
00499
00500 void C2F(setalufunctionGif)(char *string)
00501 {
00502 integer value;
00503 if (GifIm == (gdImagePtr)0 ) {
00504 sciprint(" 5 xinit must be called before any action \r\n");
00505 return;
00506 }
00507 C2F(idfromnameGif)(string,&value);
00508 if ( value != -1) {
00509 ScilabGCGif.CurDrawFunction = value;
00510 gdSetAlu(GifIm, value);
00511
00512 }
00513 }
00514
00517 struct alinfo {
00518 char *name;
00519 char id;
00520 char *info;} AluStrucGif[] =
00521 {
00522 {"GXclear" ,GXclear," 0 "},
00523 {"GXand" ,GXand," src AND dst "},
00524 {"GXandReverse" ,GXandReverse," src AND NOT dst "},
00525 {"GXcopy" ,GXcopy," src "},
00526 {"GXandInverted" ,GXandInverted," NOT src AND dst "},
00527 {"GXnoop" ,GXnoop," dst "},
00528 {"GXxor" ,GXxor," src XOR dst "},
00529 {"GXor" ,GXor," src OR dst "},
00530 {"GXnor" ,GXnor," NOT src AND NOT dst "},
00531 {"GXequiv" ,GXequiv," NOT src XOR dst "},
00532 {"GXinvert" ,GXinvert," NOT dst "},
00533 {"GXorReverse" ,GXorReverse," src OR NOT dst "},
00534 {"GXcopyInverted" ,GXcopyInverted," NOT src "},
00535 {"GXorInverted" ,GXorInverted," NOT src OR dst "},
00536 {"GXnand" ,GXnand," NOT src OR NOT dst "},
00537 {"GXset" ,GXset," 1 "}
00538 };
00539
00540 void C2F(idfromnameGif)(char *name1, integer *num)
00541 {integer i;
00542 *num = -1;
00543 for ( i =0 ; i < 16;i++)
00544 if (strcmp(AluStrucGif[i].name,name1)== 0)
00545 *num=AluStrucGif[i].id;
00546 if (*num == -1 )
00547 {
00548 sciprint("\n Use the following keys :");
00549 for ( i=0 ; i < 16 ; i++)
00550 sciprint("\nkey %s -> %s\r\n",AluStrucGif[i].name,
00551 AluStrucGif[i].info);
00552 }
00553 }
00554
00555
00556 void C2F(setalufunction1Gif)(integer *num, integer *v2, integer *v3, integer *v4)
00557 {
00558 integer value;
00559
00560 if (GifIm == (gdImagePtr)0 ) {
00561 sciprint(" 6 xinit must be called before any action \r\n");
00562 return;
00563 }
00564 value=AluStrucGif[Min(15,Max(0,*num))].id;
00565 if ( value != -1)
00566 {
00567 ScilabGCGif.CurDrawFunction = value;
00568 gdSetAlu(GifIm, value);
00569 }
00570 }
00571
00574 void C2F(getalufunctionGif)(integer *verbose, integer *value, integer *narg, double *dummy)
00575 {
00576 *narg =1 ;
00577 *value = ScilabGCGif.CurDrawFunction ;
00578 if (*verbose ==1 )
00579 { sciprint("\nThe Alufunction is %s -> <%s>\r\n",
00580 AluStrucGif[*value].name,
00581 AluStrucGif[*value].info);}
00582 }
00583
00584 integer GetAluGif(void)
00585 {
00586 return ScilabGCGif.CurDrawFunction;
00587 }
00591 #define Thick_prec 5
00592
00593 void C2F(setthicknessGif)(integer *value, integer *v2, integer *v3, integer *v4)
00594 {
00595 ScilabGCGif.CurLineWidth =Max(0, *value);
00596 }
00597
00600 void C2F(getthicknessGif)(integer *verbose, integer *value, integer *narg, double *dummy)
00601 {
00602 *narg =1 ;
00603 *value = ScilabGCGif.CurLineWidth ;
00604 if (*verbose ==1 )
00605 sciprint("\nLine Width:%d\r\n",
00606 ScilabGCGif.CurLineWidth ) ;
00607 }
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617 void C2F(setpatternGif)(integer *num, integer *v2, integer *v3, integer *v4)
00618 {
00619 integer i ;
00620 if ( ScilabGCGif.CurColorStatus ==1)
00621 {
00622 i= Max(0,Min(*num-1,ScilabGCGif.Numcolors+1));
00623 ScilabGCGif.CurColor = i ;
00624 C2F(set_cGif)(i);
00625 }
00626 else
00627 {
00628
00629
00630 if ( *num-1 > GREYNUMBER -1 )
00631 i=0;
00632 else
00633 i= Max(0,Min(*num-1,GREYNUMBER-1));
00634 ScilabGCGif.CurPattern = i;
00635
00636
00637
00638
00639 }
00640 }
00641
00644 void C2F(getpatternGif)(integer *verbose, integer *num, integer *narg, double *dummy)
00645 {
00646
00647 *narg=1;
00648 if ( ScilabGCGif.CurColorStatus ==1)
00649 {
00650 *num = ScilabGCGif.CurColor +1 ;
00651 if (*verbose == 1)
00652 sciprint("\n Color : %d\r\n",*num);
00653 }
00654 else
00655 {
00656 *num = ScilabGCGif.CurPattern +1 ;
00657 if (*verbose == 1)
00658 sciprint("\n Pattern : %d\r\n",*num);
00659 }
00660 }
00661
00664 void C2F(getlastGif)(integer *verbose, integer *num, integer *narg, double *dummy)
00665 {
00666 *num = ScilabGCGif.IDLastPattern +1 ;
00667 if (*verbose==1)
00668 sciprint("\n Id of White Pattern %d\r\n",(int)*num);
00669 *narg=1;
00670 }
00671
00676 #define MAXDASH 6
00677
00678 static integer DashTabGif[MAXDASH][4] = {
00679 {2,5,2,5}, {7,2,7,2}, {2,2,2,2}, {7,2,2,2},
00680 {11,3,2,3}, {11,3,5,3}};
00681
00682
00683 void C2F(set_dash_or_color_Gif)(integer *value, integer *v2, integer *v3, integer *v4)
00684 {
00685 static integer maxdash = 6, l2=4,l3 ;
00686
00687 if ( ScilabGCGif.CurColorStatus == 1)
00688 {
00689 int i;
00690 i= Max(0,Min(*value-1,ScilabGCGif.Numcolors+1));
00691 ScilabGCGif.CurColor =i;
00692 C2F(set_cGif)(i);
00693 }
00694 else
00695 {
00696 l3 = Max(0,Min(maxdash - 1,*value - 1));
00697 C2F(setdashstyleGif)(&l3,DashTabGif[l3],&l2);
00698 ScilabGCGif.CurDashStyle = l3;
00699 }
00700 }
00701 void C2F(setdashGif)(integer *value, integer *v2, integer *v3, integer *v4)
00702 {
00703 static integer maxdash = 6, l2=4,l3 ;
00704 l3 = Max(0,Min(maxdash - 1,*value - 1));
00705 C2F(setdashstyleGif)(&l3,DashTabGif[l3],&l2);
00706 ScilabGCGif.CurDashStyle = l3;
00707 }
00708
00709 static int GifLineColor (void)
00710 {
00711 int i, c = col_index[ScilabGCGif.CurColor];
00712
00713 if (GifIm == (gdImagePtr)0 ) {
00714 sciprint(" 7 xinit must be called before any action \r\n");
00715 return 0;
00716 }
00717 if (c < 0) c = 0;
00718 if (ScilabGCGif.CurDashStyle == 0) return c;
00719 for (i = 0; i < nGifDashes; i++) {
00720 if (GifDashes[i] != gdTransparent) GifDashes[i] = c;
00721 }
00722 gdImageSetStyle(GifIm, GifDashes, nGifDashes);
00723 return gdStyled;
00724 }
00725
00726 static int GifPatternColor(int pat)
00727 {
00728 int c = col_index[pat - 1];
00729 if (c < 0) c = 0;
00730 return c;
00731 }
00732
00738 void C2F(setdashstyleGif)(integer *value, integer *xx, integer *n)
00739 {
00740 int i, j, cn, c1, c = col_index[ScilabGCGif.CurColor];
00741
00742 if (GifIm == (gdImagePtr)0 ) {
00743 sciprint(" 8 xinit must be called before any action \r\n");
00744 return;
00745 }
00746 if (*value != 0) {
00747 cn = 0;
00748 c1 = c;
00749 for (i = 0; i < *n; i++) {
00750 for (j = 0; j < xx[i]; j++) {
00751 GifDashes[cn] = c1;
00752 cn++;
00753 }
00754 if (c1 != gdTransparent) c1 = gdTransparent;
00755 else c1 = c;
00756 }
00757 nGifDashes = cn;
00758 gdImageSetStyle(GifIm, GifDashes, nGifDashes);
00759 } else {
00760 nGifDashes = 0;
00761 }
00762 }
00763 static void C2F(set_dash_and_color_Gif)(integer *value, integer *v2, integer *v3, integer *v4)
00764 {
00765 C2F(setdashGif)(value, v2, v3, v4);
00766 C2F(setpatternGif)(value+6, v2, v3, v4);
00767 }
00768
00769 void C2F(set_line_style_Gif)(integer *value, integer *v2, integer *v3, integer *v4)
00770 {
00771 integer j;
00772 if (ScilabGCGif.CurColorStatus == 0)
00773 C2F(setdashGif)(value,PI0,PI0,PI0);
00774 else {
00775 j= ScilabGCGif.CurDashStyle + 1;
00776 C2F(setdashGif)(&j,PI0,PI0,PI0);
00777 C2F(setpatternGif)(value,PI0,PI0,PI0);
00778 }
00779 }
00780
00781
00783
00784 void C2F(get_dash_or_color_Gif)(integer *verbose, integer *value, integer *narg, double *dummy)
00785 {integer i ;
00786 *narg =1 ;
00787 if ( ScilabGCGif.CurColorStatus ==1)
00788 {
00789 *value= ScilabGCGif.CurColor + 1;
00790 if (*verbose == 1) sciprint("Color %d",(int)*value);
00791 return;
00792 }
00793 *value=ScilabGCGif.CurDashStyle+1;
00794 if ( *value == 1)
00795 { if (*verbose == 1) sciprint("\nLine style = Line Solid");}
00796 else
00797 {
00798 value[1]=4;
00799 *narg = value[1]+2;
00800 for ( i =0 ; i < value[1]; i++) value[i+2]=DashTabGif[*value-1][i];
00801 if (*verbose ==1 )
00802 {
00803 sciprint("\nDash Style %d:<",(int)*value);
00804 for ( i =0 ; i < value[1]; i++)
00805 sciprint("%d ",(int)value[i+2]);
00806 sciprint(">\n");
00807 }
00808 }
00809 }
00810
00811 void C2F(getdashGif)(integer *verbose, integer *value, integer *narg, double *dummy)
00812 {integer i ;
00813 *narg =1 ;
00814 *value=ScilabGCGif.CurDashStyle+1;
00815 if ( *value == 1)
00816 { if (*verbose == 1) sciprint("\nLine style = Line Solid");}
00817 else
00818 {
00819 value[1]=4;
00820 *narg = value[1]+2;
00821 for ( i =0 ; i < value[1]; i++) value[i+2]=DashTabGif[*value-1][i];
00822 if (*verbose ==1 )
00823 {
00824 sciprint("\nDash Style %d:<",(int)*value);
00825 for ( i =0 ; i < value[1]; i++)
00826 sciprint("%d ",(int)value[i+2]);
00827 sciprint(">\n");
00828 }
00829 }
00830 }
00831 void C2F(get_dash_and_color_Gif)(integer *verbose, integer *value, integer *narg, double *dummy)
00832 {
00833
00834 C2F(getdashGif)(verbose, value, narg,dummy);
00835 C2F(getpatternGif)(verbose, value+6, narg,dummy);
00836 *narg = 6;
00837 }
00838
00839 void C2F(usecolorGif)(integer *num, integer *v2, integer *v3, integer *v4)
00840 {
00841 integer i;
00842 i = Min(Max(*num,0),1);
00843 if ( ScilabGCGif.CurColorStatus != (int)i)
00844 {
00845 if (ScilabGCGif.CurColorStatus == 1)
00846 {
00847
00848
00849 ScilabGCGif.CurColorStatus = 1;
00850 C2F(setpatternGif)((i=1,&i),PI0,PI0,PI0);
00851
00852 ScilabGCGif.CurColorStatus = 0;
00853 i= ScilabGCGif.CurPattern+1;
00854 C2F(setpatternGif)(&i,PI0,PI0,PI0);
00855 i= ScilabGCGif.CurDashStyle+1;
00856 C2F(setdashGif)(&i,PI0,PI0,PI0);
00857 ScilabGCGif.IDLastPattern = GREYNUMBER - 1;
00858 }
00859 else
00860 {
00861
00862
00863
00864 ScilabGCGif.CurColorStatus = 0;
00865 C2F(setpatternGif)((i=1,&i),PI0,PI0,PI0);
00866 C2F(setdashGif)((i=1,&i),PI0,PI0,PI0);
00867
00868 ScilabGCGif.CurColorStatus = 1;
00869 i= ScilabGCGif.CurColor+1;
00870 C2F(setpatternGif)(&i,PI0,PI0,PI0);
00871 ScilabGCGif.IDLastPattern = ScilabGCGif.Numcolors - 1;
00872 }
00873 }
00874 }
00875
00876
00877 void C2F(getusecolorGif)(integer *verbose, integer *num, integer *narg, double *dummy)
00878 {
00879 *num = ScilabGCGif.CurColorStatus;
00880 if (*verbose == 1)
00881 sciprint("\n Use color %d\r\n",(int)*num);
00882 *narg=1;
00883 }
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902 void setcolormapgGif(struct BCG *Xgc,integer *v1,integer *v2, double *a, integer *v3);
00903
00904 void C2F(setgccolormapGif)(struct BCG *Xgc,integer m, double *a, integer *v3)
00905 {
00906 int i,j,r,g,b,c,ierr,m1,mm;
00907 double *cmap;
00908 int *ind,i1;
00909 int old_white,old_black;
00910 if (GifIm == (gdImagePtr)0 ) {
00911 sciprint(" 9 xinit must be called before any action \r\n");
00912 *v3 = 1;
00913 return;
00914 }
00915
00916
00917 for (i = 0; i < m; i++) {
00918 if (a[i] < 0 || a[i] > 1 || a[i+m] < 0 || a[i+m] > 1 ||
00919 a[i+2*m] < 0 || a[i+2*m]> 1) {
00920 sciprint("RGB values must be between 0 and 1\n");
00921 *v3 = 1;
00922 return;
00923 }
00924 }
00925 old_white=col_index[Xgc->Numcolors+1];
00926 old_black=col_index[Xgc->Numcolors];
00927
00928 for ( i=0; i < GifIm->colorsTotal; i++)
00929 gdImageColorDeallocate(GifIm, i);
00930 for ( i=0;i < Xgc->Numcolors+2; i++)
00931 col_index[i] = -1;
00932
00933 if (m>gdMaxColors-3)
00934 {
00935
00936 sciprint(COLORMAP_WARNING,gdMaxColors-2) ;
00937 m1 = gdMaxColors-2;
00938 if ( (cmap = (double*) MALLOC(3*m1 * sizeof(double)))== NULL) {
00939 sciprint("Not enough memory\n");
00940 *v3 = 1;
00941 return;
00942 }
00943 if ( (ind = (int*) MALLOC(m * sizeof(int)))== NULL) {
00944 sciprint("Not enough memory\n");
00945 FREE(cmap);
00946 *v3 = 1;
00947 return;
00948 }
00949
00950 C2F(nues1)(a,&m,cmap,&m1,ind,&ierr);
00951
00952 Xgc->Numcolors = m;
00953 for ( i=0; i < Xgc->Numcolors; i++) {
00954 i1 = ind[i] - 1;
00955 r=(int)(cmap[i1] * 255);
00956 g=(int)(cmap[i1 + m1] * 255);
00957 b=(int)(cmap[i1 + 2*m1] * 255);
00958 if (r==255 && g==255 && b==255) {
00959
00960 r=254;g=254;b=254; }
00961
00962
00963 c = gdImageColorAllocate(GifIm,r,g,b);
00964 col_index[i] = c;
00965 }
00966 FREE(ind);
00967 FREE(cmap);
00968 }
00969 else {
00970
00971 Xgc->Numcolors = m;
00972 for ( i=0; i < Xgc->Numcolors; i++) {
00973 r=(int)(a[i] * 255);
00974 g=(int)(a[i + m] * 255);
00975 b=(int)(a[i + 2*m] * 255);
00976 if (r==255&&g==255&&b==255) {
00977
00978 r=254;g=254;b=254; }
00979
00980
00981 c = gdImageColorAllocate(GifIm,r,g,b);
00982 col_index[i] = c;
00983 }
00984 }
00985
00986
00987
00988 c = gdImageColorAllocate(GifIm,0,0,0);
00989 col_index[m]=c;
00990
00991
00992 c = gdImageColorAllocate(GifIm,255,255,255);
00993 col_index[m+1]=c;
00994 col_white=c;
00995
00996 Xgc->IDLastPattern = m - 1;
00997 Xgc->NumForeground = m;
00998 Xgc->NumBackground = m + 1;
00999
01000
01001 C2F(usecolorGif)((i=1,&i) ,PI0,PI0,PI0);
01002 C2F(setalufunction1Gif)((i=3,&i),PI0,PI0,PI0);
01003 C2F(setpatternGif)((i=Xgc->NumForeground+1,&i),PI0,PI0,PI0);
01004
01005
01006
01007
01008 for (i=0;i<Xgc->CWindowWidth;i++) {
01009 for (j=0;j<Xgc->CWindowHeight;j++) {
01010 c=gdImageGetPixel(GifIm, i, j);
01011 if(c==old_white)
01012 gdImageSetPixel(GifIm, i, j,col_index[m+1]);
01013 else if (c==old_black)
01014 gdImageSetPixel(GifIm, i, j,col_index[m]);
01015 }
01016 }
01017
01018
01019
01020
01021 FREE(Xgc->Red);
01022 FREE(Xgc->Green);
01023 FREE(Xgc->Blue);
01024
01025
01026 mm = m;
01027 if (!(Xgc->Red = (float *) MALLOC(mm*sizeof(float)))) {
01028 sciprint("XgcAllocColors: unable to alloc\n");
01029 return;
01030 }
01031 if (!(Xgc->Green = (float *) MALLOC(mm*sizeof(float)))) {
01032 sciprint("XgcAllocColors: unable to alloc\n");
01033 FREE(Xgc->Red);
01034 return;
01035 }
01036 if (!(Xgc->Blue = (float *) MALLOC(mm*sizeof(float)))) {
01037 sciprint("XgcAllocColors: unable to alloc\n");
01038 FREE(Xgc->Red);
01039 FREE(Xgc->Green);
01040 return;
01041 }
01042
01043 for(i=0;i<m;i++){
01044 Xgc->Red[i] = (float)a[i];
01045 Xgc->Green[i] = (float)a[i+m];
01046 Xgc->Blue[i] = (float)a[i+2*m];
01047 }
01048
01049
01050
01051
01052
01053
01054
01055
01056 }
01057
01058
01059
01060
01061
01062
01063 void C2F(setcolormapGif)(integer *v1, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, double *a)
01064 {
01065 int m;
01066
01067 *v3 = 0;
01068
01069 if (*v2 != 3 || *v1 < 0 ) {
01070 sciprint("Colormap must be a m x 3 array \n");
01071 *v3 = 1;
01072 return;
01073 }
01074 if (GifIm == (gdImagePtr)0 ) {
01075 sciprint(" 10 xinit must be called before any action \r\n");
01076 *v3 = 1;
01077 return;
01078 }
01079 m = *v1;
01080
01081 C2F(setgccolormapGif)(&ScilabGCGif,m, a, v3);
01082 }
01083
01084 void C2F(getcolormapsizeGif)(integer *v1, integer *v2, integer *v3, double *val)
01085 {
01086 if (GifIm == (gdImagePtr)0 ) {
01087 sciprint(" 10.1 xinit must be called before any action \r\n");
01088 return;
01089 }
01090
01091 *v2 = ScilabGCGif.Numcolors;
01092 }
01093
01094
01095
01096 void C2F(getcolormapGif)(integer *v1, integer *v2, integer *v3, double *val)
01097 {
01098 int m;
01099 int i;
01100 *v3 = 0;
01101
01102 if (GifIm == (gdImagePtr)0 ) {
01103 sciprint(" 10.1 xinit must be called before any action \r\n");
01104 return;
01105 }
01106
01107 m = ScilabGCGif.Numcolors;
01108
01109 for (i = 0; i < m; i++) {
01110 val[i] = (double)ScilabGCGif.Red[i];
01111 val[i+m] = (double)ScilabGCGif.Green[i];
01112 val[i+2*m] = (double)ScilabGCGif.Blue[i];
01113 }
01114 }
01115
01116
01117
01118 void setcolormapgGif(struct BCG *Xgc,integer *m,integer *v2, double *a, integer *v3)
01119 {
01120 C2F(setgccolormapGif)(Xgc,*m, a, v3);
01121 }
01122
01123
01128 static void ColorInitGif(void)
01129 {
01130 int m,i,r,g,b,c;
01131
01132 if (GifIm == (gdImagePtr)0 ) {
01133 sciprint(" 11 xinit must be called before any action \r\n");
01134 return;
01135 }
01136
01137 m = DEFAULTNUMCOLORS;
01138 ScilabGCGif.Numcolors = m;
01139 for ( i=0; i < ScilabGCGif.Numcolors; i++) {
01140 r = default_colors[3 * i];
01141 g = default_colors[3 * i + 1];
01142 b = default_colors[3 * i + 2];
01143 if (r==255&&g==255&&b==255) {
01144
01145 r=254;g=254;b=254; }
01146 col_index[i] = gdImageColorAllocate(GifIm,r,g,b);
01147 }
01148
01149
01150
01151 c = gdImageColorAllocate(GifIm,0,0,0);
01152 col_index[m]=c;
01153
01154
01155 c = gdImageColorAllocate(GifIm,255,255,255);
01156 col_index[m+1]=c;
01157 col_white=col_index[m+1];
01158 ScilabGCGif.NumForeground = m;
01159 ScilabGCGif.NumBackground = m + 1;
01160 C2F(setpatternGif)((i=ScilabGCGif.NumForeground+1,&i),PI0,PI0,PI0);
01161 if (ScilabGCGif.CurColorStatus == 1)
01162 {
01163 ScilabGCGif.IDLastPattern = ScilabGCGif.Numcolors - 1;
01164 }
01165
01166 }
01167
01168
01169 void C2F(set_cGif)(integer i)
01170 {
01171 integer j;
01172 j=Max(Min(i,ScilabGCGif.Numcolors+1),0);
01173
01174 }
01175
01176
01179 void C2F(setbackgroundGif)(integer *num, integer *v2, integer *v3, integer *v4)
01180 {
01181 if (ScilabGCGif.CurColorStatus == 1)
01182 {
01183 ScilabGCGif.NumBackground = Max(0,Min(*num - 1,ScilabGCGif.Numcolors + 2));
01184 }
01185 }
01186
01187 void C2F(getbackgroundGif)(integer *verbose, integer *num, integer *narg, double *dummy)
01188 {
01189 *narg=1;
01190 if ( ScilabGCGif.CurColorStatus == 1 )
01191 {
01192 *num = ScilabGCGif.NumBackground + 1;
01193 }
01194 else
01195 {
01196 *num = 1;
01197 }
01198 if (*verbose == 1)
01199 sciprint("\n Background : %d\r\n",*num);
01200 }
01201
01202
01205 void C2F(setforegroundGif)(integer *num, integer *v2, integer *v3, integer *v4)
01206 {
01207 if (ScilabGCGif.CurColorStatus == 1)
01208 {
01209 ScilabGCGif.NumForeground = Max(0,Min(*num - 1,ScilabGCGif.Numcolors + 1));
01210 }
01211 }
01212
01213 void C2F(getforegroundGif)(integer *verbose, integer *num, integer *narg, double *dummy)
01214 {
01215 *narg=1;
01216 if ( ScilabGCGif.CurColorStatus == 1 )
01217 {
01218 *num = ScilabGCGif.NumForeground + 1;
01219 }
01220 else
01221 {
01222 *num = 1;
01223 }
01224 if (*verbose == 1)
01225 sciprint("\n Foreground : %d\r\n",*num);
01226 }
01227
01228
01229
01232 void C2F(sethidden3dGif)(integer *num, integer *v2, integer *v3, integer *v4)
01233 {
01234 if (ScilabGCGif.CurColorStatus == 1)
01235 {
01236
01237
01238 ScilabGCGif.NumHidden3d = Max(-2,Min(*num - 1,ScilabGCGif.Numcolors + 1));
01239 }
01240 }
01241
01242 void C2F(gethidden3dGif)(integer *verbose, integer *num, integer *narg, double *dummy)
01243 {
01244 *narg=1;
01245 if ( ScilabGCGif.CurColorStatus == 1 )
01246 {
01247 *num = ScilabGCGif.NumHidden3d + 1;
01248 }
01249 else
01250 {
01251 *num = 1;
01252 }
01253 if (*verbose == 1)
01254 sciprint("\n Hidden3d : %d\r\n",*num);
01255 }
01256
01257
01258
01259
01260
01261
01262
01263
01264 void C2F(semptyGif)(integer *v1, integer *v2, integer *v3, integer *v4)
01265 {
01266
01267 }
01268 void C2F(setwwhowGif)(integer *verbose, integer *v2, integer *v3, integer *v4)
01269 {
01270
01271 }
01272
01273 void C2F(gemptyGif)(integer *verbose, integer *v2, integer *v3, double *dummy)
01274 {
01275 if ( *verbose ==1 ) sciprint("\n No operation ");
01276 }
01277
01278 #define NUMSETFONC 31
01279
01282 struct bgc { char *name ;
01283 void (*setfonc )() ;
01284 void (*getfonc )() ;}
01285 ScilabGCTabGif[] = {
01286 {"alufunction",C2F(setalufunction1Gif),C2F(getalufunctionGif)},
01287 {"background",C2F(setbackgroundGif),C2F(getbackgroundGif)},
01288 {"clipoff",C2F(unsetclipGif),C2F(getclipGif)},
01289 {"clipping",C2F(setclipGif),C2F(getclipGif)},
01290 {"cmap_size",C2F(semptyGif),C2F(getcolormapsizeGif)},
01291 {"color",C2F(setpatternGif),C2F(getpatternGif)},
01292 {"colormap",C2F(setcolormapGif),C2F(getcolormapGif)},
01293 {"dashes",C2F(set_dash_or_color_Gif),C2F(get_dash_or_color_Gif)},
01294 {"default",InitScilabGCGif, C2F(gemptyGif)},
01295 {"figure",C2F(setscilabFigureGif),C2F(getscilabFigureGif)},
01296 {"font",C2F(xsetfontGif),C2F(xgetfontGif)},
01297 {"foreground",C2F(setforegroundGif),C2F(getforegroundGif)},
01298 {"gc",C2F(semptyGif),C2F(getscilabxgcGif)},
01299 {"gccolormap",C2F(setgccolormapGif),C2F(gemptyGif)},
01300 {"hidden3d",C2F(sethidden3dGif),C2F(gethidden3dGif)},
01301 {"lastpattern",C2F(semptyGif),C2F(getlastGif)},
01302 {"line mode",C2F(setabsourelGif),C2F(getabsourelGif)},
01303 {"line style",C2F(setdashGif),C2F(getdashGif)},
01304 {"mark",C2F(xsetmarkGif),C2F(xgetmarkGif)},
01305 {"pattern",C2F(setpatternGif),C2F(getpatternGif)},
01306 {"pixmap",C2F(semptyGif),C2F(gemptyGif)},
01307 {"thickness",C2F(setthicknessGif),C2F(getthicknessGif)},
01308 {"use color",C2F(usecolorGif),C2F(getusecolorGif)},
01309 {"viewport",C2F(semptyGif),C2F(gemptyGif)},
01310 {"wdim",C2F(setwindowdimGif),C2F(getwindowdimGif)},
01311 {"white",C2F(semptyGif),C2F(getlastGif)},
01312 {"window",C2F(setcurwinGif),C2F(getcurwinGif)},
01313 {"wpdim",C2F(semptyGif),C2F(gemptyGif)},
01314 {"wpos",C2F(setwindowposGif),C2F(getwindowposGif)},
01315 {"wresize",C2F(semptyGif),C2F(gemptyGif)},
01316 {"wshow",C2F(setwwhowGif),C2F(gemptyGif)},
01317 {"wwpc",C2F(semptyGif),C2F(gemptyGif)}
01318 };
01319
01320 #ifdef lint
01321
01322
01323
01324 static test(str,flag,verbose,x1,x2,x3,x4,x5)
01325 char str[];
01326 integer flag ;
01327 integer *verbose,*x1,*x2,*x3,*x4,*x5;
01328 {
01329 double *dv;
01330 C2F(setalufunction1Gif)(x1,x2,x3,x4);C2F(getalufunctionGif)(verbose,x1,x2,dv);
01331 C2F(setclipGif)(x1,x2,x3,x4);C2F(getclipGif)(verbose,x1,x2,dv);
01332 C2F(setdashGif)(x1,x2,x3,x4);C2F(getdashGif)(verbose,x1,x2,dv);
01333 InitScilabGCGif(x1,x2,x3,x4); C2F(gemptyGif)(verbose,x1,x2,dv);
01334 C2F(xsetfontGif)(x1,x2,x3,x4);C2F(xgetfontGif)(verbose,x1,x2,dv);
01335 C2F(setabsourelGif)(x1,x2,x3,x4);C2F(getabsourelGif)(verbose,x1,x2,dv);
01336 C2F(xsetmarkGif)(x1,x2,x3,x4);C2F(xgetmarkGif)(verbose,x1,x2,dv);
01337 C2F(setpatternGif)(x1,x2,x3,x4);C2F(getpatternGif)(verbose,x1,x2,dv);
01338 C2F(setthicknessGif)(x1,x2,x3,x4);C2F(getthicknessGif)(verbose,x1,x2,dv);
01339 C2F(usecolorGif)(x1,x2,x3,x4);C2F(gemptyGif)(verbose,x1,x2,dv);
01340 C2F(setwindowdimGif)(x1,x2,x3,x4);C2F(getwindowdimGif)(verbose,x1,x2,dv);
01341 C2F(semptyGif)(x1,x2,x3,x4);C2F(getlastGif)(verbose,x1,x2,dv);
01342 C2F(setcurwinGif)(x1,x2,x3,x4);C2F(getcurwinGif)(verbose,x1,x2,dv);
01343 C2F(setwindowposGif)(x1,x2,x3,x4);getwindowposGif(verbose,x1,x2,dv);
01344 }
01345
01346 #endif
01347
01348
01349 void C2F(scilabgcgetGif)(char *str, integer *verbose, integer *x1, integer *x2, integer *x3, integer *x4, integer *x5, double *dv1, double *dv2, double *dv3, double *dv4)
01350 {
01351 int x6=0;
01352 C2F(ScilabGCGetorSetGif)(str,(integer)1L,verbose,x1,x2,x3,x4,x5,&x6,dv1);
01353 }
01354
01355 void C2F(scilabgcsetGif)(char *str, integer *x1, integer *x2, integer *x3, integer *x4, integer *x5, integer *x6, double *dv1, double *dv2, double *dv3, double *dv4)
01356 {
01357 integer verbose ;
01358 verbose = 0 ;
01359 C2F(ScilabGCGetorSetGif)(str,(integer)0L,&verbose,x1,x2,x3,x4,x5,x6,dv1);}
01360
01361 void C2F(ScilabGCGetorSetGif)(char *str, integer flag, integer *verbose, integer *x1, integer *x2, integer *x3, integer *x4, integer *x5, integer *x6, double *dv1)
01362 { integer i ;
01363 for (i=0; i < NUMSETFONC ; i++)
01364 {
01365 integer j;
01366 j = strcmp(str,ScilabGCTabGif[i].name);
01367 if ( j == 0 )
01368 { if (*verbose == 1)
01369 sciprint("\nGetting Info on %s\r\n",str);
01370 if (flag == 1)
01371 (ScilabGCTabGif[i].getfonc)(verbose,x1,x2,dv1);
01372 else
01373 (ScilabGCTabGif[i].setfonc)(x1,x2,x3,x4,x5,x6,dv1);
01374 return;}
01375 else
01376 { if ( j <= 0)
01377 {
01378 sciprint("\nUnknow GIF operator <%s>\r\n",str);
01379 *x1=1;*x2=0;
01380 return;
01381 }
01382 }
01383 }
01384 sciprint("\n Unknow GIF operator <%s>\r\n",str);
01385 *x1=1;*x2=0;
01386 }
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400 void C2F(DispStringAngleGif)(integer *x0, integer *yy0, char *string, double *angle)
01401 {
01402 int i;
01403 integer x,y, rect[4];
01404 double sina ,cosa,l;
01405 char str1[2];
01406 integer verbose, Dnarg,Dvalue[10],j;
01407 verbose =0 ;
01408
01409 if (GifIm == (gdImagePtr)0 ) {
01410 sciprint(" 12 xinit must be called before any action \r\n");
01411 return;
01412 }
01413
01414 str1[1]='\0';
01415 x= *x0;
01416 y= *yy0;
01417 sina= sin(*angle * M_PI/180.0);
01418 cosa= cos(*angle * M_PI/180.0);
01419 str1[0]=string[0];
01420 C2F(boundingboxGif)(str1,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01421
01422 C2F(getdashGif)(&verbose,Dvalue,&Dnarg,vdouble);
01423 C2F(setdashGif)((j=1,&j),PI0,PI0,PI0);
01424 for ( i = 0 ; i < (int)strlen(string); i++)
01425 {
01426 str1[0]=string[i];
01427 gdImageString(GifIm, GifFont, x, y - rect[3], (unsigned char *)str1,
01428 GifLineColor());
01429 C2F(boundingboxGif)(str1,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01430
01431 if ( cosa <= 0.0 && i < (int)strlen(string)-1)
01432 { char str2[2];
01435 str2[1]='\0';str2[0]=string[i+1];
01436 C2F(boundingboxGif)(str2,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01437 }
01438 if ( Abs(cosa) >= 1.e-8 )
01439 {
01440 if ( Abs(sina/cosa) <= Abs(((double)rect[3])/((double)rect[2])))
01441 l = Abs(rect[2]/cosa);
01442 else
01443 l = Abs(rect[3]/sina);
01444 }
01445 else
01446 l = Abs(rect[3]/sina);
01447 x += (integer)(cosa*l*1.1);
01448 y += (integer)(sina*l*1.1);
01449 }
01450 C2F(setdashGif)(Dvalue,PI0,PI0,PI0);
01451 }
01452
01453 void C2F(displaystringGif)(char *string, integer *x, integer *y, integer *v1, integer *flag, integer *v6, integer *v7, double *angle, double *dv2, double *dv3, double *dv4)
01454 {
01455 integer rect[4] ;
01456 integer boxX = 0 ;
01457 integer boxY = 0 ;
01458
01459 integer verbose, Dnarg,Dvalue[10],j;
01460 verbose =0 ;
01461 if (GifIm == (gdImagePtr)0 ) {
01462 sciprint(" 13 xinit must be called before any action \r\n");
01463 return;
01464 }
01465 if ( Abs(*angle) <= 0.1) {
01466 C2F(boundingboxGif)(string,&boxX,&boxY,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01467 C2F(getdashGif)(&verbose,Dvalue,&Dnarg,vdouble);
01468 C2F(setdashGif)((j=1,&j),PI0,PI0,PI0);
01469 gdImageString(GifIm, GifFont, *x, *y - rect[3], (unsigned char*) string,
01470 GifLineColor());
01471 C2F(setdashGif)(Dvalue,PI0,PI0,PI0);
01472 }
01473 else if ( Abs(*angle + 90) <= 0.1 )
01474 {
01475 C2F(boundingboxGif)(string,&boxX,&boxY,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01476 C2F(getdashGif)(&verbose,Dvalue,&Dnarg,vdouble);
01477 C2F(setdashGif)((j=1,&j),PI0,PI0,PI0);
01478
01479
01480 gdImageStringUp(GifIm, GifFont, *x - rect[3], *y - rect[2], (unsigned char*) string,
01481 GifLineColor());
01482 C2F(setdashGif)(Dvalue,PI0,PI0,PI0);
01483 }
01484 else
01485 C2F(DispStringAngleGif)(x,y,string,angle);
01486 }
01487
01488
01489 void C2F(boundingboxGif)(char *string, integer *x, integer *y, integer *rect, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01490 {
01491 int k,width;
01492 if (GifIm == (gdImagePtr)0 ) {
01493 sciprint(" 14 xinit must be called before any action \r\n");
01494 return;
01495 }
01496 width = 0;
01497 for (k=0;k< (int) strlen(string);k++)
01498 width += gdCharWidth(GifFont, string[k]);
01499 rect[0]= (int)(*x);
01500 rect[1]= (int)(*y);
01501 rect[2]= width;
01502 rect[3]= GifFont->h;
01503 }
01504
01507 void C2F(drawlineGif)(integer *xx1, integer *yy1, integer *x2, integer *y2)
01508 {
01509 if (GifIm == (gdImagePtr)0 ) {
01510 sciprint(" 15 xinit must be called before any action \r\n");
01511 return;
01512 }
01513 gdImageThickLine(GifIm, *xx1, *yy1, *x2, *y2, GifLineColor(),
01514 Max(1,ScilabGCGif.CurLineWidth));
01515 }
01516
01521 void C2F(drawsegmentsGif)(char *str, integer *vx, integer *vy, integer *n, integer *style, integer *iflag, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01522 {
01523 integer verbose=0,Dnarg,Dvalue[10],NDvalue;
01524 int i;
01525 if (GifIm == (gdImagePtr)0 ) {
01526 sciprint(" 16 xinit must be called before any action \r\n");
01527 return;
01528 }
01529
01530
01531
01532
01533
01534 C2F(get_dash_and_color_Gif)(&verbose,Dvalue,&Dnarg,vdouble);
01535 if ((int) *iflag == 0 )
01536 {
01539 NDvalue= (*style < 1) ? Dvalue[0] : *style;
01540 C2F(set_dash_or_color_Gif)(&NDvalue,PI0,PI0,PI0);
01541 for ( i=0 ; i < *n/2 ; i++) {
01542 gdImageThickLine(GifIm, vx[2*i], vy[2*i],
01543 vx[2*i + 1], vy[2*i + 1],
01544 GifLineColor(),Max(1,ScilabGCGif.CurLineWidth));
01545 }
01546 }
01547 else
01548 {
01549 for ( i=0 ; i < *n/2 ; i++)
01550 {
01551 integer NDvalue2;
01552 NDvalue2 = style[i];
01553 C2F(setpatternGif)(&NDvalue2,PI0,PI0,PI0);
01554 gdImageThickLine(GifIm, vx[2*i], vy[2*i],
01555 vx[2*i + 1], vy[2*i + 1],
01556 GifLineColor(),Max(1,ScilabGCGif.CurLineWidth));
01557 }
01558 }
01559 C2F(set_dash_and_color_Gif)( Dvalue,PI0,PI0,PI0);
01560 }
01561
01568 void C2F(drawarrowsGif)(char *str, integer *vx, integer *vy, integer *n, integer *as, integer *style, integer *iflag, double *dv1, double *dv2, double *dv3, double *dv4)
01569 {
01570 integer verbose=0,Dnarg,Dvalue[10],NDvalue,i;
01571 double cos20=cos(20.0*M_PI/180.0);
01572 double sin20=sin(20.0*M_PI/180.0);
01573 integer polyx[4],polyy[4];
01574
01575 if (GifIm == (gdImagePtr)0 ) {
01576 sciprint(" 17 xinit must be called before any action \r\n");
01577 return;
01578 }
01579
01580 C2F(get_dash_and_color_Gif)(&verbose,Dvalue,&Dnarg,vdouble);
01581 for (i=0 ; i < *n/2 ; i++)
01582 {
01583 double dx,dy,norm;
01584 if ( (int) *iflag == 1)
01585 NDvalue = style[i];
01586 else
01587 NDvalue=(*style < 1) ? Dvalue[0] : *style;
01588 C2F(set_line_style_Gif)(&NDvalue,PI0,PI0,PI0);
01589
01590 dx=( vx[2*i+1]-vx[2*i]);
01591 dy=( vy[2*i+1]-vy[2*i]);
01592 norm = sqrt(dx*dx+dy*dy);
01593 if ( Abs(norm) > SMDOUBLE )
01594 { integer nn=1,p=3;
01595 dx=(*as/10.0)*dx/norm;dy=(*as/10.0)*dy/norm;
01596 polyx[0]= polyx[3]=vx[2*i+1];
01597 polyx[1]= inint(polyx[0] - cos20*dx -sin20*dy );
01598 polyx[2]= inint(polyx[0] - cos20*dx + sin20*dy);
01599 polyy[0]= polyy[3]=vy[2*i+1];
01600 polyy[1]= inint(polyy[0] + sin20*dx -cos20*dy) ;
01601 polyy[2]= inint(polyy[0] - sin20*dx - cos20*dy) ;
01602 C2F(fillpolylinesGif)("v",polyx,polyy,&NDvalue, &nn,&p,PI0,PD0,PD0,PD0,PD0);
01603 }
01604
01605 gdImageThickLine(GifIm, vx[2*i], vy[2*i],(int)
01606 (vx[2*i + 1]-dx*cos20), (int)(vy[2*i + 1]-dy*cos20),
01607 GifLineColor(),Max(1,ScilabGCGif.CurLineWidth));
01608
01609 }
01610 C2F(set_dash_and_color_Gif)( Dvalue,PI0,PI0,PI0);
01611 }
01612
01613
01622 void C2F(drawrectanglesGif)(char *str, integer *vects, integer *fillvect, integer *n, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01623 {
01624 int i,cpat,verb=0,num,cd[10],thick;
01625
01626 if (GifIm == (gdImagePtr)0 ) {
01627 sciprint(" 18 xinit must be called before any action \r\n");
01628 return;
01629 }
01630 C2F(getpatternGif)(&verb,&cpat,&num,vdouble);
01631 C2F(get_dash_and_color_Gif)(&verb,cd,&num,vdouble);
01632 thick = Max(1,ScilabGCGif.CurLineWidth);
01633 for (i = 0; i < *n; i++) {
01634 int x, y, w, h;
01635 x = vects[4 * i];
01636 y = vects[4 * i + 1];
01637 w = vects[4 * i + 2];
01638 h = vects[4 * i + 3];
01639 if ( fillvect[i] < 0 ) {
01640 int dash = - fillvect[i];
01641 C2F(set_line_style_Gif)(&dash,PI0,PI0,PI0);
01642 gdImageThickRectangle(GifIm, x, y, x + w, y + h, GifLineColor(),thick);
01643 }
01644 else if ( fillvect[i] == 0 )
01645 gdImageThickRectangle(GifIm, x, y, x + w, y + h, GifLineColor(),thick);
01646 else
01647 gdImageFilledRectangle(GifIm, x, y, x + w, y + h,
01648 GifPatternColor(abs(fillvect[i])));
01649 }
01650 C2F(set_dash_and_color_Gif)(cd,PI0,PI0,PI0);
01651 }
01652
01653 void C2F(drawrectangleGif)(char *str, integer *x, integer *y, integer *width, integer *height, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01654 {
01655 if (GifIm == (gdImagePtr)0 ) {
01656 sciprint(" 19 xinit must be called before any action \r\n");
01657 return;
01658 }
01659 gdImageRectangle(GifIm, *x, *y, *x + *width, *y + *height, GifLineColor());
01660 }
01661
01664 void C2F(fillrectangleGif)(char *str, integer *x, integer *y, integer *width, integer *height, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01665 {
01666
01667 integer cpat,verb=0,num;
01668
01669 if (GifIm == (gdImagePtr)0 ) {
01670 sciprint(" 20 xinit must be called before any action \r\n");
01671 return;
01672 }
01673 C2F(getpatternGif)(&verb,&cpat,&num,vdouble);
01674 gdImageFilledRectangle(GifIm, *x, *y, *x + *width, *y + *height,
01675 GifPatternColor(cpat));
01676 }
01682 void C2F(fillarcsGif)(char *str, integer *vects, integer *fillvect, integer *n, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01683 {
01684 integer verbose=0,Dnarg,pat;
01685 int i,i6;
01686
01687 if (GifIm == (gdImagePtr)0 ) {
01688 sciprint(" 21 xinit must be called before any action \r\n");
01689 return;
01690 }
01691
01692 C2F(getpatternGif)(&verbose,&pat,&Dnarg,vdouble);
01693 for ( i=0 ; i < *n ; i++)
01694 {
01696 C2F(setpatternGif)(&fillvect[i],PI0,PI0,PI0);
01697 i6=6*i;
01698 C2F(fillarcGif)(str,&(vects[i6]),&(vects[i6+1]),&(vects[i6+2]),
01699 &(vects[i6+3]),&(vects[i6+4]),&(vects[i6+5]) ,dv1, dv2, dv3, dv4);
01700
01701 }
01702 C2F(setpatternGif)(&pat,PI0,PI0,PI0);
01703 }
01704
01712 void C2F(drawarcsGif)(char *str, integer *vects, integer *style, integer *n, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01713 {
01714 integer verbose=0,Dnarg,Dvalue[10],NDvalue;
01715 int i,i6;
01716
01717 if (GifIm == (gdImagePtr)0 ) {
01718 sciprint(" 22 xinit must be called before any action \r\n");
01719 return;
01720 }
01721
01722 C2F(get_dash_and_color_Gif)(&verbose,Dvalue,&Dnarg,vdouble);
01723 for ( i=0 ; i < *n ; i++)
01724 {
01726 NDvalue = style[i];
01727 C2F(set_line_style_Gif)(&NDvalue,PI0,PI0,PI0);
01728 i6=6*i;
01729 C2F(drawarcGif)(str,vects+i6,vects+(i6+1),vects+(i6+2),vects+(i6+3),
01730 vects+(i6+4),vects+(i6+5) , dv1, dv2, dv3, dv4);
01731 }
01732 C2F(set_dash_and_color_Gif)( Dvalue,PI0,PI0,PI0);
01733 }
01734
01735
01739 void C2F(drawarcGif)(char *str, integer *x, integer *y, integer *width, integer *height, integer *angle1, integer *angle2, double *dv1, double *dv2, double *dv3, double *dv4)
01740 {
01741 integer vx[365],vy[365],k,n;
01742 float alpha,fact= (float) 0.01745329251994330,w,h;
01743 integer close = 0;
01744
01745 if (GifIm == (gdImagePtr)0 ) {
01746 sciprint(" 23 xinit must be called before any action \r\n");
01747 return;
01748 }
01749
01750 w = (float) ((*width)/2.0);
01751 h = (float) ((*height)/2.0);
01752 n=Min((*angle2/64),360);
01753 for (k = 0; k < n; ++k) {
01754 alpha=((*angle1/64)+k)*fact;
01755 vx[k] = (integer) (*x + w*(cos(alpha)+1.0));
01756 vy[k] = (integer) (*y + h*(-sin(alpha)+1.0));}
01757
01758
01759 if(n == 360) close = 1;
01760
01761 C2F(drawpolylineGif)(str, &n, vx, vy, &close, PI0, PI0, dv1, dv2, dv3, dv4);
01762 }
01763
01767 void C2F(fillarcGif)(char *str, integer *x, integer *y, integer *width, integer *height, integer *angle1, integer *angle2, double *dv1, double *dv2, double *dv3, double *dv4)
01768 {
01769 integer vx[365],vy[365],k,k0,kmax,n;
01770 float alpha,fact= (float) 0.01745329251994330,w,h;
01771 integer close = 1;
01772 if (GifIm == (gdImagePtr)0 ) {
01773 sciprint(" 24 xinit must be called before any action \r\n");
01774 return;
01775 }
01776 n=Min((*angle2/64),360);
01777
01778 w = (float) ((*width)/2.0);
01779 h = (float) ((*height)/2.0);
01780 k0 = 0;
01781 kmax = n-1;
01782
01783 if (n != 360) {
01784 vx[0] = (integer) (*x + w);
01785 vy[0] = (integer) (*y + h);
01786 k0 = 1;
01787 kmax = n;}
01788
01789 for (k = k0; k <= kmax; ++k) {
01790 alpha=((*angle1/64)+k)*fact;
01791 vx[k] = (integer) (*x + w*(cos(alpha)+1.0));
01792 vy[k] = (integer) (*y + h*(-sin(alpha)+1.0));}
01793 if (n != 360) {
01794 n++;
01795 vx[n] = (integer) (*x + ((*width)/2.0));
01796 vy[n] = (integer) (*y + ((*height)/2.0));
01797 n++;
01798 }
01799 C2F(fillpolylineGif)(str, &n, vx, vy, &close, PI0, PI0, dv1, dv2, dv3, dv4);
01800 }
01801
01802
01803
01804
01805
01811 void C2F(drawpolylinesGif)(char *str, integer *vectsx, integer *vectsy, integer *drawvect, integer *n, integer *p, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01812 { integer verbose ,symb[2],Mnarg,Dnarg,Dvalue[10],NDvalue,i,j,close;
01813 verbose =0 ;
01814 if (GifIm == (gdImagePtr)0 ) {
01815 sciprint(" 25 xinit must be called before any action \r\n");
01816 return;
01817 }
01818
01819 C2F(xgetmarkGif)(&verbose,symb,&Mnarg,vdouble);
01820 C2F(get_dash_and_color_Gif)(&verbose,Dvalue,&Dnarg,vdouble);
01821 for (i=0 ; i< *n ; i++)
01822 {
01823 if (drawvect[i] <= 0)
01824 {
01825 NDvalue = - drawvect[i];
01826 C2F(setdashGif)((j=1,&j),PI0,PI0,PI0);
01827
01828 C2F(xsetmarkGif)(&NDvalue,symb+1,PI0,PI0);
01829
01830 C2F(drawpolymarkGif)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01831 C2F(setdashGif)(Dvalue,PI0,PI0,PI0);
01832 }
01833 else
01834 {
01836 C2F(set_line_style_Gif)(drawvect+i,PI0,PI0,PI0);
01837 close = 0;
01838 C2F(drawpolylineGif)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,&close,PI0,PI0,PD0,PD0,PD0,PD0);
01839 }
01840 }
01842 C2F(set_dash_and_color_Gif)(Dvalue,PI0,PI0,PI0);
01843 C2F(xsetmarkGif)(symb,symb+1,PI0,PI0);
01844 }
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857 void C2F(fillpolylinesGif)(char *str, integer *vectsx, integer *vectsy, integer *fillvect, integer *n, integer *p, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01858 {
01859 integer n1,i,j,o;
01860
01861 gdPoint *points;
01862 integer c,thick;
01863 if (GifIm == (gdImagePtr)0 ) {
01864 sciprint(" 26 xinit must be called before any action \r\n");
01865 return;
01866 }
01867 n1 = *p;
01868 if (fillpolylines_closeflag) n1++;
01869 points = (gdPoint*) MALLOC(n1 * sizeof(gdPoint));
01870 if (points == (gdPoint*) NULL) return;
01871 for (j = 0; j < *n; j++) {
01872 o = j * (*p);
01873 for (i = 0; i < *p; i++) {
01874 points[i].x = vectsx[o + i];
01875 points[i].y = vectsy[o + i];
01876 }
01877 if (fillpolylines_closeflag) {
01878 points[*p].x = vectsx[o];
01879 points[*p].y = vectsy[o];
01880 }
01881 if (fillvect[j] != 0) {
01882 gdImageFilledPolygon(GifIm, points, n1,
01883 GifPatternColor(abs(fillvect[j])));
01884 }
01885 if (fillvect[j] >= 0) {
01886 c = GifLineColor();
01887 thick = Max(1,ScilabGCGif.CurLineWidth);
01888 gdImagePolyLine(GifIm, &(vectsx[o]), &(vectsy[o]),
01889 *p,c,thick,fillpolylines_closeflag);
01890 }
01891 }
01892 FREE(points);
01893 }
01894
01898 void C2F(drawpolylineGif)(char *str, integer *n, integer *vx, integer *vy, integer *closeflag, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01899 {
01900 integer thick,n1;
01901 if (GifIm == (gdImagePtr)0 ) {
01902 sciprint(" 27 xinit must be called before any action \r\n");
01903 return;
01904 }
01905 thick = Max(1,ScilabGCGif.CurLineWidth);
01906 n1 = *n;
01907 gdImagePolyLine(GifIm,vx,vy,n1,GifLineColor(),thick,*closeflag);
01908
01909 }
01910
01913 void C2F(fillpolylineGif)(char *str, integer *n, integer *vx, integer *vy, integer *closeareaflag, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01914 {
01915 integer i =1;
01916 integer cpat,verb=0,num;
01917 if (GifIm == (gdImagePtr)0 ) {
01918 sciprint(" 28 xinit must be called before any action \r\n");
01919 return;
01920 }
01921 C2F(getpatternGif)(&verb,&cpat,&num,vdouble);
01923 cpat = -cpat;
01924 fillpolylines_closeflag = *closeareaflag;
01925 C2F(fillpolylinesGif)(str,vx,vy,&cpat,&i,n,PI0,PD0,PD0,PD0,PD0);
01926 }
01927
01931 void C2F(drawpolymarkGif)(char *str, integer *n, integer *vx, integer *vy, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01932 {
01933 integer keepid,keepsize,i=1,sz=ScilabGCGif.CurHardSymbSize;
01934
01935 keepid = ScilabGCGif.FontId;
01936 keepsize= ScilabGCGif.FontSize;
01937 C2F(xsetfontGif)(&i,&sz,PI0,PI0);
01938 C2F(displaysymbolsGif)(str,n,vx,vy);
01939 C2F(xsetfontGif)(&keepid,&keepsize,PI0,PI0);
01940 }
01941
01942
01943
01944
01945
01946 void C2F(initgraphicGif)(char *string, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01947 {
01948 char string1[256];
01949 static integer EntryCounter = 0;
01950 integer x[2],verbose=0,narg;
01951 double dummy;
01952 *v3=0;
01953 if (EntryCounter >= 1)
01954 {
01955 C2F(xendgraphicGif)();
01956 }
01957 strncpy(string1,string,256);
01958
01959 file=fopen(string1,"wb");
01960 if (file == 0)
01961 {
01962
01963 *v3=1;
01964 return;
01965 }
01966 x[0]=640;
01967 x[1]=480;
01968
01969 if (CheckScilabXgc()) {
01970 C2F(getwindowdim)(&verbose, x, &narg,&dummy);
01971 }
01972
01973 LoadFontsGif();
01974 GifIm = gdImageCreate(x[0], x[1]);
01975
01976
01977 ScilabGCGif.CWindowWidth = x[0];
01978 ScilabGCGif.CWindowHeight = x[1];
01979 FileInitGif();
01980 ScilabGCGif.CurWindow =EntryCounter;
01981 EntryCounter =EntryCounter +1;
01982
01983 gdImageFilledRectangle(GifIm, 0, 0, x[0]-1, x[1]-1, col_white);
01984
01985 }
01986
01987 static void FileInitGif(void)
01988 {
01989
01990 int i;
01991 integer x[2],verbose,narg;
01992
01993 verbose = 0;
01994 C2F(getwindowdimGif)(&verbose,x,&narg,vdouble);
01995 ColorInitGif();
01996 InitScilabGCGif(PI0,PI0,PI0,PI0);
01997
01998 C2F(setpatternGif)((i=ScilabGCGif.NumForeground+1,&i),PI0,PI0,PI0);
01999 if (ScilabGCGif.CurColorStatus == 1)
02000 {
02001 ScilabGCGif.IDLastPattern = ScilabGCGif.Numcolors - 1;
02002 }
02003
02004 }
02005
02006
02007
02008
02009
02010
02011
02012 void InitScilabGCGif(integer *v1, integer *v2, integer *v3, integer *v4)
02013 { integer i,j,col;
02014 ScilabGCGif.IDLastPattern = GREYNUMBER-1;
02015 ScilabGCGif.CurLineWidth=0 ;
02016 i=1;
02017 C2F(setthicknessGif)(&i,PI0,PI0,PI0);
02018 C2F(setalufunctionGif)("GXcopy");
02020 i=j= -1;
02021 C2F(unsetclipGif)(PI0,PI0,PI0,PI0);
02022 C2F(xsetfontGif)((i=2,&i),(j=1,&j),PI0,PI0);
02023 C2F(xsetmarkGif)((i=0,&i),(j=0,&j),PI0,PI0);
02025 ScilabGCGif.CurVectorStyle = CoordModeOrigin ;
02026
02027 ScilabGCGif.CurColorStatus =0;
02028 C2F(setpatternGif)((i=1,&i),PI0,PI0,PI0);
02029 C2F(setdashGif)((i=1,&i),PI0,PI0,PI0);
02030
02031
02032 ScilabGCGif.Numcolors = DEFAULTNUMCOLORS;
02033 ScilabGCGif.CurColorStatus = 1 ;
02034 C2F(setpatternGif)((i=1,&i),PI0,PI0,PI0);
02035 C2F(setforegroundGif)((i=ScilabGCGif.NumForeground+1,&i),PI0,PI0,PI0);
02036 C2F(setbackgroundGif)((i=ScilabGCGif.NumForeground+2,&i),PI0,PI0,PI0);
02037 C2F(sethidden3dGif)((i=4,&i),PI0,PI0,PI0);
02038
02039 getcolordef(&col);
02044 ScilabGCGif.mafigure = (sciPointObj *)NULL;
02045 ScilabGCGif.CurColorStatus = (col == 1) ? 0: 1;
02046 C2F(usecolorGif)(&col,PI0,PI0,PI0);
02047 if (col == 1) ScilabGCGif.IDLastPattern = ScilabGCGif.Numcolors - 1;
02048 strcpy(ScilabGCGif.CurNumberDispFormat,"%-5.2g");
02049 }
02050
02051
02052
02053
02054
02055
02056
02057
02058
02059
02060
02061
02062
02063
02064
02065
02066
02067
02068
02069
02070
02071
02072
02073 void C2F(drawaxisGif)(char *str, integer *alpha, integer *nsteps, integer *v2, integer *initpoint, integer *v6, integer *v7, double *size, double *dx2, double *dx3, double *dx4)
02074 { integer i;
02075 double xi,yi,xf,yf;
02076 double cosal,sinal;
02077
02078 if (GifIm == (gdImagePtr)0 ) {
02079 sciprint(" 29 xinit must be called before any action \r\n");
02080 return;
02081 }
02082 cosal= cos( (double)M_PI * (*alpha)/180.0);
02083 sinal= sin( (double)M_PI * (*alpha)/180.0);
02084 for (i=0; i <= nsteps[0]*nsteps[1]; i++)
02085 {
02086 if (( i % nsteps[0]) != 0)
02087 {
02088 xi = initpoint[0]+i*size[0]*cosal;
02089 yi = initpoint[1]+i*size[0]*sinal;
02090 xf = xi - ( size[1]*sinal);
02091 yf = yi + ( size[1]*cosal);
02092 gdImageThickLine(GifIm,inint(xi),inint(yi),inint(xf),inint(yf),
02093 GifLineColor(),Max(1,ScilabGCGif.CurLineWidth));
02094 }
02095 }
02096 for (i=0; i <= nsteps[1]; i++)
02097 { xi = initpoint[0]+i*nsteps[0]*size[0]*cosal;
02098 yi = initpoint[1]+i*nsteps[0]*size[0]*sinal;
02099 xf = xi - ( size[1]*size[2]*sinal);
02100 yf = yi + ( size[1]*size[2]*cosal);
02101 gdImageThickLine(GifIm,inint(xi),inint(yi),inint(xf),inint(yf),
02102 GifLineColor(),Max(1,ScilabGCGif.CurLineWidth));
02103 }
02104
02105 xi = initpoint[0]; yi= initpoint[1];
02106 xf = initpoint[0]+ nsteps[0]*nsteps[1]*size[0]*cosal;
02107 yf = initpoint[1]+ nsteps[0]*nsteps[1]*size[0]*sinal;
02108 gdImageThickLine(GifIm, inint(xi),inint(yi),inint(xf),inint(yf),
02109 GifLineColor(),Max(1,ScilabGCGif.CurLineWidth));
02110 }
02111
02112
02113
02114
02115
02116
02117 void C2F(displaynumbersGif)(char *str, integer *x, integer *y, integer *v1, integer *v2, integer *n, integer *flag, double *z, double *alpha, double *dx3, double *dx4)
02118 { integer i ;
02119 char buf[20];
02120 for (i=0 ; i< *n ; i++)
02121 {
02122 sprintf(buf,ScilabGCGif.CurNumberDispFormat,z[i]);
02123 C2F(displaystringGif)(buf,&(x[i]),&(y[i]),PI0,flag,PI0,PI0,&(alpha[i]),PD0,PD0,PD0) ;
02124 }
02125 }
02126
02129 #define FONTNUMBER 11
02130 #define FONTMAXSIZE 6
02131 #define SYMBOLNUMBER 10
02132
02133
02134 static char *sizeGif[] = { "08" ,"10","12","14","18","24"};
02135 static int isizeGif[FONTMAXSIZE] = { 8 ,10,12,14,18,24 };
02136
02137
02138
02139
02140
02141 gdFont FontListGif[FONTNUMBER][FONTMAXSIZE];
02142
02143
02144
02145
02146
02147
02148
02149
02150
02151 struct FontInfo { integer ok;
02152 char fname[100];
02153 } FontInfoTabGif[FONTNUMBER];
02154
02155 typedef struct {
02156 char *alias;
02157 char *name;
02158 } FontAlias;
02159
02162 static FontAlias fonttab[] ={
02163 {"courR", "-adobe-courier-medium-r-normal--*-%s0-*-*-m-*-iso8859-1"},
02164 {"symb", "-adobe-symbol-medium-r-normal--*-%s0-*-*-p-*-adobe-fontspecific"},
02165 {"timR", "-adobe-times-medium-r-normal--*-%s0-*-*-p-*-iso8859-1"},
02166 {"timI", "-adobe-times-medium-i-normal--*-%s0-*-*-p-*-iso8859-1"},
02167 {"timB", "-adobe-times-bold-r-normal--*-%s0-*-*-p-*-iso8859-1"},
02168 {"timBI", "-adobe-times-bold-i-normal--*-%s0-*-*-p-*-iso8859-1"},
02169 {"helvR", "-adobe-helvetica-medium-r-normal--*-%s0-*-*-p-*-iso8859-1"},
02170 {"helvO", "-adobe-helvetica-medium-o-normal--*-%s0-*-*-p-*-iso8859-1"},
02171 {"helvB", "-adobe-helvetica-bold-r-normal--*-%s0-*-*-p-*-iso8859-1"},
02172 {"helvBO","-adobe-helvetica-bold-o-normal--*-%s0-*-*-p-*-iso8859-1"},
02173 {(char *) NULL,( char *) NULL}
02174 };
02175
02178 void C2F(xsetfontGif)(integer *fontid, integer *fontsize, integer *v3, integer *v4)
02179 { integer i,fsiz;
02180 i = Min(FONTNUMBER-1,Max(*fontid,0));
02181 fsiz = Min(FONTMAXSIZE-1,Max(*fontsize,0));
02182 if ( FontInfoTabGif[i].ok !=1 )
02183 {
02184 if (i != FONTNUMBER-1 )
02185 {
02186 C2F(loadfamilyGif)(fonttab[i].alias,&i,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
02187 }
02188 else
02189 {
02190 sciprint(" The Font Id %d is not affected: use default font (Times)\r\n",(int)i);
02191 i = 2;
02192 }
02193 }
02194 ScilabGCGif.FontId = i;
02195 ScilabGCGif.FontSize = fsiz;
02196 GifFont = &(FontListGif[i][fsiz]);
02197 }
02198
02201 void C2F(xgetfontGif)(integer *verbose, integer *font, integer *nargs, double *dummy)
02202 {
02203 *nargs=2;
02204 font[0]= ScilabGCGif.FontId ;
02205 font[1] =ScilabGCGif.FontSize ;
02206 if (*verbose == 1)
02207 {
02208 sciprint("\nFontId : %d ", ScilabGCGif.FontId );
02209 sciprint("%s %s at size %s pts\r\n",SCIPROMPT,
02210 "GifFont",
02211 sizeGif[ScilabGCGif.FontSize]);
02212 }
02213 }
02214
02217 void C2F(xsetmarkGif)(integer *number, integer *size, integer *v3, integer *v4)
02218 {
02219 ScilabGCGif.CurHardSymb = Max(Min(SYMBOLNUMBER-1,*number),0);
02220 ScilabGCGif.CurHardSymbSize = Max(Min(FONTMAXSIZE-1,*size),0);
02221 ;}
02222
02225 void C2F(xgetmarkGif)(integer *verbose, integer *symb, integer *narg, double *dummy)
02226 {
02227 *narg =2 ;
02228 symb[0] = ScilabGCGif.CurHardSymb ;
02229 symb[1] = ScilabGCGif.CurHardSymbSize ;
02230 if (*verbose == 1)
02231 sciprint("\nMark : %d at size %d pts\r\n",
02232 ScilabGCGif.CurHardSymb,
02233 isizeGif[ScilabGCGif.CurHardSymbSize]);
02234 }
02235
02236 char symb_listGif[] = {
02237
02238
02239
02240 (char)0x2e,(char)0x2b,(char)0xb4,(char)0xc5,(char)0xa8,
02241 (char)0xe0,(char)0x44,(char)0xd1,(char)0xa7,(char)0x4f};
02242
02243 static void C2F(displaysymbolsGif)(char *str, integer *n, integer *vx, integer *vy)
02244 {
02245 int col, i, c;
02246
02247
02248
02249
02250
02251
02252 col = ( ScilabGCGif.CurColorStatus ==1) ? ScilabGCGif.CurColor : ScilabGCGif.CurPattern ;
02253 for (i = 0; i < *n; i++) {
02254 c = Char2Int(symb_listGif[ScilabGCGif.CurHardSymb]);
02255 gdImageSymb(GifIm, GifFont, vx[i], vy[i], c,GifLineColor());
02256
02257
02258 }
02259 }
02260
02261
02265 void C2F(getFontMaxSizeGif)(char *str, integer *sizeMin, integer *sizeMax, integer *v1, integer *v2, integer *v3, integer *v4, double *dx1, double *dx2, double *dx3, double *dx4)
02266 {
02267 *sizeMin = 0 ;
02268 *sizeMax = FONTMAXSIZE ;
02269 }
02270
02271
02272
02273
02274
02275
02276
02277 void C2F(loadfamilyGif)(char *name, integer *j, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
02278 {
02279 FILE *ff;
02280 char fname[1024];
02281 int i,ierr;
02282 char *SciPath;
02283 gdFontPtr font;
02284
02286 if ( strchr(name,'%') != (char *) NULL)
02287 {
02288 sciprint("only alias font name are supported by gif driver\n");
02289 return;
02290 }
02291 SciPath=getSCIpath();
02292 if (SciPath==NULL)
02293 {
02294 sciprint("The SCI environment variable is not set\n");
02295 return;
02296 }
02297 fname[0]=0;
02298
02299 if (FontInfoTabGif[*j].ok == 1) {
02300 if (strcmp(FontInfoTabGif[*j].fname,name)!=0) {
02301
02302 FontInfoTabGif[*j].ok = 0;
02303 for (i=0;i<FONTMAXSIZE;i++) {
02304 font = &(FontListGif[*j][i]);
02305 if (font != NULL) FREE(font->data);
02306 }
02307 }
02308 }
02309 if (FontInfoTabGif[*j].ok == 0) {
02310 for (i=0;i<FONTMAXSIZE;i++) {
02311 sprintf(fname,"%s/modules/graphics/fonts/giffonts/75dpi/%s%s.bdf",SciPath,name,sizeGif[i]);
02312 ff=fopen(fname,"r");
02313 if (ff == 0)
02314 {
02315 sciprint("Can't open font file %s\n",fname);
02316 return;
02317 }
02318 ierr=ReadbdfFont(ff,&(FontListGif[*j][i]),fname);
02319 fclose(ff);
02320 if (ierr==1) {
02321 sciprint("\n Cannot allocate memory for font : %s%s\n",name,sizeGif[i]);
02322 return;
02323 }
02324 if (ierr==2) {
02325 sciprint("\n Font not found: %s%s\n",name,sizeGif[i]);
02326 return;
02327 }
02328
02329
02330 FontInfoTabGif[*j].ok = 1;
02331 strcpy(FontInfoTabGif[*j].fname,name);
02332 }
02333 }
02334 }
02335
02336 void C2F(queryfamilyGif)(char *name, integer *j, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
02337 {
02338 integer i ;
02339 name[0]='\0';
02340 for (i=0;i<FONTNUMBER;i++) {
02341 v3[i]=strlen(FontInfoTabGif[i].fname);
02342 strcat(name,FontInfoTabGif[i].fname);
02343 }
02344 *j=FONTNUMBER;
02345 }
02346
02347
02348
02349 static void LoadFontsGif(void)
02350 {
02351 int i;
02352
02353
02354 i = 0;
02355 C2F(loadfamilyGif)("courR",&i,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
02356
02357
02358 i = 1;
02359 C2F(loadfamilyGif)("symb",&i,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
02360
02361
02362 i = 2;
02363 C2F(loadfamilyGif)("timR",&i,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
02364
02365
02366
02367
02368
02369
02370
02371
02372
02373
02374
02375
02376
02377 }
02378
02379
02380 void C2F(setscilabFigureGif)(integer *v1,integer *v2,integer *v3,integer *v4,integer *v5,integer *v6,double *figure)
02381 {
02382 figure=(double *)ScilabGCGif.mafigure;
02383 }
02384
02385 void C2F(getscilabFigureGif)(integer *verbose, integer *x,integer *narg, double *figure)
02386 {
02387 figure=(double *)ScilabGCGif.mafigure;
02388 }
02389 void C2F(setscilabVersionGif)(integer *vers, integer *v2, integer *v3, integer *v4)
02390 {
02391
02392 }
02393
02394 void C2F(getscilabVersionGif)(integer *verbose, integer *vers, integer *narg, double *dummy)
02395 {
02396 *vers = 0 ;
02397 }
02398 void C2F(getscilabxgcGif)(integer *verbose, integer *x,integer *narg, double *dummy)
02399 {
02400 double **XGC;
02401 XGC=(double **)dummy;
02402 *XGC= (double *)&ScilabGCGif;
02403 }
02404 void C2F(setscilabxgcGif)(integer *v1, integer *v2, integer *v3, integer *v4)
02405 {}
02406
02407
02408
02409
02410
02411
02412
02413 void C2F(initgraphicfromscreenGif)(char *string, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
02414 {
02415 char string1[256];
02416 static integer EntryCounter = 0;
02417 integer x[2],verbose=0,narg;
02418 double dummy;
02419 *v3=0;
02420 if (EntryCounter >= 1)
02421 {
02422 C2F(xendgraphicGif)();
02423 }
02424 strncpy(string1,string,256);
02425
02426 file=fopen(string1,"wb");
02427 if (file == 0)
02428 {
02429
02430 *v3=1;
02431 return;
02432 }
02433 x[0]=640;
02434 x[1]=480;
02435
02436 if (CheckScilabXgc()) {
02437 C2F(getwindowdim)(&verbose, x, &narg,&dummy);
02438 }
02439
02440 LoadFontsGif();
02441 GifIm = gdImageCreate(x[0], x[1]);
02442
02443
02444 ScilabGCGif.CWindowWidth = x[0];
02445 ScilabGCGif.CWindowHeight = x[1];
02446 FileInitFromScreenGif();
02447 ScilabGCGif.CurWindow =EntryCounter;
02448 EntryCounter =EntryCounter +1;
02449
02450 gdImageFilledRectangle(GifIm, 0, 0, x[0]-1, x[1]-1, col_white);
02451
02452 }
02453
02454 static void FileInitFromScreenGif(void)
02455 {
02456 int m,r,g,b,c,i;
02457 float R,G,B;
02458 double *bigcmap,*cmap;
02459 int *ind,m1,ierr,i1;
02460
02461 integer x[2],verbose,narg;
02462
02463 verbose = 0;
02464 C2F(getwindowdimGif)(&verbose,x,&narg,vdouble);
02465 ColorInitGif();
02466 InitScilabGCGif(PI0,PI0,PI0,PI0);
02467
02468 if ( CheckColormap(&m) == 1) {
02469
02470
02471 for ( i=0; i < GifIm->colorsTotal; i++)
02472 gdImageColorDeallocate(GifIm, i);
02473 for ( i=0;i < ScilabGCGif.Numcolors+2; i++)
02474 col_index[i] = -1;
02475
02476 if (m>gdMaxColors-3) {
02477 sciprint(COLORMAP_WARNING,gdMaxColors-2) ;
02478 if ( (bigcmap = (double*) MALLOC(3*m * sizeof(double)))== NULL) {
02479 sciprint("Not enough memory\n");
02480 return;
02481 }
02482 for ( i=0; i < m; i++) {
02483 get_r(i,&R);
02484 get_g(i,&G);
02485 get_b(i,&B);
02486 bigcmap[i] = R;
02487 bigcmap[i + m] = G;
02488 bigcmap[i + 2 * m] = B;
02489 }
02490 m1 = gdMaxColors-2;
02491 if ( (cmap = (double*) MALLOC(3*m1 * sizeof(double)))== NULL) {
02492 sciprint("Not enough memory\n");
02493 FREE(bigcmap);
02494 return;
02495 }
02496 if ( (ind = (int*) MALLOC(m * sizeof(int)))== NULL) {
02497 sciprint("Not enough memory\n");
02498 FREE(bigcmap);
02499 FREE(cmap);
02500 return;
02501 }
02502
02503 C2F(nues1)(bigcmap,&m,cmap,&m1,ind,&ierr);
02504
02505 ScilabGCGif.Numcolors = m;
02506 for ( i=0; i < ScilabGCGif.Numcolors; i++) {
02507 i1 = ind[i] - 1;
02508 r=(int)(cmap[i1] * 255);
02509 g=(int)(cmap[i1 + m1] * 255);
02510 b=(int)(cmap[i1 + 2 * m1] * 255);
02511 if (r==255&&g==255&&b==255) {
02512
02513 r=254;g=254;b=254; }
02514
02515
02516 c = gdImageColorAllocate(GifIm,r,g,b);
02517 col_index[i] = c;
02518 }
02519 FREE(ind);
02520 FREE(cmap);
02521 FREE(bigcmap);
02522 }
02523 else {
02524
02525 ScilabGCGif.Numcolors = m;
02526 for ( i=0; i < ScilabGCGif.Numcolors; i++) {
02527 get_r(i,&R);
02528 get_g(i,&G);
02529 get_b(i,&B);
02530 r = (int)(R*255);
02531 g = (int)(G*255);
02532 b = (int)(B*255);
02533
02534
02535 c = gdImageColorAllocate(GifIm,r,g,b);
02536 col_index[i] = c;
02537 }
02538 }
02539
02540
02541
02542 c = gdImageColorAllocate(GifIm,0,0,0);
02543 col_index[m]=c;
02544
02545
02546 c = gdImageColorAllocate(GifIm,255,255,255);
02547 col_index[m+1]=c;
02548 col_white=col_index[m+1];
02549 ScilabGCGif.NumForeground = m;
02550 ScilabGCGif.NumBackground = m + 1;
02551 }
02552 C2F(setpatternGif)((i=ScilabGCGif.NumForeground+1,&i),PI0,PI0,PI0);
02553 if (ScilabGCGif.CurColorStatus == 1)
02554 {
02555 ScilabGCGif.IDLastPattern = ScilabGCGif.Numcolors - 1;
02556 }
02557
02558 }