From: Johannes Zellner (johannes@zellner.org)
Date: Thu 09 Nov 2000 - 19:21:20 IST
On Thu, Nov 09, 2000 at 09:39:06AM -0600, Remenic wrote:
> Hi there,
>
> Has anyone written code before that makes a screenshot of the current
> physicalscreen, and saves it to a file(png, or anything)?
yes. I've. Here's a snipped, hope it helps. It writes a ppm.
It was written for an 8bit visual, but I think you get the
idea. P6 can do any number of colors, you can use the third
line of the P6 header to specify the color depth.
Basically a P6 file looks like this:
P6 (ppm format)
200 200 (width, height)
255 (color depth)
pixel1.red pixel1.green pixel1.blue pixel2.red ...
This was a quick hack and I used it only for debugging. If
you don't understand parts of the code, don't hestitate to
ask me!
void
VGAGL_write_dump_file(void)
{
FILE* fp;
unsigned char* buf;
unsigned char* bufptr;
int x, y, index;
char thisfile[0xff];
static int thisfileno = 0;
if (!VGAGL_dump_file) {
return;
}
sprintf(thisfile, "%s%05d.ppm", VGAGL_dump_file, thisfileno++);
fp = fopen(thisfile, "w");
if (!fp) {
free(VGAGL_dump_file);
VGAGL_dump_file = 0;
}
fprintf(fp, "P6\n");
fprintf(fp, "%d %d\n", modeinfo->width, modeinfo->height);
fprintf(fp, "255\n");
buf = gp_alloc(modeinfo->width * modeinfo->height * 3, "vgagl->buf");
bufptr = buf;
for (y = 0; y < modeinfo->height; y++) {
for (x = 0; x < modeinfo->width; x++) {
index = gl_getpixel(x, y);
while (index < 0) {
/* this is a kludge, as gl_getpixel() seems to
* return pixels > 128 as the negative complement */
index += 256;
}
*bufptr++ = VGAGL_palette[index][0];
*bufptr++ = VGAGL_palette[index][1];
*bufptr++ = VGAGL_palette[index][2];
}
}
fwrite(buf, 3, modeinfo->width * modeinfo->height, fp);
fclose(fp);
}
--
Johannes
------------------------------------------------------------------
Unsubscribe: To: listbot@svgalib.org
Body: unsubscribe linux-svgalib
This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:23 IST