GRASS Programmer's Manual
6.4.2(2012)
|
00001 00027 #include <stdlib.h> 00028 00029 #include <grass/gis.h> 00030 #include <grass/glocale.h> 00031 #include <grass/ogsf_proto.h> 00032 #include <grass/gstypes.h> 00033 00042 int GS_write_ppm(const char *name) 00043 { 00044 unsigned int x; 00045 int y; 00046 unsigned int xsize, ysize; 00047 FILE *fp; 00048 unsigned char *pixbuf; 00049 00050 gsd_getimage(&pixbuf, &xsize, &ysize); 00051 00052 if (NULL == (fp = fopen(name, "w"))) { 00053 G_warning(_("Unable to open file <%s> for writing"), name); 00054 return (1); 00055 } 00056 00057 fprintf(fp, "P6 %d %d 255\n", xsize, ysize); 00058 00059 for (y = ysize - 1; y >= 0; y--) { 00060 for (x = 0; x < xsize; x++) { 00061 unsigned char r = pixbuf[(y * xsize + x) * 4 + 0]; 00062 unsigned char g = pixbuf[(y * xsize + x) * 4 + 1]; 00063 unsigned char b = pixbuf[(y * xsize + x) * 4 + 2]; 00064 00065 fputc((int)r, fp); 00066 fputc((int)g, fp); 00067 fputc((int)b, fp); 00068 } 00069 00070 } 00071 G_free(pixbuf); 00072 fclose(fp); 00073 00074 return (0); 00075 } 00076 00086 int GS_write_zoom(const char *name, unsigned int xsize, unsigned int ysize) 00087 { 00088 unsigned int x; 00089 int y; 00090 FILE *fp; 00091 unsigned char *pixbuf; 00092 00093 gsd_writeView(&pixbuf, xsize, ysize); 00094 00095 if (NULL == (fp = fopen(name, "w"))) { 00096 G_warning(_("Unable to open file <%s> for writing"), name); 00097 return (1); 00098 } 00099 00100 fprintf(fp, "P6 %d %d 255\n", xsize, ysize); 00101 00102 for (y = ysize - 1; y >= 0; y--) { 00103 for (x = 0; x < xsize; x++) { 00104 unsigned char r = pixbuf[(y * xsize + x) * 4 + 0]; 00105 unsigned char g = pixbuf[(y * xsize + x) * 4 + 1]; 00106 unsigned char b = pixbuf[(y * xsize + x) * 4 + 2]; 00107 00108 fputc((int)r, fp); 00109 fputc((int)g, fp); 00110 fputc((int)b, fp); 00111 } 00112 00113 } 00114 free(pixbuf); 00115 fclose(fp); 00116 00117 return (0); 00118 }