Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
Data Structures | Macros | Typedefs | Functions | Variables
rletoabA62.c File Reference
#include <stdio.h>
Include dependency graph for rletoabA62.c:

Go to the source code of this file.

Data Structures

struct  yiq_t
 

Macros

#define TRUE   1
 
#define FALSE   0
 
#define WIDTH   768
 
#define HEIGHT   512
 
#define OUT(y, OP, iq)   putc((char) (raster[i][j + 0].y OP raster[i][j + 0].iq + 60), stdout);
 

Typedefs

typedef char bool
 

Functions

void rasterInit ()
 
void rasterRowGet ()
 
void rasterDone ()
 
void filterY ()
 
void filterIQ ()
 
void dump1 ()
 
void dump2 ()
 
void main (int argc, char **argv)
 
void filterY (float *yVal, float c0, float c1, float c2)
 
void filterIQ (float *iqVal, float c0, float c1, float c2, int start, int stride)
 
void dump1 (yiq_t **raster, int start)
 
void dump2 (yiq_t **raster, int start)
 

Variables

static char rcsid [] = "$Header: /l/spencer/src/urt/cnv/rletoabA62/RCS/rletoabA62.c,v 3.0.1.1 1992/04/30 14:15:19 spencer Exp $"
 
int Width = 768
 
int Height = 512
 
int Debug = 0
 
bool NoFilter = 0
 
int Frame = 1
 
int NumFrames = 2
 
int BkgRed = 0
 
int BkgBlue = 0
 
int BkgGreen = 0
 
char * optarg
 
int optind
 

Macro Definition Documentation

#define FALSE   0

Definition at line 48 of file rletoabA62.c.

#define HEIGHT   512

Definition at line 57 of file rletoabA62.c.

#define OUT (   y,
  OP,
  iq 
)    putc((char) (raster[i][j + 0].y OP raster[i][j + 0].iq + 60), stdout);

Definition at line 378 of file rletoabA62.c.

#define TRUE   1

Definition at line 47 of file rletoabA62.c.

#define WIDTH   768

Definition at line 56 of file rletoabA62.c.

Typedef Documentation

typedef char bool

Definition at line 50 of file rletoabA62.c.

Function Documentation

void dump1 ( )
void dump1 ( yiq_t **  raster,
int  start 
)

Definition at line 380 of file rletoabA62.c.

383 {
384  register int i, j;
385 
386  for (i = start; i < Height; i += 4) { /* field I */
387  for (j = 0; j < Width; j += 4) {
388  putc((char) (raster[i][j + 0].y + raster[i][j + 0].i + 60), stdout);
389  putc((char) (raster[i][j + 1].y + raster[i][j + 1].q + 60), stdout);
390  putc((char) (raster[i][j + 2].y - raster[i][j + 2].i + 60), stdout);
391  putc((char) (raster[i][j + 3].y - raster[i][j + 3].q + 60), stdout);
392  }
393  for (j = 0; j < Width; j += 4) {
394  putc((char) (raster[i + 2][j + 0].y - raster[i + 2][j + 0].i + 60), stdout);
395  putc((char) (raster[i + 2][j + 1].y - raster[i + 2][j + 1].q + 60), stdout);
396  putc((char) (raster[i + 2][j + 2].y + raster[i + 2][j + 2].i + 60), stdout);
397  putc((char) (raster[i + 2][j + 3].y + raster[i + 2][j + 3].q + 60), stdout);
398  }
399  }
400 }
static int y
Definition: getami.c:691
int i
Definition: rletorla.c:82
int Height
Definition: rletoabA62.c:67
int Width
Definition: rletoabA62.c:66
void dump2 ( )
void dump2 ( yiq_t **  raster,
int  start 
)

Definition at line 412 of file rletoabA62.c.

