@@ -3,11 +3,16 @@ import { tween } from "@thi.ng/transducers/tween";
3
3
import { setS4 } from "@thi.ng/vectors/sets" ;
4
4
import type { TypedColor } from "./api.js" ;
5
5
import type { GradientOpts } from "./api/gradients.js" ;
6
+ import { intArgb32Abgr32 } from "./int/int-int.js" ;
7
+ import { argb32 } from "./int/int.js" ;
6
8
import { mix as $mix } from "./mix.js" ;
7
9
8
10
/**
9
11
* Similar to {@link multiCosineGradient}, but using any number of gradient
10
- * color stops and isn't limited to RGB, but for arbitrary color types.
12
+ * color stops and isn't limited to RGB, but for arbitrary color types. The
13
+ * optional `isABGR` boolean arg can be used to autoconvert resulting colors
14
+ * into packed ARGB (false) or ABGR (true) integers. If that arg is given, an
15
+ * array of numbers will be returned.
11
16
*
12
17
* @remarks
13
18
* @see {@link @thi.ng/transducers#tween }
@@ -41,11 +46,25 @@ import { mix as $mix } from "./mix.js";
41
46
* );
42
47
* ```
43
48
*
44
- * @param opts -
49
+ * @param opts -
50
+ * @param isABGR -
45
51
*/
46
- export const multiColorGradient = < T extends TypedColor < any > > (
52
+ export function multiColorGradient < T extends TypedColor < any > > (
47
53
opts : GradientOpts < T >
48
- ) => [ ...gradient ( opts ) ] ;
54
+ ) : T [ ] ;
55
+ export function multiColorGradient < T extends TypedColor < any > > (
56
+ opts : GradientOpts < T > ,
57
+ isABGR : boolean
58
+ ) : number [ ] ;
59
+ export function multiColorGradient < T extends TypedColor < any > > (
60
+ opts : GradientOpts < T > ,
61
+ isABGR ?: boolean
62
+ ) {
63
+ const cols = [ ...gradient ( opts ) ] ;
64
+ if ( isABGR === undefined ) return cols ;
65
+ const rgba = cols . map ( ( x ) => argb32 ( x ) [ 0 ] ) ;
66
+ return isABGR ? rgba . map ( intArgb32Abgr32 ) : rgba ;
67
+ }
49
68
50
69
/**
51
70
* Similar to {@link multiColorGradient}, but writes results into `buffer` from
@@ -55,7 +74,7 @@ export const multiColorGradient = <T extends TypedColor<any>>(
55
74
* Intended use case for this function: 1D texturemap/tonemap generation, e.g.
56
75
* for dataviz etc. Also @see {@link cosineGradientBuffer}.
57
76
*
58
- * @param opts -
77
+ * @param opts -
59
78
* @param buffer - target buffer/array
60
79
* @param offset - start index (default: 0)
61
80
* @param cstride - channel stride (default: 1)
0 commit comments