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
115
116
117
|
include <mach.h>
include "../export.h"
# EXRAS.X - Source file for the EXPORT task rasterfile builtin format.
define SZ_RASHDR 8
define RAS_MAGIC 1 # Magic number
define RAS_WIDTH 2 # Image width (pixels per line)
define RAS_HEIGHT 3 # Image height (number of lines)
define RAS_DEPTH 4 # Image depth (bits per pixel)
define RAS_LENGTH 5 # Image length (bytes)
define RAS_TYPE 6 # File type
define RAS_MAPTYPE 7 # Colormap type
define RAS_MAPLENGTH 8 # Colormap length (bytes)
# Rasterfile magic number
define RAS_MAGIC_NUM 59A66A95X
define RAS_RLE 80X
# Sun supported ras_types
define RT_OLD 0 # Raw pixrect image in 68000 byte order
define RT_STANDARD 1 # Raw pixrect image in 68000 byte order
define RT_BYTE_ENCODED 2 # Run-length compression of bytes
define RT_FORMAT_RGB 3 # XRGB or RGB instead of XBGR or BGR
define RT_FORMAT_TIFF 4 # tiff <-> standard rasterfile
define RT_FORMAT_IFF 5 # iff (TAAC format) <-> standard rasterfile
define RT_EXPERIMENTAL 65535 # Reserved for testing
# Sun supported ras_maptypes
define RMT_NONE 0 # ras_maplength is expected to be 0
define RMT_EQUAL_RGB 1 # red[ras_maplength/3],green[],blue[]
define RMT_RAW 2
# EX_RAS - Write the evaluated expressions as a Sun Rasterfile.
procedure ex_ras (ex)
pointer ex #i task struct pointer
pointer sp, cmap
long header[SZ_RASHDR]
int i, flags
begin
# Check to see that we have the correct number of expressions to
# write this format.
flags = EX_OUTFLAGS(ex)
if (EX_NEXPR(ex) != 1 && EX_NEXPR(ex) != 3 && EX_NEXPR(ex) != 4) {
if (!bitset(flags, OF_BAND))
call error (7, "Invalid number of expressions for rasterfile.")
}
if (bitset(flags, OF_LINE) || bitset (flags, LINE_STORAGE))
call error (7, "Line storage illegal for rasterfile.")
# Fix the output pixel type to single bytes.
call ex_do_outtype (ex, "b1")
EX_OUTFLAGS(ex) = or (EX_OUTFLAGS(ex), OF_FLIPY)
# Make sure the output is padded to the nearest 16-bits.
if (mod (O_WIDTH(ex,1),2) != 0) {
do i = 1, EX_NEXPR(ex) {
call strcat ("//repl(0,1)", O_EXPR(ex,i), SZ_EXPSTR)
O_WIDTH(ex,i) = O_WIDTH(ex,i) + 1
}
EX_OCOLS(ex) = EX_OCOLS(ex) + 1
}
# Set the header values.
header[RAS_MAGIC] = RAS_MAGIC_NUM
header[RAS_WIDTH] = EX_OCOLS(ex)
header[RAS_HEIGHT] = EX_OROWS(ex)
header[RAS_TYPE] = RT_STANDARD
if (EX_NEXPR(ex) == 1 || bitset (flags, OF_BAND)) {
header[RAS_LENGTH] = header[RAS_WIDTH] * header[RAS_HEIGHT]
header[RAS_DEPTH] = long (8)
} else {
header[RAS_LENGTH] = header[RAS_WIDTH] * header[RAS_HEIGHT] * 3
header[RAS_DEPTH] = long (24)
header[RAS_TYPE] = RT_FORMAT_RGB
}
if (bitset(flags, OF_CMAP)) {
header[RAS_MAPTYPE] = RMT_EQUAL_RGB
header[RAS_MAPLENGTH] = long (3*CMAP_SIZE)
} else {
header[RAS_MAPTYPE] = RMT_NONE
header[RAS_MAPLENGTH] = long (0)
}
# Write the header to the file. First swap it to Sun byte order if
# needed (although the format doesn't require this), then swap it
# if requested by the user.
if (BYTE_SWAP4 == YES)
call bswap4 (header, 1, header, 1, (SZ_RASHDR * SZ_LONG * SZB_CHAR))
if (EX_BSWAP(ex) == S_I4)
call bswap4 (header, 1, header, 1, (SZ_RASHDR * SZ_LONG * SZB_CHAR))
call write (EX_FD(ex), header, (SZ_RASHDR * SZ_LONG))
# If we have a colormap write that out now.
if (bitset(flags, OF_CMAP)) {
call smark (sp)
call salloc (cmap, 3*CMAP_SIZE, TY_CHAR)
call achtcb (Memc[EX_CMAP(ex)], Memc[cmap], (3 * CMAP_SIZE))
call write (EX_FD(ex), Memc[cmap], ((3 * CMAP_SIZE) / SZB_CHAR))
call sfree (sp)
}
# Finally, evaluate the expressions and write the image.
if (EX_NEXPR(ex) == 1 || bitset (flags, OF_BAND))
call ex_no_interleave (ex)
else if (EX_NEXPR(ex) == 3 || EX_NEXPR(ex) == 4)
call ex_px_interleave (ex)
end
|