From c672506f950461389bd2ecfd887650086d77e16d Mon Sep 17 00:00:00 2001 From: Phil Race Date: Mon, 28 Apr 2008 15:57:46 -0700 Subject: [PATCH] 6679308: Poor text rendering on translucent image Reviewed-by: flar, campbell --- .../native/sun/java2d/loops/AlphaMacros.h | 12 +- .../share/native/sun/java2d/loops/ByteGray.h | 2 + .../native/sun/java2d/loops/FourByteAbgr.h | 2 + .../native/sun/java2d/loops/FourByteAbgrPre.h | 2 + .../native/sun/java2d/loops/Index12Gray.h | 2 + .../native/sun/java2d/loops/Index8Gray.h | 2 + .../share/native/sun/java2d/loops/IntArgb.h | 2 + .../share/native/sun/java2d/loops/IntArgbBm.h | 2 + .../native/sun/java2d/loops/IntArgbPre.h | 2 + .../share/native/sun/java2d/loops/IntBgr.h | 2 + .../share/native/sun/java2d/loops/IntRgb.h | 2 + .../share/native/sun/java2d/loops/IntRgbx.h | 2 + .../native/sun/java2d/loops/LoopMacros.h | 16 ++- .../native/sun/java2d/loops/ThreeByteBgr.h | 2 + .../native/sun/java2d/loops/Ushort4444Argb.h | 2 + .../native/sun/java2d/loops/Ushort555Rgb.h | 2 + .../native/sun/java2d/loops/Ushort555Rgbx.h | 2 + .../native/sun/java2d/loops/Ushort565Rgb.h | 2 + .../native/sun/java2d/loops/UshortGray.h | 2 + .../sun/java2d/loops/vis_FourByteAbgr.c | 14 ++- .../sun/java2d/loops/vis_FourByteAbgrPre.c | 32 +++++- .../native/sun/java2d/loops/vis_IntArgb.c | 8 ++ .../native/sun/java2d/loops/vis_IntArgbPre.c | 4 - .../DrawString/AlphaSurfaceText.java | 106 ++++++++++++++++++ 24 files changed, 209 insertions(+), 17 deletions(-) create mode 100644 jdk/test/java/awt/Graphics2D/DrawString/AlphaSurfaceText.java diff --git a/jdk/src/share/native/sun/java2d/loops/AlphaMacros.h b/jdk/src/share/native/sun/java2d/loops/AlphaMacros.h index a7c0c84c38a..3053003f455 100644 --- a/jdk/src/share/native/sun/java2d/loops/AlphaMacros.h +++ b/jdk/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/jdk/src/share/native/sun/java2d/loops/ByteGray.h b/jdk/src/share/native/sun/java2d/loops/ByteGray.h index 335a47b7a89..5cb4bd264cb 100644 --- a/jdk/src/share/native/sun/java2d/loops/ByteGray.h +++ b/jdk/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/jdk/src/share/native/sun/java2d/loops/FourByteAbgr.h b/jdk/src/share/native/sun/java2d/loops/FourByteAbgr.h index 2af1150f7e7..5f77047d6ad 100644 --- a/jdk/src/share/native/sun/java2d/loops/FourByteAbgr.h +++ b/jdk/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/jdk/src/share/native/sun/java2d/loops/FourByteAbgrPre.h b/jdk/src/share/native/sun/java2d/loops/FourByteAbgrPre.h index 8b4b9f7e59a..c6bde946e57 100644 --- a/jdk/src/share/native/sun/java2d/loops/FourByteAbgrPre.h +++ b/jdk/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/jdk/src/share/native/sun/java2d/loops/Index12Gray.h b/jdk/src/share/native/sun/java2d/loops/Index12Gray.h index bb583b6ce2b..f728c14ff5b 100644 --- a/jdk/src/share/native/sun/java2d/loops/Index12Gray.h +++ b/jdk/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/jdk/src/share/native/sun/java2d/loops/Index8Gray.h b/jdk/src/share/native/sun/java2d/loops/Index8Gray.h index 15e2ecdc799..2691863af81 100644 --- a/jdk/src/share/native/sun/java2d/loops/Index8Gray.h +++ b/jdk/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/jdk/src/share/native/sun/java2d/loops/IntArgb.h b/jdk/src/share/native/sun/java2d/loops/IntArgb.h index 26aa69a9369..cdc8435ced0 100644 --- a/jdk/src/share/native/sun/java2d/loops/IntArgb.h +++ b/jdk/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/jdk/src/share/native/sun/java2d/loops/IntArgbBm.h b/jdk/src/share/native/sun/java2d/loops/IntArgbBm.h index 4a07a98a388..201c2ff92b8 100644 --- a/jdk/src/share/native/sun/java2d/loops/IntArgbBm.h +++ b/jdk/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/jdk/src/share/native/sun/java2d/loops/IntArgbPre.h b/jdk/src/share/native/sun/java2d/loops/IntArgbPre.h index 9657af26f7f..14f4b809042 100644 --- a/jdk/src/share/native/sun/java2d/loops/IntArgbPre.h +++ b/jdk/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/jdk/src/share/native/sun/java2d/loops/IntBgr.h b/jdk/src/share/native/sun/java2d/loops/IntBgr.h index f2f99eba0f9..124ee70b7b3 100644 --- a/jdk/src/share/native/sun/java2d/loops/IntBgr.h +++ b/jdk/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/jdk/src/share/native/sun/java2d/loops/IntRgb.h b/jdk/src/share/native/sun/java2d/loops/IntRgb.h index 9fc4d076437..1f74bfe256c 100644 --- a/jdk/src/share/native/sun/java2d/loops/IntRgb.h +++ b/jdk/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/jdk/src/share/native/sun/java2d/loops/IntRgbx.h b/jdk/src/share/native/sun/java2d/loops/IntRgbx.h index e695ac846ee..6e774c4f5fd 100644 --- a/jdk/src/share/native/sun/java2d/loops/IntRgbx.h +++ b/jdk/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/jdk/src/share/native/sun/java2d/loops/LoopMacros.h b/jdk/src/share/native/sun/java2d/loops/LoopMacros.h index 45199c81ecb..f009404648c 100644 --- a/jdk/src/share/native/sun/java2d/loops/LoopMacros.h +++ b/jdk/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/jdk/src/share/native/sun/java2d/loops/ThreeByteBgr.h b/jdk/src/share/native/sun/java2d/loops/ThreeByteBgr.h index 7bb4944f520..16641c8bc89 100644 --- a/jdk/src/share/native/sun/java2d/loops/ThreeByteBgr.h +++ b/jdk/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/jdk/src/share/native/sun/java2d/loops/Ushort4444Argb.h b/jdk/src/share/native/sun/java2d/loops/Ushort4444Argb.h index 216f521b297..3eac497c292 100644 --- a/jdk/src/share/native/sun/java2d/loops/Ushort4444Argb.h +++ b/jdk/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/jdk/src/share/native/sun/java2d/loops/Ushort555Rgb.h b/jdk/src/share/native/sun/java2d/loops/Ushort555Rgb.h index 5c59c46da30..e52516a958f 100644 --- a/jdk/src/share/native/sun/java2d/loops/Ushort555Rgb.h +++ b/jdk/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/jdk/src/share/native/sun/java2d/loops/Ushort555Rgbx.h b/jdk/src/share/native/sun/java2d/loops/Ushort555Rgbx.h index 4586ba23829..e517e2feddf 100644 --- a/jdk/src/share/native/sun/java2d/loops/Ushort555Rgbx.h +++ b/jdk/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/jdk/src/share/native/sun/java2d/loops/Ushort565Rgb.h b/jdk/src/share/native/sun/java2d/loops/Ushort565Rgb.h index 68008b3a500..2571b9fe442 100644 --- a/jdk/src/share/native/sun/java2d/loops/Ushort565Rgb.h +++ b/jdk/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/jdk/src/share/native/sun/java2d/loops/UshortGray.h b/jdk/src/share/native/sun/java2d/loops/UshortGray.h index 89c65cf41fa..8370af99809 100644 --- a/jdk/src/share/native/sun/java2d/loops/UshortGray.h +++ b/jdk/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/jdk/src/solaris/native/sun/java2d/loops/vis_FourByteAbgr.c b/jdk/src/solaris/native/sun/java2d/loops/vis_FourByteAbgr.c index 2745801a181..75ef3363801 100644 --- a/jdk/src/solaris/native/sun/java2d/loops/vis_FourByteAbgr.c +++ b/jdk/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/jdk/src/solaris/native/sun/java2d/loops/vis_FourByteAbgrPre.c b/jdk/src/solaris/native/sun/java2d/loops/vis_FourByteAbgrPre.c index 6e5074e79ac..aab22666746 100644 --- a/jdk/src/solaris/native/sun/java2d/loops/vis_FourByteAbgrPre.c +++ b/jdk/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; + mlib_u8* dst_start = dstBase; - ADD_SUFF(FourByteAbgrPreToIntArgbConvert)(dstBase, pbuff, width, 1, + /* + * 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/jdk/src/solaris/native/sun/java2d/loops/vis_IntArgb.c b/jdk/src/solaris/native/sun/java2d/loops/vis_IntArgb.c index 69fc04339c8..72bde3a6b20 100644 --- a/jdk/src/solaris/native/sun/java2d/loops/vis_IntArgb.c +++ b/jdk/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/jdk/src/solaris/native/sun/java2d/loops/vis_IntArgbPre.c b/jdk/src/solaris/native/sun/java2d/loops/vis_IntArgbPre.c index cd773365ea8..8c4f4f583f6 100644 --- a/jdk/src/solaris/native/sun/java2d/loops/vis_IntArgbPre.c +++ b/jdk/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/jdk/test/java/awt/Graphics2D/DrawString/AlphaSurfaceText.java b/jdk/test/java/awt/Graphics2D/DrawString/AlphaSurfaceText.java new file mode 100644 index 00000000000..219b5e3565b --- /dev/null +++ b/jdk/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); + } +}