|
From: <ls...@us...> - 2007-01-27 10:06:11
|
Revision: 3089
http://jnode.svn.sourceforge.net/jnode/?rev=3089&view=rev
Author: lsantha
Date: 2007-01-27 02:06:09 -0800 (Sat, 27 Jan 2007)
Log Message:
-----------
Classpath patches.
Modified Paths:
--------------
trunk/core/src/classpath/java/java/awt/image/BufferedImage.java
trunk/core/src/classpath/java/java/awt/image/ComponentColorModel.java
trunk/core/src/classpath/java/java/awt/image/CropImageFilter.java
trunk/core/src/classpath/java/java/awt/image/DirectColorModel.java
trunk/core/src/classpath/java/java/awt/image/IndexColorModel.java
trunk/core/src/classpath/java/java/awt/image/MemoryImageSource.java
Modified: trunk/core/src/classpath/java/java/awt/image/BufferedImage.java
===================================================================
--- trunk/core/src/classpath/java/java/awt/image/BufferedImage.java 2007-01-27 09:39:31 UTC (rev 3088)
+++ trunk/core/src/classpath/java/java/awt/image/BufferedImage.java 2007-01-27 10:06:09 UTC (rev 3089)
@@ -38,6 +38,7 @@
package java.awt.image;
+import gnu.java.awt.Buffers;
import gnu.java.awt.ComponentDataBlitOp;
import java.awt.Graphics;
@@ -129,12 +130,12 @@
* <li>{@link #TYPE_BYTE_INDEXED}</li>
* </ul>
*
- * @param w the width (must be > 0).
- * @param h the height (must be > 0).
+ * @param width the width (must be > 0).
+ * @param height the height (must be > 0).
* @param type the image type (see the list of valid types above).
*
- * @throws IllegalArgumentException if <code>w</code> or <code>h</code> is
- * less than or equal to zero.
+ * @throws IllegalArgumentException if <code>width</code> or
+ * <code>height</code> is less than or equal to zero.
* @throws IllegalArgumentException if <code>type</code> is not one of the
* specified values.
*/
@@ -161,7 +162,10 @@
width, height,
3, width * 3,
new int[]{ 2, 1, 0 } );
- cm = new DirectColorModel( 24, 0xff, 0xff00, 0xff0000 );
+ cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
+ false, false,
+ BufferedImage.OPAQUE,
+ DataBuffer.TYPE_BYTE);
break;
case BufferedImage.TYPE_INT_ARGB:
@@ -172,18 +176,25 @@
0x0000FF00,
0x000000FF,
0xFF000000 } );
+ if (premultiplied)
+ cm = new DirectColorModel( ColorSpace.getInstance(ColorSpace.CS_sRGB),
+ 32, 0xff0000, 0xff00, 0xff, 0xff000000,
+ true,
+ Buffers.smallestAppropriateTransferType(32));
+ else
cm = new DirectColorModel( 32, 0xff0000, 0xff00, 0xff, 0xff000000 );
break;
case BufferedImage.TYPE_4BYTE_ABGR:
case BufferedImage.TYPE_4BYTE_ABGR_PRE:
- sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_INT,
+ sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
width, height,
- new int[]{ 0x000000FF,
- 0xFF000000,
- 0x00FF0000,
- 0x0000FF00 } );
- cm = new DirectColorModel( 32, 0xff, 0xff00, 0xff0000, 0xff000000 );
+ 4, 4*width,
+ new int[]{3, 2, 1, 0});
+ cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
+ true, premultiplied,
+ BufferedImage.TRANSLUCENT,
+ DataBuffer.TYPE_BYTE);
break;
case BufferedImage.TYPE_INT_BGR:
@@ -192,24 +203,24 @@
new int[]{ 0x000000FF,
0x0000FF00,
0x00FF0000 } ) ;
- cm = new DirectColorModel( 32, 0xff, 0xff00, 0xff0000 );
+ cm = new DirectColorModel( 24, 0xff, 0xff00, 0xff0000 );
break;
case BufferedImage.TYPE_USHORT_565_RGB:
sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_USHORT,
width, height,
- new int[]{ 0x0000001F,
- 0x000007E0,
- 0x0000F800 } ) ;
- cm = new DirectColorModel( 16, 0x1F, 0x7E0, 0xf800 );
+ new int[]{ 0xF800,
+ 0x7E0,
+ 0x1F } ) ;
+ cm = new DirectColorModel( 16, 0xF800, 0x7E0, 0x1F );
break;
case BufferedImage.TYPE_USHORT_555_RGB:
sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_USHORT,
width, height,
- new int[]{ 0x0000001F,
- 0x000003E0,
- 0x00007C00 } ) ;
- cm = new DirectColorModel( 15, 0x1F, 0x3E0, 0x7c00 );
+ new int[]{ 0x7C00,
+ 0x3E0,
+ 0x1F } ) ;
+ cm = new DirectColorModel( 15, 0x7C00, 0x3E0, 0x1F );
break;
case BufferedImage.TYPE_BYTE_INDEXED:
@@ -287,7 +298,7 @@
public BufferedImage(ColorModel colormodel,
WritableRaster writableraster,
boolean premultiplied,
- Hashtable properties)
+ Hashtable<?,?> properties)
{
init(colormodel, writableraster, premultiplied, properties,
TYPE_CUSTOM);
@@ -347,6 +358,7 @@
public void coerceData(boolean premultiplied)
{
colorModel = colorModel.coerceData(raster, premultiplied);
+ isPremultiplied = premultiplied;
}
public WritableRaster copyData(WritableRaster dest)
@@ -616,7 +628,7 @@
};
}
- public Vector getSources()
+ public Vector<RenderedImage> getSources()
{
return null;
}
Modified: trunk/core/src/classpath/java/java/awt/image/ComponentColorModel.java
===================================================================
--- trunk/core/src/classpath/java/java/awt/image/ComponentColorModel.java 2007-01-27 09:39:31 UTC (rev 3088)
+++ trunk/core/src/classpath/java/java/awt/image/ComponentColorModel.java 2007-01-27 10:06:09 UTC (rev 3089)
@@ -306,16 +306,15 @@
public ColorModel coerceData(WritableRaster raster,
boolean isAlphaPremultiplied) {
- if (this.isAlphaPremultiplied == isAlphaPremultiplied)
+ if (this.isAlphaPremultiplied == isAlphaPremultiplied || !hasAlpha())
return this;
/* TODO: provide better implementation based on the
assumptions we can make due to the specific type of the
color model. */
- super.coerceData(raster, isAlphaPremultiplied);
+ super.coerceDataWorker(raster, isAlphaPremultiplied);
- return new ComponentColorModel(cspace, bits, hasAlpha(),
- isAlphaPremultiplied, // argument
+ return new ComponentColorModel(cspace, hasAlpha, isAlphaPremultiplied,
transparency, transferType);
}
Modified: trunk/core/src/classpath/java/java/awt/image/CropImageFilter.java
===================================================================
--- trunk/core/src/classpath/java/java/awt/image/CropImageFilter.java 2007-01-27 09:39:31 UTC (rev 3088)
+++ trunk/core/src/classpath/java/java/awt/image/CropImageFilter.java 2007-01-27 10:06:09 UTC (rev 3089)
@@ -91,11 +91,12 @@
*
* @param props the list of properties associated with this image
*/
- public void setProperties(Hashtable props)
+ public void setProperties(Hashtable<?, ?> props)
{
- props.put("filters", "CropImageFilter");
+ Hashtable<Object, Object> prop2 = (Hashtable<Object, Object>) props;
+ prop2.put("filters", "CropImageFilter");
if (consumer != null)
- consumer.setProperties(props);
+ consumer.setProperties(prop2);
}
/**
Modified: trunk/core/src/classpath/java/java/awt/image/DirectColorModel.java
===================================================================
--- trunk/core/src/classpath/java/java/awt/image/DirectColorModel.java 2007-01-27 09:39:31 UTC (rev 3088)
+++ trunk/core/src/classpath/java/java/awt/image/DirectColorModel.java 2007-01-27 10:06:09 UTC (rev 3089)
@@ -393,20 +393,20 @@
return Buffers.getData(buffer);
}
- public final ColorModel coerceData (WritableRaster raster,
+ public ColorModel coerceData (WritableRaster raster,
boolean isAlphaPremultiplied)
{
- if (this.isAlphaPremultiplied == isAlphaPremultiplied)
+ if (this.isAlphaPremultiplied == isAlphaPremultiplied || !hasAlpha())
return this;
/* TODO: provide better implementation based on the
assumptions we can make due to the specific type of the
color model. */
- super.coerceData(raster, isAlphaPremultiplied);
+ super.coerceDataWorker(raster, isAlphaPremultiplied);
- return new ComponentColorModel(cspace, bits, hasAlpha(),
- isAlphaPremultiplied, // argument
- transparency, transferType);
+ return new DirectColorModel(cspace, pixel_bits, getRedMask(),
+ getGreenMask(), getBlueMask(), getAlphaMask(),
+ isAlphaPremultiplied, transferType);
}
public boolean isCompatibleRaster(Raster raster)
Modified: trunk/core/src/classpath/java/java/awt/image/IndexColorModel.java
===================================================================
--- trunk/core/src/classpath/java/java/awt/image/IndexColorModel.java 2007-01-27 09:39:31 UTC (rev 3088)
+++ trunk/core/src/classpath/java/java/awt/image/IndexColorModel.java 2007-01-27 10:06:09 UTC (rev 3089)
@@ -134,11 +134,7 @@
if (size < 1)
throw new IllegalArgumentException("size < 1");
map_size = size;
- if (0 <= trans && trans < size) {
- this.trans = trans;
- transparency = BITMASK;
- }
- rgb = new int[size];
+ rgb = createColorMap(bits, size);
for (int i = 0; i < size; i++)
{
rgb[i] = (0xff000000
@@ -146,6 +142,9 @@
| ((greens[i] & 0xff) << 8)
| (blues[i] & 0xff));
}
+
+ setTransparentPixel(trans);
+
// Generate a bigint with 1's for every pixel
validBits = validBits.setBit(size).subtract(BigInteger.ONE);
}
@@ -188,7 +187,7 @@
map_size = size;
opaque = (alphas == null);
- rgb = new int[size];
+ rgb = createColorMap(bits, size);
if (alphas == null)
{
for (int i = 0; i < size; i++)
@@ -275,10 +274,8 @@
throw new IllegalArgumentException("size < 1");
map_size = size;
opaque = !hasAlpha;
- if (0 <= trans && trans < size)
- this.trans = trans;
- rgb = new int[size];
+ rgb = createColorMap(bits, size);
if (hasAlpha)
{
int alpha;
@@ -318,6 +315,8 @@
transparency = BITMASK;
}
+ setTransparentPixel(trans);
+
// Generate a bigint with 1's for every pixel
validBits = validBits.setBit(size).subtract(BigInteger.ONE);
}
@@ -361,16 +360,15 @@
throw new IllegalArgumentException("size < 1");
map_size = size;
opaque = !hasAlpha;
- if (0 <= trans && trans < size)
- this.trans = trans;
-
- rgb = new int[size];
+ rgb = createColorMap(bits, size);
if (!hasAlpha)
for (int i = 0; i < size; i++)
rgb[i] = cmap[i + start] | 0xff000000;
else
System.arraycopy(cmap, start, rgb, 0, size);
+ setTransparentPixel(trans);
+
// Generate a bigint with 1's for every pixel
validBits = validBits.setBit(size).subtract(BigInteger.ONE);
}
@@ -421,7 +419,7 @@
this.trans = -1;
this.validBits = validBits;
- rgb = new int[size];
+ rgb = createColorMap(bits, size);
if (!hasAlpha)
for (int i = 0; i < size; i++)
rgb[i] = cmap[i + start] | 0xff000000;
@@ -584,12 +582,7 @@
*/
public final int getAlpha(int pixel)
{
- if (opaque && pixel != trans)
- return 255;
- if ((pixel == trans && trans != -1) || pixel >= map_size)
- return 0;
-
- return (0xFF000000 & rgb[pixel]) >> 24;
+ return (rgb[pixel] >> 24) & 0xFF;
}
/**
@@ -694,4 +687,50 @@
return im;
}
+
+ /**
+ * Creates a {@link SampleModel} that is compatible to this color model.
+ * This will be a {@link MultiPixelPackedSampleModel} for bits/pixel of
+ * 1, 2 or 4, or a {@link ComponentColorModel} for the other cases.
+ *
+ * @param w the width of the sample model to create
+ * @param h the height of the sample model to create
+ *
+ * @return a compatible sample model
+ */
+ public SampleModel createCompatibleSampleModel(int w, int h)
+ {
+ SampleModel sm;
+ if (pixel_bits == 1 || pixel_bits == 2 || pixel_bits == 4)
+ sm = new MultiPixelPackedSampleModel(transferType, w, h, pixel_bits);
+ else
+ sm = new ComponentSampleModel(transferType, w, h, 1, w, new int[]{0});
+ return sm;
+ }
+
+ /**
+ * Sets the transparent pixel. This is called by the various constructors.
+ *
+ * @param t the transparent pixel
+ */
+ private void setTransparentPixel(int t)
+ {
+ if (t >= 0 && t < map_size)
+ {
+ rgb[t] &= 0xffffff; // Make the value transparent.
+ trans = t;
+ if (transparency == OPAQUE)
+ {
+ transparency = BITMASK;
+ hasAlpha = true;
+ }
+ }
+ }
+
+ private int[] createColorMap(int bits, int size)
+ {
+ // According to a Mauve test, the RI allocates at least 256 entries here.
+ int realSize = Math.max(256, Math.max(1 << bits, size));
+ return new int[realSize];
+ }
}
Modified: trunk/core/src/classpath/java/java/awt/image/MemoryImageSource.java
===================================================================
--- trunk/core/src/classpath/java/java/awt/image/MemoryImageSource.java 2007-01-27 09:39:31 UTC (rev 3088)
+++ trunk/core/src/classpath/java/java/awt/image/MemoryImageSource.java 2007-01-27 10:06:09 UTC (rev 3089)
@@ -1,5 +1,5 @@
/* MemoryImageSource.java -- Java class for providing image data
- Copyright (C) 1999, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2004, 2006, Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -41,6 +41,9 @@
import java.util.Hashtable;
import java.util.Vector;
+/**
+ * An image producer that delivers image data from an array.
+ */
public class MemoryImageSource implements ImageProducer
{
private boolean animated = false;
@@ -73,10 +76,19 @@
}
/**
- * Constructs an ImageProducer from memory
+ * Constructs an ImageProducer from memory.
+ *
+ * @param w the image width.
+ * @param h the image height.
+ * @param cm the color model.
+ * @param pix the image data.
+ * @param off the offset to the first pixel in the array.
+ * @param scan the number of array elements from a pixel on one row to the
+ * corresponding pixel on the next row.
+ * @param props image properties (<code>null</code> permitted).
*/
public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off,
- int scan, Hashtable props)
+ int scan, Hashtable<?,?> props)
{
width = w;
height = h;
@@ -106,10 +118,19 @@
}
/**
- Constructs an ImageProducer from memory
+ * Constructs an ImageProducer from memory
+ *
+ * @param w the image width.
+ * @param h the image height.
+ * @param cm the color model.
+ * @param pix the image data.
+ * @param off the offset to the first pixel in the array.
+ * @param scan the number of array elements from a pixel on one row to the
+ * corresponding pixel on the next row.
+ * @param props image properties (<code>null</code> permitted).
*/
public MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off,
- int scan, Hashtable props)
+ int scan, Hashtable<?,?> props)
{
width = w;
height = h;
@@ -122,16 +143,32 @@
}
/**
- * Constructs an ImageProducer from memory using the default RGB ColorModel
+ * Constructs an ImageProducer from memory using the default RGB ColorModel.
+ *
+ * @param w the image width.
+ * @param h the image height.
+ * @param pix the image data.
+ * @param off the offset to the first pixel in the array.
+ * @param scan the number of array elements from a pixel on one row to the
+ * corresponding pixel on the next row.
+ * @param props image properties (<code>null</code> permitted).
+
*/
public MemoryImageSource(int w, int h, int[] pix, int off, int scan,
- Hashtable props)
+ Hashtable<?,?> props)
{
this(w, h, ColorModel.getRGBdefault(), pix, off, scan, props);
}
/**
- * Constructs an ImageProducer from memory using the default RGB ColorModel
+ * Constructs an ImageProducer from memory using the default RGB ColorModel.
+ *
+ * @param w the image width.
+ * @param h the image height.
+ * @param pix the image data.
+ * @param off the offset to the first pixel in the array.
+ * @param scan the number of array elements from a pixel on one row to the
+ * corresponding pixel on the next row.
*/
public MemoryImageSource(int w, int h, int[] pix, int off, int scan)
{
@@ -141,6 +178,8 @@
/**
* Used to register an <code>ImageConsumer</code> with this
* <code>ImageProducer</code>.
+ *
+ * @param ic the image consumer.
*/
public synchronized void addConsumer(ImageConsumer ic)
{
@@ -153,6 +192,8 @@
/**
* Used to determine if the given <code>ImageConsumer</code> is
* already registered with this <code>ImageProducer</code>.
+ *
+ * @param ic the image consumer.
*/
public synchronized boolean isConsumer(ImageConsumer ic)
{
@@ -164,6 +205,8 @@
/**
* Used to remove an <code>ImageConsumer</code> from the list of
* registered consumers for this <code>ImageProducer</code>.
+ *
+ * @param ic the image consumer.
*/
public synchronized void removeConsumer(ImageConsumer ic)
{
@@ -197,6 +240,8 @@
* Used to register an <code>ImageConsumer</code> with this
* <code>ImageProducer</code> and then request that this producer
* resend the image data in the order top-down, left-right.
+ *
+ * @param ic the image consumer.
*/
public void requestTopDownLeftRightResend(ImageConsumer ic)
{
@@ -219,7 +264,7 @@
* sending animation. If this flag is set then full buffers are sent
* in the newPixels methods instead of just regions.
*
- * @param fullbuffers - a flag indicating whether to send the full buffers
+ * @param fullbuffers a flag indicating whether to send the full buffers
*/
public synchronized void setFullBufferUpdates(boolean fullbuffers)
{
@@ -260,6 +305,11 @@
/**
* Send an animation frame to the image consumers containing the specified
* pixels unless setFullBufferUpdates is set.
+ *
+ * @param x the x-coordinate.
+ * @param y the y-coordinate.
+ * @param w the width.
+ * @param h the height.
*/
public synchronized void newPixels(int x, int y, int w, int h)
{
@@ -306,6 +356,12 @@
*
* If framenotify is set then a notification is sent when the frame
* is sent otherwise no status is sent.
+ *
+ * @param x the x-coordinate.
+ * @param y the y-coordinate.
+ * @param w the width.
+ * @param h the height.
+ * @param framenotify send notification?
*/
public synchronized void newPixels(int x, int y, int w, int h,
boolean framenotify)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|