Path: blob/master/src/java.desktop/share/native/libawt/java2d/loops/AnyByteBinary.h
41159 views
/*1* Copyright (c) 2000, 2013, 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 AnyByteBinary_h_Included26#define AnyByteBinary_h_Included2728#include <string.h>2930#include "AlphaMacros.h"31#include "GraphicsPrimitiveMgr.h"32#include "LoopMacros.h"33#include "LineUtils.h"3435/*36* This file contains macros that are similar to those found in LoopMacros.h37* and AlphaMacros.h, yet have been specialized to manipulate any one of the38* surfaces in the "ByteBinary" family. It also contains generalized versions39* of some macros that are used by the more specific ByteBinary surfaces.40*/4142/* REMIND: the ByteBinary store macros should probably do ordered dithering */43#define DeclareByteBinaryLoadVars(PREFIX) \44jint *PREFIX ## Lut;4546#define DeclareByteBinaryStoreVars(PREFIX) \47unsigned char *PREFIX ## InvLut;4849#define SetByteBinaryStoreVarsYPos(PREFIX, pRasInfo, LOC)50#define SetByteBinaryStoreVarsXPos(PREFIX, pRasInfo, LOC)5152#define InitByteBinaryLoadVars(PREFIX, pRasInfo) \53PREFIX ## Lut = (pRasInfo)->lutBase5455#define InitByteBinaryStoreVarsY(PREFIX, pRasInfo) \56PREFIX ## InvLut = (pRasInfo)->invColorTable5758#define InitByteBinaryStoreVarsX(PREFIX, pRasInfo)59#define NextByteBinaryStoreVarsX(PREFIX)60#define NextByteBinaryStoreVarsY(PREFIX)616263#define DeclareByteBinaryInitialLoadVars(TYPE, INFO, pRas, PREFIX, x) \64int PREFIX ## adjx = (x) + (INFO)->pixelBitOffset / TYPE ## BitsPerPixel; \65int PREFIX ## index = (PREFIX ## adjx) / TYPE ## PixelsPerByte; \66int PREFIX ## bits = TYPE ## MaxBitOffset - \67(((PREFIX ## adjx) % TYPE ## PixelsPerByte) * \68TYPE ## BitsPerPixel); \69int PREFIX ## bbpix = (pRas)[PREFIX ## index];7071#define InitialLoadByteBinary(TYPE, pRas, PREFIX) \72do { \73if (PREFIX ## bits < 0) { \74(pRas)[PREFIX ## index] = (jubyte) PREFIX ## bbpix; \75PREFIX ## bbpix = (pRas)[++(PREFIX ## index)]; \76PREFIX ## bits = TYPE ## MaxBitOffset; \77} \78} while (0)7980#define ShiftBitsByteBinary(TYPE, PREFIX) \81PREFIX ## bits -= TYPE ## BitsPerPixel8283#define FinalStoreByteBinary(TYPE, pRas, PREFIX) \84(pRas)[PREFIX ## index] = (jubyte) PREFIX ## bbpix8586#define CurrentPixelByteBinary(TYPE, PREFIX) \87((PREFIX ## bbpix >> PREFIX ## bits) & TYPE ## PixelMask)888990#define StoreByteBinaryPixel(TYPE, pRas, x, pixel)9192#define StoreByteBinaryPixelData(TYPE, pPix, x, pixel, PREFIX) \93do { \94PREFIX ## bbpix &= ~(TYPE ## PixelMask << PREFIX ## bits); \95PREFIX ## bbpix |= (pixel << PREFIX ## bits); \96} while (0)9798#define ByteBinaryPixelFromArgb(TYPE, pixel, rgb, pRasInfo) \99do { \100jint r, g, b; \101ExtractIntDcmComponentsX123(rgb, r, g, b); \102(pixel) = SurfaceData_InvColorMap((pRasInfo)->invColorTable, \103r, g, b); \104} while (0)105106#define XorByteBinaryPixelData(TYPE, pDst, x, PREFIX, \107srcpixel, xorpixel, mask) \108PREFIX ## bbpix ^= ((((srcpixel) ^ (xorpixel)) & TYPE ## PixelMask) \109<< PREFIX ## bits)110111112#define LoadByteBinaryTo1IntRgb(TYPE, pRas, PREFIX, x, rgb) \113(rgb) = PREFIX ## Lut[CurrentPixelByteBinary(TYPE, PREFIX)]114115#define LoadByteBinaryTo1IntArgb(TYPE, pRas, PREFIX, x, argb) \116(argb) = PREFIX ## Lut[CurrentPixelByteBinary(TYPE, PREFIX)]117118#define LoadByteBinaryTo3ByteRgb(TYPE, pRas, PREFIX, x, r, g, b) \119do { \120jint rgb = PREFIX ## Lut[CurrentPixelByteBinary(TYPE, PREFIX)]; \121ExtractIntDcmComponentsX123(rgb, r, g, b); \122} while (0)123124#define LoadByteBinaryTo4ByteArgb(TYPE, pRas, PREFIX, x, a, r, g, b) \125do { \126jint argb = PREFIX ## Lut[CurrentPixelByteBinary(TYPE, PREFIX)]; \127ExtractIntDcmComponents1234(argb, a, r, g, b); \128} while (0)129130#define StoreByteBinaryFrom1IntRgb(TYPE, pRas, PREFIX, x, rgb) \131do { \132int r, g, b; \133ExtractIntDcmComponentsX123(rgb, r, g, b); \134StoreByteBinaryFrom3ByteRgb(TYPE, pRas, PREFIX, x, r, g, b); \135} while (0)136137#define StoreByteBinaryFrom1IntArgb(TYPE, pRas, PREFIX, x, argb) \138StoreByteBinaryFrom1IntRgb(TYPE, pRas, PREFIX, x, argb)139140#define StoreByteBinaryFrom3ByteRgb(TYPE, pRas, PREFIX, x, r, g, b) \141StoreByteBinaryPixelData(TYPE, pRas, x, \142SurfaceData_InvColorMap(PREFIX ## InvLut, \143r, g, b), \144PREFIX)145146#define StoreByteBinaryFrom4ByteArgb(TYPE, pRas, PREFIX, x, a, r, g, b) \147StoreByteBinaryFrom3ByteRgb(TYPE, pRas, PREFIX, x, r, g, b)148149150#define DeclareByteBinaryAlphaLoadData(TYPE, PREFIX) \151jint *PREFIX ## Lut; \152jint PREFIX ## rgb;153154#define InitByteBinaryAlphaLoadData(TYPE, PREFIX, pRasInfo) \155do { \156PREFIX ## Lut = (pRasInfo)->lutBase; \157PREFIX ## rgb = 0; \158} while (0)159160#define LoadAlphaFromByteBinaryFor4ByteArgb(TYPE, pRas, PREFIX, COMP_PREFIX) \161do { \162PREFIX ## rgb = PREFIX ## Lut[CurrentPixelByteBinary(TYPE, PREFIX)]; \163COMP_PREFIX ## A = ((juint) PREFIX ## rgb) >> 24; \164} while (0)165166#define Postload4ByteArgbFromByteBinary(TYPE, pRas, PREFIX, COMP_PREFIX) \167do { \168COMP_PREFIX ## R = (PREFIX ## rgb >> 16) & 0xff; \169COMP_PREFIX ## G = (PREFIX ## rgb >> 8) & 0xff; \170COMP_PREFIX ## B = (PREFIX ## rgb >> 0) & 0xff; \171} while (0)172173174#define ByteBinaryIsPremultiplied 0175176#define StoreByteBinaryFrom4ByteArgbComps(TYPE, pRas, PREFIX, x, COMP_PREFIX)\177StoreByteBinaryFrom4ByteArgb(TYPE, pRas, PREFIX, x, \178COMP_PREFIX ## A, COMP_PREFIX ## R, \179COMP_PREFIX ## G, COMP_PREFIX ## B)180181182183184#define BBBlitLoopWidthHeight(SRCTYPE, SRCPTR, SRCBASE, SRCINFO, SRCPREFIX, \185DSTTYPE, DSTPTR, DSTBASE, DSTINFO, DSTPREFIX, \186WIDTH, HEIGHT, BODY) \187do { \188SRCTYPE ## DataType *SRCPTR = (SRCTYPE ## DataType *) (SRCBASE); \189DSTTYPE ## DataType *DSTPTR = (DSTTYPE ## DataType *) (DSTBASE); \190jint srcScan = (SRCINFO)->scanStride; \191jint dstScan = (DSTINFO)->scanStride; \192jint srcx1 = (SRCINFO)->bounds.x1; \193jint dstx1 = (DSTINFO)->bounds.x1; \194Init ## DSTTYPE ## StoreVarsY(DSTPREFIX, DSTINFO); \195srcScan -= (WIDTH) * SRCTYPE ## PixelStride; \196dstScan -= (WIDTH) * DSTTYPE ## PixelStride; \197do { \198Declare ## SRCTYPE ## InitialLoadVars(SRCINFO, SRCPTR, SRCPREFIX, \199srcx1) \200Declare ## DSTTYPE ## InitialLoadVars(DSTINFO, DSTPTR, DSTPREFIX, \201dstx1) \202juint w = WIDTH; \203Init ## DSTTYPE ## StoreVarsX(DSTPREFIX, DSTINFO); \204do { \205InitialLoad ## SRCTYPE(SRCPTR, SRCPREFIX); \206InitialLoad ## DSTTYPE(DSTPTR, DSTPREFIX); \207BODY; \208ShiftBits ## SRCTYPE(SRCPREFIX); \209ShiftBits ## DSTTYPE(DSTPREFIX); \210SRCPTR = PtrAddBytes(SRCPTR, SRCTYPE ## PixelStride); \211DSTPTR = PtrAddBytes(DSTPTR, DSTTYPE ## PixelStride); \212Next ## DSTTYPE ## StoreVarsX(DSTPREFIX); \213} while (--w > 0); \214FinalStore ## DSTTYPE(DSTPTR, DSTPREFIX); \215SRCPTR = PtrAddBytes(SRCPTR, srcScan); \216DSTPTR = PtrAddBytes(DSTPTR, dstScan); \217Next ## DSTTYPE ## StoreVarsY(DSTPREFIX); \218} while (--HEIGHT > 0); \219} while (0)220221#define BBXorVia1IntArgb(SRCPTR, SRCTYPE, SRCPREFIX, \222DSTPTR, DSTTYPE, DSTPREFIX, \223XVAR, XORPIXEL, MASK, DSTINFOPTR) \224do { \225jint srcpixel; \226Load ## SRCTYPE ## To1IntArgb(SRCPTR, SRCPREFIX, XVAR, srcpixel); \227\228if (IsArgbTransparent(srcpixel)) { \229break; \230} \231\232DSTTYPE ## PixelFromArgb(srcpixel, srcpixel, DSTINFOPTR); \233\234Xor ## DSTTYPE ## PixelData(DSTPTR, XVAR, DSTPREFIX, srcpixel, \235XORPIXEL, MASK); \236} while (0)237238#define DEFINE_BYTE_BINARY_CONVERT_BLIT(SRC, DST, STRATEGY) \239void NAME_CONVERT_BLIT(SRC, DST)(void *srcBase, void *dstBase, \240juint width, juint height, \241SurfaceDataRasInfo *pSrcInfo, \242SurfaceDataRasInfo *pDstInfo, \243NativePrimitive *pPrim, \244CompositeInfo *pCompInfo) \245{ \246Declare ## SRC ## LoadVars(SrcRead) \247Declare ## DST ## StoreVars(DstWrite) \248\249Init ## SRC ## LoadVars(SrcRead, pSrcInfo); \250BBBlitLoopWidthHeight(SRC, pSrc, srcBase, pSrcInfo, SrcRead, \251DST, pDst, dstBase, pDstInfo, DstWrite, \252width, height, \253ConvertVia ## STRATEGY(pSrc, SRC, SrcRead, \254pDst, DST, DstWrite, \2550, 0)); \256}257258#define DEFINE_BYTE_BINARY_XOR_BLIT(SRC, DST) \259void NAME_XOR_BLIT(SRC, DST)(void *srcBase, void *dstBase, \260juint width, juint height, \261SurfaceDataRasInfo *pSrcInfo, \262SurfaceDataRasInfo *pDstInfo, \263NativePrimitive *pPrim, \264CompositeInfo *pCompInfo) \265{ \266jint xorpixel = pCompInfo->details.xorPixel; \267juint alphamask = pCompInfo->alphaMask; \268Declare ## SRC ## LoadVars(SrcRead) \269Declare ## DST ## StoreVars(DstWrite) \270\271Init ## SRC ## LoadVars(SrcRead, pSrcInfo); \272BBBlitLoopWidthHeight(SRC, pSrc, srcBase, pSrcInfo, SrcRead, \273DST, pDst, dstBase, pDstInfo, DstWrite, \274width, height, \275BBXorVia1IntArgb(pSrc, SRC, SrcRead, \276pDst, DST, DstWrite, \2770, xorpixel, \278alphamask, pDstInfo)); \279}280281#define DEFINE_BYTE_BINARY_SOLID_FILLRECT(DST) \282void NAME_SOLID_FILLRECT(DST)(SurfaceDataRasInfo *pRasInfo, \283jint lox, jint loy, \284jint hix, jint hiy, \285jint pixel, \286NativePrimitive *pPrim, \287CompositeInfo *pCompInfo) \288{ \289DST ## DataType *pPix; \290jint scan = pRasInfo->scanStride; \291juint height = hiy - loy; \292juint width = hix - lox; \293\294pPix = PtrCoord(pRasInfo->rasBase, lox, DST ## PixelStride, loy, scan); \295do { \296Declare ## DST ## InitialLoadVars(pRasInfo, pPix, DstPix, lox) \297jint w = width; \298do { \299InitialLoad ## DST(pPix, DstPix); \300Store ## DST ## PixelData(pPix, 0, pixel, DstPix); \301ShiftBits ## DST(DstPix); \302} while (--w > 0); \303FinalStore ## DST(pPix, DstPix); \304pPix = PtrAddBytes(pPix, scan); \305} while (--height > 0); \306}307308#define DEFINE_BYTE_BINARY_SOLID_FILLSPANS(DST) \309void NAME_SOLID_FILLSPANS(DST)(SurfaceDataRasInfo *pRasInfo, \310SpanIteratorFuncs *pSpanFuncs, void *siData, \311jint pixel, NativePrimitive *pPrim, \312CompositeInfo *pCompInfo) \313{ \314void *pBase = pRasInfo->rasBase; \315jint scan = pRasInfo->scanStride; \316jint bbox[4]; \317\318while ((*pSpanFuncs->nextSpan)(siData, bbox)) { \319jint x = bbox[0]; \320jint y = bbox[1]; \321juint w = bbox[2] - x; \322juint h = bbox[3] - y; \323DST ## DataType *pPix = PtrCoord(pBase, \324x, DST ## PixelStride, \325y, scan); \326do { \327Declare ## DST ## InitialLoadVars(pRasInfo, pPix, DstPix, x) \328jint relx = w; \329do { \330InitialLoad ## DST(pPix, DstPix); \331Store ## DST ## PixelData(pPix, 0, pixel, DstPix); \332ShiftBits ## DST(DstPix); \333} while (--relx > 0); \334FinalStore ## DST(pPix, DstPix); \335pPix = PtrAddBytes(pPix, scan); \336} while (--h > 0); \337} \338}339340#define DEFINE_BYTE_BINARY_SOLID_DRAWLINE(DST) \341void NAME_SOLID_DRAWLINE(DST)(SurfaceDataRasInfo *pRasInfo, \342jint x1, jint y1, jint pixel, \343jint steps, jint error, \344jint bumpmajormask, jint errmajor, \345jint bumpminormask, jint errminor, \346NativePrimitive *pPrim, \347CompositeInfo *pCompInfo) \348{ \349jint scan = pRasInfo->scanStride; \350DST ## DataType *pPix = PtrCoord(pRasInfo->rasBase, \351x1, DST ## PixelStride, \352y1, scan); \353DeclareBumps(bumpmajor, bumpminor) \354\355scan *= DST ## PixelsPerByte; \356InitBumps(bumpmajor, bumpminor, bumpmajormask, bumpminormask, 1, scan); \357if (errmajor == 0) { \358do { \359Declare ## DST ## InitialLoadVars(pRasInfo, pPix, DstPix, x1) \360Store ## DST ## PixelData(pPix, 0, pixel, DstPix); \361FinalStore ## DST(pPix, DstPix); \362x1 += bumpmajor; \363} while (--steps > 0); \364} else { \365do { \366Declare ## DST ## InitialLoadVars(pRasInfo, pPix, DstPix, x1) \367Store ## DST ## PixelData(pPix, 0, pixel, DstPix); \368FinalStore ## DST(pPix, DstPix); \369if (error < 0) { \370x1 += bumpmajor; \371error += errmajor; \372} else { \373x1 += bumpminor; \374error -= errminor; \375} \376} while (--steps > 0); \377} \378}379380#define DEFINE_BYTE_BINARY_XOR_FILLRECT(DST) \381void NAME_XOR_FILLRECT(DST)(SurfaceDataRasInfo *pRasInfo, \382jint lox, jint loy, \383jint hix, jint hiy, \384jint pixel, \385NativePrimitive *pPrim, \386CompositeInfo *pCompInfo) \387{ \388jint xorpixel = pCompInfo->details.xorPixel; \389juint alphamask = pCompInfo->alphaMask; \390DST ## DataType *pPix; \391jint scan = pRasInfo->scanStride; \392juint height = hiy - loy; \393juint width = hix - lox; \394\395pPix = PtrCoord(pRasInfo->rasBase, lox, DST ## PixelStride, loy, scan); \396do { \397Declare ## DST ## InitialLoadVars(pRasInfo, pPix, DstPix, lox) \398jint w = width; \399do { \400InitialLoad ## DST(pPix, DstPix); \401Xor ## DST ## PixelData(pPix, 0, DstPix, \402pixel, xorpixel, alphamask); \403ShiftBits ## DST(DstPix); \404} while (--w > 0); \405FinalStore ## DST(pPix, DstPix); \406pPix = PtrAddBytes(pPix, scan); \407} while (--height > 0); \408}409410#define DEFINE_BYTE_BINARY_XOR_FILLSPANS(DST) \411void NAME_XOR_FILLSPANS(DST)(SurfaceDataRasInfo *pRasInfo, \412SpanIteratorFuncs *pSpanFuncs, \413void *siData, jint pixel, \414NativePrimitive *pPrim, \415CompositeInfo *pCompInfo) \416{ \417void *pBase = pRasInfo->rasBase; \418jint xorpixel = pCompInfo->details.xorPixel; \419juint alphamask = pCompInfo->alphaMask; \420jint scan = pRasInfo->scanStride; \421jint bbox[4]; \422\423while ((*pSpanFuncs->nextSpan)(siData, bbox)) { \424jint x = bbox[0]; \425jint y = bbox[1]; \426juint w = bbox[2] - x; \427juint h = bbox[3] - y; \428DST ## DataType *pPix = PtrCoord(pBase, \429x, DST ## PixelStride, \430y, scan); \431do { \432Declare ## DST ## InitialLoadVars(pRasInfo, pPix, DstPix, x) \433jint relx = w; \434do { \435InitialLoad ## DST(pPix, DstPix); \436Xor ## DST ## PixelData(pPix, 0, DstPix, \437pixel, xorpixel, alphamask); \438ShiftBits ## DST(DstPix); \439} while (--relx > 0); \440FinalStore ## DST(pPix, DstPix); \441pPix = PtrAddBytes(pPix, scan); \442} while (--h > 0); \443} \444}445446#define DEFINE_BYTE_BINARY_XOR_DRAWLINE(DST) \447void NAME_XOR_DRAWLINE(DST)(SurfaceDataRasInfo *pRasInfo, \448jint x1, jint y1, jint pixel, \449jint steps, jint error, \450jint bumpmajormask, jint errmajor, \451jint bumpminormask, jint errminor, \452NativePrimitive *pPrim, \453CompositeInfo *pCompInfo) \454{ \455jint xorpixel = pCompInfo->details.xorPixel; \456juint alphamask = pCompInfo->alphaMask; \457jint scan = pRasInfo->scanStride; \458DST ## DataType *pPix = PtrCoord(pRasInfo->rasBase, \459x1, DST ## PixelStride, \460y1, scan); \461DeclareBumps(bumpmajor, bumpminor) \462\463scan *= DST ## PixelsPerByte; \464InitBumps(bumpmajor, bumpminor, bumpmajormask, bumpminormask, 1, scan); \465\466if (errmajor == 0) { \467do { \468Declare ## DST ## InitialLoadVars(pRasInfo, pPix, DstPix, x1) \469Xor ## DST ## PixelData(pPix, 0, DstPix, \470pixel, xorpixel, alphamask); \471FinalStore ## DST(pPix, DstPix); \472x1 += bumpmajor; \473} while (--steps > 0); \474} else { \475do { \476Declare ## DST ## InitialLoadVars(pRasInfo, pPix, DstPix, x1) \477Xor ## DST ## PixelData(pPix, 0, DstPix, \478pixel, xorpixel, alphamask); \479FinalStore ## DST(pPix, DstPix); \480if (error < 0) { \481x1 += bumpmajor; \482error += errmajor; \483} else { \484x1 += bumpminor; \485error -= errminor; \486} \487} while (--steps > 0); \488} \489}490491#define DEFINE_BYTE_BINARY_SOLID_DRAWGLYPHLIST(DST) \492void NAME_SOLID_DRAWGLYPHLIST(DST)(SurfaceDataRasInfo *pRasInfo, \493ImageRef *glyphs, \494jint totalGlyphs, jint fgpixel, \495jint argbcolor, \496jint clipLeft, jint clipTop, \497jint clipRight, jint clipBottom, \498NativePrimitive *pPrim, \499CompositeInfo *pCompInfo) \500{ \501jint glyphCounter; \502jint scan = pRasInfo->scanStride; \503DST ## DataType *pPix; \504\505for (glyphCounter = 0; glyphCounter < totalGlyphs; glyphCounter++) { \506DeclareDrawGlyphListClipVars(pixels, rowBytes, width, height, \507left, top, right, bottom) \508ClipDrawGlyphList(DST, pixels, 1, rowBytes, width, height, \509left, top, right, bottom, \510clipLeft, clipTop, clipRight, clipBottom, \511glyphs, glyphCounter, continue) \512pPix = PtrCoord(pRasInfo->rasBase,left,DST ## PixelStride,top,scan); \513\514do { \515Declare ## DST ## InitialLoadVars(pRasInfo, pPix, DstPix, left) \516jint x = 0; \517do { \518InitialLoad ## DST(pPix, DstPix); \519if (pixels[x]) { \520Store ## DST ## PixelData(pPix, 0, fgpixel, DstPix); \521} \522ShiftBits ## DST(DstPix); \523} while (++x < width); \524FinalStore ## DST(pPix, DstPix); \525pPix = PtrAddBytes(pPix, scan); \526pixels += rowBytes; \527} while (--height > 0); \528} \529}530531/*532* REMIND: we shouldn't be attempting to do antialiased text for the533* ByteBinary surfaces in the first place534*/535#define DEFINE_BYTE_BINARY_SOLID_DRAWGLYPHLISTAA(DST, STRATEGY) \536void NAME_SOLID_DRAWGLYPHLISTAA(DST)(SurfaceDataRasInfo *pRasInfo, \537ImageRef *glyphs, \538jint totalGlyphs, jint fgpixel, \539jint argbcolor, \540jint clipLeft, jint clipTop, \541jint clipRight, jint clipBottom, \542NativePrimitive *pPrim, \543CompositeInfo *pCompInfo) \544{ \545jint glyphCounter; \546jint scan = pRasInfo->scanStride; \547DST ## DataType *pPix; \548DeclareAlphaVarFor ## STRATEGY(srcA) \549DeclareCompVarsFor ## STRATEGY(src) \550\551Declare ## DST ## LoadVars(pix) \552Declare ## DST ## StoreVars(pix) \553\554Init ## DST ## LoadVars(pix, pRasInfo); \555Init ## DST ## StoreVarsY(pix, pRasInfo); \556Init ## DST ## StoreVarsX(pix, pRasInfo); \557Extract ## STRATEGY ## CompsAndAlphaFromArgb(argbcolor, src); \558\559for (glyphCounter = 0; glyphCounter < totalGlyphs; glyphCounter++) { \560DeclareDrawGlyphListClipVars(pixels, rowBytes, width, height, \561left, top, right, bottom) \562ClipDrawGlyphList(DST, pixels, 1, rowBytes, width, height, \563left, top, right, bottom, \564clipLeft, clipTop, clipRight, clipBottom, \565glyphs, glyphCounter, continue) \566pPix = PtrCoord(pRasInfo->rasBase,left,DST ## PixelStride,top,scan); \567\568Set ## DST ## StoreVarsYPos(pix, pRasInfo, top); \569do { \570Declare ## DST ## InitialLoadVars(pRasInfo, pPix, pix, left) \571int x = 0; \572Set ## DST ## StoreVarsXPos(pix, pRasInfo, left); \573do { \574InitialLoad ## DST(pPix, pix); \575GlyphListAABlend ## STRATEGY(DST, pixels, x, pPix, \576fgpixel, pix, src); \577ShiftBits ## DST(pix); \578Next ## DST ## StoreVarsX(pix); \579} while (++x < width); \580FinalStore ## DST(pPix, pix); \581pPix = PtrAddBytes(pPix, scan); \582pixels += rowBytes; \583Next ## DST ## StoreVarsY(pix); \584} while (--height > 0); \585} \586}587588#define DEFINE_BYTE_BINARY_XOR_DRAWGLYPHLIST(DST) \589void NAME_XOR_DRAWGLYPHLIST(DST)(SurfaceDataRasInfo *pRasInfo, \590ImageRef *glyphs, \591jint totalGlyphs, jint fgpixel, \592jint argbcolor, \593jint clipLeft, jint clipTop, \594jint clipRight, jint clipBottom, \595NativePrimitive *pPrim, \596CompositeInfo *pCompInfo) \597{ \598jint glyphCounter; \599jint scan = pRasInfo->scanStride; \600jint xorpixel = pCompInfo->details.xorPixel; \601juint alphamask = pCompInfo->alphaMask; \602DST ## DataType *pPix; \603\604for (glyphCounter = 0; glyphCounter < totalGlyphs; glyphCounter++) { \605DeclareDrawGlyphListClipVars(pixels, rowBytes, width, height, \606left, top, right, bottom) \607ClipDrawGlyphList(DST, pixels, 1, rowBytes, width, height, \608left, top, right, bottom, \609clipLeft, clipTop, clipRight, clipBottom, \610glyphs, glyphCounter, continue) \611pPix = PtrCoord(pRasInfo->rasBase,left,DST ## PixelStride,top,scan); \612\613do { \614Declare ## DST ## InitialLoadVars(pRasInfo, pPix, DstPix, left) \615jint x = 0; \616do { \617InitialLoad ## DST(pPix, DstPix); \618if (pixels[x]) { \619Xor ## DST ## PixelData(pPix, 0, DstPix, \620fgpixel, xorpixel, alphamask); \621} \622ShiftBits ## DST(DstPix); \623} while (++x < width); \624FinalStore ## DST(pPix, DstPix); \625pPix = PtrAddBytes(pPix, scan); \626pixels += rowBytes; \627} while (--height > 0); \628} \629}630631#define DEFINE_BYTE_BINARY_ALPHA_MASKBLIT(SRC, DST, STRATEGY) \632void NAME_ALPHA_MASKBLIT(SRC, DST) \633(void *dstBase, void *srcBase, \634jubyte *pMask, jint maskOff, jint maskScan, \635jint width, jint height, \636SurfaceDataRasInfo *pDstInfo, \637SurfaceDataRasInfo *pSrcInfo, \638NativePrimitive *pPrim, \639CompositeInfo *pCompInfo) \640{ \641DeclareAndSetOpaqueAlphaVarFor ## STRATEGY(pathA) \642DeclareAndClearAlphaVarFor ## STRATEGY(srcA) \643DeclareAndClearAlphaVarFor ## STRATEGY(dstA) \644DeclareAndInitExtraAlphaFor ## STRATEGY(extraA) \645jint srcScan = pSrcInfo->scanStride; \646jint dstScan = pDstInfo->scanStride; \647jboolean loadsrc, loaddst; \648jint srcx1 = pSrcInfo->bounds.x1; \649jint dstx1 = pDstInfo->bounds.x1; \650SRC ## DataType *pSrc = (SRC ## DataType *) (srcBase); \651DST ## DataType *pDst = (DST ## DataType *) (dstBase); \652Declare ## SRC ## AlphaLoadData(SrcRead) \653Declare ## DST ## AlphaLoadData(DstWrite) \654Declare ## DST ## StoreVars(DstWrite) \655DeclareAlphaOperands(SrcOp) \656DeclareAlphaOperands(DstOp) \657\658ExtractAlphaOperandsFor ## STRATEGY(AlphaRules[pCompInfo->rule].srcOps, \659SrcOp); \660ExtractAlphaOperandsFor ## STRATEGY(AlphaRules[pCompInfo->rule].dstOps, \661DstOp); \662loadsrc = !FuncIsZero(SrcOp) || FuncNeedsAlpha(DstOp); \663loaddst = pMask || !FuncIsZero(DstOp) || FuncNeedsAlpha(SrcOp); \664\665Init ## SRC ## AlphaLoadData(SrcRead, pSrcInfo); \666Init ## DST ## AlphaLoadData(DstWrite, pDstInfo); \667srcScan -= width * SRC ## PixelStride; \668dstScan -= width * DST ## PixelStride; \669maskScan -= width; \670if (pMask) { \671pMask += maskOff; \672} \673\674Init ## DST ## StoreVarsY(DstWrite, pDstInfo); \675do { \676Declare ## SRC ## InitialLoadVars(pSrcInfo, pSrc, SrcRead, srcx1) \677Declare ## DST ## InitialLoadVars(pDstInfo, pDst, DstWrite, dstx1) \678jint w = width; \679Init ## DST ## StoreVarsX(DstWrite, pDstInfo); \680do { \681DeclareAlphaVarFor ## STRATEGY(resA) \682DeclareCompVarsFor ## STRATEGY(res) \683DeclareAlphaVarFor ## STRATEGY(srcF) \684DeclareAlphaVarFor ## STRATEGY(dstF) \685\686InitialLoad ## SRC(pSrc, SrcRead); \687InitialLoad ## DST(pDst, DstWrite); \688if (pMask) { \689pathA = *pMask++; \690if (!pathA) { \691ShiftBits ## SRC(SrcRead); \692ShiftBits ## DST(DstWrite); \693pSrc = PtrAddBytes(pSrc, SRC ## PixelStride); \694pDst = PtrAddBytes(pDst, DST ## PixelStride); \695Next ## DST ## StoreVarsX(DstWrite); \696continue; \697} \698PromoteByteAlphaFor ## STRATEGY(pathA); \699} \700if (loadsrc) { \701LoadAlphaFrom ## SRC ## For ## STRATEGY(pSrc,SrcRead,src); \702srcA = MultiplyAlphaFor ## STRATEGY(extraA, srcA); \703} \704if (loaddst) { \705LoadAlphaFrom ## DST ## For ## STRATEGY(pDst,DstWrite,dst); \706} \707srcF = ApplyAlphaOperands(SrcOp, dstA); \708dstF = ApplyAlphaOperands(DstOp, srcA); \709if (pathA != MaxValFor ## STRATEGY) { \710srcF = MultiplyAlphaFor ## STRATEGY(pathA, srcF); \711dstF = MaxValFor ## STRATEGY - pathA + \712MultiplyAlphaFor ## STRATEGY(pathA, dstF); \713} \714if (srcF) { \715resA = MultiplyAlphaFor ## STRATEGY(srcF, srcA); \716if (!(SRC ## IsPremultiplied)) { \717srcF = resA; \718} else { \719srcF = MultiplyAlphaFor ## STRATEGY(srcF, extraA); \720} \721if (srcF) { \722/* assert(loadsrc); */ \723Postload ## STRATEGY ## From ## SRC(pSrc, SrcRead, res); \724if (srcF != MaxValFor ## STRATEGY) { \725MultiplyAndStore ## STRATEGY ## Comps(res, \726srcF, res); \727} \728} else { \729Set ## STRATEGY ## CompsToZero(res); \730} \731} else { \732if (dstF == MaxValFor ## STRATEGY) { \733ShiftBits ## SRC(SrcRead); \734ShiftBits ## DST(DstWrite); \735pSrc = PtrAddBytes(pSrc, SRC ## PixelStride); \736pDst = PtrAddBytes(pDst, DST ## PixelStride); \737Next ## DST ## StoreVarsX(DstWrite); \738continue; \739} \740resA = 0; \741Set ## STRATEGY ## CompsToZero(res); \742} \743if (dstF) { \744dstA = MultiplyAlphaFor ## STRATEGY(dstF, dstA); \745if (!(DST ## IsPremultiplied)) { \746dstF = dstA; \747} \748resA += dstA; \749if (dstF) { \750DeclareCompVarsFor ## STRATEGY(tmp) \751/* assert(loaddst); */ \752Postload ## STRATEGY ## From ## DST(pDst,DstWrite,tmp); \753if (dstF != MaxValFor ## STRATEGY) { \754MultiplyAndStore ## STRATEGY ## Comps(tmp, \755dstF, tmp); \756} \757Store ## STRATEGY ## CompsUsingOp(res, +=, tmp); \758} \759} \760if (!(DST ## IsPremultiplied) && resA && \761resA < MaxValFor ## STRATEGY) \762{ \763DivideAndStore ## STRATEGY ## Comps(res, res, resA); \764} \765Store ## DST ## From ## STRATEGY ## Comps(pDst, DstWrite, \7660, res); \767ShiftBits ## SRC(SrcRead); \768ShiftBits ## DST(DstWrite); \769pSrc = PtrAddBytes(pSrc, SRC ## PixelStride); \770pDst = PtrAddBytes(pDst, DST ## PixelStride); \771Next ## DST ## StoreVarsX(DstWrite); \772} while (--w > 0); \773FinalStore ## DST(pDst, DstWrite); \774pSrc = PtrAddBytes(pSrc, srcScan); \775pDst = PtrAddBytes(pDst, dstScan); \776Next ## DST ## StoreVarsY(DstWrite); \777if (pMask) { \778pMask = PtrAddBytes(pMask, maskScan); \779} \780} while (--height > 0); \781}782783#define DEFINE_BYTE_BINARY_ALPHA_MASKFILL(TYPE, STRATEGY) \784void NAME_ALPHA_MASKFILL(TYPE) \785(void *rasBase, \786jubyte *pMask, jint maskOff, jint maskScan, \787jint width, jint height, \788jint fgColor, \789SurfaceDataRasInfo *pRasInfo, \790NativePrimitive *pPrim, \791CompositeInfo *pCompInfo) \792{ \793DeclareAndSetOpaqueAlphaVarFor ## STRATEGY(pathA) \794DeclareAlphaVarFor ## STRATEGY(srcA) \795DeclareCompVarsFor ## STRATEGY(src) \796DeclareAndClearAlphaVarFor ## STRATEGY(dstA) \797DeclareAlphaVarFor ## STRATEGY(dstF) \798DeclareAlphaVarFor ## STRATEGY(dstFbase) \799jint rasScan = pRasInfo->scanStride; \800jboolean loaddst; \801jint x1 = pRasInfo->bounds.x1; \802TYPE ## DataType *pRas = (TYPE ## DataType *) (rasBase); \803Declare ## TYPE ## AlphaLoadData(DstWrite) \804Declare ## TYPE ## StoreVars(DstWrite) \805DeclareAlphaOperands(SrcOp) \806DeclareAlphaOperands(DstOp) \807\808Extract ## STRATEGY ## CompsAndAlphaFromArgb(fgColor, src); \809if (srcA != MaxValFor ## STRATEGY) { \810MultiplyAndStore ## STRATEGY ## Comps(src, srcA, src); \811} \812\813ExtractAlphaOperandsFor ## STRATEGY(AlphaRules[pCompInfo->rule].srcOps, \814SrcOp); \815ExtractAlphaOperandsFor ## STRATEGY(AlphaRules[pCompInfo->rule].dstOps, \816DstOp); \817loaddst = pMask || !FuncIsZero(DstOp) || FuncNeedsAlpha(SrcOp); \818\819dstFbase = dstF = ApplyAlphaOperands(DstOp, srcA); \820\821Init ## TYPE ## AlphaLoadData(DstWrite, pRasInfo); \822maskScan -= width; \823if (pMask) { \824pMask += maskOff; \825} \826\827Init ## TYPE ## StoreVarsY(DstWrite, pRasInfo); \828do { \829Declare ## TYPE ## InitialLoadVars(pRasInfo, pRas, DstWrite, x1) \830jint w = width; \831Init ## TYPE ## StoreVarsX(DstWrite, pRasInfo); \832do { \833DeclareAlphaVarFor ## STRATEGY(resA) \834DeclareCompVarsFor ## STRATEGY(res) \835DeclareAlphaVarFor ## STRATEGY(srcF) \836\837InitialLoad ## TYPE(pRas, DstWrite); \838if (pMask) { \839pathA = *pMask++; \840if (!pathA) { \841ShiftBits ## TYPE(DstWrite); \842Next ## TYPE ## StoreVarsX(DstWrite); \843continue; \844} \845PromoteByteAlphaFor ## STRATEGY(pathA); \846dstF = dstFbase; \847} \848if (loaddst) { \849LoadAlphaFrom ## TYPE ## For ## STRATEGY(pRas,DstWrite,dst);\850} \851srcF = ApplyAlphaOperands(SrcOp, dstA); \852if (pathA != MaxValFor ## STRATEGY) { \853srcF = MultiplyAlphaFor ## STRATEGY(pathA, srcF); \854dstF = MaxValFor ## STRATEGY - pathA + \855MultiplyAlphaFor ## STRATEGY(pathA, dstF); \856} \857if (srcF) { \858if (srcF == MaxValFor ## STRATEGY) { \859resA = srcA; \860Store ## STRATEGY ## CompsUsingOp(res, =, src); \861} else { \862resA = MultiplyAlphaFor ## STRATEGY(srcF, srcA); \863MultiplyAndStore ## STRATEGY ## Comps(res, srcF, src); \864} \865} else { \866if (dstF == MaxValFor ## STRATEGY) { \867ShiftBits ## TYPE(DstWrite); \868Next ## TYPE ## StoreVarsX(DstWrite); \869continue; \870} \871resA = 0; \872Set ## STRATEGY ## CompsToZero(res); \873} \874if (dstF) { \875dstA = MultiplyAlphaFor ## STRATEGY(dstF, dstA); \876if (!(TYPE ## IsPremultiplied)) { \877dstF = dstA; \878} \879resA += dstA; \880if (dstF) { \881DeclareCompVarsFor ## STRATEGY(tmp) \882/* assert(loaddst); */ \883Postload ## STRATEGY ## From ## TYPE(pRas,DstWrite,tmp); \884if (dstF != MaxValFor ## STRATEGY) { \885MultiplyAndStore ## STRATEGY ## Comps(tmp, \886dstF, tmp); \887} \888Store ## STRATEGY ## CompsUsingOp(res, +=, tmp); \889} \890} \891if (!(TYPE ## IsPremultiplied) && resA && \892resA < MaxValFor ## STRATEGY) \893{ \894DivideAndStore ## STRATEGY ## Comps(res, res, resA); \895} \896Store ## TYPE ## From ## STRATEGY ## Comps(pRas, DstWrite, \8970, res); \898ShiftBits ## TYPE(DstWrite); \899Next ## TYPE ## StoreVarsX(DstWrite); \900} while (--w > 0); \901FinalStore ## TYPE(pRas, DstWrite); \902pRas = PtrAddBytes(pRas, rasScan); \903Next ## TYPE ## StoreVarsY(DstWrite); \904if (pMask) { \905pMask = PtrAddBytes(pMask, maskScan); \906} \907} while (--height > 0); \908}909910911/*912* The macros defined above use the following macro definitions supplied913* for the various ByteBinary-specific surface types to manipulate pixel data.914*915* In the macro names in the following definitions, the string <stype>916* is used as a place holder for the SurfaceType name (eg. ByteBinary2Bit).917* The macros above access these type specific macros using the ANSI918* CPP token concatenation operator "##".919*920* Declare<stype>InitialLoadVars Declare and initialize the variables used921* for managing byte/bit offsets922* InitialLoad<stype> Store the current byte, fetch the next923* byte, and reset the bit offset924* ShiftBits<stype> Advance to the next pixel by adjusting925* the bit offset (1, 2, or 4 bits)926* FinalStore<stype> Store the current byte927* CurrentPixel<stype> Represents the current pixel by shifting928* the value with the current bit offset and929* then masking the value to either 1, 2, or930* 4 bits931*/932933#endif /* AnyByteBinary_h_Included */934935936