415 {
416  register int i, j;
417 
418  for (i = start; i < Height; i += 4) { /* field I */
419  for (j = 0; j < Width; j += 4) {
420  putc((char) (raster[i][j + 0].y - raster[i][j + 0].i + 60), stdout);
421  putc((char) (raster[i][j + 1].y - raster[i][j + 1].q + 60), stdout);
422  putc((char) (raster[i][j + 2].y + raster[i][j + 2].i + 60), stdout);
423  putc((char) (raster[i][j + 3].y + raster[i][j + 3].q + 60), stdout);
424  }
425  for (j = 0; j < Width; j += 4) {
426  putc((char) (raster[i + 2][j + 0].y + raster[i + 2][j + 0].i + 60), stdout);
427  putc((char) (raster[i + 2][j + 1].y + raster[i + 2][j + 1].q + 60), stdout);
428  putc((char) (raster[i + 2][j + 2].y - raster[i + 2][j + 2].i + 60), stdout);
429  putc((char) (raster[i + 2][j + 3].y - raster[i + 2][j + 3].q + 60), stdout);
430  }
431  }
432 }
static int y
Definition: getami.c:691
int i
Definition: rletorla.c:82
int Height
Definition: rletoabA62.c:67
int Width
Definition: rletoabA62.c:66
void filterIQ ( )
void filterIQ ( float *  iqVal,
float  c0,
float  c1,
float  c2,
int  start,
int  stride 
)

Definition at line 345 of file rletoabA62.c.

348 {
349  static float *m0 = NULL;
350  static float *m1 = NULL;
351  static float *m2 = NULL;
352  register int i;
353 
354  if (m1 == NULL) {
355  m0 = (float *) calloc(Width + 4, sizeof(float));
356  m1 = (float *) calloc(Width + 4, sizeof(float));
357  m2 = (float *) calloc(Width + 4, sizeof(float));
358  }
359  for (i = -2; i < Width + 2; i++) {
360  m0[i] = c0 * iqVal[i];
361  m1[i] = c1 * iqVal[i];
362  m2[i] = c2 * iqVal[i];
363  }
364  for (i = start; i < Width; i += stride) {
365  iqVal[i] = m2[i - 2] + m1[i - 1] + m0[i] + m1[i + 1] + m2[i + 2];
366  }
367 }
int i
Definition: rletorla.c:82
int Width
Definition: rletoabA62.c:66
void filterY ( )
void filterY ( float *  yVal,
float  c0,
float  c1,
float  c2 
)

Definition at line 307 of file rletoabA62.c.

309 {
310  static float *m0 = NULL;
311  static float *m1 = NULL;
312  static float *m2 = NULL;
313  register int i;
314 
315  if (m1 == NULL) {
316  m0 = (float *) calloc(Width + 8, sizeof(float));
317  m1 = (float *) calloc(Width + 8, sizeof(float));
318  m2 = (float *) calloc(Width + 8, sizeof(float));
319  }
320  for (i = -4; i < Width + 4; i++) {
321  m0[i] = c0 * yVal[i];
322  m1[i] = c1 * yVal[i];
323  m2[i] = c2 * yVal[i];
324  }
325  for (i = 0; i < Width; i++) {
326  yVal[i] = m2[i - 4] + m1[i - 3] + m0[i - 2] + m1[i - 1] + m2[i];
327  }
328 }
int i
Definition: rletorla.c:82
int Width
Definition: rletoabA62.c:66
void main ( int  argc,
char **  argv 
)

Definition at line 105 of file rletoabA62.c.

