Path: utzoo!utgpu!news-server.csri.toronto.edu!eecg.toronto.edu!drb Newsgroups: comp.sys.sgi From: drb@eecg.toronto.edu (David R. Blythe) Subject: Re: wrong colours from scrsave Message-ID: <1991Feb1.133751.1470@jarvis.csri.toronto.edu> Organization: EECG, University of Toronto References: <9101311334.AA06753@scylla.drea.dnd.ca> Date: 1 Feb 91 18:37:52 GMT Lines: 96 In article <9101311334.AA06753@scylla.drea.dnd.ca> hally@SCYLLA.DREA.DND.CA (dave hally) writes: >The following small program makes a 101 x 101 window, clears it to >white, and saves it in the file white.img. It works correctly. > >#include >main() >{ prefposition(500,600,500,600); > winopen("mytest"); > RGBmode(); >/* doublebuffer(); */ > gconfig(); > cpack(0xffffff); > clear(); >/* swapbuffers(); */ > system("scrsave white.img 500 600 500 600"); >} > >When the comment delimiters are removed so that double buffering is in >force, the display on the screen is exactly the same, but now in the file, >every pixel has the colour value f0f0f0 (very light gray) instead of >ffffff (white). What is going on? > >If the colour map is used instead of RGBmode, it works correctly both >with and without double buffering. > >(BTW: I have a 4D/20 running 3.3.1) > > Dave This sounds weird, maybe there is a bug in the PI library. Here is some code that saves the contents of an RGB or color map window. If you have turned on double buffering make sure you call readsource(SRC_FRONT); before calling savewin() if you want the front buffer since the back buffer is the default. I find this a touch faster when I am saving an animation sequence to disk [though for better animations you would probably want the versions that decimate by 2 or 4]. [ BTW, there is similar code in the -lgutil library - but it uses readRGB(), etc (look in the source for libgutil in 4Dgifts for documentation :-).] david blythe ontario centre for large scale computation drb@clsc.utoronto.ca ----------------------------- cut here --------------------------------------- #include #include #include savewin(name) char *name; { long xsize, ysize; int x, y; short *sbuf; IMAGE *im; char *malloc(); getsize(&xsize, &ysize); /* can we create the file ?? */ if ((x = creat(name, 0666)) < 0) return -1; else close(x); if ((x = getdisplaymode()) == DMRGB || x == DMRGBDOUBLE) { im = iopen(name,"w",RLE(1),3,xsize,ysize,3); sbuf = (short *)malloc(xsize*3*sizeof(short)); for(y = 0; y < ysize; y++) { lrectread(0, y, xsize-1, y, sbuf); for(x = 0; x < xsize; x++) { long s = *((long *)sbuf+xsize-x-1); sbuf[0*xsize+xsize-x-1] = s&0xff; sbuf[1*xsize+xsize-x-1] = (s>>8)&0xff; sbuf[2*xsize+xsize-x-1] = (s>>16)&0xff; } putrow(im,sbuf,y,0); /* red row */ putrow(im,sbuf+xsize,y,1); /* green row */ putrow(im,sbuf+2*xsize,y,2); /* blue row */ } } else { im = iopen(name,"w",RLE(2),2,xsize,ysize,1); isetcolormap(im, CM_SCREEN); sbuf = (short *)malloc(xsize*sizeof(short)); for(y = 0; y < ysize; y++) { rectread(0, y, xsize-1, y, sbuf); putrow(im,sbuf,y,0); } } iclose(im); free((char *)im); /* would be nice if iclose() did this */ free((char *)sbuf); return 0; }