From a4ba0219a08eb7910445f1b3d44e62f9d7ca8957 Mon Sep 17 00:00:00 2001 From: dank074 Date: Wed, 8 Dec 2021 01:06:27 -0600 Subject: [PATCH] simplify palette filter --- src/core/utils/PaletteMapFilter.ts | 28 +++------------------------- src/nitro/avatar/AvatarImage.ts | 2 +- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/src/core/utils/PaletteMapFilter.ts b/src/core/utils/PaletteMapFilter.ts index 77241737..604aff32 100644 --- a/src/core/utils/PaletteMapFilter.ts +++ b/src/core/utils/PaletteMapFilter.ts @@ -48,27 +48,13 @@ export class PaletteMapFilter extends NitroFilter private _lut: NitroBaseTexture; private _channel: number; - constructor(reds: number[], greens: number[], blues: number[], alphas: number[]) + constructor(palette: number[], channel = PaletteMapFilter.CHANNEL_RED) { super(vertex, fragment); - this._channel = this.getChannelForPalette(reds, greens, blues, alphas); + this._channel = channel; let lut: number[] = []; - switch(this._channel) - { - case (PaletteMapFilter.CHANNEL_RED): - lut = this.getLutForPalette(reds); - break; - case (PaletteMapFilter.CHANNEL_GREEN): - lut = this.getLutForPalette(greens); - break; - case (PaletteMapFilter.CHANNEL_BLUE): - lut = this.getLutForPalette(blues); - break; - case (PaletteMapFilter.CHANNEL_ALPHA): - lut = this.getLutForPalette(alphas); - break; - } + lut = this.getLutForPalette(palette); this._lut = NitroBaseTexture.fromBuffer(Uint8Array.from(lut), lut.length / 4, 1, { mipmap: 0, scaleMode: 0 }); @@ -95,14 +81,6 @@ export class PaletteMapFilter extends NitroFilter return lut; } - private getChannelForPalette(reds: number[], greens: number[], blues: number[], alphas: number[]): number - { - if(reds.length === 256) return PaletteMapFilter.CHANNEL_RED; - if(greens.length === 256) return PaletteMapFilter.CHANNEL_GREEN; - if(blues.length === 256) return PaletteMapFilter.CHANNEL_BLUE; - if(alphas.length === 256) return PaletteMapFilter.CHANNEL_ALPHA; - } - public get lut(): NitroBaseTexture { return this._lut; diff --git a/src/nitro/avatar/AvatarImage.ts b/src/nitro/avatar/AvatarImage.ts index 8a126047..b1fccede 100644 --- a/src/nitro/avatar/AvatarImage.ts +++ b/src/nitro/avatar/AvatarImage.ts @@ -396,7 +396,7 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener { this.convertToGrayscale(container); - container.filters.push(new PaletteMapFilter(this._avatarSpriteData.reds, [], [], [])); + container.filters.push(new PaletteMapFilter(this._avatarSpriteData.reds, PaletteMapFilter.CHANNEL_RED)); } if(!cache)