Skip to content

Commit 77a66c7

Browse files
committed
Merge branch 'master' of github.com:jcupitt/nip2
2 parents 8299535 + df954a0 commit 77a66c7

File tree

8 files changed

+148
-5
lines changed

8 files changed

+148
-5
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ started 8.5 24/1/17
22
- add max_slope to lhist
33
- gaussnoise goes via vips8 now
44
- add snake option to array join [Joe Padfield]
5+
- parse_float was broken for numbers starting "0."
6+
- add alpha section to Image / Band menu ... Flatten, Premultiply,
7+
Unpremultiply, Blend
8+
- add Entropy to hist menu
59

610
started 8.4.1 25/9/16
711
- simplify nip2-icon.rc build, bgilbert

TODO

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
- seeing occasional "rewind image with active regions" message
22

3+
- should parse_float / _int etc. allow leading and trailing spaces?
4+
5+
(split is_space x)?0
6+
37
- how about adding
48

59
zip2 10 [1..5] == [[10, 1], [10, 2], [10, 3], ..

share/nip2/start/Filter.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ Filter_blend_item = class
10051005
}
10061006

10071007
Blend_alpha_item = class
1008-
Menuaction "_Alpha" "blend images with optional alpha channels" {
1008+
Menuaction "Blend _Alpha" "blend images with optional alpha channels" {
10091009
// usage: layerit foreground background
10101010
// input images must be either 1 or 3 bands, optionally + 1 band
10111011
// which is used as the alpha channel

share/nip2/start/Histogram.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ Hist_zerox_item = class
162162
}
163163
}
164164

165+
Hist_entropy_item = class Menuaction "Entropy" "calculate histogram entropy" {
166+
action x = hist_entropy x;
167+
}
168+
165169
#separator
166170

167171
Hist_profile_item = class

share/nip2/start/Image.def

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,30 @@ Image_band_item = class
10621062

10631063
sep1 = Menuseparator;
10641064

