Re: Screenshots?

Search this archive.

From: Matan Ziv-Av (matan@svgalib.org)
Date: Thu 09 Nov 2000 - 21:57:13 IST


On Thu, 9 Nov 2000, Remenic wrote:

> Has anyone written code before that makes a screenshot of the current
> physicalscreen, and saves it to a file(png, or anything)?

Here's one that writes the sceen (size heigh*width) in 16 or 24 bits to
ppm (P6 format).

writeppm(FILE * file)
{
    int y;
    unsigned char tmp[8192], tmp2[8192];
    int i, j, k;

    fprintf(file, "P6\n%i %i\n255\n", width, height);
    for (y = 0; y < height; y++) {
        vga_getscansegment(tmp, 0, y, width * bpp);
        switch (bitspp) {
        case 16:
            for (i = 0; i < width; i++) {
                j = tmp[i * 2] + 256 * tmp[i * 2 + 1];
                tmp2[i * 3] = (j & 0xf800) >> 8;
                tmp2[i * 3 + 1] = (j & 0x7e0) >> 3;
                tmp2[i * 3 + 2] = (j & 0x1f) << 3;
            };
            break;
        case 24:
            memcpy(tmp2, tmp, width * 3);
            break;
        };
        fwrite(tmp2, width * 3, 1, file);
    };
};
 


-- 
Matan Ziv-Av.                         matan@svgalib.org


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