ImageSurfacepublic class ImageSurface extends Surface implements org.apache.harmony.awt.gl.image.DataBufferListenerThis class represent Surface for different types of Images (BufferedImage,
OffscreenImage and so on) |
Fields Summary |
---|
boolean | nativeDrawable | int | surfaceType | int | csType | ColorModel | cm | WritableRaster | raster | Object | data | boolean | needToRefresh | boolean | dataTaken | private long | cachedDataPtr | private boolean | alphaPre |
Constructors Summary |
---|
public ImageSurface(ColorModel cm, WritableRaster raster) // Cached Image Data alpha premultiplied
this(cm, raster, Surface.getType(cm, raster));
| public ImageSurface(ColorModel cm, WritableRaster raster, int type)
if (!cm.isCompatibleRaster(raster)) {
// awt.4D=The raster is incompatible with this ColorModel
throw new IllegalArgumentException(Messages.getString("awt.4D")); //$NON-NLS-1$
}
this.cm = cm;
this.raster = raster;
surfaceType = type;
data = AwtImageBackdoorAccessor.getInstance().
getData(raster.getDataBuffer());
ColorSpace cs = cm.getColorSpace();
transparency = cm.getTransparency();
width = raster.getWidth();
height = raster.getHeight();
// For the moment we can build natively only images which have
// sRGB, Linear_RGB, Linear_Gray Color Space and type different
// from BufferedImage.TYPE_CUSTOM
if(cs == LUTColorConverter.sRGB_CS){
csType = sRGB_CS;
}else if(cs == LUTColorConverter.LINEAR_RGB_CS){
csType = Linear_RGB_CS;
}else if(cs == LUTColorConverter.LINEAR_GRAY_CS){
csType = Linear_Gray_CS;
}else{
csType = Custom_CS;
nativeDrawable = false;
}
if(type == BufferedImage.TYPE_CUSTOM){
nativeDrawable = false;
}
|
Methods Summary |
---|
private void | createSufaceStructure()Creates native Surface structure which used for native blitting
int cmType = 0;
int numComponents = cm.getNumComponents();
boolean hasAlpha = cm.hasAlpha();
boolean isAlphaPre = cm.isAlphaPremultiplied();
int transparency = cm.getTransparency();
int bits[] = cm.getComponentSize();
int pixelStride = cm.getPixelSize();
int masks[] = null;
int colorMap[] = null;
int colorMapSize = 0;
int transpPixel = -1;
boolean isGrayPallete = false;
SampleModel sm = raster.getSampleModel();
int smType = 0;
int dataType = sm.getDataType();
int scanlineStride = 0;
int bankIndeces[] = null;
int bandOffsets[] = null;
int offset = raster.getDataBuffer().getOffset();
if(cm instanceof DirectColorModel){
cmType = DCM;
DirectColorModel dcm = (DirectColorModel) cm;
masks = dcm.getMasks();
smType = SPPSM;
SinglePixelPackedSampleModel sppsm = (SinglePixelPackedSampleModel) sm;
scanlineStride = sppsm.getScanlineStride();
}else if(cm instanceof IndexColorModel){
cmType = ICM;
IndexColorModel icm = (IndexColorModel) cm;
colorMapSize = icm.getMapSize();
colorMap = new int[colorMapSize];
icm.getRGBs(colorMap);
transpPixel = icm.getTransparentPixel();
isGrayPallete = Surface.isGrayPallete(icm);
if(sm instanceof MultiPixelPackedSampleModel){
smType = MPPSM;
MultiPixelPackedSampleModel mppsm =
(MultiPixelPackedSampleModel) sm;
scanlineStride = mppsm.getScanlineStride();
}else if(sm instanceof ComponentSampleModel){
smType = CSM;
ComponentSampleModel csm =
(ComponentSampleModel) sm;
scanlineStride = csm.getScanlineStride();
}else{
// awt.4D=The raster is incompatible with this ColorModel
throw new IllegalArgumentException(Messages.getString("awt.4D")); //$NON-NLS-1$
}
}else if(cm instanceof ComponentColorModel){
cmType = CCM;
if(sm instanceof ComponentSampleModel){
ComponentSampleModel csm = (ComponentSampleModel) sm;
scanlineStride = csm.getScanlineStride();
bankIndeces = csm.getBankIndices();
bandOffsets = csm.getBandOffsets();
if(sm instanceof PixelInterleavedSampleModel){
smType = PISM;
}else if(sm instanceof BandedSampleModel){
smType = BSM;
}else{
smType = CSM;
}
}else{
// awt.4D=The raster is incompatible with this ColorModel
throw new IllegalArgumentException(Messages.getString("awt.4D")); //$NON-NLS-1$
}
}else{
surfaceDataPtr = 0L;
return;
}
surfaceDataPtr = createSurfStruct(surfaceType, width, height, cmType, csType, smType, dataType,
numComponents, pixelStride, scanlineStride, bits, masks, colorMapSize,
colorMap, transpPixel, isGrayPallete, bankIndeces, bandOffsets,
offset, hasAlpha, isAlphaPre, transparency);
| private native long | createSurfStruct(int surfaceType, int width, int height, int cmType, int csType, int smType, int dataType, int numComponents, int pixelStride, int scanlineStride, int[] bits, int[] masks, int colorMapSize, int[] colorMap, int transpPixel, boolean isGrayPalette, int[] bankIndeces, int[] bandOffsets, int offset, boolean hasAlpha, boolean isAlphaPre, int transparency)
| public void | dataChanged()
needToRefresh = true;
clearValidCaches();
| public void | dataReleased()
dataTaken = false;
needToRefresh = true;
clearValidCaches();
| public void | dataTaken()
dataTaken = true;
needToRefresh = true;
clearValidCaches();
| public void | dispose()
if(surfaceDataPtr != 0L){
dispose(surfaceDataPtr);
surfaceDataPtr = 0L;
}
| private native void | dispose(long structPtr)
| public long | getCachedData(boolean alphaPre)
if(nativeDrawable){
if(cachedDataPtr == 0L || needToRefresh || this.alphaPre != alphaPre){
cachedDataPtr = updateCache(getSurfaceDataPtr(), data, alphaPre);
this.alphaPre = alphaPre;
validate();
}
}
return cachedDataPtr;
| public java.awt.image.ColorModel | getColorModel()
return cm;
| public java.lang.Object | getData()
return data;
| public Surface | getImageSurface()
return this;
| public java.awt.image.WritableRaster | getRaster()
return raster;
| public long | getSurfaceDataPtr()
if(surfaceDataPtr == 0L && nativeDrawable){
createSufaceStructure();
}
return surfaceDataPtr;
| public int | getSurfaceType()
return surfaceType;
| public void | invalidate()
needToRefresh = true;
clearValidCaches();
| public boolean | invalidated()
return needToRefresh;
| public boolean | isNativeDrawable()
return nativeDrawable;
| public long | lock()
// TODO
return 0;
| private native void | setImageSize(long structPtr, int width, int height)
| public void | setRaster(java.awt.image.WritableRaster r)Supposes that new raster is compatible with an old one
raster = r;
data = AwtImageBackdoorAccessor.getInstance().getData(r.getDataBuffer());
if (surfaceDataPtr != 0) {
setImageSize(surfaceDataPtr, r.getWidth(), r.getHeight());
}
this.width = r.getWidth();
this.height = r.getHeight();
| public void | unlock()
//TODO
| private native long | updateCache(long structPtr, java.lang.Object data, boolean alphaPre)
| public void | validate()
if(!needToRefresh) {
return;
}
if(!dataTaken){
needToRefresh = false;
AwtImageBackdoorAccessor ba = AwtImageBackdoorAccessor.getInstance();
ba.validate(raster.getDataBuffer());
}
|
|