108 {
109  register int i, j;
110  int errors, c, file;
111  float rTOy[256], gTOy[256], bTOy[256];
112  float rTOi[256], gTOi[256], bTOi[256];
113  float rTOq[256], gTOq[256], bTOq[256];
114  float *iVal, *yVal, *qVal, *tmpVal;
115  unsigned char *red, *green, *blue;
116  int r, g, b;
117  yiq_t **raster;
118 
119  /*
120  * Parse program arguments...
121  *
122  * The -w and -h args should actually not be used.
123  */
124 
125  errors = 0;
126  while ((c = getopt(argc, argv, "Nn:f:w:h:d:D:b")) != EOF) {
127  switch (c) {
128  case 'b':
129  BkgRed = atoi(argv[optind++]);
130  BkgGreen = atoi(argv[optind++]);
131  BkgBlue = atoi(argv[optind++]);
132  break;
133  case 'N':
134  NoFilter = TRUE;
135  break;
136  case 'w':
137  Width = atoi(optarg);
138  break;
139  case 'f':
140  Frame = atoi(optarg);
141  break;
142  case 'n':
143  NumFrames = atoi(optarg);
144  break;
145  case 'h':
146  Height = atoi(optarg);
147  break;
148  case 'D':
149  Debug = atoi(optarg);
150  break;
151  case '?':
152  errors++;
153  }
154  }
155  if (errors > 0) {
156  fprintf(stderr, "Usage: %s [-n] [-D debug-level] [file]\n", argv[0]);
157  exit(1);
158  }
159  if (optind < argc) {
160  if ((file = open(argv[optind], 0)) == -1) {
161  perror(argv[optind]);
162  exit(1);
163  }
164  } else {
165  file = 0;
166  }
167 
168  /*
169  * Initialize the type manager for Utah RLE files
170  */
171 
173 
174  /*
175  * Allocate storage for the RGB inputs, the computed YIQ, and the
176  * results. This is all dynamically allocated because the dimensions of
177  * the framestore are only decided at run time.
178  *
179  * The YIQ arrays are extended two entries at either end to simplify the
180  * filtering code. The effect is that the iVal and qVal arrays can be
181  * indexed [-2 .. Width+2] and yVal [-4 .. Width+4] (the stuff at the
182  * end of the yVal array isn't used).
183  */
184 
185  red = (unsigned char *) calloc(Width, sizeof *red);
186  green = (unsigned char *) calloc(Width, sizeof *green);
187  blue = (unsigned char *) calloc(Width, sizeof *blue);
188 
189  tmpVal = (float *) calloc(Width + 8, sizeof *yVal);
190  yVal = tmpVal + 4;
191  tmpVal = (float *) calloc(Width + 4, sizeof *iVal);
192  iVal = tmpVal + 2;
193  tmpVal = (float *) calloc(Width + 4, sizeof *qVal);
194  qVal = tmpVal + 2;
195 
196  /*
197  * Allocate storage to hold the 8-bit YIQ values for the entire
198  * picture.
199  */
200 
201  raster = (yiq_t **) calloc(Height, sizeof *raster);
202  for (i = 0; i < Height; i++) {
203  raster[i] = (yiq_t *) calloc(Width, sizeof **raster);
204  }
205 
206  /*
207  * Build the mappings from R,G,B to Y,I,Q. The pedastal is factored
208  * into this mapping.
209  */
210 
211  for (i = 0; i < 256; i++) {
212  rTOy[i] = ((float) i / 255.0 * 0.925 + 0.075) * 0.299;
213  gTOy[i] = ((float) i / 255.0 * 0.925 + 0.075) * 0.587;
214  bTOy[i] = ((float) i / 255.0 * 0.925 + 0.075) * 0.114;
215 
216  rTOi[i] = ((float) i / 255.0 * 0.925 + 0.075) * 0.596;
217  gTOi[i] = ((float) i / 255.0 * 0.925 + 0.075) * -0.274;
218  bTOi[i] = ((float) i / 255.0 * 0.925 + 0.075) * -0.322;
219 
220  rTOq[i] = ((float) i / 255.0 * 0.925 + 0.075) * 0.211;
221  gTOq[i] = ((float) i / 255.0 * 0.925 + 0.075) * -0.523;
222  bTOq[i] = ((float) i / 255.0 * 0.925 + 0.075) * 0.312;
223  }
224 
225  /*
226  * process the input raster line by raster line
227  */
228 
229  for (i = 0; i < Height; i++) {
230  rasterRowGet(red, green, blue);
231  yVal[-4] = yVal[-3] = yVal[-2] = yVal[-1] = 0;
232  iVal[-2] = iVal[-1] = 0;
233  qVal[-2] = qVal[-1] = 0;
234  yVal[Width + 3] = yVal[Width + 2] = yVal[Width + 1] = yVal[Width + 0] = 0;
235  iVal[Width + 0] = iVal[Width + 1] = 0;
236  qVal[Width + 0] = qVal[Width + 1] = 0;
237 
238  /*
239  * Convert RGB to YIQ. The multiplication is done by table lookup
240  * into the [rgb]TO[yiq] arrays.
241  */
242 
243  for (j = 0; j < Width; j++) {
244  r = red[j];
245  g = green[j];
246  b = blue[j];
247  yVal[j] = rTOy[r] + gTOy[g] + bTOy[b];
248  iVal[j] = rTOi[r] + gTOi[g] + bTOi[b];
249  qVal[j] = rTOq[r] + gTOq[g] + bTOq[b];
250  }
251  if (!NoFilter) {
252  filterY(yVal, 0.62232, 0.21732, -0.02848);
253  filterIQ(iVal, 0.42354, 0.25308, 0.03515, 0, 2);
254  filterIQ(qVal, 0.34594, 0.25122, 0.07581, 1, 2);
255  }
256  /*
257  * Build the YIQ raster
258  */
259 
260  for (j = 0; j < Width; j++) {
261  raster[Height - i - 1][j].y = yVal[j] * 140.0;
262  raster[Height - i - 1][j].i = iVal[j] * 140.0;
263  raster[Height - i - 1][j].q = qVal[j] * 140.0;
264  }
265  }
266 
267  /*
268  * Dump the raster as four color fields.
269  *
270  * Assert that Width%4 ==0 and Height%4 == 0
271  *
272  * Despite what the A62 SCSI manual says, for frames I and IV, the even
273  * numbered lines (starting with line 0) begin Y-I and the others begin
274  * Y+I.
275  */
276 
277  for (i = 0; i < NumFrames; i++) {
278  switch ((i + Frame - 1) % 4 + 1) {
279  case 1:
280  dump2(raster, 0); /* even lines, starts Y-I */
281  break;
282  case 2:
283  dump1(raster, 1); /* odd lines, starts Y+I */
284  break;
285  case 3:
286  dump1(raster, 0); /* even lines, starts Y+I */
287  break;
288  case 4:
289  dump2(raster, 1); /* odd lines, starts Y-I */
290  break;
291  }
292  }
293  exit(0);
294 }
static unsigned char g
Definition: getami.c:692
int getopt(int argc, argv, char *optstring)
Definition: getopt.c:37
static unsigned char blue[256]
Definition: rastorle.c:71
char y
Definition: rletoabA62.c:80
static unsigned char r
Definition: getami.c:692
char q
Definition: rletoabA62.c:80
static unsigned char b
Definition: getami.c:692
int BkgBlue
Definition: rletoabA62.c:73
void dump1()
void rasterRowGet()
#define TRUE
Definition: rletoabA62.c:47
static unsigned char green[256]
Definition: rastorle.c:71
void filterY()
void rasterInit()
int BkgGreen
Definition: rletoabA62.c:74
void filterIQ()
int optind
Definition: getopt.c:30
int Frame
Definition: rletoabA62.c:70
int BkgRed
Definition: rletoabA62.c:72
int NumFrames
Definition: rletoabA62.c:71
rle_pixel * raster
Definition: wedge.c:24
int i
Definition: rletorla.c:82
int Height
Definition: rletoabA62.c:67
int Debug
Definition: rletoabA62.c:68
bool NoFilter
Definition: rletoabA62.c:69
char * optarg
Definition: getopt.c:29
void dump2()
int Width
Definition: rletoabA62.c:66
static unsigned char red[256]
Definition: rastorle.c:71
char i
Definition: rletoabA62.c:80
void rasterDone ( )

