GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pngdriver/Draw_bitmap.c
Go to the documentation of this file.
1 
2 /*
3  * draw a line between two given points in the current color.
4  *
5  * Called by:
6  * Cont_abs() in ../lib/Cont_abs.c
7  */
8 
9 #include <math.h>
10 
11 #include "pngdriver.h"
12 
13 #ifndef min
14 #define min(a,b) ((a)<(b)?(a):(b))
15 #endif
16 #ifndef max
17 #define max(a,b) ((a)>(b)?(a):(b))
18 #endif
19 
20 void PNG_draw_bitmap(int ncols, int nrows, int threshold,
21  const unsigned char *buf)
22 {
23  int i0 = max(clip_left - cur_x, 0);
24  int i1 = min(clip_rite - cur_x, ncols);
25  int j0 = max(clip_top - cur_y, 0);
26  int j1 = min(clip_bot - cur_y, nrows);
27 
28  if (!true_color) {
29  int i, j;
30 
31  for (j = j0; j < j1; j++) {
32  int y = cur_y + j;
33 
34  for (i = i0; i < i1; i++) {
35  int x = cur_x + i;
36  unsigned int k = buf[j * ncols + i];
37  unsigned int *p = &grid[y * width + x];
38 
39  if (k > threshold)
40  *p = currentColor;
41  }
42  }
43  }
44  else {
45  int r1, g1, b1, a1;
46  int i, j;
47 
48  get_pixel(currentColor, &r1, &g1, &b1, &a1);
49 
50  for (j = j0; j < j1; j++) {
51  int y = cur_y + j;
52 
53  for (i = i0; i < i1; i++) {
54  int x = cur_x + i;
55  unsigned int k = buf[j * ncols + i];
56  unsigned int *p = &grid[y * width + x];
57  unsigned int a0, r0, g0, b0;
58  unsigned int a, r, g, b;
59 
60  get_pixel(*p, &r0, &g0, &b0, &a0);
61 
62  a = (a0 * (255 - k) + a1 * k) / 255;
63  r = (r0 * (255 - k) + r1 * k) / 255;
64  g = (g0 * (255 - k) + g1 * k) / 255;
65  b = (b0 * (255 - k) + b1 * k) / 255;
66 
67  *p = get_color(r, g, b, a);
68  }
69  }
70  }
71 
72  modified = 1;
73 }
int cur_y
Definition: driver/init.c:38
void PNG_draw_bitmap(int ncols, int nrows, int threshold, const unsigned char *buf)
float b
Definition: named_colr.c:8
int currentColor
void get_pixel(unsigned int pixel, int *r, int *g, int *b, int *a)
int modified
float r
Definition: named_colr.c:8
tuple width
int clip_rite
unsigned char * grid
int y
Definition: plot.c:34
int clip_bot
int true_color
int clip_top
float g
Definition: named_colr.c:8
#define min(a, b)
int clip_left
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
int cur_x
Definition: driver/init.c:37
unsigned int get_color(int r, int g, int b, int a)
double x
Definition: cnversions.c:36
#define max(a, b)