GRASS 8 Programmer's Manual
8.6.0dev(2026)-0f6a7341fc
Loading...
Searching...
No Matches
gsd_img_tif.c
Go to the documentation of this file.
1
/*!
2
\file lib/ogsf/gsd_img_tif.c
3
4
\brief OGSF library - TIFF stuff
5
6
GRASS OpenGL gsurf OGSF Library
7
8
SPDX-FileCopyrightText: 1999-2008 GRASS Development Team
9
SPDX-License-Identifier: GPL-2.0-or-later
10
11
- added little/big endian test Markus Neteler
12
- modified to PPM by Bob Covill <bcovill@tekmap.ns.ca>
13
- changed 10/99 Jaro
14
- Created new function GS_write_tif based on RGB dump
15
16
\author Bill Brown USACERL, GMSL/University of Illinois
17
\author Markus Neteler
18
\author Jaro Hofierka
19
\author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
20
*/
21
22
#include <
grass/config.h
>
23
24
#ifdef HAVE_TIFFIO_H
25
26
#include <
stdlib.h
>
27
#include <sys/types.h>
28
#ifdef __CYGWIN__
29
#include <w32api/wtypes.h>
30
#endif
31
#include <
grass/gis.h
>
32
#include <
grass/ogsf.h
>
33
#include <
grass/glocale.h
>
34
35
#include <tiffio.h>
36
37
unsigned
short
config
=
PLANARCONFIG_CONTIG
;
38
unsigned
short
compression
= -1;
39
unsigned
short
rowsperstrip
= 0;
40
41
/*!
42
\brief Write data to tif file
43
44
\param name filename
45
46
\return 1 on error
47
\return 0 on success
48
*/
49
int
GS_write_tif
(
const
char
*
name
)
50
{
51
TIFF
*
out
;
52
unsigned
int
y,
x
;
53
unsigned
int
xsize
,
ysize
;
54
int
linebytes
;
55
unsigned
char
*buf, *
tmpptr
;
56
unsigned
char
*
pixbuf
;
57
58
if
(0 ==
gsd_getimage
(&
pixbuf
, &
xsize
, &
ysize
)) {
59
G_warning
(
_
(
"Unable to get image of current GL screen"
));
60
return
(1);
61
}
62
63
out
=
TIFFOpen
(
name
,
"w"
);
64
if
(
out
==
NULL
) {
65
G_warning
(
_
(
"Unable to open file <%s> for writing"
),
name
);
66
return
(1);
67
}
68
69
/* Write out TIFF Tags */
70
/* Assuming 24 bit RGB Tif */
71
TIFFSetField
(
out
,
TIFFTAG_IMAGEWIDTH
,
xsize
);
72
TIFFSetField
(
out
,
TIFFTAG_IMAGELENGTH
,
ysize
);
73
TIFFSetField
(
out
,
TIFFTAG_ORIENTATION
,
ORIENTATION_TOPLEFT
);
74
TIFFSetField
(
out
,
TIFFTAG_SAMPLESPERPIXEL
, 24 > 8 ? 3 : 1);
75
TIFFSetField
(
out
,
TIFFTAG_BITSPERSAMPLE
, 24 > 1 ? 8 : 1);
76
TIFFSetField
(
out
,
TIFFTAG_PLANARCONFIG
,
config
);
77
78
TIFFSetField
(
out
,
TIFFTAG_PHOTOMETRIC
,
79
24 > 8 ?
PHOTOMETRIC_RGB
:
PHOTOMETRIC_MINISBLACK
);
80
81
linebytes
= ((
xsize
*
ysize
+ 15) >> 3) & ~1;
82
83
if
(
TIFFScanlineSize
(
out
) >
linebytes
) {
84
buf = (
unsigned
char
*)
G_malloc
(
linebytes
);
85
}
86
else
{
87
buf = (
unsigned
char
*)
G_malloc
(
TIFFScanlineSize
(
out
));
88
}
89
90
if
(
rowsperstrip
!= (
unsigned
short
)-1) {
91
rowsperstrip
= (
unsigned
short
)(8 * 1024 /
linebytes
);
92
}
93
94
TIFFSetField
(
out
,
TIFFTAG_ROWSPERSTRIP
,
95
rowsperstrip
== 0 ? 1 :
rowsperstrip
);
96
97
/* Done with Header Info */
98
for
(y = 0; y <
ysize
; y++) {
99
unsigned
int
yy
=
ysize
- y - 1;
100
101
tmpptr
= buf;
102
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];
107
}
108
109
if
(
TIFFWriteScanline
(
out
, buf, y, 0) < 0) {
110
break
;
111
}
112
}
113
114
G_free
((
void
*)
pixbuf
);
115
G_free
(buf);
116
(
void
)
TIFFClose
(
out
);
117
118
return
(0);
119
}
120
121
#endif
/* HAVE_TIFF */
NULL
#define NULL
Definition
ccmath.h:32
AMI_STREAM
Definition
ami_stream.h:153
config.h
G_free
void G_free(void *)
Free allocated memory.
Definition
gis/alloc.c:145
G_warning
void G_warning(const char *,...) __attribute__((format(printf
G_malloc
#define G_malloc(n)
Definition
defs/gis.h:136
gsd_getimage
int gsd_getimage(unsigned char **, unsigned int *, unsigned int *)
Get image of current GL screen.
Definition
gsd_prim.c:898
gis.h
glocale.h
_
#define _(str)
Definition
glocale.h:10
rowsperstrip
unsigned short rowsperstrip
Definition
gsd_img_tif.c:39
GS_write_tif
int GS_write_tif(const char *name)
Write data to tif file.
Definition
gsd_img_tif.c:49
config
unsigned short config
Definition
gsd_img_tif.c:37
compression
unsigned short compression
Definition
gsd_img_tif.c:38
name
const char * name
Definition
named_colr.c:6
ogsf.h
OGSF header file (structures)
stdlib.h
x
#define x
lib
ogsf
gsd_img_tif.c
Generated on Sat Sep 12 2026 06:57:47 for GRASS 8 Programmer's Manual by
1.9.8