Commit 27c2c3ec by Ingo Proetel Committed by Michael Koch

ColorModel.java (getRGBdefault): Default ColorModel has 32 bit pixels not 8 bit pixels.

2004-05-04  Ingo Proetel  <proetel@aicas.com>

	* java/awt/image/ColorModel.java (getRGBdefault): Default ColorModel has
        32 bit pixels not 8 bit pixels.
	(isCompatibleRaster): Added javadoc comment.

2004-05-04  Ingo Proetel  <proetel@aicas.com>

	* java/awt/image/ComponentSampleModel.java (setDataSamples):Do not reset
	scanline stride.

2004-05-04  Ingo Proetel  <proetel@aicas.com>

	* java/awt/ColorPaintContext.java (<init>): Added ColorModel to signature.
	(getColorModel): Return the actual color model.
	(getRaster): Implemented.
	(ColorRaster): New inner class.
	* java/awt/SystemColor.java (createContext): Use ColorModel when creating
	a PaintContext.
	* java/awt/Color.java (<init>): Make exception more verbose.
	(createContext): Use ColorModel when creating a PaintContext.

From-SVN: r81486
parent fae4c98f
2004-05-04 Ingo Proetel <proetel@aicas.com>
* java/awt/image/ColorModel.java (getRGBdefault): Default ColorModel has
32 bit pixels not 8 bit pixels.
(isCompatibleRaster): Added javadoc comment.
2004-05-04 Ingo Proetel <proetel@aicas.com>
* java/awt/image/ComponentSampleModel.java (setDataSamples):Do not reset
scanline stride.
2004-05-04 Ingo Proetel <proetel@aicas.com>
* java/awt/ColorPaintContext.java (<init>): Added ColorModel to signature.
(getColorModel): Return the actual color model.
(getRaster): Implemented.
(ColorRaster): New inner class.
* java/awt/SystemColor.java (createContext): Use ColorModel when creating
a PaintContext.
* java/awt/Color.java (<init>): Make exception more verbose.
(createContext): Use ColorModel when creating a PaintContext.
2004-05-04 Michael Koch <konqueror@gmx.de> 2004-05-04 Michael Koch <konqueror@gmx.de>
* gnu/java/text/CharacterBreakIterator.java * gnu/java/text/CharacterBreakIterator.java
......
...@@ -319,7 +319,12 @@ public class Color implements Paint, Serializable ...@@ -319,7 +319,12 @@ public class Color implements Paint, Serializable
{ {
if ((red & 255) != red || (green & 255) != green || (blue & 255) != blue if ((red & 255) != red || (green & 255) != green || (blue & 255) != blue
|| (alpha & 255) != alpha) || (alpha & 255) != alpha)
throw new IllegalArgumentException("Bad RGB values"); throw new IllegalArgumentException("Bad RGB values"
+" red=0x"+Integer.toHexString(red)
+" green=0x"+Integer.toHexString(green)
+" blue=0x"+Integer.toHexString(blue)
+" alpha=0x"+Integer.toHexString(alpha) );
value = (alpha << 24) | (red << 16) | (green << 8) | blue; value = (alpha << 24) | (red << 16) | (green << 8) | blue;
falpha = 1; falpha = 1;
cs = null; cs = null;
...@@ -950,7 +955,7 @@ public class Color implements Paint, Serializable ...@@ -950,7 +955,7 @@ public class Color implements Paint, Serializable
* object, regardless of the parameters. Subclasses, however, may have a * object, regardless of the parameters. Subclasses, however, may have a
* mutable result. * mutable result.
* *
* @param cm the requested color model, ignored * @param cm the requested color model
* @param deviceBounds the bounding box in device coordinates, ignored * @param deviceBounds the bounding box in device coordinates, ignored
* @param userBounds the bounding box in user coordinates, ignored * @param userBounds the bounding box in user coordinates, ignored
* @param xform the bounds transformation, ignored * @param xform the bounds transformation, ignored
...@@ -962,8 +967,8 @@ public class Color implements Paint, Serializable ...@@ -962,8 +967,8 @@ public class Color implements Paint, Serializable
AffineTransform xform, AffineTransform xform,
RenderingHints hints) RenderingHints hints)
{ {
if (context == null) if (context == null || !context.getColorModel().equals(cm))
context = new ColorPaintContext(value); context = new ColorPaintContext(cm,value);
return context; return context;
} }
......
/* ColorPaintContext.java -- context for painting solid colors /* ColorPaintContext.java -- context for painting solid colors
Copyright (C) 2002 Free Software Foundation, Inc. Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -55,15 +55,31 @@ class ColorPaintContext implements PaintContext ...@@ -55,15 +55,31 @@ class ColorPaintContext implements PaintContext
* SystemColor. * SystemColor.
*/ */
final int color; final int color;
final ColorModel colorModel;
private ColorRaster cachedRaster;
/** /**
* Create the context for a given color. * Create the context for a given color.
* *
* @param c the solid color to use * @param c The solid color to use.
*/ */
ColorPaintContext(int c) ColorPaintContext(int colorRGB)
{ {
color = c; this(ColorModel.getRGBdefault(), colorRGB);
}
/**
* Create the context for a given color.
*
* @param cm The color model of this context.
* @param c The solid color to use.
*/
ColorPaintContext(ColorModel cm,int colorRGB)
{
color = colorRGB;
colorModel = cm;
} }
/** /**
...@@ -75,14 +91,13 @@ class ColorPaintContext implements PaintContext ...@@ -75,14 +91,13 @@ class ColorPaintContext implements PaintContext
} }
/** /**
* Return the color model of this context. This ignores the model passed * Return the color model of this context.
* in the request, since colors are always in sRGB.
* *
* @return the context color model * @return the context color model
*/ */
public ColorModel getColorModel() public ColorModel getColorModel()
{ {
return ColorModel.getRGBdefault(); return colorModel;
} }
/** /**
...@@ -94,10 +109,87 @@ class ColorPaintContext implements PaintContext ...@@ -94,10 +109,87 @@ class ColorPaintContext implements PaintContext
* @param h the height, in device space * @param h the height, in device space
* @return a raster for the given area and color * @return a raster for the given area and color
*/ */
public Raster getRaster(int x, int y, int w, int h) public Raster getRaster(int x, int y, int width, int height)
{
if( cachedRaster == null
|| cachedRaster.getWidth() < width
|| cachedRaster.getHeight() < height)
{
cachedRaster = new ColorRaster(colorModel, 0, 0, width, height, color);
}
return cachedRaster.createChild(0 ,0 ,width ,height ,x ,y , null);
}
/**
* A ColorRaster is a raster that is completely filled with one color. The
* data layout is taken from the color model given to the constructor.
*/
private class ColorRaster extends Raster
{ {
// XXX Implement. Sun uses undocumented implementation class
// sun.awt.image.IntegerInterleavedRaster. /**
throw new Error("not implemented"); * Create a raster that is compaltible with the given color model and
* filled with the given color.
* @param cm The color model for this raster.
* @param x The smallest horizontal corrdinate in the raster.
* @param y The smallest vertical coordinate in the raster.
* @param width The width of the raster.
* @param height The height of the raster.
* @param rgbPixel The RGB value of the color for this raster.
*/
ColorRaster(ColorModel cm,int x, int y, int width, int height, int rgbPixel)
{
super(cm.createCompatibleSampleModel(width,height),new Point(x,y));
Object pixel = cm.getDataElements(rgbPixel,null);
getSampleModel().setDataElements(0, 0,
width, height,
multiplyData(pixel,null,width*height),
dataBuffer);
}
private Object multiplyData(Object src, Object dest, int factor)
{
Object from;
int srcLength = 0;
if (src instanceof byte[])
{
srcLength = ((byte[])src).length;
if (dest == null) dest = new byte[factor * srcLength];
}
else if (src instanceof short[])
{
srcLength = ((short[])src).length;
if (dest == null) dest = new short[factor * srcLength];
}
else if (src instanceof int[])
{
srcLength = ((int[]) src).length;
if (dest == null) dest = new int[factor * srcLength];
}
else
{
throw new ClassCastException("Unknown data buffer type");
}
System.arraycopy(src,0,dest,0,srcLength);
int count = 1;
while(count*2 < factor)
{
System.arraycopy(dest, 0, dest, count * srcLength, count*srcLength);
count *= 2;
}
if(factor > count)
System.arraycopy(dest,0, dest, count * srcLength,
(factor - count) * srcLength );
return dest;
}
} }
} // class ColorPaintContext } // class ColorPaintContext
...@@ -427,7 +427,7 @@ public final class SystemColor extends Color implements Serializable ...@@ -427,7 +427,7 @@ public final class SystemColor extends Color implements Serializable
* as the system color is solid, the context does not need any of the * as the system color is solid, the context does not need any of the
* passed parameters to do its job. * passed parameters to do its job.
* *
* @param cm the requested color model, ignored * @param cm the requested color model
* @param deviceBounds the bounding box in device coordinates, ignored * @param deviceBounds the bounding box in device coordinates, ignored
* @param userBounds the bounding box in user coordinates, ignored * @param userBounds the bounding box in user coordinates, ignored
* @param xform the bounds transformation, ignored * @param xform the bounds transformation, ignored
...@@ -441,8 +441,8 @@ public final class SystemColor extends Color implements Serializable ...@@ -441,8 +441,8 @@ public final class SystemColor extends Color implements Serializable
{ {
Toolkit.getDefaultToolkit().loadSystemColors(colors); Toolkit.getDefaultToolkit().loadSystemColors(colors);
int color = colors[value] | ALPHA_MASK; int color = colors[value] | ALPHA_MASK;
if (context == null || color != context.color) if (context == null || color != context.color || !context.getColorModel().equals(cm))
context = new ColorPaintContext(color); context = new ColorPaintContext(cm,color);
return context; return context;
} }
......
...@@ -166,7 +166,7 @@ public abstract class ColorModel implements Transparency ...@@ -166,7 +166,7 @@ public abstract class ColorModel implements Transparency
*/ */
public static ColorModel getRGBdefault() public static ColorModel getRGBdefault()
{ {
return new DirectColorModel(8, 0xff0000, 0xff00, 0xff, 0xff000000); return new DirectColorModel(32, 0xff0000, 0xff00, 0xff, 0xff000000);
} }
public final boolean hasAlpha() public final boolean hasAlpha()
...@@ -597,7 +597,11 @@ public abstract class ColorModel implements Transparency ...@@ -597,7 +597,11 @@ public abstract class ColorModel implements Transparency
return null; return null;
} }
// Typically overridden /**
* Checks if the given raster has a compatible data-layout (SampleModel).
* @param raster The Raster to test.
* @return true if raster is compatible.
*/
public boolean isCompatibleRaster(Raster raster) public boolean isCompatibleRaster(Raster raster)
{ {
SampleModel sampleModel = raster.getSampleModel(); SampleModel sampleModel = raster.getSampleModel();
......
...@@ -349,7 +349,7 @@ public class ComponentSampleModel extends SampleModel ...@@ -349,7 +349,7 @@ public class ComponentSampleModel extends SampleModel
if (scanlineStride == rowSize) if (scanlineStride == rowSize)
{ {
// Collapse scan lines: // Collapse scan lines:
scanlineStride = rowSize *= h; rowSize *= h;
h = 1; h = 1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment