Geant4-11
SbPainterPS.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26/*----------------------------HEPVis----------------------------------------*/
27/* */
28/* Node: SbPainterPS */
29/* Author: Guy Barrand */
30/* */
31/*--------------------------------------------------------------------------*/
32// this :
33#include <HEPVis/SbPainterPS.h>
34
35//#include <HEPVis/SbString.h>
36#define STRDUP(str) ((str) != NULL ? (::strcpy((char*)::malloc((unsigned)::strlen(str) + 1), str)) : (char*)NULL)
37#define STRDEL(str) {if((str)!=NULL) {::free(str);str=NULL;}}
38
39//#define DEBUG
40#include <stdlib.h>
41#include <string.h>
42#include <stdio.h>
43#include <stdarg.h>
44#include <time.h>
45#include <locale.h>
46
47#define METAFILE_DEFAULT "out.ps"
48#define METAFILE_SCALE 1.
49
50static char* GetDate();
51static double ConvertRGB_ToGrey(double,double,double);
54)
55:fDeviceWidth((8.5-1.) * 72. * METAFILE_SCALE) /* 540. * METAFILE_SCALE */
56,fDeviceHeight(11. * 72. * METAFILE_SCALE) /* 792. * METAFILE_SCALE */
57,fPageNumber(0)
58,fMarkerSize(2.)
59,fFile(NULL)
60,fFileName(NULL)
61,fGSave(0)
62,fBufferCount(0)
63,fBufferString(NULL)
66{
67 fParams.shade = Color;
68 fParams.portrait = 1;
69 fParams.nbit = 2;
70 fParams.doBack = 1;
71 fParams.lineWidth = -1.;
72 fBufferPointer[0] = '\0';
73#ifdef WIN32
74 ::setlocale(LC_NUMERIC,"USA");
75#endif
76}
79)
82{
83 if(fFile!=NULL) closeStream ();
85 fBufferString = NULL;
86 if(fGSave!=0) {
87 ::printf("SbPainterPS : bad gsave/grestore balance : %d.\n",fGSave);
88 }
89}
94)
97{
98 if(fFile==NULL) openFileForWriting(NULL);
99 if(fFile==NULL) return;
103}
106)
109{
110 if(fFile==NULL) return;
111 putFrameInStream(0.0,0.0,0.0,(float)fWindowWidth,(float)fWindowHeight);
114}
117 float aRed
118,float aGreen
119,float aBlue
120)
123{
124 if(fFile==NULL) return;
125 putBackgroundInStream(aRed,aGreen,aBlue,
126 (float)fWindowWidth,(float)fWindowHeight);
127}
128/*
130void SbPainterPS::drawPrimitive (
131 SbPrimitiveType aType
132,int aPointn
133,float* aXs
134,float* aYs
135,float* //aZs
136,const SbPainterContext& aAtb
137)
140{
141 if(fFile==NULL) return;
142 switch(aType) {
143 case SbPrimitivePoints:
144 drawMarkers(aPointn,
145 aXs,aYs,
146 aAtb.fRed,aAtb.fGreen,aAtb.fBlue,
147 aAtb.fMarkerStyle,aAtb.fMarkerSize);
148 break;
149 case SbPrimitiveLineStrip:
150 case SbPrimitiveLineLoop:
151 drawLines(aPointn,
152 aXs,aYs,
153 aAtb.fRed,aAtb.fGreen,aAtb.fBlue,
154 aAtb.fLineStyle,aAtb.fLineWidth);
155 break;
156 case SbPrimitivePolygon:
157 drawPolygon(aPointn,
158 aXs,aYs,
159 aAtb.fRed,aAtb.fGreen,aAtb.fBlue,
160 aAtb.fAreaStyle);
161 break;
162 default:
163 break;
164 }
165}
167void SbPainterPS::drawPolygon(
168 int aPointn
169,float* aXs
170,float* aYs
171,float aRed
172,float aGreen
173,float aBlue
174,const SbAreaStyle& //aStyle
175)
178{
179 if(fFile==NULL) return;
180 if(aPointn<=0) return;
181 putNewPathInStream();
182 putMoveInStream(aXs[0],aYs[0]);
183 for(int count=1;count<aPointn;count++) {
184 putLineToInStream(aXs[count] - aXs[count-1],
185 aYs[count] - aYs[count-1]);
186 }
187 if ( (aXs[0]==aXs[aPointn-1]) &&
188 (aYs[0]==aYs[aPointn-1]) )
189 putClosePathInStream();
190 putRGB_InStream(aRed,aGreen,aBlue);
191 putFillInStream();
192}
194void SbPainterPS::drawLines(
195 int aPointn
196,float* aXs
197,float* aYs
198,float aRed
199,float aGreen
200,float aBlue
201,const SbLineStyle& aStyle
202,int aWidth
203)
206{
207 if(fFile==NULL) return;
208 if(aPointn<=0) return;
209 putMoveInStream(aXs[0],aYs[0]);
210 for(int count=1;count<aPointn;count++) {
211 putLineToInStream(aXs[count] - aXs[count-1],
212 aYs[count] - aYs[count-1]);
213 }
214 if ( (aXs[0]==aXs[aPointn-1]) &&
215 (aYs[0]==aYs[aPointn-1]) )
216 putClosePathInStream();
217 putRGB_InStream(aRed,aGreen,aBlue);
218 putLineWidthInStream(aWidth);
219 putCapInStream(1);
220 putLineStyleInStream(aStyle);
221 putStrokeInStream();
222}
224void SbPainterPS::drawMarkers (
225 int aPointn
226,float* aXs
227,float* aYs
228,float aRed
229,float aGreen
230,float aBlue
231,const SbMarkerStyle& aStyle
232,int aSize
233)
236{
237 if(fFile==NULL) return;
238 float mark_size = (float)(aSize <=0 ? 1. : aSize);
239 mark_size *= 0.6F;
240 if(aStyle==SbMarkerCircleLine) {
241 putNewPathInStream();
242 int icount = 1;
243 for(int count=0;count<aPointn;count++) {
244 putCircleInStream(aXs[count],aYs[count],mark_size);
245#define MAX_PATH_POINT 100
246 if(icount==MAX_PATH_POINT) {
247 putRGB_InStream(aRed,aGreen,aBlue);
248 putLineWidthInStream(1);
249 putCapInStream(1);
250 putStrokeInStream();
251 icount = 1;
252 if(count!=aPointn-1) putNewPathInStream();
253 } else {
254 icount++;
255 }
256 }
257 putRGB_InStream(aRed,aGreen,aBlue);
258 putLineWidthInStream(1);
259 putCapInStream(1);
260 putStrokeInStream();
261 } else {
262 putNewPathInStream();
263 int icount = 1;
264 for(int count=0;count<aPointn;count++) {
265 putMoveInStream(aXs[count],aYs[count]);
266 putMarkerSizeInStream(mark_size);
267 putMarkerStyleInStream(aStyle);
268 if(icount==MAX_PATH_POINT) {
269 putRGB_InStream(aRed,aGreen,aBlue);
270 putLineWidthInStream(1);
271 putCapInStream(1);
272 putStrokeInStream();
273 icount = 1;
274 if(count!=aPointn-1) putNewPathInStream();
275 } else {
276 icount++;
277 }
278 }
279 putRGB_InStream(aRed,aGreen,aBlue);
280 putLineWidthInStream(1);
281 putCapInStream(1);
282 putStrokeInStream();
283 }
284}
285*/
291 int aShade
292)
295{
296 fParams.shade = aShade;
297}
300 int aPortrait
301)
304{
305 fParams.portrait = aPortrait;
306}
309 int aDoback
310)
313{
314 fParams.doBack = aDoback;
315}
318 int aNbit
319)
322{
323 if( (aNbit==2) || (aNbit==4) || (aNbit==8) )
324 fParams.nbit = aNbit;
325 else
326 fParams.nbit = 2;
327}
330 int aWidth
331)
334{
335 fParams.lineWidth = (float)aWidth;
336}
341 const char* aString
342)
345{
347 fFileName = STRDUP(aString);
348}
351) const
354{
355 return fFileName;
356}
359)
362{
363 return fFile;
364}
367 const char* aString
368)
371{
372 if(fFile!=NULL) closeStream ();
373 if( (aString==NULL) || (*aString=='\0') ) {
374 if( (fFileName==NULL) || (*fFileName=='\0') ) { // Take default name :
375 fFile = ::fopen(METAFILE_DEFAULT,"wb");
378 } else {
379 fFile = ::fopen(fFileName,"wb");
380 }
381 } else {
382 fFile = ::fopen(aString,"wb");
384 fFileName = STRDUP(aString);
385 }
386 if(fFile==NULL) return;
387
388 fBufferCount = 0;
390 fPageNumber = 0;
391 // Header :
392 printFLN ("%%!PS-Adobe-2.0");
393 printFLN ("%%%%Creator: HEPVis::SbPainterPS.");
394 printFLN("%%%%CreationDate: %s",GetDate());
395 printFLN("%%%%Title: %s",fFileName);
396 printFLN("%%%%Pages: (atend)");
397 printFLN("%%%%BoundingBox: 0 0 %d %d",
398 (int)fDeviceWidth,(int)fDeviceHeight);
399 printFLN("%%%%DocumentFonts: Courier-Bold");
400 printFLN("%%%%DocumentPaperSizes: a4");
401 printFLN("%%%%EndComments");
402 // PostScript :
404 // General :
405 putInStreamF("/n {newpath} def ");
406 putInStreamF("/cl {closepath} def ");
407 putInStreamF("/s {stroke} def ");
408 putInStreamF("/f {fill} def ");
409 // Move :
410 putInStreamF("/m {moveto} def ");
411 putInStreamF("/rm {rmoveto} def ");
412 putInStreamF("/rl {rlineto} def ");
413 // Line :
414 putInStreamF("/lc {setlinecap} def ");
415 putInStreamF("/lw {setlinewidth} def ");
416 putInStreamF("/rgb {setrgbcolor} def ");
417 putInStreamF("/ss {[] 0 setdash} def ") ; /* style solid */
418 putInStreamF("/sd {[12 6] 0 setdash} def "); /* style dashed */
419 putInStreamF("/so {[6 12] 0 setdash} def "); /* style dotted */
420 putInStreamF("/sdo {[18 12 6 12] 0 setdash} def "); /* style dash dotted */
421 // Mark :
422 fMarkerSize = 2.;
423 putInStreamF("/ms 2. def /msi .5 def "); /* mark size */
424 putInStreamF("/cross {ms ms scale -1. -1. rm ");
425 putInStreamF("2. 2. rl 0. -2. rm -2. 2. rl msi msi scale} def ");
426 putInStreamF("/plus {ms ms scale -1. 0. rm 2. 0. rl ");
427 putInStreamF("-1. 1. rm 0. -2. rl msi msi scale} def ");
428 putInStreamF("/asterisk {ms ms scale -1. 0. rm 2. 0. rl -1. 1. rm ");
429 putInStreamF("0. -2. rl 0. 1. rm -0.707 -0.707 rm 1.414 1.414 rl ");
430 putInStreamF("0. -1.414 rm -1.414 1.414 rl msi msi scale} def ");
431 putInStreamF("/triangle {ms ms scale 0. 1. rm -0.6 -1.5 rl ");
432 putInStreamF("1.2 0. rl -0.6 1.5 rl msi msi scale} def ");
433 // Text :
434 putInStreamF("/sh {show} def ");
435 putInStreamF("/df {/Courier-Bold findfont} def ");
436 putInStreamF("/mf {makefont setfont} def ");
437 printFLN("%%%%EndProlog");
438}
441)
444{
445 if(fFile==NULL) return;
447 printFLN("%%%%Trailer");
448 printFLN("%%%%Pages: %d",fPageNumber);
449 printFLN("%%%%EOF");
450 if(fFile!=NULL) ::fclose(fFile);
451 fFile = NULL;
453 fFileName = NULL;
454}
457 const char* aFormat
458,...
459)
462{
463 if(fFile==NULL) return;
464 va_list args;
465 va_start(args,aFormat);
466 printV(aFormat,args);
467 va_end(args);
468 int length = ::strlen(fBufferString);
469 if(length>METAFILE_RECORD_LENGTH) {
470 ::printf("SoPostScript::putInStreamF overflow\n");
471 return;
472 }
473 int nlength = fBufferCount + length;
474 if(nlength>METAFILE_RECORD_LENGTH) {
476 if(::fprintf(fFile,"%s\n",(char*)fBufferPointer)<0) {
477 ::printf("SoPostScript::putInStreamF fprintf error\n");
478 }
479 fBufferCount = 0;
480 nlength = length;
481 }
482 unsigned char* pointer = fBufferPointer + fBufferCount;
483 ::strcpy((char*)pointer,fBufferString);
484 fBufferCount = nlength;
485}
488 const char* aFormat
489,...
490)
493{
494 if(fFile==NULL) return;
495 va_list args;
496 va_start(args,aFormat);
497 printV(aFormat,args);
498 va_end(args);
499/* put buffer in file */
500 if(fBufferCount>0) {
502 if(::fprintf (fFile,"%s\n",(char*)fBufferPointer)<0) {
503 ::printf("SbPainterPS::printFLN fprintf error\n");
504 }
505 fBufferCount = 0;
506 }
507/* put comment in file */
508 if(::fprintf (fFile,"%s\n",fBufferString)<0) {
509 ::printf("SbPainterPS::printFLN fprintf error\n");
510 }
511}
514 const char* This
515,va_list aArgs
516)
519{
520#define MAX_STR 2048
521 if(fBufferString==NULL) {
522 fBufferString = (char*)::malloc(MAX_STR * sizeof(char));
523 if(fBufferString==NULL) return;
524 }
525 fBufferString[MAX_STR-1] = '\0';
526 ::vsprintf(fBufferString,This,aArgs);
527 if(fBufferString[MAX_STR-1]!='\0') {
528 ::printf("SbPainterPS::printV overflow\n");
529 fBufferString[0] = '\0';
530 }
531}
537 float aWidth
538,float aHeight
539)
542{
543 if(aWidth <=0.) aWidth = 100.;
544 if(aHeight<=0.) aHeight = 100.;
545
548 (float)(fDeviceHeight/30.));
549
550 float scale;
552 scale = (aHeight<=aWidth ?
553 fDeviceWidth /aWidth : fDeviceWidth /aHeight );
554 else
555 scale = (aHeight<=aWidth ?
556 fDeviceHeight /aWidth : fDeviceHeight /aHeight );
557
558 float xtra,ytra;
559 if(fParams.portrait==1) {
560 xtra = (fDeviceWidth - scale * aWidth)/2;
561 ytra = (fDeviceHeight - scale * aHeight)/2;
562 } else {
565 xtra = (fDeviceHeight - scale * aWidth)/2;
566 ytra = (fDeviceWidth - scale * aHeight)/2;
567 }
568 putTranslationInStream (xtra,ytra);
569
570 putScaleInStream (scale,scale);
571}
577)
580{
581 putInStreamF("gsave ");
582 fGSave++;
583}
586)
589{
590 putInStreamF("grestore ");
591 fGSave--;
592}
595 float aX
596,float aY
597)
600{
601 putInStreamF("%.2f %.2f translate ",aX,aY);
602}
605 float aX
606,float aY
607)
610{
611 putInStreamF("%.2f %.2f scale ",aX,aY);
612}
615)
618{
619 fPageNumber++;
620 printFLN("%%%%Page: %d %d",fPageNumber,fPageNumber);
622}
625)
628{
629 putInStreamF("showpage ");
631}
634 float aR
635,float aG
636,float aB
637)
640{
641 if(fParams.shade==Color)
642 putInStreamF("%.2f %.2f %.2f rgb ",aR,aG,aB);
643 else if(fParams.shade==Grey)
644 putInStreamF("%.2f setgray ",convertRGB_ToGrey(aR,aG,aB));
645 else if(fParams.shade==BlackWhite)
646 putInStreamF("0. setgray ",convertRGB_ToGrey(aR,aG,aB));
647}
650 int aWidth
651)
654{
655 if(fParams.lineWidth<0.) {
656 if(aWidth==1) {
657 putInStreamF("%.1f lw ",0.5); // For a better rendering.
658 } else {
659 putInStreamF("%.1f lw ",(float)(aWidth));
660 }
661 } else {
662 putInStreamF("%.1f lw ",fParams.lineWidth);
663 }
664}
667 float aSize
668)
671{
672 if(aSize==fMarkerSize) return;
673 fMarkerSize = aSize;
674 putInStreamF("/ms %g def /msi %g def ",aSize,1./aSize);
675}
676/*
678void SbPainterPS::putMarkerStyleInStream (
679 SbMarkerStyle aStyle
680)
683{
684 switch (aStyle) {
685 case SbMarkerPlus:
686 putInStreamF("plus ");
687 break;
688 case SbMarkerAsterisk:
689 case SbMarkerStar:
690 putInStreamF("asterisk ");
691 break;
692 case SbMarkerCross:
693 putInStreamF("cross ");
694 break;
695 case SbMarkerTriangleUpLine:
696 putInStreamF("triangle ");
697 break;
698 default:
699 putLineToInStream(0.,0.);
700 break;
701 }
702}
703*/
706 float aR
707,float aG
708,float aB
709,float aWidth
710,float aHeight
711)
714{
716 putMoveInStream(0.,0.);
717 putLineToInStream(aWidth,0.);
718 putLineToInStream(0.,aHeight);
719 putLineToInStream(-aWidth,0.);
720 putLineToInStream(0.,-aHeight);
722 if(fParams.doBack==1) {
723 // Back :
725 putRGB_InStream(aR,aG,aB);
728 }
729 // Clip :
730 putInStreamF("clip ");
731}
734 float aR
735,float aG
736,float aB
737,float aWidth
738,float aHeight
739)
742{
744 putMoveInStream(0.,0.);
745 putLineToInStream(aWidth,0.);
746 putLineToInStream(0.,aHeight);
747 putLineToInStream(-aWidth,0.);
748 putLineToInStream(0.,-aHeight);
750 putRGB_InStream(aR,aG,aB);
753 putInStreamF("ss ");
755}
758 float aRed
759,float aGreen
760,float aBlue
761)
764{
765 return (0.3F * aRed + 0.59F * aGreen + 0.11F * aBlue);
766}
769 float aX
770)
773{
774 putInStreamF("%.2f rotate ",aX);
775}
778)
781{
782 putInStreamF("n ");
783}
786)
789{
790 putInStreamF("s ");
791}
794)
797{
798 putInStreamF("f ");
799}
802)
805{
806 putInStreamF("cl ");
807}
810 int aX
811)
814{
815 putInStreamF("%1d lc ",aX);
816}
819 float aX
820,float aY
821)
824{
825 putInStreamF ("%.2f %.2f rl ",aX,aY);
826}
829 float aX
830,float aY
831)
834{
835 putInStreamF ("%.2f %.2f m ",aX,aY);
836}
839 float aX
840,float aY
841,float aR
842)
845{
846 putInStreamF("%.2f %.2f %.2f 0 360 arc s ",aX,aY,aR);
847}
848/*
850void SbPainterPS::putLineStyleInStream(
851 SbLineStyle aStyle
852)
855{
856 switch(aStyle) {
857 case SbLineSolid:putInStreamF("ss ") ;break;
858 case SbLineDashed:putInStreamF("sd ") ;break;
859 case SbLineDotted:putInStreamF("so ") ;break;
860 case SbLineDashDotted:putInStreamF("sdo ");break;
861 }
862}
863*/
870 unsigned int aWidth
871,unsigned int aHeight
872,GetRGB_Function aProc
873)
876{
877 if((aWidth<=0)||(aHeight<=0)) return;
878 if(!aProc) return;
879
881 putInStreamF ("%d %d scale ", aWidth, aHeight );
882 int status = 1;
883 int nbhex;
884 unsigned int row,col,col_max;
885 double dr,dg,db;
886 typedef unsigned char Uchar;
887 Uchar red,green,blue,b;
888 if(fParams.shade!=0) { /*grey*/
889 putInStreamF ("/picstr %d string def ",aWidth);
890 putInStreamF ("%d %d %d ",aWidth,aHeight,8);
891 putInStreamF ("[ %d 0 0 -%d 0 %d ] ",aWidth,aHeight,aHeight);
892 putInStreamF ("{ currentfile picstr readhexstring pop } " );
893 printFLN ("image " );
894 for ( row = 0; row < aHeight; row++ ){
895 for ( col = 0; col < aWidth; col++){
896 double fgrey;
897 Uchar grey;
898 status = aProc(col,row,dr,dg,db)==0 ? 0 : status;
899 fgrey = ConvertRGB_ToGrey(dr,dg,db);
900 grey = (Uchar) ( 255. * fgrey);
901 writeByte (grey);
902 }
903 }
904 nbhex = aWidth * aHeight * 2;
905 printFLN ("%%%% nbhex digit :%d ",nbhex);
906 printFLN ("%%%% nbhex/record_length :%d ",nbhex/METAFILE_RECORD_LENGTH);
907 printFLN ("%%%% nbhex%%record_length :%d ",nbhex%METAFILE_RECORD_LENGTH);
908 }else if(fParams.nbit==2){
909 int nbyte2;
910 nbyte2 = (aWidth * 3)/4;
911 nbyte2 /=3;
912 nbyte2 *=3;
913 col_max = (nbyte2 * 4)/3;
914 /* 2 bit for r and g and b */
915 /* rgbs following each other */
916 putInStreamF ("/rgbstr %d string def ",nbyte2);
917 putInStreamF ("%d %d %d ",col_max,aHeight,2);
918 putInStreamF ("[ %d 0 0 -%d 0 %d ] ",col_max,aHeight,aHeight);
919 putInStreamF ("{ currentfile rgbstr readhexstring pop } " );
920 putInStreamF ("false 3 " );
921 printFLN ("colorimage " );
922 for ( row = 0; row < aHeight; row++ ){
923 for ( col = 0; col < col_max; col+=4){
924 status = aProc(col,row,dr,dg,db)==0 ? 0 : status;
925 red = (Uchar) ( 3. * dr);
926 green = (Uchar) ( 3. * dg);
927 blue = (Uchar) ( 3. * db);
928 b = red;
929 b = (b<<2)+green;
930 b = (b<<2)+blue;
931 status = aProc(col+1,row,dr,dg,db)==0 ? 0 : status;
932 red = (Uchar) ( 3. * dr);
933 green = (Uchar) ( 3. * dg);
934 blue = (Uchar) ( 3. * db);
935 b = (b<<2)+red;
936 writeByte (b);
937
938 b = green;
939 b = (b<<2)+blue;
940 status = aProc(col+2,row,dr,dg,db)==0 ? 0 : status;
941 red = (Uchar) ( 3. * dr);
942 green = (Uchar) ( 3. * dg);
943 blue = (Uchar) ( 3. * db);
944 b = (b<<2)+red;
945 b = (b<<2)+green;
946 writeByte (b);
947
948 b = blue;
949 status = aProc(col+3,row,dr,dg,db)==0 ? 0 : status;
950 red = (Uchar) ( 3. * dr);
951 green = (Uchar) ( 3. * dg);
952 blue = (Uchar) ( 3. * db);
953 b = (b<<2)+red;
954 b = (b<<2)+green;
955 b = (b<<2)+blue;
956 writeByte (b);
957 }
958 }
959 }else if(fParams.nbit==4){
960 int nbyte4;
961 nbyte4 = (aWidth * 3)/2;
962 nbyte4 /=3;
963 nbyte4 *=3;
964 col_max = (nbyte4 * 2)/3;
965 /* 4 bit for r and g and b */
966 /* rgbs following each other */
967 putInStreamF ("/rgbstr %d string def ",nbyte4);
968 putInStreamF ("%d %d %d ",col_max,aHeight,4);
969 putInStreamF ("[ %d 0 0 -%d 0 %d ] ",col_max,aHeight,aHeight);
970 putInStreamF ("{ currentfile rgbstr readhexstring pop } " );
971 putInStreamF ("false 3 " );
972 printFLN ("colorimage " );
973 for ( row = 0; row < aHeight; row++ ){
974 for ( col = 0; col < col_max; col+=2){
975 status = aProc(col,row,dr,dg,db)==0 ? 0 : status;
976 red = (Uchar) ( 15. * dr);
977 green = (Uchar) ( 15. * dg);
978 putInStreamF ("%x%x",red,green);
979 blue = (Uchar) ( 15. * db);
980
981 status = aProc(col+1,row,dr,dg,db)==0 ? 0 : status;
982 red = (Uchar) ( 15. * dr);
983 putInStreamF ("%x%x",blue,red);
984 green = (Uchar) ( 15. * dg);
985 blue = (Uchar) ( 15. * db);
986 putInStreamF ("%x%x",green,blue);
987 }
988 }
989 }else{
990 int nbyte8;
991 nbyte8 = aWidth * 3;
992 /* 8 bit for r and g and b */
993 putInStreamF ("/rgbstr %d string def ",nbyte8);
994 putInStreamF ("%d %d %d ",aWidth,aHeight,8);
995 putInStreamF ("[ %d 0 0 -%d 0 %d ] ",aWidth,aHeight,aHeight);
996 putInStreamF ("{ currentfile rgbstr readhexstring pop } " );
997 putInStreamF ("false 3 " );
998 printFLN ("colorimage " );
999 for ( row = 0; row < aHeight; row++ ){
1000 for ( col = 0; col < aWidth; col++){
1001 status = aProc(col,row,dr,dg,db)==0 ? 0 : status;
1002 red = (Uchar) ( 255. * dr);
1003 writeByte (red);
1004 green = (Uchar) ( 255. * dg);
1005 writeByte (green);
1006 blue = (Uchar) ( 255. * db);
1007 writeByte (blue);
1008 }
1009 }
1010 }
1011 if(status==0)
1012 ::printf("SbPainterPS::putImageInStream: problem to retrieve some pixel rgb.\n");
1014}
1017 unsigned char a_byte
1018)
1021{
1022 unsigned char h = a_byte / 16;
1023 unsigned char l = a_byte % 16;
1024 putInStreamF ("%x%x",h,l);
1025}
1029char* GetDate (
1030)
1032// Return local date.
1034{
1035 time_t d;
1036 time(&d);
1037 char* string = ctime(&d);
1038 string[24] = '\0';
1039 return string;
1040}
1043 double a_red
1044,double a_green
1045,double a_blue
1046)
1049{
1050 return (0.30 * a_red + 0.59 * a_green + 0.11 * a_blue);
1051}
static char ** args
Definition: G4Xt.cc:51
static double ConvertRGB_ToGrey(double, double, double)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
#define STRDUP(str)
Definition: SbPainterPS.cc:36
#define METAFILE_SCALE
Definition: SbPainterPS.cc:48
#define MAX_STR
#define STRDEL(str)
Definition: SbPainterPS.cc:37
#define METAFILE_DEFAULT
Definition: SbPainterPS.cc:47
static char * GetDate()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
#define METAFILE_RECORD_LENGTH
Definition: SbPainterPS.h:114
unsigned char Uchar
void putMoveInStream(float, float)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:828
void endTraversal()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:105
int fBufferCount
Definition: SbPainterPS.h:112
void putStrokeInStream()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:785
void putCircleInStream(float, float, float)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:838
void putBeginPageInStream()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:614
void putClosePathInStream()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:801
void setOrientation(int)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:299
void beginTraversal()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:93
void putSaveStateInStream()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:576
void putImageInStream(unsigned int, unsigned int, GetRGB_Function)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:869
void setBackgroundDrawn(int)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:308
float fDeviceWidth
Definition: SbPainterPS.h:105
unsigned char fBufferPointer[METAFILE_RECORD_LENGTH+1]
Definition: SbPainterPS.h:115
void putNewPathInStream()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:777
void setFileName(const char *)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:340
void putCapInStream(int)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:809
void setBitsPerPixel(int)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:317
void writeByte(unsigned char)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void clearColorBuffer(float, float, float)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:116
void setColorScheme(int)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:290
float convertRGB_ToGrey(float, float, float)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:757
void putPageScaleInStream(float, float)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:536
struct SbPainterPS::@111 fParams
FILE * fFile
Definition: SbPainterPS.h:109
void putInStreamF(const char *,...)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:456
void putLineToInStream(float, float)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:818
void openFileForWriting(const char *)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:366
void printV(const char *, va_list)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:513
~SbPainterPS()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:78
void setLineWidth(int)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:329
float fDeviceHeight
Definition: SbPainterPS.h:106
void putRestoreStateInStream()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:585
void putEndPageInStream()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:624
void * getStream()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:358
void printFLN(const char *,...)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:487
void putRotateInStream(float)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:768
void putLineWidthInStream(int)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:649
void putMarkerSizeInStream(float)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:666
char * fBufferString
Definition: SbPainterPS.h:113
void putRGB_InStream(float, float, float)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:633
void putFillInStream()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:793
void putBackgroundInStream(float, float, float, float, float)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:705
char * fFileName
Definition: SbPainterPS.h:110
void putFrameInStream(float, float, float, float, float)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:733
const char * getFileName() const
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:350
void putScaleInStream(float, float)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:604
void putTranslationInStream(float, float)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:594
void closeStream()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbPainterPS.cc:440
float fMarkerSize
Definition: SbPainterPS.h:108
int fWindowWidth
Definition: SbPainter.h:72
int fWindowHeight
Definition: SbPainter.h:72