1065+
Flatten_item = class Menuaction "_Flatten" "flatten alpha out of image" {
1066+
action x = class
1067+
_result {
1068+
_vislevel = 3;
1069+
1070+
bg = Expression "Background" 0;
1071+
1072+
_result = map_unary (flattenimage bg) x;
1073+
}
1074+
}
1075+
1076+
Premultiply_item = class Menuaction "_Premultiply" "premultiply alpha" {
1077+
action x = premultiply x;
1078+
}
1079+
1080+
Unpremultiply_item = class
1081+
Menuaction "_Unpremultiply" "unpremultiply alpha" {
1082+
action x = unpremultiply x;
1083+
}
1084+
1085+
Blend_alpha_item = Filter_blend_item.Blend_alpha_item;
1086+
1087+
sep1a = Menuseparator;
1088+
10651089
Bandand_item = class
10661090
Menuaction "Bitwise Band AND" "bitwise AND of image bands" {
10671091
action x = bandand x;
@@ -1321,8 +1345,8 @@ Image_draw_item = class
13211345
_result {
13221346
_vislevel = 3;
13231347

1324-
sx = Expression "Start x" 100;
1325-
sy = Expression "Start y" 100;
1348+
sx = Expression "Start x" 0;
1349+
sy = Expression "Start y" 0;
13261350

13271351
e = Option "Flood while" [
13281352
"Not equal to ink",

share/nip2/start/_convert.def

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,36 @@ to_matrix x
2121
= error (_ "not image");
2222
}
2323

24+
/* Try to make a Vector ... works for Vector/Image/Real, plus image/real
25+
*/
26+
to_vector x
27+
= to_vector x.expr, is_Expression x
28+
= x, is_Vector x
29+
= oo_unary_function to_vector_op x, is_class x
30+
= tov x
31+
{
32+
to_vector_op = Operator "to_vector" tov Operator_type.COMPOUND false;
33+
34+
tov x
35+
= Vector (itov x), is_image x
36+
= Vector [x], is_real x
37+
= Vector x, is_real_list x
38+
= Vector x?0, is_matrix x && len x == 1
39+
= Vector (transpose x)?0, is_matrix x && len x?0 == 1
40+
= error (_ "bad arguments to " ++ "to_vector");
41+
42+
itov i
43+
= v, is_image i
44+
= error (_ "not image")
45+
{
46+
m = im_vips2mask ((double) i);
47+
v
48+
= m.value?0, m.height == 1
49+
= (transpose m.value)?0, m.width == 1
50+
= error (_ "image is not 1xN or Nx1");
51+
}
52+
}
53+
2454
/* Try to make an Image ... works for Vector/Matrix/Real, plus image/real
2555
* Special case for Colour ... pull out the colour_space and set Type in the
2656
* image.
@@ -189,7 +219,7 @@ parse_float l
189219

190220
ipart = parse_int parts?0;
191221
sign
192-
= 1, ipart > 0
222+
= 1, ipart >= 0
193223
= -1;
194224
fpart
195225
= 0, parts?1 == [];

share/nip2/start/_stdenv.def

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,3 +2528,70 @@ gaussnoise width height mean sigma
25282528
$sigma => to_real sigma
25292529
];
25302530
}
2531+
2532+
flattenimage bg x
2533+
= oo_unary_function flatten_op x, is_class x
2534+
= flt (to_vector bg) x, is_image x
2535+
= error (_ "bad arguments to " ++ "flattenimage")
2536+
{
2537+
flatten_op = Operator "flatten"
2538+
(flattenimage bg) Operator_type.COMPOUND_REWRAP false;
2539+
2540+
flt bg x
2541+
= out
2542+
{
2543+
[out] = vips_call "flatten" [x] [
2544+
$background => bg.value
2545+
];
2546+
}
2547+
}
2548+
2549+
premultiply x
2550+
= oo_unary_function premultiply_op x, is_class x
2551+
= prem x, is_image x
2552+
= error (_ "bad arguments to " ++ "premultiply")
2553+
{
2554+
premultiply_op = Operator "premultiply"
2555+
premultiply Operator_type.COMPOUND_REWRAP false;
2556+
2557+
prem x
2558+
= out
2559+
{
2560+
[out] = vips_call "premultiply" [x] [
2561+
];
2562+
}
2563+
}
2564+
2565+
unpremultiply x
2566+
= oo_unary_function unpremultiply_op x, is_class x
2567+
= unprem x, is_image x
2568+
= error (_ "bad arguments to " ++ "unpremultiply")
2569+
{
2570+
unpremultiply_op = Operator "unpremultiply"
2571+
unpremultiply Operator_type.COMPOUND_REWRAP false;
2572+
2573+
unprem x
2574+
= out
2575+
{
2576+
[out] = vips_call "unpremultiply" [x] [
2577+
];
2578+
}
2579+
}
2580+
2581+
hist_entropy x
2582+
= oo_unary_function hist_entropy_op x, is_class x
2583+
= entropy x, is_image x
2584+
= error (_ "bad arguments to " ++ "hist_entropy")
2585+
{
2586+
hist_entropy_op = Operator "hist_entropy"
2587+
hist_entropy Operator_type.COMPOUND_REWRAP false;
2588+
2589+
entropy x
2590+
= out
2591+
{
2592+
[out] = vips_call "hist_entropy" [x] [
2593+
];
2594+
}
2595+
}
2596+
2597+

src/heap.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,7 @@ heap_ip_to_gvalue( PElement *in, GValue *out )
18911891
im_ref_string_set( out, name );
18921892
}
18931893
#if VIPS_MAJOR_VERSION > 7 || VIPS_MINOR_VERSION > 39
1894-
/* vips_value_set_array_image() is a 7.40 feature.
1894+
/* vips_value_set_array_*() is a 7.40 feature.
18951895
*/
18961896
else if( heap_is_imagevec( in, &result ) &&
18971897
result ) {
@@ -1914,6 +1914,16 @@ heap_ip_to_gvalue( PElement *in, GValue *out )
19141914
g_object_ref( ivec[i] );
19151915
}
19161916
}
1917+
else if( heap_is_realvec( in, &result ) &&
1918+
result ) {
1919+
double realvec[100];
1920+
int n;
1921+
1922+
if( (n = heap_get_realvec( in, realvec, 100 )) < 0 )
1923+
return( FALSE );
1924+
g_value_init( out, VIPS_TYPE_ARRAY_DOUBLE );
1925+
vips_value_set_array_double( out, realvec, n );
1926+
}
19171927
#endif
19181928
else {
19191929
error_top( _( "Unimplemented list type." ) );

0 commit comments

Comments
 (0)