1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
/*
* draw a line between two given points in the current color.
*
* Called by:
* Cont_abs() in ../lib/Cont_abs.c
*/
#include <math.h>
#include "pngdriver.h"
#ifndef min
#define min(a,b) ((a)<(b)?(a):(b))
#endif
#ifndef max
#define max(a,b) ((a)>(b)?(a):(b))
#endif
void PNG_draw_bitmap(int ncols, int nrows, int threshold,
const unsigned char *buf)
{
int i0 = max(clip_left - cur_x, 0);
int i1 = min(clip_rite - cur_x, ncols);
int j0 = max(clip_top - cur_y, 0);
int j1 = min(clip_bot - cur_y, nrows);
if (!true_color) {
int i, j;
for (j = j0; j < j1; j++) {
int y = cur_y + j;
for (i = i0; i < i1; i++) {
int x = cur_x + i;
unsigned int k = buf[j * ncols + i];
unsigned int *p = &grid[y * width + x];
if (k > threshold)
*p = currentColor;
}
}
}
else {
int r1, g1, b1, a1;
int i, j;
get_pixel(currentColor, &r1, &g1, &b1, &a1);
for (j = j0; j < j1; j++) {
int y = cur_y + j;
for (i = i0; i < i1; i++) {
int x = cur_x + i;
unsigned int k = buf[j * ncols + i];
unsigned int *p = &grid[y * width + x];
unsigned int a0, r0, g0, b0;
unsigned int a, r, g, b;
get_pixel(*p, &r0, &g0, &b0, &a0);
a = (a0 * (255 - k) + a1 * k) / 255;
r = (r0 * (255 - k) + r1 * k) / 255;
g = (g0 * (255 - k) + g1 * k) / 255;
b = (b0 * (255 - k) + b1 * k) / 255;
*p = get_color(r, g, b, a);
}
}
}
modified = 1;
}
|