| Bsoft 2.0.5 Bernard's software package

rwPostScript.cpp
Go to the documentation of this file.
1
9 #include "ps_plot.h"
10 #include "rwPostScript.h"
11 #include "utilities.h"
12
13 // Declaration of global variables
14 extern int verbose; // Level of output to the screen
15
27 int writePostScriptImage(Bimage* p)
28 {
29 if ( p->sizeZ()*p->sizeY() < 2 ) {
30 Bplot* plot = p->plot();
31 ps_plot(p->file_name(), plot);
32 delete plot;
33 return 0;
34 }
35
36 p->change_type(UCharacter);
37
38 long i = 0, j = 0, n, x, y, z, c, nc, nr;
39 long line_length = 32;
40 long width = 600, height = 800;
41 float scale = 1;
42 unsigned char* data = p->data_pointer();
43
44 long cols = (int) (sqrt((p->sizeZ() - 1)*width*1.0/height) + 1);
45 long rows = (int) ((p->sizeZ() - 1)*1.0/cols + 1);
46
47 if ( cols*p->sizeX() > width ) scale = width*1.0/(cols*p->sizeX());
48 if ( scale*rows*p->sizeY() > height ) scale = height*1.0/(rows*p->sizeY());
49
50 if ( p->sizeZ()*p->sizeY() < 2 ) {
51 width = 600;
52 height = 800;
53 }
54
55 ofstream* fimg = ps_open_and_init(p->file_name(), p->file_name(), p->images(), width, height);
56
57 *fimg << "%Command line: " << p->label() << endl;
58 *fimg << "/Helvetica findfont 10 scalefont setfont" << endl;
59 for ( n=0; n<p->images(); n++ ) {
60 *fimg << "%%Page: Image " << n+1 << endl;
61 *fimg << "gsave" << endl;
62 if ( p->compound_type() == TRGB )
63 *fimg << "/DeviceRGB setcolorspace" << endl;
64 else
65 *fimg << "/DeviceGray setcolorspace" << endl;
66 *fimg << scale << " " << scale << " scale" << endl;
67 for ( z=0; z<p->sizeZ(); z++ ) {
68 *fimg << "gsave" << endl;
69 nr = z/cols;
70 nc = z - cols*nr;
71 *fimg << nc*p->sizeX() << " " << nr*p->sizeY() << " translate" << endl;
72 *fimg << "<<" << endl;
73 *fimg << " /ImageType 1" << endl;
74 *fimg << " /Width " << p->sizeX() << " /Height " << p->sizeY() << endl;
75 *fimg << " /BitsPerComponent 8" << endl;
76 if ( p->compound_type() == TRGB )
77 *fimg << " /Decode [0 1 0 1 0 1]" << endl;
78 else
79 *fimg << " /Decode [0 1]" << endl;
80 *fimg << " /ImageMatrix [1 0 0 1 0 0]" << endl;
81 *fimg << " /DataSource currentfile /ASCIIHexDecode filter" << endl;
82 *fimg << ">>" << endl;
83 *fimg << "%%BeginData: " << p->channels()*p->sizeX()*p->sizeY() << " hex bytes" << endl;
84 *fimg << "image" << endl;
85 *fimg << hex << right << setfill('0');
86 j = 0;
87 for ( y=0; y<p->sizeY(); y++ ) {
88 for ( x=0; x<p->sizeX(); x++ ) {
89 for ( c=0; c<p->channels(); c++ ) {
90 // i = (((n*p->z + z)*p->sizeY() + y)*p->sizeX() + x)*p->channels() + c;
91 i = p->index(c,x,y,z,n);
92 if ( j >= line_length ) {
93 *fimg << endl;
94 j = 0;
95 }
96 *fimg << setw(2) << (int)data[i];
97 j++;
98 }
99 }
100 }
101 *fimg << ">";
102 if ( j <= line_length ) *fimg << endl;
103 *fimg << dec << "%%EndData" << endl;
104 if ( p->sizeZ() > 1 ) {
105 *fimg << "1 1 0 setrgbcolor" << endl;
106 *fimg << "0 0.9 moveto" << endl << "(" << z << ") show" << endl;
107 }
108 *fimg << "grestore" << endl;
109 }
110 *fimg << "showpage" << endl;
111 *fimg << "grestore" << endl;
112 }
113
114 ps_close(fimg);
115
116 return 0;
117 }
118
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
utilities.h
Header file for general utilities.
Bimage::compound_type
CompoundType compound_type()
Definition: Bimage.h:351
Bimage::index
long index(long nx, long ny) const
Definition: Bimage.h:383
ps_open_and_init
ofstream * ps_open_and_init(Bstring filename, Bstring title, int npages, int width, int height)
Opens and initializes a postscript file.
Definition: ps_plot.cpp:31
Bimage::file_name
void file_name(string s)
Definition: Bimage.h:230
verbose
int verbose
rwPostScript.h
Header file for (reading and) writing postscript image files.
Bimage
General image parameter class.
Definition: Bimage.h:163
Bimage::label
void label(string s)
Definition: Bimage.h:235
writePostScriptImage
int writePostScriptImage(Bimage *p)
Writing a postscript image format.
Definition: rwPostScript.cpp:27
Bimage::channels
long channels()
Definition: Bimage.h:371
ps_plot
int ps_plot(Bstring filename, Bplot *plot)
Generates postscript graphs.
Definition: ps_plot.cpp:128
TRGB
Definition: Bimage.h:62
Bimage::data_pointer
unsigned char * data_pointer()
Definition: Bimage.h:261
UCharacter
Definition: utilities.h:149
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:377
ps_plot.h
Header file for postscript output functions.
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:379
Bimage::images
long images()
Definition: Bimage.h:491
ps_close
int ps_close(ofstream *fps)
Closes a postscript file.
Definition: ps_plot.cpp:104
Bimage::plot
Bplot * plot()
Converts a one-dimensional image into a plot.
Definition: Bimage.cpp:3836
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:378
Bplot
Definition: Bplot.h:146