GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-d6dec75dd4
psdriver/raster.c
Go to the documentation of this file.
1 #include <string.h>
2 
3 #include "psdriver.h"
4 
5 static int masked;
6 
7 void PS_begin_raster(int mask, int src[2][2], double dst[2][2])
8 {
9  const char *type = ps.true_color ? (mask ? "RASTERRGBMASK" : "RASTERRGB")
10  : (mask ? "RASTERGRAYMASK" : "RASTERGRAY");
11 
12  int ssx = src[0][1] - src[0][0];
13  int ssy = src[1][1] - src[1][0];
14  int sox = src[0][0];
15  int soy = src[1][0];
16 
17  double dsx = dst[0][1] - dst[0][0];
18  double dsy = dst[1][1] - dst[1][0];
19  double dox = dst[0][0];
20  double doy = dst[1][0];
21 
22  masked = mask;
23 
24  output("gsave\n");
25  output("%f %f translate %f %f scale\n", dox, doy, dsx, dsy);
26  output("%d %d [%d 0 0 %d %d %d] %s\n", ssx, ssy, ssx, ssy, sox, soy, type);
27 }
28 
29 int PS_raster(int n, int row, const unsigned char *red,
30  const unsigned char *grn, const unsigned char *blu,
31  const unsigned char *nul)
32 {
33  int i;
34 
35  for (i = 0; i < n; i++) {
36  if (ps.true_color) {
37  if (masked)
38  output("%02X%02X%02X%02X", (nul && nul[i]) ? 0xFF : 0x00,
39  red[i], grn[i], blu[i]);
40  else
41  output("%02X%02X%02X", red[i], grn[i], blu[i]);
42  }
43  else {
44  unsigned int gray = (unsigned int)(red[i] * 0.299 + grn[i] * 0.587 +
45  blu[i] * 0.114);
46 
47  if (masked)
48  output("%02X%02X", (nul && nul[i]) ? 0xFF : 0x00, gray);
49  else
50  output("%02X", gray);
51  }
52  }
53 
54  output("\n");
55 
56  return row + 1;
57 }
58 
59 void PS_end_raster(void)
60 {
61  output("grestore\n");
62 }
char * dst
Definition: lz4.h:981
const char * src
Definition: lz4.h:989
struct ps_state ps
void output(const char *fmt,...)
void PS_begin_raster(int mask, int src[2][2], double dst[2][2])
void PS_end_raster(void)
int PS_raster(int n, int row, const unsigned char *red, const unsigned char *grn, const unsigned char *blu, const unsigned char *nul)
int true_color
Definition: psdriver.h:14