summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2007-03-16 18:35:35 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2007-03-16 18:35:35 +0100
commitd09316016e4e0b782d784785641fec91de7d58a6 (patch)
tree3921013b0762e1c564d5e8cdba93154fd677fb9c
parent79dc410663f418ab36acd61fe53aeba8d5942705 (diff)
switch to 16 bit color depth internally
-rw-r--r--src/GipfelWidget.H8
-rw-r--r--src/GipfelWidget.cxx49
-rw-r--r--src/JPEGOutputImage.H2
-rw-r--r--src/JPEGOutputImage.cxx8
-rw-r--r--src/OutputImage.H4
-rw-r--r--src/OutputImage.cxx4
-rw-r--r--src/PreviewOutputImage.H2
-rw-r--r--src/PreviewOutputImage.cxx8
-rw-r--r--src/Stitch.H2
-rw-r--r--src/Stitch.cxx39
-rw-r--r--src/TIFFOutputImage.H2
-rw-r--r--src/TIFFOutputImage.cxx8
12 files changed, 66 insertions, 70 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H
index f5254e7..8cb6d3f 100644
--- a/src/GipfelWidget.H
+++ b/src/GipfelWidget.H
@@ -39,13 +39,13 @@ class GipfelWidget : public Fl_Widget {
int get_rel_track_width(Hill *m);
static int get_pixel_nearest(Fl_Image *img, double x, double y,
- uchar *r, uchar *g, uchar *b);
+ int *r, int *g, int *b);
static int get_pixel_bilinear(Fl_Image *img, double x, double y,
- uchar *r, uchar *g, uchar *b);
+ int *r, int *g, int *b);
static int get_pixel(Fl_Image *img, int x, int y,
- uchar *r, uchar *g, uchar *b);
+ int *r, int *g, int *b);
public:
typedef enum {
@@ -124,7 +124,7 @@ class GipfelWidget : public Fl_Widget {
int comp_params();
int get_pixel(GipfelWidget::sample_mode_t,
- double a_alph, double a_nick, uchar *r, uchar *g, uchar *b);
+ double a_alph, double a_nick, int *r, int *g, int *b);
double get_angle_off(double view, double nick);
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index e88c0cb..1eb8866 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -670,9 +670,9 @@ GipfelWidget::handle(int event) {
int
GipfelWidget::get_pixel(GipfelWidget::sample_mode_t m,
- double a_alph, double a_nick, uchar *r, uchar *g, uchar *b) {
+ double a_alph, double a_nick, int *r, int *g, int *b) {
double px, py;
- uchar r_tmp, g_tmp, b_tmp;
+ int r_tmp, g_tmp, b_tmp;
int ret;
if (img == NULL) {
@@ -691,20 +691,6 @@ GipfelWidget::get_pixel(GipfelWidget::sample_mode_t m,
py + ((double) img->h()) / 2.0, r, g, b);
}
-#if 0
- if (ret == 0) {
-fprintf(stderr, "===> %d\n", ret);
- double angle = atan(pow(pow(tan(a_alph - pan->parms.a_center), 2.0) +
- pow(tan(a_nick - pan->parms.a_nick), 2.0), 0.5));
- double devign = 1.0 / pow(cos(angle), 1.5);
- fprintf(stderr, "===> %lf\n", devign);
-
- *r = (uchar) MIN(rint((double) r_tmp * devign), 255);
- *g = (uchar) MIN(rint((double) g_tmp * devign), 255);
- *b = (uchar) MIN(rint((double) b_tmp * devign), 255);
- }
-#endif
-
return ret;
}
@@ -718,7 +704,7 @@ GipfelWidget::get_angle_off(double a_alph, double a_nick) {
int
GipfelWidget::get_pixel_nearest(Fl_Image *img, double x, double y,
- uchar *r, uchar *g, uchar *b) {
+ int *r, int *g, int *b) {
if (isnan(x) || isnan(y)) {
return 1;
} else {
@@ -728,10 +714,10 @@ GipfelWidget::get_pixel_nearest(Fl_Image *img, double x, double y,
int
GipfelWidget::get_pixel_bilinear(Fl_Image *img, double x, double y,
- uchar *r, uchar *g, uchar *b) {
- uchar a_r[4] = {0, 0, 0, 0};
- uchar a_g[4] = {0, 0, 0, 0};
- uchar a_b[4] = {0, 0, 0, 0};
+ int *r, int *g, int *b) {
+ int a_r[4] = {0, 0, 0, 0};
+ int a_g[4] = {0, 0, 0, 0};
+ int a_b[4] = {0, 0, 0, 0};
float v0 , v1;
int fl_x = (int) floor(x);
int fl_y = (int) floor(y);
@@ -748,15 +734,15 @@ GipfelWidget::get_pixel_bilinear(Fl_Image *img, double x, double y,
v0 = a_r[0] * (1 - (x - fl_x)) + a_r[1] * (x - fl_x);
v1 = a_r[2] * (1 - (x - fl_x)) + a_r[3] * (x - fl_x);
- *r = (uchar) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y));
+ *r = (int) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y));
v0 = a_g[0] * (1 - (x - fl_x)) + a_g[1] * (x - fl_x);
v1 = a_g[2] * (1 - (x - fl_x)) + a_g[3] * (x - fl_x);
- *g = (uchar) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y));
+ *g = (int) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y));
v0 = a_b[0] * (1 - (x - fl_x)) + a_b[1] * (x - fl_x);
v1 = a_b[2] * (1 - (x - fl_x)) + a_b[3] * (x - fl_x);
- *b = (uchar) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y));
+ *b = (int) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y));
if (n >= 1) {
return 1;
@@ -767,7 +753,7 @@ GipfelWidget::get_pixel_bilinear(Fl_Image *img, double x, double y,
int
GipfelWidget::get_pixel(Fl_Image *img, int x, int y,
- uchar *r, uchar *g, uchar *b) {
+ int *r, int *g, int *b) {
if ( img->d() == 0 ) {
return 1;
}
@@ -779,16 +765,16 @@ GipfelWidget::get_pixel(Fl_Image *img, int x, int y,
switch (img->count()) {
case 1:
{ // bitmap
- const char *buf = img->data()[0];
+ const unsigned char *buf = (const unsigned char*) img->data()[0];
switch (img->d())
{
case 1:
*r = *g = *b = *(buf+index);
break;
case 3: // 24bit
- *r = *(buf+index+0);
- *g = *(buf+index+1);
- *b = *(buf+index+2);
+ *r = (int) *(buf+index+0);
+ *g = (int) *(buf+index+1);
+ *b = (int) *(buf+index+2);
break;
default: // ??
printf("Not supported: chans=%d\n", img->d());
@@ -801,8 +787,11 @@ GipfelWidget::get_pixel(Fl_Image *img, int x, int y,
return 1;
}
- return 0;
+ *r = *r * 255;
+ *g = *g * 255;
+ *b = *b * 255;
+ return 0;
}
int
diff --git a/src/JPEGOutputImage.H b/src/JPEGOutputImage.H
index b3554c8..a4b8f47 100644
--- a/src/JPEGOutputImage.H
+++ b/src/JPEGOutputImage.H
@@ -32,7 +32,7 @@ class JPEGOutputImage : OutputImage {
protected:
int init_internal(int w, int h);
- int set_pixel_internal(int x, char r, char g, char b);
+ int set_pixel_internal(int x, int r, int g, int b);
int next_line_internal();
diff --git a/src/JPEGOutputImage.cxx b/src/JPEGOutputImage.cxx
index 6e685d0..bfe4595 100644
--- a/src/JPEGOutputImage.cxx
+++ b/src/JPEGOutputImage.cxx
@@ -68,10 +68,10 @@ JPEGOutputImage::init_internal(int w1, int h1) {
}
int
-JPEGOutputImage::set_pixel_internal(int x, char r, char g, char b) {
- row[x*3+0] = r;
- row[x*3+1] = g;
- row[x*3+2] = b;
+JPEGOutputImage::set_pixel_internal(int x, int r, int g, int b) {
+ row[x*3+0] = (unsigned char) r;
+ row[x*3+1] = (unsigned char) g;
+ row[x*3+2] = (unsigned char) b;
return 0;
}
diff --git a/src/OutputImage.H b/src/OutputImage.H
index 7c9f0fd..17955b9 100644
--- a/src/OutputImage.H
+++ b/src/OutputImage.H
@@ -19,7 +19,7 @@ class OutputImage {
virtual int init(int w1, int h1);
- int set_pixel(int x, char r, char g, char b);
+ int set_pixel(int x, int r, int g, int b);
int next_line();
@@ -30,7 +30,7 @@ class OutputImage {
virtual int init_internal(int w1, int h1);
- virtual int set_pixel_internal(int x, char r, char g, char b);
+ virtual int set_pixel_internal(int x, int r, int g, int b);
virtual int next_line_internal();
diff --git a/src/OutputImage.cxx b/src/OutputImage.cxx
index ddf8e14..f981f18 100644
--- a/src/OutputImage.cxx
+++ b/src/OutputImage.cxx
@@ -35,7 +35,7 @@ OutputImage::init_internal(int w1, int h1) {
}
int
-OutputImage::set_pixel(int x, char r, char g, char b) {
+OutputImage::set_pixel(int x, int r, int g, int b) {
if (!initialized || x < 0 || x >= W) {
return 1;
} else {
@@ -44,7 +44,7 @@ OutputImage::set_pixel(int x, char r, char g, char b) {
}
int
-OutputImage::set_pixel_internal(int x, char r, char g, char b) {
+OutputImage::set_pixel_internal(int x, int r, int g, int b) {
return 0;
}
diff --git a/src/PreviewOutputImage.H b/src/PreviewOutputImage.H
index 8b41684..cbd55a6 100644
--- a/src/PreviewOutputImage.H
+++ b/src/PreviewOutputImage.H
@@ -29,7 +29,7 @@ class PreviewOutputImage : OutputImage , public Fl_Widget {
protected:
int init_internal(int w, int h);
- int set_pixel_internal(int x, char r, char g, char b);
+ int set_pixel_internal(int x, int r, int g, int b);
int next_line_internal();
diff --git a/src/PreviewOutputImage.cxx b/src/PreviewOutputImage.cxx
index 86dadee..0ae182e 100644
--- a/src/PreviewOutputImage.cxx
+++ b/src/PreviewOutputImage.cxx
@@ -35,15 +35,15 @@ PreviewOutputImage::init_internal(int w, int h) {
int
-PreviewOutputImage::set_pixel_internal(int x, char r, char g, char b) {
+PreviewOutputImage::set_pixel_internal(int x, int r, int g, int b) {
if (!data) {
return 1;
}
long index = (line * w() * d + (x * d));
- *(data+index+0) = r;
- *(data+index+1) = g;
- *(data+index+2) = b;
+ *(data+index+0) = (unsigned char) (r / 255);
+ *(data+index+1) = (unsigned char) (g / 255);
+ *(data+index+2) = (unsigned char) (b / 255);
return 0;
}
diff --git a/src/Stitch.H b/src/Stitch.H
index 9fe3c15..b5fb6fd 100644
--- a/src/Stitch.H
+++ b/src/Stitch.H
@@ -23,7 +23,7 @@ class Stitch {
OutputImage *single_images[MAX_PICS];
OutputImage *merged_image;
- uchar color_correct(uchar c, double a, int pic, int color);
+ int color_correct(int c, double a, int pic, int color);
public:
Stitch();
diff --git a/src/Stitch.cxx b/src/Stitch.cxx
index 3876e77..af0df91 100644
--- a/src/Stitch.cxx
+++ b/src/Stitch.cxx
@@ -17,7 +17,7 @@
#include "Stitch.H"
#define MIN(A,B) ((A)<(B)?(A):(B))
-
+#define MAX_VALUE 65025
static double pi_d = asin(1.0) * 2.0;
static double deg2rad = pi_d / 180.0;
@@ -99,12 +99,12 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m,
view_end = view_end * deg2rad;
double step_view = (view_end - view_start) / w;
- uchar r, g, b;
+ int r, g, b;
int y_off = h / 2;
int merged_pixel_set;
double radius = (double) w / (view_end -view_start);
- int max_samples = 5000 * 3, n_samples = 0;
+ int max_samples = 50000 * 3, n_samples = 0;
int ret;
int n_vars = 2 + num_pics * 3 ;
gsl_matrix *X, *cov;
@@ -129,7 +129,7 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m,
a_view = view_start + x * step_view;
merged_pixel_set = 0;
double a1, a2;
- uchar c1[3], c2[3];
+ int c1[3], c2[3];
double c1d[3], c2d[3];
for (int p1=0; p1<num_pics; p1++) {
@@ -137,7 +137,6 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m,
break;
} else if (gipf[p1]->get_pixel(m, a_view, a_nick,
&c1[0], &c1[1], &c1[2]) == 0) {
-
for (int l = 0; l<3; l++) {
c1d[l] = (double) c1[l];
}
@@ -159,12 +158,20 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m,
a2 = gipf[p2]->get_angle_off(a_view, a_nick);
if (n_samples < max_samples &&
- c1[0] < 200 && c1[1] < 200 && c1[2] < 200 &&
- c2[0] < 200 && c2[1] < 200 && c2[2] < 200 &&
- c1[0] > 20 && c1[1] > 20 && c1[2] > 20 &&
- c2[0] > 20 && c2[1] > 20 && c2[2] > 20 &&
- fabs(c1d[1] / c1d[0] - c2d[1] / c2d[0]) < 0.02 &&
- fabs(c1d[2] / c1d[0] - c2d[2] / c2d[0]) < 0.02 ) {
+ c1[0] < MAX_VALUE * 0.8 &&
+ c1[1] < MAX_VALUE * 0.8 &&
+ c1[2] < MAX_VALUE * 0.8 &&
+ c2[0] < MAX_VALUE * 0.8 &&
+ c2[1] < MAX_VALUE * 0.8 &&
+ c2[2] < MAX_VALUE * 0.8 &&
+ c1[0] > MAX_VALUE * 0.2 &&
+ c1[1] > MAX_VALUE * 0.2 &&
+ c1[2] > MAX_VALUE * 0.2 &&
+ c2[0] > MAX_VALUE * 0.2 &&
+ c2[1] > MAX_VALUE * 0.2 &&
+ c2[2] > MAX_VALUE * 0.2) {
+// fabs(c1d[1] / c1d[0] - c2d[1] / c2d[0]) < 0.2 &&
+// fabs(c1d[2] / c1d[0] - c2d[2] / c2d[0]) < 0.2 ) {
for (int l = 0; l<3; l++) {
if (p1 == 0) {
@@ -186,7 +193,7 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m,
}
if (merged_image) {
- merged_image->set_pixel(x, 255, 0, 0);
+ merged_image->set_pixel(x, 65025, 0, 0);
merged_pixel_set++;
}
}
@@ -233,15 +240,15 @@ fprintf(stderr, "==> V1 %f V2 %f\n", V1, V2);
return 0;
}
-uchar
-Stitch::color_correct(uchar c, double a, int pic, int color) {
+int
+Stitch::color_correct(int c, double a, int pic, int color) {
double cd = (double) c;
cd = cd * (color_adjust[pic][color] +
V1 * a * a +
V2 * a * a * a * a);
- return (uchar) MIN(rint(cd), 255.0);
+ return (int) MIN(rint(cd), 65025.0);
}
int
@@ -252,7 +259,7 @@ Stitch::resample(GipfelWidget::sample_mode_t m,
view_end = view_end * deg2rad;
double step_view = (view_end - view_start) / w;
- uchar r, g, b;
+ int r, g, b;
int y_off = h / 2;
int merged_pixel_set;
double radius = (double) w / (view_end -view_start);
diff --git a/src/TIFFOutputImage.H b/src/TIFFOutputImage.H
index 820a281..ce61462 100644
--- a/src/TIFFOutputImage.H
+++ b/src/TIFFOutputImage.H
@@ -26,7 +26,7 @@ class TIFFOutputImage : OutputImage {
protected:
int init_internal(int w, int h);
- int set_pixel_internal(int x, char r, char g, char b);
+ int set_pixel_internal(int x, int r, int g, int b);
int next_line_internal();
diff --git a/src/TIFFOutputImage.cxx b/src/TIFFOutputImage.cxx
index 397caac..4034c97 100644
--- a/src/TIFFOutputImage.cxx
+++ b/src/TIFFOutputImage.cxx
@@ -61,10 +61,10 @@ TIFFOutputImage::init_internal(int w1, int h1) {
}
int
-TIFFOutputImage::set_pixel_internal(int x, char r, char g, char b) {
- row[x*4+0] = r;
- row[x*4+1] = g;
- row[x*4+2] = b;
+TIFFOutputImage::set_pixel_internal(int x, int r, int g, int b) {
+ row[x*4+0] = (unsigned char) r;
+ row[x*4+1] = (unsigned char) g;
+ row[x*4+2] = (unsigned char) b;
row[x*4+3] = 255;
return 0;