diff options
author | taw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-08-28 16:07:32 +0000 |
---|---|---|
committer | taw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-08-28 16:07:32 +0000 |
commit | 85b8978beedd0142560573a92442a5ed907b0ed2 (patch) | |
tree | a5fb149aa94b540a568ac6c7b2831a8065e53959 /src/imagedisplay.c | |
parent | 49ad910255546917c22a1d0ef01b4109c7772b16 (diff) |
Be a lot more clear about which things are properties of images and which
belong to the control context.
git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@81 bf6ca9ba-c028-0410-8290-897cf20841d1
Diffstat (limited to 'src/imagedisplay.c')
-rw-r--r-- | src/imagedisplay.c | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/src/imagedisplay.c b/src/imagedisplay.c index 9c7aee5..3a87aa5 100644 --- a/src/imagedisplay.c +++ b/src/imagedisplay.c @@ -76,29 +76,34 @@ static void imagedisplay_put_data(ImageDisplay *imagedisplay, int16_t *image16) unsigned int x, y; unsigned int w, h; + int16_t min, max; h = imagedisplay->height; w = imagedisplay->width; - + + min = 0; max = 0; + for ( y=0; y<h; y++ ) { + for ( x=0; x<w; x++ ) { + int16_t val; + val = image16[x+w*y]; + if ( val > max ) max = val; + if ( val < min ) min = val; + } + } + /* Turn 16-bit image data into 8-bit display data */ imagedisplay->data = malloc(3*w*h); for ( y=0; y<h; y++ ) { for ( x=0; x<w; x++ ) { - int16_t val16 = image16[x+w*y]; - if ( val16 > 255 ) { - imagedisplay->data[3*( x+w*(h-1-y) )] = 255; - imagedisplay->data[3*( x+w*(h-1-y) )+1] = 255; - imagedisplay->data[3*( x+w*(h-1-y) )+2] = 255; - } else if ( val16 < 0 ) { - imagedisplay->data[3*( x+w*(h-1-y) )] = 0; - imagedisplay->data[3*( x+w*(h-1-y) )+1] = 0; - imagedisplay->data[3*( x+w*(h-1-y) )+2] = 0; - } else { - imagedisplay->data[3*( x+w*(h-1-y) )] = val16; - imagedisplay->data[3*( x+w*(h-1-y) )+1] = val16; - imagedisplay->data[3*( x+w*(h-1-y) )+2] = val16; - } + int16_t val16, val8; + + val16 = image16[x+w*y]; + val8 = (255*(val16-min)) / (max-min); + + imagedisplay->data[3*( x+w*(h-1-y) )] = val8; + imagedisplay->data[3*( x+w*(h-1-y) )+1] = val8; + imagedisplay->data[3*( x+w*(h-1-y) )+2] = val8; } } @@ -149,7 +154,7 @@ ImageDisplay *imagedisplay_open(int16_t *image, unsigned int width, unsigned int } -void imagedisplay_add_tilt_axis(ImageDisplay *imagedisplay, ControlContext *ctx, double omega) { +void imagedisplay_add_tilt_axis(ImageDisplay *imagedisplay, double xc, double yc, double omega) { guchar *image_eightbit; int w, h; @@ -170,7 +175,7 @@ void imagedisplay_add_tilt_axis(ImageDisplay *imagedisplay, ControlContext *ctx, gradient = 1/gradient; /* Start at the centre and draw a line out in each direction until it hits an edge. This makes the whole thing a lot easier. */ - xs = ctx->x_centre; y = ctx->y_centre; + xs = xc; y = yc; do { x = xs; image_eightbit[3*(x+w*(h-1-y))+0] = 255; @@ -179,7 +184,7 @@ void imagedisplay_add_tilt_axis(ImageDisplay *imagedisplay, ControlContext *ctx, y++; xs += gradient; } while ( (xs<w) && (y<h) && (xs>=0) && (y>=0) ); - xs = ctx->x_centre; y = ctx->y_centre; + xs = xc; y = yc; do { x = xs; image_eightbit[3*(x+w*(h-1-y))+0] = 255; @@ -191,7 +196,7 @@ void imagedisplay_add_tilt_axis(ImageDisplay *imagedisplay, ControlContext *ctx, } else { double ys; signed int x, y; - x = ctx->x_centre; ys = ctx->y_centre; + x = xc; ys = yc; do { y = ys; image_eightbit[3*(x+w*(h-1-y))+0] = 255; @@ -201,7 +206,7 @@ void imagedisplay_add_tilt_axis(ImageDisplay *imagedisplay, ControlContext *ctx, ys += gradient; } while ( (x<w) && (ys<h) && (x>=0) && (ys>=0) ); - x = ctx->x_centre; ys = ctx->y_centre; + x = xc; ys = yc; do { y = ys; image_eightbit[3*(x+w*(h-1-y))+0] = 255; |