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;
64 out = TIFFOpen(name,
"w");
66 G_warning(_(
"Unable to open file <%s> for writing"), name);
72 TIFFSetField(out, TIFFTAG_IMAGEWIDTH, xsize);
73 TIFFSetField(out, TIFFTAG_IMAGELENGTH, ysize);
74 TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
75 TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 24 > 8 ? 3 : 1);
76 TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 24 > 1 ? 8 : 1);
77 TIFFSetField(out, TIFFTAG_PLANARCONFIG,
config);
80 TIFFSetField(out, TIFFTAG_PHOTOMETRIC, 24 > 8 ?
81 PHOTOMETRIC_RGB : PHOTOMETRIC_MINISBLACK);
83 linebytes = ((xsize * ysize + 15) >> 3) & ~1;
85 if (TIFFScanlineSize(out) > linebytes) {
86 buf = (
unsigned char *)G_malloc(linebytes);
89 buf = (
unsigned char *)G_malloc(TIFFScanlineSize(out));
96 TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
100 for (y = 0; y < ysize; y++) {
101 unsigned int yy = ysize - y - 1;
105 for (x = 0; x < (xsize); x++) {
106 *tmpptr++ = pixbuf[(yy * xsize +
x) * 4 + 0];
107 *tmpptr++ = pixbuf[(yy * xsize +
x) * 4 + 1];
108 *tmpptr++ = pixbuf[(yy * xsize +
x) * 4 + 2];
111 if (TIFFWriteScanline(out, buf, y, 0) < 0) {
117 (void)TIFFClose(out);
unsigned short compression
int GS_write_tif(const char *name)
Write data to tif file.
unsigned short rowsperstrip
int gsd_getimage(unsigned char **pixbuf, unsigned int *xsize, unsigned int *ysize)
Get image of current GL screen.
void G_free(void *buf)
Free allocated memory.
void G_warning(const char *msg,...)
Print a warning message to stderr.