Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up some code and variables #1

Open
wants to merge 2 commits into
base: rlucy
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ tools/iop_deps.pdf
cscope.out
.*.swp
.vscode/
.idea

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

190 changes: 97 additions & 93 deletions src/bauhaus/bauhaus.c

Large diffs are not rendered by default.

47 changes: 24 additions & 23 deletions src/bauhaus/bauhaus.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#define DT_BAUHAUS_WIDGET_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST((obj), DT_BAUHAUS_WIDGET, DtBauhausWidgetClass))
#define DT_IS_BAUHAUS_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), DT_BAUHAUS_WIDGET_TYPE))
#define DT_IS_BAUHAUS_WIDGET_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((obj), DT_BAUHAUS_WIDGET_TYPE))
#define DT_BAUHAUS_WIDGET_GET_CLASS \
#define DT_BAUHAUS_WIDGET_GET_CLASS \
(G_TYPE_INSTANCE_GET_CLASS((obj), DT_BAUHAUS_WIDGET_TYPE, DtBauhausWidgetClass))

extern GType DT_BAUHAUS_WIDGET_TYPE;
Expand Down Expand Up @@ -82,10 +82,10 @@ typedef struct dt_bauhaus_slider_data_t

char format[24]; // numeric value is printed with this string

int is_dragging; // indicates is mouse is dragging slider
int is_changed; // indicates new data
guint timeout_handle; // used to store id of timeout routine
float (*callback)(GtkWidget*, float, dt_bauhaus_callback_t); // callback function
int is_dragging; // indicates is mouse is dragging slider
int is_changed; // indicates new data
guint timeout_handle; // used to store id of timeout routine
float (*callback)(GtkWidget *, float, dt_bauhaus_callback_t); // callback function
} dt_bauhaus_slider_data_t;

typedef enum dt_bauhaus_combobox_alignment_t
Expand Down Expand Up @@ -227,7 +227,7 @@ void dt_bauhaus_cleanup();
// common functions:
// set the label text:
void dt_bauhaus_widget_set_label(GtkWidget *w, const char *section, const char *label);
const char* dt_bauhaus_widget_get_label(GtkWidget *w);
const char *dt_bauhaus_widget_get_label(GtkWidget *w);
// attach a custom painted quad to the space at the right side (overwriting the default icon if any):
void dt_bauhaus_widget_set_quad_paint(GtkWidget *w, dt_bauhaus_quad_paint_f f, int paint_flags);
// make this quad a toggle button:
Expand All @@ -238,27 +238,27 @@ void dt_bauhaus_show_popup(dt_bauhaus_widget_t *w);

// slider:
GtkWidget *dt_bauhaus_slider_new(dt_iop_module_t *self);
GtkWidget *dt_bauhaus_slider_new_with_range(dt_iop_module_t *self, float min, float max, float step,
float defval, int digits);
GtkWidget *dt_bauhaus_slider_new_with_range_and_feedback(dt_iop_module_t *self, float min, float max,
float step, float defval, int digits, int feedback);
GtkWidget *dt_bauhaus_slider_new_with_range(dt_iop_module_t *self, float min, float max, float step, float defval,
int digits);
GtkWidget *dt_bauhaus_slider_new_with_range_and_feedback(dt_iop_module_t *self, float min, float max, float step,
float defval, int digits, int feedback);

GtkWidget *dt_bauhaus_slider_from_widget(dt_bauhaus_widget_t* widget, dt_iop_module_t *self, float min, float max,
float step, float defval, int digits, int feedback);
GtkWidget *dt_bauhaus_slider_from_widget(dt_bauhaus_widget_t *widget, dt_iop_module_t *self, float min, float max,
float step, float defval, int digits, int feedback);
// outside doesn't see the real type, we cast it internally.
void dt_bauhaus_slider_set(GtkWidget *w, float pos);
void dt_bauhaus_slider_set_soft(GtkWidget *w, float pos);
float dt_bauhaus_slider_get(GtkWidget *w);

