📄 layerdrawing.java
字号:
if (layer.getGraphics().getTransparentLayer() == 0) { numOpaque++; } else { numTransparent++; } } TransparentRaster[] transparentRasters = new TransparentRaster[numTransparent]; int[] transparentMasks = new int[numTransparent]; TransparentRaster[] opaqueRasters = new TransparentRaster[numOpaque]; int[] opaqueCols = new int[numOpaque]; numTransparent = numOpaque = 0; for (Map.Entry<Layer,TransparentRaster> e: dd.layerRasters.entrySet()) { Layer layer = e.getKey(); if (!layer.isVisible()) continue; TransparentRaster raster = e.getValue(); int transparentNum = layer.getGraphics().getTransparentLayer(); if (transparentNum != 0) { transparentMasks[numTransparent] = (1 << (transparentNum - 1)) & (colorMap.length - 1); transparentRasters[numTransparent++] = raster; } else { opaqueCols[numOpaque] = dd.offscreen.getTheColor(layer.getGraphics(), layer.isDimmed()); opaqueRasters[numOpaque++] = raster; } } // determine range int numIntsPerRow = dd.numIntsPerRow; int backgroundColor = User.getColor(User.ColorPrefType.BACKGROUND) & 0xFFFFFF; int lx = 0, hx = dd.width-1; int ly = 0, hy = dd.height-1; for(int y=ly; y<=hy; y++) { int baseByteIndex = y*numIntsPerRow;// int baseIndex = y * dd.width; for(int x=0; x<=hx; x++) { int entry = baseByteIndex + (x>>5); int maskBit = 1 << (x & 31); int opaqueIndex = -1; for (int i = 0; i < opaqueRasters.length; i++) { if ((opaqueRasters[i].layerBitMap[entry] & maskBit) != 0) opaqueIndex = i; } int pixelValue; if (opaqueIndex >= 0) { pixelValue = opaqueCols[opaqueIndex]; } else { int bits = 0; for (int i = 0; i < transparentRasters.length; i++) { if ((transparentRasters[i].layerBitMap[entry] & maskBit) != 0) bits |= transparentMasks[i]; } pixelValue = bits != 0 ? colorMap[bits].getRGB() & 0xFFFFFF : backgroundColor; } smallOpaqueData[x] = pixelValue; } g.drawImage(smallImg, 0, y, null); } } /** * This method is called from Job thread. */ @Override public void render(Dimension sz, WindowFrame.DisplayAttributes da, boolean fullInstantiate, Rectangle2D bounds) { LayerDrawing offscreen = null; if (drawingData != null && drawingData.offscreen.getSize().equals(sz)) offscreen = drawingData.offscreen; if (offscreen == null) offscreen = new LayerDrawing(sz); this.da = da;// updateScaleAndOffset(); offscreen.drawImage(this, fullInstantiate, bounds); needComposite = true; drawingData = new DrawingData(offscreen); } private static boolean joglChecked = false; private static Class<?> layerDrawerClass; private static Method joglShowLayerMethod; /** * Method to tell whether JOGL redisplay is available. * JOGL is Java extension. * This method dynamically figures out whether the JOGL module is present by using reflection. * @return true if the JOGL redisplay is available. */ public static boolean hasJogl() { if (!joglChecked) { joglChecked = true; // find the LayerDrawer class try { layerDrawerClass = Class.forName("com.sun.electric.plugins.jogl.LayerDrawer"); joglShowLayerMethod = layerDrawerClass.getMethod("showLayer", new Class[] {Dimension.class, (new int[0]).getClass(), Double.TYPE, Double.TYPE, Double.TYPE}); } catch (Exception e) {} } return joglShowLayerMethod != null; } @Override public void testJogl() { if (hasJogl()) { try { int numBoxes = 1000000; int[] boxes = new int[numBoxes*4]; for (int i = 0; i < numBoxes; i++) { int x = (i*5) % 501 - 100; int y = (i*7) % 500 - 200; boxes[i*4 + 0] = x; boxes[i*4 + 1] = y; boxes[i*4 + 2] = x + 10; boxes[i*4 + 3] = y + 10; }// joglShowLayerMethod.invoke(layerDrawerClass, new Object[] {offscreen___.sz, boxes, 1.0, 0.0, 0.0}); } catch (Exception e) { System.out.println("Unable to run the LayerDrawer input module (" + e.getClass() + ")"); e.printStackTrace(System.out); } return; }// testJogl_(); }// private void testJogl_() {// JFrame frame = new JFrame("Jogl");// GLCapabilities capabilities = new GLCapabilities();// capabilities.setDoubleBuffered(false);// capabilities.setHardwareAccelerated(false);// System.out.println("Capabilities: " + capabilities);// GLCanvas canvas = new GLCanvas(capabilities);//// canvas.addGLEventListener(new JoglEventListener());// frame.add(canvas);// frame.setSize(offscreen.getSize());//// frame.setVisible(true);// }//// private static void showInt(GL gl, String s, int i) {// IntBuffer intBuffer = IntBuffer.allocate(100);// gl.glGetIntegerv(GL.GL_MULTISAMPLE, intBuffer);// System.out.println(s + ": " + intBuffer.get(0));// }//// private class JoglEventListener implements GLEventListener {//// public void init(GLAutoDrawable drawable) {// GL gl = drawable.getGL();// gl = new DebugGL(gl);// drawable.setGL(gl);////// gl.glDisable(GL.GL_MULTISAMPLE);//// System.out.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR));// System.out.println("GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER));// System.out.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION));// showInt(gl, "GL_MULTISAMPLE", GL.GL_MULTISAMPLE);// showInt(gl, "GL_SAMPLE_BUFFERS", GL.GL_SAMPLE_BUFFERS);// showInt(gl, "GL_SAMPLES", GL.GL_SAMPLES);////// gl.glPixelStorei(GL.GL_UNPACK_SWAP_BYTES, 1);//// gl.glPixelStorei(gl.GL_UNPACK_LSB_FIRST, 1);//// gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1);////// gl.glPixelTransferi(gl.GL_MAP_COLOR, 1);// gl.glEnable(gl.GL_BLEND);// gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA);// }//// public void display(GLAutoDrawable drawable) {// List<EditWindow.LayerColor> blendingOrder = offscreen.wnd.getBlendingOrder(offscreen.layerRasters.keySet(), false);//// GL gl = drawable.getGL();//// BufferedImage bImg = vImg.getSnapshot();// DataBufferInt dbi = (DataBufferInt)bImg.getRaster().getDataBuffer();// int[] opaqueData = dbi.getData();// int w = bImg.getWidth(), h = bImg.getHeight();// IntBuffer intBuffer = IntBuffer.allocate(w*h);// ByteBuffer redBuffer = ByteBuffer.allocate(w*h);// ByteBuffer greenBuffer = ByteBuffer.allocate(w*h);// ByteBuffer blueBuffer = ByteBuffer.allocate(w*h);// assert intBuffer.order() == ByteOrder.nativeOrder();// for (int y = 0; y < h; y++) {// for (int x = 0; x < w; x++) {// int v = opaqueData[(h - y - 1)*w + x];// intBuffer.put(v | 0xFF000000);// redBuffer.put((byte)(v >> 16));// greenBuffer.put((byte)(v >> 8));// blueBuffer.put((byte)v);// }// }// intBuffer.rewind();// redBuffer.rewind();// greenBuffer.rewind();// blueBuffer.rewind();//// IntBuffer intBuffer = IntBuffer.wrap(offscreen.opaqueData, 0, w*h);//// long startTime = System.currentTimeMillis();//// float[] bg = (new Color(User.getColor(User.ColorPrefType.BACKGROUND))).getRGBComponents(null);//// gl.glClearColor(bg[0], bg[1], bg[2], 1.0f);// gl.glClearColor(1f, 1f, 1f, 1f);// gl.glClear(GL.GL_COLOR_BUFFER_BIT);//// gl.glMatrixMode(GL.GL_PROJECTION);// gl.glLoadIdentity();//// gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);//// gl.glMatrixMode(GL.GL_MODELVIEW);// gl.glLoadIdentity();////// ByteBuffer buf = ByteBuffer.allocate((w + 7)/8*h);//// for (int i = 0; i < 100; i++)//// buf.put(i*3, (byte)0x55);//// gl.glPixelMapfv(gl.GL_PIXEL_MAP_I_TO_R, 2, new float[256], 0);//// float[] green = new float[256];//// Arrays.fill(green, 1.0f);//// green[0] = 0;//// gl.glPixelMapfv(gl.GL_PIXEL_MAP_I_TO_G, 2, green, 0);//// gl.glPixelMapfv(gl.GL_PIXEL_MAP_I_TO_B, 2, new float[256], 0);//// gl.glPixelMapfv(gl.GL_PIXEL_MAP_I_TO_A, 2, new float[256], 0);//// gl.glDrawPixels(10, 10, gl.GL_COLOR_INDEX, gl.GL_BITMAP, buf);//// gl.glBitmap(10, 10, 0f, 0f, 0f, 0f, buf);////// byte[] bytes1 = new byte[(w+7)/8*h*2];//// Arrays.fill(bytes1, (byte)-2);//// bytes1[0] = 0;//// bytes1[299] = 0;// if (true) {//// gl.glPixelMapfv(gl.GL_PIXEL_MAP_I_TO_R, 256, new float[256], 0);//// float[] green = new float[256];//// for (int i = 0; i < green.length; i++)//// green[i] = i/255f;//// gl.glPixelMapfv(gl.GL_PIXEL_MAP_I_TO_G, 256, green, 0);//// gl.glPixelMapfv(gl.GL_PIXEL_MAP_I_TO_B, 256, new float[256], 0);//// float[] alpha = new float[256];//// Arrays.fill(alpha, 1f);//// gl.glPixelMapfv(gl.GL_PIXEL_MAP_I_TO_A, 256, alpha, 0);//// for (int i = 0; i < 1000; i++)// gl.glDrawPixels(w, h, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, intBuffer);//// gl.glDrawPixels(w, h, GL.GL_GREEN, GL.GL_UNSIGNED_BYTE, greenBuffer);//// gl.glDrawPixels(w, h, GL.GL_BLUE, GL.GL_UNSIGNED_BYTE, blueBuffer);//// gl.glDrawPixels(w, h, GL.GL_RED, GL.GL_UNSIGNED_BYTE, redBuffer);//// ByteBuffer byteBuffer = ByteBuffer.allocate(w*h);//// gl.glReadPixels(0, 0, w, h, GL.GL_BLUE, GL.GL_UNSIGNED_BYTE, byteBuffer);//// for (int y = 0; y < h; y++) {//// for (int x = 0; x < w; x++) {//// int v = opaqueData[(h - y - 1)*w + x];//// byte b = byteBuffer.get();//// if (((v >> 16) & 0xFF) != (b & 0xFF))//// System.out.println("Mismatch at x=" + x + " y=" + y + " v=" + Integer.toHexString(v) + " b=" + Integer.toHexString(b));//// }//// }// } else {// for (EditWindow.LayerColor layerColor: blendingOrder) {// float[] c = layerColor.color.getComponents(null);//// gl.glColor4f(c[0], c[1], c[2], c[3]);// gl.glPixelMapfv(gl.GL_PIXEL_MAP_I_TO_R, 2, new float[] {0f, c[0]}, 0);// gl.glPixelMapfv(gl.GL_PIXEL_MAP_I_TO_G, 2, new float[] {0f, c[1]}, 0);// gl.glPixelMapfv(gl.GL_PIXEL_MAP_I_TO_B, 2, new float[] {0f, c[2]}, 0);// gl.glPixelMapfv(gl.GL_PIXEL_MAP_I_TO_A, 2, new float[] {0f, c[3]}, 0);//// byte[] b = offscreen.layerRasters.get(layerColor.layer).layerBitMap;//// buf.rewind();//// buf.put(b);//// buf.rewind();//// ByteBuffer buf = offscreen.layerBuffers.get(layerColor.layer);//// gl.glDrawPixels(w, h, gl.GL_COLOR_INDEX, gl.GL_BITMAP, buf);//// gl.glBitmap(w, h, 0f, 0f, 0f, 0f, buf);// }// }// long endTime = System.currentTimeMillis();// System.out.println("jogl display took " + (endTime - startTime) + " msec");//// }//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -