|
Packit |
5e46da |
/*
|
|
Packit |
5e46da |
* This file is part of libbluray
|
|
Packit |
5e46da |
* Copyright (C) 2012 libbluray
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
* This library is free software; you can redistribute it and/or
|
|
Packit |
5e46da |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
5e46da |
* License as published by the Free Software Foundation; either
|
|
Packit |
5e46da |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
5e46da |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
5e46da |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
5e46da |
* Lesser General Public License for more details.
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
5e46da |
* License along with this library. If not, see
|
|
Packit |
5e46da |
* <http://www.gnu.org/licenses/>.
|
|
Packit |
5e46da |
*/
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
package java.awt;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
import java.lang.reflect.Constructor;
|
|
Packit |
5e46da |
import java.lang.reflect.InvocationTargetException;
|
|
Packit |
5e46da |
import java.security.AccessController;
|
|
Packit |
5e46da |
import java.security.PrivilegedAction;
|
|
Packit |
5e46da |
import java.util.Vector;
|
|
Packit |
5e46da |
import java.util.Enumeration;
|
|
Packit |
5e46da |
import java.awt.color.ColorSpace;
|
|
Packit |
5e46da |
import java.awt.image.AreaAveragingScaleFilter;
|
|
Packit |
5e46da |
import java.awt.image.DataBuffer;
|
|
Packit |
5e46da |
import java.awt.image.DirectColorModel;
|
|
Packit |
5e46da |
import java.awt.image.ImageConsumer;
|
|
Packit |
5e46da |
import java.awt.image.ImageProducer;
|
|
Packit |
5e46da |
import java.awt.image.ImageObserver;
|
|
Packit |
5e46da |
import java.awt.image.ColorModel;
|
|
Packit |
5e46da |
import java.awt.image.BufferedImage;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
class BDImageBase extends Image {
|
|
Packit |
5e46da |
private static Constructor bufferedImageConstructor;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
private Component component;
|
|
Packit |
5e46da |
protected int width, height;
|
|
Packit |
5e46da |
protected int[] backBuffer;
|
|
Packit |
5e46da |
protected Area dirty;
|
|
Packit |
5e46da |
private GraphicsConfiguration gc;
|
|
Packit |
5e46da |
private Vector observers = new Vector();
|
|
Packit |
5e46da |
private ImageProducer offscreenSource = null;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
static {
|
|
Packit |
5e46da |
try {
|
|
Packit |
5e46da |
final Class c = Class.forName("java.awt.image.BufferedImage");
|
|
Packit |
5e46da |
AccessController.doPrivileged(
|
|
Packit |
5e46da |
new PrivilegedAction() {
|
|
Packit |
5e46da |
public Object run() {
|
|
Packit |
5e46da |
bufferedImageConstructor = c.getDeclaredConstructors()[0];
|
|
Packit |
5e46da |
bufferedImageConstructor.setAccessible(true);
|
|
Packit |
5e46da |
return null;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
);
|
|
Packit |
5e46da |
} catch (ClassNotFoundException e) {
|
|
Packit |
5e46da |
throw new AWTError("java.awt.image.BufferedImage not found");
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
private static BufferedImage createBuffededImage(Image image) {
|
|
Packit |
5e46da |
try {
|
|
Packit |
5e46da |
return (BufferedImage)bufferedImageConstructor.newInstance(new Object[] { image });
|
|
Packit |
5e46da |
} catch (IllegalArgumentException e) {
|
|
Packit |
5e46da |
e.printStackTrace();
|
|
Packit |
5e46da |
} catch (InstantiationException e) {
|
|
Packit |
5e46da |
e.printStackTrace();
|
|
Packit |
5e46da |
} catch (IllegalAccessException e) {
|
|
Packit |
5e46da |
e.printStackTrace();
|
|
Packit |
5e46da |
} catch (InvocationTargetException e) {
|
|
Packit |
5e46da |
e.printStackTrace();
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
return null;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
BDImageBase(Component component, int width, int height, GraphicsConfiguration gc) {
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
this.component = component;
|
|
Packit |
5e46da |
this.width = width;
|
|
Packit |
5e46da |
this.height = height;
|
|
Packit |
5e46da |
this.gc = gc;
|
|
Packit |
5e46da |
if (width > 0 && height > 0)
|
|
Packit |
5e46da |
backBuffer = new int[width * height];
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
dirty = new Area(width, height);
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
offscreenSource = new BDOffScreenImageSource(backBuffer, width, height);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public void flush() {
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public Graphics getGraphics() {
|
|
Packit |
5e46da |
return new BDGraphics((BDImage)this);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public int getWidth() {
|
|
Packit |
5e46da |
return width;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public int getWidth(ImageObserver observer) {
|
|
Packit |
5e46da |
if (width < 0)
|
|
Packit |
5e46da |
addObserver(observer);
|
|
Packit |
5e46da |
return width;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public int getHeight() {
|
|
Packit |
5e46da |
return height;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public int getHeight(ImageObserver observer) {
|
|
Packit |
5e46da |
if (height < 0)
|
|
Packit |
5e46da |
addObserver(observer);
|
|
Packit |
5e46da |
return height;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public Object getProperty(String name) {
|
|
Packit |
5e46da |
return null;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public Object getProperty(String name, ImageObserver observer) {
|
|
Packit |
5e46da |
return null;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public String[] getPropertyNames() {
|
|
Packit |
5e46da |
return null;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public Image getScaledInstance(int width, int height, int hints) {
|
|
Packit |
5e46da |
BDImageConsumer scaledImage = new BDImageConsumer(null);
|
|
Packit |
5e46da |
AreaAveragingScaleFilter scaleFilter =
|
|
Packit |
5e46da |
new AreaAveragingScaleFilter(width, height);
|
|
Packit |
5e46da |
scaleFilter = (AreaAveragingScaleFilter)scaleFilter.getFilterInstance(scaledImage);
|
|
Packit |
5e46da |
scaleFilter.setDimensions(this.width, this.height);
|
|
Packit |
5e46da |
scaleFilter.setPixels(0, 0, this.width, this.height,
|
|
Packit |
5e46da |
ColorModel.getRGBdefault(), backBuffer, 0, this.width);
|
|
Packit |
5e46da |
scaleFilter.imageComplete(ImageConsumer.STATICIMAGEDONE);
|
|
Packit |
5e46da |
return scaledImage;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public ImageProducer getSource() {
|
|
Packit |
5e46da |
return offscreenSource;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public Component getComponent() {
|
|
Packit |
5e46da |
return component;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
protected int[] getBdBackBuffer() {
|
|
Packit |
5e46da |
return backBuffer;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
protected int[] getBackBuffer() {
|
|
Packit |
5e46da |
System.err.println("**** BDIMAGE GETBACKBUFFER ****");
|
|
Packit |
5e46da |
return backBuffer;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
protected Area getDirtyArea() {
|
|
Packit |
5e46da |
return dirty;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public GraphicsConfiguration getGraphicsConfiguration() {
|
|
Packit |
5e46da |
return gc;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
protected void addObserver(ImageObserver observer) {
|
|
Packit |
5e46da |
if (observer != null && !isObserver(observer))
|
|
Packit |
5e46da |
observers.addElement(observer);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
protected boolean isObserver(ImageObserver observer) {
|
|
Packit |
5e46da |
return observers.contains(observer);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
protected void removeObserver(ImageObserver observer) {
|
|
Packit |
5e46da |
observers.removeElement(observer);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
protected void notifyObservers(Image img, int info, int x, int y, int w, int h) {
|
|
Packit |
5e46da |
Enumeration enumeration = observers.elements();
|
|
Packit |
5e46da |
Vector acquired = null;
|
|
Packit |
5e46da |
while (enumeration.hasMoreElements()) {
|
|
Packit |
5e46da |
ImageObserver observer = (ImageObserver)enumeration.nextElement();
|
|
Packit |
5e46da |
if (!observer.imageUpdate(img, info, x, y, w, h)) {
|
|
Packit |
5e46da |
if (acquired == null) {
|
|
Packit |
5e46da |
acquired = new Vector();
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
acquired.addElement(observer);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
if (acquired != null) {
|
|
Packit |
5e46da |
enumeration = acquired.elements();
|
|
Packit |
5e46da |
while (enumeration.hasMoreElements()) {
|
|
Packit |
5e46da |
ImageObserver observer = (ImageObserver)enumeration.nextElement();
|
|
Packit |
5e46da |
removeObserver(observer);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public int getType() {
|
|
Packit |
5e46da |
return BufferedImage.TYPE_INT_ARGB;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public ColorModel getColorModel() {
|
|
Packit |
5e46da |
return new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
|
|
Packit |
5e46da |
32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, true,
|
|
Packit |
5e46da |
DataBuffer.TYPE_INT);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public int getRGB(int x, int y) {
|
|
Packit |
5e46da |
return backBuffer[y * width + x];
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public int[] getRGB(int x, int y, int w, int h, int[] rgbArray, int offset, int scansize) {
|
|
Packit |
5e46da |
if (rgbArray == null)
|
|
Packit |
5e46da |
rgbArray = new int[offset + h * scansize];
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
for (int i = 0; i < h; i++)
|
|
Packit |
5e46da |
System.arraycopy(backBuffer, (y + i) * width + x,
|
|
Packit |
5e46da |
rgbArray, i * scansize + offset,
|
|
Packit |
5e46da |
w);
|
|
Packit |
5e46da |
return rgbArray;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public void setRGB(int x, int y, int rgb) {
|
|
Packit |
5e46da |
backBuffer[y * width + x] = rgb;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
dirty.add(x, y);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public void setRGB(int x, int y, int w, int h, int[] rgbArray, int offset, int scansize) {
|
|
Packit |
5e46da |
for (int i = 0; i < h; i++)
|
|
Packit |
5e46da |
System.arraycopy(rgbArray, i * scansize + offset,
|
|
Packit |
5e46da |
backBuffer, (y + i) * width + x,
|
|
Packit |
5e46da |
w);
|
|
Packit |
5e46da |
dirty.add(new Rectangle(x, y, w, h));
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public BufferedImage getSubimage(int x, int y, int w, int h) {
|
|
Packit |
5e46da |
BDImage image = new BDImage(component, w, h, gc);
|
|
Packit |
5e46da |
int[] rgbArray = image.getBdBackBuffer();
|
|
Packit |
5e46da |
getRGB(x, y, w, h, rgbArray, 0, w);
|
|
Packit |
5e46da |
return createBuffededImage(image);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public static BufferedImage getBuffededImage(int w, int h, GraphicsConfiguration gc) {
|
|
Packit |
5e46da |
BDImage image = new BDImage(null, w, h, gc);
|
|
Packit |
5e46da |
return createBuffededImage(image);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
}
|