aboutsummaryrefslogtreecommitdiff
path: root/pkg/dataio/export/exbltins.x
blob: bb0152ddc3389a37dafca50803af4a522f2f7183 (plain) (blame)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
include <mach.h>
include "export.h"
include "exbltins.h"


# EXb_BUILTIN - Process a builtin format.  

procedure exb_process_image (ex)

pointer	ex				#i task struct pointer

begin
	# Branch to the appropriate procedure for processing.
	switch (EX_BLTIN(ex)) {
	case EPS:			# Encapsulated PostScript
	    call ex_eps (ex)
	case GIF:			# GIF
	    call ex_gif (ex)
	case IMH:			# IRAF OIF
	    call ex_iraf (ex)
	case MIFF:			# ImageMagick MIFF file
	    call ex_miff (ex)
	case PGM:			# PBMplus PGM (grayscale) file
	    call ex_pgm (ex)
	case PPM:			# PBMplus PPM (RGB) file
	    call ex_ppm (ex)
	case RAS:			# Sun rasterfile
	    call ex_ras (ex)
	case RGB:			# SGI RGB format file
	    call ex_rgb (ex)
	case XWD:			# X11 Window Dump
	    call ex_xwd (ex)
	case VICAR:			# JPL VICAR2 format image
	    call ex_vicar (ex)
	default:
	    call error (0, "Unrecognized format")
	}
end


# EXB_CHKPARS - Check the parameters for the builtin parameters.

int procedure exb_chkpars (ex)

pointer ex                              #i task struct pointer

int	legal, fmt

begin
        # Do a quick check that the number of expressions is valid for
        # the requested format.
        legal = NO
        fmt = EX_BLTIN(ex)
        switch (EX_NEXPR(ex)) {
        case 1:
            # PPM is the only format required to have 3 expressions.
            if (fmt != PPM)
                legal = YES
        case 3:
            if (fmt == PPM || fmt == RAS || fmt == RGB ||
                fmt == XWD || fmt == EPS || fmt == MIFF)
                    legal = YES
        case 4:
            if (fmt == RAS || fmt == XWD)
                legal = YES
        case EX_UNDEFINED:             	# let it slide for now....
            legal = YES
        default:
            if (bitset (EX_OUTFLAGS(ex), OF_BAND))
                legal = YES
        }
        if (legal == NO) {
            call error (1, "Wrong no. of expressions for requested format")
            return (ERR)
        }

        # Check the bswap param. If it's set but ignored by a given format
        # warn the user.
        if (EX_BSWAP(ex) != S_NONE && (fmt != RAS && fmt != XWD)) {
            call eprintf ("Warning: `bswap' parameter will be ignored")
            return (ERR)
        }

	return (OK)
end


# EXB_DO_FORMAT - Process a builtin task format parameter and set appropriate
# flags.

procedure exb_do_format (ex, format)

pointer ex                              #i task struct pointer
char    format[ARB]                     #i format parameter value

char    fmt[SZ_FNAME]
int     strdic()

begin
        switch (strdic (format, fmt, SZ_FNAME, EX_FORMATS)) {
        case EPS, EPSI, EPI, EPSF, PS:
            EX_BLTIN(ex) = EPS
            EX_COLOR(ex) = YES
        case GIF, GIFF:
            EX_BLTIN(ex) = GIF
            EX_COLOR(ex) = YES
        case IMH, IRAF:
            EX_BLTIN(ex) = IMH
            EX_COLOR(ex) = NO
        case MIFF:
            EX_BLTIN(ex) = MIFF
            EX_COLOR(ex) = YES
        case PGM:
            EX_BLTIN(ex) = PGM
            EX_COLOR(ex) = NO
        case PPM:
            EX_BLTIN(ex) = PPM
            EX_COLOR(ex) = NO
        case RAS, SUN, SUNRAS:
            EX_BLTIN(ex) = RAS
            EX_COLOR(ex) = YES
        case RGB, SGI, IRIS:
            EX_BLTIN(ex) = RGB
            EX_COLOR(ex) = NO
        case XWD, X11:
            EX_BLTIN(ex) = XWD
            EX_COLOR(ex) = YES
        case VICAR:
            EX_BLTIN(ex) = VICAR
            EX_COLOR(ex) = NO
        default:
            call error (2, "Unknown format.")
        }
