From 2c340f0e43bc4af78a425aee5ba37af2dde4570e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Fri, 14 Jun 2013 13:39:45 +0200 Subject: [PATCH] Added quick unit test for perspective correction --- src/rendering/render.c | 11 +++++++++++ src/rendering/render.h | 2 ++ src/rendering/tools/color.c | 24 ++++++++++++++++++------ src/rendering/tools/color.h | 3 ++- src/testing/common.h | 1 + src/testing/test_render.c | 11 +++++++++++ 6 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/rendering/render.c b/src/rendering/render.c index 2f13971..4f0e74e 100644 --- a/src/rendering/render.c +++ b/src/rendering/render.c @@ -584,6 +584,17 @@ void renderPushTriangle(RenderArea* area, Vector3 pixel1, Vector3 pixel2, Vector mutexRelease(area->lock); } +Color renderGetPixel(RenderArea* area, int x, int y) +{ + Color result; + + mutexAcquire(area->lock); + result = _getFinalPixel(area, x, y); + mutexRelease(area->lock); + + return result; +} + void* _renderPostProcessChunk(void* data) { int x, y; diff --git a/src/rendering/render.h b/src/rendering/render.h index 0479951..62184a0 100644 --- a/src/rendering/render.h +++ b/src/rendering/render.h @@ -39,6 +39,8 @@ void renderUpdate(RenderArea* area); void renderPushTriangle(RenderArea* area, Vector3 pixel1, Vector3 pixel2, Vector3 pixel3, Vector3 location1, Vector3 location2, Vector3 location3, f_RenderFragmentCallback callback, void* callback_data); +Color renderGetPixel(RenderArea* area, int x, int y); + void renderPostProcess(RenderArea* area, int nbchunks); int renderSaveToFile(RenderArea* area, const char* path); void renderSetPreviewCallbacks(RenderArea* area, RenderCallbackStart start, RenderCallbackDraw draw, RenderCallbackUpdate update); diff --git a/src/rendering/tools/color.c b/src/rendering/tools/color.c index 102ece7..c0c7db3 100644 --- a/src/rendering/tools/color.c +++ b/src/rendering/tools/color.c @@ -257,15 +257,27 @@ static Color _toneMappingReinhard(Color pixel, double exposure) return pixel; } +static Color _toneMappingClamp(Color pixel, double exposure) +{ + UNUSED(exposure); + + pixel.r = pixel.r > 1.0 ? 1.0 : pixel.r; + pixel.g = pixel.g > 1.0 ? 1.0 : pixel.g; + pixel.b = pixel.b > 1.0 ? 1.0 : pixel.b; + + return pixel; +} + void colorProfileSetToneMapping(ColorProfile* profile, ToneMappingOperator tonemapper, double exposure) { - if (tonemapper == TONE_MAPPING_REIHNARD) + switch (tonemapper) { - profile->mapper = _toneMappingReinhard; - } - else - { - profile->mapper = _toneMappingUncharted; + case TONE_MAPPING_REIHNARD: + profile->mapper = _toneMappingReinhard; + case TONE_MAPPING_UNCHARTED: + profile->mapper = _toneMappingUncharted; + default: + profile->mapper = _toneMappingClamp; } profile->exposure = exposure; } diff --git a/src/rendering/tools/color.h b/src/rendering/tools/color.h index 35ad880..b6185ba 100644 --- a/src/rendering/tools/color.h +++ b/src/rendering/tools/color.h @@ -50,7 +50,8 @@ typedef struct ColorProfile ColorProfile; typedef enum { TONE_MAPPING_UNCHARTED, - TONE_MAPPING_REIHNARD + TONE_MAPPING_REIHNARD, + TONE_MAPPING_CLAMP } ToneMappingOperator; ColorProfile* colorProfileCreate(); diff --git a/src/testing/common.h b/src/testing/common.h index 1992adb..fa4188f 100644 --- a/src/testing/common.h +++ b/src/testing/common.h @@ -87,5 +87,6 @@ static char _ck_gen_strbuf2[101]; /***** Some builtin comparisons *****/ #define ck_assert_double_in_range(_double_, _x_, _y_) ck_assert_double_gte(_double_, _x_);ck_assert_double_lte(_double_, _y_) #define ck_assert_vector_values(_vector_, _x_, _y_, _z_) ck_assert_double_eq(_vector_.x, _x_);ck_assert_double_eq(_vector_.y, _y_);ck_assert_double_eq(_vector_.z, _z_) +#define ck_assert_color_values(_color_, _r_, _g_, _b_, _a_) ck_assert_double_eq(_color_.r, _r_);ck_assert_double_eq(_color_.g, _g_);ck_assert_double_eq(_color_.b, _b_);ck_assert_double_eq(_color_.a, _a_) #endif diff --git a/src/testing/test_render.c b/src/testing/test_render.c index 3a1c05a..4031933 100644 --- a/src/testing/test_render.c +++ b/src/testing/test_render.c @@ -32,11 +32,13 @@ static Color _postProcessFragment(Renderer* renderer, Vector3 location, void* da START_TEST(test_render_quad) { + Color col; Renderer* renderer = rendererCreate(); renderer->render_width = 800; renderer->render_height = 600; renderer->render_quality = 1; + renderSetToneMapping(renderer->render_area, TONE_MAPPING_CLAMP, 0.0); cameraSetLocationCoords(renderer->render_camera, 0.0, 0.5, 2.0); cameraSetTargetCoords(renderer->render_camera, 0.0, 0.5, 0.0); @@ -51,6 +53,15 @@ START_TEST(test_render_quad) renderer->pushQuad(renderer, v3(-1.0, 0.0, 1.0), v3(-1.0, 0.0, -1.0), v3(1.0, 0.0, -1.0), v3(1.0, 0.0, 1.0), _postProcessFragment, NULL); renderPostProcess(renderer->render_area, tests_cpu_count); + col = renderGetPixel(renderer->render_area, 399, 599 - 435); + ck_assert_color_values(col, 1.0, 1.0, 1.0, 1.0); + col = renderGetPixel(renderer->render_area, 399, 599 - 436); + ck_assert_color_values(col, 0.0, 0.0, 0.0, 1.0); + col = renderGetPixel(renderer->render_area, 400, 599 - 435); + ck_assert_color_values(col, 0.0, 0.0, 0.0, 1.0); + col = renderGetPixel(renderer->render_area, 400, 599 - 436); + ck_assert_color_values(col, 1.0, 1.0, 1.0, 1.0); + renderSaveToFile(renderer->render_area, "./output/test_render_quad.png"); rendererDelete(renderer);