37#include <Inventor/errors/SoDebugError.h>
38#include <Inventor/elements/SoViewportRegionElement.h>
39#include <Inventor/actions/SoGLRenderAction.h>
58static int sHeight = 0;
59static float* sImage = 0;
60static int getRGB(
unsigned int,
unsigned int,
double&,
double&,
double&);
69 static bool first =
true;
85 SO_NODE_ADD_FIELD(
fileName,(
"out.ps"));
125 SoGLRenderAction* aAction
133 SbViewportRegion vpr = SoViewportRegionElement::get(aAction->getState());
134 const SbVec2s& win = vpr.getWindowSize();
138 SoDebugError::postInfo(
"SoImageWriter::GLRender",
"null area window !");
145 float* image =
new float[s];
151 glReadPixels(x,y,w,h,GL_RGB,GL_FLOAT,image);
186 SoDebugError::postInfo(
"SoImageWriter::GLRender",
187 "can't open file \"%s\".",
fileName.getValue().getString());
230 if( (aWidth * aHeight) <=0) return;
232 Uchar* rs = (Uchar*)malloc(size * sizeof(Uchar));
233 Uchar* gs = (Uchar*)malloc(size * sizeof(Uchar));
234 Uchar* bs = (Uchar*)malloc(size * sizeof(Uchar));
235 Uchar* data = new Uchar[aWidth * aHeight];
236 if( !rs || !gs || !bs || !data ) {
245 Uchar red,green,blue;
246 Uchar ored = 0,ogreen = 0,oblue = 0;
247 float* pimag = aImage;
251 for(row=0;row<aHeight;row++) {
252 pdata = data + (aHeight - 1 - row) * aWidth;
253 for(col=0;col<aWidth;col++){
254 red = (Uchar)(255 * (*pimag));pimag++;
255 green = (Uchar)(255 * (*pimag));pimag++;
256 blue = (Uchar)(255 * (*pimag));pimag++;
257 //printf("debug : %d %d : %d %d %d\n",row,col,red,green,blue);
258 if( (pixeln==0) || (red!=ored) || (green!=ogreen) || (blue!=oblue) ){
259 // Search exact color :
261 for(int count=0;count<pixeln;count++){
262 if( (red==rs[count]) && (green==gs[count]) && (blue==bs[count]) ){
270 // We can't store more than 256 on an Uchar.
271 // Search closest color :
275 for(int count=0;count<pixeln;count++){
276 dr = red - rs[count];dr = dr<0 ? -dr : dr;
277 dg = green - gs[count];dg = dg<0 ? -dg : dg;
278 db = blue - bs[count];db = db<0 ? -db : db;
279 if( (dr<=PRECISION) && (dg<=PRECISION) && (db<=PRECISION) ){
292 rs = (Uchar*)realloc(rs,size * sizeof(Uchar));
293 gs = (Uchar*)realloc(gs,size * sizeof(Uchar));
294 bs = (Uchar*)realloc(bs,size * sizeof(Uchar));
295 if( !rs || !gs || !bs ) {
303 //printf("debug : SoImageWriter pixeln %d : %d %d %d\n",
304 // pixeln,red,green,blue);
321 printf("SoImageWriter : more than 256 colors in picture ; some colors approximated.\n");
342 float* pimag = sImage + 3 * (sWidth * (sHeight - 1 - aY) + aX);
343 aRed = *pimag;pimag++;
344 aGreen = *pimag;pimag++;
345 aBlue = *pimag;pimag++;
void endTraversal()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void beginTraversal()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void putImageInStream(unsigned int, unsigned int, GetRGB_Function)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void setBitsPerPixel(int)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void clearColorBuffer(float, float, float)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void openFileForWriting(const char *)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void * getStream()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void closeStream()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void setWindowSize(int, int)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
virtual ~SoImageWriter()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
virtual void GLRender(SoGLRenderAction *)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
SbBool getStatus() const
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void disable()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void enable()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//