diff options
author | Matthias Klose <doko@gcc.gnu.org> | 2007-06-03 23:18:43 +0000 |
---|---|---|
committer | Matthias Klose <doko@gcc.gnu.org> | 2007-06-03 23:18:43 +0000 |
commit | e1bea0c0687c5f4551b3a6058ec37ce3705fa6cc (patch) | |
tree | a9c9e7d91c484d53fe154f9285fc57325572ce50 /libjava/classpath/java/awt/image | |
parent | af333b9a7f9e1cc1029bec56d48f2de63acdf686 (diff) | |
download | gcc-e1bea0c0687c5f4551b3a6058ec37ce3705fa6cc.zip gcc-e1bea0c0687c5f4551b3a6058ec37ce3705fa6cc.tar.gz gcc-e1bea0c0687c5f4551b3a6058ec37ce3705fa6cc.tar.bz2 |
libjava/classpath/ChangeLog.gcj:
2007-05-31 Matthias Klose <doko@ubuntu.com>
* javax/management/NotificationBroadcasterSupport.java
(getNotificationInfo): Add cast.
* native/jni/qt-peer/Makefile.am (AM_CXXFLAGS): Add libstdc++ include
directories.
* native/jni/qt-peer/Makefile.in: Regenerate.
libjava/ChangeLog:
2007-06-03 Matthias Klose <doko@ubuntu.com>
* java/io/natFileWin32.cc (setFilePermissions): New (stub only).
_access: Handle EXEC query, stub only.
2007-06-03 Matthias Klose <doko@ubuntu.com>
Merged from classpath:
* gnu/java/nio/SelectorProviderImpl.java: Whitespace merge.
* java/lang/System.java(inheritedChannel): New.
* java/lang/Character.java: Remove stray`;'.
* java/net/MulticastSocket.java: Merged.
* java/text/DateFormatSymbols.java(getInstance): New, comment updates.
* java/text/Collator.java(getInstance): Merged.
* java/util/Calendar.java: New attributes ALL_STYLES, SHORT, LONG.
getDisplayName, getDisplayNames: New.
* java/util/logging/Logger.java: Merged.
* Regenerate .class and .h files.
2007-06-03 Matthias Klose <doko@ubuntu.com>
* java/io/File.java: Merge with classpath-0.95, new method
setFilePermissions, new attribute EXEC.
* java/io/natFilePosix.cc (setFilePermissions): New.
_access: Handle EXEC query.
* classpath/lib/java/io/File.class, java/io/File.h: Regenerate.
2007-06-03 Matthias Klose <doko@ubuntu.com>
Imported GNU Classpath 0.95.
* classpath/Makefile.in,
classpath/native/jni/midi-dssi/Makefile.in,
classpath/native/jni/classpath/Makefile.in,
classpath/native/jni/Makefile.in,
classpath/native/jni/gconf-peer/Makefile.in,
classpath/native/jni/java-io/Makefile.in,
classpath/native/jni/native-lib/Makefile.in,
classpath/native/jni/java-util/Makefile.in,
classpath/native/jni/midi-alsa/Makefile.in,
classpath/native/jni/java-lang/Makefile.in,
classpath/native/jni/java-nio/Makefile.in,
classpath/native/jni/java-net/Makefile.in,
classpath/native/jni/xmlj/Makefile.in,
classpath/native/jni/qt-peer/Makefile.in,
classpath/native/jni/gtk-peer/Makefile.in,
classpath/native/Makefile.in, classpath/native/jawt/Makefile.in,
classpath/native/fdlibm/Makefile.in,
classpath/native/plugin/Makefile.in,
classpath/resource/Makefile.in, classpath/scripts/Makefile.in,
classpath/tools/Makefile.in, classpath/doc/Makefile.in,
classpath/doc/api/Makefile.in, classpath/lib/Makefile.in,
classpath/external/Makefile.in, classpath/external/jsr166/Makefile.in,
classpath/external/sax/Makefile.in,
classpath/external/w3c_dom/Makefile.in,
classpath/external/relaxngDatatype/Makefile.in,
classpath/include/Makefile.in,
classpath/examples/Makefile.in: Regenerate.
* classpath/config.guess, classpath/config.sub,
classpath/ltmain.sh : Update.
* classpath/configure, classpath/depcomp, classpath/missing,
classpath/aclocal.m4, classpath/install-sh: Regenerate.
* gnu/classpath/Configuration.java (CLASSPATH_VERSION): Now 0.95.
* sources.am: Regenerate.
* Makefile.in: Regenerate.
* Update the .class files and generated CNI header files, add new
.class and generated CNI header files.
* Remove generated files for removed java source files:
classpath/gnu/java/net/BASE64.java,
classpath/gnu/java/security/util/Base64.java,
classpath/gnu/java/awt/peer/gtk/GThreadMutex.java,
classpath/gnu/java/awt/peer/gtk/GThreadNativeMethodRunner.java,
classpath/gnu/java/awt/font/autofit/Scaler.java,
classpath/gnu/classpath/jdwp/util/Value.java,
classpath/gnu/javax/net/ssl/Base64.java.
* Remove empty directories.
* Makefile.am(nat_source_files): Add natVMOperatingSystemMXBeanImpl.cc.
* java/lang/Class.java(setAccessible): Merge from classpath.
* java/util/Locale.java: Remove.
* gnu/java/lang/management/VMOperatingSystemMXBeanImpl.java,
gnu/java/lang/management/natVMOperatingSystemMXBeanImpl.cc: New.
* gcj/javaprims.h: Update class declarations.
* scripts/classes.pl: Update usage.
* HACKING: Mention to build all peers.
From-SVN: r125302
Diffstat (limited to 'libjava/classpath/java/awt/image')
4 files changed, 371 insertions, 571 deletions
diff --git a/libjava/classpath/java/awt/image/BufferedImage.java b/libjava/classpath/java/awt/image/BufferedImage.java index ef3141d..c987946 100644 --- a/libjava/classpath/java/awt/image/BufferedImage.java +++ b/libjava/classpath/java/awt/image/BufferedImage.java @@ -39,7 +39,9 @@ exception statement from your version. */ package java.awt.image; import gnu.java.awt.Buffers; +import gnu.java.awt.ClasspathGraphicsEnvironment; import gnu.java.awt.ComponentDataBlitOp; +import gnu.java.awt.peer.gtk.CairoSurface; import java.awt.Graphics; import java.awt.Graphics2D; @@ -83,7 +85,7 @@ public class BufferedImage extends Image /** * Vector of TileObservers (or null) */ - Vector tileObservers; + Vector<TileObserver> tileObservers; /** * The image's WritableRaster @@ -143,39 +145,39 @@ public class BufferedImage extends Image { SampleModel sm = null; ColorModel cm = null; - boolean premultiplied = (type == BufferedImage.TYPE_INT_ARGB_PRE || - type == BufferedImage.TYPE_4BYTE_ABGR_PRE); + boolean premultiplied = (type == BufferedImage.TYPE_INT_ARGB_PRE + || type == BufferedImage.TYPE_4BYTE_ABGR_PRE); switch( type ) { case BufferedImage.TYPE_INT_RGB: - sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_INT, - width, height, - new int[]{ 0x00FF0000, - 0x0000FF00, - 0x000000FF } ) ; - cm = new DirectColorModel( 24, 0xff0000, 0xff00, 0xff ); - break; + sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_INT, + width, height, + new int[]{ 0x00FF0000, + 0x0000FF00, + 0x000000FF } ) ; + cm = new DirectColorModel( 24, 0xff0000, 0xff00, 0xff ); + break; case BufferedImage.TYPE_3BYTE_BGR: - sm = new PixelInterleavedSampleModel( DataBuffer.TYPE_BYTE, - width, height, - 3, width * 3, - new int[]{ 2, 1, 0 } ); - cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), - false, false, - BufferedImage.OPAQUE, - DataBuffer.TYPE_BYTE); + sm = new PixelInterleavedSampleModel( DataBuffer.TYPE_BYTE, + width, height, + 3, width * 3, + new int[]{ 2, 1, 0 } ); + cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), + false, false, + BufferedImage.OPAQUE, + DataBuffer.TYPE_BYTE); break; case BufferedImage.TYPE_INT_ARGB: case BufferedImage.TYPE_INT_ARGB_PRE: - sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_INT, - width, height, - new int[]{ 0x00FF0000, - 0x0000FF00, - 0x000000FF, - 0xFF000000 } ); + sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_INT, + width, height, + new int[]{ 0x00FF0000, + 0x0000FF00, + 0x000000FF, + 0xFF000000 } ); if (premultiplied) cm = new DirectColorModel( ColorSpace.getInstance(ColorSpace.CS_sRGB), 32, 0xff0000, 0xff00, 0xff, 0xff000000, @@ -183,7 +185,8 @@ public class BufferedImage extends Image Buffers.smallestAppropriateTransferType(32)); else cm = new DirectColorModel( 32, 0xff0000, 0xff00, 0xff, 0xff000000 ); - break; + + break; case BufferedImage.TYPE_4BYTE_ABGR: case BufferedImage.TYPE_4BYTE_ABGR_PRE: @@ -195,57 +198,58 @@ public class BufferedImage extends Image true, premultiplied, BufferedImage.TRANSLUCENT, DataBuffer.TYPE_BYTE); - break; + break; case BufferedImage.TYPE_INT_BGR: - sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_INT, - width, height, - new int[]{ 0x000000FF, - 0x0000FF00, - 0x00FF0000 } ) ; - cm = new DirectColorModel( 24, 0xff, 0xff00, 0xff0000 ); + sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_INT, + width, height, + new int[]{ 0x000000FF, + 0x0000FF00, + 0x00FF0000 } ) ; + cm = new DirectColorModel( 24, 0xff, 0xff00, 0xff0000 ); break; case BufferedImage.TYPE_USHORT_565_RGB: - sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_USHORT, - width, height, - new int[]{ 0xF800, - 0x7E0, - 0x1F } ) ; - cm = new DirectColorModel( 16, 0xF800, 0x7E0, 0x1F ); - break; + sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_USHORT, + width, height, + 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[]{ 0x7C00, - 0x3E0, - 0x1F } ) ; - cm = new DirectColorModel( 15, 0x7C00, 0x3E0, 0x1F ); - break; + sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_USHORT, + width, height, + new int[]{ 0x7C00, + 0x3E0, + 0x1F } ) ; + cm = new DirectColorModel( 15, 0x7C00, 0x3E0, 0x1F ); + break; case BufferedImage.TYPE_BYTE_INDEXED: - cm = createDefaultIndexedColorModel( false ); + cm = createDefaultIndexedColorModel( false ); case BufferedImage.TYPE_BYTE_GRAY: - sm = new PixelInterleavedSampleModel( DataBuffer.TYPE_BYTE, - width, height, - 1, width, new int[]{ 0 } ); - break; + sm = new PixelInterleavedSampleModel( DataBuffer.TYPE_BYTE, + width, height, + 1, width, new int[]{ 0 } ); + break; case BufferedImage.TYPE_USHORT_GRAY: - sm = new PixelInterleavedSampleModel( DataBuffer.TYPE_USHORT, - width, height, - 1, width, new int[]{ 0 } ); - break; + sm = new PixelInterleavedSampleModel( DataBuffer.TYPE_USHORT, + width, height, + 1, width, new int[]{ 0 } ); + break; case BufferedImage.TYPE_BYTE_BINARY: - cm = createDefaultIndexedColorModel( true ); - sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, - width, height, 1); - break; + cm = createDefaultIndexedColorModel( true ); + sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, + width, height, 1); + break; default: - sm = null; + sm = null; } if( sm == null ) @@ -253,33 +257,41 @@ public class BufferedImage extends Image if( cm == null ) // only for the grayscale types { - int buftype; - int[] bits = new int[1]; - if( type == BufferedImage.TYPE_BYTE_GRAY ) - { - buftype = DataBuffer.TYPE_BYTE; - bits[0] = 8; - } - else - { - buftype = DataBuffer.TYPE_USHORT; - bits[0] = 16; - } - ColorSpace graySpace = ColorSpace.getInstance( ColorSpace.CS_GRAY ); - - cm = new ComponentColorModel( graySpace, bits, false, false, - Transparency.OPAQUE, buftype ); + int buftype; + int[] bits = new int[1]; + if( type == BufferedImage.TYPE_BYTE_GRAY ) + { + buftype = DataBuffer.TYPE_BYTE; + bits[0] = 8; + } + else + { + buftype = DataBuffer.TYPE_USHORT; + bits[0] = 16; + } + ColorSpace graySpace = ColorSpace.getInstance( ColorSpace.CS_GRAY ); + + cm = new ComponentColorModel( graySpace, bits, false, false, + Transparency.OPAQUE, buftype ); } - init( cm, - Raster.createWritableRaster(sm, new Point( 0, 0 ) ), - premultiplied, - null, // no properties - type ); + WritableRaster rst = null; + + // Attempt to create an accelerated backend for this image + GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); + if (env instanceof ClasspathGraphicsEnvironment) + rst = ((ClasspathGraphicsEnvironment)env).createRaster(cm, sm); + + // Default to a standard Java raster & databuffer if needed + if (rst == null) + rst = Raster.createWritableRaster(sm, new Point( 0, 0 ) ); + + init(cm, rst, premultiplied, + null, // no properties + type ); } - public BufferedImage(int w, int h, int type, - IndexColorModel indexcolormodel) + public BufferedImage(int w, int h, int type, IndexColorModel indexcolormodel) { if ((type != TYPE_BYTE_BINARY) && (type != TYPE_BYTE_INDEXED)) throw new IllegalArgumentException("Type must be TYPE_BYTE_BINARY or TYPE_BYTE_INDEXED"); @@ -289,27 +301,21 @@ public class BufferedImage extends Image throw new IllegalArgumentException("Byte type cannot have a larger than 256-color palette."); init( indexcolormodel, - indexcolormodel.createCompatibleWritableRaster(w, h), - indexcolormodel.isAlphaPremultiplied(), - null, // no properties - type ); + indexcolormodel.createCompatibleWritableRaster(w, h), + indexcolormodel.isAlphaPremultiplied(), + null, // no properties + type ); } - public BufferedImage(ColorModel colormodel, - WritableRaster writableraster, - boolean premultiplied, - Hashtable<?,?> properties) + public BufferedImage(ColorModel colormodel, WritableRaster writableraster, + boolean premultiplied, Hashtable<?,?> properties) { - init(colormodel, writableraster, premultiplied, properties, - TYPE_CUSTOM); + init(colormodel, writableraster, premultiplied, properties, TYPE_CUSTOM); } - private void init(ColorModel cm, - WritableRaster writableraster, - boolean premultiplied, - Hashtable properties, - int type) + private void init(ColorModel cm, WritableRaster writableraster, + boolean premultiplied, Hashtable properties, int type) { raster = writableraster; colorModel = cm; @@ -329,29 +335,32 @@ public class BufferedImage extends Image { if( binary ) { - byte[] t = new byte[]{ 0, (byte)255 }; - return new IndexColorModel( 1, 2, t, t, t ); + byte[] t = new byte[]{ 0, (byte)255 }; + return new IndexColorModel( 1, 2, t, t, t ); } byte[] r = new byte[256]; byte[] g = new byte[256]; byte[] b = new byte[256]; + int index = 0; for( int i = 0; i < 6; i++ ) for( int j = 0; j < 6; j++ ) - for( int k = 0; k < 6; k++ ) - { - r[ index ] = (byte)(i * 51); - g[ index ] = (byte)(j * 51); - b[ index ] = (byte)(k * 51); - index++; - } + for( int k = 0; k < 6; k++ ) + { + r[ index ] = (byte)(i * 51); + g[ index ] = (byte)(j * 51); + b[ index ] = (byte)(k * 51); + index++; + } + while( index < 256 ) { - r[ index ] = g[ index ] = b[ index ] = - (byte)(18 + (index - 216) * 6); - index++; + r[ index ] = g[ index ] = b[ index ] = + (byte)(18 + (index - 216) * 6); + index++; } + return new IndexColorModel( 8, 256, r, g, b ); } @@ -375,12 +384,13 @@ public class BufferedImage extends Image // create a src child that has the right bounds... WritableRaster src = raster.createWritableChild(x, y, w, h, x, y, - null // same bands - ); + null); // same bands + if (src.getSampleModel () instanceof ComponentSampleModel && dest.getSampleModel () instanceof ComponentSampleModel) // Refer to ComponentDataBlitOp for optimized data blitting: ComponentDataBlitOp.INSTANCE.filter(src, dest); + else { // slower path @@ -397,7 +407,8 @@ public class BufferedImage extends Image return env.createGraphics (this); } - public void flush() { + public void flush() + { } public WritableRaster getAlphaRaster() @@ -512,26 +523,24 @@ public class BufferedImage extends Image public int getRGB(int x, int y) { - Object rgbElem = raster.getDataElements(x, y, - null // create as needed - ); + Object rgbElem = raster.getDataElements(x, y, null); return colorModel.getRGB(rgbElem); } - public int[] getRGB(int startX, int startY, int w, int h, - int[] rgbArray, - int offset, int scanlineStride) + public int[] getRGB(int startX, int startY, int w, int h, int[] rgbArray, + int offset, int scanlineStride) { if (rgbArray == null) - { - /* - 000000000000000000 - 00000[#######----- [ = start - -----########----- ] = end - -----#######]00000 - 000000000000000000 */ - int size = (h-1)*scanlineStride + w; - rgbArray = new int[size]; + { + /* + 000000000000000000 + 00000[#######----- [ = start + -----########----- ] = end + -----#######]00000 + 000000000000000000 + */ + int size = (h-1)*scanlineStride + w; + rgbArray = new int[size]; } int endX = startX + w; @@ -547,15 +556,15 @@ public class BufferedImage extends Image Object rgbElem = null; for (int y=startY; y<endY; y++) { - int xoffset = offset; - for (int x=startX; x<endX; x++) - { - int rgb; - rgbElem = raster.getDataElements(x, y, rgbElem); - rgb = colorModel.getRGB(rgbElem); - rgbArray[xoffset++] = rgb; - } - offset += scanlineStride; + int xoffset = offset; + for (int x=startX; x<endX; x++) + { + int rgb; + rgbElem = raster.getDataElements(x, y, rgbElem); + rgb = colorModel.getRGB(rgbElem); + rgbArray[xoffset++] = rgb; + } + offset += scanlineStride; } return rgbArray; } @@ -572,14 +581,14 @@ public class BufferedImage extends Image public ImageProducer getSource() { - return new ImageProducer() { - - Vector consumers = new Vector(); + return new ImageProducer() + { + Vector<ImageConsumer> consumers = new Vector<ImageConsumer>(); public void addConsumer(ImageConsumer ic) { - if(!consumers.contains(ic)) - consumers.add(ic); + if(!consumers.contains(ic)) + consumers.add(ic); } public boolean isConsumer(ImageConsumer ic) @@ -589,7 +598,7 @@ public class BufferedImage extends Image public void removeConsumer(ImageConsumer ic) { - consumers.remove(ic); + consumers.remove(ic); } public void startProduction(ImageConsumer ic) @@ -610,9 +619,9 @@ public class BufferedImage extends Image consumers.add(ic); - for(int i=0;i<consumers.size();i++) + for(int i = 0; i < consumers.size(); i++) { - ImageConsumer c = (ImageConsumer) consumers.elementAt(i); + ImageConsumer c = consumers.elementAt(i); c.setHints(ImageConsumer.SINGLEPASS); c.setDimensions(getWidth(), getHeight()); c.setPixels(x, y, width, height, model, pixels, offset, stride); @@ -638,10 +647,8 @@ public class BufferedImage extends Image WritableRaster subRaster = getRaster().createWritableChild(x, y, w, h, 0, 0, null); - return new BufferedImage(getColorModel(), - subRaster, - isPremultiplied, - properties); + return new BufferedImage(getColorModel(), subRaster, isPremultiplied, + properties); } public Raster getTile(int tileX, int tileY) @@ -730,9 +737,7 @@ public class BufferedImage extends Image // create a dest child that has the right bounds... WritableRaster dest = - raster.createWritableChild(x, y, w, h, x, y, - null // same bands - ); + raster.createWritableChild(x, y, w, h, x, y, null); if (src.getSampleModel () instanceof ComponentSampleModel && dest.getSampleModel () instanceof ComponentSampleModel) @@ -762,14 +767,14 @@ public class BufferedImage extends Image Object rgbElem = null; for (int y=startY; y<endY; y++) { - int xoffset = offset; - for (int x=startX; x<endX; x++) - { - int argb = argbArray[xoffset++]; - rgbElem = colorModel.getDataElements(argb, rgbElem); - raster.setDataElements(x, y, rgbElem); - } - offset += scanlineStride; + int xoffset = offset; + for (int x=startX; x<endX; x++) + { + int argb = argbArray[xoffset++]; + rgbElem = colorModel.getDataElements(argb, rgbElem); + raster.setDataElements(x, y, rgbElem); + } + offset += scanlineStride; } } @@ -800,7 +805,7 @@ public class BufferedImage extends Image public void addTileObserver (TileObserver to) { if (tileObservers == null) - tileObservers = new Vector (); + tileObservers = new Vector<TileObserver>(); tileObservers.add (to); } diff --git a/libjava/classpath/java/awt/image/ComponentSampleModel.java b/libjava/classpath/java/awt/image/ComponentSampleModel.java index bccabbb..73e7fb4 100644 --- a/libjava/classpath/java/awt/image/ComponentSampleModel.java +++ b/libjava/classpath/java/awt/image/ComponentSampleModel.java @@ -36,12 +36,8 @@ exception statement from your version. */ package java.awt.image; -import gnu.java.awt.Buffers; - import java.util.Arrays; -/* FIXME: This class does not yet support data type TYPE_SHORT */ - /** * ComponentSampleModel supports a flexible organization of pixel samples in * memory, permitting pixel samples to be interleaved by band, by scanline, @@ -88,9 +84,7 @@ public class ComponentSampleModel extends SampleModel * corresponding sample for the next pixel in the same row. */ protected int pixelStride; - - private boolean tightPixelPacking = false; - + /** * Creates a new sample model that assumes that all bands are stored in a * single bank of the {@link DataBuffer}. @@ -203,22 +197,6 @@ public class ComponentSampleModel extends SampleModel this.scanlineStride = scanlineStride; this.pixelStride = pixelStride; - // See if we can use some speedups - - /* FIXME: May these checks should be reserved for the - PixelInterleavedSampleModel? */ - - if (pixelStride == numBands) - { - tightPixelPacking = true; - for (int b = 0; b < numBands; b++) { - if ((bandOffsets[b] != b) || (bankIndices[b] != 0)) - { - tightPixelPacking = false; - break; - } - } - } } /** @@ -275,8 +253,30 @@ public class ComponentSampleModel extends SampleModel highestOffset = Math.max(highestOffset, bandOffsets[b]); int size = pixelStride * (width - 1) + scanlineStride * (height - 1) + highestOffset + 1; - - return Buffers.createBuffer(getDataType(), size, numBanks); + + DataBuffer buffer = null; + switch (getTransferType()) + { + case DataBuffer.TYPE_BYTE: + buffer = new DataBufferByte(size, numBanks); + break; + case DataBuffer.TYPE_SHORT: + buffer = new DataBufferShort(size, numBanks); + break; + case DataBuffer.TYPE_USHORT: + buffer = new DataBufferUShort(size, numBanks); + break; + case DataBuffer.TYPE_INT: + buffer = new DataBufferInt(size, numBanks); + break; + case DataBuffer.TYPE_FLOAT: + buffer = new DataBufferFloat(size, numBanks); + break; + case DataBuffer.TYPE_DOUBLE: + buffer = new DataBufferDouble(size, numBanks); + break; + } + return buffer; } /** @@ -424,239 +424,80 @@ public class ComponentSampleModel extends SampleModel */ public Object getDataElements(int x, int y, Object obj, DataBuffer data) { - int xyOffset = pixelStride * x + scanlineStride * y; - - int[] totalBandDataOffsets = new int[numBands]; - - /* Notice that band and bank offsets are different. Band offsets - are managed by the sample model, and bank offsets are managed - by the data buffer. Both must be accounted for. */ - - /* FIXME: For single pixels, it is probably easier to simple - call getElem instead of calculating the bank offset ourself. - - On the other hand, then we need to push the value through - the int type returned by the getElem method. */ - - int[] bankOffsets = data.getOffsets(); - - for (int b = 0; b < numBands; b++) + int type = getTransferType(); + int numDataEls = getNumDataElements(); + int offset = y * scanlineStride + x * pixelStride; + switch (type) { - totalBandDataOffsets[b] = bandOffsets[b] + bankOffsets[bankIndices[b]] - + xyOffset; - } - - try - { - switch (getTransferType()) + case DataBuffer.TYPE_BYTE: + byte[] bData; + if (obj == null) + bData = new byte[numDataEls]; + else + bData = (byte[]) obj; + for (int i = 0; i < numDataEls; i++) { - case DataBuffer.TYPE_BYTE: - DataBufferByte inByte = (DataBufferByte) data; - byte[] outByte = (byte[]) obj; - if (outByte == null) - outByte = new byte[numBands]; - - for (int b = 0; b < numBands; b++) - { - int dOffset = totalBandDataOffsets[b]; - outByte[b] = inByte.getData(bankIndices[b])[dOffset]; - } - return outByte; - - case DataBuffer.TYPE_USHORT: - DataBufferUShort inUShort = (DataBufferUShort) data; - short[] outUShort = (short[]) obj; - if (outUShort == null) - outUShort = new short[numBands]; - - for (int b = 0; b < numBands; b++) - { - int dOffset = totalBandDataOffsets[b]; - outUShort[b] = inUShort.getData(bankIndices[b])[dOffset]; - } - return outUShort; - - case DataBuffer.TYPE_SHORT: - DataBufferShort inShort = (DataBufferShort) data; - short[] outShort = (short[]) obj; - if (outShort == null) - outShort = new short[numBands]; - - for (int b = 0; b < numBands; b++) - { - int dOffset = totalBandDataOffsets[b]; - outShort[b] = inShort.getData(bankIndices[b])[dOffset]; - } - return outShort; - - case DataBuffer.TYPE_INT: - DataBufferInt inInt = (DataBufferInt) data; - int[] outInt = (int[]) obj; - if (outInt == null) - outInt = new int[numBands]; - - for (int b = 0; b < numBands; b++) - { - int dOffset = totalBandDataOffsets[b]; - outInt[b] = inInt.getData(bankIndices[b])[dOffset]; - } - return outInt; - - case DataBuffer.TYPE_FLOAT: - DataBufferFloat inFloat = (DataBufferFloat) data; - float[] outFloat = (float[]) obj; - if (outFloat == null) - outFloat = new float[numBands]; - - for (int b = 0; b < numBands; b++) - { - int dOffset = totalBandDataOffsets[b]; - outFloat[b] = inFloat.getData(bankIndices[b])[dOffset]; - } - return outFloat; - - case DataBuffer.TYPE_DOUBLE: - DataBufferDouble inDouble = (DataBufferDouble) data; - double[] outDouble = (double[]) obj; - if (outDouble == null) - outDouble = new double[numBands]; - - for (int b = 0; b < numBands; b++) - { - int dOffset = totalBandDataOffsets[b]; - outDouble[b] = inDouble.getData(bankIndices[b])[dOffset]; - } - return outDouble; - - default: - throw new IllegalStateException("unknown transfer type " - + getTransferType()); + bData[i] = (byte) data.getElem(bankIndices[i], + offset + bandOffsets[i]); } - } - catch (ArrayIndexOutOfBoundsException aioobe) - { - String msg = "While reading data elements, " + - "x=" + x + ", y=" + y +", " + ", xyOffset=" + xyOffset + - ", data.getSize()=" + data.getSize() + ": " + aioobe; - throw new ArrayIndexOutOfBoundsException(msg); - } - } - - /** - * Returns the samples for the pixels in the region defined by - * <code>(x, y, w, h)</code> in a primitive array (the array type is - * determined by the data type for this model). The <code>obj</code> - * argument provides an option to supply an existing array to hold the - * result, if this is <code>null</code> a new array will be allocated. - * - * @param x the x-coordinate. - * @param y the y-coordinate. - * @param w the width. - * @param h the height. - * @param obj a primitive array that, if not <code>null</code>, will be - * used to store and return the sample values. - * @param data the data buffer (<code>null</code> not permitted). - * - * @return An array of sample values for the specified pixels. - * - * @see #setDataElements(int, int, int, int, Object, DataBuffer) - */ - public Object getDataElements(int x, int y, int w, int h, Object obj, - DataBuffer data) - { - if (!tightPixelPacking) - { - return super.getDataElements(x, y, w, h, obj, data); - } - - // using get speedup - - // We can copy whole rows - int rowSize = w * numBands; - int dataSize = rowSize * h; - - DataBuffer transferBuffer = Buffers.createBuffer(getTransferType(), obj, - dataSize); - obj = Buffers.getData(transferBuffer); - - int inOffset = pixelStride * x + scanlineStride * y + data.getOffset(); - // Assumes only one band is used - - /* We don't add band offsets since we assume that bands have - offsets 0, 1, 2, ... */ - - // See if we can copy everything in one go - if (scanlineStride == rowSize) - { - // Collapse scan lines: - rowSize *= h; - // We ignore scanlineStride since it won't be of any use - h = 1; - } - - int outOffset = 0; - Object inArray = Buffers.getData(data); - for (int yd = 0; yd < h; yd++) - { - System.arraycopy(inArray, inOffset, obj, outOffset, rowSize); - inOffset += scanlineStride; - outOffset += rowSize; + obj = bData; + break; + case DataBuffer.TYPE_SHORT: + case DataBuffer.TYPE_USHORT: + short[] sData; + if (obj == null) + sData = new short[numDataEls]; + else + sData = (short[]) obj; + for (int i = 0; i < numDataEls; i++) + { + sData[i] = (short) data.getElem(bankIndices[i], + offset + bandOffsets[i]); + } + obj = sData; + break; + case DataBuffer.TYPE_INT: + int[] iData; + if (obj == null) + iData = new int[numDataEls]; + else + iData = (int[]) obj; + for (int i = 0; i < numDataEls; i++) + { + iData[i] = data.getElem(bankIndices[i], offset + bandOffsets[i]); + } + obj = iData; + break; + case DataBuffer.TYPE_FLOAT: + float[] fData; + if (obj == null) + fData = new float[numDataEls]; + else + fData = (float[]) obj; + for (int i = 0; i < numDataEls; i++) + { + fData[i] = data.getElemFloat(bankIndices[i], + offset + bandOffsets[i]); + } + obj = fData; + break; + case DataBuffer.TYPE_DOUBLE: + double[] dData; + if (obj == null) + dData = new double[numDataEls]; + else + dData = (double[]) obj; + for (int i = 0; i < numDataEls; i++) + { + dData[i] = data.getElemDouble(bankIndices[i], + offset + bandOffsets[i]); + } + obj = dData; + break; } return obj; } - /** - * Sets the samples for the pixels in the region defined by - * <code>(x, y, w, h)</code> from a supplied primitive array (the array type - * must be consistent with the data type for this model). - * - * @param x the x-coordinate. - * @param y the y-coordinate. - * @param w the width. - * @param h the height. - * @param obj a primitive array containing the sample values. - * @param data the data buffer (<code>null</code> not permitted). - * - * @see #getDataElements(int, int, int, int, Object, DataBuffer) - */ - public void setDataElements(int x, int y, int w, int h, - Object obj, DataBuffer data) - { - if (!tightPixelPacking) - { - super.setDataElements(x, y, w, h, obj, data); - return; - } - - // using set speedup, we can copy whole rows - int rowSize = w * numBands; - int dataSize = rowSize * h; - - DataBuffer transferBuffer - = Buffers.createBufferFromData(getTransferType(), obj, dataSize); - - int[] bankOffsets = data.getOffsets(); - - int outOffset = pixelStride * x + scanlineStride * y + bankOffsets[0]; - // same assumptions as in get... - - // See if we can copy everything in one go - if (scanlineStride == rowSize) - { - // Collapse scan lines: - rowSize *= h; - h = 1; - } - - int inOffset = 0; - Object outArray = Buffers.getData(data); - for (int yd = 0; yd < h; yd++) - { - System.arraycopy(obj, inOffset, outArray, outOffset, rowSize); - outOffset += scanlineStride; - inOffset += rowSize; - } - } /** * Returns all the samples for the pixel at location <code>(x, y)</code> @@ -764,78 +605,51 @@ public class ComponentSampleModel extends SampleModel */ public void setDataElements(int x, int y, Object obj, DataBuffer data) { - int offset = pixelStride * x + scanlineStride * y; - int[] totalBandDataOffsets = new int[numBands]; - int[] bankOffsets = data.getOffsets(); - for (int b = 0; b < numBands; b++) - totalBandDataOffsets[b] = bandOffsets[b] + bankOffsets[bankIndices[b]] - + offset; - - switch (getTransferType()) + int type = getTransferType(); + int numDataEls = getNumDataElements(); + int offset = y * scanlineStride + x * pixelStride; + switch (type) { case DataBuffer.TYPE_BYTE: - { - DataBufferByte out = (DataBufferByte) data; - byte[] in = (byte[]) obj; - - for (int b = 0; b < numBands; b++) - out.getData(bankIndices[b])[totalBandDataOffsets[b]] = in[b]; - - return; - } - case DataBuffer.TYPE_USHORT: - { - DataBufferUShort out = (DataBufferUShort) data; - short[] in = (short[]) obj; - - for (int b = 0; b < numBands; b++) - out.getData(bankIndices[b])[totalBandDataOffsets[b]] = in[b]; - - return; - } + byte[] bData = (byte[]) obj; + for (int i = 0; i < numDataEls; i++) + { + data.setElem(bankIndices[i], offset + bandOffsets[i], + ((int) bData[i]) & 0xFF); + } + break; case DataBuffer.TYPE_SHORT: - { - DataBufferShort out = (DataBufferShort) data; - short[] in = (short[]) obj; - - for (int b = 0; b < numBands; b++) - out.getData(bankIndices[b])[totalBandDataOffsets[b]] = in[b]; - - return; - } + case DataBuffer.TYPE_USHORT: + short[] sData = (short[]) obj; + for (int i = 0; i < numDataEls; i++) + { + data.setElem(bankIndices[i], offset + bandOffsets[i], + ((int) sData[i]) & 0xFFFF); + } + break; case DataBuffer.TYPE_INT: - { - DataBufferInt out = (DataBufferInt) data; - int[] in = (int[]) obj; - - for (int b = 0; b < numBands; b++) - out.getData(bankIndices[b])[totalBandDataOffsets[b]] = in[b]; - - return; - } + int[] iData = (int[]) obj; + for (int i = 0; i < numDataEls; i++) + { + data.setElem(bankIndices[i], offset + bandOffsets[i], iData[i]); + } + break; case DataBuffer.TYPE_FLOAT: - { - DataBufferFloat out = (DataBufferFloat) data; - float[] in = (float[]) obj; - - for (int b = 0; b < numBands; b++) - out.getData(bankIndices[b])[totalBandDataOffsets[b]] = in[b]; - - return; - } + float[] fData = (float[]) obj; + for (int i = 0; i < numDataEls; i++) + { + data.setElemFloat(bankIndices[i], offset + bandOffsets[i], + fData[i]); + } + break; case DataBuffer.TYPE_DOUBLE: - { - DataBufferDouble out = (DataBufferDouble) data; - double[] in = (double[]) obj; - - for (int b = 0; b < numBands; b++) - out.getData(bankIndices[b])[totalBandDataOffsets[b]] = in[b]; - - return; - } - default: - throw new UnsupportedOperationException("transfer type not " + - "implemented"); + double[] dData = (double[]) obj; + for (int i = 0; i < numDataEls; i++) + { + data.setElemDouble(bankIndices[i], offset + bandOffsets[i], + dData[i]); + } + break; } } diff --git a/libjava/classpath/java/awt/image/IndexColorModel.java b/libjava/classpath/java/awt/image/IndexColorModel.java index 46879cc..d8a27d5 100644 --- a/libjava/classpath/java/awt/image/IndexColorModel.java +++ b/libjava/classpath/java/awt/image/IndexColorModel.java @@ -134,7 +134,7 @@ public class IndexColorModel extends ColorModel if (size < 1) throw new IllegalArgumentException("size < 1"); map_size = size; - rgb = new int[size]; + rgb = createColorMap(bits, size); for (int i = 0; i < size; i++) { rgb[i] = (0xff000000 @@ -187,7 +187,7 @@ public class IndexColorModel extends ColorModel 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,7 +275,7 @@ public class IndexColorModel extends ColorModel map_size = size; opaque = !hasAlpha; - rgb = new int[size]; + rgb = createColorMap(bits, size); if (hasAlpha) { int alpha; @@ -360,7 +360,7 @@ public class IndexColorModel extends ColorModel throw new IllegalArgumentException("size < 1"); map_size = size; opaque = !hasAlpha; - rgb = new int[size]; + rgb = createColorMap(bits, size); if (!hasAlpha) for (int i = 0; i < size; i++) rgb[i] = cmap[i + start] | 0xff000000; @@ -419,7 +419,7 @@ public class IndexColorModel extends ColorModel 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; @@ -726,4 +726,11 @@ public class IndexColorModel extends ColorModel } } } + + 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]; + } } diff --git a/libjava/classpath/java/awt/image/SinglePixelPackedSampleModel.java b/libjava/classpath/java/awt/image/SinglePixelPackedSampleModel.java index 9ed948c..1b0ac3f 100644 --- a/libjava/classpath/java/awt/image/SinglePixelPackedSampleModel.java +++ b/libjava/classpath/java/awt/image/SinglePixelPackedSampleModel.java @@ -39,7 +39,6 @@ package java.awt.image; import java.util.Arrays; import gnu.java.awt.BitMaskExtent; -import gnu.java.awt.Buffers; /** * A <code>SampleModel</code> used when all samples are stored in a single @@ -151,14 +150,25 @@ public class SinglePixelPackedSampleModel extends SampleModel */ public DataBuffer createDataBuffer() { - int size; - // We can save (scanlineStride - width) pixels at the very end of // the buffer. The Sun reference implementation (J2SE 1.3.1 and // 1.4.1_01) seems to do this; tested with Mauve test code. - size = scanlineStride * (height - 1) + width; + int size = scanlineStride * (height - 1) + width; - return Buffers.createBuffer(getDataType(), size); + DataBuffer buffer = null; + switch (getTransferType()) + { + case DataBuffer.TYPE_BYTE: + buffer = new DataBufferByte(size); + break; + case DataBuffer.TYPE_USHORT: + buffer = new DataBufferUShort(size); + break; + case DataBuffer.TYPE_INT: + buffer = new DataBufferInt(size); + break; + } + return buffer; } /** @@ -253,73 +263,39 @@ public class SinglePixelPackedSampleModel extends SampleModel public Object getDataElements(int x, int y, Object obj, DataBuffer data) { - int offset = scanlineStride*y + x + data.getOffset(); - - return Buffers.getData(data, offset, obj, - 0, // destination offset, - 1 // length - ); - } - - /** - * This is a more efficient implementation of the default implementation in - * the super class. - * @param x The x-coordinate of the pixel rectangle to store in - * <code>obj</code>. - * @param y The y-coordinate of the pixel rectangle to store in - * <code>obj</code>. - * @param w The width of the pixel rectangle to store in <code>obj</code>. - * @param h The height of the pixel rectangle to store in <code>obj</code>. - * @param obj The primitive array to store the pixels into or null to force - * creation. - * @param data The DataBuffer that is the source of the pixel data. - * @return The primitive array containing the pixel data. - * @see java.awt.image.SampleModel#getDataElements(int, int, int, int, - * java.lang.Object, java.awt.image.DataBuffer) - */ - public Object getDataElements(int x, int y, int w, int h, Object obj, - DataBuffer data) - { - int size = w*h; - int dataSize = size; - Object pixelData = null; - switch (getTransferType()) - { + int type = getTransferType(); + Object ret = null; + switch (type) + { case DataBuffer.TYPE_BYTE: - pixelData = ((DataBufferByte) data).getData(); - if (obj == null) obj = new byte[dataSize]; + { + byte[] in = (byte[]) obj; + if (in == null) + in = new byte[1]; + in[0] = (byte) data.getElem(x + y * scanlineStride); + ret = in; + } break; - case DataBuffer.TYPE_USHORT: - pixelData = ((DataBufferUShort) data).getData(); - if (obj == null) obj = new short[dataSize]; - break; - case DataBuffer.TYPE_INT: - pixelData = ((DataBufferInt) data).getData(); - if (obj == null) obj = new int[dataSize]; - break; - default: - // Seems like the only sensible thing to do. - throw new ClassCastException(); - } - if(x == 0 && scanlineStride == w) - { - // The full width need to be copied therefore we can copy in one shot. - System.arraycopy(pixelData, scanlineStride*y + data.getOffset(), obj, - 0, size); - } - else - { - // Since we do not need the full width we need to copy line by line. - int outOffset = 0; - int dataOffset = scanlineStride*y + x + data.getOffset(); - for (int yy = y; yy<(y+h); yy++) + case DataBuffer.TYPE_USHORT: + { + short[] in = (short[]) obj; + if (in == null) + in = new short[1]; + in[0] = (short) data.getElem(x + y * scanlineStride); + ret = in; + } + break; + case DataBuffer.TYPE_INT: { - System.arraycopy(pixelData, dataOffset, obj, outOffset, w); - dataOffset += scanlineStride; - outOffset += w; + int[] in = (int[]) obj; + if (in == null) + in = new int[1]; + in[0] = data.getElem(x + y * scanlineStride); + ret = in; } + break; } - return obj; + return ret; } /** @@ -414,30 +390,29 @@ public class SinglePixelPackedSampleModel extends SampleModel public void setDataElements(int x, int y, Object obj, DataBuffer data) { - int transferType = getTransferType(); - switch (transferType) - { - case DataBuffer.TYPE_BYTE: - { - byte[] in = (byte[]) obj; - data.setElem(y * scanlineStride + x, ((int) in[0]) & 0xff); - break; - } - case DataBuffer.TYPE_USHORT: - { - short[] in = (short[]) obj; + switch (transferType) + { + case DataBuffer.TYPE_BYTE: + { + byte[] in = (byte[]) obj; + data.setElem(y * scanlineStride + x, ((int) in[0]) & 0xff); + } + break; + case DataBuffer.TYPE_USHORT: + { + short[] in = (short[]) obj; data.setElem(y * scanlineStride + x, ((int) in[0]) & 0xffff); - break; - } - case DataBuffer.TYPE_INT: - { - int[] in = (int[]) obj; + } + break; + case DataBuffer.TYPE_INT: + { + int[] in = (int[]) obj; data.setElem(y * scanlineStride + x, in[0]); break; - } - } - } + } + } + } /** * Sets the samples for the pixel at (x, y) in the specified data buffer to @@ -479,7 +454,6 @@ public class SinglePixelPackedSampleModel extends SampleModel DataBuffer data) { int inOffset = 0; - int[] pixel = new int[numBands]; for (int yy=y; yy<(y+h); yy++) { int offset = scanlineStride*yy + x; |