33
33
*/
34
34
package net .imglib2 .algorithm .blocks .convert ;
35
35
36
+ import java .util .function .Function ;
36
37
import java .util .function .Supplier ;
37
38
39
+ import net .imglib2 .algorithm .blocks .BlockSupplier ;
38
40
import net .imglib2 .algorithm .blocks .DefaultUnaryBlockOperator ;
39
41
import net .imglib2 .algorithm .blocks .UnaryBlockOperator ;
40
42
import net .imglib2 .converter .Converter ;
59
61
*/
60
62
public class Convert
61
63
{
64
+ /**
65
+ * Create {@link UnaryBlockOperator} to convert blocks from {@code S} to
66
+ * {@code T}.
67
+ * <p>
68
+ * Supported source/target types are {@code ByteType}, {@code
69
+ * UnsignedByteType}, {@code ShortType}, {@code UnsignedShortType}, {@code
70
+ * IntType}, {@code UnsignedIntType}, {@code LongType}, {@code
71
+ * UnsignedLongType}, {@code FloatType}, and {@code DoubleType}.
72
+ * <p>
73
+ * Target values are not clamped, so overflow may occur if the source type
74
+ * has a larger range than the target type.
75
+ * <p>
76
+ * The returned factory function creates an operator matching the type
77
+ * {@code S} of the given input {@code BlockSupplier<T>}.
78
+ *
79
+ * @param targetType
80
+ * an instance of the target type
81
+ * @param <S>
82
+ * source type
83
+ * @param <T>
84
+ * target type
85
+ *
86
+ * @return factory for {@code UnaryBlockOperator} to convert blocks from {@code S} to {@code T}
87
+ */
88
+ public static < S extends NativeType < S >, T extends NativeType < T > >
89
+ Function < BlockSupplier < S >, UnaryBlockOperator < S , T > > convert ( final T targetType )
90
+ {
91
+ return convert ( targetType , ClampType .NONE );
92
+ }
93
+
94
+ /**
95
+ * Create {@link UnaryBlockOperator} to convert blocks from {@code S} to
96
+ * {@code T}.
97
+ * <p>
98
+ * Supported source/target types are {@code ByteType}, {@code
99
+ * UnsignedByteType}, {@code ShortType}, {@code UnsignedShortType}, {@code
100
+ * IntType}, {@code UnsignedIntType}, {@code LongType}, {@code
101
+ * UnsignedLongType}, {@code FloatType}, and {@code DoubleType}.
102
+ * <p>
103
+ * If the target type cannot represent the full range of the source type,
104
+ * values are clamped according to the specified {@link ClampType}.
105
+ * <p>
106
+ * The returned factory function creates an operator matching the type
107
+ * {@code S} of the given input {@code BlockSupplier<T>}.
108
+ *
109
+ * @param targetType
110
+ * an instance of the target type
111
+ * @param clamp
112
+ * ClampType
113
+ * @param <S>
114
+ * source type
115
+ * @param <T>
116
+ * target type
117
+ *
118
+ * @return factory for {@code UnaryBlockOperator} to convert blocks from {@code S} to {@code T}
119
+ */
120
+ public static < S extends NativeType < S >, T extends NativeType < T > >
121
+ Function < BlockSupplier < S >, UnaryBlockOperator < S , T > > convert ( final T targetType , final ClampType clamp )
122
+ {
123
+ return s -> createOperator ( s .getType (), targetType , clamp );
124
+ }
125
+
126
+ /**
127
+ * Create {@link UnaryBlockOperator} to convert blocks from {@code S} to
128
+ * {@code T} with the specified {@code Converter}.
129
+ * <p>
130
+ * The returned factory function creates an operator matching the type
131
+ * {@code S} of the given input {@code BlockSupplier<T>}.
132
+ *
133
+ * @param targetType
134
+ * an instance of the target type
135
+ * @param converterSupplier
136
+ * creates new converter instances
137
+ * @param <S>
138
+ * source type
139
+ * @param <T>
140
+ * target type
141
+ *
142
+ * @return factory for {@code UnaryBlockOperator} to convert blocks from {@code S} to {@code T}
143
+ */
144
+ public static < S extends NativeType < S >, T extends NativeType < T > >
145
+ Function < BlockSupplier < S >, UnaryBlockOperator < S , T > > convert ( final T targetType , Supplier < Converter < ? super S , T > > converterSupplier )
146
+ {
147
+ return s -> createOperator ( s .getType (), targetType , converterSupplier );
148
+ }
149
+
62
150
/**
63
151
* Create {@link UnaryBlockOperator} to convert blocks between {@code
64
152
* sourceType} and {@code targetType}.
65
153
* No clamping.
66
154
*/
67
155
public static < S extends NativeType < S >, T extends NativeType < T > >
68
- UnaryBlockOperator < S , T > convert ( final S sourceType , final T targetType )
156
+ UnaryBlockOperator < S , T > createOperator ( final S sourceType , final T targetType )
69
157
{
70
- return convert ( sourceType , targetType , ClampType .NONE );
158
+ return createOperator ( sourceType , targetType , ClampType .NONE );
71
159
}
72
160
73
161
/**
@@ -76,7 +164,7 @@ UnaryBlockOperator< S, T > convert( final S sourceType, final T targetType )
76
164
* Clamp target values according to {@code clamp}.
77
165
*/
78
166
public static < S extends NativeType < S >, T extends NativeType < T > >
79
- UnaryBlockOperator < S , T > convert ( final S sourceType , final T targetType , final ClampType clamp )
167
+ UnaryBlockOperator < S , T > createOperator ( final S sourceType , final T targetType , final ClampType clamp )
80
168
{
81
169
return new DefaultUnaryBlockOperator <>(
82
170
sourceType , targetType , 0 , 0 ,
@@ -88,7 +176,7 @@ UnaryBlockOperator< S, T > convert( final S sourceType, final T targetType, fina
88
176
* sourceType} and {@code targetType} with the specified {@code Converter}.
89
177
*/
90
178
public static < S extends NativeType < S >, T extends NativeType < T > >
91
- UnaryBlockOperator < S , T > convert ( final S sourceType , final T targetType , Supplier < Converter < ? super S , T > > converterSupplier )
179
+ UnaryBlockOperator < S , T > createOperator ( final S sourceType , final T targetType , Supplier < Converter < ? super S , T > > converterSupplier )
92
180
{
93
181
return new DefaultUnaryBlockOperator <>(
94
182
sourceType , targetType , 0 , 0 ,
0 commit comments