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

Go to the source code of this file.

Macros

#define LINE_LENGTH   720
 
#define FRAME_LENGTH   486
 
#define shifty(val)   y4=y3;y3=y2;y2=y1;y1=y0;y0=(val)
 
#define shiftu(val)   u4=u3;u3=u2;u2=u1;u1=u0;u0=(val)
 
#define shiftv(val)   v4=v3;v3=v2;v2=v1;v1=v0;v0=(val)
 

Functions

void read_image ()
 
void send_image ()
 
void main (int argc, char **argv)
 
void read_image (int yrun, scanbuf, int minx, int maxy, int xrun)
 
void send_image (FILE *outfile)
 

Variables

rle_hdr hdr
 
rle_pixel scanred [486][720]
 
rle_pixel scanblu [486][720]
 
rle_pixel scangrn [486][720]
 

Macro Definition Documentation

#define FRAME_LENGTH   486

Definition at line 38 of file rletoabA60.c.

#define LINE_LENGTH   720

Definition at line 37 of file rletoabA60.c.

#define shiftu (   val)    u4=u3;u3=u2;u2=u1;u1=u0;u0=(val)

Definition at line 45 of file rletoabA60.c.

#define shiftv (   val)    v4=v3;v3=v2;v2=v1;v1=v0;v0=(val)

Definition at line 46 of file rletoabA60.c.

#define shifty (   val)    y4=y3;y3=y2;y2=y1;y1=y0;y0=(val)

Definition at line 44 of file rletoabA60.c.

Function Documentation

void main ( int  argc,
char **  argv 
)

Definition at line 56 of file rletoabA60.c.

59 {
60  char *infname = NULL,
61  *out_fname = NULL;
62  int cflag = 0,
63  Pflag = 0,
64  pflag = 0,
65  oflag = 0;
66  register int i, xrun, maxy;
67  int minx, maxx, miny, yrun, px, py;
68  int ix, iy;
69  rle_pixel *scanbuf[3];
70  FILE *outfile;
71 
72  if ( scanargs( argc, argv,
73  "% c%- P%-incx!dincy!d p%-posx!dposy!d o%-outfile!s infile%s\n(\
74 \t-c\tCenter image in Abekas frame.\n\
75 \t-p\tPosition image at given position.\n\
76 \t-P\tIncrementally position image by given offset.)",
77  &cflag,
78  &Pflag, &ix, &iy,
79  &pflag, &px, &py, &oflag, &out_fname, &infname ) == 0 )
80  exit(3);
81 
82  /* Initialize header. */
83  hdr = *rle_hdr_init( (rle_hdr *)NULL );
84  rle_names( &hdr, cmd_name( argv ), infname, 0 );
85 
86  if ( cflag + pflag + Pflag > 1 ) {
87  fprintf( stderr, "%s: specify exactly one of -c -p -P\n", hdr.cmd );
88  exit(3);
89  }
90  hdr.rle_file = rle_open_f(hdr.cmd, infname, "r");
91  outfile = rle_open_f(hdr.cmd, out_fname, "w");
92  /*
93  * Do the rle initialization stuff
94  */
95  rle_get_setup_ok( &hdr, NULL, NULL );
96 
97  if ( hdr.xmax > LINE_LENGTH || hdr.ymax > FRAME_LENGTH ) {
98  fprintf( stderr,"%s: rle image too big for Abekas\n", hdr.cmd);
99  exit(3);
100  }
102  for (i = 3 ; i < hdr.ncolors ; i++)
103  RLE_CLR_BIT( hdr, i );
104 
105  /*
106  * Initialize some variables.
107  */
108  bzero( scanred, LINE_LENGTH * FRAME_LENGTH );
109  bzero( scangrn, LINE_LENGTH * FRAME_LENGTH );
110  bzero( scanblu, LINE_LENGTH * FRAME_LENGTH );
111 
112  for (i=0; i<3; i++)
113  scanbuf[i] = (rle_pixel *) malloc ( LINE_LENGTH * sizeof(rle_pixel));
114 
115  /*
116  * Put the entire rle image into a buffer upside down and centered.
117  */
118  xrun = hdr.xmax - hdr.xmin + 1;
119  yrun = hdr.ymax - hdr.ymin + 1;
120  if ( cflag ) {
121  minx = (LINE_LENGTH - xrun) / 2;
122  miny = (FRAME_LENGTH - yrun) / 2;
123  }
124  else if ( pflag ) {
125  minx = px;
126  miny = FRAME_LENGTH - (yrun + py);
127  }
128  else if ( Pflag ) {
129  minx = hdr.xmin + ix;
130  miny = FRAME_LENGTH - (yrun + hdr.ymin + iy);
131  }
132  else {
133  minx = hdr.xmin;
134  miny = FRAME_LENGTH - (yrun + hdr.ymin);
135  }
136 
137  maxx = minx + xrun - 1;
138  maxy = miny + yrun - 1;
139 
140  if ( maxx > LINE_LENGTH-1 )
141  xrun = LINE_LENGTH - minx;
142 
143  read_image( yrun, scanbuf, minx, maxy, xrun );
144  send_image( outfile );
145 
146  exit(0);
147 }
void send_image()
int xmin
Definition: rle.h:100
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
FILE * outfile
Definition: giftorle.c:61
rle_pixel scanred[486][720]
Definition: rletoabA60.c:51
static gif_pixel ** scanbuf
Definition: rletogif.c:39
int ymin
Definition: rle.h:100
string infname
Definition: getbob.c:68
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
const char * cmd
Definition: rle.h:133
Definition: rle.h:96
int xmax
Definition: rle.h:100
#define RLE_CLR_BIT(glob, bit)
Definition: rle.h:124
rle_pixel scangrn[486][720]
Definition: rletoabA60.c:53
int ymax
Definition: rle.h:100
rle_hdr hdr
Definition: rletoabA60.c:50
unsigned char rle_pixel
Definition: rle.h:56
void * malloc()
int i
Definition: rletorla.c:82
void read_image()
#define RLE_ALPHA
Definition: rle.h:65
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
rle_pixel scanblu[486][720]
Definition: rletoabA60.c:52
int cflag
Definition: getgmr.c:19
#define FRAME_LENGTH
Definition: rletoabA60.c:38
char * cmd_name(char **argv)
Definition: cmd_name.c:31
#define LINE_LENGTH
Definition: rletoabA60.c:37
int oflag
Definition: painttorle.c:45
void rle_get_setup_ok(rle_hdr *the_hdr, const char *prog_name, const char *file_name)
FILE * rle_file
Definition: rle.h:114
int ncolors
Definition: rle.h:100
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
void read_image ( )
void read_image ( int  yrun,
scanbuf  ,
int  minx,
int  maxy,
int  xrun 
)

