0N/A/*
2362N/A * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#if !defined(JAVA2D_NO_MLIB) || defined(MLIB_ADD_SUFF)
0N/A
0N/A#include "vis_AlphaMacros.h"
0N/A
0N/A/***************************************************************/
0N/A
0N/A#define FUNC_CONVERT(TYPE, OPER) \
0N/Avoid ADD_SUFF(TYPE##ToFourByteAbgrPre##OPER)(BLIT_PARAMS) \
0N/A{ \
0N/A mlib_d64 buff[BUFF_SIZE/2]; \
0N/A void *pbuff = buff; \
0N/A mlib_s32 dstScan = pDstInfo->scanStride; \
0N/A mlib_s32 srcScan = pSrcInfo->scanStride; \
0N/A mlib_s32 j; \
0N/A \
0N/A if (width > BUFF_SIZE) pbuff = mlib_malloc(width*sizeof(mlib_s32)); \
0N/A \
0N/A for (j = 0; j < height; j++) { \
0N/A ADD_SUFF(TYPE##ToIntArgbPre##OPER)(srcBase, pbuff, width, 1, \
0N/A pSrcInfo, pDstInfo, \
0N/A pPrim, pCompInfo); \
0N/A \
0N/A ADD_SUFF(IntArgbToFourByteAbgrConvert)(pbuff, dstBase, width, 1, \
0N/A pSrcInfo, pDstInfo, \
0N/A pPrim, pCompInfo); \
0N/A \
0N/A PTR_ADD(dstBase, dstScan); \
0N/A PTR_ADD(srcBase, srcScan); \
0N/A } \
0N/A \
0N/A if (pbuff != buff) { \
0N/A mlib_free(pbuff); \
0N/A } \
0N/A}
0N/A
0N/A/***************************************************************/
0N/A
0N/A#define FUNC_SCALE_1(TYPE, OPER) \
0N/Avoid ADD_SUFF(TYPE##ToFourByteAbgrPre##OPER)(SCALE_PARAMS) \
0N/A{ \
0N/A mlib_d64 buff[BUFF_SIZE/2]; \
0N/A void *pbuff = buff; \
0N/A mlib_s32 dstScan = pDstInfo->scanStride; \
0N/A mlib_s32 j; \
0N/A \
0N/A if (width > BUFF_SIZE) pbuff = mlib_malloc(width*sizeof(mlib_s32)); \
0N/A \
0N/A for (j = 0; j < height; j++) { \
0N/A ADD_SUFF(TYPE##ToIntArgbPre##OPER)(srcBase, pbuff, width, 1, \
0N/A sxloc, syloc, \
0N/A sxinc, syinc, shift, \
0N/A pSrcInfo, pDstInfo, \
0N/A pPrim, pCompInfo); \
0N/A \
0N/A ADD_SUFF(IntArgbToFourByteAbgrConvert)(pbuff, dstBase, width, 1, \
0N/A pSrcInfo, pDstInfo, \
0N/A pPrim, pCompInfo); \
0N/A \
0N/A PTR_ADD(dstBase, dstScan); \
0N/A syloc += syinc; \
0N/A } \
0N/A \
0N/A if (pbuff != buff) { \
0N/A mlib_free(pbuff); \
0N/A } \
0N/A}
0N/A
0N/A/***************************************************************/
0N/A
0N/A#define FUNC_INDEXED(TYPE, OPER, PARAMS, CALL_PARAMS) \
0N/Avoid ADD_SUFF(TYPE##ToFourByteAbgrPre##OPER)(PARAMS) \
0N/A{ \
0N/A SurfaceDataRasInfo new_src[1]; \
0N/A jint *pixLut = pSrcInfo->lutBase; \
0N/A mlib_s32 buff[256]; \
0N/A \
0N/A ADD_SUFF(IntArgbToIntArgbPreConvert)(pixLut, buff, 256, 1, \
0N/A pSrcInfo, pDstInfo, \
0N/A pPrim, pCompInfo); \
0N/A \
0N/A new_src->lutBase = buff; \
0N/A new_src->scanStride = pSrcInfo->scanStride; \
0N/A pSrcInfo = new_src; \
0N/A \
0N/A ADD_SUFF(TYPE##ToFourByteAbgr##OPER)(CALL_PARAMS); \
0N/A}
0N/A
0N/A/***************************************************************/
0N/A
0N/Avoid ADD_SUFF(FourByteAbgrPreToIntArgbConvert)(BLIT_PARAMS)
0N/A{
0N/A ADD_SUFF(FourByteAbgrToIntArgbConvert)(BLIT_CALL_PARAMS);
0N/A pSrcInfo = pDstInfo;
0N/A srcBase = dstBase;
0N/A ADD_SUFF(IntArgbPreToIntArgbConvert)(BLIT_CALL_PARAMS);
0N/A}
0N/A
0N/A/***************************************************************/
0N/A
0N/Avoid ADD_SUFF(FourByteAbgrPreToIntArgbScaleConvert)(SCALE_PARAMS)
0N/A{
0N/A ADD_SUFF(FourByteAbgrToIntArgbScaleConvert)(SCALE_CALL_PARAMS);
0N/A pSrcInfo = pDstInfo;
0N/A srcBase = dstBase;
0N/A ADD_SUFF(IntArgbPreToIntArgbConvert)(BLIT_CALL_PARAMS);
0N/A}
0N/A
0N/A/***************************************************************/
0N/A
0N/AFUNC_CONVERT(ByteGray, Convert)
0N/AFUNC_CONVERT(IntArgb, Convert)
0N/AFUNC_CONVERT(IntRgb, Convert)
0N/AFUNC_CONVERT(ThreeByteBgr, Convert)
0N/A
0N/AFUNC_SCALE_1(ByteGray, ScaleConvert)
0N/AFUNC_SCALE_1(IntArgb, ScaleConvert)
0N/AFUNC_SCALE_1(IntRgb, ScaleConvert)
0N/AFUNC_SCALE_1(ThreeByteBgr, ScaleConvert)
0N/A
0N/AFUNC_INDEXED(ByteIndexed, Convert, BLIT_PARAMS, BLIT_CALL_PARAMS)
0N/AFUNC_INDEXED(ByteIndexedBm, XparOver, BLIT_PARAMS, BLIT_CALL_PARAMS)
0N/AFUNC_INDEXED(ByteIndexedBm, XparBgCopy, BCOPY_PARAMS, BCOPY_CALL_PARAMS)
0N/AFUNC_INDEXED(ByteIndexedBm, ScaleXparOver, SCALE_PARAMS, SCALE_CALL_PARAMS)
0N/AFUNC_INDEXED(ByteIndexed, ScaleConvert, SCALE_PARAMS, SCALE_CALL_PARAMS)
0N/A
0N/A/***************************************************************/
0N/A
0N/Avoid ADD_SUFF(FourByteAbgrPreDrawGlyphListAA)(SurfaceDataRasInfo * pRasInfo,
0N/A ImageRef *glyphs,
0N/A jint totalGlyphs,
0N/A jint fgpixel, jint argbcolor,
0N/A jint clipLeft, jint clipTop,
0N/A jint clipRight, jint clipBottom,
0N/A NativePrimitive * pPrim,
0N/A CompositeInfo * pCompInfo)
0N/A{
0N/A mlib_d64 buff[BUFF_SIZE/2];
0N/A void *pbuff = buff;
0N/A mlib_s32 glyphCounter;
0N/A mlib_s32 scan = pRasInfo->scanStride;
0N/A mlib_u8 *dstBase;
0N/A mlib_s32 solidpix0, solidpix1, solidpix2, solidpix3;
0N/A mlib_s32 i, j;
0N/A mlib_d64 dmix0, dmix1, dd, d0, d1, e0, e1;
0N/A mlib_d64 done, d_half;
0N/A mlib_s32 pix;
0N/A mlib_f32 srcG_f;
0N/A mlib_s32 max_width = BUFF_SIZE;
0N/A
0N/A solidpix0 = fgpixel;
0N/A solidpix1 = fgpixel >> 8;
0N/A solidpix2 = fgpixel >> 16;
0N/A solidpix3 = fgpixel >> 24;
0N/A
0N/A done = vis_to_double_dup(0x7fff7fff);
0N/A d_half = vis_to_double_dup((1 << (16 + 6)) | (1 << 6));
0N/A
0N/A srcG_f = vis_to_float(argbcolor);
300N/A ARGB2ABGR_FL(srcG_f);
0N/A
0N/A for (glyphCounter = 0; glyphCounter < totalGlyphs; glyphCounter++) {
0N/A const jubyte *pixels;
0N/A unsigned int rowBytes;
0N/A int left, top;
0N/A int width, height;
0N/A int right, bottom;
0N/A
0N/A pixels = (const jubyte *) glyphs[glyphCounter].pixels;
0N/A
0N/A if (!pixels) continue;
0N/A
0N/A left = glyphs[glyphCounter].x;
0N/A top = glyphs[glyphCounter].y;
0N/A width = glyphs[glyphCounter].width;
0N/A height = glyphs[glyphCounter].height;
0N/A rowBytes = width;
0N/A right = left + width;
0N/A bottom = top + height;
0N/A if (left < clipLeft) {
0N/A pixels += clipLeft - left;
0N/A left = clipLeft;
0N/A }
0N/A if (top < clipTop) {
0N/A pixels += (clipTop - top) * rowBytes;
0N/A top = clipTop;
0N/A }
0N/A if (right > clipRight) {
0N/A right = clipRight;
0N/A }
0N/A if (bottom > clipBottom) {
0N/A bottom = clipBottom;
0N/A }
0N/A if (right <= left || bottom <= top) {
0N/A continue;
0N/A }
0N/A width = right - left;
0N/A height = bottom - top;
0N/A
0N/A dstBase = pRasInfo->rasBase;
0N/A PTR_ADD(dstBase, top*scan + 4*left);
0N/A
0N/A if (((mlib_s32)dstBase | scan) & 3) {
0N/A if (width > max_width) {
0N/A if (pbuff != buff) {
0N/A mlib_free(pbuff);
0N/A }
0N/A pbuff = mlib_malloc(width*sizeof(mlib_s32));
0N/A if (pbuff == NULL) return;
0N/A max_width = width;
0N/A }
0N/A }
0N/A
0N/A for (j = 0; j < height; j++) {
0N/A mlib_u8 *src = (void*)pixels;
0N/A mlib_s32 *dst, *dst_end;
0N/A mlib_u8 *dst8;
300N/A mlib_u8* dst_start = dstBase;
0N/A
300N/A /*
300N/A * Typically the inner loop here works on Argb input data, an
300N/A * Argb color, and produces ArgbPre output data. To use that
300N/A * standard approach we would need a FourByteAbgrPre to IntArgb
300N/A * converter for the front end and an IntArgbPre to FourByteAbgrPre
300N/A * converter for the back end. The converter exists for the
300N/A * front end, but it is a workaround implementation that uses a 2
300N/A * stage conversion and an intermediate buffer that is allocated
300N/A * on every call. The converter for the back end doesn't really
300N/A * exist, but we could reuse the IntArgb to FourByteAbgr converter
300N/A * to do the same work - at the cost of swapping the components as
300N/A * we copy the data back. All of this is more work than we really
300N/A * need so we use an alternate procedure:
300N/A * - Copy the data into an int-aligned temporary buffer (if needed)
300N/A * - Convert the data from FourByteAbgrPre to IntAbgr by using the
300N/A * IntArgbPre to IntArgb converter in the int-aligned buffer.
300N/A * - Swap the color data to Abgr so that the inner loop goes from
300N/A * IntAbgr data to IntAbgrPre data
300N/A * - Simply copy the IntAbgrPre data back into place.
300N/A */
300N/A if (((mlib_s32)dstBase) & 3) {
300N/A COPY_NA(dstBase, pbuff, width*sizeof(mlib_s32));
300N/A dst_start = pbuff;
300N/A }
300N/A ADD_SUFF(IntArgbPreToIntArgbConvert)(dst_start, pbuff, width, 1,
0N/A pRasInfo, pRasInfo,
0N/A pPrim, pCompInfo);
0N/A
0N/A vis_write_gsr(0 << 3);
0N/A
0N/A dst = pbuff;
0N/A dst_end = dst + width;
0N/A
0N/A if ((mlib_s32)dst & 7) {
0N/A pix = *src++;
0N/A dd = vis_fpadd16(MUL8_VIS(srcG_f, pix), d_half);
0N/A dd = vis_fpadd16(MUL8_VIS(*(mlib_f32*)dst, 255 - pix), dd);
0N/A *(mlib_f32*)dst = vis_fpack16(dd);
0N/A dst++;
0N/A }
0N/A
0N/A#pragma pipeloop(0)
0N/A for (; dst <= (dst_end - 2); dst += 2) {
0N/A dmix0 = vis_freg_pair(((mlib_f32 *)vis_mul8s_tbl)[src[0]],
0N/A ((mlib_f32 *)vis_mul8s_tbl)[src[1]]);
0N/A dmix1 = vis_fpsub16(done, dmix0);
0N/A src += 2;
0N/A
0N/A dd = *(mlib_d64*)dst;
0N/A d0 = vis_fmul8x16al(srcG_f, vis_read_hi(dmix0));
0N/A d1 = vis_fmul8x16al(srcG_f, vis_read_lo(dmix0));
0N/A e0 = vis_fmul8x16al(vis_read_hi(dd), vis_read_hi(dmix1));
0N/A e1 = vis_fmul8x16al(vis_read_lo(dd), vis_read_lo(dmix1));
0N/A d0 = vis_fpadd16(vis_fpadd16(d0, d_half), e0);
0N/A d1 = vis_fpadd16(vis_fpadd16(d1, d_half), e1);
0N/A dd = vis_fpack16_pair(d0, d1);
0N/A
0N/A *(mlib_d64*)dst = dd;
0N/A }
0N/A
0N/A while (dst < dst_end) {
0N/A pix = *src++;
0N/A dd = vis_fpadd16(MUL8_VIS(srcG_f, pix), d_half);
0N/A dd = vis_fpadd16(MUL8_VIS(*(mlib_f32*)dst, 255 - pix), dd);
0N/A *(mlib_f32*)dst = vis_fpack16(dd);
0N/A dst++;
0N/A }
0N/A
300N/A COPY_NA(pbuff, dstBase, width*sizeof(mlib_s32));
0N/A
0N/A src = (void*)pixels;
0N/A dst8 = (void*)dstBase;
0N/A
0N/A#pragma pipeloop(0)
0N/A for (i = 0; i < width; i++) {
0N/A if (src[i] == 255) {
0N/A dst8[4*i ] = solidpix0;
0N/A dst8[4*i + 1] = solidpix1;
0N/A dst8[4*i + 2] = solidpix2;
0N/A dst8[4*i + 3] = solidpix3;
0N/A }
0N/A }
0N/A
0N/A PTR_ADD(dstBase, scan);
0N/A pixels += rowBytes;
0N/A }
0N/A }
0N/A
0N/A if (pbuff != buff) {
0N/A mlib_free(pbuff);
0N/A }
0N/A}
0N/A
0N/A/***************************************************************/
0N/A
0N/A#endif /* JAVA2D_NO_MLIB */