35 static char rcsid[] =
"$Header: /l/spencer/src/urt/cnv/RCS/rlatorle.c,v 3.0.1.5 1992/04/30 13:58:32 spencer Exp $";
47 #define VPRINTF if (verbose || header) fprintf
61 #define SHORTREAD(var, fp) {fread(&craybuf, 2
, 1
, fp); *var=craybuf>>48
;}
62 #define LONGREAD(var, fp) {fread(&craybuf, 4
, 1
, fp); *var=craybuf>>32
;}
64 #define SHORTREAD(var, fp) {fread(var, 2
, 1
, fp);}
65 #define LONGREAD(var, fp) {fread(var, 4
, 1
, fp);}
76 void read_rla_header(act_x_res, act_y_res, width, height)
86 SHORTREAD(&head.rla_head.window.left, fp);
87 SHORTREAD(&head.rla_head.window.right, fp);
88 SHORTREAD(&head.rla_head.window.bottom, fp);
89 SHORTREAD(&head.rla_head.window.top, fp);
90 SHORTREAD(&head.rla_head.active_window.left, fp);
91 SHORTREAD(&head.rla_head.active_window.right, fp);
92 SHORTREAD(&head.rla_head.active_window.bottom, fp);
93 SHORTREAD(&head.rla_head.active_window.top, fp);
94 SHORTREAD(&head.rla_head.frame, fp);
95 SHORTREAD(&head.rla_head.storage_type, fp);
96 SHORTREAD(&head.rla_head.num_chan, fp);
97 SHORTREAD(&head.rla_head.num_matte, fp);
98 SHORTREAD(&head.rla_head.num_aux, fp);
99 SHORTREAD(&head.rla_head.aux_mask, fp);
100 fread(&head.rla_head.gamma, 16, 1, fp);
101 fread(&head.rla_head.red_pri, 24, 1, fp);
102 fread(&head.rla_head.green_pri, 24, 1, fp);
103 fread(&head.rla_head.blue_pri, 24, 1, fp);
104 fread(&head.rla_head.white_pt, 24, 1, fp);
105 LONGREAD(&head.rla_head.job_num, fp);
106 fread(&head.rla_head.name, 128, 1, fp);
107 fread(&head.rla_head.desc, 128, 1, fp);
108 fread(&head.rla_head.program, 64, 1, fp);
109 fread(&head.rla_head.machine, 32, 1, fp);
110 fread(&head.rla_head.user, 32, 1, fp);
111 fread(&head.rla_head.date, 20, 1, fp);
113 fread(&head.rlb_head.aspect, 24, 1, fp);
114 fread(&head.rlb_head.aspect_ratio, 8, 1, fp);
115 fread(&head.rlb_head.chan, 32, 1, fp);
116 SHORTREAD(&head.rlb_head.field, fp);
117 SHORTREAD(&head.rlb_head.filter_type, fp);
118 LONGREAD(&head.rlb_head.magic_number, fp);
119 LONGREAD(&head.rlb_head.lut_size, fp);
120 LONGREAD(&head.rlb_head.user_space_size, fp);
121 LONGREAD(&head.rlb_head.wf_space_size, fp);
122 SHORTREAD(&head.rlb_head.lut_type, fp);
123 SHORTREAD(&head.rlb_head.mix_type, fp);
124 SHORTREAD(&head.rlb_head.encode_type, fp);
125 SHORTREAD(&head.rlb_head.padding, fp);
126 fread(&head.rlb_head.space, 100, 1, fp);
129 fread(&head.rla_head.aspect, 32, 1, fp);
130 fread(&head.rla_head.chan, 32, 1, fp);
131 fread(&head.rla_head.space, 128, 1, fp);
134 if (fread(&head, 740, 1,
fp) != 1) {
135 fprintf(stderr,
"Error reading Wavefront file header!\n");
145 VPRINTF(stderr,
"Full image: %dx%d\n", *width, *height);
146 VPRINTF(stderr,
"Active window: %dx%d\n", *act_x_res, *act_y_res);
150 VPRINTF(stderr,
"Original filename: %s\n", head.rla_head
.name);
151 VPRINTF(stderr,
"Description: %s\n", head.rla_head
.desc);
161 VPRINTF(stderr,
"Aspect ratio: %s\n",
"-unused-");
163 VPRINTF(stderr,
"Channel color space %s\n", head.rla_head
.chan);
167 VPRINTF(stderr,
"Interlaced? %s\n",
"-unused-");
169 VPRINTF(stderr,
"Converting matte channel only...\n");
174 void write_rle_header()
200 decode(c_in, c_out, len)
223 for (ct = 256-ct; ct-- > 0; len--)
231 void write_rle_data()
241 U_CHAR *red, *green, *blue, *matte;
248 if (!(offset = (
int *)malloc(
sizeof(
int) *
act_y_res))) {
249 fprintf(stderr,
"Offset malloc failed!\n");
253 for (scan=0;scan<act_y_res;scan++) {
254 fread(&craybuf, 4, 1, fp); offset[scan] = craybuf >> 32;
258 fprintf(stderr,
"Offset table read failed!\n");
266 fprintf(stderr,
"Buf malloc failed!\n");
270 fprintf(stderr,
"Red scanline malloc failed!\n");
274 blue = &green[
width];
275 matte = &blue[
width];
281 fprintf(stderr,
"Unable to malloc space for pixels\n");
299 if (fseek(
fp, (
long)offset[scan-bottom], 0)) {
300 fprintf(stderr,
"rla file incomplete!\n");
307 fread(buf, 1, (
int)len,
fp);
308 decode(buf, red, (
int)len);
313 fread(buf, 1, (
int)len,
fp);
314 decode(buf, green, (
int)len);
319 fread(buf, 1, (
int)len,
fp);
320 decode(buf, blue, (
int)len);
325 fread(buf, 1, (
int)len,
fp);
326 decode(buf, matte, (
int)len);
341 scanline[0][x] = (red[x-left] ||
343 blue[x-left] ? 255 : 0);
346 scanline[0][x] = matte[x-left];
347 scanline[1][x] = red[x-left];
348 scanline[2][x] = green[x-left];
349 scanline[3][x] = blue[x-left];
358 VPRINTF(stderr,
"Done -- write oef to RLE data.\n");
380 char *periodP, *inname = NULL, *outname = NULL;
381 static char filename[BUFSIZ];
387 "% b%- v%- h%- m%- o%-outfile!s infile.rla%s",
398 if (inname == NULL) {
399 strcpy(filename,
"stdin");
403 periodP = strrchr(inname, (
int)
'.');
404 strcpy(filename, inname);
407 if (strcmp(periodP,
".rlb")) {
408 if (!strcmp(periodP,
".rla")) {
409 fprintf(stderr,
"This is an rla file -- don't use the -b flag.\n");
412 strcat(filename,
".rlb");
416 if (strcmp(periodP,
".rla")) {
417 if (!strcmp(periodP,
".rlb"))
420 strcat(filename,
".rla");
426 strcat(filename,
".rlb");
428 strcat(filename,
".rla");
429 if (!(
fp = fopen(filename,
"r"))) {
430 fprintf(stderr,
"Cannot open %s for reading.\n", filename);
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
#define RLE_SET_BIT(glob, bit)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
char * cmd_name(char **argv)
void main(int argc, char **argv)
int scanargs(int argc, char **argv, const char *format,...)
void rle_puteof(rle_hdr *the_hdr)
void rle_putrow(rows, int rowlen, rle_hdr *the_hdr)
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
void rle_skiprow(rle_hdr *the_hdr, int nrow)
void rle_put_setup(rle_hdr *the_hdr)
const char * rle_putcom(char *value, rle_hdr *the_hdr) const
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
#define SHORTREAD(var, fp)