Definition at line 150 of file rletoabA60.c.

154 {
155  register int line, upsidedowny;
156 
157  for( line = 0; line < yrun; line++ ) {
158  rle_getrow( &hdr, scanbuf );
159  upsidedowny = maxy - line;
160 
161  if ( ( upsidedowny > FRAME_LENGTH-1 ) || ( upsidedowny < 0 ) )
162  continue;
163 
164  bcopy( scanbuf[RLE_RED], &scanred[upsidedowny][minx], xrun );
165  bcopy( scanbuf[RLE_GREEN], &scangrn[upsidedowny][minx], xrun );
166  bcopy( scanbuf[RLE_BLUE], &scanblu[upsidedowny][minx], xrun );
167  }
168 
169 }
#define RLE_GREEN
Definition: rle.h:63
rle_pixel scanred[486][720]
Definition: rletoabA60.c:51
static gif_pixel ** scanbuf
Definition: rletogif.c:39
#define RLE_BLUE
Definition: rle.h:64
#define RLE_RED
Definition: rle.h:62
rle_pixel scangrn[486][720]
Definition: rletoabA60.c:53
rle_hdr hdr
Definition: rletoabA60.c:50
rle_pixel scanblu[486][720]
Definition: rletoabA60.c:52
#define FRAME_LENGTH
Definition: rletoabA60.c:38
int rle_getrow(rle_hdr *the_hdr, rle_pixel *scanline[])
void send_image ( )
void send_image ( FILE *  outfile)

Definition at line 172 of file rletoabA60.c.

