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&);
82 SO_NODE_ADD_FIELD(fileName,(
"out.ps"));
122 SoGLRenderAction* aAction
129 if(!fEnabled)
return;
130 SbViewportRegion vpr = SoViewportRegionElement::get(aAction->getState());
131 const SbVec2s& win = vpr.getWindowSize();
135 SoDebugError::postInfo(
"SoImageWriter::GLRender",
"null area window !");
142 float* image =
new float[s];
148 glReadPixels(x,y,w,h,GL_RGB,GL_FLOAT,image);
183 SoDebugError::postInfo(
"SoImageWriter::GLRender",
184 "can't open file \"%s\".",
fileName.getValue().getString());
227 if( (aWidth * aHeight) <=0) return;
229 Uchar* rs = (Uchar*)malloc(size * sizeof(Uchar));
230 Uchar* gs = (Uchar*)malloc(size * sizeof(Uchar));
231 Uchar* bs = (Uchar*)malloc(size * sizeof(Uchar));
232 Uchar* data = new Uchar[aWidth * aHeight];
233 if( !rs || !gs || !bs || !data ) {
242 Uchar red,green,blue;
243 Uchar ored = 0,ogreen = 0,oblue = 0;
244 float* pimag = aImage;
248 for(row=0;row<aHeight;row++) {
249 pdata = data + (aHeight - 1 - row) * aWidth;
250 for(col=0;col<aWidth;col++){
251 red = (Uchar)(255 * (*pimag));pimag++;
252 green = (Uchar)(255 * (*pimag));pimag++;
253 blue = (Uchar)(255 * (*pimag));pimag++;
254 //printf("debug : %d %d : %d %d %d\n",row,col,red,green,blue);
255 if( (pixeln==0) || (red!=ored) || (green!=ogreen) || (blue!=oblue) ){
256 // Search exact color :
258 for(int count=0;count<pixeln;count++){
259 if( (red==rs[count]) && (green==gs[count]) && (blue==bs[count]) ){
267 // We can't store more than 256 on an Uchar.
268 // Search closest color :
272 for(int count=0;count<pixeln;count++){
273 dr = red - rs[count];dr = dr<0 ? -dr : dr;
274 dg = green - gs[count];dg = dg<0 ? -dg : dg;
275 db = blue - bs[count];db = db<0 ? -db : db;
276 if( (dr<=PRECISION) && (dg<=PRECISION) && (db<=PRECISION) ){
289 rs = (Uchar*)realloc(rs,size * sizeof(Uchar));
290 gs = (Uchar*)realloc(gs,size * sizeof(Uchar));
291 bs = (Uchar*)realloc(bs,size * sizeof(Uchar));
292 if( !rs || !gs || !bs ) {
300 //printf("debug : SoImageWriter pixeln %d : %d %d %d\n",
301 // pixeln,red,green,blue);
318 printf("SoImageWriter : more than 256 colors in picture ; some colors approximated.\n");
339 float* pimag = sImage + 3 * (sWidth * (sHeight - 1 - aY) + aX);
340 aRed = *pimag;pimag++;
341 aGreen = *pimag;pimag++;
342 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 *)