From c77d160603298560b89243dda34fd81ee52d3d10 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 18 Nov 2009 15:13:09 +0100 Subject: Bloom simulation --- src/detector.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 91 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/detector.c b/src/detector.c index 13d5a20b..9de99e6c 100644 --- a/src/detector.c +++ b/src/detector.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "image.h" #include "utils.h" @@ -23,28 +24,106 @@ /* Detector's quantum efficiency */ -#define DQE (0.8) +#define DQE (0.9) -static uint16_t *bloom(double *hdr, int width, int height) +/* Detector's saturation value */ +#define SATURATION (60000) + + +/* Bleed excess intensity into neighbouring pixels */ +static void bloom_values(double *tmp, int x, int y, + int width, int height, double val) +{ + double overflow; + + overflow = val - SATURATION; + + /* Intensity which bleeds off the edge of the detector is lost */ + if ( x > 0 ) { + tmp[x-1 + width*y] += overflow / 6.0; + if ( y > 0 ) { + tmp[x-1 + width*(y-1)] += overflow / 12.0; + } + if ( y < height-1 ) { + tmp[x-1 + width*(y+1)] += overflow / 12.0; + } + } + + if ( x < width-1 ) { + tmp[x+1 + width*y] += overflow / 6.0; + if ( y > 0 ) { + tmp[x+1 + width*(y-1)] += overflow / 12.0; + } + if ( y < height-1 ) { + tmp[x+1 + width*(y+1)] += overflow / 12.0; + } + } + + if ( y > 0 ) { + tmp[x + width*(y-1)] += overflow / 6.0; + } + if ( y < height-1 ) { + tmp[x + width*(y+1)] += overflow / 6.0; + } +} + + +static uint16_t *bloom(double *hdr_in, int width, int height) { int x, y; uint16_t *data; - + double *tmp; + double *hdr; + int did_something; + data = malloc(width * height * sizeof(uint16_t)); - + tmp = malloc(width * height * sizeof(double)); + hdr = malloc(width * height * sizeof(double)); + + memcpy(hdr, hdr_in, width*height*sizeof(double)); + do { + + memset(tmp, 0, width*height*sizeof(double)); + did_something = 0; + + for ( x=0; x