11
22import { describe , expect , test } from "vitest" ;
3- import { renderChunk , renderChunkWithLUT } from "../src/render.ts" ;
3+ import {
4+ renderChunk ,
5+ renderChunkWithLUT ,
6+ renderChunkWithColormap ,
7+ renderChunks } from "../src/render.ts" ;
8+ import { FILL_VALUE_KEY } from "../src/utils.ts" ;
9+
10+
11+ test ( "renderChunks" , async ( ) => {
12+
13+ let fakeChunk = { shape : [ 2 , 3 ] , data : [ 0 , 1 , 2 , 3 , 4 , 5 ] } ;
14+ let colors = [ [ 255 , 0 , 0 ] , [ 0 , 255 , 0 ] , [ 0 , 0 , 255 ] ] ;
15+ let rendered = renderChunks (
16+ [ fakeChunk , fakeChunk , fakeChunk ] ,
17+ [ [ 0 , 3 ] , [ 0 , 6 ] , [ 0 , 9 ] ] , // ranges
18+ colors
19+ ) ;
20+
21+ let expected = new Uint8ClampedArray ( [
22+ 0 , 0 , 0 , 255 ,
23+ 85 , 43 , 28 , 255 ,
24+ 170 , 85 , 57 , 255 ,
25+ 255 , 128 , 85 , 255 ,
26+ 255 , 170 , 113 , 255 ,
27+ 255 , 213 , 142 , 255 ,
28+ ] ) ;
29+ expect ( rendered ) . toStrictEqual ( expected ) ;
30+ } ) ;
431
532
633test ( "renderChunk" , async ( ) => {
@@ -20,7 +47,7 @@ test("renderChunk", async () => {
2047
2148
2249test ( "renderChunkWithLUT" , async ( ) => {
23-
50+
2451 let fakeChunk = { shape : [ 3 , 3 ] , data : [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] } ;
2552 let transparent = [ 0 , 0 , 0 , 0 ] ;
2653 let red = [ 255 , 0 , 0 ] ;
@@ -53,7 +80,6 @@ test("renderChunkWithLUTrange", async () => {
5380
5481 // with range, values are scaled to the LUT range
5582 let rendered = renderChunkWithLUT ( fakeChunk , lut , { range : [ 0 , 8 ] } ) ;
56- console . log ( "rendered" , rendered ) ;
5783
5884 let expected = new Uint8ClampedArray ( [
5985 0 , 0 , 0 , 255 ,
@@ -69,3 +95,36 @@ test("renderChunkWithLUTrange", async () => {
6995 expect ( rendered ) . toStrictEqual ( expected ) ;
7096} ) ;
7197
98+
99+ test ( "renderChunkWithColormap" , async ( ) => {
100+
101+ let fakeChunk = { shape : [ 2 , 3 ] , data : [ 0 , 1 , 2 , 3 , 4 , 5 ] } ;
102+ let colorMap = new Map ( ) ;
103+ colorMap . set ( 0 , [ 0 , 0 , 0 , 255 ] ) ;
104+ colorMap . set ( 1 , [ 255 , 0 , 0 , 255 ] ) ;
105+ colorMap . set ( 2 , [ 0 , 255 , 0 , 255 ] ) ;
106+
107+ // default fill value is [0, 0, 0, 0]
108+ let rendered = renderChunkWithColormap ( fakeChunk , colorMap ) ;
109+ let expected = new Uint8ClampedArray ( [
110+ 0 , 0 , 0 , 255 ,
111+ 255 , 0 , 0 , 255 ,
112+ 0 , 255 , 0 , 255 ,
113+ 0 , 0 , 0 , 0 , // default fill value
114+ 0 , 0 , 0 , 0 ,
115+ 0 , 0 , 0 , 0 ,
116+ ] ) ;
117+ expect ( rendered ) . toStrictEqual ( expected ) ;
118+
119+ // custom fill value
120+ rendered = renderChunkWithColormap ( fakeChunk , colorMap , { fillValue : [ 255 , 255 , 255 , 255 ] } ) ;
121+ expected = new Uint8ClampedArray ( [
122+ 0 , 0 , 0 , 255 ,
123+ 255 , 0 , 0 , 255 ,
124+ 0 , 255 , 0 , 255 ,
125+ 255 , 255 , 255 , 255 , // new fill value
126+ 255 , 255 , 255 , 255 ,
127+ 255 , 255 , 255 , 255 ,
128+ ] ) ;
129+ expect ( rendered ) . toStrictEqual ( expected ) ;
130+ } ) ;
0 commit comments