From 31fc2b714c6405470e03173918a2bf3a6cfbec1e Mon Sep 17 00:00:00 2001 From: dank074 Date: Tue, 31 Aug 2021 15:53:45 -0500 Subject: [PATCH] fixed effect 11 and 12 --- src/nitro/avatar/AvatarImage.ts | 35 +++++++++++-- .../avatar/animation/AvatarDataContainer.ts | 51 +++++++++---------- 2 files changed, 55 insertions(+), 31 deletions(-) diff --git a/src/nitro/avatar/AvatarImage.ts b/src/nitro/avatar/AvatarImage.ts index 3bc44f3e..7ab3389e 100644 --- a/src/nitro/avatar/AvatarImage.ts +++ b/src/nitro/avatar/AvatarImage.ts @@ -419,7 +419,7 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener { if(this._avatarSpriteData.paletteIsGrayscale) { - this._reusableTexture = this.applyPalette(this._reusableTexture, this._avatarSpriteData.reds); + this._reusableTexture = this.applyPalette(this._reusableTexture, this._avatarSpriteData.reds, [], []); } } @@ -431,7 +431,7 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener public applyPalette(texture: RenderTexture, reds: number[] = [], greens: number[] = [], blues: number[] = []): RenderTexture { - console.log(reds); + const textureCanvas = TextureUtils.generateCanvas(texture); const textureCtx = textureCanvas.getContext('2d'); const textureImageData = textureCtx.getImageData(0, 0, textureCanvas.width, textureCanvas.height); @@ -439,10 +439,35 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener for(let i = 0; i < data.length; i += 4) { - let paletteColor = (reds[ data[i] ]); - if(paletteColor === undefined) paletteColor = 0; + if(reds.length == 256) + { + let paletteColor = reds[ data[i] ]; + if(paletteColor === undefined) paletteColor = 0; + + data[ i ] = ((paletteColor >> 16) & 0xFF); + data[ i + 1] = ((paletteColor >> 8) & 0xFF); + data[ i + 2] = (paletteColor & 0xFF); + } + + if(greens.length == 256) + { + let paletteColor = greens[ data[i + 1] ]; + if(paletteColor === undefined) paletteColor = 0; + + data[ i ] = ((paletteColor >> 16) & 0xFF); + data[ i + 1] = ((paletteColor >> 8) & 0xFF); + data[ i + 2] = (paletteColor & 0xFF); + } + if(blues.length == 256) + { + let paletteColor = greens[ data[i + 2] ]; + if(paletteColor === undefined) paletteColor = 0; + + data[ i ] = ((paletteColor >> 16) & 0xFF); + data[ i + 1] = ((paletteColor >> 8) & 0xFF); + data[ i + 2] = (paletteColor & 0xFF); + } - data[ i ] = ((paletteColor >> 16)); } textureCtx.putImageData(textureImageData, 0, 0); diff --git a/src/nitro/avatar/animation/AvatarDataContainer.ts b/src/nitro/avatar/animation/AvatarDataContainer.ts index d587ca7b..cac32397 100644 --- a/src/nitro/avatar/animation/AvatarDataContainer.ts +++ b/src/nitro/avatar/animation/AvatarDataContainer.ts @@ -86,45 +86,44 @@ export class AvatarDataContainer implements IAvatarDataContainer return this._paletteIsGrayscale; } - private generatePaletteMapForGrayscale(k: number, _arg_2: number): Map + private generatePaletteMapForGrayscale(background: number, foreground: number): Map { - const _local_3 = ((k >> 24) & 0xFF); - const _local_4 = ((k >> 16) & 0xFF); - const _local_5 = ((k >> 8) & 0xFF); - const _local_6 = ((k >> 0) & 0xFF); - const _local_7 = ((_arg_2 >> 24) & 0xFF); - const _local_8 = ((_arg_2 >> 16) & 0xFF); - const _local_9 = ((_arg_2 >> 8) & 0xFF); - const _local_10 = ((_arg_2 >> 0) & 0xFF); - const _local_11 = ((_local_7 - _local_3) / 0xFF); - const _local_12 = ((_local_8 - _local_4) / 0xFF); - const _local_13 = ((_local_9 - _local_5) / 0xFF); - const _local_14 = ((_local_10 - _local_6) / 0xFF); + const alphaBackground = ((background >> 24) & 0xFF); + const redBackground = ((background >> 16) & 0xFF); + const greenBackground = ((background >> 8) & 0xFF); + const blueBackground = ((background >> 0) & 0xFF); + const alphaForeground = ((foreground >> 24) & 0xFF); + const redForeground = ((foreground >> 16) & 0xFF); + const greenForeground = ((foreground >> 8) & 0xFF); + const blueForeground = ((foreground >> 0) & 0xFF); + const alphaDifference = ((alphaForeground - alphaBackground) / 0xFF); + const redDifference = ((redForeground - redBackground) / 0xFF); + const greenDifference = ((greenForeground - greenBackground) / 0xFF); + const blueDifference = ((blueForeground - blueBackground) / 0xFF); const _local_15: Map = new Map(); const _local_16: number[] = []; const _local_17: number[] = []; const _local_18: number[] = []; const _local_19: number[] = []; - let _local_20 = _local_3; - let _local_21 = _local_4; - let _local_22 = _local_5; - let _local_23 = _local_6; - let _local_24 = 0; - while(_local_24 < 0x0100) + let _local_20 = alphaBackground; + let _local_21 = redBackground; + let _local_22 = greenBackground; + let _local_23 = blueBackground; + + for(let i = 0; i < 256; i++) { - if((((_local_21 == _local_4) && (_local_22 == _local_5)) && (_local_23 == _local_6))) + if((((_local_21 == redBackground) && (_local_22 == greenBackground)) && (_local_23 == blueBackground))) { _local_20 = 0; } - _local_20 = (_local_20 + _local_11); - _local_21 = (_local_21 + _local_12); - _local_22 = (_local_22 + _local_13); - _local_23 = (_local_23 + _local_14); + _local_20 = (_local_20 + alphaDifference); + _local_21 = (_local_21 + redDifference); + _local_22 = (_local_22 + greenDifference); + _local_23 = (_local_23 + blueDifference); _local_19.push((_local_20 << 24)); - _local_16.push((((((_local_20 << 24) | (_local_21 << 16)) | (_local_22 << 8)) | _local_23))); + _local_16.push(((((_local_20 << 24) | (_local_21 << 16)) | (_local_22 << 8)) | _local_23)); _local_17.push(((((_local_20 << 24) | (_local_21 << 16)) | (_local_22 << 8)) | _local_23)); _local_18.push(((((_local_20 << 24) | (_local_21 << 16)) | (_local_22 << 8)) | _local_23)); - _local_24++; } _local_15.set('alphas', _local_16);