mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2025-01-31 03:12:35 +01:00
simplify palette filter
This commit is contained in:
parent
17d1e300cb
commit
a4ba0219a0
@ -48,27 +48,13 @@ export class PaletteMapFilter extends NitroFilter
|
|||||||
private _lut: NitroBaseTexture;
|
private _lut: NitroBaseTexture;
|
||||||
private _channel: number;
|
private _channel: number;
|
||||||
|
|
||||||
constructor(reds: number[], greens: number[], blues: number[], alphas: number[])
|
constructor(palette: number[], channel = PaletteMapFilter.CHANNEL_RED)
|
||||||
{
|
{
|
||||||
super(vertex, fragment);
|
super(vertex, fragment);
|
||||||
this._channel = this.getChannelForPalette(reds, greens, blues, alphas);
|
this._channel = channel;
|
||||||
let lut: number[] = [];
|
let lut: number[] = [];
|
||||||
|
|
||||||
switch(this._channel)
|
lut = this.getLutForPalette(palette);
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._lut = NitroBaseTexture.fromBuffer(Uint8Array.from(lut), lut.length / 4, 1, { mipmap: 0, scaleMode: 0 });
|
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;
|
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
|
public get lut(): NitroBaseTexture
|
||||||
{
|
{
|
||||||
return this._lut;
|
return this._lut;
|
||||||
|
@ -396,7 +396,7 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener
|
|||||||
{
|
{
|
||||||
this.convertToGrayscale(container);
|
this.convertToGrayscale(container);
|
||||||
|
|
||||||
container.filters.push(new PaletteMapFilter(this._avatarSpriteData.reds, [], [], []));
|
container.filters.push(new PaletteMapFilter(this._avatarSpriteData.reds, PaletteMapFilter.CHANNEL_RED));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!cache)
|
if(!cache)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user