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
74
75
76
77
78
79
80
81
82
|
/*
fill an image area with a particular pixel value
By Jim Frost 1989.10.02, Bryan Henderson 2006.03.25.
See COPYRIGHT file for copyright information.
*/
#include "pm.h"
#include "image.h"
#include "valtomem.h"
#include "fill.h"
void
fill(Image * const imageP,
unsigned int const fx,
unsigned int const fy,
unsigned int const fw,
unsigned int const fh,
Pixel const pixval) {
assertGoodImage(imageP);
switch(imageP->type) {
case IBITMAP: {
unsigned int const linelen = (imageP->width +7)/ 8;
unsigned int const start = (fx +7) / 8;
unsigned char const startmask = 0x80 >> (fx % 8);
unsigned int y;
unsigned char * lineptr;
for (y = fy, lineptr = imageP->data + linelen * fy;
y < fy + fh;
++y, lineptr += linelen) {
unsigned int x;
unsigned char mask;
unsigned char * pixptr;
mask = startmask;
pixptr = lineptr + start;
for (x = fx; x < fw; ++x) {
if (pixval)
*pixptr |= mask;
else
*pixptr &= ~mask;
if (!(mask >>= 1)) {
mask = 0x80;
++pixptr;
}
}
}
} break;
case IRGB:
case ITRUE: {
unsigned int const linelen= imageP->width * imageP->pixlen;
unsigned int const start = imageP->pixlen * fx;
unsigned int y;
unsigned char * lineptr;
for (y = fy, lineptr = imageP->data + (linelen * fy);
y < fy + fh;
++y, lineptr += linelen) {
unsigned int x;
unsigned char * pixptr;
pixptr = lineptr + start;
for (x = fx, pixptr = lineptr + start;
x < fw;
++x, pixptr += imageP->pixlen) {
valToMem(pixval, pixptr, imageP->pixlen);
}
}
} break;
default:
pm_error("INTERNAL ERROR: Impossible image type %u", imageP->type);
}
}
|