end


# EXB_PNAME -  Print verbose name of the format.

procedure exb_pname (ex)

pointer ex                              #i task struct pointer

begin
        switch (EX_BLTIN(ex)) {
        case EPS:
	    call pargstr ("Encapsulated PostScript")
        case GIF:
	    call pargstr ("GIF")
        case MIFF:
	    call pargstr ("ImageMagick MIFF")
        case PGM:
	    call pargstr ("PGM")
        case PPM:
	    call pargstr ("PPM")
        case RAS:
	    call pargstr ("Sun Rasterfile")
        case RGB:
	    call pargstr ("SGI RGB")
        case XWD:
	    call pargstr ("X11 Window Dump")
        case VICAR:
	    call pargstr ("JPL VICAR2 Image")
        default:
	     call pargstr ("")
        }
end


# EXB_PENDIAN - Print byte order of the format.

procedure exb_pendian (ex)

pointer ex                              #i task struct pointer

begin
        switch (EX_BLTIN(ex)) {
        case GIF:    
	    call pargstr ("Least Significant Byte First")
        default:
            if (EX_BSWAP(ex) == 0 && (BYTE_SWAP2==NO || BYTE_SWAP4==NO))
               call pargstr ("Most Significant Byte First")
            else
                call pargstr ("Least Significant Byte First")
        }
end


# EXB_PSTORAGE - Print pixel storage type of the format.

procedure exb_pstorage (ex)

pointer ex                              #i task struct pointer

int	flags

begin
        switch (EX_BLTIN(ex)) {
        case GIF:    
	    call pargstr ("LZW compressed bytes")
        case RGB:    
	    call pargstr ("Band interleaved")
        default:
	    flags = EX_OUTFLAGS(ex)
            if (bitset(flags, OF_BAND) || bitset(flags,BAND_STORAGE))
                call pargstr ("Band Interleaved")
            else if (bitset(flags, OF_LINE) || bitset(flags,LINE_STORAGE))
                call pargstr ("Line Interleaved")
            else if (bitset(flags,PIXEL_STORAGE))
                call pargstr ("Pixel Interleaved")
            else
                call pargstr ("Unknown")
        }
end


# EXB_FMT_EXT - Print the name of the builtin format.  The returned pointer
# must be freed by the calling procedure.

pointer procedure exb_fmt_ext (ex)

pointer	ex				#i task struct pointer

pointer	suf

begin
	call malloc (suf, SZ_FNAME, TY_CHAR)

        switch (EX_BLTIN(ex)) {
        case EPS:    call strcpy (".eps",  Memc[suf], SZ_FNAME)
        case GIF:    call strcpy (".gif",  Memc[suf], SZ_FNAME)
        case IMH:    call strcpy (".imh",  Memc[suf], SZ_FNAME)
        case MIFF:   call strcpy (".miff", Memc[suf], SZ_FNAME)
        case PGM:    call strcpy (".pgm",  Memc[suf], SZ_FNAME)
        case PPM:    call strcpy (".ppm",  Memc[suf], SZ_FNAME)
        case RAS:    call strcpy (".ras",  Memc[suf], SZ_FNAME)
        case RGB:    call strcpy (".rgb",  Memc[suf], SZ_FNAME)
        case XWD:    call strcpy (".xwd",  Memc[suf], SZ_FNAME)
        case VICAR:  call strcpy (".vic",  Memc[suf], SZ_FNAME)
        default:     Memc[suf] = EOS
	}

	return (suf)
end