GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
psdriver/Raster.c
Go to the documentation of this file.
1 
2 #include <string.h>
3 
4 #include "psdriver.h"
5 
6 static int masked;
7 
8 void PS_begin_scaled_raster(int mask, int src[2][2], int dst[2][2])
9 {
10  const char *type = true_color ? (mask ? "RASTERRGBMASK" : "RASTERRGB")
11  : (mask ? "RASTERGRAYMASK" : "RASTERGRAY");
12 
13  int ssx = src[0][1] - src[0][0];
14  int ssy = src[1][1] - src[1][0];
15  int sox = src[0][0];
16  int soy = src[1][0];
17 
18  int dsx = dst[0][1] - dst[0][0];
19  int dsy = dst[1][1] - dst[1][0];
20  int dox = dst[0][0];
21  int doy = dst[1][0];
22 
23  masked = mask;
24 
25  output("gsave\n");
26  output("%d %d translate %d %d scale\n", dox, doy, dsx, dsy);
27  output("%d %d [%d 0 0 %d %d %d] %s\n", ssx, ssy, ssx, ssy, sox, soy,
28  type);
29 }
30 
31 int PS_scaled_raster(int n, int row,
32  const unsigned char *red, const unsigned char *grn,
33  const unsigned char *blu, const unsigned char *nul)
34 {
35  int i;
36 
37  for (i = 0; i < n; i++) {
38  if (true_color) {
39  if (masked)
40  output("%02X%02X%02X%02X", (nul && nul[i]) ? 0xFF : 0x00,
41  red[i], grn[i], blu[i]);
42  else
43  output("%02X%02X%02X", red[i], grn[i], blu[i]);
44  }
45  else {
46  unsigned int gray =
47  (unsigned int)(red[i] * 0.299 + grn[i] * 0.587 +
48  blu[i] * 0.114);
49 
50  if (masked)
51  output("%02X%02X", (nul && nul[i]) ? 0xFF : 0x00, gray);
52  else
53  output("%02X", gray);
54  }
55  }
56 
57  output("\n");
58 
59  return row + 1;
60 }
61 
63 {
64  output("grestore\n");
65 }
void PS_begin_scaled_raster(int, int[2][2], int[2][2])
int true_color
int PS_scaled_raster(int, int, const unsigned char *, const unsigned char *, const unsigned char *, const unsigned char *)
int
Definition: g3dcolor.c:48
void PS_end_scaled_raster(void)
int n
Definition: dataquad.c:291
void output(const char *fmt,...)