From b9c3f8db4fddf294dc0cf178852611813c0c559a Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 11 May 2012 02:05:24 +0000 Subject: [PATCH] - Added a new patch style: CopyNewAlpha. This works just like Copy except it multiplies each pixel's alpha channel by the specified Alpha property. SVN r3637 (trunk) --- src/textures/bitmap.cpp | 111 ++++++----------------------- src/textures/bitmap.h | 27 ++++--- src/textures/multipatchtexture.cpp | 2 +- 3 files changed, 41 insertions(+), 99 deletions(-) diff --git a/src/textures/bitmap.cpp b/src/textures/bitmap.cpp index 4da12b9c35..cf419d70da 100644 --- a/src/textures/bitmap.cpp +++ b/src/textures/bitmap.cpp @@ -185,96 +185,30 @@ void iCopyColors(BYTE *pout, const BYTE *pin, int count, int step, FCopyInfo *in typedef void (*CopyFunc)(BYTE *pout, const BYTE *pin, int count, int step, FCopyInfo *inf); +#define COPY_FUNCS(op) \ + { \ + iCopyColors, \ + iCopyColors, \ + iCopyColors, \ + iCopyColors, \ + iCopyColors, \ + iCopyColors, \ + iCopyColors, \ + iCopyColors, \ + iCopyColors \ + } static const CopyFunc copyfuncs[][9]={ - { - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors - }, - { - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors - }, - { - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors - }, - { - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors - }, - { - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors - }, - { - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors - }, - { - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors - }, - { - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors - }, + COPY_FUNCS(bCopy), + COPY_FUNCS(bBlend), + COPY_FUNCS(bAdd), + COPY_FUNCS(bSubtract), + COPY_FUNCS(bReverseSubtract), + COPY_FUNCS(bModulate), + COPY_FUNCS(bCopyAlpha), + COPY_FUNCS(bCopyNewAlpha), + COPY_FUNCS(bOverwrite) }; +#undef COPY_FUNCS //=========================================================================== // @@ -487,6 +421,7 @@ static const CopyPalettedFunc copypalettedfuncs[]= iCopyPaletted, iCopyPaletted, iCopyPaletted, + iCopyPaletted, iCopyPaletted }; diff --git a/src/textures/bitmap.h b/src/textures/bitmap.h index da039fd0f8..dc125bf87e 100644 --- a/src/textures/bitmap.h +++ b/src/textures/bitmap.h @@ -318,6 +318,7 @@ enum ECopyOp OP_REVERSESUBTRACT, OP_MODULATE, OP_COPYALPHA, + OP_COPYNEWALPHA, OP_OVERWRITE }; @@ -330,6 +331,13 @@ struct FCopyInfo fixed_t invalpha; }; +struct bOverwrite +{ + static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = s; } + static __forceinline void OpA(BYTE &d, BYTE s, FCopyInfo *i) { d = s; } + static __forceinline bool ProcessAlpha0() { return true; } +}; + struct bCopy { static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = s; } @@ -337,11 +345,18 @@ struct bCopy static __forceinline bool ProcessAlpha0() { return false; } }; -struct bOverwrite +struct bCopyNewAlpha { static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = s; } + static __forceinline void OpA(BYTE &d, BYTE s, FCopyInfo *i) { d = (s*i->alpha) >> FRACBITS; } + static __forceinline bool ProcessAlpha0() { return false; } +}; + +struct bCopyAlpha +{ + static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = (s*a + d*(255-a))/255; } static __forceinline void OpA(BYTE &d, BYTE s, FCopyInfo *i) { d = s; } - static __forceinline bool ProcessAlpha0() { return true; } + static __forceinline bool ProcessAlpha0() { return false; } }; struct bBlend @@ -379,13 +394,5 @@ struct bModulate static __forceinline bool ProcessAlpha0() { return false; } }; -struct bCopyAlpha -{ - static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = (s*a + d*(255-a))/255; } - static __forceinline void OpA(BYTE &d, BYTE s, FCopyInfo *i) { d = s; } - static __forceinline bool ProcessAlpha0() { return false; } -}; - - #endif diff --git a/src/textures/multipatchtexture.cpp b/src/textures/multipatchtexture.cpp index c1fc95492a..5799ad04ea 100644 --- a/src/textures/multipatchtexture.cpp +++ b/src/textures/multipatchtexture.cpp @@ -1180,7 +1180,7 @@ void FMultiPatchTexture::ParsePatch(FScanner &sc, TexPart & part, bool silent, i } else if (sc.Compare("style")) { - static const char *styles[] = {"copy", "translucent", "add", "subtract", "reversesubtract", "modulate", "copyalpha", NULL }; + static const char *styles[] = {"copy", "translucent", "add", "subtract", "reversesubtract", "modulate", "copyalpha", "copynewalpha", NULL }; sc.MustGetString(); part.op = sc.MustMatchString(styles); bComplex |= (part.op != OP_COPY);