void dt_bauhaus_slider_set_soft_min(GtkWidget* w, float val);
float dt_bauhaus_slider_get_soft_min(GtkWidget* w);
void dt_bauhaus_slider_set_soft_max(GtkWidget* w, float val);
float dt_bauhaus_slider_get_soft_max(GtkWidget* w);
void dt_bauhaus_slider_set_soft_min(GtkWidget *w, float val);
float dt_bauhaus_slider_get_soft_min(GtkWidget *w);
void dt_bauhaus_slider_set_soft_max(GtkWidget *w, float val);
float dt_bauhaus_slider_get_soft_max(GtkWidget *w);

void dt_bauhaus_slider_set_hard_min(GtkWidget* w, float val);
float dt_bauhaus_slider_get_hard_min(GtkWidget* w);
void dt_bauhaus_slider_set_hard_max(GtkWidget* w, float val);
float dt_bauhaus_slider_get_hard_max(GtkWidget* w);
void dt_bauhaus_slider_set_hard_min(GtkWidget *w, float val);
float dt_bauhaus_slider_get_hard_min(GtkWidget *w);
void dt_bauhaus_slider_set_hard_max(GtkWidget *w, float val);
float dt_bauhaus_slider_get_hard_max(GtkWidget *w);

void dt_bauhaus_slider_set_digits(GtkWidget *w, int val);
int dt_bauhaus_slider_get_digits(GtkWidget *w);
Expand All @@ -271,17 +271,18 @@ void dt_bauhaus_slider_set_stop(GtkWidget *widget, float stop, float r, float g,
void dt_bauhaus_slider_clear_stops(GtkWidget *widget);
void dt_bauhaus_slider_set_default(GtkWidget *widget, float def);
void dt_bauhaus_slider_enable_soft_boundaries(GtkWidget *widget, float hard_min, float hard_max);
void dt_bauhaus_slider_set_callback(GtkWidget *widget, float (*callback)(GtkWidget *self, float value, dt_bauhaus_callback_t dir));
void dt_bauhaus_slider_set_callback(GtkWidget *widget,
float (*callback)(GtkWidget *self, float value, dt_bauhaus_callback_t dir));

// combobox:
void dt_bauhaus_combobox_from_widget(dt_bauhaus_widget_t* widget,dt_iop_module_t *self);
void dt_bauhaus_combobox_from_widget(dt_bauhaus_widget_t *widget, dt_iop_module_t *self);
GtkWidget *dt_bauhaus_combobox_new(dt_iop_module_t *self);

void dt_bauhaus_combobox_add(GtkWidget *widget, const char *text);
void dt_bauhaus_combobox_add_aligned(GtkWidget *widget, const char *text, dt_bauhaus_combobox_alignment_t align);
void dt_bauhaus_combobox_set(GtkWidget *w, int pos);
void dt_bauhaus_combobox_remove_at(GtkWidget *widget, int pos);
void dt_bauhaus_combobox_insert(GtkWidget *widget, const char *text,int pos);
void dt_bauhaus_combobox_insert(GtkWidget *widget, const char *text, int pos);
int dt_bauhaus_combobox_length(GtkWidget *widget);
void dt_bauhaus_combobox_set_editable(GtkWidget *w, int editable);
int dt_bauhaus_combobox_get_editable(GtkWidget *w);
Expand Down
3 changes: 2 additions & 1 deletion src/chart/cairo.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ void draw_color_boxes_outline(cairo_t *cr, point_t *bb, chart_t *chart)
_draw_boxes(cr, bb, chart->box_table);
}