174 {
175  unsigned char buf[LINE_LENGTH*5];
176  register unsigned char *bp;
177  int line, col;
178  register rle_pixel *sr, *sg, *sb;
179  register int r, g, b;
180  int y, u, v;
181  int y0=0, y1=0, y2=0, y3=0, y4=0;
182  int u0=0, u1=0, u2=0, u3=0, u4=0;
183  int v0=0, v1=0, v2=0, v3=0, v4=0;
184 
185  /*
186  * Convert the 720x486 rle image to yuv one byte at a time.
187  *
188  * All arithmetic is performed in "fixed point" integer for speed.
189  * The original equations are shown in comments.
190  */
191  for( line=0; line < FRAME_LENGTH; line++ ) {
192  sr = scanred[line];
193  sg = scangrn[line];
194  sb = scanblu[line];
195  bp = buf;
196 
197  for( col=0; col < LINE_LENGTH; col+=2 ) {
198  if ( *sr || *sg || *sb )
199  {
200  /*
201  * r = *sr++ / 255.0;
202  * g = *sg++ / 255.0;
203  * b = *sb++ / 255.0;
204  */
205  r = (*sr++ * 8000000) / 255;
206  g = (*sg++ * 8000000) / 255;
207  b = (*sb++ * 8000000) / 255;
208 
209  /*
210  * shifty( ( 0.2990 * r + 0.5870 * g + 0.1140 * b));
211  * shiftu( (-0.1686 * r - 0.3311 * g + 0.4997 * b));
212  * shiftv( ( 0.4998 * r - 0.4185 * g - 0.0813 * b));
213  */
214  shifty( ( r / 33445 + g / 17036 + b / 87719) * 1000000 );
215  shiftu( (-r / 59312 - g / 30202 + b / 20012) * 1000000 );
216  shiftv( ( r / 20012 - g / 23895 - b / 123001) * 1000000 );
217  }
218  else
219  {
220  sr++; sg++; sb++;
221  shifty( 0 ); shiftu( 0 ); shiftv( 0 );
222  }
223 
224  /*
225  * u = ( (0.14963 * u0) + (0.22010 * u1)
226  * +(0.26054 * u2) + (0.22010 * u3)
227  * +(0.14963 * u4)) * 224;
228  */
229  u = ( (u0 / 66832) + (u1 / 45434)
230  +(u2 / 38382) + (u3 / 45434)
231  +(u4 / 66832)) * 224 / 80000;
232  *bp++ = u + 128;
233 
234  /*
235  * y = (-(0.05674 * y0) + (0.01883 * y1)
236  * +(1.07582 * y2) + (0.01883 * y3)
237  * -(0.05674 * y4)) * 219.0;
238  */
239  y = (-(y0 / 176243) + (y1 / 531067)
240  +(y1 / 9295) + (y3 / 531067)
241  -(y4 / 176243)) * 219 / 80000;
242  *bp++ = y + 16;
243 
244  /*
245  * v = ((0.14963 * v0) + (0.22010 * v1)
246  * +(0.26054 * v2) + (0.22010 * v3)
247  * +(0.14963 * v4)) * 224.0;
248  */
249  v = ( (v0 / 66832) + (v1 / 45434)
250  +(v2 / 38382) + (v3 / 45434)
251  +(v4 / 66832)) * 224 / 80000;
252  *bp++ = v + 128;
253 
254  if ( *sr || *sg || *sb )
255  {
256  r = (*sr++ * 8000000) / 255;
257  g = (*sg++ * 8000000) / 255;
258  b = (*sb++ * 8000000) / 255;
259 
260  shifty( ( r / 33445 + g / 17036 + b / 87719) * 1000000 );
261  shiftu( (-r / 59312 - g / 30202 + b / 20012) * 1000000 );
262  shiftv( ( r / 20012 - g / 23895 - b / 123001) * 1000000 );
263  }
264  else
265  {
266  sr++; sg++; sb++;
267  shifty( 0 ); shiftu( 0 ); shiftv( 0 );
268  }
269 
270  y = (-(y0 / 176243) + (y1 / 531067)
271  +(y1 / 9295) + (y3 / 531067)
272  -(y4 / 176243)) * 219 / 80000;
273  *bp++ = y + 16;
274  }
275 
276  fwrite( buf, 1, bp - buf, outfile );
277  }
278 }
static unsigned char g
Definition: getami.c:692
#define shiftv(val)
Definition: rletoabA60.c:46
FILE * outfile
Definition: giftorle.c:61
static unsigned char r
Definition: getami.c:692
rle_pixel scanred[486][720]
Definition: rletoabA60.c:51
static int y
Definition: getami.c:691
static unsigned char b
Definition: getami.c:692
static char buf[4096 +1]
Definition: into.c:46
#define shiftu(val)
Definition: rletoabA60.c:45
rle_pixel scangrn[486][720]
Definition: rletoabA60.c:53
unsigned char rle_pixel
Definition: rle.h:56
#define shifty(val)
Definition: rletoabA60.c:44
rle_pixel scanblu[486][720]
Definition: rletoabA60.c:52
#define FRAME_LENGTH
Definition: rletoabA60.c:38
#define LINE_LENGTH
Definition: rletoabA60.c:37

Variable Documentation

rle_hdr hdr

Definition at line 50 of file rletoabA60.c.

rle_pixel scanblu[486][720]

Definition at line 52 of file rletoabA60.c.

rle_pixel scangrn[486][720]

Definition at line 53 of file rletoabA60.c.

rle_pixel scanred[486][720]

Definition at line 51 of file rletoabA60.c.