GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pngdriver/write_ppm.c
Go to the documentation of this file.
1 
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 
6 #include <grass/gis.h>
7 #include "pngdriver.h"
8 
9 void write_ppm(void)
10 {
11  FILE *output;
12  int x, y;
13  unsigned int *p;
14 
15  output = fopen(file_name, "wb");
16  if (!output)
17  G_fatal_error("PNG: couldn't open output file %s", file_name);
18 
19  fprintf(output, "P6\n%d %d\n255\n", width, height);
20 
21  for (y = 0, p = grid; y < height; y++) {
22  for (x = 0; x < width; x++, p++) {
23  unsigned int c = *p;
24  int r, g, b, a;
25 
26  get_pixel(c, &r, &g, &b, &a);
27 
28  fputc((unsigned char)r, output);
29  fputc((unsigned char)g, output);
30  fputc((unsigned char)b, output);
31  }
32  }
33 
34  fclose(output);
35 }
36 
37 void write_pgm(void)
38 {
39  char *mask_name = G_store(file_name);
40  FILE *output;
41  int x, y;
42  unsigned int *p;
43 
44  mask_name[strlen(mask_name) - 2] = 'g';
45 
46  output = fopen(mask_name, "wb");
47  if (!output)
48  G_fatal_error("PNG: couldn't open mask file %s", mask_name);
49 
50  G_free(mask_name);
51 
52  fprintf(output, "P5\n%d %d\n255\n", width, height);
53 
54  for (y = 0, p = grid; y < height; y++) {
55  for (x = 0; x < width; x++, p++) {
56  unsigned int c = *p;
57  int r, g, b, a;
58 
59  get_pixel(c, &r, &g, &b, &a);
60 
61  fputc((unsigned char)(255 - a), output);
62  }
63  }
64 
65  fclose(output);
66 }
void write_pgm(void)
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:142
float b
Definition: named_colr.c:8
char * G_store(const char *s)
Copy string to allocated memory.
Definition: store.c:32
void get_pixel(unsigned int pixel, int *r, int *g, int *b, int *a)
float r
Definition: named_colr.c:8
tuple width
unsigned char * grid
int y
Definition: plot.c:34
void write_ppm(void)
char * file_name
float g
Definition: named_colr.c:8
fclose(fd)
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int height
void output(const char *fmt,...)