From 17a172c830430eebeb8b48d4cd707449a053a6d7 Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Sun, 16 Aug 2015 16:41:27 -0700 Subject: [PATCH] Fix the vertical stitching function. --- docs/_static/overrides.css | 1 + src/ops.c | 16 ++++++++-------- test/test_planet.c | 28 +++++++++++++++++++--------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/docs/_static/overrides.css b/docs/_static/overrides.css index be7b601..bde12c7 100644 --- a/docs/_static/overrides.css +++ b/docs/_static/overrides.css @@ -1 +1,2 @@ .wy-side-nav-search a { display: none } +.wy-side-nav-search .version { display: none } diff --git a/src/ops.c b/src/ops.c index 9bed815..9b0a48e 100644 --- a/src/ops.c +++ b/src/ops.c @@ -1,5 +1,6 @@ #include "image.h" #include +#include heman_image* heman_ops_step(heman_image* hmap, HEMAN_FLOAT threshold) { @@ -80,20 +81,19 @@ heman_image* heman_ops_stitch_vertical(heman_image** images, int count) assert(count > 0); int width = images[0]->width; int height = images[0]->height; + int nbands = images[0]->nbands; for (int i = 0; i < count; i++) { assert(images[i]->width == width); assert(images[i]->height == height); - assert(images[i]->nbands == 1 || images[i]->nbands == 3); + assert(images[i]->nbands == nbands); } heman_image* result = heman_image_create(width, height * count, 3); - -#pragma omp parallel for - for (int y = 0; y < height; y++) { - for (int tile = 0; tile < count; tile++) { - copy_row(images[tile], result, 0, y + height * tile); - } + int size = width * height * nbands; + HEMAN_FLOAT* dst = result->data; + for (int tile = 0; tile < count; tile++) { + memcpy(dst, images[tile]->data, size * sizeof(float)); + dst += size; } - return result; } diff --git a/test/test_planet.c b/test/test_planet.c index 72e60c3..d902a1d 100644 --- a/test/test_planet.c +++ b/test/test_planet.c @@ -3,8 +3,7 @@ #define COUNT(a) (sizeof(a) / sizeof(a[0])) #define OUTFOLDER "build/" -#define SEED 7000 -#define HEIGHT 512 +#define HEIGHT 256 static int CP_LOCATIONS[] = { 000, // Dark Blue @@ -30,17 +29,28 @@ static heman_color CP_COLORS[] = { static float LIGHTPOS[] = {-0.5f, 0.5f, 1.0f}; -int main(int argc, char** argv) +heman_image* make_planet(int seed, heman_image* grad) { - heman_image* grad = heman_color_create_gradient( - 256, COUNT(CP_COLORS), CP_LOCATIONS, CP_COLORS); - heman_image* hmap = heman_generate_planet_heightmap(HEIGHT * 2, HEIGHT, SEED); + heman_image* hmap = heman_generate_planet_heightmap(HEIGHT * 2, HEIGHT, seed); heman_image* albedo = heman_color_apply_gradient(hmap, -0.5, 0.5, grad); - heman_image_destroy(grad); heman_image* planet = heman_lighting_apply(hmap, albedo, 1, 1, 0.75, LIGHTPOS); heman_image_destroy(hmap); heman_image_destroy(albedo); - hut_write_image(OUTFOLDER "planet.png", planet, 0, 1); - heman_image_destroy(planet); + return planet; +} + +int main(int argc, char** argv) +{ + heman_image* grad = heman_color_create_gradient( + 256, COUNT(CP_COLORS), CP_LOCATIONS, CP_COLORS); + heman_image* tiles[2]; + tiles[0] = make_planet(1000, grad); + tiles[1] = make_planet(1001, grad); + heman_image* planets = heman_ops_stitch_vertical(tiles, 2); + heman_image_destroy(tiles[0]); + heman_image_destroy(tiles[1]); + hut_write_image(OUTFOLDER "planets.png", planets, 0, 1); + heman_image_destroy(planets); + heman_image_destroy(grad); }