summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bmp.c46
-rw-r--r--bmp.h8
-rw-r--r--color.h2
-rw-r--r--nebula2.c26
-rw-r--r--render.c86
5 files changed, 84 insertions, 84 deletions
diff --git a/bmp.c b/bmp.c
index 5ca1594..246b5d3 100644
--- a/bmp.c
+++ b/bmp.c
@@ -22,59 +22,59 @@ static const char* header_template = "BM \0\0\0\0\x36\0\0\0\x28\0\0\0
static int
bmp_write_header(bmp_write_handle_t* bmph) {
- char* header;
+ char* header;
uint32_t filesize;
- int32_t height;
-
+ int32_t height;
+
if(!(header = malloc(HEADERSIZE))) {
fputs("Could not allocate memory for BMP header.\n", stderr);
return 0;
}
-
+
filesize = HEADERSIZE + (bmph->width * BYTES_PER_PIXEL + bmph->line_padding) * bmph->height;
- height = -(bmph->height);
-
+ height = -(bmph->height);
+
memcpy(header, header_template, HEADERSIZE);
memcpy(header + OFFSET_bfSize, &filesize, 4);
memcpy(header + OFFSET_biWidth, &(bmph->width), 4);
memcpy(header + OFFSET_biHeight, &height, 4);
-
+
if(fwrite(header, HEADERSIZE, 1, bmph->fh) != 1) {
fprintf(stderr, "Could not write BMP header: %s\n", strerror(errno));
free(header);
return 0;
}
-
+
free(header);
return 1;
}
bmp_write_handle_t*
bmp_create(const char* fn, int32_t width, int32_t height) {
- FILE* fh = NULL;
+ FILE* fh = NULL;
bmp_write_handle_t* rv;
-
+
if(!(fh = fopen(fn, "wb"))) {
return NULL;
}
-
+
if(!(rv = malloc(sizeof(bmp_write_handle_t)))) {
fclose(fh);
return NULL;
}
-
- rv->fh = fh;
- rv->width = width;
- rv->height = height;
- rv->line_left = width;
+
+ rv->fh = fh;
+ rv->width = width;
+ rv->height = height;
+ rv->line_left = width;
rv->line_padding = bmp_calc_padding(width);
-
+
if(!bmp_write_header(rv)) {
fclose(fh);
free(rv);
return NULL;
}
-
+
return rv;
}
@@ -86,19 +86,19 @@ bmp_write_pixel(bmp_write_handle_t* bmph, color_t col) {
pixel[0] = col.b;
pixel[1] = col.g;
pixel[2] = col.r;
-
+
if(fwrite(pixel, 3, 1, bmph->fh) != 1) {
return 0;
}
-
+
if(bmph->line_padding != 0) {
if(--(bmph->line_left) == 0) {
bmph->line_left = bmph->width;
-
+
return (fwrite(padding, bmph->line_padding, 1, bmph->fh) == 1);
}
}
-
+
return 1;
}
@@ -107,6 +107,6 @@ bmp_destroy(bmp_write_handle_t* bmph) {
if(bmph->fh) {
fclose(bmph->fh);
}
-
+
free(bmph);
}
diff --git a/bmp.h b/bmp.h
index 89ab893..a1753cd 100644
--- a/bmp.h
+++ b/bmp.h
@@ -8,13 +8,13 @@
typedef struct {
int32_t width, height;
- size_t line_padding;
- size_t line_left;
- FILE* fh;
+ size_t line_padding;
+ size_t line_left;
+ FILE* fh;
} bmp_write_handle_t;
extern bmp_write_handle_t* bmp_create(const char* fn, int32_t width, int32_t height);
extern int bmp_write_pixel(bmp_write_handle_t* bmph, color_t col);
extern void bmp_destroy(bmp_write_handle_t* bmph);
-#endif \ No newline at end of file
+#endif
diff --git a/color.h b/color.h
index 61a5a56..0e474d1 100644
--- a/color.h
+++ b/color.h
@@ -9,4 +9,4 @@ extern color_t color_fix(color_t col);
extern color_t color_add(color_t a, color_t b);
extern color_t color_mul(color_t col, double s);
-#endif \ No newline at end of file
+#endif
diff --git a/nebula2.c b/nebula2.c
index 1e0a948..2308d68 100644
--- a/nebula2.c
+++ b/nebula2.c
@@ -156,11 +156,11 @@ calc_pos(double zx, double zy, size_t width, size_t height, double conv, int hw,
pos_t rv;
rv.x = fast_floor(zx * conv) + hw;
rv.y = fast_floor(zy * conv) + hh;
-
+
if((rv.x < 0) || (rv.y < 0) || (rv.x >= width) || (rv.y >= height)) {
rv.x = -1;
}
-
+
return rv;
}
@@ -176,21 +176,21 @@ worker(void* _wd) {
double cx, cy, zx, zy;
/* Misc... */
- int todo;
- int iter, maxiter, mii;
- size_t off, mapsize;
- pos_t pos;
+ int todo;
+ int iter, maxiter, mii;
+ size_t off, mapsize;
+ pos_t pos;
/* Aliases */
worker_data_t* wd = _wd;
nebula_data_t* nd = wd->nd;
config_t* conf = wd->conf;
sfmt_t* sfmt_state = wd->sfmt_state;
- pos_t* pointlist;
- uint32_t* map = nd->map;
- size_t width = conf->width;
- size_t height = conf->height;
-
+ pos_t* pointlist;
+ uint32_t* map = nd->map;
+ size_t width = conf->width;
+ size_t height = conf->height;
+
precalc_nebula_params(conf, &conv, &mult_x, &mult_y, &hw, &hh);
mapsize = width * height;
maxiter = conf->iters[conf->iters_n - 1];
@@ -359,7 +359,7 @@ setup_sighandler(void) {
void
stop_workers(nebula_data_t* nd, worker_data_t* workers, int* workers_alive) {
int rq;
-
+
while(*workers_alive > 0) {
rq = jobrq_get(nd);
if(rq >= 0) {
@@ -424,7 +424,7 @@ nebula2(config_t* conf) {
fprintf(stderr, "Error while saving state: %s\n", strerror(errno));
goto tidyup;
}
-
+
rv = render(conf, nd->map) ? 0 : 1;
tidyup:
diff --git a/render.c b/render.c
index 49b0d33..e78d91b 100644
--- a/render.c
+++ b/render.c
@@ -11,11 +11,11 @@
/* Adding submap i to all submaps > i to reconstruct the result of single buddhabrot calculations. */
static void
add_submaps(config_t* conf, uint32_t* map) {
- int i, j;
+ int i, j;
size_t k, mapsize, off_i, off_j;
-
+
mapsize = conf->width * conf->height;
-
+
for(i = conf->iters_n - 1; i <= 0; i--) {
off_i = mapsize * i;
for(j = 0; j < i; j++) {
@@ -28,7 +28,7 @@ add_submaps(config_t* conf, uint32_t* map) {
}
typedef struct lookup_elem_t {
- uint32_t val;
+ uint32_t val;
struct lookup_elem_t* prev;
struct lookup_elem_t* next;
} lookup_elem_t;
@@ -39,22 +39,22 @@ new_lookup_elem(uint32_t val, lookup_elem_t* prev, lookup_elem_t* next) {
if(!rv) {
return NULL;
}
-
- rv->val = val;
+
+ rv->val = val;
rv->prev = prev;
rv->next = next;
-
+
return rv;
}
static int
maybe_insert(uint32_t val, lookup_elem_t* a, lookup_elem_t* b) {
lookup_elem_t* new;
-
+
if(!(new = new_lookup_elem(val, a, b))) {
return 0;
}
-
+
if(!a) {
b->prev = new;
return 1;
@@ -63,7 +63,7 @@ maybe_insert(uint32_t val, lookup_elem_t* a, lookup_elem_t* b) {
a->next = new;
return 1;
}
-
+
if((a->val < val) && (val < b->val)) {
a->next = new;
b->prev = new;
@@ -75,24 +75,24 @@ maybe_insert(uint32_t val, lookup_elem_t* a, lookup_elem_t* b) {
static int
build_lookup(uint32_t* map, size_t mapsize, lookup_elem_t** e) {
- size_t i;
+ size_t i;
uint32_t val;
-
+
for(i = 0; i < mapsize; i++) {
val = map[i];
-
+
if(!*e) {
if(!(*e = new_lookup_elem(val, NULL, NULL))) {
return 0;
}
continue;
}
-
- for(;;) {
+
+ for(;; ) {
if((*e)->val == val) {
break;
}
-
+
if(val > (*e)->val) {
if(!maybe_insert(val, *e, (*e)->next)) {
return 0;
@@ -106,26 +106,26 @@ build_lookup(uint32_t* map, size_t mapsize, lookup_elem_t** e) {
}
}
}
-
+
while((*e)->prev) {
*e = (*e)->prev;
}
-
+
return 1;
}
static size_t
lookup_len(lookup_elem_t* e) {
size_t len;
-
+
if(!e) {
return 0;
}
-
+
while(e->prev) {
e = e->prev;
}
-
+
len = 0;
while(e) {
len++;
@@ -163,58 +163,58 @@ lookup(uint32_t val, lookup_elem_t** e, size_t* pos) {
int
render(config_t* conf, uint32_t* map) {
- int rv = 0;
- size_t i, j;
- color_t col;
- double factor;
- bmp_write_handle_t* bmph = NULL;
- size_t mapsize = conf->width * conf->height;
-
+ int rv = 0;
+ size_t i, j;
+ color_t col;
+ double factor;
+ bmp_write_handle_t* bmph = NULL;
+ size_t mapsize = conf->width * conf->height;
+
lookup_elem_t** lookups = NULL;
- size_t* poss = NULL;
- size_t* lens = NULL;
-
+ size_t* poss = NULL;
+ size_t* lens = NULL;
+
lookups = calloc(sizeof(lookup_elem_t*), conf->iters_n);
- poss = calloc(sizeof(size_t), conf->iters_n);
- lens = calloc(sizeof(size_t), conf->iters_n);
+ poss = calloc(sizeof(size_t), conf->iters_n);
+ lens = calloc(sizeof(size_t), conf->iters_n);
if((!lookups) || (!poss) || (!lens)) {
fputs("Could not allocate memory for lookup tables.\n", stderr);
goto tidyup;
}
-
+
if(!(bmph = bmp_create(conf->output, conf->width, conf->height))) {
fprintf(stderr, "Could not create BMP.\n");
/* TODO: More details? */
goto tidyup;
}
-
+
add_submaps(conf, map);
-
+
for(i = 0; i < conf->iters_n; i++) {
- if(!build_lookup(map+(mapsize*i), mapsize, &(lookups[i]))) {
+ if(!build_lookup(map + (mapsize * i), mapsize, &(lookups[i]))) {
fputs("Could not build lookup table.\n", stderr);
goto tidyup;
}
lens[i] = lookup_len(lookups[i]);
}
-
+
for(i = 0; i < mapsize; i++) {
col.r = 0;
col.g = 0;
col.b = 0;
-
+
for(j = 0; j < conf->iters_n; j++) {
factor = (double) lookup(map[i + mapsize * j], &(lookups[j]), &(poss[j])) / (double) lens[j];
- col = color_add(col, color_mul(conf->colors[j], factor));
+ col = color_add(col, color_mul(conf->colors[j], factor));
}
if(!bmp_write_pixel(bmph, color_fix(col))) {
fputs("Could not write pixel data.\n", stderr);
goto tidyup;
}
}
-
+
rv = 1;
-
+
tidyup:
if(bmph) {
bmp_destroy(bmph);
@@ -233,6 +233,6 @@ tidyup:
if(lens) {
free(lens);
}
-
+
return rv;
}