GRASS Programmer's Manual  6.4.2(2012)
pngdriver/Draw_bitmap.c
Go to the documentation of this file.
00001 
00002 /*
00003  * draw a line between two given points in the current color.
00004  *
00005  * Called by:
00006  *     Cont_abs() in ../lib/Cont_abs.c
00007  */
00008 
00009 #include <math.h>
00010 
00011 #include "pngdriver.h"
00012 
00013 #ifndef min
00014 #define min(a,b) ((a)<(b)?(a):(b))
00015 #endif
00016 #ifndef max
00017 #define max(a,b) ((a)>(b)?(a):(b))
00018 #endif
00019 
00020 void PNG_draw_bitmap(int ncols, int nrows, int threshold,
00021                      const unsigned char *buf)
00022 {
00023     int i0 = max(clip_left - cur_x, 0);
00024     int i1 = min(clip_rite - cur_x, ncols);
00025     int j0 = max(clip_top - cur_y, 0);
00026     int j1 = min(clip_bot - cur_y, nrows);
00027 
00028     if (!true_color) {
00029         int i, j;
00030 
00031         for (j = j0; j < j1; j++) {
00032             int y = cur_y + j;
00033 
00034             for (i = i0; i < i1; i++) {
00035                 int x = cur_x + i;
00036                 unsigned int k = buf[j * ncols + i];
00037                 unsigned int *p = &grid[y * width + x];
00038 
00039                 if (k > threshold)
00040                     *p = currentColor;
00041             }
00042         }
00043     }
00044     else {
00045         int r1, g1, b1, a1;
00046         int i, j;
00047 
00048         get_pixel(currentColor, &r1, &g1, &b1, &a1);
00049 
00050         for (j = j0; j < j1; j++) {
00051             int y = cur_y + j;
00052 
00053             for (i = i0; i < i1; i++) {
00054                 int x = cur_x + i;
00055                 unsigned int k = buf[j * ncols + i];
00056                 unsigned int *p = &grid[y * width + x];
00057                 unsigned int a0, r0, g0, b0;
00058                 unsigned int a, r, g, b;
00059 
00060                 get_pixel(*p, &r0, &g0, &b0, &a0);
00061 
00062                 a = (a0 * (255 - k) + a1 * k) / 255;
00063                 r = (r0 * (255 - k) + r1 * k) / 255;
00064                 g = (g0 * (255 - k) + g1 * k) / 255;
00065                 b = (b0 * (255 - k) + b1 * k) / 255;
00066 
00067                 *p = get_color(r, g, b, a);
00068             }
00069         }
00070     }
00071 
00072     modified = 1;
00073 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines