26#ifdef G4VIS_BUILD_OI_DRIVER
38#include <Inventor/errors/SoDebugError.h>
39#include <Inventor/elements/SoViewportRegionElement.h>
40#include <Inventor/actions/SoGLRenderAction.h>
53typedef unsigned char Uchar;
59static int sHeight = 0;
60static float* sImage = 0;
61static int getRGB(
unsigned int,
unsigned int,
double&,
double&,
double&);
70 static bool first =
true;
86 SO_NODE_ADD_FIELD(fileName,(
"out.ps"));
126 SoGLRenderAction* aAction
133 if(!fEnabled)
return;
134 SbViewportRegion vpr = SoViewportRegionElement::get(aAction->getState());
135 const SbVec2s& win = vpr.getWindowSize();
139 SoDebugError::postInfo(
"SoImageWriter::GLRender",
"null area window !");
146 float* image =
new float[s];
152 glReadPixels(x,y,w,h,GL_RGB,GL_FLOAT,image);
187 SoDebugError::postInfo(
"SoImageWriter::GLRender",
188 "can't open file \"%s\".",
fileName.getValue().getString());
231 if( (aWidth * aHeight) <=0) return;
233 Uchar* rs = (Uchar*)malloc(size * sizeof(Uchar));
234 Uchar* gs = (Uchar*)malloc(size * sizeof(Uchar));
235 Uchar* bs = (Uchar*)malloc(size * sizeof(Uchar));
236 Uchar* data = new Uchar[aWidth * aHeight];
237 if( !rs || !gs || !bs || !data ) {
246 Uchar red,green,blue;
247 Uchar ored = 0,ogreen = 0,oblue = 0;
248 float* pimag = aImage;
252 for(row=0;row<aHeight;row++) {
253 pdata = data + (aHeight - 1 - row) * aWidth;
254 for(col=0;col<aWidth;col++){
255 red = (Uchar)(255 * (*pimag));pimag++;
256 green = (Uchar)(255 * (*pimag));pimag++;
257 blue = (Uchar)(255 * (*pimag));pimag++;
258 //printf("debug : %d %d : %d %d %d\n",row,col,red,green,blue);
259 if( (pixeln==0) || (red!=ored) || (green!=ogreen) || (blue!=oblue) ){
260 // Search exact color :
262 for(int count=0;count<pixeln;count++){
263 if( (red==rs[count]) && (green==gs[count]) && (blue==bs[count]) ){
271 // We can't store more than 256 on an Uchar.
272 // Search closest color :
276 for(int count=0;count<pixeln;count++){
277 dr = red - rs[count];dr = dr<0 ? -dr : dr;
278 dg = green - gs[count];dg = dg<0 ? -dg : dg;
279 db = blue - bs[count];db = db<0 ? -db : db;
280 if( (dr<=PRECISION) && (dg<=PRECISION) && (db<=PRECISION) ){
293 rs = (Uchar*)realloc(rs,size * sizeof(Uchar));
294 gs = (Uchar*)realloc(gs,size * sizeof(Uchar));
295 bs = (Uchar*)realloc(bs,size * sizeof(Uchar));
296 if( !rs || !gs || !bs ) {
304 //printf("debug : SoImageWriter pixeln %d : %d %d %d\n",
305 // pixeln,red,green,blue);
322 printf("SoImageWriter : more than 256 colors in picture ; some colors approximated.\n");
343 float* pimag = sImage + 3 * (sWidth * (sHeight - 1 - aY) + aX);
344 aRed = *pimag;pimag++;
345 aGreen = *pimag;pimag++;
346 aBlue = *pimag;pimag++;
void putImageInStream(unsigned int, unsigned int, GetRGB_Function)
void setBitsPerPixel(int)
void clearColorBuffer(float, float, float)
void openFileForWriting(const char *)
void setWindowSize(int, int)
virtual void GLRender(SoGLRenderAction *)