Definition at line 103 of file rle.c.

References hdr, and rle_puteof().

104 {
105  rle_puteof(&hdr);
106 }
rle_hdr hdr
Definition: rle.c:21
void rle_puteof(rle_hdr *the_hdr)
Definition: rle_putrow.c:474

Here is the call graph for this function:

void rasterInit ( )
void rasterRowGet ( )

Variable Documentation

int BkgBlue = 0

Definition at line 73 of file rletoabA62.c.

int BkgGreen = 0

Definition at line 74 of file rletoabA62.c.

int BkgRed = 0

Definition at line 72 of file rletoabA62.c.

int Debug = 0

Definition at line 68 of file rletoabA62.c.

int Frame = 1

Definition at line 70 of file rletoabA62.c.

int Height = 512

Definition at line 67 of file rletoabA62.c.

bool NoFilter = 0

Definition at line 69 of file rletoabA62.c.

int NumFrames = 2

Definition at line 71 of file rletoabA62.c.

char* optarg

Definition at line 29 of file getopt.c.

int optind

Definition at line 30 of file getopt.c.

char rcsid[] = "$Header: /l/spencer/src/urt/cnv/rletoabA62/RCS/rletoabA62.c,v 3.0.1.1 1992/04/30 14:15:19 spencer Exp $"
static

Definition at line 39 of file rletoabA62.c.

int Width = 768

Definition at line 66 of file rletoabA62.c.