Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/sun/java2d/loops/AlphaMath.h
38918 views
/*1* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#ifndef AlphaMath_h_Included26#define AlphaMath_h_Included2728extern unsigned char mul8table[256][256];29extern unsigned char div8table[256][256];30extern void initAlphaTables();313233/*34* Multiply and Divide macros for single byte (8-bit) quantities representing35* the values 0.0 to 1.0 as 0x00 to 0xff.36* MUL8 multiplies its operands together37* DIV8 divides the first operand by the second, clipping to 0xff38* (Note that since the divisor for DIV8 is likely to be39* the alpha quantity which is likely to be the same for40* multiple adjacent invocations, the table is designed41* with the first index being the divisor to hopefully42* improve memory cache hits...)43*/44#define MUL8(a,b) mul8table[a][b]45#define DIV8(a,b) div8table[b][a]4647/*48* Multiply and Divide macros for operations involving a single short (16-bit)49* quantity and a single byte (8-bit) quantity. Typically, promoting the50* 8-bit value to 16 bits would lead to overflow when the operation occurs.51* These macros have been modified somewhat so that overflow will not occur.52* MUL8_16 multiplies an 8-bit value by a 16-bit value (the order of operands53* is unimportant since multiplication is a commutative operation)54* DIV16_8 divides the first (16-bit) operand by the second (8-bit) value55*/5657#define MUL8_16(a,b) (((a) * (b)) / 255)58#define DIV16_8(a,b) (((a) * 255) / (b))5960/*61* Multiply and Divide macros for single short (16-bit) quantities62* representing the values 0.0 to 1.0 as 0x0000 to 0xffff.63* MUL16 multiplies its operands using the standard multiplication operator64* and normalizes the result to the appropriate range65* DIV16 divides the first operand by the second and normalizes the result66* to a 16-bit value67*/68#define MUL16(a,b) (((a) * (b)) / 65535)69#define DIV16(a,b) (((a) * 65535) / (b))7071/*72* Macro for the sum of two normalized (16-bit) products. Refer to the73* following equation and note that the right side reduces the number of74* divide operations in the left side and increases the precision of the75* result:76* a*f1 + b*f2 a*f1 + b*f277* ---- ---- = ----------- (where n in this case will be 65535)78* n n n79*/80#define AddNormalizedProducts16(a, f1, b, f2) \81((((a) * (f1)) + ((b) * (f2))) / 65535)828384/*85* The following macros help to generalize the MaskBlit and MaskFill loops86* found in AlphaMacros.h. The appropriate macros will be used based on the87* strategy of the given loop. The strategy types take the form:88* <number of components per pixel><component data type><colorspace>89* For example, these are the current strategy types:90* 3ByteRgb (currently only used as a glyph list blending strategy where91* the alpha value itself is neither blended nor stored)92* 4ByteArgb (eg. IntArgb, ThreeByteBgr, Ushort555Rgb, ByteIndexed, etc.)93* 4ShortArgb (not used currently; could be used when surface types using94* 16 bits per component are implemented)95* 1ByteGray (eg. ByteGray)96* 1ShortGray (eg. UshortGray)97* Note that the macros which operate on alpha values have the word "Alpha"98* somewhere in their name. Those macros that only operate on the color/gray99* components of a given strategy will have the word "Components" or "Comps"100* in their name.101*/102103104/*105* MaxValFor ## STRATEGY106*/107#define MaxValFor4ByteArgb 0xff108#define MaxValFor1ByteGray 0xff109#define MaxValFor1ShortGray 0xffff110111112/*113* AlphaType ## STRATEGY114*/115#define AlphaType3ByteRgb jint116#define AlphaType4ByteArgb jint117#define AlphaType1ByteGray jint118#define AlphaType1ShortGray juint119120121/*122* ComponentType ## STRATEGY123*/124#define ComponentType3ByteRgb jint125#define ComponentType4ByteArgb jint126#define ComponentType1ByteGray jint127#define ComponentType1ShortGray juint128129130/*131* DeclareAlphaVarFor ## STRATEGY(VAR)132*133* jint a;134*/135#define DeclareAlphaVarFor3ByteRgb(VAR) \136AlphaType3ByteRgb VAR;137138#define DeclareAlphaVarFor4ByteArgb(VAR) \139AlphaType4ByteArgb VAR;140141#define DeclareAlphaVarFor1ByteGray(VAR) \142AlphaType1ByteGray VAR;143144#define DeclareAlphaVarFor1ShortGray(VAR) \145AlphaType1ShortGray VAR;146147148/*149* DeclareAndInitAlphaVarFor ## STRATEGY(VAR, initval)150*151* jint a = initval;152*/153#define DeclareAndInitAlphaVarFor4ByteArgb(VAR, initval) \154AlphaType4ByteArgb VAR = initval;155156#define DeclareAndInitAlphaVarFor1ByteGray(VAR, initval) \157AlphaType1ByteGray VAR = initval;158159#define DeclareAndInitAlphaVarFor1ShortGray(VAR, initval) \160AlphaType1ShortGray VAR = initval;161162163/*164* DeclareAndClearAlphaVarFor ## STRATEGY(VAR)165*166* jint a = 0;167*/168#define DeclareAndClearAlphaVarFor4ByteArgb(VAR) \169DeclareAndInitAlphaVarFor4ByteArgb(VAR, 0)170171#define DeclareAndClearAlphaVarFor1ByteGray(VAR) \172DeclareAndInitAlphaVarFor1ByteGray(VAR, 0)173174#define DeclareAndClearAlphaVarFor1ShortGray(VAR) \175DeclareAndInitAlphaVarFor1ShortGray(VAR, 0)176177178/*179* DeclareAndSetOpaqueAlphaVarFor ## STRATEGY(VAR)180*181* jint a = 0xff;182*/183#define DeclareAndSetOpaqueAlphaVarFor4ByteArgb(VAR) \184DeclareAndInitAlphaVarFor4ByteArgb(VAR, MaxValFor4ByteArgb)185186#define DeclareAndSetOpaqueAlphaVarFor1ByteGray(VAR) \187DeclareAndInitAlphaVarFor1ByteGray(VAR, MaxValFor1ByteGray)188189#define DeclareAndSetOpaqueAlphaVarFor1ShortGray(VAR) \190DeclareAndInitAlphaVarFor1ShortGray(VAR, MaxValFor1ShortGray)191192193/*194* DeclareAndInvertAlphaVarFor ## STRATEGY(VAR, invalpha)195*196* jint a = 0xff - resA;197*/198#define DeclareAndInvertAlphaVarFor4ByteArgb(VAR, invalpha) \199DeclareAndInitAlphaVarFor4ByteArgb(VAR, MaxValFor4ByteArgb - invalpha)200201#define DeclareAndInvertAlphaVarFor1ByteGray(VAR, invalpha) \202DeclareAndInitAlphaVarFor1ByteGray(VAR, MaxValFor1ByteGray - invalpha)203204#define DeclareAndInvertAlphaVarFor1ShortGray(VAR, invalpha) \205DeclareAndInitAlphaVarFor1ShortGray(VAR, MaxValFor1ShortGray - invalpha)206207208/*209* DeclareCompVarsFor ## STRATEGY(PREFIX)210*211* jint c;212*/213#define DeclareCompVarsFor3ByteRgb(PREFIX) \214ComponentType3ByteRgb PREFIX ## R, PREFIX ## G, PREFIX ## B;215216#define DeclareCompVarsFor4ByteArgb(PREFIX) \217ComponentType4ByteArgb PREFIX ## R, PREFIX ## G, PREFIX ## B;218219#define DeclareCompVarsFor1ByteGray(PREFIX) \220ComponentType1ByteGray PREFIX ## G;221222#define DeclareCompVarsFor1ShortGray(PREFIX) \223ComponentType1ShortGray PREFIX ## G;224225226/*227* DeclareAndInitExtraAlphaFor ## STRATEGY(VAR)228*229* jint extraA = (int)(pCompInfo->details.extraAlpha * 255.0 + 0.5);230*/231#define DeclareAndInitExtraAlphaFor4ByteArgb(VAR) \232AlphaType4ByteArgb VAR = \233(AlphaType4ByteArgb)(pCompInfo->details.extraAlpha * 255.0 + 0.5);234235#define DeclareAndInitExtraAlphaFor1ByteGray(VAR) \236AlphaType1ByteGray VAR = \237(AlphaType1ByteGray)(pCompInfo->details.extraAlpha * 255.0 + 0.5);238239#define DeclareAndInitExtraAlphaFor1ShortGray(VAR) \240AlphaType1ShortGray VAR = \241(AlphaType1ShortGray)(pCompInfo->details.extraAlpha * 65535.0 + 0.5);242243244/*245* PromoteByteAlphaFor ## STRATEGY(a)246*/247#define PromoteByteAlphaFor4ByteArgb(a)248#define PromoteByteAlphaFor1ByteGray(a)249#define PromoteByteAlphaFor1ShortGray(a) \250(a) = (((a) << 8) + (a))251252253/*254* DeclareAndInitPathAlphaFor ## STRATEGY(VAR)255*256* jint pathA = *pMask++;257*/258#define DeclareAndInitPathAlphaFor4ByteArgb(VAR) \259AlphaType4ByteArgb VAR = *pMask++;260261#define DeclareAndInitPathAlphaFor1ByteGray(VAR) \262AlphaType1ByteGray VAR = *pMask++;263264#define DeclareAndInitPathAlphaFor1ShortGray(VAR) \265AlphaType1ShortGray VAR = *pMask++;266267268/*269* MultiplyAlphaFor ## STRATEGY(a, b)270*271* a * b272*/273#define MultiplyAlphaFor4ByteArgb(a, b) \274MUL8(a, b)275276#define MultiplyAlphaFor1ByteGray(a, b) \277MUL8(a, b)278279#define MultiplyAlphaFor1ShortGray(a, b) \280MUL16(a, b)281282283/*284* MultiplyAndStore ## STRATEGY ## Comps(PROD_PREFIX, M1, M2_PREFIX)285*286* c = m1 * m2;287*/288#define MultiplyAndStore3Components(PROD_PREFIX, M1, M2_PREFIX, PRECISION) \289do { \290PROD_PREFIX ## R = MUL ## PRECISION(M1, M2_PREFIX ## R); \291PROD_PREFIX ## G = MUL ## PRECISION(M1, M2_PREFIX ## G); \292PROD_PREFIX ## B = MUL ## PRECISION(M1, M2_PREFIX ## B); \293} while (0)294295#define MultiplyAndStore1Component(PROD_PREFIX, M1, M2_PREFIX, PRECISION) \296PROD_PREFIX ## G = MUL ## PRECISION(M1, M2_PREFIX ## G)297298#define MultiplyAndStore4ByteArgbComps(PROD_PREFIX, M1, M2_PREFIX) \299MultiplyAndStore3Components(PROD_PREFIX, M1, M2_PREFIX, 8)300301#define MultiplyAndStore1ByteGrayComps(PROD_PREFIX, M1, M2_PREFIX) \302MultiplyAndStore1Component(PROD_PREFIX, M1, M2_PREFIX, 8)303304#define MultiplyAndStore1ShortGrayComps(PROD_PREFIX, M1, M2_PREFIX) \305MultiplyAndStore1Component(PROD_PREFIX, M1, M2_PREFIX, 16)306307308/*309* DivideAndStore ## STRATEGY ## Comps(QUOT_PREFIX, D1_PREFIX, D2)310*311* c = d1 / d2;312*/313#define DivideAndStore3Components(QUOT_PREFIX, D1_PREFIX, D2, PRECISION) \314do { \315QUOT_PREFIX ## R = DIV ## PRECISION(D1_PREFIX ## R, D2); \316QUOT_PREFIX ## G = DIV ## PRECISION(D1_PREFIX ## G, D2); \317QUOT_PREFIX ## B = DIV ## PRECISION(D1_PREFIX ## B, D2); \318} while (0)319320#define DivideAndStore1Component(QUOT_PREFIX, D1_PREFIX, D2, PRECISION) \321QUOT_PREFIX ## G = DIV ## PRECISION(D1_PREFIX ## G, D2)322323#define DivideAndStore4ByteArgbComps(QUOT_PREFIX, D1_PREFIX, D2) \324DivideAndStore3Components(QUOT_PREFIX, D1_PREFIX, D2, 8)325326#define DivideAndStore1ByteGrayComps(QUOT_PREFIX, D1_PREFIX, D2) \327DivideAndStore1Component(QUOT_PREFIX, D1_PREFIX, D2, 8)328329#define DivideAndStore1ShortGrayComps(QUOT_PREFIX, D1_PREFIX, D2) \330DivideAndStore1Component(QUOT_PREFIX, D1_PREFIX, D2, 16)331332333/*334* MultiplyAddAndStore ## STRATEGY ## Comps(RES_PREFIX, M1, \335* M2_PREFIX, A_PREFIX)336*337* c = (m1 * m2) + a;338*/339#define MultiplyAddAndStore3Components(RES_PREFIX, M1, M2_PREFIX, A_PREFIX, \340PRECISION) \341do { \342RES_PREFIX ## R = MUL ## PRECISION(M1, M2_PREFIX ## R) + \343A_PREFIX ## R; \344RES_PREFIX ## G = MUL ## PRECISION(M1, M2_PREFIX ## G) + \345A_PREFIX ## G; \346RES_PREFIX ## B = MUL ## PRECISION(M1, M2_PREFIX ## B) + \347A_PREFIX ## B; \348} while (0)349350#define MultiplyAddAndStore1Component(RES_PREFIX, M1, M2_PREFIX, A_PREFIX, \351PRECISION) \352RES_PREFIX ## G = MUL ## PRECISION(M1, M2_PREFIX ## G) + A_PREFIX ## G353354#define MultiplyAddAndStore4ByteArgbComps(RES_PREFIX, M1, M2_PREFIX, \355A_PREFIX) \356MultiplyAddAndStore3Components(RES_PREFIX, M1, M2_PREFIX, A_PREFIX, 8)357358#define MultiplyAddAndStore1ByteGrayComps(RES_PREFIX, M1, M2_PREFIX, \359A_PREFIX) \360MultiplyAddAndStore1Component(RES_PREFIX, M1, M2_PREFIX, A_PREFIX, 8)361362#define MultiplyAddAndStore1ShortGrayComps(RES_PREFIX, M1, M2_PREFIX, \363A_PREFIX) \364MultiplyAddAndStore1Component(RES_PREFIX, M1, M2_PREFIX, A_PREFIX, 16)365366367/*368* MultMultAddAndStore ## STRATEGY ## Comps(RES_PREFIX, M1, M2_PREFIX, \369* M3, M4_PREFIX)370*371* c = (m1 * m2) + (m3 * m4);372*/373#define MultMultAddAndStore3Components(RES_PREFIX, M1, M2_PREFIX, \374M3, M4_PREFIX, PRECISION) \375do { \376RES_PREFIX ## R = MUL ## PRECISION(M1, M2_PREFIX ## R) + \377MUL ## PRECISION(M3, M4_PREFIX ## R); \378RES_PREFIX ## G = MUL ## PRECISION(M1, M2_PREFIX ## G) + \379MUL ## PRECISION(M3, M4_PREFIX ## G); \380RES_PREFIX ## B = MUL ## PRECISION(M1, M2_PREFIX ## B) + \381MUL ## PRECISION(M3, M4_PREFIX ## B); \382} while (0)383384385#define MultMultAddAndStoreLCD3Components(RES_PREFIX, M1, M2_PREFIX, \386M3, M4_PREFIX, PRECISION) \387do { \388RES_PREFIX ## R = MUL ## PRECISION(M1 ## R, M2_PREFIX ## R) + \389MUL ## PRECISION(M3 ## R, M4_PREFIX ## R); \390RES_PREFIX ## G = MUL ## PRECISION(M1 ## G, M2_PREFIX ## G) + \391MUL ## PRECISION(M3 ## G, M4_PREFIX ## G); \392RES_PREFIX ## B = MUL ## PRECISION(M1 ## B, M2_PREFIX ## B) + \393MUL ## PRECISION(M3 ## B, M4_PREFIX ## B); \394} while (0)395396#define MultMultAddAndStore1Component(RES_PREFIX, M1, M2_PREFIX, \397M3, M4_PREFIX, PRECISION) \398RES_PREFIX ## G = MUL ## PRECISION(M1, M2_PREFIX ## G) + \399MUL ## PRECISION(M3, M4_PREFIX ## G)400401#define MultMultAddAndStore3ByteRgbComps(RES_PREFIX, M1, M2_PREFIX, \402M3, M4_PREFIX) \403MultMultAddAndStore3Components(RES_PREFIX, M1, M2_PREFIX, \404M3, M4_PREFIX, 8)405406#define MultMultAddAndStoreLCD3ByteRgbComps(RES_PREFIX, M1, M2_PREFIX, \407M3, M4_PREFIX) \408MultMultAddAndStoreLCD3Components(RES_PREFIX, M1, M2_PREFIX, \409M3, M4_PREFIX, 8)410411#define MultMultAddAndStore4ByteArgbComps(RES_PREFIX, M1, M2_PREFIX, \412M3, M4_PREFIX) \413MultMultAddAndStore3Components(RES_PREFIX, M1, M2_PREFIX, \414M3, M4_PREFIX, 8)415416#define MultMultAddAndStoreLCD4ByteArgbComps(RES_PREFIX, M1, M2_PREFIX, \417M3, M4_PREFIX) \418MultMultAddAndStoreLCD3Components(RES_PREFIX, M1, M2_PREFIX, \419M3, M4_PREFIX, 8)420421#define MultMultAddAndStore1ByteGrayComps(RES_PREFIX, M1, M2_PREFIX, \422M3, M4_PREFIX) \423MultMultAddAndStore1Component(RES_PREFIX, M1, M2_PREFIX, \424M3, M4_PREFIX, 8)425426#define MultMultAddAndStore1ShortGrayComps(RES_PREFIX, M1, M2_PREFIX, \427M3, M4_PREFIX) \428RES_PREFIX ## G = AddNormalizedProducts16(M1, M2_PREFIX ## G, \429M3, M4_PREFIX ## G)430431432/*433* Store ## STRATEGY ## CompsUsingOp(L_PREFIX, OP, R_PREFIX)434*435* l op r; // where op can be something like = or +=436*/437#define Store3ComponentsUsingOp(L_PREFIX, OP, R_PREFIX) \438do { \439L_PREFIX ## R OP R_PREFIX ## R; \440L_PREFIX ## G OP R_PREFIX ## G; \441L_PREFIX ## B OP R_PREFIX ## B; \442} while (0)443444#define Store1ComponentUsingOp(L_PREFIX, OP, R_PREFIX) \445L_PREFIX ## G OP R_PREFIX ## G446447#define Store4ByteArgbCompsUsingOp(L_PREFIX, OP, R_PREFIX) \448Store3ComponentsUsingOp(L_PREFIX, OP, R_PREFIX)449450#define Store1ByteGrayCompsUsingOp(L_PREFIX, OP, R_PREFIX) \451Store1ComponentUsingOp(L_PREFIX, OP, R_PREFIX)452453#define Store1ShortGrayCompsUsingOp(L_PREFIX, OP, R_PREFIX) \454Store1ComponentUsingOp(L_PREFIX, OP, R_PREFIX)455456457/*458* Set ## STRATEGY ## CompsToZero(PREFIX)459*460* c = 0;461*/462#define Set4ByteArgbCompsToZero(PREFIX) \463PREFIX ## R = PREFIX ## G = PREFIX ## B = 0464465#define Set1ByteGrayCompsToZero(PREFIX) \466PREFIX ## G = 0467468#define Set1ShortGrayCompsToZero(PREFIX) \469PREFIX ## G = 0470471#endif /* AlphaMath_h_Included */472473474