wrong colours from scrsave

David R. Blythe drb at eecg.toronto.edu
Sat Feb 2 05:37:52 AEST 1991


In article <9101311334.AA06753 at scylla.drea.dnd.ca> hally at 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 <gl.h>
>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 at clsc.utoronto.ca

----------------------------- cut here ---------------------------------------
#include <gl/gl.h>
#include <gl/image.h>
#include <gl/get.h>

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;
}



More information about the Comp.sys.sgi mailing list