forked from darktable-org/darktable
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraw.h
More file actions
212 lines (187 loc) · 6.65 KB
/
Copy pathdraw.h
File metadata and controls
212 lines (187 loc) · 6.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
This file is part of darktable,
copyright (c) 2009--2010 johannes hanika.
darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
darktable is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with darktable. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DT_GUI_DRAW_H
#define DT_GUI_DRAW_H
/** some common drawing routines. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <math.h>
#include "common/curve_tools.h"
#include <cairo.h>
#include <stdint.h>
#include <glib.h>
#include "common/darktable.h"
#include "develop/develop.h"
/** wrapper around nikon curve or gegl. */
typedef struct dt_draw_curve_t
{
CurveData c;
CurveSample csample;
}
dt_draw_curve_t;
/** draws a rating star
TODO: Use this instead of views/view.c dt_view_star in lightable expose.
*/
static inline void dt_draw_star(cairo_t *cr, float x, float y, float r1, float r2)
{
const float d = 2.0*M_PI*0.1f;
const float dx[10] = {sinf(0.0), sinf(d), sinf(2*d), sinf(3*d), sinf(4*d), sinf(5*d), sinf(6*d), sinf(7*d), sinf(8*d), sinf(9*d)};
const float dy[10] = {cosf(0.0), cosf(d), cosf(2*d), cosf(3*d), cosf(4*d), cosf(5*d), cosf(6*d), cosf(7*d), cosf(8*d), cosf(9*d)};
cairo_move_to(cr, x+r1*dx[0], y-r1*dy[0]);
for(int k=1; k<10; k++)
if(k&1) cairo_line_to(cr, x+r2*dx[k], y-r2*dy[k]);
else cairo_line_to(cr, x+r1*dx[k], y-r1*dy[k]);
cairo_close_path(cr);
}
static inline void dt_draw_line(cairo_t *cr, float left, float top, float right, float bottom)
{
cairo_move_to(cr, left, top);
cairo_line_to(cr, right, bottom);
}
static inline void dt_draw_grid(cairo_t *cr, const int num, const int left, const int top, const int right, const int bottom)
{
float width = right - left;
float height = bottom - top;
for(int k=1; k<num; k++)
{
dt_draw_line(cr, left + k/(float)num*width, top, left + k/(float)num*width, bottom);
cairo_stroke(cr);
dt_draw_line(cr, left, top + k/(float)num*height, right, top + k/(float)num*height);
cairo_stroke(cr);
}
}
static inline void dt_draw_vertical_lines(cairo_t *cr, const int num,
const int left, const int top,
const int right, const int bottom)
{
float width = right - left;
for(int k=1; k<num; k++)
{
cairo_move_to(cr, left + k/(float)num*width, top);
cairo_line_to(cr, left + k/(float)num*width, bottom);
cairo_stroke(cr);
}
}
static inline void dt_draw_endmarker(cairo_t *cr, const int width, const int height, const int left)
{
// fibonacci spiral:
float v[14] = { -8., 3.,
-8., 0., -13., 0., -13, 3.,
-13., 8., -8., 8., 0., 0.
};
for(int k=0; k<14; k+=2) v[k] = v[k]*0.01 + 0.5;
for(int k=1; k<14; k+=2) v[k] = v[k]*0.03 + 0.5;
for(int k=0; k<14; k+=2) v[k] *= width;
for(int k=1; k<14; k+=2) v[k] *= height;
if(left)
for(int k=0; k<14; k+=2) v[k] = width - v[k];
cairo_set_line_width(cr, 2.);
cairo_set_source_rgb(cr, 0.3, 0.3, 0.3);
cairo_move_to (cr, v[0], v[1]);
cairo_curve_to(cr, v[2], v[3], v[4], v[5], v[6], v[7]);
cairo_curve_to(cr, v[8], v[9], v[10], v[11], v[12], v[13]);
for(int k=0; k<14; k+=2) v[k] = width - v[k];
for(int k=1; k<14; k+=2) v[k] = height - v[k];
cairo_curve_to(cr, v[10], v[11], v[8], v[9], v[6], v[7]);
cairo_curve_to(cr, v[4], v[5], v[2], v[3], v[0], v[1]);
cairo_stroke(cr);
}
static inline dt_draw_curve_t *dt_draw_curve_new(const float min, const float max,
unsigned int type)
{
dt_draw_curve_t *c = (dt_draw_curve_t *)malloc(sizeof(dt_draw_curve_t));
c->csample.m_samplingRes = 0x10000;
c->csample.m_outputRes = 0x10000;
c->csample.m_Samples = (uint16_t *)malloc(sizeof(uint16_t)*0x10000);
c->c.m_spline_type = type;
c->c.m_numAnchors = 0;
c->c.m_min_x = 0.0;
c->c.m_max_x = 1.0;
c->c.m_min_y = 0.0;
c->c.m_max_y = 1.0;
return c;
}
static inline void dt_draw_curve_destroy(dt_draw_curve_t *c)
{
free(c->csample.m_Samples);
free(c);
}
static inline void dt_draw_curve_set_point(dt_draw_curve_t *c, const int num, const float x, const float y)
{
c->c.m_anchors[num].x = x;
c->c.m_anchors[num].y = y;
}
static inline void dt_draw_curve_calc_values(dt_draw_curve_t *c, const float min, const float max, const int res, float *x, float *y)
{
c->csample.m_samplingRes = res;
c->csample.m_outputRes = 0x10000;
CurveDataSample(&c->c, &c->csample);
if(x) for(int k=0; k<res; k++) x[k] = k*(1.0f/res);
if(y) for(int k=0; k<res; k++)
y[k] = min + (max-min)*c->csample.m_Samples[k]*(1.0f/0x10000);
}
static inline float dt_draw_curve_calc_value(dt_draw_curve_t *c, const float x)
{
float xa[20], ya[20];
float val;
float *ypp;
for(int i=0; i<c->c.m_numAnchors; i++)
{
xa[i] = c->c.m_anchors[i].x;
ya[i] = c->c.m_anchors[i].y;
}
ypp = interpolate_set(c->c.m_numAnchors, xa, ya, c->c.m_spline_type);
val = interpolate_val(c->c.m_numAnchors, xa, x, ya, ypp, c->c.m_spline_type);
free(ypp);
return MIN(MAX(val, c->c.m_min_y), c->c.m_max_y);
}
static inline int dt_draw_curve_add_point(dt_draw_curve_t *c, const float x, const float y)
{
c->c.m_anchors[c->c.m_numAnchors].x = x;
c->c.m_anchors[c->c.m_numAnchors].y = y;
c->c.m_numAnchors++;
return 0;
}
static inline void dt_draw_histogram_8_linear(cairo_t *cr, float *hist, int32_t channel)
{
cairo_move_to(cr, 0, 0);
for(int k=0; k<64; k++)
cairo_line_to(cr, k, hist[4*k+channel]);
cairo_line_to(cr, 63, 0);
cairo_close_path(cr);
cairo_fill(cr);
}
static inline void dt_draw_histogram_8_log(cairo_t *cr, float *hist, int32_t channel)
{
cairo_move_to(cr, 0, 0);
for(int k=0; k<64; k++)
cairo_line_to(cr, k, logf(1.0 + hist[4*k+channel]));
cairo_line_to(cr, 63, 0);
cairo_close_path(cr);
cairo_fill(cr);
}
static inline void dt_draw_histogram_8(cairo_t *cr, float *hist, int32_t channel)
{
if(darktable.develop->histogram_linear == TRUE)
dt_draw_histogram_8_linear(cr, hist, channel);
else
dt_draw_histogram_8_log(cr, hist, channel);
}
#endif
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-space on;