Skip to content

Commit

Permalink
Fix the vertical stitching function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Rideout committed Aug 16, 2015
1 parent 699ce72 commit 17a172c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
1 change: 1 addition & 0 deletions docs/_static/overrides.css
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.wy-side-nav-search a { display: none }
.wy-side-nav-search .version { display: none }
16 changes: 8 additions & 8 deletions src/ops.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "image.h"
#include <assert.h>
#include <memory.h>

heman_image* heman_ops_step(heman_image* hmap, HEMAN_FLOAT threshold)
{
Expand Down Expand Up @@ -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;
}

Expand Down
28 changes: 19 additions & 9 deletions test/test_planet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

0 comments on commit 17a172c

Please sign in to comment.