Skip to content

Commit 91cdd6d

Browse files
committed
Parameterize output filename.
1 parent d557082 commit 91cdd6d

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ check: ${THE_TESTS}
2121
${SILENT}./${THE_TESTS}
2222

2323
approval: ${THE_PROGRAM}
24-
${SILENT}./${THE_PROGRAM} gd 800 500 100 0.0 0.0 4.0
24+
${SILENT}./${THE_PROGRAM} gd pngelbrot.png 800 500 100 0.0 0.0 4.0
2525
${SILENT}./${APPROVAL_TESTS} pngelbrot.png
2626

2727
valgrind: ${THE_TESTS}

main.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@
55
#include "mandelbrot.h"
66

77
static int usage(char *progname) {
8-
printf("usage: %s <library> <width> <height> <iterations> <a> <b> <range>\n",
8+
printf("usage: %s <library> <filename> <width> <height> <iterations> <a> <b> <range>\n",
99
basename(progname));
1010
return 77;
1111
}
1212

1313
int main(int argc, char *argv[]) {
14-
if (argc == 8) {
14+
if (argc == 9) {
1515
mandelbrot(
1616
argv[1],
17-
atoi(argv[2]),
17+
argv[2],
1818
atoi(argv[3]),
1919
atoi(argv[4]),
20-
atof(argv[5]) + I * atof(argv[6]),
21-
atof(argv[7])
20+
atoi(argv[5]),
21+
atof(argv[6]) + I * atof(argv[7]),
22+
atof(argv[8])
2223
);
2324
} else {
2425
return usage(argv[0]);

mandelbrot.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include "mandelbrot.h"
1313

14-
static const char *OUTPUTFILE = "pngelbrot.png";
1514
static const size_t NUM_COLORS = 5;
1615
static int rgb_colors[NUM_COLORS][3] = {
1716
{ 255, 255, 255 },
@@ -151,7 +150,7 @@ choose_color(size_t escape, size_t maximum_iterations)
151150
}
152151

153152
static void
154-
mandelbrot_cairo(size_t width, size_t height, size_t iterations, complex double center, double range)
153+
mandelbrot_cairo(const char *outputfile, size_t width, size_t height, size_t iterations, complex double center, double range)
155154
{
156155
cairo_surface_t *my_surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height);
157156
cairo_t *my_cairo = cairo_create(my_surface);
@@ -176,14 +175,14 @@ mandelbrot_cairo(size_t width, size_t height, size_t iterations, complex double
176175
}
177176
}
178177

179-
cairo_surface_write_to_png(my_surface, OUTPUTFILE);
178+
cairo_surface_write_to_png(my_surface, outputfile);
180179

181180
cairo_destroy(my_cairo);
182181
cairo_surface_destroy(my_surface);
183182
}
184183

185184
static void
186-
mandelbrot_gd(size_t width, size_t height, size_t iterations, complex double center, double range)
185+
mandelbrot_gd(const char *outputfile, size_t width, size_t height, size_t iterations, complex double center, double range)
187186
{
188187
gdImagePtr im = gdImageCreate(width, height);
189188
FILE *pngout;
@@ -203,17 +202,17 @@ mandelbrot_gd(size_t width, size_t height, size_t iterations, complex double cen
203202
}
204203
}
205204

206-
pngout = fopen(OUTPUTFILE, "wb");
205+
pngout = fopen(outputfile, "wb");
207206
gdImagePng(im, pngout);
208207

209208
fclose(pngout);
210209
gdImageDestroy(im);
211210
}
212211

213-
void mandelbrot(const char *backend, size_t width, size_t height, size_t iterations, complex double center, double range)
212+
void mandelbrot(const char *backend, const char *outputfile, size_t width, size_t height, size_t iterations, complex double center, double range)
214213
{
215214
if (0 == strcmp("cairo", backend))
216-
mandelbrot_cairo(width, height, iterations, center, range);
215+
mandelbrot_cairo(outputfile, width, height, iterations, center, range);
217216
else
218-
mandelbrot_gd(width, height, iterations, center, range);
217+
mandelbrot_gd(outputfile, width, height, iterations, center, range);
219218
}

mandelbrot.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ typedef struct extreme_coordinates {
66
complex double upper_right;
77
} extremes_t;
88

9-
void mandelbrot(const char *, size_t, size_t, size_t, complex double, double);
9+
void mandelbrot(const char *,const char *, size_t, size_t, size_t, complex double, double);
1010
extremes_t get_extreme_coordinates(size_t, size_t, complex double, double);
1111
complex double coords_for_pixel(size_t, size_t, complex double, double, size_t, size_t);
1212
size_t count_escape(complex double, size_t);

0 commit comments

Comments
 (0)