26 #include <grass/config.h>
31 #include <sys/types.h>
33 #include <grass/gis.h>
34 #include <grass/gstypes.h>
35 #include <grass/glocale.h>
39 unsigned short config = PLANARCONFIG_CONTIG;
55 unsigned int xsize, ysize;
56 int mapsize, linebytes;
57 unsigned char *
buf, *tmpptr;
58 unsigned char *pixbuf;
62 out = TIFFOpen(name,
"w");
64 G_warning(_(
"Unable to open file <%s> for writing"), name);
70 TIFFSetField(out, TIFFTAG_IMAGEWIDTH, xsize);
71 TIFFSetField(out, TIFFTAG_IMAGELENGTH, ysize);
72 TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
73 TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 24 > 8 ? 3 : 1);
74 TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 24 > 1 ? 8 : 1);
75 TIFFSetField(out, TIFFTAG_PLANARCONFIG,
config);
78 TIFFSetField(out, TIFFTAG_PHOTOMETRIC, 24 > 8 ?
79 PHOTOMETRIC_RGB : PHOTOMETRIC_MINISBLACK);
81 linebytes = ((xsize * ysize + 15) >> 3) & ~1;
83 if (TIFFScanlineSize(out) > linebytes) {
84 buf = (
unsigned char *)G_malloc(linebytes);
87 buf = (
unsigned char *)G_malloc(TIFFScanlineSize(out));
94 TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
98 for (y = 0; y < ysize; y++) {
99 int yy = ysize - y - 1;
103 for (x = 0; x < (xsize); x++) {
104 *tmpptr++ = pixbuf[(yy * xsize + x) * 4 + 0];
105 *tmpptr++ = pixbuf[(yy * xsize + x) * 4 + 1];
106 *tmpptr++ = pixbuf[(yy * xsize + x) * 4 + 2];
109 if (TIFFWriteScanline(out, buf, y, 0) < 0) {
115 (void)TIFFClose(out);
void G_free(void *buf)
Free allocated memory.
unsigned short compression
int GS_write_tif(const char *name)
Write data to tif file.
unsigned short rowsperstrip
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int gsd_getimage(unsigned char **pixbuf, unsigned int *xsize, unsigned int *ysize)
Get image of current GL screen.