26 #ifdef G4VIS_BUILD_OI_DRIVER
38 #define STRDUP(str) ((str) != NULL ? (::strcpy((char*)::malloc((unsigned)::strlen(str) + 1), str)) : (char*)NULL)
39 #define STRDEL(str) {if((str)!=NULL) {::free(str);str=NULL;}}
49 #define METAFILE_DEFAULT "out.ps"
50 #define METAFILE_SCALE 1.
52 static char* GetDate();
53 static double ConvertRGB_ToGrey(
double,
double,
double);
57 :fDeviceWidth((8.5-1.) * 72. * METAFILE_SCALE)
58 ,fDeviceHeight(11. * 72. * METAFILE_SCALE)
69 fParams.shade = Color;
73 fParams.lineWidth = -1.;
74 fBufferPointer[0] =
'\0';
76 ::setlocale(LC_NUMERIC,
"USA");
89 ::printf(
"SbPainterPS : bad gsave/grestore balance : %d.\n",
fGSave);
101 if(
fFile==NULL)
return;
112 if(
fFile==NULL)
return;
126 if(
fFile==NULL)
return;
325 if( (aNbit==2) || (aNbit==4) || (aNbit==8) )
337 fParams.lineWidth = (float)aWidth;
375 if( (aString==NULL) || (*aString==
'\0') ) {
377 fFile = ::fopen(METAFILE_DEFAULT,
"wb");
384 fFile = ::fopen(aString,
"wb");
388 if(
fFile==NULL)
return;
395 printFLN (
"%%%%Creator: HEPVis::SbPainterPS.");
396 printFLN(
"%%%%CreationDate: %s",GetDate());
399 printFLN(
"%%%%BoundingBox: 0 0 %d %d",
401 printFLN(
"%%%%DocumentFonts: Courier-Bold");
402 printFLN(
"%%%%DocumentPaperSizes: a4");
427 putInStreamF(
"2. 2. rl 0. -2. rm -2. 2. rl msi msi scale} def ");
429 putInStreamF(
"-1. 1. rm 0. -2. rl msi msi scale} def ");
430 putInStreamF(
"/asterisk {ms ms scale -1. 0. rm 2. 0. rl -1. 1. rm ");
431 putInStreamF(
"0. -2. rl 0. 1. rm -0.707 -0.707 rm 1.414 1.414 rl ");
432 putInStreamF(
"0. -1.414 rm -1.414 1.414 rl msi msi scale} def ");
433 putInStreamF(
"/triangle {ms ms scale 0. 1. rm -0.6 -1.5 rl ");
434 putInStreamF(
"1.2 0. rl -0.6 1.5 rl msi msi scale} def ");
447 if(
fFile==NULL)
return;
465 if(
fFile==NULL)
return;
467 va_start(args,aFormat);
472 ::printf(
"SoPostScript::putInStreamF overflow\n");
479 ::printf(
"SoPostScript::putInStreamF fprintf error\n");
486 fBufferCount = nlength;
496 if(
fFile==NULL)
return;
498 va_start(args,aFormat);
505 ::printf(
"SbPainterPS::printFLN fprintf error\n");
511 ::printf(
"SbPainterPS::printFLN fprintf error\n");
530 ::printf(
"SbPainterPS::printV overflow\n");
545 if(aWidth <=0.) aWidth = 100.;
546 if(aHeight<=0.) aHeight = 100.;
554 scale = (aHeight<=aWidth ?
557 scale = (aHeight<=aWidth ?
767 return (0.3F * aRed + 0.59F * aGreen + 0.11F * aBlue);
873 ,
unsigned int aHeight
874 ,GetRGB_Function aProc
879 if((aWidth<=0)||(aHeight<=0))
return;
886 unsigned int row,
col,col_max;
888 typedef unsigned char Uchar;
889 Uchar red,green,blue,
b;
893 putInStreamF (
"[ %d 0 0 -%d 0 %d ] ",aWidth,aHeight,aHeight);
894 putInStreamF (
"{ currentfile picstr readhexstring pop } " );
896 for ( row = 0; row < aHeight; row++ ){
897 for ( col = 0; col < aWidth; col++){
900 status = aProc(col,row,dr,dg,db)==0 ? 0 : status;
901 fgrey = ConvertRGB_ToGrey(dr,dg,db);
902 grey = (Uchar) ( 255. * fgrey);
906 nbhex = aWidth * aHeight * 2;
907 printFLN (
"%%%% nbhex digit :%d ",nbhex);
912 nbyte2 = (aWidth * 3)/4;
915 col_max = (nbyte2 * 4)/3;
920 putInStreamF (
"[ %d 0 0 -%d 0 %d ] ",col_max,aHeight,aHeight);
921 putInStreamF (
"{ currentfile rgbstr readhexstring pop } " );
924 for ( row = 0; row < aHeight; row++ ){
925 for ( col = 0; col < col_max; col+=4){
926 status = aProc(col,row,dr,dg,db)==0 ? 0 : status;
927 red = (Uchar) ( 3. * dr);
928 green = (Uchar) ( 3. * dg);
929 blue = (Uchar) ( 3. * db);
933 status = aProc(col+1,row,dr,dg,db)==0 ? 0 : status;
934 red = (Uchar) ( 3. * dr);
935 green = (Uchar) ( 3. * dg);
936 blue = (Uchar) ( 3. * db);
942 status = aProc(col+2,row,dr,dg,db)==0 ? 0 : status;
943 red = (Uchar) ( 3. * dr);
944 green = (Uchar) ( 3. * dg);
945 blue = (Uchar) ( 3. * db);
951 status = aProc(col+3,row,dr,dg,db)==0 ? 0 : status;
952 red = (Uchar) ( 3. * dr);
953 green = (Uchar) ( 3. * dg);
954 blue = (Uchar) ( 3. * db);
963 nbyte4 = (aWidth * 3)/2;
966 col_max = (nbyte4 * 2)/3;
971 putInStreamF (
"[ %d 0 0 -%d 0 %d ] ",col_max,aHeight,aHeight);
972 putInStreamF (
"{ currentfile rgbstr readhexstring pop } " );
975 for ( row = 0; row < aHeight; row++ ){
976 for ( col = 0; col < col_max; col+=2){
977 status = aProc(col,row,dr,dg,db)==0 ? 0 : status;
978 red = (Uchar) ( 15. * dr);
979 green = (Uchar) ( 15. * dg);
981 blue = (Uchar) ( 15. * db);
983 status = aProc(col+1,row,dr,dg,db)==0 ? 0 : status;
984 red = (Uchar) ( 15. * dr);
986 green = (Uchar) ( 15. * dg);
987 blue = (Uchar) ( 15. * db);
997 putInStreamF (
"[ %d 0 0 -%d 0 %d ] ",aWidth,aHeight,aHeight);
998 putInStreamF (
"{ currentfile rgbstr readhexstring pop } " );
1001 for ( row = 0; row < aHeight; row++ ){
1002 for ( col = 0; col < aWidth; col++){
1003 status = aProc(col,row,dr,dg,db)==0 ? 0 : status;
1004 red = (Uchar) ( 255. * dr);
1006 green = (Uchar) ( 255. * dg);
1008 blue = (Uchar) ( 255. * db);
1014 ::printf(
"SbPainterPS::putImageInStream: problem to retrieve some pixel rgb.\n");
1019 unsigned char a_byte
1024 unsigned char h = a_byte / 16;
1025 unsigned char l = a_byte % 16;
1039 char*
string = ctime(&d);
1044 double ConvertRGB_ToGrey(
1052 return (0.30 * a_red + 0.59 * a_green + 0.11 * a_blue);