summaryrefslogtreecommitdiff
path: root/external/ikvm/openjdk/java/awt/image/BufferedImage.java
diff options
context:
space:
mode:
Diffstat (limited to 'external/ikvm/openjdk/java/awt/image/BufferedImage.java')
-rw-r--r--external/ikvm/openjdk/java/awt/image/BufferedImage.java82
1 files changed, 66 insertions, 16 deletions
diff --git a/external/ikvm/openjdk/java/awt/image/BufferedImage.java b/external/ikvm/openjdk/java/awt/image/BufferedImage.java
index 33c9c2701e..ee00c6a819 100644
--- a/external/ikvm/openjdk/java/awt/image/BufferedImage.java
+++ b/external/ikvm/openjdk/java/awt/image/BufferedImage.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -38,6 +38,8 @@ import java.awt.geom.Rectangle2D;
import java.awt.geom.Point2D;
import java.awt.Point;
import java.awt.Rectangle;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.Hashtable;
import java.util.Vector;
@@ -425,6 +427,7 @@ public class BufferedImage extends java.awt.Image
colorModel = cm;
this.imageType = imageType;
this.currentBuffer = BUFFER_RASTER;
+ raster.getDataBuffer().setImage( this );
}
/**
@@ -469,7 +472,7 @@ public class BufferedImage extends java.awt.Image
WritableRaster raster,
boolean isRasterPremultiplied,
Hashtable<?,?> properties) {
-
+
if (!cm.isCompatibleRaster(raster)) {
throw new
IllegalArgumentException("Raster "+raster+
@@ -486,10 +489,12 @@ public class BufferedImage extends java.awt.Image
colorModel = cm;
this.raster = raster;
+ raster.getDataBuffer().setImage( this );
this.currentBuffer = BUFFER_RASTER;
this.properties = properties;
int numBands = raster.getNumBands();
boolean isAlphaPre = cm.isAlphaPremultiplied();
+ final boolean isStandard = isStandard(cm, raster);
ColorSpace cs;
// Force the raster data alpha state to match the premultiplied
@@ -500,8 +505,9 @@ public class BufferedImage extends java.awt.Image
cs = cm.getColorSpace();
int csType = cs.getType();
if (csType != ColorSpace.TYPE_RGB) {
- if (csType == ColorSpace.TYPE_GRAY
- && cm instanceof ComponentColorModel) {
+ if (csType == ColorSpace.TYPE_GRAY &&
+ isStandard &&
+ cm instanceof ComponentColorModel) {
// Check if this might be a child raster (fix for bug 4240596)
if (sm instanceof ComponentSampleModel &&
((ComponentSampleModel)sm).getPixelStride() != numBands) {
@@ -531,6 +537,7 @@ public class BufferedImage extends java.awt.Image
// are correct
int pixSize = cm.getPixelSize();
if (iraster.getPixelStride() == 1 &&
+ isStandard &&
cm instanceof DirectColorModel &&
(pixSize == 32 || pixSize == 24))
{
@@ -563,6 +570,7 @@ public class BufferedImage extends java.awt.Image
} // if (iraster.getPixelStride() == 1
} // ((raster instanceof IntegerComponentRaster) &&
else if ((cm instanceof IndexColorModel) && (numBands == 1) &&
+ isStandard &&
(!cm.hasAlpha() || !isAlphaPre))
{
IndexColorModel icm = (IndexColorModel) cm;
@@ -580,6 +588,7 @@ public class BufferedImage extends java.awt.Image
} // else if (cm instanceof IndexColorModel) && (numBands == 1))
else if ((raster instanceof ShortComponentRaster)
&& (cm instanceof DirectColorModel)
+ && isStandard
&& (numBands == 3)
&& !cm.hasAlpha())
{
@@ -599,6 +608,7 @@ public class BufferedImage extends java.awt.Image
} // else if ((cm instanceof IndexColorModel) && (numBands == 1))
else if ((raster instanceof ByteComponentRaster)
&& (cm instanceof ComponentColorModel)
+ && isStandard
&& (raster.getSampleModel() instanceof PixelInterleavedSampleModel)
&& (numBands == 3 || numBands == 4))
{
@@ -623,14 +633,15 @@ public class BufferedImage extends java.awt.Image
}
}
if (is8bit &&
+ braster.getPixelStride() == numBands &&
offs[0] == numBands-1 &&
offs[1] == numBands-2 &&
offs[2] == numBands-3)
{
- if (numBands == 3) {
+ if (numBands == 3 && !ccm.hasAlpha()) {
imageType = TYPE_3BYTE_BGR;
}
- else if (offs[3] == 0) {
+ else if (offs[3] == 0 && ccm.hasAlpha()) {
imageType = (isAlphaPre
? TYPE_4BYTE_ABGR_PRE
: TYPE_4BYTE_ABGR);
@@ -638,6 +649,27 @@ public class BufferedImage extends java.awt.Image
}
} // else if ((raster instanceof ByteComponentRaster) &&
}
+
+ private static boolean isStandard(ColorModel cm, WritableRaster wr) {
+ final Class<? extends ColorModel> cmClass = cm.getClass();
+ final Class<? extends WritableRaster> wrClass = wr.getClass();
+ final Class<? extends SampleModel> smClass = wr.getSampleModel().getClass();
+
+ final PrivilegedAction<Boolean> checkClassLoadersAction =
+ new PrivilegedAction<Boolean>()
+ {
+
+ @Override
+ public Boolean run() {
+ final ClassLoader std = System.class.getClassLoader();
+
+ return (cmClass.getClassLoader() == std) &&
+ (smClass.getClassLoader() == std) &&
+ (wrClass.getClassLoader() == std);
+ }
+ };
+ return AccessController.doPrivileged(checkClassLoadersAction);
+ }
/**
* Get the .NET Bitmap object.
@@ -649,6 +681,23 @@ public class BufferedImage extends java.awt.Image
}
/**
+ * Switch to the BITMAP buffer and invalidate the RASTER buffer before a graphics operation.
+ */
+ final void toBitmap(){
+ raster2Bitmap();
+ currentBuffer = BUFFER_BITMAP;
+ }
+
+ /**
+ * Switch to the RASTER buffer and invalidate the BITMAP buffer before a graphics operation.
+ */
+ @cli.IKVM.Attributes.HideFromJavaAttribute.Annotation
+ final void toRaster() {
+ bitmap2Raster();
+ currentBuffer = BUFFER_RASTER;
+ }
+
+ /**
* This Implementation of BufferedImage has 2 different Buffer,
* a Java WritableRaster and a .NET Bitmap.
* This method convert a Java WritableRaster to a .NET Bitmap if needed.
@@ -714,21 +763,23 @@ public class BufferedImage extends java.awt.Image
}
if(raster == null){
raster = createRaster(width, height);
+ raster.getDataBuffer().setImage( this );
}
+ this.currentBuffer = BUFFER_BOTH;
switch (getType()){
case TYPE_INT_ARGB:
copyFromBitmap(bitmap, ((DataBufferInt)raster.getDataBuffer()).getData());
break;
default:
+ Object pixel = colorModel.getDataElements( 0, null ); //allocate a buffer for the follow loop
for( int y = 0; y<height; y++){
for(int x = 0; x<width; x++){
int rgb = bitmap.GetPixel(x, y).ToArgb();
- raster.setDataElements(x, y, colorModel.getDataElements(rgb, null));
+ raster.setDataElements(x, y, colorModel.getDataElements(rgb, pixel));
}
}
}
- this.currentBuffer = BUFFER_BOTH;
}
}
@@ -1192,7 +1243,7 @@ public class BufferedImage extends java.awt.Image
* pixels for this image.
* @see ImageProducer
*/
- public ImageProducer getSource(){
+ public ImageProducer getSource() {
if(currentBuffer != BUFFER_RASTER){
synchronized( bitmap ) {
int width = bitmap.get_Width();
@@ -1281,10 +1332,9 @@ public class BufferedImage extends java.awt.Image
* image.
*/
public Graphics2D createGraphics() {
- ikvm.awt.IkvmToolkit toolkit = ikvm.awt.IkvmToolkit.DefaultToolkit.get();
- raster2Bitmap();
- this.currentBuffer = BUFFER_BITMAP;
- return toolkit.createGraphics( bitmap );
+ GraphicsEnvironment env =
+ GraphicsEnvironment.getLocalGraphicsEnvironment();
+ return env.createGraphics(this);
}
/**
@@ -1346,9 +1396,9 @@ public class BufferedImage extends java.awt.Image
* <code>BufferedImage</code>.
*/
public String toString() {
- return new String("BufferedImage@"+Integer.toHexString(hashCode())
- +": type = "+imageType
- +" "+colorModel+" "+raster);
+ return "BufferedImage@"+Integer.toHexString(hashCode())
+ +": type = "+imageType
+ +" "+colorModel+" "+raster;
}
/**