void draw_color_boxes_inside(cairo_t *cr, point_t *bb, chart_t *chart, float shrink, float line_width, gboolean colored)
void draw_color_boxes_inside(cairo_t *cr, point_t *bb, chart_t *chart, float shrink, float line_width,
gboolean colored)
{
GHashTableIter table_iter;
gpointer key, value;
Expand Down
3 changes: 2 additions & 1 deletion src/chart/colorchart.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

#define MAX_LINE_LENGTH 512

typedef enum parser_state_t {
typedef enum parser_state_t
{
BLOCK_NONE = 0,
BLOCK_BOXES,
BLOCK_BOX_SHRINK,
Expand Down
44 changes: 22 additions & 22 deletions src/chart/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,7 @@ static void export_raw(dt_lut_t *self, char *filename, char *name, char *descrip
GList *patch_names = NULL;
char *gray_ramp_key = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(self->gray_ramp));

if(gray_ramp_key)
patch_names = g_hash_table_lookup(self->chart->patch_sets, gray_ramp_key);
if(gray_ramp_key) patch_names = g_hash_table_lookup(self->chart->patch_sets, gray_ramp_key);

const int num_gray = g_list_length(patch_names);

Expand Down Expand Up @@ -708,13 +707,15 @@ static void add_hdr_patches(int *N, double **target_L, double **target_a, double

for(int j = 0; j < *N; j++)
{
if((*target_L)[j] == 100.0 && (*target_a)[j] == 0.0 && (*target_b)[j] == 0.0 && (*colorchecker_Lab)[j * 3] == 100.0
&& (*colorchecker_Lab)[j * 3 + 1] == 0.0 && (*colorchecker_Lab)[j * 3 + 2] == 0.0)
if((*target_L)[j] == 100.0 && (*target_a)[j] == 0.0 && (*target_b)[j] == 0.0
&& (*colorchecker_Lab)[j * 3] == 100.0 && (*colorchecker_Lab)[j * 3 + 1] == 0.0
&& (*colorchecker_Lab)[j * 3 + 2] == 0.0)
{
need_hdr00 = FALSE;
}
else if((*target_L)[j] == 200.0 && (*target_a)[j] == 0.0 && (*target_b)[j] == 0.0 && (*colorchecker_Lab)[j * 3] == 200.0
&& (*colorchecker_Lab)[j * 3 + 1] == 0.0 && (*colorchecker_Lab)[j * 3 + 2] == 0.0)
else if((*target_L)[j] == 200.0 && (*target_a)[j] == 0.0 && (*target_b)[j] == 0.0
&& (*colorchecker_Lab)[j * 3] == 200.0 && (*colorchecker_Lab)[j * 3 + 1] == 0.0
&& (*colorchecker_Lab)[j * 3 + 2] == 0.0)
{
need_hdr01 = FALSE;
}
Expand Down Expand Up @@ -970,14 +971,14 @@ static void process_data(dt_lut_t *self, double *target_L, double *target_a, dou
double avgerr, maxerr;
sparsity = thinplate_match(&tonecurve, 3, N, colorchecker_Lab, target, sparsity, perm, coeff, &avgerr, &maxerr);

if (self->result_label != NULL)
if(self->result_label != NULL)
{
// TODO: is the rank interesting, too?
char *result_string = g_strdup_printf(_("average dE: %.02f\nmax dE: %.02f"), avgerr, maxerr);
gtk_label_set_text(GTK_LABEL(self->result_label), result_string);
g_free(result_string);
}

free(coeff_b);
free(coeff_a);
free(coeff_L);
Expand Down Expand Up @@ -1539,21 +1540,19 @@ static void get_corners(point_t *bb, box_t *box, point_t *corners)
static void get_pixel_region(const image_t *const image, const point_t *const corners, int *x_start, int *y_start,
int *x_end, int *y_end)
{
*x_start = CLAMP((int)(MIN(corners[TOP_LEFT].x,
MIN(corners[TOP_RIGHT].x, MIN(corners[BOTTOM_RIGHT].x, corners[BOTTOM_LEFT].x)))
+ 0.5),
0, image->width);
*x_start
= CLAMP((int)(MIN(corners[TOP_LEFT].x,
MIN(corners[TOP_RIGHT].x, MIN(corners[BOTTOM_RIGHT].x, corners[BOTTOM_LEFT].x))) + 0.5),
0, image->width);
*x_end = CLAMP((int)(MAX(corners[TOP_LEFT].x,
MAX(corners[TOP_RIGHT].x, MAX(corners[BOTTOM_RIGHT].x, corners[BOTTOM_LEFT].x)))
+ 0.5),
MAX(corners[TOP_RIGHT].x, MAX(corners[BOTTOM_RIGHT].x, corners[BOTTOM_LEFT].x))) + 0.5),
0, image->width);
*y_start = CLAMP((int)(MIN(corners[TOP_LEFT].y,
MIN(corners[TOP_RIGHT].y, MIN(corners[BOTTOM_RIGHT].y, corners[BOTTOM_LEFT].y)))
+ 0.5),
0, image->height);
*y_start
= CLAMP((int)(MIN(corners[TOP_LEFT].y,
MIN(corners[TOP_RIGHT].y, MIN(corners[BOTTOM_RIGHT].y, corners[BOTTOM_LEFT].y))) + 0.5),
0, image->height);
*y_end = CLAMP((int)(MAX(corners[TOP_LEFT].y,
MAX(corners[TOP_RIGHT].y, MAX(corners[BOTTOM_RIGHT].y, corners[BOTTOM_LEFT].y)))
+ 0.5),
MAX(corners[TOP_RIGHT].y, MAX(corners[BOTTOM_RIGHT].y, corners[BOTTOM_LEFT].y))) + 0.5),
0, image->height);
}

Expand Down Expand Up @@ -1675,7 +1674,8 @@ static int main_gui(dt_lut_t *self, int argc, char *argv[])
}

static int parse_csv(dt_lut_t *self, const char *filename, double **target_L_ptr, double **target_a_ptr,
double **target_b_ptr, double **source_Lab_ptr, int *num_gray, char **name, char **description)
double **target_b_ptr, double **source_Lab_ptr, int *num_gray, char **name,
char **description)
{
*target_L_ptr = NULL;
*target_a_ptr = NULL;
Expand All @@ -1698,7 +1698,7 @@ static int parse_csv(dt_lut_t *self, const char *filename, double **target_L_ptr
}

// header lines
char key[16] = {0}, value[256] = {0};
char key[16] = { 0 }, value[256] = { 0 };
int unused = fscanf(f, "%15[^;];%255[^\n]\n", key, value);
if(g_strcmp0(key, "name") || unused == EOF)
{
Expand Down
6 changes: 4 additions & 2 deletions src/chart/pfm.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ float *read_pfm(const char *filename, int *wd, int *ht)
for(size_t i = (size_t)width * height; i > 0; i--)
for(int c = 0; c < 3; c++)
{
union {
union
{
float f;
guint32 i;
} v;
Expand All @@ -95,7 +96,8 @@ float *read_pfm(const char *filename, int *wd, int *ht)
for(size_t j = 0; j < height; j++)
for(size_t i = 0; i < width; i++)
{
union {
union
{
float f;
guint32 i;
} v;
Expand Down
39 changes: 19 additions & 20 deletions src/chart/thinplate.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
// very fast, very approximate
static inline float __attribute__((__unused__)) fasterlog(float x)
{
union { float f; uint32_t i; } vx = { x };
union
{
float f;
uint32_t i;
} vx = { x };
float y = vx.i;
y *= 8.2629582881927490e-8f;
return y - 87.989971088f;
Expand All @@ -55,14 +59,9 @@ static inline double thinplate_kernel(const double *x, const double *y)
// return r * r * fasterlog(MAX(1e-8f, r));
}

static inline double compute_error(
const tonecurve_t *c,
const double **target,
const double *residual_L,
const double *residual_a,
const double *residual_b,
const int wd,
double *maxerr)
static inline double compute_error(const tonecurve_t *c, const double **target, const double *residual_L,
const double *residual_a, const double *residual_b, const int wd,
double *maxerr)
{
// compute error:
double err = 0.0;
Expand All @@ -78,8 +77,9 @@ static inline double compute_error(
const double localerr = dt_colorspaces_deltaE_2000(Lab0, Lab1);
err += localerr;
#else
const double localerr = sqrt(residual_L[i] * residual_L[i] + residual_a[i] * residual_a[i] + residual_b[i] * residual_b[i]);
err += localerr/wd;
const double localerr
= sqrt(residual_L[i] * residual_L[i] + residual_a[i] * residual_a[i] + residual_b[i] * residual_b[i]);
err += localerr / wd;
#endif
merr = MAX(merr, localerr);

Expand Down Expand Up @@ -150,8 +150,8 @@ int thinplate_match(const tonecurve_t *curve, // tonecurve to apply after this (
int *permutation, // pointing to original order of points, to identify correct output coeff
double **coeff, // output coefficient arrays for each dimension, ordered according to
// permutation[dim]
double *avgerr, // average error
double *maxerr) // max error
double *avgerr, // average error
double *maxerr) // max error
{
if(avgerr) *avgerr = 0.0;
if(maxerr) *maxerr = 0.0;
Expand Down Expand Up @@ -306,7 +306,7 @@ int thinplate_match(const tonecurve_t *curve, // tonecurve to apply after this (
for(int i = 0; i < sparsity; i++)
for(int j = 0; j < wd; j++) As[j * S + i] = A[j * wd + permutation[i]];

if(solve(As, w, v, b[ch], coeff[ch], wd, sparsity-1, S))
if(solve(As, w, v, b[ch], coeff[ch], wd, sparsity - 1, S))
{
free(r);
free(b);
Expand Down Expand Up @@ -357,7 +357,7 @@ int thinplate_match(const tonecurve_t *curve, // tonecurve to apply after this (
fprintf(stderr, "replacing %d <- %d\n", mincol, maxcol);
// replace column
permutation[mincol] = maxcol;
// reset norm[] of discarded column to something > 0
// reset norm[] of discarded column to something > 0
#ifdef EXACT
norm[mincol] = 1.0;
#else
Expand All @@ -372,7 +372,7 @@ int thinplate_match(const tonecurve_t *curve, // tonecurve to apply after this (
#ifdef EXACT
double err = 1. / maxdot;
#else
const int sp = MIN(sparsity, S-1); // need to fix up for replacement
const int sp = MIN(sparsity, S - 1); // need to fix up for replacement
// solve linear least squares for sparse c for every output channel:
for(int ch = 0; ch < dim; ch++)
{
Expand Down Expand Up @@ -408,15 +408,14 @@ int thinplate_match(const tonecurve_t *curve, // tonecurve to apply after this (
#endif
// residual is max CIE76 delta E now
// everything < 2 is usually considired a very good approximation:
if(patches == S-4)
if(patches == S - 4)
{
if(avgerr) *avgerr = err;
if(maxerr) *maxerr = merr;
fprintf(stderr, "rank %d/%d avg DE %g max DE %g\n", sp + 1, patches, err, merr);
}
if(s >= S && err >= olderr)
fprintf(stderr, "error increased!\n");
// return sparsity + 1;
if(s >= S && err >= olderr) fprintf(stderr, "error increased!\n");
// return sparsity + 1;
// if(err < 2.0) return sparsity+1;
olderr = err;
}
Expand Down
4 changes: 2 additions & 2 deletions src/chart/thinplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ int thinplate_match(const tonecurve_t *curve, // tonecurve to apply after this (
int *permutation, // pointing to original order of points, to identify correct output coeff
double **coeff, // output coefficient arrays for each dimension, ordered according to
// permutation[dim]
double *avgerr, // average error
double *maxerr); // max error
double *avgerr, // average error
double *maxerr); // max error

float thinplate_color_pos(float L, float a, float b);

Expand Down
Loading