1 7 package com.sun.java.swing.plaf.nimbus; 8 9 import java.awt.image.BufferedImage ; 10 import java.awt.image.Raster ; 11 import java.awt.image.WritableRaster ; 12 import java.util.Arrays ; 13 14 20 class DropShadowEffect extends ShadowEffect { 21 22 25 32 EffectType getEffectType() { 33 return EffectType.UNDER; 34 } 35 36 48 BufferedImage applyEffect(BufferedImage src, BufferedImage dst, int w, int h) { 49 double trangleAngle = Math.toRadians(angle - 90); 51 int offsetX = (int) (Math.sin(trangleAngle) * distance); 52 int offsetY = (int) (Math.cos(trangleAngle) * distance); 53 int tmpOffX = offsetX + size; 55 int tmpOffY = offsetX + size; 56 int tmpW = w + offsetX + size + size; 57 int tmpH = h + offsetX + size; 58 int[] lineBuf = getArrayCache().getTmpIntArray(w); 60 byte[] tmpBuf1 = getArrayCache().getTmpByteArray1(tmpW * tmpH); 61 Arrays.fill(tmpBuf1, (byte) 0x00); 62 byte[] tmpBuf2 = getArrayCache().getTmpByteArray2(tmpW * tmpH); 63 Raster srcRaster = src.getRaster(); 65 for (int y = 0; y < h; y++) { 66 int dy = (y + tmpOffY); 67 int offset = dy * tmpW; 68 srcRaster.getDataElements(0, y, w, 1, lineBuf); 69 for (int x = 0; x < w; x++) { 70 int dx = x + tmpOffX; 71 tmpBuf1[offset + dx] = (byte) ((lineBuf[x] & 0xFF000000) >>> 24); 72 } 73 } 74 float[] kernel = EffectUtils.createGaussianKernel(size); 76 EffectUtils.blur(tmpBuf1, tmpBuf2, tmpW, tmpH, kernel, size); EffectUtils.blur(tmpBuf2, tmpBuf1, tmpH, tmpW, kernel, size); float spread = Math.min(1 / (1 - (0.01f * this.spread)), 255); 80 for (int i = 0; i < tmpBuf1.length; i++) { 81 int val = (int) (((int) tmpBuf1[i] & 0xFF) * spread); 82 tmpBuf1[i] = (val > 255) ? (byte) 0xFF : (byte) val; 83 } 84 if (dst == null) dst = EffectUtils.createCompatibleTranslucentImage(w, h); 86 WritableRaster shadowRaster = dst.getRaster(); 87 int red = color.getRed(), green = color.getGreen(), blue = color.getBlue(); 88 for (int y = 0; y < h; y++) { 89 int srcY = y + tmpOffY; 90 int shadowOffset = (srcY - offsetY) * tmpW; 91 for (int x = 0; x < w; x++) { 92 int srcX = x + tmpOffX; 93 lineBuf[x] = tmpBuf1[shadowOffset + (srcX - offsetX)] << 24 | red << 16 | green << 8 | blue; 94 } 95 shadowRaster.setDataElements(0, y, w, 1, lineBuf); 96 } 97 return dst; 98 } 99 } 100 | Popular Tags |