@@ -8,14 +8,18 @@ import type { ZarrPixelSource } from "../ZarrPixelSource";
8
8
9
9
type Texture = ReturnType < BitmapLayer [ "context" ] [ "device" ] [ "createTexture" ] > ;
10
10
11
- export type OmeColors = Readonly < Record < number , readonly [ number , number , number , number ] > > ;
11
+ export type OmeColor = Readonly < {
12
+ labelValue : number ;
13
+ rgba : readonly [ r : number , g : number , b : number , a : number ] ;
14
+ } > ;
15
+
12
16
export interface LabelLayerProps {
13
17
id : string ;
14
18
loader : Array < ZarrPixelSource > ;
15
19
selection : Array < number > ;
16
20
opacity : number ;
17
21
modelMatrix : Matrix4 ;
18
- colors ?: OmeColors ;
22
+ colors ?: ReadonlyArray < OmeColor > ;
19
23
}
20
24
21
25
/**
@@ -237,7 +241,7 @@ function getTileSizeForResolutions(resolutions: Array<ZarrPixelSource>): number
237
241
return tileSize ;
238
242
}
239
243
240
- const SEEN_LUTS = new WeakSet < OmeColors > ( ) ;
244
+ const SEEN_LUTS = new WeakSet < ReadonlyArray < OmeColor > > ( ) ;
241
245
242
246
/**
243
247
* Creates a color lookup table (LUT) as a 2D texture.
@@ -246,7 +250,7 @@ const SEEN_LUTS = new WeakSet<OmeColors>();
246
250
* @param options.maxTextureDimension2D - The maximum texture dimension size.
247
251
*/
248
252
function createColorTexture ( options : {
249
- source ?: OmeColors ;
253
+ source ?: ReadonlyArray < OmeColor > ;
250
254
maxTextureDimension2D : number ;
251
255
} ) {
252
256
const { source, maxTextureDimension2D } = options ;
@@ -261,7 +265,7 @@ function createColorTexture(options: {
261
265
}
262
266
263
267
// pack the colors into a 2D texture
264
- const size = Math . max ( ...Object . keys ( source ) . map ( Number ) ) + 1 ;
268
+ const size = Math . max ( ...source . map ( ( e ) => e . labelValue ) ) + 1 ;
265
269
const width = Math . min ( size , maxTextureDimension2D ) ;
266
270
const height = Math . ceil ( size / width ) ;
267
271
@@ -274,15 +278,14 @@ function createColorTexture(options: {
274
278
}
275
279
276
280
const data = new Uint8Array ( width * height * 4 ) ;
277
- for ( const [ key , [ r , g , b , a ] ] of Object . entries ( source ) ) {
278
- const index = + key ;
279
- const x = index % width ;
280
- const y = Math . floor ( index / width ) ;
281
+ for ( const { labelValue, rgba } of source ) {
282
+ const x = labelValue % width ;
283
+ const y = Math . floor ( labelValue / width ) ;
281
284
const texIndex = ( y * width + x ) * 4 ;
282
- data [ texIndex ] = r ;
283
- data [ texIndex + 1 ] = g ;
284
- data [ texIndex + 2 ] = b ;
285
- data [ texIndex + 3 ] = a ;
285
+ data [ texIndex ] = rgba [ 0 ] ;
286
+ data [ texIndex + 1 ] = rgba [ 1 ] ;
287
+ data [ texIndex + 2 ] = rgba [ 2 ] ;
288
+ data [ texIndex + 3 ] = rgba [ 3 ] ;
286
289
}
287
290
288
291
return { data, width, height } ;
@@ -340,7 +343,7 @@ const COLOR_PALETTES = {
340
343
] ,
341
344
} as const ;
342
345
343
- const DEFAULT_COLOR_TEXTURE = Uint8Array . from ( COLOR_PALETTES . pathology . flatMap ( ( color ) => [ ...color , 255 ] ) ) ;
346
+ const DEFAULT_COLOR_TEXTURE = Uint8Array . from ( COLOR_PALETTES . pathologyLarge . flatMap ( ( color ) => [ ...color , 255 ] ) ) ;
344
347
345
348
function typedArrayConstructorName ( arr : zarr . TypedArray < LabelDataType > ) {
346
349
const ArrayType = arr . constructor as zarr . TypedArrayConstructor < LabelDataType > ;
0 commit comments