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

Go to the source code of this file.

Functions

void main (int argc, char **argv)
 

Function Documentation

void main ( int  argc,
char **  argv 
)

Definition at line 16 of file rlemandl.c.

19 {
20  char *out_fname = NULL;
22  char comment[128];
23  float real, imaginary, width, step;
24  float ypos, xpos;
25  rle_pixel ** rows;
26  int xsize = 256, ysize = 256;
27  int x_pixel, y_pixel;
28  int oflag = 0, offset = 1, junk, verbose = 0;
29  double scale = 1;
30  register int iter;
31  int stop;
32  /* May want to use floats...whatever's fastest */
33  register double z_r, z_i, z_rs, z_is;
34 
35  out_hdr = *rle_hdr_init( NULL );
36 
37  if (! scanargs(argc, argv,
38  "% v%- s%-xsize!dysize!d b%-band-scale!Fband-offset%d \n\
39 \to%-outfile!s real!f imag!f width!f",
40  &verbose,
41  &junk, &xsize, &ysize,
42  &junk, &scale, &offset,
43  &oflag, &out_fname,
44  &real, &imaginary, &width ))
45  exit( -2 );
46 
47  step = width / (double) xsize;
48 
49  sprintf( comment,
50  "Mandelbrot=set centered at (%g %g), width %g. Bands %g wide, offset %d.",
51  real, imaginary, width, scale, offset );
52 
53  xpos = real - width / 2.0;
54  ypos = imaginary - (step / 2.0) * (double) ysize;
55 
56  /* Re-use real as left margin */
57  real = xpos;
58 
59  /* Change the default rle_dflt_hdr struct to match what we need */
60  out_hdr.rle_file = rle_open_f(cmd_name( argv ), out_fname, "w");
61  rle_names( &out_hdr, cmd_name( argv ), out_fname, 0 );
62 
63  out_hdr.xmax = xsize - 1;
64  out_hdr.ymax = ysize - 1;
65  out_hdr.ncolors = 1; /* One output channel */
66  out_hdr.alpha = 0; /* No coverage (alpha) */
67 
68  rle_putcom( comment, &out_hdr );
69  rle_addhist( argv, (rle_hdr *)0, &out_hdr );
70 
71  /* Allocate storage for the output row */
72  if (rle_row_alloc( &out_hdr, &rows ) < 0)
73  RLE_CHECK_ALLOC( cmd_name( argv ), 0, 0 );
74 
75  /* Create the header in the output file */
76  rle_put_setup( &out_hdr );
77 
78  for (y_pixel = 0; y_pixel < ysize; y_pixel++)
79  {
80  xpos = real;
81  for (x_pixel = 0; x_pixel < xsize; x_pixel++)
82  {
83  z_r = 0;
84  z_i = 0;
85  iter = 0;
86  stop = scale * 255 + offset;
87  while (iter < stop &&
88  ((z_rs = z_r * z_r) + (z_is = z_i * z_i)) < 4)
89  {
90  z_i = 2 * z_r*z_i + ypos;
91  z_r = z_rs - z_is + xpos;
92  iter++;
93  }
94  if ( iter == stop )
95  iter = 255;
96  else
97  iter = (iter - offset) / scale;
98  rows[0][x_pixel] = (rle_pixel) (iter <= 0 ? 0 : iter);
99  xpos += step;
100  }
101  rle_putrow( rows, xsize + 1, &out_hdr );
102  if (verbose)
103  if ((y_pixel % 50) == 0)
104  fprintf(stderr, "line %d...\n", y_pixel);
105  ypos += step;
106  }
107  rle_puteof( &out_hdr );
108  exit( 0 );
109 }
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
Definition: rle_row_alc.c:56
const char * rle_putcom(const char *value, rle_hdr *the_hdr)
int width
Definition: pgmtorle.c:51
void rle_putrow(rle_pixel *rows[], int rowlen, rle_hdr *the_hdr)
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
int xsize
Definition: read98721.c:58
void rle_puteof(rle_hdr *the_hdr)
Definition: rle_putrow.c:474
int verbose
Definition: aliastorle.c:96
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
Definition: rle.h:96
int xmax
Definition: rle.h:100
rle_pixel ** rows
Definition: rletopaint.c:57
int ymax
Definition: rle.h:100
int ysize
Definition: read98721.c:59
unsigned char rle_pixel
Definition: rle.h:56
int alpha
Definition: rle.h:100
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
char * cmd_name(char **argv)
Definition: cmd_name.c:31
int oflag
Definition: painttorle.c:45
FILE * rle_file
Definition: rle.h:114
rle_hdr out_hdr
Definition: dvirle2.c:89
int ncolors
Definition: rle.h:100
#define RLE_CHECK_ALLOC(pgm, ptr, name)
Definition: rle.h:86
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267