From 23f0ecff4a6e9c554e4ddddf59d022e632810a72 Mon Sep 17 00:00:00 2001 From: Michael Koch Date: Tue, 20 Apr 2004 11:13:09 +0000 Subject: [PATCH] [multiple changes] 2004-04-20 Ingo Proetel * java/awt/FontMetrics.java: (charsWidth): fixed accumulation of total_width (getWidth): simple default implementation * java/awt/Polygon.java (getBoundingBox): Use correct y-coordinate in Rectangle constructor. * java/awt/image/Raster.java (toString): Added method. * java/awt/image/SampleModel.java (): Added error cause information to thrown exception. * java/awt/image/SinglePixelPackedSampleModel.java (getDataElements): New method. (setDataElements): New method. (setPixels): New method. (toString): New method. 2004-04-20 Sascha Brawer * java/awt/image/ComponentColorModel.java (createCompatibleSampleModel): Return PixelInterleavedSampleModel for TYPE_BYTE and TYPE_USHORT transferTypes, in order to pass the Mauve tests on this method. Improved documentation. From-SVN: r80894 --- libjava/ChangeLog | 23 +++ libjava/java/awt/FontMetrics.java | 11 +- libjava/java/awt/Polygon.java | 2 +- .../java/awt/image/ComponentColorModel.java | 57 +++++-- libjava/java/awt/image/Raster.java | 21 +++ libjava/java/awt/image/SampleModel.java | 6 +- .../image/SinglePixelPackedSampleModel.java | 158 +++++++++++++++++- 7 files changed, 260 insertions(+), 18 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 2388b081901..17017de7ae5 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,26 @@ +2004-04-20 Ingo Proetel + + * java/awt/FontMetrics.java: + (charsWidth): fixed accumulation of total_width + (getWidth): simple default implementation + * java/awt/Polygon.java (getBoundingBox): Use correct y-coordinate + in Rectangle constructor. + * java/awt/image/Raster.java (toString): Added method. + * java/awt/image/SampleModel.java (): Added error cause + information to thrown exception. + * java/awt/image/SinglePixelPackedSampleModel.java (getDataElements): + New method. + (setDataElements): New method. + (setPixels): New method. + (toString): New method. + +2004-04-20 Sascha Brawer + + * java/awt/image/ComponentColorModel.java + (createCompatibleSampleModel): Return PixelInterleavedSampleModel + for TYPE_BYTE and TYPE_USHORT transferTypes, in order to pass the + Mauve tests on this method. Improved documentation. + 2004-04-20 Michael Koch * javax/swing/JLayeredPane.java, diff --git a/libjava/java/awt/FontMetrics.java b/libjava/java/awt/FontMetrics.java index 6a1a1c09ce1..cb76f507909 100644 --- a/libjava/java/awt/FontMetrics.java +++ b/libjava/java/awt/FontMetrics.java @@ -292,8 +292,7 @@ charsWidth(char buf[], int offset, int len) { int total_width = 0; for (int i = offset; i < len; i++) - total_width = charWidth(buf[i]); - + total_width += charWidth(buf[i]); return(total_width); } @@ -328,7 +327,12 @@ bytesWidth(byte buf[], int offset, int len) public int[] getWidths() { - return(new int[256]); + int [] result = new int[256]; + for(char i = 0; i < 256; i++) + { + result[i]= charWidth(i); + } + return(result); } /*************************************************************************/ @@ -347,3 +351,4 @@ toString() } // class FontMetrics + diff --git a/libjava/java/awt/Polygon.java b/libjava/java/awt/Polygon.java index e91144c8812..96c370aafc1 100644 --- a/libjava/java/awt/Polygon.java +++ b/libjava/java/awt/Polygon.java @@ -294,7 +294,7 @@ public class Polygon implements Shape, Serializable else if (y > maxy) maxy = y; } - bounds = new Rectangle (minx, maxy, maxx - minx, maxy - miny); + bounds = new Rectangle (minx, miny, maxx - minx, maxy - miny); } return bounds; } diff --git a/libjava/java/awt/image/ComponentColorModel.java b/libjava/java/awt/image/ComponentColorModel.java index cc96ab15516..24d8b8ea685 100644 --- a/libjava/java/awt/image/ComponentColorModel.java +++ b/libjava/java/awt/image/ComponentColorModel.java @@ -1,4 +1,4 @@ -/* Copyright (C) 2000, 2002 Free Software Foundation +/* Copyright (C) 2000, 2002, 2004 Free Software Foundation This file is part of GNU Classpath. @@ -292,19 +292,56 @@ public class ComponentColorModel extends ColorModel return Raster.createWritableRaster(sm, origin); } + + /** + * Creates a SampleModel whose arrangement of pixel + * data is compatible to this ColorModel. + * + * @param w the number of pixels in the horizontal direction. + * @param h the number of pixels in the vertical direction. + */ public SampleModel createCompatibleSampleModel(int w, int h) { - int pixelStride = getNumComponents(); - - /* TODO: Maybe we don't need to create a new offset array each - time, but rather use the same array every time. */ - int[] bandOffsets = new int[pixelStride]; - for (int i=0; iobj. + * @param y The y-coordinate of the pixel rectangle to store in obj. + * @param w The width of the pixel rectangle to store in obj. + * @param h The height of the pixel rectangle to store in obj. + * @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()) + { + case DataBuffer.TYPE_BYTE: + pixelData = ((DataBufferByte) data).getData(); + if (obj == null) obj = new byte[dataSize]; + 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++) + { + System.arraycopy(pixelData, dataOffset, obj, outOffset, w); + dataOffset += scanlineStride; + outOffset += w; + } + } + return obj; + } + public int[] getPixel(int x, int y, int[] iArray, DataBuffer data) { @@ -201,7 +258,51 @@ public class SinglePixelPackedSampleModel extends SampleModel int samples = data.getElem(offset); return (samples & bitMasks[b]) >>> bitOffsets[b]; } - + + /** + * This method implements a more efficient way to set data elements than the default + * implementation of the super class. It sets the data elements line by line instead + * of pixel by pixel. + * @param x The x-coordinate of the data elements in obj. + * @param y The y-coordinate of the data elements in obj. + * @param w The width of the data elements in obj. + * @param h The height of the data elements in obj. + * @param obj The primitive array containing the data elements to set. + * @param data The DataBuffer to store the data elements into. + * @see java.awt.image.SampleModel#setDataElements(int, int, int, int, java.lang.Object, java.awt.image.DataBuffer) + */ + public void setDataElements(int x, int y, int w, int h, + Object obj, DataBuffer data) + { + + Object pixelData; + switch (getTransferType()) + { + case DataBuffer.TYPE_BYTE: + pixelData = ((DataBufferByte) data).getData(); + break; + case DataBuffer.TYPE_USHORT: + pixelData = ((DataBufferUShort) data).getData(); + break; + case DataBuffer.TYPE_INT: + pixelData = ((DataBufferInt) data).getData(); + break; + default: + // Seems like the only sensible thing to do. + throw new ClassCastException(); + } + + int inOffset = 0; + int dataOffset = scanlineStride*y + x + data.getOffset(); + for (int yy=y; yy<(y+h); yy++) + { + System.arraycopy(obj,inOffset,pixelData,dataOffset,w); + dataOffset += scanlineStride; + inOffset += w; + } + } + + public void setDataElements(int x, int y, Object obj, DataBuffer data) { int offset = scanlineStride*y + x + data.getOffset(); @@ -273,6 +374,39 @@ public class SinglePixelPackedSampleModel extends SampleModel data.setElem(offset, samples); } + /** + * This method implements a more efficient way to set pixels than the default + * implementation of the super class. It copies the pixel components directly + * from the input array instead of creating a intermediate buffer. + * @param x The x-coordinate of the pixel rectangle in obj. + * @param y The y-coordinate of the pixel rectangle in obj. + * @param w The width of the pixel rectangle in obj. + * @param h The height of the pixel rectangle in obj. + * @param obj The primitive array containing the pixels to set. + * @param data The DataBuffer to store the pixels into. + * @see java.awt.image.SampleModel#setPixels(int, int, int, int, int[], java.awt.image.DataBuffer) + */ + public void setPixels(int x, int y, int w, int h, int[] iArray, + DataBuffer data) + { + int inOffset = 0; + int[] pixel = new int[numBands]; + for (int yy=y; yy<(y+h); yy++) + { + int offset = scanlineStride*yy + x; + for (int xx=x; xx<(x+w); xx++) + { + int samples = 0; + for (int b=0; b