Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/visualization/OpenInventor/src/SoImageWriter.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/OpenInventor/src/SoImageWriter.cc (Version 11.3.0) and /visualization/OpenInventor/src/SoImageWriter.cc (Version 8.0.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
 25 //                                                 22 //
                                                   >>  23 #ifdef G4VIS_BUILD_OI_DRIVER
 26                                                    24 
 27 /*----------------------------HEPVis----------     25 /*----------------------------HEPVis----------------------------------------*/
 28 /*                                                 26 /*                                                                          */
 29 /* Node:             SoImageWriter                 27 /* Node:             SoImageWriter                                          */
 30 /* Author:           Guy Barrand                   28 /* Author:           Guy Barrand                                            */
 31 /*                                                 29 /*                                                                          */
 32 /*--------------------------------------------     30 /*--------------------------------------------------------------------------*/
 33                                                    31 
 34 // this :                                          32 // this :
 35 #include <HEPVis/nodes/SoImageWriter.h>            33 #include <HEPVis/nodes/SoImageWriter.h>
 36                                                    34 
 37 #include <Inventor/errors/SoDebugError.h>          35 #include <Inventor/errors/SoDebugError.h>
 38 #include <Inventor/elements/SoViewportRegionEl     36 #include <Inventor/elements/SoViewportRegionElement.h>
 39 #include <Inventor/actions/SoGLRenderAction.h>     37 #include <Inventor/actions/SoGLRenderAction.h>
 40                                                    38 
 41 #include <HEPVis/SbGL.h>                           39 #include <HEPVis/SbGL.h>
 42 #include <HEPVis/SbPainterPS.h>                    40 #include <HEPVis/SbPainterPS.h>
 43 //#include <HEPVis/SbGIF.h>                        41 //#include <HEPVis/SbGIF.h>
 44                                                    42 
 45 #include <stdlib.h>                                43 #include <stdlib.h>
 46                                                    44 
 47 typedef struct {                                   45 typedef struct {
 48   unsigned char red;                               46   unsigned char red;
 49   unsigned char green;                             47   unsigned char green;
 50   unsigned char blue;                              48   unsigned char blue;
 51 } Pixel;                                           49 } Pixel;
 52 typedef unsigned char Uchar;                       50 typedef unsigned char Uchar;
 53                                                    51 
 54 //static void getImagePixels(int,int,float*,in     52 //static void getImagePixels(int,int,float*,int&,
 55 //                         Uchar*&,Uchar*&,Uch     53 //                         Uchar*&,Uchar*&,Uchar*&,Uchar*&);
 56                                                    54 
 57 static int sWidth = 0;                             55 static int sWidth = 0;
 58 static int sHeight = 0;                            56 static int sHeight = 0;
 59 static float* sImage = 0;                          57 static float* sImage = 0;
 60 static int getRGB(unsigned int,unsigned int,do     58 static int getRGB(unsigned int,unsigned int,double&,double&,double&);
 61                                                    59 
 62 SO_NODE_SOURCE(SoImageWriter)                      60 SO_NODE_SOURCE(SoImageWriter)
 63 //////////////////////////////////////////////     61 //////////////////////////////////////////////////////////////////////////////
 64 void SoImageWriter::initClass (                    62 void SoImageWriter::initClass (
 65 )                                                  63 )
 66 //////////////////////////////////////////////     64 //////////////////////////////////////////////////////////////////////////////
 67 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     65 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 68 {                                                  66 {
 69   static bool first = true;                    <<  67   SO_NODE_INIT_CLASS(SoImageWriter,SoNode,"Node");
 70   if (first) {                                 << 
 71     first = false;                             << 
 72     SO_NODE_INIT_CLASS(SoImageWriter,SoNode,"N << 
 73   }                                            << 
 74 }                                                  68 }
 75 //////////////////////////////////////////////     69 //////////////////////////////////////////////////////////////////////////////
 76 SoImageWriter::SoImageWriter(                      70 SoImageWriter::SoImageWriter(
 77 )                                                  71 )
 78 :fEnabled(FALSE)                                   72 :fEnabled(FALSE)
 79 ,fStatus(FALSE)                                    73 ,fStatus(FALSE)
 80 //////////////////////////////////////////////     74 //////////////////////////////////////////////////////////////////////////////
 81 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     75 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 82 {                                                  76 {
 83   SO_NODE_CONSTRUCTOR(SoImageWriter);              77   SO_NODE_CONSTRUCTOR(SoImageWriter);
 84   //SO_NODE_ADD_FIELD(format,(POST_SCRIPT));       78   //SO_NODE_ADD_FIELD(format,(POST_SCRIPT));
 85   SO_NODE_ADD_FIELD(fileName,("out.ps"));          79   SO_NODE_ADD_FIELD(fileName,("out.ps"));
 86                                                    80   
 87   //SO_NODE_DEFINE_ENUM_VALUE(Format,POST_SCRI     81   //SO_NODE_DEFINE_ENUM_VALUE(Format,POST_SCRIPT);
 88   //SO_NODE_DEFINE_ENUM_VALUE(Format,GIF);         82   //SO_NODE_DEFINE_ENUM_VALUE(Format,GIF);
 89                                                    83   
 90   //SO_NODE_SET_SF_ENUM_TYPE(format,Format);       84   //SO_NODE_SET_SF_ENUM_TYPE(format,Format);
 91 }                                                  85 }
 92 //////////////////////////////////////////////     86 //////////////////////////////////////////////////////////////////////////////
 93 SoImageWriter::~SoImageWriter (                    87 SoImageWriter::~SoImageWriter (
 94 )                                                  88 )
 95 //////////////////////////////////////////////     89 //////////////////////////////////////////////////////////////////////////////
 96 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     90 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 97 {                                                  91 {
 98 }                                                  92 }
 99 //////////////////////////////////////////////     93 //////////////////////////////////////////////////////////////////////////////
100 void SoImageWriter::enable(                        94 void SoImageWriter::enable(
101 )                                                  95 )
102 //////////////////////////////////////////////     96 //////////////////////////////////////////////////////////////////////////////
103 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     97 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
104 {                                                  98 {
105   fEnabled = TRUE;                                 99   fEnabled = TRUE;
106 }                                                 100 }
107 //////////////////////////////////////////////    101 //////////////////////////////////////////////////////////////////////////////
108 void SoImageWriter::disable(                      102 void SoImageWriter::disable(
109 )                                                 103 )
110 //////////////////////////////////////////////    104 //////////////////////////////////////////////////////////////////////////////
111 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    105 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
112 {                                                 106 {
113   fEnabled = FALSE;                               107   fEnabled = FALSE;
114 }                                                 108 }
115 //////////////////////////////////////////////    109 //////////////////////////////////////////////////////////////////////////////
116 SbBool SoImageWriter::getStatus(                  110 SbBool SoImageWriter::getStatus(
117 ) const                                           111 ) const
118 //////////////////////////////////////////////    112 //////////////////////////////////////////////////////////////////////////////
119 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    113 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
120 {                                                 114 {
121   return fStatus;                                 115   return fStatus;
122 }                                                 116 }
123 //////////////////////////////////////////////    117 //////////////////////////////////////////////////////////////////////////////
124 void SoImageWriter::GLRender(                     118 void SoImageWriter::GLRender(
125  SoGLRenderAction* aAction                        119  SoGLRenderAction* aAction
126 )                                                 120 )
127 //////////////////////////////////////////////    121 //////////////////////////////////////////////////////////////////////////////
128 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    122 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
129 {                                                 123 {
130   fStatus = FALSE;                                124   fStatus = FALSE;
131   //printf("debug : SoImageWriter::GLRender :     125   //printf("debug : SoImageWriter::GLRender : enabled : %d\n",fEnabled);
132   if(!fEnabled) return;                           126   if(!fEnabled) return;
133   SbViewportRegion vpr = SoViewportRegionEleme    127   SbViewportRegion vpr = SoViewportRegionElement::get(aAction->getState());
134   const SbVec2s& win = vpr.getWindowSize();       128   const SbVec2s& win = vpr.getWindowSize();
135   int w = win[0];                                 129   int w = win[0];
136   int h = win[1];                                 130   int h = win[1];
137   if((w*h)<=0) {                                  131   if((w*h)<=0) {
138     SoDebugError::postInfo("SoImageWriter::GLR    132     SoDebugError::postInfo("SoImageWriter::GLRender","null area window !");
139     return;                                       133     return;
140   }                                               134   }
141                                                   135 
142   int x = 0;                                      136   int x = 0;
143   int y = 0;                                      137   int y = 0;
144   int s = 3 * w * h;                              138   int s = 3 * w * h;
145   float* image = new float[s];                    139   float* image = new float[s];
146   if(!image) return;                              140   if(!image) return;
147                                                   141 
148   //printf("debug : SoImageWriter::GLRender :     142   //printf("debug : SoImageWriter::GLRender : %d %d %d %d\n",x,y,w,h);
149                                                   143 
150   //glReadPixels(x,y,w,h,GL_RGB,GL_UNSIGNED_BY    144   //glReadPixels(x,y,w,h,GL_RGB,GL_UNSIGNED_BYTE,image); Don't work !
151   glReadPixels(x,y,w,h,GL_RGB,GL_FLOAT,image);    145   glReadPixels(x,y,w,h,GL_RGB,GL_FLOAT,image);
152                                                   146 
153   //Format fm = (Format)format.getValue();        147   //Format fm = (Format)format.getValue();
154   //if(fm==GIF) {                                 148   //if(fm==GIF) {  
155 /*                                                149 /*
156     FILE* file = fopen(fileName.getValue().get    150     FILE* file = fopen(fileName.getValue().getString(),"wb");
157     if(!file) {                                   151     if(!file) {
158       SoDebugError::postInfo("SoImageWriter::G    152       SoDebugError::postInfo("SoImageWriter::GLRender",
159         "can't open file \"%s\".",fileName.get    153         "can't open file \"%s\".",fileName.getValue().getString());
160     } else {                                      154     } else {
161       int coln;                                   155       int coln;
162       Uchar* rs;                                  156       Uchar* rs;
163       Uchar* gs;                                  157       Uchar* gs;
164       Uchar* bs;                                  158       Uchar* bs;
165       Uchar* data;                                159       Uchar* data;
166       getImagePixels(w,h,image,coln,rs,gs,bs,d    160       getImagePixels(w,h,image,coln,rs,gs,bs,data);
167                                                   161       
168       SbGIF::putBytesInStream(file,data,w,h,co    162       SbGIF::putBytesInStream(file,data,w,h,coln,rs,gs,bs);
169                                                   163       
170       delete [] data;                             164       delete [] data;
171                                                   165 
172       if(rs) free(rs);                            166       if(rs) free(rs);
173       if(gs) free(gs);                            167       if(gs) free(gs);
174       if(bs) free(bs);                            168       if(bs) free(bs);
175                                                   169 
176       fclose(file);                               170       fclose(file);
177                                                   171 
178       fStatus = TRUE;                             172       fStatus = TRUE;
179     }                                             173     }
180   } else {                                        174   } else {
181 */                                                175 */
182                                                   176 
183     SbPainterPS painterPS;                        177     SbPainterPS painterPS;
184     painterPS.openFileForWriting(fileName.getV    178     painterPS.openFileForWriting(fileName.getValue().getString());
185     if(!painterPS.getStream()) {                  179     if(!painterPS.getStream()) {
186       SoDebugError::postInfo("SoImageWriter::G    180       SoDebugError::postInfo("SoImageWriter::GLRender",
187         "can't open file \"%s\".",fileName.get    181         "can't open file \"%s\".",fileName.getValue().getString());
188     } else {                                      182     } else {
189       painterPS.setWindowSize(w,h);               183       painterPS.setWindowSize(w,h);
190       //painterPS.setBitsPerPixel(8);             184       //painterPS.setBitsPerPixel(8);
191       painterPS.setBitsPerPixel(4);               185       painterPS.setBitsPerPixel(4);
192       painterPS.beginTraversal();                 186       painterPS.beginTraversal();
193       painterPS.clearColorBuffer(1.,1.,1.);       187       painterPS.clearColorBuffer(1.,1.,1.);
194                                                   188 
195       sWidth = w;                                 189       sWidth = w;
196       sHeight = h;                                190       sHeight = h;
197       sImage = image;                             191       sImage = image;
198       painterPS.putImageInStream((unsigned int    192       painterPS.putImageInStream((unsigned int)w,(unsigned int)h,getRGB);
199                                                   193       
200       painterPS.endTraversal();                   194       painterPS.endTraversal();
201                                                   195       
202       painterPS.closeStream();                    196       painterPS.closeStream();
203                                                   197       
204       fStatus = TRUE;                             198       fStatus = TRUE;
205     }                                             199     }
206   //}                                             200   //}
207   delete [] image;                                201   delete [] image;
208                                                   202 
209 }                                                 203 }
210 /*                                                204 /*
211 //////////////////////////////////////////////    205 //////////////////////////////////////////////////////////////////////////////
212 void getImagePixels (                             206 void getImagePixels (
213  int aWidth                                       207  int aWidth
214 ,int aHeight                                      208 ,int aHeight
215 ,float* aImage                                    209 ,float* aImage
216 ,int& aColorn                                     210 ,int& aColorn
217 ,Uchar*& aReds                                    211 ,Uchar*& aReds
218 ,Uchar*& aGreens                                  212 ,Uchar*& aGreens
219 ,Uchar*& aBlues                                   213 ,Uchar*& aBlues
220 ,Uchar*& aData                                    214 ,Uchar*& aData
221 )                                                 215 )
222 //////////////////////////////////////////////    216 //////////////////////////////////////////////////////////////////////////////
223 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    217 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
224 {                                                 218 {
225   aColorn = 0;                                    219   aColorn = 0;
226   aReds = 0;                                      220   aReds = 0;
227   aGreens = 0;                                    221   aGreens = 0;
228   aBlues = 0;                                     222   aBlues = 0;
229   aData = 0;                                      223   aData = 0;
230   if( (aWidth * aHeight) <=0) return;             224   if( (aWidth * aHeight) <=0) return;
231   int size = 256;                                 225   int size = 256;
232   Uchar* rs = (Uchar*)malloc(size * sizeof(Uch    226   Uchar* rs = (Uchar*)malloc(size * sizeof(Uchar));
233   Uchar* gs = (Uchar*)malloc(size * sizeof(Uch    227   Uchar* gs = (Uchar*)malloc(size * sizeof(Uchar));
234   Uchar* bs = (Uchar*)malloc(size * sizeof(Uch    228   Uchar* bs = (Uchar*)malloc(size * sizeof(Uchar));
235   Uchar* data = new Uchar[aWidth * aHeight];      229   Uchar* data = new Uchar[aWidth * aHeight];
236   if( !rs || !gs || !bs || !data ) {              230   if( !rs || !gs || !bs || !data ) {
237     if(rs) free(rs);                              231     if(rs) free(rs);
238     if(gs) free(gs);                              232     if(gs) free(gs);
239     if(bs) free(bs);                              233     if(bs) free(bs);
240     delete [] data;                               234     delete [] data;
241     return;                                       235     return;
242   }                                               236   }
243   int pixeln = 0;                                 237   int pixeln = 0;
244   int row,col;                                    238   int row,col;
245   Uchar red,green,blue;                           239   Uchar red,green,blue;
246   Uchar ored = 0,ogreen = 0,oblue = 0;            240   Uchar ored = 0,ogreen = 0,oblue = 0;
247   float* pimag = aImage;                          241   float* pimag = aImage;
248   Uchar* pdata = 0;                               242   Uchar* pdata = 0;
249   Uchar index = 0;                                243   Uchar index = 0;
250   int status = 0;                                 244   int status = 0;
251   for(row=0;row<aHeight;row++) {                  245   for(row=0;row<aHeight;row++) {
252     pdata = data + (aHeight - 1 - row) * aWidt    246     pdata = data + (aHeight - 1 - row) * aWidth;
253     for(col=0;col<aWidth;col++){                  247     for(col=0;col<aWidth;col++){ 
254       red   = (Uchar)(255 * (*pimag));pimag++;    248       red   = (Uchar)(255 * (*pimag));pimag++;
255       green = (Uchar)(255 * (*pimag));pimag++;    249       green = (Uchar)(255 * (*pimag));pimag++;
256       blue  = (Uchar)(255 * (*pimag));pimag++;    250       blue  = (Uchar)(255 * (*pimag));pimag++;
257       //printf("debug : %d %d : %d %d %d\n",ro    251       //printf("debug : %d %d : %d %d %d\n",row,col,red,green,blue);
258       if( (pixeln==0) || (red!=ored) || (green    252       if( (pixeln==0) || (red!=ored) || (green!=ogreen) || (blue!=oblue) ){
259         // Search exact color :                   253         // Search exact color :
260         int found = 0;                            254         int found = 0;
261         for(int count=0;count<pixeln;count++){    255         for(int count=0;count<pixeln;count++){
262           if( (red==rs[count]) && (green==gs[c    256           if( (red==rs[count]) && (green==gs[count]) && (blue==bs[count]) ){
263             found = 1;                            257             found = 1;
264             index = count;                        258             index = count;
265             break;                                259             break;
266           }                                       260           }
267         }                                         261         }
268         if(found==0){                             262         if(found==0){
269           if(pixeln>=256) {                       263           if(pixeln>=256) {
270             // We can't store more than 256 on    264             // We can't store more than 256 on an Uchar.
271             // Search closest color :             265             // Search closest color :
272             int dr,dg,db;                         266             int dr,dg,db;
273             int PRECISION = 20;                   267             int PRECISION = 20;
274             int closest = 0;                      268             int closest = 0;
275             for(int count=0;count<pixeln;count    269             for(int count=0;count<pixeln;count++){
276               dr = red   - rs[count];dr = dr<0    270               dr = red   - rs[count];dr = dr<0 ? -dr : dr;
277               dg = green - gs[count];dg = dg<0    271               dg = green - gs[count];dg = dg<0 ? -dg : dg;
278               db = blue  - bs[count];db = db<0    272               db = blue  - bs[count];db = db<0 ? -db : db;
279               if( (dr<=PRECISION) && (dg<=PREC    273               if( (dr<=PRECISION) && (dg<=PRECISION) && (db<=PRECISION) ){
280                 closest = 1;                      274                 closest = 1;
281                 index = count;                    275                 index = count;
282                 break;                            276                 break;
283               }                                   277               }
284             }                                     278             }
285             if(closest==0) {                      279             if(closest==0) {
286               index = 0;                          280               index = 0;
287               status  = 1;                        281               status  = 1;
288             }                                     282             }
289           } else {                                283           } else {
290             if(pixeln>=size){                     284             if(pixeln>=size){
291               size += 256;                        285               size += 256;
292               rs = (Uchar*)realloc(rs,size * s    286               rs = (Uchar*)realloc(rs,size * sizeof(Uchar));
293               gs = (Uchar*)realloc(gs,size * s    287               gs = (Uchar*)realloc(gs,size * sizeof(Uchar));
294               bs = (Uchar*)realloc(bs,size * s    288               bs = (Uchar*)realloc(bs,size * sizeof(Uchar));
295               if( !rs || !gs || !bs ) {           289               if( !rs || !gs || !bs ) {
296                 if(rs) free(rs);                  290                 if(rs) free(rs);
297                 if(gs) free(gs);                  291                 if(gs) free(gs);
298                 if(bs) free(bs);                  292                 if(bs) free(bs);
299                 delete [] data;                   293                 delete [] data;
300                 return;                           294                 return;
301               }                                   295               } 
302             }                                     296             } 
303             //printf("debug : SoImageWriter pi    297             //printf("debug : SoImageWriter pixeln %d : %d %d %d\n",
304             //   pixeln,red,green,blue);          298             //   pixeln,red,green,blue);
305             rs[pixeln] = red;                     299             rs[pixeln] = red;
306             gs[pixeln] = green;                   300             gs[pixeln] = green;
307             bs[pixeln] = blue;                    301             bs[pixeln] = blue;
308             index = pixeln;                       302             index = pixeln;
309             pixeln++;                             303             pixeln++;
310           }                                       304           }
311         }                                         305         }
312       }                                           306       }
313       *pdata = index;                             307       *pdata = index;
314       pdata++;                                    308       pdata++;
315       ored = red;                                 309       ored = red;
316       ogreen = green;                             310       ogreen = green;
317       oblue = blue;                               311       oblue = blue;
318     }                                             312     }
319   }                                               313   }
320   if(status==1)                                   314   if(status==1) 
321     printf("SoImageWriter : more than 256 colo    315     printf("SoImageWriter : more than 256 colors in picture ; some colors approximated.\n");
322   aColorn = pixeln;                               316   aColorn = pixeln;
323   aReds = rs;                                     317   aReds = rs;
324   aGreens = gs;                                   318   aGreens = gs;
325   aBlues = bs;                                    319   aBlues = bs;
326   aData = data;                                   320   aData = data;
327 }                                                 321 }
328 */                                                322 */
329 //////////////////////////////////////////////    323 //////////////////////////////////////////////////////////////////////////////
330 int getRGB(                                       324 int getRGB(
331  unsigned int aX                                  325  unsigned int aX
332 ,unsigned int aY                                  326 ,unsigned int aY
333 ,double& aRed                                     327 ,double& aRed
334 ,double& aGreen                                   328 ,double& aGreen
335 ,double& aBlue                                    329 ,double& aBlue
336 )                                                 330 )
337 //////////////////////////////////////////////    331 //////////////////////////////////////////////////////////////////////////////
338 // OpenGL image is from down to up.               332 // OpenGL image is from down to up.
339 // PS image is up to down.                        333 // PS image is up to down.
340 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    334 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
341 {                                                 335 {
342   float* pimag = sImage + 3 * (sWidth * (sHeig    336   float* pimag = sImage + 3 * (sWidth * (sHeight - 1 - aY) + aX);
343   aRed   = *pimag;pimag++;                        337   aRed   = *pimag;pimag++;
344   aGreen = *pimag;pimag++;                        338   aGreen = *pimag;pimag++;
345   aBlue  = *pimag;pimag++;                        339   aBlue  = *pimag;pimag++;
346   return 1;                                       340   return 1;
347 }                                                 341 }
                                                   >> 342 
                                                   >> 343 #endif
348                                                   344