Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
rlemandl.c
Go to the documentation of this file.
1 /*
2  * rlemandl.c - Compute images of the Mandelbrot set in RLE format
3  *
4  * Author: John W. Peterson
5  * Computer Science Dept.
6  * University of Utah
7  * Date: Mon Nov 9 1987
8  * Copyright (c) 1987, University of Utah
9  */
10 
11 #include <stdio.h>
12 #include <math.h>
13 #include "rle.h"
14 
15 void
17 int argc;
18 char **argv;
19 {
20  char *out_fname = NULL;
21  rle_hdr out_hdr;
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 }
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
Definition: rle_open_f.c:216
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
Definition: rle_hdr.c:48
char * cmd_name(char **argv)
Definition: cmd_name.c:31
void main(int argc, char **argv)
Definition: aliastorle.c:121
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
Definition: rle_row_alc.c:56
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
void rle_puteof(rle_hdr *the_hdr)
Definition: rle_putrow.c:474
void rle_putrow(rows, int rowlen, rle_hdr *the_hdr)
Definition: rle_putrow.c:96
int xmax
Definition: rle.h:100
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
Definition: rle_addhist.c:54
int ymax
Definition: rle.h:100
unsigned char rle_pixel
Definition: rle.h:56
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
const char * rle_putcom(char *value, rle_hdr *the_hdr) const
Definition: rle_putcom.c:82
int alpha
Definition: rle.h:100
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
FILE * rle_file
Definition: rle.h:114
int ncolors
Definition: rle.h:100
#define RLE_CHECK_ALLOC(pgm, ptr, name)
Definition: rle.h:86