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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
include <mach.h>
include <imhdr.h>
define FONTWIDE 6
define FONTHIGH 7
define MAXSTRING 100
# TEXTIM -- Write a text string into an image using a pixel font for speed.
# Characters are made twice as big as the font by doubling in both axes.
procedure textim (im, s, x, y, xmag, ymag, value, zerobgnd, bgndvalu)
pointer im # Image to put the text in.
char s[MAXSTRING] # Text to put in the image.
int x, y # x, y position in the image.
int xmag, ymag # x, y magnification values.
int value # Value to use in image for text.
int zerobgnd # Flag to tell if we should zero bgnd.
int bgndvalu # Background value to use.
int numrow, numcol, numchars
int fonthigh, fontwide
int i, l, ch
int nchar, line
int pixary[5]
pointer lineget, lineput
short tshort
int strlen()
pointer imgl2s(), impl2s()
errchk imgl2s, impl2s
begin
# Find the length of the string (if there aren't any chars, return).
numchars = strlen (s)
if (numchars <= 0)
return
# Calculate height and width of magnified font.
fonthigh = FONTHIGH * ymag
fontwide = FONTWIDE * xmag
# Check for row/col out of bounds.
numcol= IM_LEN(im,1)
numrow = IM_LEN(im,2)
if (x <= 0) {
call printf ("Warning: Image text deleted, column <= 0.\n")
return
}
if (x > numcol - fontwide*numchars) {
call printf ("Warning: Image text truncated or deleted\n")
numchars = int((numcol - x)/fontwide)
if (numchars <= 0)
return
}
if ((y <= 0) || (y > numrow - fonthigh)) {
call printf ("Warning: Image text deleted, wrong row number.\n")
return
}
# For each line of the text (backward).
for (i=7; i>=1; i=i-1) {
line = y+(8-i)*ymag-1
do l = 1, ymag {
# Get and put the line of the image.
lineget = imgl2s (im, line+(l-1))
lineput = impl2s (im, line+(l-1))
# Copy input array or the background value to output array.
if (zerobgnd == 1) {
tshort = bgndvalu
call amovks (tshort, Mems[lineput+x-1],
fontwide*numchars)
} else
call amovs (Mems[lineget], Mems[lineput], numcol)
# Put the font.
do ch = 1, numchars {
nchar = int(s[ch])
call pixbit (nchar, i, pixary)
call putpix (pixary, Mems[lineput], numcol,
x+(ch-1)*fontwide, value, xmag)
}
} # End of do on l.
}
end
# PUTPIX -- Put one line of one character into the data array.
procedure putpix (pixary, array, size, position, value, xmag)
int pixary[5] # array of pixels in character
int size, position # size of data array
short array[size] # data array in which to put character line
int value # value to use for character pixels
int xmag # x-magnification of text
int i, k, x
begin
do i = 1, 5 {
if (pixary[i] == 1) {
x = position + (i-1) * xmag
do k = 1, xmag
array[x+(k-1)] = value
}
}
end
|