Update of /cvsroot/ufraw/ufraw
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv23262
Modified Files:
configure.ac ufraw.h ufraw_conf.c ufraw_preview.c
ufraw_ufraw.c ufraw_ui.h
Log Message:
Add support for hot pixel elimination. It is enabled by the configuration
switch --enable-hotpixels. Based on patch by Frank van Maarseveen.
Index: ufraw_preview.c
===================================================================
RCS file: /cvsroot/ufraw/ufraw/ufraw_preview.c,v
retrieving revision 1.274
retrieving revision 1.275
diff -u -d -r1.274 -r1.275
--- ufraw_preview.c 27 Sep 2009 22:39:39 -0000 1.274
+++ ufraw_preview.c 29 Sep 2009 16:45:36 -0000 1.275
@@ -1418,6 +1418,9 @@
gtk_adjustment_set_value(data->GreenAdjustment, CFG->green);
gtk_adjustment_set_value(data->ExposureAdjustment, CFG->exposure);
gtk_adjustment_set_value(data->ThresholdAdjustment, CFG->threshold);
+#ifdef UFRAW_HOTPIXELS
+ gtk_adjustment_set_value(data->HotpixelAdjustment, CFG->hotpixel);
+#endif
#ifdef UFRAW_CONTRAST
gtk_adjustment_set_value(data->ContrastAdjustment, CFG->contrast);
#endif
@@ -1456,6 +1459,10 @@
fabs( conf_default.exposure - CFG->exposure) > 0.001);
gtk_widget_set_sensitive(data->ResetThresholdButton,
fabs( conf_default.threshold - CFG->threshold) > 1);
+#ifdef UFRAW_HOTPIXELS
+ gtk_widget_set_sensitive(data->ResetHotpixelButton,
+ fabs( conf_default.hotpixel - CFG->hotpixel) > 0);
+#endif
#ifdef UFRAW_CONTRAST
gtk_widget_set_sensitive(data->ResetContrastButton,
fabs( conf_default.contrast - CFG->contrast) > 0.001);
@@ -1864,6 +1871,9 @@
static void create_base_image(preview_data *data)
{
+#ifdef UFRAW_HOTPIXELS
+ gchar buf[20];
+#endif
int shrinkSave = CFG->shrink;
int sizeSave = CFG->size;
if (CFG->Scale==0) {
@@ -1884,6 +1894,10 @@
data->UF->conf->rotationAngle);
CFG->shrink = shrinkSave;
CFG->size = sizeSave;
+#ifdef UFRAW_HOTPIXELS
+ g_snprintf(buf, sizeof (buf), "%d", data->UF->hotpixels);
+ gtk_label_set_text(data->HotpixelCount, buf);
+#endif
}
static void update_shrink_ranges(preview_data *data)
@@ -2601,6 +2615,12 @@
CFG->threshold = conf_default.threshold;
preview_invalidate_layer(data, ufraw_denoise_phase);
}
+#ifdef UFRAW_HOTPIXELS
+ if (button==data->ResetHotpixelButton) {
+ CFG->hotpixel = conf_default.hotpixel;
+ preview_invalidate_layer(data, ufraw_first_phase);
+ }
+#endif
#ifdef UFRAW_CONTRAST
if (button==data->ResetContrastButton) {
CFG->contrast = conf_default.contrast;
@@ -2756,6 +2776,13 @@
if (!Developer->doWB) // !doWB means do interpolate
preview_invalidate_layer(data, ufraw_first_phase);
render_preview(data);
+#ifdef UFRAW_HOTPIXELS
+ } else if ( valuep==&data->UF->mark_hotpixels ) {
+ if (data->UF->hotpixels) {
+ preview_invalidate_layer(data, ufraw_first_phase);
+ render_preview(data);
+ }
+#endif
}
}
}
@@ -2835,6 +2862,10 @@
preview_invalidate_layer(data, ufraw_first_phase);
} else if (valuep==&CFG->threshold) {
preview_invalidate_layer(data, ufraw_denoise_phase);
+#ifdef UFRAW_HOTPIXELS
+ } else if (valuep==&CFG->hotpixel) {
+ preview_invalidate_layer(data, ufraw_first_phase);
+#endif
} else {
if (CFG->autoExposure==enabled_state) CFG->autoExposure = apply_state;
if (CFG->autoBlack==enabled_state) CFG->autoBlack = apply_state;
@@ -3871,6 +3902,51 @@
gtk_widget_show_all(menu);
}
+#ifdef UFRAW_HOTPIXELS
+static void hotpixel_fill_interface(preview_data *data, GtkWidget *page)
+{
+ GtkWidget *button;
+ GtkWidget *label;
+ GtkBox *box;
+ GtkWidget *frame;
+
+ frame = gtk_frame_new(NULL);
+ gtk_box_pack_start(GTK_BOX(page), frame, FALSE, FALSE, 0);
+ box = GTK_BOX(gtk_hbox_new(FALSE, 0));
+ gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(box));
+ label = gtk_label_new(_("Hot pixels: "));
+ gtk_box_pack_start(box, label, FALSE, FALSE, 0);
+
+ data->HotpixelCount = GTK_LABEL(gtk_label_new(NULL));
+ gtk_box_pack_start(box, GTK_WIDGET(data->HotpixelCount), FALSE, FALSE, 0);
+ button = gtk_check_button_new_with_label("mark");
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),
+ data->UF->mark_hotpixels);
+ g_signal_connect(G_OBJECT(button), "toggled",
+ G_CALLBACK(toggle_button_update), &data->UF->mark_hotpixels);
+ gtk_box_pack_start(box, button, FALSE, FALSE, 3);
+ gtk_box_pack_start(box, gtk_label_new(NULL), TRUE, TRUE, 0);
+
+ data->HotpixelAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(
+ CFG->hotpixel, 0.0, 999.99, 0.1, 0.5, 0));
+ g_object_set_data(G_OBJECT(data->HotpixelAdjustment),
+ "Adjustment-Accuracy", (gpointer)3);
+ button = gtk_spin_button_new(data->HotpixelAdjustment, 0.001, 3);
+ g_object_set_data(G_OBJECT(data->HotpixelAdjustment),
+ "Parent-Widget", button);
+ g_signal_connect(G_OBJECT(data->HotpixelAdjustment), "value-changed",
+ G_CALLBACK(adjustment_update), &CFG->hotpixel);
+ uf_widget_set_tooltip(button, _("Hot pixel sensitivity"));
+ gtk_box_pack_start(box, button, FALSE, FALSE, 0);
+
+ button = reset_button(
+ _("Reset hot pixel sensitivity"), G_CALLBACK(button_update), NULL);
+ gtk_box_pack_end(box, button, FALSE, FALSE, 0);
+ gtk_widget_set_sensitive(button, FALSE);
+ data->ResetHotpixelButton = button;
+}
+#endif
+
static void livehistogram_fill_interface(preview_data *data,
GtkTable *table)
{
@@ -4203,6 +4279,11 @@
&data->ResetThresholdButton,
_("Reset denoise threshold to default"), G_CALLBACK(button_update));
+#ifdef UFRAW_HOTPIXELS
+ /* Hot pixel shaving */
+ hotpixel_fill_interface(data, page);
+#endif
+
// Dark frame controls:
box = GTK_BOX(gtk_hbox_new(FALSE, 0));
frame = gtk_frame_new(NULL);
Index: ufraw.h
===================================================================
RCS file: /cvsroot/ufraw/ufraw/ufraw.h,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -d -r1.121 -r1.122
--- ufraw.h 29 Sep 2009 01:03:11 -0000 1.121
+++ ufraw.h 29 Sep 2009 16:45:36 -0000 1.122
@@ -166,6 +166,9 @@
double temperature, green;
double chanMul[4];
double threshold;
+#ifdef UFRAW_HOTPIXELS
+ double hotpixel;
+#endif
#ifdef UFRAW_CONTRAST
double contrast;
#endif
@@ -283,6 +286,10 @@
int postproc_ops; /* postprocessing operations (LF_MODIFY_XXX) */
lfModifier *modifier;
#endif /* HAVE_LENSFUN */
+#ifdef UFRAW_HOTPIXELS
+ int hotpixels;
+ gboolean mark_hotpixels;
+#endif
} ufraw_data;
extern const conf_data conf_default;
Index: configure.ac
===================================================================
RCS file: /cvsroot/ufraw/ufraw/configure.ac,v
retrieving revision 1.139
retrieving revision 1.140
diff -u -d -r1.139 -r1.140
--- configure.ac 1 Sep 2009 19:13:25 -0000 1.139
+++ configure.ac 29 Sep 2009 16:45:35 -0000 1.140
@@ -375,6 +375,13 @@
enable_contrast=no)
AC_MSG_RESULT($enable_contrast)
+AC_MSG_CHECKING(whether to enable hot pixel elimination)
+AC_ARG_ENABLE(hotpixels,
+ [ --enable-hotpixels enable hot pixel elimination],
+ AC_DEFINE(UFRAW_HOTPIXELS, 1, Hot pixel elimination enabled),
+ enable_hotpixels=no)
+AC_MSG_RESULT($enable_hotpixels)
+
AC_MSG_CHECKING(whether to enable 'None' interpolation)
AC_ARG_ENABLE(interp_none,
[ --enable-interp-none enable 'None' interpolation (mostly for
debugging)],
Index: ufraw_conf.c
===================================================================
RCS file: /cvsroot/ufraw/ufraw/ufraw_conf.c,v
retrieving revision 1.145
retrieving revision 1.146
diff -u -d -r1.145 -r1.146
--- ufraw_conf.c 28 Sep 2009 22:42:44 -0000 1.145
+++ ufraw_conf.c 29 Sep 2009 16:45:36 -0000 1.146
@@ -36,6 +36,9 @@
6500, 1.0, /* temperature, green */
{ -1.0, -1.0, -1.0, -1.0 }, /* chanMul[] */
0.0, /* wavelet denoising threshold */
+#ifdef UFRAW_HOTPIXELS
+ 0.0, /* hotpixel sensitivity */
+#endif
#ifdef UFRAW_CONTRAST
1.0, /* global contrast */
#endif
@@ -624,6 +627,10 @@
}
if (!strcmp("WaveletDenoisingThreshold", element))
sscanf(temp, "%lf", &c->threshold);
+#ifdef UFRAW_HOTPIXELS
+ if (!strcmp("HotpixelSensitivity", element))
+ sscanf(temp, "%lf", &c->hotpixel);
+#endif
#ifdef UFRAW_CONTRAST
if (!strcmp("Contrast", element))
sscanf(temp, "%lf", &c->contrast);
@@ -938,6 +945,12 @@
buf = uf_markup_buf(buf,
"<WaveletDenoisingThreshold>%d</WaveletDenoisingThreshold>\n",
(int)floor(c->threshold));
+#ifdef UFRAW_HOTPIXELS
+ if (c->hotpixel!=conf_default.hotpixel)
+ buf = uf_markup_buf(buf,
+ "<HotpixelSensitivity>%f</HotpixelSensitivity>\n",
+ c->hotpixel);
+#endif
#ifdef UFRAW_CONTRAST
if (c->contrast!=conf_default.contrast)
buf = uf_markup_buf(buf,
@@ -1209,6 +1222,9 @@
g_strlcpy(dst->model, src->model, max_name);
dst->threshold = src->threshold;
dst->exposure = src->exposure;
+#ifdef UFRAW_HOTPIXELS
+ dst->hotpixel = src->hotpixel;
+#endif
#ifdef UFRAW_CONTRAST
dst->contrast = src->contrast;
#endif
@@ -1385,6 +1401,9 @@
conf->autoExposure = cmd->autoExposure;
}
if (cmd->threshold!=NULLF) conf->threshold = cmd->threshold;
+#ifdef UFRAW_HOTPIXELS
+ if (cmd->hotpixel!=NULLF) conf->hotpixel = cmd->hotpixel;
+#endif
#ifdef UFRAW_CONTRAST
if (cmd->contrast!=NULLF) conf->contrast = cmd->contrast;
#endif
@@ -1515,6 +1534,10 @@
N_("--saturation=SAT Saturation adjustment (default 1.0, 0 for B&W
output).\n"),
N_("--wavelet-denoising-threshold=THRESHOLD\n"
" Wavelet denoising threshold (default 0.0).\n"),
+#ifdef UFRAW_HOTPIXELS
+N_("--hotpixel-sensitivity=VALUE\n"
+" Sensitivity for detecting and shaving hot pixels
(default 0.0).\n"),
+#endif
N_("--exposure=auto|EXPOSURE\n"
" Auto exposure or exposure correction in EV (default
0).\n"),
N_("--black-point=auto|BLACK\n"
@@ -1628,6 +1651,9 @@
{ "gamma", 1, 0, 'G'},
{ "linearity", 1, 0, 'L'},
{ "saturation", 1, 0, 's'},
+#ifdef UFRAW_HOTPIXELS
+ { "hotpixel-sensitivity", 1, 0, 'H'},
+#endif
#ifdef UFRAW_CONTRAST
{ "contrast", 1, 0, 'y'},
#endif
@@ -1672,6 +1698,9 @@
&baseCurveName, &baseCurveFile, &curveName, &curveFile,
&cmd->profile[0][0].gamma, &cmd->profile[0][0].linear,
&cmd->saturation,
+#ifdef UFRAW_HOTPIXELS
+ &cmd->hotpixel,
+#endif
#ifdef UFRAW_CONTRAST
&cmd->contrast,
#endif
@@ -1693,6 +1722,9 @@
cmd->silent=FALSE;
cmd->profile[0][0].gamma=NULLF;
cmd->profile[0][0].linear=NULLF;
+#ifdef UFRAW_HOTPIXELS
+ cmd->hotpixel=NULLF;
+#endif
#ifdef UFRAW_CONTRAST
cmd->contrast=NULLF;
#endif
@@ -1732,7 +1764,12 @@
case 'G':
case 'L':
case 's':
+#ifdef UFRAW_HOTPIXELS
+ case 'H':
+#endif
+#ifdef UFRAW_CONTRAST
case 'y':
+#endif
case 'n':
if (sscanf(optarg, "%lf", (double *)optPointer[index])==0) {
ufraw_message(UFRAW_ERROR,
Index: ufraw_ufraw.c
===================================================================
RCS file: /cvsroot/ufraw/ufraw/ufraw_ufraw.c,v
retrieving revision 1.189
retrieving revision 1.190
diff -u -d -r1.189 -r1.190
--- ufraw_ufraw.c 29 Sep 2009 03:52:13 -0000 1.189
+++ ufraw_ufraw.c 29 Sep 2009 16:45:36 -0000 1.190
@@ -734,6 +734,9 @@
int ufraw_convert_image(ufraw_data *uf)
{
+#ifdef UFRAW_HOTPIXELS
+ uf->mark_hotpixels = FALSE;
+#endif
ufraw_developer_prepare(uf, file_developer);
ufraw_convert_image_init(uf);
ufraw_convert_image_first_phase(uf, TRUE);
@@ -925,12 +928,78 @@
#endif /* HAVE_LENSFUN */
+#ifdef UFRAW_HOTPIXELS
+/*
+ * A pixel with a significantly larger value than all of its four direct
+ * neighbours is considered "hot". It will be replaced by the maximum value
+ * of its neighbours. For simplicity border pixels are not considered.
+ *
+ * Reasonable values for uf->conf->hotpixel are in the range 0.5-10.
+ */
+static void ufraw_shave_hotpixels(ufraw_data *uf, dcraw_image_type *img,
+ int width, int height, int colors, unsigned rgbMax)
+{
+ int w, h, c, i;
+ unsigned delta, t, v, hi;
+ dcraw_image_type *p;
+
+ uf->hotpixels = 0;
+ if (uf->conf->hotpixel <= 0.0)
+ return;
+ delta = rgbMax / (uf->conf->hotpixel + 1.0);
+ for (h = 1; h < height - 1; ++h) {
+ p = img + 1 + h * width;
+ for (w = 1; w < width - 1; ++w, ++p) {
+ for (c = 0; c < colors; ++c) {
+ t = p[0][c];
+ if (t <= delta)
+ continue;
+ t -= delta;
+ v = p[-1][c];
+ if (v > t)
+ continue;
+ hi = v;
+ v = p[1][c];
+ if (v > t)
+ continue;
+ if (v > hi)
+ hi = v;
+ v = p[-w][c];
+ if (v > t)
+ continue;
+ if (v > hi)
+ hi = v;
+ v = p[w][c];
+ if (v > t)
+ continue;
+ if (v > hi)
+ hi = v;
+#if 0
+ if (uf->hotpixels < 100)
+ printf("%u %u %u: %u->%u\t\n", w, h, c, p[0][c], hi);
+#endif
+ /* mark the pixel using the original hot value */
+ if (uf->mark_hotpixels) {
+ for (i = -10; i >= -20 && w + i >= 0; --i)
+ memcpy(p[i], p[0], sizeof (p[i]));
+ for (i = 10; i <= 20 && w + i < width; ++i)
+ memcpy(p[i], p[0], sizeof (p[i]));
+ }
+ p[0][c] = hi;
+ ++uf->hotpixels;
+ }
+ }
+ }
+}
+#endif
+
/* This is the part of the conversion which is not supported by
* ufraw_convert_image_area() */
int ufraw_convert_image_first_phase(ufraw_data *uf, gboolean lensfix)
{
ufraw_image_data *FirstImage = &uf->Images[ufraw_first_phase];
dcraw_data *raw = uf->raw;
+ dcraw_image_type *rawimage;
// final->image memory will be realloc'd as needed
dcraw_image_data final;
final.image = (image_type *)FirstImage->buffer;
@@ -938,27 +1007,25 @@
final.height = FirstImage->height;
dcraw_data *dark = uf->conf->darkframe ? uf->conf->darkframe->raw : NULL;
+ rawimage = raw->raw.image;
+ raw->raw.image = g_memdup(rawimage, raw->raw.height * raw->raw.width *
+ sizeof (dcraw_image_type));
+#ifdef UFRAW_HOTPIXELS
+ ufraw_shave_hotpixels(uf, raw->raw.image, raw->raw.width, raw->raw.height,
+ raw->raw.colors, raw->rgbMax);
+#endif
if ( uf->ConvertShrink>1 || !uf->HaveFilters ) {
dcraw_finalize_shrink(&final, raw, dark, uf->ConvertShrink);
uf->developer->doWB = 1;
} else {
- if (uf->conf->threshold>0) {
- dcraw_image_type *tmp = raw->raw.image;
- raw->raw.image = g_memdup(tmp, raw->raw.height * raw->raw.width *
- sizeof (dcraw_image_type));
- dcraw_wavelet_denoise(raw, uf->conf->threshold);
- dcraw_finalize_interpolate(&final, raw, dark,
- uf->conf->interpolation, uf->conf->smoothing,
- uf->developer->rgbWB);
- g_free(raw->raw.image);
- raw->raw.image = tmp;
- } else {
- dcraw_finalize_interpolate(&final, raw, dark,
- uf->conf->interpolation, uf->conf->smoothing,
- uf->developer->rgbWB);
- }
+ dcraw_wavelet_denoise(raw, uf->conf->threshold);
+ dcraw_finalize_interpolate(&final, raw, dark,
+ uf->conf->interpolation, uf->conf->smoothing,
+ uf->developer->rgbWB);
uf->developer->doWB = 0;
}
+ g_free(raw->raw.image);
+ raw->raw.image = rawimage;
dcraw_image_stretch(&final, raw->pixel_aspect);
if (uf->conf->size==0 && uf->conf->shrink>1) {
Index: ufraw_ui.h
===================================================================
RCS file: /cvsroot/ufraw/ufraw/ufraw_ui.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- ufraw_ui.h 27 Sep 2009 22:39:39 -0000 1.19
+++ ufraw_ui.h 29 Sep 2009 16:45:36 -0000 1.20
@@ -61,12 +61,18 @@
GtkTable *GrayscaleMixerTable;
GtkLabel *GrayscaleMixerColor;
GtkLabel *SpotPatch;
+#ifdef UFRAW_HOTPIXELS
+ GtkLabel *HotpixelCount;
+#endif
colorLabels *SpotLabels, *AvrLabels, *DevLabels, *OverLabels, *UnderLabels;
GtkToggleButton *AutoExposureButton, *AutoBlackButton, *LockAspectButton;
GtkWidget *AutoCurveButton;
GtkWidget *ResetWBButton, *ResetGammaButton, *ResetLinearButton;
GtkWidget *ResetExposureButton, *ResetSaturationButton;
GtkWidget *ResetThresholdButton;
+#ifdef UFRAW_HOTPIXELS
+ GtkWidget *ResetHotpixelButton;
+#endif
#ifdef UFRAW_CONTRAST
GtkWidget *ResetContrastButton;
#endif
@@ -92,6 +98,9 @@
GtkAdjustment *LinearAdjustment;
GtkAdjustment *ExposureAdjustment;
GtkAdjustment *ThresholdAdjustment;
+#ifdef UFRAW_HOTPIXELS
+ GtkAdjustment *HotpixelAdjustment;
+#endif
GtkAdjustment *SaturationAdjustment;
#ifdef UFRAW_CONTRAST
GtkAdjustment *ContrastAdjustment;
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
ufraw-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ufraw-cvs