-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtras.def
198 lines (171 loc) · 6.28 KB
/
Extras.def
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
Draw_scalebar_item = class
Menuaction (_"Draw Scale Bar")
( "Add a consistant scale bar to an image (x), or a group of images, based on a defined resolution (y) (ppmm)") {
action x y = class
_result {
_vislevel = 3;
ow = Option "Output Width" ["One Column", "Two Column", "Custom (cm)"] 1;
cow = Expression "Optional Custom Output Width (cm)" 8;
text = Option "Display Text" [
"20 µm", "50 µm", "100 µm", "200 µm", "500 µm",
"1 mm", "2 mm", "5 mm", "1 cm", "2 cm", "5 cm",
"10 cm", "20 cm", "50 cm", "1 m"] 1;
pos = Option "Position Text" ["Left", "Right"] 0;
col = Option "Text Colour" ["White", "Black", "Red"] 0;
Options = class
{
_vislevel = 1;
dpi = Expression "Output Printing DPI" 600;
ed = Expression "Distance from printed side edge ( % of printed width )" 4;
bd = Expression "Distance from printed bottom edge ( % of printed height )" 3;
thick = Scale "Line thickness" 1 50 5;
font = Fontname "Use font" Workspaces.Preferences.PAINTBOX_FONT;
}
_ow' = [80, 160, (cow.expr*10)]?ow;
_sbw = [0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000]?text;
_colv = [[255, 255, 255], [0, 0, 0], [255, 0, 0]];
_col' = Colour "sRGB" _colv?col;
_dpi = Options.dpi.expr;
_dpmm = _dpi/(2.54*10);
_pw =_ow' * _dpmm;
_edmm = (Options.ed.expr * _ow')/100;
_interp = Interpolate_picker Interpolate_type.BILINEAR;
//Check for a group + int pair
_y = y, is_Group y;
= Group (map (const y) [1..(len x.value)]), is_Group x;
= y;
_result
= map_binary process x _y
{
process im ppmm = blend (Image scale) ink' nim
{
// make an ink compatible with the image
ink' = colour_transform_to (get_type im) _col';
im_scale = _pw / im.width;
ph = im.height * im_scale;
oh = (_ow' * im.height)/im.width;
nim = resize _interp im_scale im_scale im;
nppmm = ppmm * im_scale;
w = _sbw * nppmm;
bdmm = (Options.bd.expr * oh)/100;
xp = [_edmm * _dpmm, _pw - w - (_edmm * _dpmm)]?pos;
yp = ph - (bdmm * _dpmm);
t = (floor Options.thick.value * _ow')/160;
bg = image_new (get_width nim) (get_height nim) (get_bands nim)
(get_format nim) (get_coding nim) (get_type nim) 0 0 0;
draw_block xp yp w t nim =
draw_rect_width xp yp w t true 1 [255] nim;
label = im_text text.labels?text Options.font.value w 1 (_dpi*(_ow'/160));
lw = get_width label;
lh = get_height label;
ly = yp - lh - t;
vx = [xp - t / 2, xp + w - t / 2];
scale = (draw_block xp yp w t @
draw_block vx?0 (yp - 2 * t) t (t * 5) @
draw_block vx?1 (yp - 2 * t) t (t * 5) @
insert_noexpand (xp + w / 2 - lw / 2) ly label)
bg;
}
}
}
};
Non_zero_colour_item = class
Menuaction (_ "Image to non zero colour")
(_ "Calculate the non zero average colour of an image") {
action x = class
_result {
_vislevel = 3;
_x = Colour_convert_item.sRGB_item.action x;
_R = meanze _x?0;
_G = meanze _x?1;
_B = meanze _x?2;
_spaces = Image_type.image_colour_spaces;
which = Option_enum (_ "Display") _spaces (_spaces.get_name 13);
_rgb = Colour_to_colour_item.action [_R, _G, _B];
_result = Colour_convert_item.conv which.value_thing _rgb;}};
Export_annotations = class
Menuaction (_ "Export relative dimensions")
(_ "Export dimensions and relative positions of a group of points or regions") {
action x =
_result {
_vislevel = 3;
_group_check = is_Group x;
_pt_l = x.value, _group_check
= x;
_str = concat ["{\"annotations\": [",foldl dostuff "" _pt_l, "]}"];
_result = String "Annotation" _str;
dostuff _s1 _s2 = _s1p2 {
_s1p2 = concat [_s1, process _s2], _s1 == ""
= concat [_s1, ", ", process _s2];}
process r = _str {
_iw = r.image.width;
_ih = r.image.height;
_rt = r.top;
_rl = r.left;
_rw = r.width;
_rh = r.height;
x = _rl/_iw;
y = _rt/_ih;
w = _rw/_iw;
h = _rh/_ih;
_str = concat ["{ \"file\":", print r.image.super.filename, ", \"x\": ",
print x, ", \"y\": ", print y, ", \"w\": ", print w, ", \"h\": ",
print h, ", \"title\": \"Default Title\", \"text\": \"Default Text.\" }"];}}};
Average_colour_from_group_of_marks_item = class
Menuaction (_ "Average colour from area")
(_ "Calculate the non zero average colour of area defined by a Group of marks") {
action x = class
_result {
_vislevel = 3;
_mask = select_polygon x;
_oim = get_image ((x.value)?0);
_im = if _mask then _oim else 0;
_x = Colour_convert_item.sRGB_item.action _im;
_R = meanze _x?0;
_G = meanze _x?1;
_B = meanze _x?2;
_spaces = Image_type.image_colour_spaces;
which = Option_enum (_ "Display") _spaces (_spaces.get_name 13);
_rgb = Colour_to_colour_item.action [_R, _G, _B];
_result = Colour_convert_item.conv which.value_thing _rgb;}};
Adjust_logo_colours_item = class
Menuaction (_ "Adjust logo colours")
(_ "Alter the colours used in a 2 tone logo, text on a background colour") {
action x = class
_result {
_vislevel = 3;
_bw_x = (colour_transform_to 1 x)?0;
_sc_x = scale _bw_x;
invert = Toggle "Swap Colours" false;
colour_1 = Colour "sRGB" [0,0,0];
colour_2 = Colour "sRGB" [255,255,255];
_result = sub_action _sc_x colour_2 colour_1, invert
= sub_action _sc_x colour_1 colour_2;
sub_action a b c
= map_trinary process a b c
{
process a b c
= blend condition in1 in2
{
compare a b
// prefer image as the condition
= false,
!has_image a && has_image b
// prefer mono images as the condition
= false,
has_bands a && has_bands b &&
get_bands a > 1 && get_bands b == 1
// prefer uchar as the condition
= false,
has_format a && has_format b &&
get_format a > Image_format.UCHAR &&
get_format b == Image_format.UCHAR
= true;
args' = sortc compare [a, b, c];
condition = args'?0;
in1 = args'?1;
in2 = args'?2;
}
}
}
};