diff --git a/src/share/native/sun/java2d/loops/AlphaMacros.h b/src/share/native/sun/java2d/loops/AlphaMacros.h index a7c0c84c38aa5fe4d2cb4022173342aca78ec979..3053003f455097b02293c95c8712dc9f36b34228 100644 --- a/src/share/native/sun/java2d/loops/AlphaMacros.h +++ b/src/share/native/sun/java2d/loops/AlphaMacros.h @@ -416,7 +416,8 @@ void NAME_SRCOVER_MASKBLIT(SRC, DST) \ MultiplyAndStore ## STRATEGY ## Comps(res, \ srcF, res);\ } \ - if (!(DST ## IsPremultiplied) && resA && \ + if (!(DST ## IsOpaque) && \ + !(DST ## IsPremultiplied) && resA && \ resA < MaxValFor ## STRATEGY) \ { \ DivideAndStore ## STRATEGY ## Comps(res, \ @@ -475,7 +476,8 @@ void NAME_SRCOVER_MASKBLIT(SRC, DST) \ MultiplyAndStore ## STRATEGY ## Comps(res, \ srcF, res); \ } \ - if (!(DST ## IsPremultiplied) && resA && \ + if (!(DST ## IsOpaque) && \ + !(DST ## IsPremultiplied) && resA && \ resA < MaxValFor ## STRATEGY) \ { \ DivideAndStore ## STRATEGY ## Comps(res, res, resA); \ @@ -797,7 +799,8 @@ void NAME_SRCOVER_MASKFILL(TYPE) \ Store ## STRATEGY ## CompsUsingOp(res, +=, tmp); \ } \ } \ - if (!(TYPE ## IsPremultiplied) && resA && \ + if (!(TYPE ## IsOpaque) && \ + !(TYPE ## IsPremultiplied) && resA && \ resA < MaxValFor ## STRATEGY) \ { \ DivideAndStore ## STRATEGY ## Comps(res, res, resA); \ @@ -831,7 +834,8 @@ void NAME_SRCOVER_MASKFILL(TYPE) \ Postload ## STRATEGY ## From ## TYPE(pRas, DstPix, res); \ MultiplyAddAndStore ## STRATEGY ## Comps(res, \ dstF, res, src); \ - if (!(TYPE ## IsPremultiplied) && resA && \ + if (!(TYPE ## IsOpaque) && \ + !(TYPE ## IsPremultiplied) && resA && \ resA < MaxValFor ## STRATEGY) \ { \ DivideAndStore ## STRATEGY ## Comps(res, res, resA); \ diff --git a/src/share/native/sun/java2d/loops/ByteGray.h b/src/share/native/sun/java2d/loops/ByteGray.h index 335a47b7a89ccf0ead6ba0774a801b7c35911444..5cb4bd264cb2b351866028c5298ec0863e46a8df 100644 --- a/src/share/native/sun/java2d/loops/ByteGray.h +++ b/src/share/native/sun/java2d/loops/ByteGray.h @@ -36,6 +36,8 @@ typedef jubyte ByteGrayPixelType; typedef jubyte ByteGrayDataType; +#define ByteGrayIsOpaque 1 + #define ByteGrayPixelStride 1 #define ByteGrayBitsPerPixel 8 diff --git a/src/share/native/sun/java2d/loops/FourByteAbgr.h b/src/share/native/sun/java2d/loops/FourByteAbgr.h index 2af1150f7e703baccc6534076dcc381a73b49076..5f77047d6adf975d4b48d132e064848d8f13515b 100644 --- a/src/share/native/sun/java2d/loops/FourByteAbgr.h +++ b/src/share/native/sun/java2d/loops/FourByteAbgr.h @@ -34,6 +34,8 @@ typedef jint FourByteAbgrPixelType; typedef jubyte FourByteAbgrDataType; +#define FourByteAbgrIsOpaque 0 + #define FourByteAbgrPixelStride 4 #define DeclareFourByteAbgrLoadVars(PREFIX) diff --git a/src/share/native/sun/java2d/loops/FourByteAbgrPre.h b/src/share/native/sun/java2d/loops/FourByteAbgrPre.h index 8b4b9f7e59a6f3982a30be0f942d5176aeeb34ed..c6bde946e574ff8efa12ea1c6c233bf0bc24dafd 100644 --- a/src/share/native/sun/java2d/loops/FourByteAbgrPre.h +++ b/src/share/native/sun/java2d/loops/FourByteAbgrPre.h @@ -34,6 +34,8 @@ typedef jint FourByteAbgrPrePixelType; typedef jubyte FourByteAbgrPreDataType; +#define FourByteAbgrPreIsOpaque 0 + #define FourByteAbgrPrePixelStride 4 #define DeclareFourByteAbgrPreLoadVars(PREFIX) diff --git a/src/share/native/sun/java2d/loops/Index12Gray.h b/src/share/native/sun/java2d/loops/Index12Gray.h index bb583b6ce2b9d4c05541adb8ed1399e0393415ee..f728c14ff5b3e073844976f2690140b0166bd4e5 100644 --- a/src/share/native/sun/java2d/loops/Index12Gray.h +++ b/src/share/native/sun/java2d/loops/Index12Gray.h @@ -37,6 +37,8 @@ typedef jushort Index12GrayPixelType; typedef jushort Index12GrayDataType; +#define Index12GrayIsOpaque 1 + #define Index12GrayPixelStride 2 #define Index12GrayBitsPerPixel 12 diff --git a/src/share/native/sun/java2d/loops/Index8Gray.h b/src/share/native/sun/java2d/loops/Index8Gray.h index 15e2ecdc799026472603e2072cfce0ce7c7253a0..2691863af8185141a0695f16f3f3aec04c643073 100644 --- a/src/share/native/sun/java2d/loops/Index8Gray.h +++ b/src/share/native/sun/java2d/loops/Index8Gray.h @@ -37,6 +37,8 @@ typedef jubyte Index8GrayPixelType; typedef jubyte Index8GrayDataType; +#define Index8GrayIsOpaque 1 + #define Index8GrayPixelStride 1 #define Index8GrayBitsPerPixel 8 diff --git a/src/share/native/sun/java2d/loops/IntArgb.h b/src/share/native/sun/java2d/loops/IntArgb.h index 26aa69a9369dfa7a3c3dd6e40fde676b8c3653c7..cdc8435ced011802a2d1f963fb547571f70c29f2 100644 --- a/src/share/native/sun/java2d/loops/IntArgb.h +++ b/src/share/native/sun/java2d/loops/IntArgb.h @@ -38,6 +38,8 @@ typedef jint IntArgbPixelType; typedef jint IntArgbDataType; +#define IntArgbIsOpaque 0 + #define IntArgbPixelStride 4 #define DeclareIntArgbLoadVars(PREFIX) diff --git a/src/share/native/sun/java2d/loops/IntArgbBm.h b/src/share/native/sun/java2d/loops/IntArgbBm.h index 4a07a98a388ed3b227ee41b985ea599d03a7e82b..201c2ff92b8fe3d18cd8362fafa724b1560e7866 100644 --- a/src/share/native/sun/java2d/loops/IntArgbBm.h +++ b/src/share/native/sun/java2d/loops/IntArgbBm.h @@ -38,6 +38,8 @@ typedef jint IntArgbBmPixelType; typedef jint IntArgbBmDataType; +#define IntArgbBmIsOpaque 0 + #define IntArgbBmPixelStride 4 #define DeclareIntArgbBmLoadVars(PREFIX) diff --git a/src/share/native/sun/java2d/loops/IntArgbPre.h b/src/share/native/sun/java2d/loops/IntArgbPre.h index 9657af26f7fcb5c466e3466cfcfbdc0641bcc30e..14f4b8090427db0f6b5992f592e3efd9a3999c3e 100644 --- a/src/share/native/sun/java2d/loops/IntArgbPre.h +++ b/src/share/native/sun/java2d/loops/IntArgbPre.h @@ -36,6 +36,8 @@ typedef jint IntArgbPrePixelType; typedef jint IntArgbPreDataType; +#define IntArgbPreIsOpaque 0 + #define IntArgbPrePixelStride 4 #define DeclareIntArgbPreLoadVars(PREFIX) diff --git a/src/share/native/sun/java2d/loops/IntBgr.h b/src/share/native/sun/java2d/loops/IntBgr.h index f2f99eba0f9d67febdeb24b6fc5bcaf6bb050f1e..124ee70b7b3479eed7ace23dc8e0a27c3020eba2 100644 --- a/src/share/native/sun/java2d/loops/IntBgr.h +++ b/src/share/native/sun/java2d/loops/IntBgr.h @@ -38,6 +38,8 @@ typedef jint IntBgrPixelType; typedef jint IntBgrDataType; +#define IntBgrIsOpaque 1 + #define IntBgrPixelStride 4 #define DeclareIntBgrLoadVars(PREFIX) diff --git a/src/share/native/sun/java2d/loops/IntRgb.h b/src/share/native/sun/java2d/loops/IntRgb.h index 9fc4d076437bcd64fa0cb9f73511b7f9bfe65e9b..1f74bfe256ce6206a647922864c5e89d2f6e8e7c 100644 --- a/src/share/native/sun/java2d/loops/IntRgb.h +++ b/src/share/native/sun/java2d/loops/IntRgb.h @@ -38,6 +38,8 @@ typedef jint IntRgbPixelType; typedef jint IntRgbDataType; +#define IntRgbIsOpaque 1 + #define IntRgbPixelStride 4 #define DeclareIntRgbLoadVars(PREFIX) diff --git a/src/share/native/sun/java2d/loops/IntRgbx.h b/src/share/native/sun/java2d/loops/IntRgbx.h index e695ac846ee67067949c2de8440b7fc881937d8e..6e774c4f5fdb72dad28c185f63f0d646c81225ff 100644 --- a/src/share/native/sun/java2d/loops/IntRgbx.h +++ b/src/share/native/sun/java2d/loops/IntRgbx.h @@ -36,6 +36,8 @@ typedef jint IntRgbxPixelType; typedef jint IntRgbxDataType; +#define IntRgbxIsOpaque 1 + #define IntRgbxPixelStride 4 #define DeclareIntRgbxLoadVars(PREFIX) diff --git a/src/share/native/sun/java2d/loops/LoopMacros.h b/src/share/native/sun/java2d/loops/LoopMacros.h index 45199c81ecba6d07962200bd5918d6292549b3b9..f009404648cd00b4258c30dbc47198418b05525c 100644 --- a/src/share/native/sun/java2d/loops/LoopMacros.h +++ b/src/share/native/sun/java2d/loops/LoopMacros.h @@ -1610,8 +1610,12 @@ void NAME_SOLID_DRAWGLYPHLIST(DST)(SurfaceDataRasInfo *pRasInfo, \ MUL8(SRC_PREFIX ## A, mixValSrc); \ MultMultAddAndStore4ByteArgbComps(dst, mixValDst, dst, \ mixValSrc, SRC_PREFIX); \ - Store ## DST ## From4ByteArgb(DST_PTR, pix, PIXEL_INDEX, \ - dstA, dstR, dstG, dstB); \ + if (!(DST ## IsOpaque) && \ + !(DST ## IsPremultiplied) && dstA && dstA < 255) { \ + DivideAndStore4ByteArgbComps(dst, dst, dstA); \ + } \ + Store ## DST ## From4ByteArgbComps(DST_PTR, pix, \ + PIXEL_INDEX, dst); \ } else { \ Store ## DST ## PixelData(DST_PTR, PIXEL_INDEX, \ FG_PIXEL, PREFIX); \ @@ -1793,8 +1797,12 @@ void NAME_SOLID_DRAWGLYPHLISTAA(DST)(SurfaceDataRasInfo *pRasInfo, \ dstR = gammaLut[dstR]; \ dstG = gammaLut[dstG]; \ dstB = gammaLut[dstB]; \ - Store ## DST ## From4ByteArgb(DST_PTR, pix, PIXEL_INDEX, \ - dstA, dstR, dstG, dstB); \ + if (!(DST ## IsOpaque) && \ + !(DST ## IsPremultiplied) && dstA && dstA < 255) { \ + DivideAndStore4ByteArgbComps(dst, dst, dstA); \ + } \ + Store ## DST ## From4ByteArgbComps(DST_PTR, pix, \ + PIXEL_INDEX, dst); \ } else { \ Store ## DST ## PixelData(DST_PTR, PIXEL_INDEX, \ FG_PIXEL, PREFIX); \ diff --git a/src/share/native/sun/java2d/loops/ThreeByteBgr.h b/src/share/native/sun/java2d/loops/ThreeByteBgr.h index 7bb4944f520726cd44de380e8bb244ea783f6528..16641c8bc89ae64d06b81dcee81e00204fcfd4be 100644 --- a/src/share/native/sun/java2d/loops/ThreeByteBgr.h +++ b/src/share/native/sun/java2d/loops/ThreeByteBgr.h @@ -34,6 +34,8 @@ typedef jint ThreeByteBgrPixelType; typedef jubyte ThreeByteBgrDataType; +#define ThreeByteBgrIsOpaque 1 + #define ThreeByteBgrPixelStride 3 #define DeclareThreeByteBgrLoadVars(PREFIX) diff --git a/src/share/native/sun/java2d/loops/Ushort4444Argb.h b/src/share/native/sun/java2d/loops/Ushort4444Argb.h index 216f521b297f33610df511d9e42f32e8575cc620..3eac497c29289dd31701167be81bea5ea9700f57 100644 --- a/src/share/native/sun/java2d/loops/Ushort4444Argb.h +++ b/src/share/native/sun/java2d/loops/Ushort4444Argb.h @@ -34,6 +34,8 @@ typedef jushort Ushort4444ArgbPixelType; typedef jushort Ushort4444ArgbDataType; +#define Ushort4444ArgbIsOpaque 0 + #define Ushort4444ArgbPixelStride 2 #define DeclareUshort4444ArgbLoadVars(PREFIX) diff --git a/src/share/native/sun/java2d/loops/Ushort555Rgb.h b/src/share/native/sun/java2d/loops/Ushort555Rgb.h index 5c59c46da30d18d79ef561cb7460a44170878890..e52516a958f8b5e28ffc3b03c567e633088fbb5d 100644 --- a/src/share/native/sun/java2d/loops/Ushort555Rgb.h +++ b/src/share/native/sun/java2d/loops/Ushort555Rgb.h @@ -34,6 +34,8 @@ typedef jushort Ushort555RgbPixelType; typedef jushort Ushort555RgbDataType; +#define Ushort555RgbIsOpaque 1 + #define Ushort555RgbPixelStride 2 #define DeclareUshort555RgbLoadVars(PREFIX) diff --git a/src/share/native/sun/java2d/loops/Ushort555Rgbx.h b/src/share/native/sun/java2d/loops/Ushort555Rgbx.h index 4586ba23829f980a666e5983dd49a54509d2b544..e517e2feddf2d9d77ecf28ff3f0606c2b8f25610 100644 --- a/src/share/native/sun/java2d/loops/Ushort555Rgbx.h +++ b/src/share/native/sun/java2d/loops/Ushort555Rgbx.h @@ -34,6 +34,8 @@ typedef jushort Ushort555RgbxPixelType; typedef jushort Ushort555RgbxDataType; +#define Ushort555RgbxIsOpaque 1 + #define Ushort555RgbxPixelStride 2 #define DeclareUshort555RgbxLoadVars(PREFIX) diff --git a/src/share/native/sun/java2d/loops/Ushort565Rgb.h b/src/share/native/sun/java2d/loops/Ushort565Rgb.h index 68008b3a500f0034648de6e2273f783a9dd5a723..2571b9fe442286788e5a2c6af5eec920a6ca01fe 100644 --- a/src/share/native/sun/java2d/loops/Ushort565Rgb.h +++ b/src/share/native/sun/java2d/loops/Ushort565Rgb.h @@ -34,6 +34,8 @@ typedef jushort Ushort565RgbPixelType; typedef jushort Ushort565RgbDataType; +#define Ushort565RgbIsOpaque 1 + #define Ushort565RgbPixelStride 2 #define DeclareUshort565RgbLoadVars(PREFIX) diff --git a/src/share/native/sun/java2d/loops/UshortGray.h b/src/share/native/sun/java2d/loops/UshortGray.h index 89c65cf41fa163ec056a2d48aaf11718e953b678..8370af998093b53d1348f2cfb09dba9ffe1f4d40 100644 --- a/src/share/native/sun/java2d/loops/UshortGray.h +++ b/src/share/native/sun/java2d/loops/UshortGray.h @@ -36,6 +36,8 @@ typedef jushort UshortGrayPixelType; typedef jushort UshortGrayDataType; +#define UshortGrayIsOpaque 1 + #define UshortGrayPixelStride 2 #define UshortGrayBitsPerPixel 16 diff --git a/src/solaris/native/sun/java2d/loops/vis_FourByteAbgr.c b/src/solaris/native/sun/java2d/loops/vis_FourByteAbgr.c index 2745801a1815cec1adccda2bfe793527eb42dc50..75ef33638011c8b0e124bbd2de960a1de99cc221 100644 --- a/src/solaris/native/sun/java2d/loops/vis_FourByteAbgr.c +++ b/src/solaris/native/sun/java2d/loops/vis_FourByteAbgr.c @@ -1936,6 +1936,7 @@ void ADD_SUFF(FourByteAbgrDrawGlyphListAA)(SurfaceDataRasInfo * pRasInfo, for (j = 0; j < height; j++) { mlib_u8 *src = (void*)pixels; mlib_s32 *dst, *dst_end; + mlib_u8 *dst_start; if ((mlib_s32)dstBase & 3) { COPY_NA(dstBase, pbuff, width*sizeof(mlib_s32)); @@ -1943,8 +1944,14 @@ void ADD_SUFF(FourByteAbgrDrawGlyphListAA)(SurfaceDataRasInfo * pRasInfo, } else { dst = (void*)dstBase; } + dst_start = (void*)dst; dst_end = dst + width; + /* Need to reset the GSR from the values set by the + * convert call near the end of this loop. + */ + vis_write_gsr(7 << 0); + if ((mlib_s32)dst & 7) { pix = *src++; dd = vis_fpadd16(MUL8_VIS(srcG_f, pix), d_half); @@ -1984,8 +1991,13 @@ void ADD_SUFF(FourByteAbgrDrawGlyphListAA)(SurfaceDataRasInfo * pRasInfo, dst++; } + ADD_SUFF(IntArgbPreToIntArgbConvert)(dst_start, dst_start, + width, 1, + pRasInfo, pRasInfo, + pPrim, pCompInfo); + if ((mlib_s32)dstBase & 3) { - COPY_NA(pbuff, dstBase, width*sizeof(mlib_s32)); + COPY_NA(dst_start, dstBase, width*sizeof(mlib_s32)); } PTR_ADD(dstBase, scan); diff --git a/src/solaris/native/sun/java2d/loops/vis_FourByteAbgrPre.c b/src/solaris/native/sun/java2d/loops/vis_FourByteAbgrPre.c index 6e5074e79ac1fc73cee928efae4711fcd6ab0476..aab22666746a74c166b715e6c84402fd5cbf75ad 100644 --- a/src/solaris/native/sun/java2d/loops/vis_FourByteAbgrPre.c +++ b/src/solaris/native/sun/java2d/loops/vis_FourByteAbgrPre.c @@ -181,6 +181,7 @@ void ADD_SUFF(FourByteAbgrPreDrawGlyphListAA)(SurfaceDataRasInfo * pRasInfo, d_half = vis_to_double_dup((1 << (16 + 6)) | (1 << 6)); srcG_f = vis_to_float(argbcolor); + ARGB2ABGR_FL(srcG_f); for (glyphCounter = 0; glyphCounter < totalGlyphs; glyphCounter++) { const jubyte *pixels; @@ -238,8 +239,33 @@ void ADD_SUFF(FourByteAbgrPreDrawGlyphListAA)(SurfaceDataRasInfo * pRasInfo, mlib_u8 *src = (void*)pixels; mlib_s32 *dst, *dst_end; mlib_u8 *dst8; - - ADD_SUFF(FourByteAbgrPreToIntArgbConvert)(dstBase, pbuff, width, 1, + mlib_u8* dst_start = dstBase; + + /* + * Typically the inner loop here works on Argb input data, an + * Argb color, and produces ArgbPre output data. To use that + * standard approach we would need a FourByteAbgrPre to IntArgb + * converter for the front end and an IntArgbPre to FourByteAbgrPre + * converter for the back end. The converter exists for the + * front end, but it is a workaround implementation that uses a 2 + * stage conversion and an intermediate buffer that is allocated + * on every call. The converter for the back end doesn't really + * exist, but we could reuse the IntArgb to FourByteAbgr converter + * to do the same work - at the cost of swapping the components as + * we copy the data back. All of this is more work than we really + * need so we use an alternate procedure: + * - Copy the data into an int-aligned temporary buffer (if needed) + * - Convert the data from FourByteAbgrPre to IntAbgr by using the + * IntArgbPre to IntArgb converter in the int-aligned buffer. + * - Swap the color data to Abgr so that the inner loop goes from + * IntAbgr data to IntAbgrPre data + * - Simply copy the IntAbgrPre data back into place. + */ + if (((mlib_s32)dstBase) & 3) { + COPY_NA(dstBase, pbuff, width*sizeof(mlib_s32)); + dst_start = pbuff; + } + ADD_SUFF(IntArgbPreToIntArgbConvert)(dst_start, pbuff, width, 1, pRasInfo, pRasInfo, pPrim, pCompInfo); @@ -283,9 +309,7 @@ void ADD_SUFF(FourByteAbgrPreDrawGlyphListAA)(SurfaceDataRasInfo * pRasInfo, dst++; } - ADD_SUFF(IntArgbToFourByteAbgrPreConvert)(pbuff, dstBase, width, 1, - pRasInfo, pRasInfo, - pPrim, pCompInfo); + COPY_NA(pbuff, dstBase, width*sizeof(mlib_s32)); src = (void*)pixels; dst8 = (void*)dstBase; diff --git a/src/solaris/native/sun/java2d/loops/vis_IntArgb.c b/src/solaris/native/sun/java2d/loops/vis_IntArgb.c index 69fc04339c85d6e99bff75851cdbfd039f61d265..72bde3a6b20568f79143c1fdef4c10c3002ca134 100644 --- a/src/solaris/native/sun/java2d/loops/vis_IntArgb.c +++ b/src/solaris/native/sun/java2d/loops/vis_IntArgb.c @@ -428,6 +428,11 @@ void ADD_SUFF(IntArgbDrawGlyphListAA)(GLYPH_LIST_PARAMS) dst = (void*)dstBase; dst_end = dst + width; + /* Clearing the Graphics Status Register is necessary otherwise + * left over scale settings affect the pack instructions. + */ + vis_write_gsr(0 << 3); + if ((mlib_s32)dst & 7) { pix = *src++; dd = vis_fpadd16(MUL8_VIS(srcG_f, pix), d_half); @@ -467,6 +472,9 @@ void ADD_SUFF(IntArgbDrawGlyphListAA)(GLYPH_LIST_PARAMS) dst++; } + ADD_SUFF(IntArgbPreToIntArgbConvert)(dstBase, dstBase, width, 1, + pRasInfo, pRasInfo, + pPrim, pCompInfo); PTR_ADD(dstBase, scan); pixels += rowBytes; } diff --git a/src/solaris/native/sun/java2d/loops/vis_IntArgbPre.c b/src/solaris/native/sun/java2d/loops/vis_IntArgbPre.c index cd773365ea85c0c33792a7164448ff496709efcd..8c4f4f583f676bfb425fbfa2ae1b2ac890328779 100644 --- a/src/solaris/native/sun/java2d/loops/vis_IntArgbPre.c +++ b/src/solaris/native/sun/java2d/loops/vis_IntArgbPre.c @@ -1193,10 +1193,6 @@ void ADD_SUFF(IntArgbPreDrawGlyphListAA)(SurfaceDataRasInfo * pRasInfo, dst++; } - ADD_SUFF(IntArgbToIntArgbPreConvert)(dstBase, dstBase, width, 1, - pRasInfo, pRasInfo, - pPrim, pCompInfo); - PTR_ADD(dstBase, scan); pixels += rowBytes; } diff --git a/test/java/awt/Graphics2D/DrawString/AlphaSurfaceText.java b/test/java/awt/Graphics2D/DrawString/AlphaSurfaceText.java new file mode 100644 index 0000000000000000000000000000000000000000..219b5e3565bd74dca9bbaa07504410e714ee854a --- /dev/null +++ b/test/java/awt/Graphics2D/DrawString/AlphaSurfaceText.java @@ -0,0 +1,106 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6679308 + * @summary test drawing to Alpha surfaces + */ + +import java.awt.*; +import java.awt.image.*; + +public class AlphaSurfaceText { + + int wid=400, hgt=200; + + public AlphaSurfaceText(int biType, Color c) { + BufferedImage opaquebi0 = + new BufferedImage(wid, hgt, BufferedImage.TYPE_INT_RGB); + drawText(opaquebi0, c); + + BufferedImage alphabi = new BufferedImage(wid, hgt, biType); + drawText(alphabi, c); + BufferedImage opaquebi1 = + new BufferedImage(wid, hgt, BufferedImage.TYPE_INT_RGB); + Graphics2D g2d = opaquebi1.createGraphics(); + g2d.drawImage(alphabi, 0, 0, null); + compare(opaquebi0, opaquebi1, biType, c); + } + + private void drawText(BufferedImage bi, Color c) { + Graphics2D g = bi.createGraphics(); + g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, + RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + g.setColor(c); + g.setFont(new Font("sansserif", Font.PLAIN, 70)); + g.drawString("Hello!", 20, 100); + g.setFont(new Font("sansserif", Font.PLAIN, 12)); + g.drawString("Hello!", 20, 130); + g.setFont(new Font("sansserif", Font.PLAIN, 10)); + g.drawString("Hello!", 20, 150); + } + + // Need to allow for minimal rounding error, so allow each component + // to differ by 1. + void compare(BufferedImage bi0, BufferedImage bi1, int biType, Color c) { + for (int x=0; x> 16; + int r1 = (rgb1 & 0xff0000) >> 16; + int rdiff = r0-r1; if (rdiff<0) rdiff = -rdiff; + int g0 = (rgb0 & 0x00ff00) >> 8; + int g1 = (rgb1 & 0x00ff00) >> 8; + int gdiff = g0-g1; if (gdiff<0) gdiff = -gdiff; + int b0 = (rgb0 & 0x0000ff); + int b1 = (rgb1 & 0x0000ff); + int bdiff = b0-b1; if (bdiff<0) bdiff = -bdiff; + if (rdiff > 1 || gdiff > 1 || bdiff > 1) { + throw new RuntimeException( + "Images differ for type "+biType + " col="+c + + " at x=" + x + " y="+ y + " " + + Integer.toHexString(rgb0) + " vs " + + Integer.toHexString(rgb1)); + } + } + } + + } + public static void main(String[] args) { + new AlphaSurfaceText(BufferedImage.TYPE_INT_ARGB, Color.white); + new AlphaSurfaceText(BufferedImage.TYPE_INT_ARGB, Color.red); + new AlphaSurfaceText(BufferedImage.TYPE_INT_ARGB, Color.blue); + new AlphaSurfaceText(BufferedImage.TYPE_INT_ARGB_PRE, Color.white); + new AlphaSurfaceText(BufferedImage.TYPE_INT_ARGB_PRE, Color.red); + new AlphaSurfaceText(BufferedImage.TYPE_INT_ARGB_PRE, Color.blue); + new AlphaSurfaceText(BufferedImage.TYPE_4BYTE_ABGR, Color.white); + new AlphaSurfaceText(BufferedImage.TYPE_4BYTE_ABGR, Color.red); + new AlphaSurfaceText(BufferedImage.TYPE_4BYTE_ABGR, Color.blue); + new AlphaSurfaceText(BufferedImage.TYPE_4BYTE_ABGR_PRE, Color.white); + new AlphaSurfaceText(BufferedImage.TYPE_4BYTE_ABGR_PRE, Color.red); + new AlphaSurfaceText(BufferedImage.TYPE_4BYTE_ABGR_PRE, Color.blue); + } +}