26 #include <grass/config.h>
31 #include <sys/types.h>
33 #include <w32api/wtypes.h>
35 #include <grass/gis.h>
36 #include <grass/ogsf.h>
37 #include <grass/glocale.h>
41 unsigned short config = PLANARCONFIG_CONTIG;
57 unsigned int xsize, ysize;
58 int mapsize, linebytes;
59 unsigned char *buf, *tmpptr;
60 unsigned char *pixbuf;
63 G_warning(_(
"Unable to get image of current GL screen"));
67 out = TIFFOpen(
name,
"w");
75 TIFFSetField(out, TIFFTAG_IMAGEWIDTH, xsize);
76 TIFFSetField(out, TIFFTAG_IMAGELENGTH, ysize);
77 TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
78 TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 24 > 8 ? 3 : 1);
79 TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 24 > 1 ? 8 : 1);
80 TIFFSetField(out, TIFFTAG_PLANARCONFIG,
config);
83 TIFFSetField(out, TIFFTAG_PHOTOMETRIC, 24 > 8 ?
84 PHOTOMETRIC_RGB : PHOTOMETRIC_MINISBLACK);
86 linebytes = ((xsize * ysize + 15) >> 3) & ~1;
88 if (TIFFScanlineSize(out) > linebytes) {
89 buf = (
unsigned char *)G_malloc(linebytes);
92 buf = (
unsigned char *)G_malloc(TIFFScanlineSize(out));
99 TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
103 for (y = 0; y < ysize; y++) {
104 unsigned int yy = ysize - y - 1;
108 for (
x = 0;
x < (xsize);
x++) {
109 *tmpptr++ = pixbuf[(yy * xsize +
x) * 4 + 0];
110 *tmpptr++ = pixbuf[(yy * xsize +
x) * 4 + 1];
111 *tmpptr++ = pixbuf[(yy * xsize +
x) * 4 + 2];
114 if (TIFFWriteScanline(out, buf, y, 0) < 0) {
120 (void)TIFFClose(out);