📄 alphablender.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: AlphaBlender.java * * Copyright (c) 2006 Sun Microsystems and Static Free Software * * Electric(tm) is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * Electric(tm) 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 for more details. * * You should have received a copy of the GNU General Public License * along with Electric(tm); see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, Mass 02111-1307, USA. */package com.sun.electric.tool.user.redisplay;import com.sun.electric.technology.Layer;import com.sun.electric.tool.user.ui.EditWindow;import java.awt.Color;import java.util.ArrayList;import java.util.List;import java.util.Map;/** * Class to perform alpha blending for LayerDrawing. */class AlphaBlender { private Color background; private int[] opaqueData; /** Creates a new instance of AlphaBlender */ public AlphaBlender() { } private static final int SCALE_SH = 8; private static final int SCALE = 1 << SCALE_SH; private AlphaBlendGroup[] groups; private int[][] layerBits;// private int m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17, m18, m19, m20, m21, m22, m23, m24, m25, m26, m27, m28, m29, m30, m31; private int r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17, r18, r19, r20, r21, r22, r23, r24, r25, r26, r27, r28, r29, r30, r31; private int g0, g1, g2, g3, g4, g5, g6, g7, g8, g9, g10, g11, g12, g13, g14, g15, g16, g17, g18, g19, g20, g21, g22, g23, g24, g25, g26, g27, g28, g29, g30, g31; private int b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31; void init(int backgroundValue, List<AbstractDrawing.LayerColor> blendingOrder, Map<Layer,int[]> layerBits) { background = new Color(backgroundValue); ArrayList<int[]> bits = new ArrayList<int[]>(); ArrayList<AbstractDrawing.LayerColor> colors = new ArrayList<AbstractDrawing.LayerColor>(); for (AbstractDrawing.LayerColor layerColor: blendingOrder) { int[] b = layerBits.get(layerColor.layer); if (b == null) continue; bits.add(b); colors.add(layerColor); } this.layerBits = bits.toArray(new int[bits.size()][]); groups = new AlphaBlendGroup[bits.size()/13 + 1]; int k = 0; for (int i = 0; i < groups.length; i++) { int l = (bits.size() - k) / (groups.length - i); groups[i] = new AlphaBlendGroup(this.layerBits, colors, k, l, i == 0); k += l; } } // private void unpackBytes(int index) {// // unpack pixels// int pixel0 = 0, pixel1 = 0, pixel2 = 0, pixel3 = 0, pixel4 = 0, pixel5 = 0, pixel6 = 0, pixel7 = 0;// int pixel8 = 0, pixel9 = 0, pixel10 = 0, pixel11 = 0, pixel12 = 0, pixel13 = 0, pixel14 = 0, pixel15 = 0;// int pixel16 = 0, pixel17 = 0, pixel18 = 0, pixel19 = 0, pixel20 = 0, pixel21 = 0, pixel22 = 0, pixel23 = 0;// int pixel24 = 0, pixel25 = 0, pixel26 = 0, pixel27 = 0, pixel28 = 0, pixel29 = 0, pixel30 = 0, pixel31 = 0;// for (int i = 0; i < layerBits.length; i++) {// int value = layerBits[i][index];// if (value == 0) continue;// pixel0 |= (value & 1) << i;// pixel1 |= ((value >> 1) & 1) << i;// pixel2 |= ((value >> 2) & 1) << i;// pixel3 |= ((value >> 3) & 1) << i;// pixel4 |= ((value >> 4) & 1) << i;// pixel5 |= ((value >> 5) & 1) << i;// pixel6 |= ((value >> 6) & 1) << i;// pixel7 |= ((value >> 7) & 1) << i;// pixel8 |= ((value >> 8) & 1) << i;// pixel9 |= ((value >> 9) & 1) << i;// pixel10 |= ((value >> 10) & 1) << i;// pixel11 |= ((value >> 11) & 1) << i;// pixel12 |= ((value >> 12) & 1) << i;// pixel13 |= ((value >> 13) & 1) << i;// pixel14 |= ((value >> 14) & 1) << i;// pixel15 |= ((value >> 15) & 1) << i;// pixel16 |= ((value >> 16) & 1) << i;// pixel17 |= ((value >> 17) & 1) << i;// pixel18 |= ((value >> 18) & 1) << i;// pixel19 |= ((value >> 19) & 1) << i;// pixel20 |= ((value >> 20) & 1) << i;// pixel21 |= ((value >> 21) & 1) << i;// pixel22 |= ((value >> 22) & 1) << i;// pixel23 |= ((value >> 23) & 1) << i;// pixel24 |= ((value >> 24) & 1) << i;// pixel25 |= ((value >> 25) & 1) << i;// pixel26 |= ((value >> 26) & 1) << i;// pixel27 |= ((value >> 27) & 1) << i;// pixel28 |= ((value >> 28) & 1) << i;// pixel29 |= ((value >> 29) & 1) << i;// pixel30 |= ((value >> 30) & 1) << i;// pixel31 |= ((value >> 31) & 1) << i;// }// m0 = pixel0;// m1 = pixel1;// m2 = pixel2;// m3 = pixel3;// m4 = pixel4;// m5 = pixel5;// m6 = pixel6;// m7 = pixel7;// m8 = pixel8;// m9 = pixel9;// m10 = pixel10;// m11 = pixel11;// m12 = pixel12;// m13 = pixel13;// m14 = pixel14;// m15 = pixel15;// m16 = pixel16;// m17 = pixel17;// m18 = pixel18;// m19 = pixel19;// m20 = pixel20;// m21 = pixel21;// m22 = pixel22;// m23 = pixel23;// m24 = pixel24;// m25 = pixel25;// m26 = pixel26;// m27 = pixel27;// m28 = pixel28;// m29 = pixel29;// m30 = pixel30;// m31 = pixel31;// } void composeLine(int inputOffset, int minX, int maxX, int[] opaqueData, int opaqueOffset) { int minInt = minX>>5; int maxInt = maxX>>5; this.opaqueData = opaqueData; if (minInt == maxInt) { int mask = (1 << ((maxX&31) + 1)) - (1 << (minX&31)); composeBits(inputOffset + minInt, mask, opaqueOffset + (minInt<<5)); return; } if ((minX&31) != 0) { int headMask = -(1 << (minX&31)); composeBits(inputOffset + minInt, headMask, opaqueOffset + (minInt<<5)); minInt++; } if ((maxX&31) != 31) { int tailMask = (1 << ((maxX&31) + 1)) - 1; composeBits(inputOffset + maxInt, tailMask, opaqueOffset + (maxInt<<5)); maxInt--; } opaqueOffset += minInt<<5; for (int index = minInt; index <= maxInt; index++) { for (AlphaBlendGroup group: groups) group.unpackBytes(inputOffset + index); opaqueOffset = storeRGB32(opaqueOffset); } } void composeBits(int inputOffset, int mask, int outputOffset) { for (AlphaBlendGroup group: groups) group.unpackBytes(inputOffset); if ((mask & (1 << 0)) != 0) storeRGB(outputOffset + 0, r0, g0, b0); if ((mask & (1 << 1)) != 0) storeRGB(outputOffset + 1, r1, g1, b1); if ((mask & (1 << 2)) != 0) storeRGB(outputOffset + 2, r2, g2, b2); if ((mask & (1 << 3)) != 0) storeRGB(outputOffset + 3, r3, g3, b3); if ((mask & (1 << 4)) != 0) storeRGB(outputOffset + 4, r4, g4, b4); if ((mask & (1 << 5)) != 0) storeRGB(outputOffset + 5, r5, g5, b5); if ((mask & (1 << 6)) != 0) storeRGB(outputOffset + 6, r6, g6, b6); if ((mask & (1 << 7)) != 0) storeRGB(outputOffset + 7, r7, g7, b7); if ((mask & (1 << 8)) != 0) storeRGB(outputOffset + 8, r8, g8, b8); if ((mask & (1 << 9)) != 0) storeRGB(outputOffset + 9, r9, g9, b9); if ((mask & (1 << 10)) != 0) storeRGB(outputOffset + 10, r10, g10, b10); if ((mask & (1 << 11)) != 0) storeRGB(outputOffset + 11, r11, g11, b11); if ((mask & (1 << 12)) != 0) storeRGB(outputOffset + 12, r12, g12, b12); if ((mask & (1 << 13)) != 0) storeRGB(outputOffset + 13, r13, g13, b13); if ((mask & (1 << 14)) != 0) storeRGB(outputOffset + 14, r14, g14, b14); if ((mask & (1 << 15)) != 0) storeRGB(outputOffset + 15, r15, g15, b15); if ((mask & (1 << 16)) != 0) storeRGB(outputOffset + 16, r16, g16, b16); if ((mask & (1 << 17)) != 0) storeRGB(outputOffset + 17, r17, g17, b17); if ((mask & (1 << 18)) != 0) storeRGB(outputOffset + 18, r18, g18, b18); if ((mask & (1 << 19)) != 0) storeRGB(outputOffset + 19, r19, g19, b19); if ((mask & (1 << 20)) != 0) storeRGB(outputOffset + 20, r20, g20, b20); if ((mask & (1 << 21)) != 0) storeRGB(outputOffset + 21, r21, g21, b21); if ((mask & (1 << 22)) != 0) storeRGB(outputOffset + 22, r22, g22, b22); if ((mask & (1 << 23)) != 0) storeRGB(outputOffset + 23, r23, g23, b23); if ((mask & (1 << 24)) != 0) storeRGB(outputOffset + 24, r24, g24, b24); if ((mask & (1 << 25)) != 0) storeRGB(outputOffset + 25, r25, g25, b25); if ((mask & (1 << 26)) != 0) storeRGB(outputOffset + 26, r26, g26, b26); if ((mask & (1 << 27)) != 0) storeRGB(outputOffset + 27, r27, g27, b27); if ((mask & (1 << 28)) != 0) storeRGB(outputOffset + 28, r28, g28, b28); if ((mask & (1 << 29)) != 0) storeRGB(outputOffset + 29, r29, g29, b29); if ((mask & (1 << 30)) != 0) storeRGB(outputOffset + 30, r30, g30, b30); if ((mask & (1 << 31)) != 0) storeRGB(outputOffset + 31, r31, g31, b31); } // private int storeRGB32(int baseIndex) {// storeRGB_(baseIndex++, m0);// storeRGB_(baseIndex++, m1);// storeRGB_(baseIndex++, m2);// storeRGB_(baseIndex++, m3);// storeRGB_(baseIndex++, m4);// storeRGB_(baseIndex++, m5);// storeRGB_(baseIndex++, m6);// storeRGB_(baseIndex++, m7);// storeRGB_(baseIndex++, m8);// storeRGB_(baseIndex++, m9);// storeRGB_(baseIndex++, m10);// storeRGB_(baseIndex++, m11);// storeRGB_(baseIndex++, m12);// storeRGB_(baseIndex++, m13);// storeRGB_(baseIndex++, m14);// storeRGB_(baseIndex++, m15);// storeRGB_(baseIndex++, m16);// storeRGB_(baseIndex++, m17);// storeRGB_(baseIndex++, m18);// storeRGB_(baseIndex++, m19);// storeRGB_(baseIndex++, m20);// storeRGB_(baseIndex++, m21);// storeRGB_(baseIndex++, m22);// storeRGB_(baseIndex++, m23);// storeRGB_(baseIndex++, m24);// storeRGB_(baseIndex++, m25);// storeRGB_(baseIndex++, m26);// storeRGB_(baseIndex++, m27);// storeRGB_(baseIndex++, m28);// storeRGB_(baseIndex++, m29);// storeRGB_(baseIndex++, m30);// storeRGB_(baseIndex++, m31);// return baseIndex;// } private int storeRGB32(int baseIndex) { storeRGB(baseIndex++, r0, g0, b0); storeRGB(baseIndex++, r1, g1, b1); storeRGB(baseIndex++, r2, g2, b2); storeRGB(baseIndex++, r3, g3, b3); storeRGB(baseIndex++, r4, g4, b4); storeRGB(baseIndex++, r5, g5, b5); storeRGB(baseIndex++, r6, g6, b6); storeRGB(baseIndex++, r7, g7, b7); storeRGB(baseIndex++, r8, g8, b8); storeRGB(baseIndex++, r9, g9, b9); storeRGB(baseIndex++, r10, g10, b10); storeRGB(baseIndex++, r11, g11, b11); storeRGB(baseIndex++, r12, g12, b12); storeRGB(baseIndex++, r13, g13, b13); storeRGB(baseIndex++, r14, g14, b14); storeRGB(baseIndex++, r15, g15, b15); storeRGB(baseIndex++, r16, g16, b16); storeRGB(baseIndex++, r17, g17, b17); storeRGB(baseIndex++, r18, g18, b18); storeRGB(baseIndex++, r19, g19, b19); storeRGB(baseIndex++, r20, g20, b20); storeRGB(baseIndex++, r21, g21, b21); storeRGB(baseIndex++, r22, g22, b22); storeRGB(baseIndex++, r23, g23, b23); storeRGB(baseIndex++, r24, g24, b24); storeRGB(baseIndex++, r25, g25, b25); storeRGB(baseIndex++, r26, g26, b26); storeRGB(baseIndex++, r27, g27, b27); storeRGB(baseIndex++, r28, g28, b28); storeRGB(baseIndex++, r29, g29, b29); storeRGB(baseIndex++, r30, g30, b30);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -