GRASS Programmer's Manual  6.4.2(2012)
psdriver/Raster.c
Go to the documentation of this file.
00001 
00002 #include <string.h>
00003 
00004 #include "psdriver.h"
00005 
00006 static int masked;
00007 
00008 void PS_begin_scaled_raster(int mask, int src[2][2], int dst[2][2])
00009 {
00010     const char *type = true_color ? (mask ? "RASTERRGBMASK" : "RASTERRGB")
00011         : (mask ? "RASTERGRAYMASK" : "RASTERGRAY");
00012 
00013     int ssx = src[0][1] - src[0][0];
00014     int ssy = src[1][1] - src[1][0];
00015     int sox = src[0][0];
00016     int soy = src[1][0];
00017 
00018     int dsx = dst[0][1] - dst[0][0];
00019     int dsy = dst[1][1] - dst[1][0];
00020     int dox = dst[0][0];
00021     int doy = dst[1][0];
00022 
00023     masked = mask;
00024 
00025     output("gsave\n");
00026     output("%d %d translate %d %d scale\n", dox, doy, dsx, dsy);
00027     output("%d %d [%d 0 0 %d %d %d] %s\n", ssx, ssy, ssx, ssy, sox, soy,
00028            type);
00029 }
00030 
00031 int PS_scaled_raster(int n, int row,
00032                      const unsigned char *red, const unsigned char *grn,
00033                      const unsigned char *blu, const unsigned char *nul)
00034 {
00035     int i;
00036 
00037     for (i = 0; i < n; i++) {
00038         if (true_color) {
00039             if (masked)
00040                 output("%02X%02X%02X%02X", (nul && nul[i]) ? 0xFF : 0x00,
00041                        red[i], grn[i], blu[i]);
00042             else
00043                 output("%02X%02X%02X", red[i], grn[i], blu[i]);
00044         }
00045         else {
00046             unsigned int gray =
00047                 (unsigned int)(red[i] * 0.299 + grn[i] * 0.587 +
00048                                blu[i] * 0.114);
00049 
00050             if (masked)
00051                 output("%02X%02X", (nul && nul[i]) ? 0xFF : 0x00, gray);
00052             else
00053                 output("%02X", gray);
00054         }
00055     }
00056 
00057     output("\n");
00058 
00059     return row + 1;
00060 }
00061 
00062 void PS_end_scaled_raster(void)
00063 {
00064     output("grestore\n");
00065 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines