GRASS Programmer's Manual
6.4.2(2012)
|
00001 00002 #include <stdio.h> 00003 #include <stdlib.h> 00004 #include <string.h> 00005 00006 #include <grass/gis.h> 00007 #include "pngdriver.h" 00008 00009 void write_ppm(void) 00010 { 00011 FILE *output; 00012 int x, y; 00013 unsigned int *p; 00014 00015 output = fopen(file_name, "wb"); 00016 if (!output) 00017 G_fatal_error("PNG: couldn't open output file %s", file_name); 00018 00019 fprintf(output, "P6\n%d %d\n255\n", width, height); 00020 00021 for (y = 0, p = grid; y < height; y++) { 00022 for (x = 0; x < width; x++, p++) { 00023 unsigned int c = *p; 00024 int r, g, b, a; 00025 00026 get_pixel(c, &r, &g, &b, &a); 00027 00028 fputc((unsigned char)r, output); 00029 fputc((unsigned char)g, output); 00030 fputc((unsigned char)b, output); 00031 } 00032 } 00033 00034 fclose(output); 00035 } 00036 00037 void write_pgm(void) 00038 { 00039 char *mask_name = G_store(file_name); 00040 FILE *output; 00041 int x, y; 00042 unsigned int *p; 00043 00044 mask_name[strlen(mask_name) - 2] = 'g'; 00045 00046 output = fopen(mask_name, "wb"); 00047 if (!output) 00048 G_fatal_error("PNG: couldn't open mask file %s", mask_name); 00049 00050 G_free(mask_name); 00051 00052 fprintf(output, "P5\n%d %d\n255\n", width, height); 00053 00054 for (y = 0, p = grid; y < height; y++) { 00055 for (x = 0; x < width; x++, p++) { 00056 unsigned int c = *p; 00057 int r, g, b, a; 00058 00059 get_pixel(c, &r, &g, &b, &a); 00060 00061 fputc((unsigned char)(255 - a), output); 00062 } 00063 } 00064 00065 fclose(output); 00066 }