Mercurial > hg > release > icedtea6-1.2
changeset 728:a4abcaf49734 cacao
2008-03-03 Joshua Sumali <jsumali@redhat.com>
* Makefile.am: Updated to b06.
* Makefile.in: Regenerated.
* patches/icedtea-ant.patch: Updated line numbers for b06.
* patches/icedtea-bytebuffer-compact.patch: Likewise.
* patches/icedtea-copy-plugs.patch: Likewise.
* patches/icedtea-core-build.patch: Likewise.
* patches/icedtea-gcc-4.3.patch: Likewise.
* patches/icedtea-headers.patch: Likewise.
* patches/icedtea-lib64.patch: Likewise.
* patches/icedtea-libraries.patch: Likewise.
* patches/icedtea-ports.patch: Likewise.
* patches/icedtea-sunsrc.patch: Likewise.
* patches/icedtea-tools.patch: Likewise.
* patches/icedtea-use-system-tzdata.patch: Likewise.
* patches/icedtea-zero.patch: Likewise.
* patches/icedtea-graphics.patch: Removed awt patches since new awt code
is included in b06.
* rt/java/awt/*: Removed files since they are newly opened in b06.
author | Joshua Sumali <jsumali@redhat.com> |
---|---|
date | Mon, 03 Mar 2008 20:58:16 -0500 |
parents | 30c5c606a04a |
children | 5e1cd318d7f5 |
files | ChangeLog Makefile.am Makefile.in generated/sun/awt/X11/generator/sizer.32 generated/sun/awt/X11/generator/sizer.32.c patches/icedtea-ant.patch patches/icedtea-bytebuffer-compact.patch patches/icedtea-copy-plugs.patch patches/icedtea-core-build.patch patches/icedtea-gcc-4.3.patch patches/icedtea-graphics.patch patches/icedtea-headers.patch patches/icedtea-lib64.patch patches/icedtea-libraries.patch patches/icedtea-ports.patch patches/icedtea-sunsrc.patch patches/icedtea-tools.patch patches/icedtea-use-system-tzdata.patch patches/icedtea-zero.patch rt/java/awt/color/CMMException.java rt/java/awt/color/ColorSpace.java rt/java/awt/color/ICC_ColorSpace.java rt/java/awt/color/ICC_Profile.java rt/java/awt/color/ICC_ProfileGray.java rt/java/awt/color/ICC_ProfileRGB.java rt/java/awt/image/BandedSampleModel.java rt/java/awt/image/ColorConvertOp.java rt/java/awt/image/ComponentSampleModel.java rt/java/awt/image/DataBuffer.java rt/java/awt/image/DataBufferByte.java rt/java/awt/image/DataBufferInt.java rt/java/awt/image/DataBufferShort.java rt/java/awt/image/DataBufferUShort.java rt/java/awt/image/MultiPixelPackedSampleModel.java rt/java/awt/image/Raster.java rt/java/awt/image/RenderedImage.java rt/java/awt/image/SampleModel.java rt/java/awt/image/SinglePixelPackedSampleModel.java rt/java/awt/image/WritableRaster.java rt/java/awt/image/WritableRenderedImage.java rt/java/awt/image/renderable/ContextualRenderedImageFactory.java rt/java/awt/image/renderable/RenderContext.java rt/java/awt/image/renderable/RenderableImage.java rt/java/awt/image/renderable/RenderableImageOp.java rt/java/awt/image/renderable/RenderableImageProducer.java rt/java/awt/image/renderable/RenderedImageFactory.java |
diffstat | 46 files changed, 94 insertions(+), 10461 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Feb 28 13:34:20 2008 -0500 +++ b/ChangeLog Mon Mar 03 20:58:16 2008 -0500 @@ -1,3 +1,24 @@ +2008-03-03 Joshua Sumali <jsumali@redhat.com> + + * Makefile.am: Updated to b06. + * Makefile.in: Regenerated. + * patches/icedtea-ant.patch: Updated line numbers for b06. + * patches/icedtea-bytebuffer-compact.patch: Likewise. + * patches/icedtea-copy-plugs.patch: Likewise. + * patches/icedtea-core-build.patch: Likewise. + * patches/icedtea-gcc-4.3.patch: Likewise. + * patches/icedtea-headers.patch: Likewise. + * patches/icedtea-lib64.patch: Likewise. + * patches/icedtea-libraries.patch: Likewise. + * patches/icedtea-ports.patch: Likewise. + * patches/icedtea-sunsrc.patch: Likewise. + * patches/icedtea-tools.patch: Likewise. + * patches/icedtea-use-system-tzdata.patch: Likewise. + * patches/icedtea-zero.patch: Likewise. + * patches/icedtea-graphics.patch: Removed awt patches since new awt code + is included in b06. + * rt/java/awt/*: Removed files since they are newly opened in b06. + 2008-02-28 Joshua Sumali <jsumali@redhat.com> * Makefile.am:
--- a/Makefile.am Thu Feb 28 13:34:20 2008 -0500 +++ b/Makefile.am Mon Mar 03 20:58:16 2008 -0500 @@ -1,6 +1,6 @@ -OPENJDK_DATE = 12_feb_2008 -OPENJDK_MD5SUM = 660e6230dfc4cdc8a7c93bc3e7e60120 -OPENJDK_VERSION = b05 +OPENJDK_DATE = 28_feb_2008 +OPENJDK_MD5SUM = 08bdfb4d78340788969a4edd853fcd2b +OPENJDK_VERSION = b06 if NETX_PLUGIN NETX_PATCH = patches/icedtea-netx-plugin.patch
--- a/Makefile.in Thu Feb 28 13:34:20 2008 -0500 +++ b/Makefile.in Mon Mar 03 20:58:16 2008 -0500 @@ -219,9 +219,9 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -OPENJDK_DATE = 12_feb_2008 -OPENJDK_MD5SUM = 660e6230dfc4cdc8a7c93bc3e7e60120 -OPENJDK_VERSION = b05 +OPENJDK_DATE = 28_feb_2008 +OPENJDK_MD5SUM = 08bdfb4d78340788969a4edd853fcd2b +OPENJDK_VERSION = b06 @NETX_PLUGIN_FALSE@NETX_PATCH = @NETX_PLUGIN_TRUE@NETX_PATCH = patches/icedtea-netx-plugin.patch EXTRA_DIST = rt generated $(ICEDTEA_PATCHES) $(ICEDTEA_ECJ_PATCH) \
--- a/generated/sun/awt/X11/generator/sizer.32.c Thu Feb 28 13:34:20 2008 -0500 +++ b/generated/sun/awt/X11/generator/sizer.32.c Mon Mar 03 20:58:16 2008 -0500 @@ -6,12 +6,26 @@ #include <X11/Xatom.h> #include <stdio.h> -#include <Xm/MwmUtil.h> #include <X11/extensions/Xdbe.h> #include "awt_p.h" #include "color.h" #include "colordata.h" +/* the struct below was copied from MwmUtil.h to workaround a lesstif bug: + http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6586752 */ + +typedef struct PROPMOTIFWMHINTS { +/* 32-bit property items are stored as long on the client (whether + * that means 32 bits or 64). XChangeProperty handles the conversion + * to the actual 32-bit quantities sent to the server. + */ + unsigned long flags; + unsigned long functions; + unsigned long decorations; + long inputMode; + unsigned long status; +} PropMwmHints; + int main(){ Screen temp0;
--- a/patches/icedtea-ant.patch Thu Feb 28 13:34:20 2008 -0500 +++ b/patches/icedtea-ant.patch Mon Mar 03 20:58:16 2008 -0500 @@ -96,7 +96,7 @@ # Default target and expected 'do everything' target --- iopenjdk/jaxws/make/build.xml 2007-10-12 03:52:21.000000000 -0400 +++ openjdk/jaxws/make/build.xml 2007-11-13 11:02:43.000000000 -0500 -@@ -100,6 +100,7 @@ +@@ -109,6 +109,7 @@ memoryMaximumSize="${javac.memoryMaximumSize}" target="${javac.target}" excludes="com/sun/tools/internal/txw2/**">
--- a/patches/icedtea-bytebuffer-compact.patch Thu Feb 28 13:34:20 2008 -0500 +++ b/patches/icedtea-bytebuffer-compact.patch Mon Mar 03 20:58:16 2008 -0500 @@ -42,7 +42,7 @@ return this; } -@@ -367,7 +367,7 @@ +@@ -368,7 +368,7 @@ */ public final Buffer rewind() { position = 0; @@ -51,7 +51,7 @@ return this; } -@@ -548,4 +548,8 @@ +@@ -547,4 +547,8 @@ throw new IndexOutOfBoundsException(); }
--- a/patches/icedtea-copy-plugs.patch Thu Feb 28 13:34:20 2008 -0500 +++ b/patches/icedtea-copy-plugs.patch Mon Mar 03 20:58:16 2008 -0500 @@ -33,8 +33,8 @@ Type[] paramTypes = constr.getGenericParameterTypes(); if (paramTypes.length != propertyNames.length) { ---- openjdk/jdk/make/common/internal/BinaryPlugs.gmk.orig 2008-02-27 16:48:35.000000000 -0500 -+++ openjdk/jdk/make/common/internal/BinaryPlugs.gmk 2008-02-27 16:46:09.000000000 -0500 +--- openjdk.orig/jdk/make/common/internal/BinaryPlugs.gmk 2008-02-28 04:39:40.000000000 -0500 ++++ openjdk/jdk/make/common/internal/BinaryPlugs.gmk 2008-02-29 14:28:47.000000000 -0500 @@ -51,28 +51,19 @@ com/sun/jmx/snmp/SnmpDataTypeEnums.class \ com/sun/jmx/snmp/SnmpDefinitions.class \ @@ -66,17 +66,7 @@ PLUG_SOUND_CLASS_NAMES = \ com/sun/media/sound/AbstractPlayer.class \ -@@ -130,9 +121,6 @@ - java/awt/color/CMMException.class \ - java/awt/color/ColorSpace.class \ - java/awt/color/ICC_ColorSpace.class \ --java/awt/color/ICC_Profile\$$1.class \ --java/awt/color/ICC_Profile\$$2.class \ --java/awt/color/ICC_Profile\$$3.class \ - java/awt/color/ICC_Profile.class \ - java/awt/color/ICC_ProfileGray.class \ - java/awt/color/ICC_ProfileRGB.class \ -@@ -162,8 +150,14 @@ +@@ -128,8 +119,14 @@ # Class list temp files (used by both import and export of plugs) @@ -87,13 +77,13 @@ +PLUG_NETX_CLASS_NAMES = net + PLUG_TEMPDIR=$(ABS_TEMPDIR)/plugs --PLUG_CLASS_AREAS = jmf sound awt -+PLUG_CLASS_AREAS = jmf sound awt gnu javax netx +-PLUG_CLASS_AREAS = jmf sound ++PLUG_CLASS_AREAS = jmf sound gnu javax netx PLUG_CLISTS = $(PLUG_CLASS_AREAS:%=$(PLUG_TEMPDIR)/%.clist) # Create jargs file command -@@ -191,6 +185,21 @@ - @for i in $(PLUG_AWT_CLASS_NAMES) ; do \ +@@ -152,6 +149,21 @@ + @for i in $(PLUG_SOUND_CLASS_NAMES) ; do \ $(ECHO) "$$i" >> $@ ; \ done +$(PLUG_TEMPDIR)/gnu.clist: @@ -114,9 +104,9 @@ $(PLUG_TEMPDIR)/all.clist: $(PLUG_CLISTS) @$(prep-target) $(CAT) $(PLUG_CLISTS) > $@ -@@ -200,6 +209,12 @@ +@@ -159,6 +171,12 @@ $(plug-create-jargs) - $(PLUG_TEMPDIR)/awt.jargs: $(PLUG_TEMPDIR)/awt.clist + $(PLUG_TEMPDIR)/sound.jargs: $(PLUG_TEMPDIR)/sound.clist $(plug-create-jargs) +$(PLUG_TEMPDIR)/gnu.jargs: $(PLUG_TEMPDIR)/gnu.clist + $(plug-create-jargs) @@ -127,7 +117,7 @@ $(PLUG_TEMPDIR)/all.jargs: $(PLUG_TEMPDIR)/all.clist $(plug-create-jargs) -@@ -229,9 +244,9 @@ +@@ -188,9 +206,9 @@ # Import classes command define import-binary-plug-classes @@ -139,10 +129,10 @@ endef # import-binary-plug-classes else # IMPORT_BINARY_PLUGS -@@ -263,13 +278,22 @@ +@@ -220,12 +238,21 @@ + $(call import-binary-plug-classes,$(PLUG_TEMPDIR)/jmf.clist) + import-binary-plug-sound-classes: $(PLUG_IMPORT_JARFILE) $(PLUG_TEMPDIR)/sound.clist $(call import-binary-plug-classes,$(PLUG_TEMPDIR)/sound.clist) - import-binary-plug-awt-classes: $(PLUG_IMPORT_JARFILE) $(PLUG_TEMPDIR)/awt.clist - $(call import-binary-plug-classes,$(PLUG_TEMPDIR)/awt.clist) +import-binary-plug-gnu-classes: $(PLUG_IMPORT_JARFILE) $(PLUG_TEMPDIR)/gnu.clist + $(call import-binary-plug-classes,$(PLUG_TEMPDIR)/gnu.clist) +import-binary-plug-javax-classes: $(PLUG_IMPORT_JARFILE) $(PLUG_TEMPDIR)/javax.clist @@ -154,12 +144,11 @@ import-binary-plug-jar: \ import-binary-plug-jmf-classes \ - import-binary-plug-sound-classes \ -- import-binary-plug-awt-classes -+ import-binary-plug-awt-classes \ +- import-binary-plug-sound-classes ++ import-binary-plug-sound-classes \ + import-binary-plug-gnu-classes \ -+ import-binary-plug-javax-classes \ -+ import-binary-plug-netx-classes \ ++ import-binary-plug-javax-classes \ ++ import-binary-plug-netx-classes \ # Import native libraries
--- a/patches/icedtea-core-build.patch Thu Feb 28 13:34:20 2008 -0500 +++ b/patches/icedtea-core-build.patch Mon Mar 03 20:58:16 2008 -0500 @@ -116,7 +116,7 @@ ifeq ($(PLATFORM), windows) # Windows vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv Windows -@@ -119,8 +149,7 @@ +@@ -122,8 +152,7 @@ $(LIB_LOCATION)/$(SERVER_LOCATION)/$(JVMMAP_NAME) \ $(LIB_LOCATION)/$(SERVER_LOCATION)/$(JVMPDB_NAME) @@ -126,7 +126,7 @@ IMPORT_LIST += $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(JVMMAP_NAME) \ $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(JVMPDB_NAME) endif -@@ -151,17 +180,25 @@ +@@ -154,17 +183,25 @@ # NOT Windows vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv NOT Windows IMPORT_LIST += \ @@ -156,7 +156,7 @@ ifeq ($(PLATFORM), solaris) # solaris vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv solaris -@@ -195,11 +232,25 @@ +@@ -198,11 +235,25 @@ $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(JVM_NAME): $(HOTSPOT_CLIENT_PATH)/$(JVM_NAME) $(install-import-file) @@ -184,7 +184,7 @@ @$(prep-target) $(LN) -s ../$(LIBJSIG_NAME) $@ -@@ -224,6 +275,9 @@ +@@ -227,6 +278,9 @@ $(LIB_LOCATION)/$(CLIENT_LOCATION)/Xusage.txt : $(HOTSPOT_CLIENT_PATH)/Xusage.txt $(install-import-file)
--- a/patches/icedtea-gcc-4.3.patch Thu Feb 28 13:34:20 2008 -0500 +++ b/patches/icedtea-gcc-4.3.patch Mon Mar 03 20:58:16 2008 -0500 @@ -31,7 +31,7 @@ #include <iostream> #else #include <iostream.h> -@@ -96,8 +96,11 @@ +@@ -99,8 +99,11 @@ FileBuffRegion *copy(); // Deep copy FileBuffRegion *merge(FileBuffRegion*); // Merge 2 regions; delete input
--- a/patches/icedtea-graphics.patch Thu Feb 28 13:34:20 2008 -0500 +++ b/patches/icedtea-graphics.patch Mon Mar 03 20:58:16 2008 -0500 @@ -1,110 +1,3 @@ -diff -urN openjdk.orig/jdk/src/share/native/sun/awt/image/imageInitIDs.h openjdk/jdk/src/share/native/sun/awt/image/imageInitIDs.h ---- openjdk.orig/jdk/src/share/native/sun/awt/image/imageInitIDs.h 2007-07-20 03:33:46.000000000 -0400 -+++ openjdk/jdk/src/share/native/sun/awt/image/imageInitIDs.h 2007-07-25 15:55:05.000000000 -0400 -@@ -120,7 +120,4 @@ - IMGEXTERN jfieldID g_KernelYOriginD; - IMGEXTERN jfieldID g_KernelDataID; - --/* DataBufferInt ids */ --IMGEXTERN jfieldID g_DataBufferIntPdataID; -- - #endif /* IMAGEINITIDS_H */ ---- iopenjdkb23/openjdk/jdk/src/share/native/sun/java2d/cmm/lcms/LCMS.c 2007-10-30 04:38:58.000000000 -0400 -+++ openjdk/jdk/src/share/native/sun/java2d/cmm/lcms/LCMS.c 2007-11-13 12:43:26.000000000 -0500 -@@ -505,5 +505,5 @@ - IL_offset_fID = (*env)->GetFieldID (env, IL, "offset", "I"); - IL_nextRowOffset_fID = (*env)->GetFieldID (env, IL, "nextRowOffset", "I"); - -- PF_ID_fID = (*env)->GetFieldID (env, Pf, "ID", "J"); -+ PF_ID_fID = (*env)->GetFieldID (env, Pf, "profileID", "J"); - } ---- iopenjdkb23/openjdk/jdk/src/share/classes/sun/awt/image/SunWritableRaster.java 2007-10-30 04:37:17.000000000 -0400 -+++ openjdk/jdk/src/share/classes/sun/awt/image/SunWritableRaster.java 2007-11-13 12:47:25.000000000 -0500 -@@ -55,51 +55,48 @@ - public int[] getData(DataBufferInt dbi, int bank); - public StateTrackableDelegate getTrackable(DataBuffer db); - } -- -+/* - public static void setDataStealer(DataStealer ds) { - if (stealer != null) { - throw new InternalError("Attempt to set DataStealer twice"); - } - stealer = ds; - } -- -+*/ - public static byte[] stealData(DataBufferByte dbb, int bank) { -- return stealer.getData(dbb, bank); -+// return stealer.getData(dbb, bank); -+ return dbb.getData(bank); - } - - public static short[] stealData(DataBufferUShort dbus, int bank) { -- return stealer.getData(dbus, bank); -+// return stealer.getData(dbus, bank); -+ return dbus.getData(bank); - } - - public static int[] stealData(DataBufferInt dbi, int bank) { -- return stealer.getData(dbi, bank); -+// return stealer.getData(dbi, bank); -+ return dbi.getData(bank); - } - - public static StateTrackableDelegate stealTrackable(DataBuffer db) { -- return stealer.getTrackable(db); -+// return stealer.getTrackable(db); -+ return StateTrackableDelegate.UNTRACKABLE_DELEGATE; - } - - public static void markDirty(DataBuffer db) { -- stealer.getTrackable(db).markDirty(); -+// stealer.getTrackable(db).markDirty(); - } - - public static void markDirty(WritableRaster wr) { -- if (wr instanceof SunWritableRaster) { -- ((SunWritableRaster) wr).markDirty(); -- } else { -- markDirty(wr.getDataBuffer()); -- } - } - - public static void markDirty(Image img) { -- SurfaceData.getPrimarySurfaceData(img).markDirty(); - } - - private StateTrackableDelegate theTrackable; - - public SunWritableRaster(SampleModel sampleModel, Point origin) { - super(sampleModel, origin); -- theTrackable = stealTrackable(dataBuffer); - } - - public SunWritableRaster(SampleModel sampleModel, -@@ -107,7 +104,6 @@ - Point origin) - { - super(sampleModel, dataBuffer, origin); -- theTrackable = stealTrackable(dataBuffer); - } - - public SunWritableRaster(SampleModel sampleModel, -@@ -117,13 +113,11 @@ - WritableRaster parent) - { - super(sampleModel, dataBuffer, aRegion, sampleModelTranslate, parent); -- theTrackable = stealTrackable(dataBuffer); - } - - /** - * Mark the TrackableDelegate of the associated DataBuffer dirty. - */ - public final void markDirty() { -- theTrackable.markDirty(); - } - } --- ../opienjdkb23/openjdk/jdk/src/share/classes/javax/swing/text/WrappedPlainView.java 2007-10-30 04:37:06.000000000 -0400 +++ openjdk/jdk/src/share/classes/javax/swing/text/WrappedPlainView.java 2007-11-13 12:50:52.000000000 -0500 @@ -236,9 +236,6 @@ @@ -165,27 +58,3 @@ throw new IllegalArgumentException("Invalid axis: " + axis); } } ---- ../iopenjdkb23/openjdk/jdk/src/share/native/sun/awt/image/imageInitIDs.c 2007-10-30 04:38:50.000000000 -0400 -+++ openjdk/jdk/src/share/native/sun/awt/image/imageInitIDs.c 2007-11-13 12:52:43.000000000 -0500 -@@ -143,7 +143,7 @@ - jclass cls) { - g_SPPSMmaskArrID = (*env)->GetFieldID(env, cls, "bitMasks", "[I"); - g_SPPSMmaskOffID = (*env)->GetFieldID(env, cls, "bitOffsets", "[I"); -- g_SPPSMnBitsID = (*env)->GetFieldID(env, cls, "bitSizes", "[I"); -+ g_SPPSMnBitsID = (*env)->GetFieldID(env, cls, "sampleSize", "[I"); - g_SPPSMmaxBitID = (*env)->GetFieldID(env, cls, "maxBitSize", "I"); - - if (g_SPPSMmaskArrID == NULL || g_SPPSMmaskOffID == NULL || -@@ -228,12 +228,3 @@ - JNU_ThrowNullPointerException(env, "Unable to grab field ids"); - } - } -- --JNIEXPORT void JNICALL --Java_java_awt_image_DataBufferInt_initIDs(JNIEnv *env, jclass cls) { -- g_DataBufferIntPdataID = (*env)->GetFieldID(env, cls, "pData", "J"); -- if (g_DataBufferIntPdataID == NULL) { -- JNU_ThrowNullPointerException(env, "Unable to grab DataBufferInt.pData"); -- return; -- } --}
--- a/patches/icedtea-headers.patch Thu Feb 28 13:34:20 2008 -0500 +++ b/patches/icedtea-headers.patch Mon Mar 03 20:58:16 2008 -0500 @@ -11,7 +11,7 @@ --- openjdkold/jdk/make/tools/freetypecheck/Makefile 2008-01-04 18:20:30.000000000 -0500 +++ openjdk/jdk/make/tools/freetypecheck/Makefile 2008-02-26 11:21:34.000000000 -0500 -@@ -54,7 +54,7 @@ +@@ -61,7 +61,7 @@ ifeq ($(PLATFORM), solaris) FT_OPTIONS += -R $(FT_LIB) -lfreetype else #linux @@ -22,7 +22,7 @@ --- openjdkold/jdk/make/common/Defs.gmk 2008-01-04 18:20:29.000000000 -0500 +++ openjdk/jdk/make/common/Defs.gmk 2008-02-26 11:21:49.000000000 -0500 -@@ -225,7 +225,7 @@ +@@ -237,7 +237,7 @@ ifeq ($(PLATFORM), windows) FREETYPE_LIB = $(FREETYPE_LIB_PATH)/freetype.lib else
--- a/patches/icedtea-lib64.patch Thu Feb 28 13:34:20 2008 -0500 +++ b/patches/icedtea-lib64.patch Mon Mar 03 20:58:16 2008 -0500 @@ -1,6 +1,6 @@ --- origopenjdk/hotspot/src/os/linux/vm/os_linux.cpp 2008-01-04 18:11:53.000000000 -0500 +++ openjdk/hotspot/src/os/linux/vm/os_linux.cpp 2008-01-11 11:15:24.000000000 -0500 -@@ -265,7 +265,12 @@ +@@ -271,7 +271,12 @@ * ... * 7: The default directories, normally /lib and /usr/lib. */
--- a/patches/icedtea-libraries.patch Thu Feb 28 13:34:20 2008 -0500 +++ b/patches/icedtea-libraries.patch Mon Mar 03 20:58:16 2008 -0500 @@ -75,7 +75,7 @@ LDFLAGS += -Wl,--allow-shlib-undefined LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../lib/$(LIBARCH)/jli LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../jre/lib/$(LIBARCH)/jli -@@ -250,7 +250,6 @@ +@@ -251,7 +251,6 @@ endif OTHER_INCLUDES += -I$(LAUNCHER_SHARE_SRC)/bin -I$(LAUNCHER_PLATFORM_SRC)/bin
--- a/patches/icedtea-ports.patch Thu Feb 28 13:34:20 2008 -0500 +++ b/patches/icedtea-ports.patch Mon Mar 03 20:58:16 2008 -0500 @@ -57,7 +57,7 @@ diff -ru openjdk.orig/hotspot/src/os/linux/vm/os_linux.cpp openjdk/hotspot/src/os/linux/vm/os_linux.cpp --- openjdk.orig/hotspot/src/os/linux/vm/os_linux.cpp 2007-11-08 11:34:54.000000000 +0000 +++ openjdk/hotspot/src/os/linux/vm/os_linux.cpp 2007-11-08 11:36:15.000000000 +0000 -@@ -171,6 +171,12 @@ +@@ -174,6 +174,12 @@ # else static char cpu_arch[] = "sparc"; # endif @@ -70,7 +70,7 @@ #else #error Add appropriate cpu_arch setting #endif -@@ -2372,7 +2378,8 @@ +@@ -2370,7 +2376,8 @@ // format has been changed), we'll use the largest page size supported by // the processor. @@ -83,7 +83,7 @@ diff -ru openjdk.orig/hotspot/src/share/vm/runtime/vm_version.cpp openjdk/hotspot/src/share/vm/runtime/vm_version.cpp --- openjdk.orig/hotspot/src/share/vm/runtime/vm_version.cpp 2007-11-08 11:34:54.000000000 +0000 +++ openjdk/hotspot/src/share/vm/runtime/vm_version.cpp 2007-11-08 11:36:15.000000000 +0000 -@@ -147,7 +147,8 @@ +@@ -146,7 +146,8 @@ #define CPU IA32_ONLY("x86") \ IA64_ONLY("ia64") \ AMD64_ONLY("amd64") \ @@ -96,7 +96,7 @@ diff -ru openjdk.orig/hotspot/src/share/vm/utilities/macros.hpp openjdk/hotspot/src/share/vm/utilities/macros.hpp --- openjdk.orig/hotspot/src/share/vm/utilities/macros.hpp 2007-11-08 11:34:54.000000000 +0000 +++ openjdk/hotspot/src/share/vm/utilities/macros.hpp 2007-11-08 11:36:15.000000000 +0000 -@@ -176,6 +176,14 @@ +@@ -156,6 +156,14 @@ #define NOT_SPARC(code) code #endif @@ -194,7 +194,7 @@ diff -ru openjdk.orig/jdk/make/common/shared/Platform.gmk openjdk/jdk/make/common/shared/Platform.gmk --- openjdk.orig/jdk/make/common/shared/Platform.gmk 2007-11-08 11:34:54.000000000 +0000 +++ openjdk/jdk/make/common/shared/Platform.gmk 2007-11-08 11:36:15.000000000 +0000 -@@ -223,9 +223,9 @@ +@@ -225,9 +225,9 @@ ARCH=sparcv9 endif else
--- a/patches/icedtea-sunsrc.patch Thu Feb 28 13:34:20 2008 -0500 +++ b/patches/icedtea-sunsrc.patch Mon Mar 03 20:58:16 2008 -0500 @@ -1,5 +1,5 @@ ---- openjdk.orig/jdk/make/common/Release.gmk 2007-10-26 16:46:41.000000000 -0400 -+++ openjdk/jdk/make/common/Release.gmk 2007-11-07 11:46:22.000000000 -0500 +--- openjdk.orig/jdk/make/common/Release.gmk 2008-02-28 04:39:40.000000000 -0500 ++++ openjdk/jdk/make/common/Release.gmk 2008-02-29 14:34:26.000000000 -0500 @@ -338,8 +338,6 @@ # Bug 5008685 - exclude jconsole from sun/tools # @@ -14,7 +14,7 @@ com/sun/tools/internal/xjc \ com/sun/tools/internal/ws \ - META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory \ -- META-INF/services/com.sun.tools.xjc.Plugin \ +- META-INF/services/com.sun.tools.internal.xjc.Plugin \ com/sun/istack/internal/tools \ com/sun/istack/internal/ws \ com/sun/codemodel \ @@ -33,7 +33,7 @@ - $(ECHO) "META-INF/services/com.sun.jdi.connect.Connector" >> $@ - $(ECHO) "META-INF/services/com.sun.jdi.connect.spi.TransportService" >> $@ - $(ECHO) "META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory" >> $@ -- $(ECHO) "META-INF/services/com.sun.tools.xjc.Plugin" >> $@ +- $(ECHO) "META-INF/services/com.sun.tools.internal.xjc.Plugin" >> $@ $(ECHO) "com/sun/tools/" >> $@ $(ECHO) "sun/jvmstat/" >> $@ $(ECHO) "sun/rmi/rmic/" >> $@
--- a/patches/icedtea-tools.patch Thu Feb 28 13:34:20 2008 -0500 +++ b/patches/icedtea-tools.patch Mon Mar 03 20:58:16 2008 -0500 @@ -50,18 +50,18 @@ java/awt/Toolkit java/awt/Toolkit$3 sun/util/CoreResourceBundleControl ---- ../openjdk-b19/openjdk/jdk/make/java/awt/Makefile 2007-08-30 03:19:36.000000000 -0400 -+++ openjdk/jdk/make/java/awt/Makefile 2007-09-04 13:56:08.000000000 -0400 -@@ -46,7 +46,7 @@ - - endif +--- openjdk.orig/jdk/make/java/awt/Makefile 2008-02-28 04:39:42.000000000 -0500 ++++ openjdk/jdk/make/java/awt/Makefile 2008-02-29 14:58:50.000000000 -0500 +@@ -34,7 +34,7 @@ + # + AUTO_FILES_JAVA_DIRS = java/awt sun/awt/geom -build: properties cursors +build: sources properties cursors # # Resources -@@ -59,9 +59,11 @@ +@@ -47,9 +47,11 @@ # include $(BUILDDIR)/common/Classes.gmk @@ -73,7 +73,7 @@ _LIBPROPS = \ flavormap.properties -@@ -114,6 +116,6 @@ +@@ -102,6 +104,6 @@ cursors.clean : $(RM) -r $(CURSORDIR)
--- a/patches/icedtea-use-system-tzdata.patch Thu Feb 28 13:34:20 2008 -0500 +++ b/patches/icedtea-use-system-tzdata.patch Mon Mar 03 20:58:16 2008 -0500 @@ -1,17 +1,3 @@ -diff -urN openjdk.orig/hotspot/src/os/linux/vm/os_linux.cpp openjdk/hotspot/src/os/linux/vm/os_linux.cpp ---- openjdk.orig/hotspot/src/os/linux/vm/os_linux.cpp 2007-10-12 18:25:55.000000000 -0400 -+++ openjdk/hotspot/src/os/linux/vm/os_linux.cpp 2007-10-12 18:26:02.000000000 -0400 -@@ -390,6 +390,10 @@ - "javax.net.ssl.trustStorePassword", - ""); - -+ // Use the system zoneinfo files, if present -+ Arguments::PropertyList_add (&sp, -+ "user.zoneinfo.dir", "/usr/share/javazi"); -+ - #undef malloc - #undef getenv - #undef EXTENSIONS_DIR --- ../openjdkb23/openjdk/jdk/src/share/classes/sun/util/calendar/ZoneInfoFile.java 2007-10-30 04:38:28.000000000 -0400 +++ openjdk/jdk/src/share/classes/sun/util/calendar/ZoneInfoFile.java 2007-11-13 13:16:52.000000000 -0500 @@ -28,6 +28,7 @@
--- a/patches/icedtea-zero.patch Thu Feb 28 13:34:20 2008 -0500 +++ b/patches/icedtea-zero.patch Mon Mar 03 20:58:16 2008 -0500 @@ -1,7 +1,7 @@ diff -ru openjdk/hotspot/src/share/vm/runtime/icache.cpp openjdk/hotspot/src/share/vm/runtime/icache.cpp --- openjdk/hotspot/src/share/vm/runtime/icache.cpp 2007-10-30 08:46:35.000000000 +0000 +++ openjdk/hotspot/src/share/vm/runtime/icache.cpp 2008-01-21 15:18:48.000000000 +0000 -@@ -78,6 +78,7 @@ +@@ -81,6 +81,7 @@ } void AbstractICache::invalidate_range(address start, int nbytes) { @@ -9,7 +9,7 @@ static bool firstTime = true; if (firstTime) { guarantee(start == CAST_FROM_FN_PTR(address, _flush_icache_stub), -@@ -97,6 +98,7 @@ +@@ -100,6 +101,7 @@ } call_flush_stub(start, round_to(nbytes, ICache::line_size) >> ICache::log2_line_size); @@ -20,7 +20,7 @@ diff -ru openjdk/hotspot/src/share/vm/runtime/jniHandles.hpp openjdk/hotspot/src/share/vm/runtime/jniHandles.hpp --- openjdk/hotspot/src/share/vm/runtime/jniHandles.hpp 2007-10-30 08:46:35.000000000 +0000 +++ openjdk/hotspot/src/share/vm/runtime/jniHandles.hpp 2008-01-24 13:26:36.000000000 +0000 -@@ -126,9 +126,17 @@ +@@ -129,9 +129,17 @@ // Fill block with bad_handle values void zap(); @@ -41,7 +41,7 @@ diff -ru openjdk/hotspot/src/share/vm/utilities/vmError.cpp openjdk/hotspot/src/share/vm/utilities/vmError.cpp --- openjdk/hotspot/src/share/vm/utilities/vmError.cpp 2008-01-24 13:17:27.000000000 +0000 +++ openjdk/hotspot/src/share/vm/utilities/vmError.cpp 2008-01-24 13:21:20.000000000 +0000 -@@ -24,6 +24,11 @@ +@@ -27,6 +27,11 @@ # include "incls/_precompiled.incl" # include "incls/_vmError.cpp.incl" @@ -53,7 +53,7 @@ // List of environment variables that should be reported in error log file. const char *env_list[] = { -@@ -392,6 +397,7 @@ +@@ -395,6 +400,7 @@ st->cr(); } @@ -61,7 +61,7 @@ STEP(110, "(printing stack bounds)" ) if (_verbose) { -@@ -449,11 +455,16 @@ +@@ -452,11 +453,16 @@ st->cr(); } } @@ -78,7 +78,7 @@ if (jt->has_last_Java_frame()) { st->print_cr("Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)"); for(StackFrameStream sfs(jt); !sfs.is_done(); sfs.next()) { -@@ -461,6 +472,7 @@ +@@ -464,6 +475,7 @@ st->cr(); } }
--- a/rt/java/awt/color/CMMException.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* CMMException.java -- error in the native CMM - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.color; - -/** - * Thrown when there is an error in the native CMM. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @status updated to 1.4 - */ -public class CMMException extends RuntimeException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 5775558044142994965L; - - /** - * Create a new instance with a specified detailed error message. - * - * @param message the message - */ - public CMMException(String message) - { - super(message); - } -} // class CMMException
--- a/rt/java/awt/color/ColorSpace.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,190 +0,0 @@ -/* ColorSpace.java -- transforms between color spaces - Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.color; - -import java.io.Serializable; -import sun.java2d.cmm.CMSManager; - -/** - * NEEDS DOCUMENTATION - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - * @since 1.2 - */ -public abstract class ColorSpace implements Serializable -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -409452704308689724L; - - public static final int TYPE_XYZ = 0; - public static final int TYPE_Lab = 1; - public static final int TYPE_Luv = 2; - public static final int TYPE_YCbCr = 3; - public static final int TYPE_Yxy = 4; - public static final int TYPE_RGB = 5; - public static final int TYPE_GRAY = 6; - public static final int TYPE_HSV = 7; - public static final int TYPE_HLS = 8; - public static final int TYPE_CMYK = 9; - // mysterious gap in the enumeration sequenece - public static final int TYPE_CMY = 11; - public static final int TYPE_2CLR = 12; - public static final int TYPE_3CLR = 13; - public static final int TYPE_4CLR = 14; - public static final int TYPE_5CLR = 15; - public static final int TYPE_6CLR = 16; - public static final int TYPE_7CLR = 17; - public static final int TYPE_8CLR = 18; - public static final int TYPE_9CLR = 19; - public static final int TYPE_ACLR = 20; - public static final int TYPE_BCLR = 21; - public static final int TYPE_CCLR = 22; - public static final int TYPE_DCLR = 23; - public static final int TYPE_ECLR = 24; - public static final int TYPE_FCLR = 25; - - public static final int CS_sRGB = 1000; - public static final int CS_LINEAR_RGB = 1004; - public static final int CS_CIEXYZ = 1001; - public static final int CS_PYCC = 1002; - public static final int CS_GRAY = 1003; - - private static final int CS_BASE = CS_sRGB; - private static final int CS_END = CS_LINEAR_RGB + 1; - private static final int CS_COUNT = CS_END - CS_BASE; - - // Instances are lazily instantiated - private static final ColorSpace[] INSTANCES = new ColorSpace[CS_COUNT]; - - /** - * @serial - */ - // Visible in subclass. - final int type; - - /** - * @serial - */ - // Visible in subclass. - final int numComponents; - - protected ColorSpace(int type, int numcomponents) - { - this.type = type; - numComponents = numcomponents; - } - - public static ColorSpace getInstance(int colorspace) - { - if ((colorspace >= CS_BASE) && (colorspace < CS_END)) - { - int instanceIndex = colorspace - CS_BASE; - if (INSTANCES[instanceIndex] == null) - { - ICC_Profile profile = new ICC_Profile(colorspace); - INSTANCES[instanceIndex] = new ICC_ColorSpace(profile); - - if (colorspace == CS_LINEAR_RGB) - CMSManager.LINEAR_RGBspace = INSTANCES[instanceIndex]; - - if (colorspace == CS_GRAY) - CMSManager.GRAYspace = INSTANCES[instanceIndex]; - } - return INSTANCES[instanceIndex]; - } - throw new IllegalArgumentException("unknown/unsupported colorspace"); - } - - public boolean isCS_sRGB() - { - return type == CS_sRGB; - } - - /** - * Transforms a color value assumed to be in this ColorSpace into a value in - * the default CS_sRGB color space. - * - * @exception ArrayIndexOutOfBoundsException If array length is not at least - * the number of components in this ColorSpace. - */ - public abstract float[] toRGB(float[] colorvalue); - - public abstract float[] fromRGB(float[] rgbvalue); - - public abstract float[] toCIEXYZ(float[] colorvalue); - - public abstract float[] fromCIEXYZ(float[] colorvalue); - - public int getType() - { - return type; - } - - public int getNumComponents() - { - return numComponents; - } - - public String getName(int idx) - { - return "type " + type; - } - - /** - * @since 1.4 - */ - public float getMinValue(int idx) - { - if (idx < 0 || idx >= numComponents) - throw new IllegalArgumentException(); - return 0; - } - - /** - * @since 1.4 - */ - public float getMaxValue(int idx) - { - if (idx < 0 || idx >= numComponents) - throw new IllegalArgumentException(); - return 1; - } -} // class ColorSpace
--- a/rt/java/awt/color/ICC_ColorSpace.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,314 +0,0 @@ -/* ICC_ColorSpace.java -- the canonical color space implementation - Copyright (C) 2000, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.color; - -import gnu.java.awt.color.CieXyzConverter; -import gnu.java.awt.color.ClutProfileConverter; -import gnu.java.awt.color.ColorSpaceConverter; -import gnu.java.awt.color.GrayProfileConverter; -import gnu.java.awt.color.GrayScaleConverter; -import gnu.java.awt.color.LinearRGBConverter; -import gnu.java.awt.color.PyccConverter; -import gnu.java.awt.color.RgbProfileConverter; -import gnu.java.awt.color.SrgbConverter; - -import java.io.IOException; -import java.io.ObjectInputStream; - -/** - * ICC_ColorSpace - an implementation of ColorSpace - * - * While an ICC_Profile class abstracts the data in an ICC profile file - * an ICC_ColorSpace performs the color space conversions defined by - * an ICC_Profile instance. - * - * Typically, an ICC_Profile will either be created using getInstance, - * either from the built-in colorspaces, or from an ICC profile file. - * Then a ICC_Colorspace will be used to perform transforms from the - * device colorspace to and from the profile color space. - * - * The PCS used by ColorSpace is CIE XYZ relative a D50 white point. - * (Profiles using a CIE Lab PCS will have their input and output converted - * to D50 CIE XYZ accordingly. - * - * Note that a valid profile may not contain transforms in both directions, - * in which case the output may be undefined. - * All built-in colorspaces have bidirectional transforms, but developers - * using an ICC profile file may want to check the profile class using - * the ICC_Profile.getProfileClass() method. Input class profiles are - * guaranteed to have transforms to the PCS, output class profiles are - * guaranteed to have transforms from the PCS to device space. - * - * @author Sven de Marothy - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - * @since 1.2 - */ -public class ICC_ColorSpace extends ColorSpace -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 3455889114070431483L; - - /** - * @serial - */ - private ICC_Profile thisProfile; - - /** - * @serial - */ - private float[] minVal; - - /** - * @serial - */ - private float[] maxVal; - - /** - * @serial - */ - private float[] diffMinMax; - - /** - * @serial - */ - private float[] invDiffMinMax; - - /** - * @serial - */ - private boolean needScaleInit; - - /** - * Tells us if the PCS is CIE LAB (must be CIEXYZ otherwise) - */ - private transient int type; - private transient int nComponents; - private transient ColorSpaceConverter converter; - - /** - * Constructs a new ICC_ColorSpace from an ICC_Profile object. - * - * @exception IllegalArgumentException If profile is inappropriate for - * representing a ColorSpace. - */ - public ICC_ColorSpace(ICC_Profile profile) - { - super(profile.getColorSpaceType(), profile.getNumComponents()); - - converter = getConverter(profile); - thisProfile = profile; - nComponents = profile.getNumComponents(); - type = profile.getColorSpaceType(); - makeArrays(); - } - - /** - * Return the profile - */ - public ICC_Profile getProfile() - { - return thisProfile; - } - - /** - * Transforms a color value assumed to be in this ColorSpace into a value in - * the default CS_sRGB color space. - * - * @exception ArrayIndexOutOfBoundsException If array length is not at least - * the number of components in this ColorSpace. - */ - public float[] toRGB(float[] colorvalue) - { - return converter.toRGB(colorvalue); - } - - /** - * Transforms a color value assumed to be in the default CS_sRGB color space - * into this ColorSpace. - * - * @exception ArrayIndexOutOfBoundsException If array length is not at - * least 3. - */ - public float[] fromRGB(float[] rgbvalue) - { - return converter.fromRGB(rgbvalue); - } - - /** - * Transforms a color value assumed to be in this ColorSpace into the - * CS_CIEXYZ conversion color space. - * - * @exception ArrayIndexOutOfBoundsException If array length is not at - * least the number of components in this ColorSpace. - */ - public float[] toCIEXYZ(float[] colorvalue) - { - return converter.toCIEXYZ(colorvalue); - } - - /** - * Transforms a color value assumed to be in the CS_CIEXYZ conversion color - * space into this ColorSpace. - * - * @exception ArrayIndexOutOfBoundsException If array length is not at - * least 3. - */ - public float[] fromCIEXYZ(float[] colorvalue) - { - return converter.fromCIEXYZ(colorvalue); - } - - public boolean isCS_sRGB() - { - return converter instanceof SrgbConverter; - } - - /** - * Returns the minimum normalized color component value for the specified - * component. - * - * @exception IllegalArgumentException If component is less than 0 or greater - * than numComponents - 1. - * - * @since 1.4 - */ - public float getMinValue(int idx) - { - // FIXME: Not 100% certain of this. - if (type == ColorSpace.TYPE_Lab && (idx == 1 || idx == 2)) - return -128f; - - if (idx < 0 || idx >= nComponents) - throw new IllegalArgumentException(); - return 0; - } - - /** - * Returns the maximum normalized color component value for the specified - * component. - * - * @exception IllegalArgumentException If component is less than 0 or greater - * than numComponents - 1. - * - * @since 1.4 - */ - public float getMaxValue(int idx) - { - if (type == ColorSpace.TYPE_XYZ && idx >= 0 && idx <= 2) - return 1 + 32767 / 32768f; - else if (type == ColorSpace.TYPE_Lab) - { - if (idx == 0) - return 100; - if (idx == 1 || idx == 2) - return 127; - } - if (idx < 0 || idx >= nComponents) - throw new IllegalArgumentException(); - return 1; - } - - /** - * Returns a colorspace converter suitable for a given profile - */ - private ColorSpaceConverter getConverter(ICC_Profile profile) - { - ColorSpaceConverter converter; - switch (profile.isPredefined()) - { - case CS_sRGB: - converter = new SrgbConverter(); - break; - case CS_CIEXYZ: - converter = new CieXyzConverter(); - break; - case CS_GRAY: - converter = new GrayScaleConverter(); - break; - case CS_LINEAR_RGB: - converter = new LinearRGBConverter(); - break; - case CS_PYCC: - converter = new PyccConverter(); - break; - default: - if (profile instanceof ICC_ProfileRGB) - converter = new RgbProfileConverter((ICC_ProfileRGB) profile); - else if (profile instanceof ICC_ProfileGray) - converter = new GrayProfileConverter((ICC_ProfileGray) profile); - else - converter = new ClutProfileConverter(profile); - break; - } - return converter; - } - - /** - * Serialization compatibility requires these variable to be set, - * although we don't use them. Perhaps we should? - */ - private void makeArrays() - { - minVal = new float[nComponents]; - maxVal = new float[nComponents]; - - invDiffMinMax = diffMinMax = null; - for (int i = 0; i < nComponents; i++) - { - minVal[i] = getMinValue(i); - maxVal[i] = getMaxValue(i); - } - needScaleInit = true; - } - - /** - * Deserializes the object - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - // set up objects - converter = getConverter(thisProfile); - nComponents = thisProfile.getNumComponents(); - type = thisProfile.getColorSpaceType(); - } -} // class ICC_ColorSpace
--- a/rt/java/awt/color/ICC_Profile.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1282 +0,0 @@ -/* ICC_Profile.java -- color space profiling - Copyright (C) 2000, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.color; - -import gnu.java.awt.color.ProfileHeader; -import gnu.java.awt.color.TagEntry; - -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.ObjectStreamException; -import java.io.OutputStream; -import java.io.Serializable; -import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; -import java.util.Enumeration; -import java.util.Hashtable; - -import sun.java2d.cmm.PCMM; -import sun.java2d.cmm.CMSManager; - -/** - * ICC Profile - represents an ICC Color profile. - * The ICC profile format is a standard file format which maps the transform - * from a device color space to a standard Profile Color Space (PCS), which - * can either be CIE L*a*b or CIE XYZ. - * (With the exception of device link profiles which map from one device space - * to another) - * - * ICC profiles calibrated to specific input/output devices are used when color - * fidelity is of importance. - * - * An instance of ICC_Profile can be created using the getInstance() methods, - * either using one of the predefined color spaces enumerated in ColorSpace, - * or from an ICC profile file, or from an input stream. - * - * An ICC_ColorSpace object can then be created to transform color values - * through the profile. - * - * The ICC_Profile class implements the version 2 format specified by - * International Color Consortium Specification ICC.1:1998-09, - * and its addendum ICC.1A:1999-04, April 1999 - * (available at www.color.org) - * - * @author Sven de Marothy - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - * @since 1.2 - */ -public class ICC_Profile implements Serializable -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -3938515861990936766L; - - /** - * ICC Profile classes - */ - public static final int CLASS_INPUT = 0; - public static final int CLASS_DISPLAY = 1; - public static final int CLASS_OUTPUT = 2; - public static final int CLASS_DEVICELINK = 3; - public static final int CLASS_COLORSPACECONVERSION = 4; - public static final int CLASS_ABSTRACT = 5; - public static final int CLASS_NAMEDCOLOR = 6; - - /** - * ICC Profile class signatures - */ - public static final int icSigInputClass = 0x73636e72; // 'scnr' - public static final int icSigDisplayClass = 0x6d6e7472; // 'mntr' - public static final int icSigOutputClass = 0x70727472; // 'prtr' - public static final int icSigLinkClass = 0x6c696e6b; // 'link' - public static final int icSigColorSpaceClass = 0x73706163; // 'spac' - public static final int icSigAbstractClass = 0x61627374; // 'abst' - public static final int icSigNamedColorClass = 0x6e6d636c; // 'nmcl' - - /** - * Color space signatures - */ - public static final int icSigXYZData = 0x58595A20; // 'XYZ ' - public static final int icSigLabData = 0x4C616220; // 'Lab ' - public static final int icSigLuvData = 0x4C757620; // 'Luv ' - public static final int icSigYCbCrData = 0x59436272; // 'YCbr' - public static final int icSigYxyData = 0x59787920; // 'Yxy ' - public static final int icSigRgbData = 0x52474220; // 'RGB ' - public static final int icSigGrayData = 0x47524159; // 'GRAY' - public static final int icSigHsvData = 0x48535620; // 'HSV ' - public static final int icSigHlsData = 0x484C5320; // 'HLS ' - public static final int icSigCmykData = 0x434D594B; // 'CMYK' - public static final int icSigCmyData = 0x434D5920; // 'CMY ' - public static final int icSigSpace2CLR = 0x32434C52; // '2CLR' - public static final int icSigSpace3CLR = 0x33434C52; // '3CLR' - public static final int icSigSpace4CLR = 0x34434C52; // '4CLR' - public static final int icSigSpace5CLR = 0x35434C52; // '5CLR' - public static final int icSigSpace6CLR = 0x36434C52; // '6CLR' - public static final int icSigSpace7CLR = 0x37434C52; // '7CLR' - public static final int icSigSpace8CLR = 0x38434C52; // '8CLR' - public static final int icSigSpace9CLR = 0x39434C52; // '9CLR' - public static final int icSigSpaceACLR = 0x41434C52; // 'ACLR' - public static final int icSigSpaceBCLR = 0x42434C52; // 'BCLR' - public static final int icSigSpaceCCLR = 0x43434C52; // 'CCLR' - public static final int icSigSpaceDCLR = 0x44434C52; // 'DCLR' - public static final int icSigSpaceECLR = 0x45434C52; // 'ECLR' - public static final int icSigSpaceFCLR = 0x46434C52; // 'FCLR' - - /** - * Rendering intents - */ - public static final int icPerceptual = 0; - public static final int icRelativeColorimetric = 1; - public static final int icSaturation = 2; - public static final int icAbsoluteColorimetric = 3; - - /** - * Tag signatures - */ - public static final int icSigAToB0Tag = 0x41324230; // 'A2B0' - public static final int icSigAToB1Tag = 0x41324231; // 'A2B1' - public static final int icSigAToB2Tag = 0x41324232; // 'A2B2' - public static final int icSigBlueColorantTag = 0x6258595A; // 'bXYZ' - public static final int icSigBlueTRCTag = 0x62545243; // 'bTRC' - public static final int icSigBToA0Tag = 0x42324130; // 'B2A0' - public static final int icSigBToA1Tag = 0x42324131; // 'B2A1' - public static final int icSigBToA2Tag = 0x42324132; // 'B2A2' - public static final int icSigCalibrationDateTimeTag = 0x63616C74; // 'calt' - public static final int icSigCharTargetTag = 0x74617267; // 'targ' - public static final int icSigCopyrightTag = 0x63707274; // 'cprt' - public static final int icSigCrdInfoTag = 0x63726469; // 'crdi' - public static final int icSigDeviceMfgDescTag = 0x646D6E64; // 'dmnd' - public static final int icSigDeviceModelDescTag = 0x646D6464; // 'dmdd' - public static final int icSigDeviceSettingsTag = 0x64657673; // 'devs' - public static final int icSigGamutTag = 0x67616D74; // 'gamt' - public static final int icSigGrayTRCTag = 0x6b545243; // 'kTRC' - public static final int icSigGreenColorantTag = 0x6758595A; // 'gXYZ' - public static final int icSigGreenTRCTag = 0x67545243; // 'gTRC' - public static final int icSigLuminanceTag = 0x6C756d69; // 'lumi' - public static final int icSigMeasurementTag = 0x6D656173; // 'meas' - public static final int icSigMediaBlackPointTag = 0x626B7074; // 'bkpt' - public static final int icSigMediaWhitePointTag = 0x77747074; // 'wtpt' - public static final int icSigNamedColor2Tag = 0x6E636C32; // 'ncl2' - public static final int icSigOutputResponseTag = 0x72657370; // 'resp' - public static final int icSigPreview0Tag = 0x70726530; // 'pre0' - public static final int icSigPreview1Tag = 0x70726531; // 'pre1' - public static final int icSigPreview2Tag = 0x70726532; // 'pre2' - public static final int icSigProfileDescriptionTag = 0x64657363; // 'desc' - public static final int icSigProfileSequenceDescTag = 0x70736571; // 'pseq' - public static final int icSigPs2CRD0Tag = 0x70736430; // 'psd0' - public static final int icSigPs2CRD1Tag = 0x70736431; // 'psd1' - public static final int icSigPs2CRD2Tag = 0x70736432; // 'psd2' - public static final int icSigPs2CRD3Tag = 0x70736433; // 'psd3' - public static final int icSigPs2CSATag = 0x70733273; // 'ps2s' - public static final int icSigPs2RenderingIntentTag = 0x70733269; // 'ps2i' - public static final int icSigRedColorantTag = 0x7258595A; // 'rXYZ' - public static final int icSigRedTRCTag = 0x72545243; // 'rTRC' - public static final int icSigScreeningDescTag = 0x73637264; // 'scrd' - public static final int icSigScreeningTag = 0x7363726E; // 'scrn' - public static final int icSigTechnologyTag = 0x74656368; // 'tech' - public static final int icSigUcrBgTag = 0x62666420; // 'bfd ' - public static final int icSigViewingCondDescTag = 0x76756564; // 'vued' - public static final int icSigViewingConditionsTag = 0x76696577; // 'view' - public static final int icSigChromaticityTag = 0x6368726D; // 'chrm' - - /** - * Non-ICC tag 'head' for use in retrieving the header with getData() - */ - public static final int icSigHead = 0x68656164; - - /** - * Header offsets - */ - public static final int icHdrSize = 0; - public static final int icHdrCmmId = 4; - public static final int icHdrVersion = 8; - public static final int icHdrDeviceClass = 12; - public static final int icHdrColorSpace = 16; - public static final int icHdrPcs = 20; - public static final int icHdrDate = 24; - public static final int icHdrMagic = 36; - public static final int icHdrPlatform = 40; - public static final int icHdrFlags = 44; - public static final int icHdrManufacturer = 48; - public static final int icHdrModel = 52; - public static final int icHdrAttributes = 56; - public static final int icHdrRenderingIntent = 64; - public static final int icHdrIlluminant = 68; - public static final int icHdrCreator = 80; - - /** - * - */ - public static final int icTagType = 0; - public static final int icTagReserved = 4; - public static final int icCurveCount = 8; - public static final int icCurveData = 12; - public static final int icXYZNumberX = 8; - - /** - * offset of the Tag table - */ - private static final int tagTableOffset = 128; - - /** - * @serial - */ - private static final int iccProfileSerializedDataVersion = 1; - - /** - * Constants related to generating profiles for - * built-in colorspace profiles - */ - /** - * Copyright notice to stick into built-in-profile files. - */ - private static final String copyrightNotice = "Generated by GNU Classpath."; - - /** - * Resolution of the TRC to use for predefined profiles. - * 1024 should suffice. - */ - private static final int TRC_POINTS = 1024; - - /** - * CIE 1931 D50 white point (in Lab coordinates) - */ - private static final float[] D50 = { 0.96422f, 1.00f, 0.82521f }; - - /** - * Color space profile ID - this is the address of the native littleCMS - * profile that backs this profile. - */ - private transient long profileID; - - /** - * The profile header data - */ - private transient ProfileHeader header; - - /** - * The ColorSpace used, or -1 if not one of the built-in types. - */ - private int colorSpace = -1; - - /** - * Store the color manager for easy access. - */ - private PCMM pcmm = CMSManager.getModule(); - - /** - * Contructor for predefined colorspaces - */ - ICC_Profile(int colorSpace) - { - this.colorSpace = colorSpace; - createProfile(colorSpace); - } - - /** - * Constructs an ICC_Profile from a byte array of data. - */ - ICC_Profile(byte[] data) throws IllegalArgumentException - { - // get header and verify it - header = new ProfileHeader(data); - header.verifyHeader(data.length); - - profileID = pcmm.loadProfile(data); - } - - /** - * Free up the used memory. - */ - protected void finalize() - { - pcmm.freeProfile(profileID); - } - - /** - * Returns an ICC_Profile instance from a byte array of profile data. - * - * An instance of the specialized classes ICC_ProfileRGB or ICC_ProfileGray - * may be returned if appropriate. - * - * @param data - the profile data - * @return An ICC_Profile object - * - * @throws IllegalArgumentException if the profile data is an invalid - * v2 profile. - */ - public static ICC_Profile getInstance(byte[] data) - { - // get header and verify it - ProfileHeader header = new ProfileHeader(data); - header.verifyHeader(data.length); - - Hashtable tags = createTagTable(data); - - if (isRGBProfile(header, tags)) - return new ICC_ProfileRGB(data); - if (isGrayProfile(header, tags)) - return new ICC_ProfileGray(data); - - return new ICC_Profile(data); - } - - /** - * Returns an predefined ICC_Profile instance. - * - * This will construct an ICC_Profile instance from one of the predefined - * color spaces in the ColorSpace class. (e.g. CS_sRGB, CS_GRAY, etc) - * - * An instance of the specialized classes ICC_ProfileRGB or ICC_ProfileGray - * may be returned if appropriate. - * - * @return An ICC_Profile object - */ - public static ICC_Profile getInstance(int cspace) - { - if (cspace == ColorSpace.CS_sRGB || cspace == ColorSpace.CS_LINEAR_RGB) - return new ICC_ProfileRGB(cspace); - if (cspace == ColorSpace.CS_GRAY) - return new ICC_ProfileGray(cspace); - return new ICC_Profile(cspace); - } - - /** - * Returns an ICC_Profile instance from an ICC Profile file. - * - * An instance of the specialized classes ICC_ProfileRGB or ICC_ProfileGray - * may be returned if appropriate. - * - * @param filename - the file name of the profile file. - * @return An ICC_Profile object - * - * @throws IllegalArgumentException if the profile data is an invalid - * v2 profile. - * @throws IOException if the file could not be read. - */ - public static ICC_Profile getInstance(String filename) - throws IOException - { - return getInstance(new FileInputStream(filename)); - } - - /** - * Returns an ICC_Profile instance from an InputStream. - * - * This method can be used for reading ICC profiles embedded in files - * which support this. (JPEG and SVG for instance). - * - * The stream is treated in the following way: The profile header - * (128 bytes) is read first, and the header is validated. If the profile - * header is valid, it will then attempt to read the rest of the profile - * from the stream. The stream is not closed after reading. - * - * An instance of the specialized classes ICC_ProfileRGB or ICC_ProfileGray - * may be returned if appropriate. - * - * @param in - the input stream to read the profile from. - * @return An ICC_Profile object - * - * @throws IllegalArgumentException if the profile data is an invalid - * v2 profile. - * @throws IOException if the stream could not be read. - */ - public static ICC_Profile getInstance(InputStream in) - throws IOException - { - // read the header - byte[] headerData = new byte[ProfileHeader.HEADERSIZE]; - if (in.read(headerData) != ProfileHeader.HEADERSIZE) - throw new IllegalArgumentException("Invalid profile header"); - - ProfileHeader header = new ProfileHeader(headerData); - - // verify it as a correct ICC header, but do not verify the - // size as we are reading from a stream. - header.verifyHeader(-1); - - // get the size - byte[] data = new byte[header.getSize()]; - System.arraycopy(headerData, 0, data, 0, ProfileHeader.HEADERSIZE); - - // read the rest - if (in.read(data, ProfileHeader.HEADERSIZE, - header.getSize() - ProfileHeader.HEADERSIZE) != header.getSize() - - ProfileHeader.HEADERSIZE) - throw new IOException("Incorrect profile size"); - - return getInstance(data); - } - - /** - * Returns the major version number - */ - public int getMajorVersion() - { - return header.getMajorVersion(); - } - - /** - * Returns the minor version number. - * - * Only the least-significant byte contains data, in BCD form: - * the least-significant nibble is the BCD bug fix revision, - * the most-significant nibble is the BCD minor revision number. - * - * (E.g. For a v2.1.0 profile this will return <code>0x10</code>) - */ - public int getMinorVersion() - { - return header.getMinorVersion(); - } - - /** - * Returns the device class of this profile, - * - * (E.g. CLASS_INPUT for a scanner profile, - * CLASS_OUTPUT for a printer) - */ - public int getProfileClass() - { - return header.getProfileClass(); - } - - /** - * Returns the color space of this profile, in terms - * of the color space constants defined in ColorSpace. - * (For example, it may be a ColorSpace.TYPE_RGB) - */ - public int getColorSpaceType() - { - return header.getColorSpace(); - } - - /** - * Returns the color space of this profile's Profile Connection Space (OCS) - * - * In terms of the color space constants defined in ColorSpace. - * This may be TYPE_XYZ or TYPE_Lab - */ - public int getPCSType() - { - return header.getProfileColorSpace(); - } - - /** - * Writes the profile data to an ICC profile file. - * @param filename - The name of the file to write - * @throws IOException if the write failed. - */ - public void write(String filename) throws IOException - { - FileOutputStream out = new FileOutputStream(filename); - write(out); - out.flush(); - out.close(); - } - - /** - * Writes the profile data in ICC profile file-format to a stream. - * This is useful for embedding ICC profiles in file formats which - * support this (such as JPEG and SVG). - * - * The stream is not closed after writing. - * @param out - The outputstream to which the profile data should be written - * @throws IOException if the write failed. - */ - public void write(OutputStream out) throws IOException - { - out.write(getData()); - } - - /** - * Returns the data corresponding to this ICC_Profile as a byte array. - * - * @return The data in a byte array, - * where the first element corresponds to first byte of the profile file. - */ - public byte[] getData() - { - byte[] data = new byte[pcmm.getProfileSize(profileID)]; - pcmm.getProfileData(profileID, data); - return data; - } - - /** - * Returns the ICC profile tag data - * The non ICC-tag icSigHead is also permitted to request the header data. - * - * @param tagSignature The ICC signature of the requested tag - * @return A byte array containing the tag data - */ - public byte[] getData(int tagSignature) - { - if (tagSignature == icSigHead) - return header.getData(getSize()); - - byte[] data = new byte[pcmm.getTagSize(profileID, tagSignature)]; - pcmm.getTagData(profileID, tagSignature, data); - return data; - } - - /** - * Sets the ICC profile tag data. - * - * Note that an ICC profile can only contain one tag of each type, if - * a tag already exists with the given signature, it is replaced. - * - * @param tagSignature - The signature of the tag to set - * @param data - A byte array containing the tag data - */ - public void setData(int tagSignature, byte[] data) - { - if (tagSignature == icSigHead) - header = new ProfileHeader(data); - - pcmm.setTagData(profileID, tagSignature, data); - } - - /** - * Get the number of components in the profile's device color space. - */ - public int getNumComponents() - { - int[] lookup = - { - ColorSpace.TYPE_RGB, 3, ColorSpace.TYPE_CMY, 3, - ColorSpace.TYPE_CMYK, 4, ColorSpace.TYPE_GRAY, 1, - ColorSpace.TYPE_YCbCr, 3, ColorSpace.TYPE_XYZ, 3, - ColorSpace.TYPE_Lab, 3, ColorSpace.TYPE_HSV, 3, - ColorSpace.TYPE_2CLR, 2, ColorSpace.TYPE_Luv, 3, - ColorSpace.TYPE_Yxy, 3, ColorSpace.TYPE_HLS, 3, - ColorSpace.TYPE_3CLR, 3, ColorSpace.TYPE_4CLR, 4, - ColorSpace.TYPE_5CLR, 5, ColorSpace.TYPE_6CLR, 6, - ColorSpace.TYPE_7CLR, 7, ColorSpace.TYPE_8CLR, 8, - ColorSpace.TYPE_9CLR, 9, ColorSpace.TYPE_ACLR, 10, - ColorSpace.TYPE_BCLR, 11, ColorSpace.TYPE_CCLR, 12, - ColorSpace.TYPE_DCLR, 13, ColorSpace.TYPE_ECLR, 14, - ColorSpace.TYPE_FCLR, 15 - }; - for (int i = 0; i < lookup.length; i += 2) - if (header.getColorSpace() == lookup[i]) - return lookup[i + 1]; - return 3; // should never happen. - } - - /** - * After deserializing we must determine if the class we want - * is really one of the more specialized ICC_ProfileRGB or - * ICC_ProfileGray classes. - */ - protected Object readResolve() throws ObjectStreamException - { - Hashtable tags = createTagTable(getData()); - - if (isRGBProfile(header, tags)) - return new ICC_ProfileRGB(getData()); - if (isGrayProfile(header, tags)) - return new ICC_ProfileGray(getData()); - return this; - } - - /** - * Deserializes an instance - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - String predef = (String) s.readObject(); - byte[] data = (byte[]) s.readObject(); - - if (data != null) - { - header = new ProfileHeader(data); - profileID = pcmm.loadProfile(data); - } - - if (predef != null) - { - predef = predef.intern(); - if (predef.equals("CS_sRGB")) - createProfile(ColorSpace.CS_sRGB); - if (predef.equals("CS_LINEAR_RGB")) - createProfile(ColorSpace.CS_LINEAR_RGB); - if (predef.equals("CS_CIEXYZ")) - createProfile(ColorSpace.CS_CIEXYZ); - if (predef.equals("CS_GRAY")) - createProfile(ColorSpace.CS_GRAY); - if (predef.equals("CS_PYCC")) - createProfile(ColorSpace.CS_PYCC); - } - } - - /** - * Sorts a ICC profile byte array into TagEntry objects stored in - * a hash table. - */ - private static Hashtable createTagTable(byte[] data) - throws IllegalArgumentException - { - ByteBuffer buf = ByteBuffer.wrap(data); - int nTags = buf.getInt(tagTableOffset); - - Hashtable tagTable = new Hashtable(); - for (int i = 0; i < nTags; i++) - { - TagEntry te = new TagEntry(buf.getInt(tagTableOffset - + i * TagEntry.entrySize + 4), - buf.getInt(tagTableOffset - + i * TagEntry.entrySize + 8), - buf.getInt(tagTableOffset - + i * TagEntry.entrySize + 12), - data); - - if (tagTable.put(te.hashKey(), te) != null) - throw new IllegalArgumentException("Duplicate tag in profile:" + te); - } - return tagTable; - } - - /** - * Serializes an instance - * The format is a String and a byte array, - * The string is non-null if the instance is one of the built-in profiles. - * Otherwise the byte array is non-null and represents the profile data. - */ - private void writeObject(ObjectOutputStream s) throws IOException - { - s.defaultWriteObject(); - - int colorSpaceID = getColorSpaceType(); - if (colorSpaceID == ColorSpace.CS_sRGB) - s.writeObject("CS_sRGB"); - else if (colorSpaceID == ColorSpace.CS_LINEAR_RGB) - s.writeObject("CS_LINEAR_RGB"); - else if (colorSpaceID == ColorSpace.CS_CIEXYZ) - s.writeObject("CS_CIEXYZ"); - else if (colorSpaceID == ColorSpace.CS_GRAY) - s.writeObject("CS_GRAY"); - else if (colorSpaceID == ColorSpace.CS_PYCC) - s.writeObject("CS_PYCC"); - else - { - s.writeObject(null); // null string - s.writeObject(getData()); // data - return; - } - s.writeObject(null); // null data - } - - /** - * Returns the total size of the padded, stored data - * Note: Tags must be stored on 4-byte aligned offsets. - */ - private int getSize() - { - return pcmm.getProfileSize(profileID); - } - - /** - * Returns if the criteria for an ICC_ProfileRGB are met. - * This means: - * Color space is TYPE_RGB - * (r,g,b)ColorantTags included - * (r,g,b)TRCTags included - * mediaWhitePointTag included - */ - private static boolean isRGBProfile(ProfileHeader header, Hashtable tags) - { - if (header.getColorSpace() != ColorSpace.TYPE_RGB) - return false; - if (tags.get(TagEntry.tagHashKey(icSigRedColorantTag)) == null) - return false; - if (tags.get(TagEntry.tagHashKey(icSigGreenColorantTag)) == null) - return false; - if (tags.get(TagEntry.tagHashKey(icSigBlueColorantTag)) == null) - return false; - if (tags.get(TagEntry.tagHashKey(icSigRedTRCTag)) == null) - return false; - if (tags.get(TagEntry.tagHashKey(icSigGreenTRCTag)) == null) - return false; - if (tags.get(TagEntry.tagHashKey(icSigBlueTRCTag)) == null) - return false; - return (tags.get(TagEntry.tagHashKey(icSigMediaWhitePointTag)) != null); - } - - /** - * Returns if the criteria for an ICC_ProfileGray are met. - * This means: - * Colorspace is TYPE_GRAY - * grayTRCTag included - * mediaWhitePointTag included - */ - private static boolean isGrayProfile(ProfileHeader header, Hashtable tags) - { - if (header.getColorSpace() != ColorSpace.TYPE_GRAY) - return false; - if (tags.get(TagEntry.tagHashKey(icSigGrayTRCTag)) == null) - return false; - return (tags.get(TagEntry.tagHashKey(icSigMediaWhitePointTag)) != null); - } - - /** - * Returns curve data for a 'curv'-type tag - * If it's a gamma curve, a single entry will be returned with the - * gamma value (including 1.0 for linear response) - * Otherwise the TRC table is returned. - * - * (Package private - used by ICC_ProfileRGB and ICC_ProfileGray) - */ - short[] getCurve(int signature) - { - byte[] data = getData(signature); - short[] curve; - - // can't find tag? - if (data == null) - return null; - - // not an curve type tag? - ByteBuffer buf = ByteBuffer.wrap(data); - if (buf.getInt(0) != 0x63757276) // 'curv' type - return null; - int count = buf.getInt(8); - if (count == 0) - { - curve = new short[1]; - curve[0] = 0x0100; // 1.00 in u8fixed8 - return curve; - } - if (count == 1) - { - curve = new short[1]; - curve[0] = buf.getShort(12); // other u8fixed8 gamma - return curve; - } - curve = new short[count]; - for (int i = 0; i < count; i++) - curve[i] = buf.getShort(12 + i * 2); - return curve; - } - - /** - * Returns XYZ tristimulus values for an 'XYZ ' type tag - * @return the XYZ values, or null if the tag was not an 'XYZ ' type tag. - * - * (Package private - used by ICC_ProfileXYZ and ICC_ProfileGray) - */ - float[] getXYZData(int signature) - { - byte[] data = getData(signature); - - // can't find tag? - if (data == null) - return null; - - // not an XYZData type tag? - ByteBuffer buf = ByteBuffer.wrap(data); - if (buf.getInt(0) != icSigXYZData) // 'XYZ ' type - return null; - - float[] point = new float[3]; - - // get the X,Y,Z tristimulus values - point[0] = ((float) buf.getInt(8)) / 65536f; - point[1] = ((float) buf.getInt(12)) / 65536f; - point[2] = ((float) buf.getInt(16)) / 65536f; - return point; - } - - /** - * Returns the profile ID if it's a predefined profile - * Or -1 for a profile loaded from an ICC profile - * - * (Package private - used by ICC_ColorSpace) - */ - int isPredefined() - { - return colorSpace; - } - - /** - * Creates a tag of XYZ-value type. - */ - private byte[] makeXYZData(float[] values) - { - ByteBuffer buf = ByteBuffer.allocate(20); - buf.putInt(0, icSigXYZData); // 'XYZ ' - buf.putInt(4, 0); - buf.putInt(8, (int) (values[0] * 65536.0)); - buf.putInt(12, (int) (values[1] * 65536.0)); - buf.putInt(16, (int) (values[2] * 65536.0)); - return buf.array(); - } - - /** - * Creates a tag of text type - */ - private byte[] makeTextTag(String text) - { - int length = text.length(); - ByteBuffer buf = ByteBuffer.allocate(8 + length + 1); - byte[] data; - try - { - data = text.getBytes("US-ASCII"); - } - catch (UnsupportedEncodingException e) - { - data = new byte[length]; // shouldn't happen - } - - buf.putInt(0, (int) 0x74657874); // 'text' - buf.putInt(4, 0); - for (int i = 0; i < length; i++) - buf.put(8 + i, data[i]); - buf.put(8 + length, (byte) 0); // null-terminate - return buf.array(); - } - - /** - * Creates a tag of textDescriptionType - */ - private byte[] makeDescTag(String text) - { - int length = text.length(); - ByteBuffer buf = ByteBuffer.allocate(90 + length + 1); - buf.putInt(0, (int) 0x64657363); // 'desc' - buf.putInt(4, 0); // reserved - buf.putInt(8, length + 1); // ASCII length, including null termination - byte[] data; - - try - { - data = text.getBytes("US-ASCII"); - } - catch (UnsupportedEncodingException e) - { - data = new byte[length]; // shouldn't happen - } - - for (int i = 0; i < length; i++) - buf.put(12 + i, data[i]); - buf.put(12 + length, (byte) 0); // null-terminate - - for (int i = 0; i < 39; i++) - buf.putShort(13 + length + (i * 2), (short) 0); // 78 bytes we can ignore - - return buf.array(); - } - - /** - * Creates a tag of TRC type (linear curve) - */ - private byte[] makeTRC() - { - ByteBuffer buf = ByteBuffer.allocate(12); - buf.putInt(0, 0x63757276); // 'curv' type - buf.putInt(4, 0); // reserved - buf.putInt(8, 0); - return buf.array(); - } - - /** - * Creates a tag of TRC type (single gamma value) - */ - private byte[] makeTRC(float gamma) - { - short gammaValue = (short) (gamma * 256f); - ByteBuffer buf = ByteBuffer.allocate(14); - buf.putInt(0, 0x63757276); // 'curv' type - buf.putInt(4, 0); // reserved - buf.putInt(8, 1); - buf.putShort(12, gammaValue); // 1.00 in u8fixed8 - return buf.array(); - } - - /** - * Creates a tag of TRC type (TRC curve points) - */ - private byte[] makeTRC(float[] trc) - { - ByteBuffer buf = ByteBuffer.allocate(12 + 2 * trc.length); - buf.putInt(0, 0x63757276); // 'curv' type - buf.putInt(4, 0); // reserved - buf.putInt(8, trc.length); // number of points - - // put the curve values - for (int i = 0; i < trc.length; i++) - buf.putShort(12 + i * 2, (short) (trc[i] * 65535f)); - - return buf.array(); - } - - /** - * Creates an identity color lookup table. - */ - private byte[] makeIdentityClut() - { - final int nIn = 3; - final int nOut = 3; - final int nInEntries = 256; - final int nOutEntries = 256; - final int gridpoints = 16; - - // gridpoints**nIn - final int clutSize = 2 * nOut * gridpoints * gridpoints * gridpoints; - final int totalSize = clutSize + 2 * nInEntries * nIn - + 2 * nOutEntries * nOut + 52; - - ByteBuffer buf = ByteBuffer.allocate(totalSize); - buf.putInt(0, 0x6D667432); // 'mft2' - buf.putInt(4, 0); // reserved - buf.put(8, (byte) nIn); // number input channels - buf.put(9, (byte) nOut); // number output channels - buf.put(10, (byte) gridpoints); // number gridpoints - buf.put(11, (byte) 0); // padding - - // identity matrix - buf.putInt(12, 65536); // = 1 in s15.16 fixed point - buf.putInt(16, 0); - buf.putInt(20, 0); - buf.putInt(24, 0); - buf.putInt(28, 65536); - buf.putInt(32, 0); - buf.putInt(36, 0); - buf.putInt(40, 0); - buf.putInt(44, 65536); - - buf.putShort(48, (short) nInEntries); // input table entries - buf.putShort(50, (short) nOutEntries); // output table entries - - // write the linear input channels, unsigned 16.16 fixed point, - // from 0.0 to FF.FF - for (int channel = 0; channel < 3; channel++) - for (int i = 0; i < nInEntries; i++) - { - short n = (short) ((i << 8) | i); // assumes 256 entries - buf.putShort(52 + (channel * nInEntries + i) * 2, n); - } - int clutOffset = 52 + nInEntries * nIn * 2; - - for (int x = 0; x < gridpoints; x++) - for (int y = 0; y < gridpoints; y++) - for (int z = 0; z < gridpoints; z++) - { - int offset = clutOffset + z * 2 * nOut + y * gridpoints * 2 * nOut - + x * gridpoints * gridpoints * 2 * nOut; - double xf = ((double) x) / ((double) gridpoints - 1.0); - double yf = ((double) y) / ((double) gridpoints - 1.0); - double zf = ((double) z) / ((double) gridpoints - 1.0); - buf.putShort(offset, (short) (xf * 65535.0)); - buf.putShort(offset + 2, (short) (yf * 65535.0)); - buf.putShort(offset + 4, (short) (zf * 65535.0)); - } - - for (int channel = 0; channel < 3; channel++) - for (int i = 0; i < nOutEntries; i++) - { - short n = (short) ((i << 8) | i); // assumes 256 entries - buf.putShort(clutOffset + clutSize + (channel * nOutEntries + i) * 2, - n); - } - - return buf.array(); - } - - /** - * Creates profile data corresponding to the built-in colorspaces. - */ - private void createProfile(int colorSpace) throws IllegalArgumentException - { - header = new ProfileHeader(); - - switch (colorSpace) - { - case ColorSpace.CS_sRGB: - createRGBProfile(); - return; - case ColorSpace.CS_LINEAR_RGB: - createLinearRGBProfile(); - return; - case ColorSpace.CS_CIEXYZ: - createCIEProfile(); - return; - case ColorSpace.CS_GRAY: - createGrayProfile(); - return; - case ColorSpace.CS_PYCC: - createPyccProfile(); - return; - default: - throw new IllegalArgumentException("Not a predefined color space!"); - } - } - - /** - * Creates an ICC_Profile representing the sRGB color space - */ - private void createRGBProfile() - { - header.setColorSpace( ColorSpace.TYPE_RGB ); - header.setProfileColorSpace( ColorSpace.TYPE_XYZ ); - ICC_ColorSpace cs = new ICC_ColorSpace(this); - - float[] r = { 1f, 0f, 0f }; - float[] g = { 0f, 1f, 0f }; - float[] b = { 0f, 0f, 1f }; - float[] black = { 0f, 0f, 0f }; - - // CIE 1931 D50 white point (in Lab coordinates) - float[] white = D50; - - // Get tristimulus values (matrix elements) - r = cs.toCIEXYZ(r); - g = cs.toCIEXYZ(g); - b = cs.toCIEXYZ(b); - - // Generate the sRGB TRC curve, this is the linear->nonlinear - // RGB transform. - cs = new ICC_ColorSpace(getInstance(ICC_ColorSpace.CS_LINEAR_RGB)); - float[] points = new float[TRC_POINTS]; - float[] in = new float[3]; - for (int i = 0; i < TRC_POINTS; i++) - { - in[0] = in[1] = in[2] = ((float) i) / ((float) TRC_POINTS - 1); - in = cs.fromRGB(in); - // Note this value is the same for all components. - points[i] = in[0]; - } - - Hashtable<String, TagEntry> tags = new Hashtable<String, TagEntry>(); - - TagEntry t = new TagEntry(icSigRedColorantTag, makeXYZData(r)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigGreenColorantTag, makeXYZData(g)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigBlueColorantTag, makeXYZData(b)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigMediaWhitePointTag, makeXYZData(white)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigMediaBlackPointTag, makeXYZData(black)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigRedTRCTag, makeTRC(points)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigGreenTRCTag, makeTRC(points)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigBlueTRCTag, makeTRC(points)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigCopyrightTag, makeTextTag(copyrightNotice)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigProfileDescriptionTag, makeDescTag("Generic sRGB")); - tags.put(t.hashKey(), t); - - profileID = pcmm.loadProfile(getDataFromTags(header, tags)); - } - - /** - * Creates an linear sRGB profile - */ - private void createLinearRGBProfile() - { - header.setColorSpace(ColorSpace.TYPE_RGB); - header.setProfileColorSpace(ColorSpace.TYPE_XYZ); - ICC_ColorSpace cs = new ICC_ColorSpace(this); - - float[] r = { 1f, 0f, 0f }; - float[] g = { 0f, 1f, 0f }; - float[] b = { 0f, 0f, 1f }; - float[] black = { 0f, 0f, 0f }; - - float[] white = D50; - - // Get tristimulus values (matrix elements) - r = cs.toCIEXYZ(r); - g = cs.toCIEXYZ(g); - b = cs.toCIEXYZ(b); - - Hashtable<String, TagEntry> tags = new Hashtable<String, TagEntry>(); - - TagEntry t = new TagEntry(icSigRedColorantTag, makeXYZData(r)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigGreenColorantTag, makeXYZData(g)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigBlueColorantTag, makeXYZData(b)); - tags.put(t.hashKey(), t); - - t = new TagEntry(icSigMediaWhitePointTag, makeXYZData(white)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigMediaBlackPointTag, makeXYZData(black)); - tags.put(t.hashKey(), t); - - t = new TagEntry(icSigRedTRCTag, makeTRC()); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigGreenTRCTag, makeTRC()); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigBlueTRCTag, makeTRC()); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigCopyrightTag, makeTextTag(copyrightNotice)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigProfileDescriptionTag, makeDescTag("Linear RGB")); - tags.put(t.hashKey(), t); - - profileID = pcmm.loadProfile(getDataFromTags(header, tags)); - } - - /** - * Creates an CIE XYZ identity profile - */ - private void createCIEProfile() - { - header.setColorSpace( ColorSpace.TYPE_XYZ ); - header.setProfileColorSpace( ColorSpace.TYPE_XYZ ); - header.setProfileClass( CLASS_COLORSPACECONVERSION ); - ICC_ColorSpace cs = new ICC_ColorSpace(this); - - float[] white = D50; - - Hashtable<String, TagEntry> tags = new Hashtable<String, TagEntry>(); - - TagEntry t = new TagEntry(icSigMediaWhitePointTag, makeXYZData(white)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigAToB0Tag, makeIdentityClut()); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigBToA0Tag, makeIdentityClut()); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigCopyrightTag, makeTextTag(copyrightNotice)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigProfileDescriptionTag, makeDescTag("CIE XYZ identity profile")); - tags.put(t.hashKey(), t); - - profileID = pcmm.loadProfile(getDataFromTags(header, tags)); - } - - /** - * Creates a linear gray ICC_Profile - */ - private void createGrayProfile() - { - header.setColorSpace(ColorSpace.TYPE_GRAY); - header.setProfileColorSpace(ColorSpace.TYPE_XYZ); - - // CIE 1931 D50 white point (in Lab coordinates) - float[] white = D50; - - Hashtable<String, TagEntry> tags = new Hashtable<String, TagEntry>(); - - TagEntry t = new TagEntry(icSigMediaWhitePointTag, makeXYZData(white)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigGrayTRCTag, makeTRC(1.0f)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigCopyrightTag, makeTextTag(copyrightNotice)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigProfileDescriptionTag, makeDescTag("Linear grayscale")); - tags.put(t.hashKey(), t); - - profileID = pcmm.loadProfile(getDataFromTags(header, tags)); - } - - /** - * XXX Implement me - */ - private void createPyccProfile() - { - header.setColorSpace(ColorSpace.TYPE_3CLR); - header.setProfileColorSpace(ColorSpace.TYPE_XYZ); - - // Create CLUTs here. :-) - - Hashtable<String, TagEntry> tags = new Hashtable<String, TagEntry>(); - - TagEntry t = new TagEntry(icSigCopyrightTag, makeTextTag(copyrightNotice)); - tags.put(t.hashKey(), t); - t = new TagEntry(icSigProfileDescriptionTag, makeDescTag("Photo YCC")); - tags.put(t.hashKey(), t); - - profileID = pcmm.loadProfile(getDataFromTags(header, tags)); - } - - /** - * Creates a byte buffer of ICC data from a given header and tags. - */ - private static byte[] getDataFromTags(ProfileHeader header, Hashtable<String, TagEntry> tags) - { - // First calculate size of buffer - int size = ProfileHeader.HEADERSIZE; // size of header - - int tagTableSize = 4 + tags.size() * TagEntry.entrySize; // size of tag table - if ((tagTableSize & 0x0003) != 0) - tagTableSize += 4 - (tagTableSize & 0x0003); // pad - size += tagTableSize; - - // Also convert tag hashtable to bytes while we're iterating through it - int offset = 4; - int tagOffset = ProfileHeader.HEADERSIZE + tagTableSize; - ByteBuffer tt = ByteBuffer.allocate(tagTableSize); - tt.putInt(tags.size()); // number of tags - - Enumeration<TagEntry> e = tags.elements(); - while (e.hasMoreElements()) - { - TagEntry tag = e.nextElement(); - int tagSize = tag.getSize(); - if ((tagSize & 0x0003) != 0) - tagSize += 4 - (tagSize & 0x0003); // pad - size += tagSize; - - tt.putInt(offset, tag.getSignature()); - tt.putInt(offset + 4, tagOffset); - tt.putInt(offset + 8, tag.getSize()); - tag.setOffset(tagOffset); - tagOffset += tagSize; - offset += 12; - } - - byte[] data = new byte[size]; - - // Copy header & tags into buffer - System.arraycopy(header.getData(size), 0, data, 0, ProfileHeader.HEADERSIZE); - - if (tt.hasArray()) - { - System.arraycopy(tt.array(), 0, data, ProfileHeader.HEADERSIZE, tt.array().length); - } - else - { - tt.rewind(); - tt.get(data, ProfileHeader.HEADERSIZE, tt.remaining()); - } - - e = tags.elements(); - while (e.hasMoreElements()) - { - TagEntry tag = e.nextElement(); - System.arraycopy(tag.getData(), 0, - data, tag.getOffset(), tag.getSize()); - } - return data; - } - -} // class ICC_Profile
--- a/rt/java/awt/color/ICC_ProfileGray.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,133 +0,0 @@ -/* ICC_ProfileGray.java -- the ICC profile for a Gray colorspace - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.color; - -/** - * ICC_ProfileGray - a special case of ICC_Profiles. - * - * The ICC_Profile.getInstance() method will return an instance of the - * ICC_ProfileGray subclass when all the following conditions are met: - * The device color space of the profile is TYPE_GRAY. - * The profile contains a gray TRCTag. - * The profile contains a mediaWhitePointTag. - * - * As per the ICC specification, the color space conversion can then - * be done through the following method: - * linearGray = grayTRC[deviceGray] - * - * Note that if the profile contains a CLUT for the color space conversion, - * it should be used instead, and the TRC information ignored. - * - * @author Sven de Marothy - * @since 1.2 - */ -public class ICC_ProfileGray extends ICC_Profile -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -1124721290732002649L; - private transient float[] whitePoint; - - /** - * Package-private constructor used by ICC_ColorSpace for creating an - * ICC_ProfileGray from a predefined ColorSpace (CS_GRAY) - */ - ICC_ProfileGray(int cspace) - { - super(cspace); - whitePoint = getXYZData(icSigMediaWhitePointTag); - } - - /** - * Package-private constructor used by ICC_ColorSpace for creating an - * ICC_ProfileGray from profile data. - */ - ICC_ProfileGray(byte[] data) - { - super(data); - whitePoint = getXYZData(icSigMediaWhitePointTag); - } - - - /** - * Returns the media white point of the profile. - */ - public float[] getMediaWhitePoint() - { - float[] wp = new float[3]; - wp[0] = whitePoint[0]; - wp[1] = whitePoint[1]; - wp[2] = whitePoint[2]; - return wp; - } - - /** - * Returns the TRC gamma value. - * @throws ProfileDataException if the TRC is described by a lookup - * table and not a gamma value. - */ - public float getGamma() - { - short[] data = getCurve(icSigGrayTRCTag); - if (data == null) - throw new IllegalArgumentException("Couldn't read Gray TRC data."); - if (data.length != 1) - throw new ProfileDataException("TRC is a table, not a gamma value."); - - // convert the unsigned 7.8 fixed-point gamma to a float. - double gamma = (double) (data[0] & (0xFFFF)) / 256.0; - return (float) gamma; - } - - /** - * Returns the TRC lookup table. - * @throws ProfileDataException if the TRC is described by a gamma value - * and not a lookup table. - */ - public short[] getTRC() - { - short[] data = getCurve(icSigGrayTRCTag); - if (data == null) - throw new IllegalArgumentException("Couldn't read Gray TRC data."); - if (data.length <= 1) - throw new ProfileDataException("Gamma value, not a TRC table."); - return data; - } -} // class ICC_ProfileGray
--- a/rt/java/awt/color/ICC_ProfileRGB.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,227 +0,0 @@ -/* ICC_ProfileRGB.java -- the ICC profile for a RGB colorspace - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.color; - -/** - * ICC_ProfileRGB - a special case of ICC_Profiles. - * - * The ICC_Profile.getInstance() method will return an instance of the - * ICC_ProfileRGB subclass when all the following conditions are met: - * The device color space of the profile is TYPE_RGB. - * The profile contains red, green and blue ColorantTags. - * The profile contains red, green and blue TRCTags. - * The profile contains a mediaWhitePointTag included. - * - * As per the ICC specification, the color space conversion can then - * be done through the following method: - * linearR = redTRC[deviceR] - * linearG = greenTRC[deviceG] - * linearB = blueTRC[deviceB] - * TRC curves are either a single gamma value, or a 1-dimensional lookup table. - * - * Followed by the matrix transform: - * PCS = M*linear - * - * Where PCS is the vector of profile color space (must be XYZ) coordinates, - * linear is the vector of linear RGB coordinates, and the matrix M is - * constructed from the ColorantTags, where the columns are red, green and - * blue respectively, and the rows are X, Y and Z. - * - * Note that if the profile contains a CLUT for the color space conversion, - * it should be used instead, and the TRC information ignored. - * - * @author Sven de Marothy - * @since 1.2 - */ -public class ICC_ProfileRGB extends ICC_Profile -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 8505067385152579334L; - - public static final int REDCOMPONENT = 0; - - public static final int GREENCOMPONENT = 1; - - public static final int BLUECOMPONENT = 2; - - private transient float[][] matrix; - - private transient float[] gamma; - - private transient float[] whitePoint; - - - /** - * Package-private constructor used by ICC_ColorSpace for creating an - * ICC_ProfileRGB from a predefined ColorSpace (CS_LINEAR_RGB and CS_sRGB) - */ - ICC_ProfileRGB(int cspace) - { - super(cspace); - matrix = createMatrix(); - whitePoint = getXYZData(icSigMediaWhitePointTag); - } - - /** - * Package-private constructor used by ICC_ColorSpace for creating an - * ICC_ProfileRGB from profile data. - */ - ICC_ProfileRGB(byte[] data) - { - super(data); - matrix = createMatrix(); - whitePoint = getXYZData(icSigMediaWhitePointTag); - } - - /** - * Returns the media white point of the profile. - */ - public float[] getMediaWhitePoint() - { - float[] wp = new float[3]; - wp[0] = whitePoint[0]; - wp[1] = whitePoint[1]; - wp[2] = whitePoint[2]; - return wp; - } - - /** - * Returns the colorant matrix of the conversion. - */ - public float[][] getMatrix() - { - float[][] mat = new float[3][3]; - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - mat[i][j] = matrix[i][j]; - return mat; - } - - /** - * Returns the gamma value of a component - * @throws ProfileDataException if the TRC is described by a lookup - * table and not a gamma value. - */ - public float getGamma(int component) - { - short[] data; - switch (component) - { - case REDCOMPONENT: - data = getCurve(icSigRedTRCTag); - break; - case GREENCOMPONENT: - data = getCurve(icSigGreenTRCTag); - break; - case BLUECOMPONENT: - data = getCurve(icSigBlueTRCTag); - break; - default: - throw new IllegalArgumentException("Not a valid component"); - } - if (data == null) - throw new IllegalArgumentException("Error reading TRC"); - - if (data.length != 1) - throw new ProfileDataException("Not a single-gamma TRC"); - - // convert the unsigned 7.8 fixed-point gamma to a float. - float gamma = (float) (((int) data[0] & 0xFF00) >> 8); - double fraction = ((int) data[0] & 0x00FF) / 256.0; - gamma += (float) fraction; - return gamma; - } - - /** - * Returns the TRC lookup table for a component - * @throws ProfileDataException if the TRC is described by a gamma - * value and not a lookup table. - */ - public short[] getTRC(int component) - { - short[] data; - switch (component) - { - case REDCOMPONENT: - data = getCurve(icSigRedTRCTag); - break; - case GREENCOMPONENT: - data = getCurve(icSigGreenTRCTag); - break; - case BLUECOMPONENT: - data = getCurve(icSigBlueTRCTag); - break; - default: - throw new IllegalArgumentException("Not a valid component"); - } - if (data == null) - throw new IllegalArgumentException("Error reading TRC"); - - if (data.length <= 1) - throw new ProfileDataException("Gamma value, not a TRC table."); - - return data; - } - - /** - * Creates the colorspace conversion matrix from the RGB tristimulus - * values. - */ - private float[][] createMatrix() throws IllegalArgumentException - { - float[][] mat = new float[3][3]; - float[] r; - float[] g; - float[] b; - r = getXYZData(icSigRedColorantTag); - g = getXYZData(icSigGreenColorantTag); - b = getXYZData(icSigBlueColorantTag); - if (r == null || g == null || b == null) - throw new IllegalArgumentException("Error reading colorant tags!"); - for (int i = 0; i < 3; i++) - { - mat[i][0] = r[i]; - mat[i][1] = g[i]; - mat[i][2] = b[i]; - } - return mat; - } -} // class ICC_ProfileRGB
--- a/rt/java/awt/image/BandedSampleModel.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,758 +0,0 @@ -/* Copyright (C) 2004, 2005, 2006, Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -import gnu.java.awt.Buffers; - -/** - * A sample model that reads each sample value from a separate band in the - * {@link DataBuffer}. - * - * @author Jerry Quinn (jlquinn@optonline.net) - */ -public final class BandedSampleModel extends ComponentSampleModel -{ - private int[] bitMasks; - private int[] bitOffsets; - private int[] sampleSize; - private int dataBitOffset; - private int elemBits; - private int numberOfBits; - private int numElems; - - private static int[] createBankArray(int size) - { - int[] result = new int[size]; - for (int i = 0; i < size; i++) - result[i] = i; - return result; - } - - /** - * Creates a new <code>BandedSampleModel</code>. - * - * @param dataType the data buffer type. - * @param w the width (in pixels). - * @param h the height (in pixels). - * @param numBands the number of bands. - */ - public BandedSampleModel(int dataType, int w, int h, int numBands) - { - this(dataType, w, h, w, createBankArray(numBands), new int[numBands]); - } - - /** - * Creates a new <code>BandedSampleModel</code>. - * - * @param dataType the data buffer type. - * @param w the width (in pixels). - * @param h the height (in pixels). - * @param scanlineStride the number of data elements from a pixel in one - * row to the corresponding pixel in the next row. - * @param bankIndices the bank indices. - * @param bandOffsets the band offsets. - */ - public BandedSampleModel(int dataType, int w, int h, int scanlineStride, - int[] bankIndices, int[] bandOffsets) - { - super(dataType, w, h, 1, scanlineStride, bankIndices, bandOffsets); - } - - /** - * Creates a new data buffer that is compatible with this sample model. - * - * @return The new data buffer. - */ - public DataBuffer createDataBuffer() - { - int size = scanlineStride * height; - return Buffers.createBuffer(getDataType(), size, numBanks); - } - - /** - * Creates a new <code>SampleModel</code> that is compatible with this - * model and has the specified width and height. - * - * @param w the width (in pixels, must be greater than zero). - * @param h the height (in pixels, must be greater than zero). - * - * @return The new sample model. - * - * @throws IllegalArgumentException if <code>w</code> or <code>h</code> is - * not greater than zero. - * @throws IllegalArgumentException if <code>w * h</code> exceeds - * <code>Integer.MAX_VALUE</code>. - */ - public SampleModel createCompatibleSampleModel(int w, int h) - { - // NOTE: blackdown 1.4.1 sets all offsets to 0. Sun's 1.4.2 docs - // disagree. - - // Compress offsets so minimum is 0, others w*scanlineStride - int[] newoffsets = new int[bandOffsets.length]; - int[] order = new int[bandOffsets.length]; - for (int i = 0; i < bandOffsets.length; i++) - order[i] = i; - // FIXME: This is N^2, but not a big issue, unless there's a lot of - // bands... - for (int i = 0; i < bandOffsets.length; i++) - for (int j = i + 1; j < bandOffsets.length; j++) - if (bankIndices[order[i]] > bankIndices[order[j]] - || (bankIndices[order[i]] == bankIndices[order[j]] - && bandOffsets[order[i]] > bandOffsets[order[j]])) - { - int t = order[i]; order[i] = order[j]; order[j] = t; - } - int bank = 0; - int offset = 0; - for (int i = 0; i < bandOffsets.length; i++) - { - if (bankIndices[order[i]] != bank) - { - bank = bankIndices[order[i]]; - offset = 0; - } - newoffsets[order[i]] = offset; - offset += w * scanlineStride; - } - - return new BandedSampleModel(dataType, w, h, w, bankIndices, newoffsets); - } - - - public SampleModel createSubsetSampleModel(int[] bands) - { - if (bands.length > bankIndices.length) - throw new - RasterFormatException("BandedSampleModel createSubsetSampleModel too" - +" many bands"); - int[] newoff = new int[bands.length]; - int[] newbanks = new int[bands.length]; - for (int i = 0; i < bands.length; i++) - { - int b = bands[i]; - newoff[i] = bandOffsets[b]; - newbanks[i] = bankIndices[b]; - } - - return new BandedSampleModel(dataType, width, height, scanlineStride, - newbanks, newoff); - } - - /** - * Extract all samples of one pixel and return in an array of transfer type. - * - * Extracts the pixel at x, y from data and stores samples into the array - * obj. If obj is null, a new array of getTransferType() is created. - * - * @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 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, - * java.lang.Object, java.awt.image.DataBuffer) - */ - public Object getDataElements(int x, int y, Object obj, DataBuffer data) - { - if (x < 0 || y < 0) - throw new ArrayIndexOutOfBoundsException( - "x and y must not be less than 0."); - int pixel = getSample(x, y, 0, data); - switch (getTransferType()) - { - case DataBuffer.TYPE_BYTE: - { - byte[] b = (byte[]) obj; - if (b == null) b = new byte[numBands]; - for (int i = 0; i < numBands; i++) - b[i] = (byte)getSample(x, y, i, data); - return b; - } - case DataBuffer.TYPE_SHORT: - case DataBuffer.TYPE_USHORT: - { - short[] b = (short[]) obj; - if (b == null) b = new short[numBands]; - for (int i = 0; i < numBands; i++) - b[i] = (short)getSample(x, y, i, data); - return b; - } - case DataBuffer.TYPE_INT: - { - int[] b = (int[]) obj; - if (b == null) b = new int[numBands]; - for (int i = 0; i < numBands; i++) - b[i] = getSample(x, y, i, data); - return b; - } - case DataBuffer.TYPE_FLOAT: - { - float[] b = (float[]) obj; - if (b == null) b = new float[numBands]; - for (int i = 0; i < numBands; i++) - b[i] = getSampleFloat(x, y, i, data); - return b; - } - case DataBuffer.TYPE_DOUBLE: - { - double[] b = (double[]) obj; - if (b == null) - b = new double[numBands]; - for (int i = 0; i < numBands; i++) - b[i] = getSample(x, y, i, data); - return b; - } - - default: - // Seems like the only sensible thing to do. - throw new ClassCastException(); - } - } - - /** - * Returns all the samples for the pixel at location <code>(x, y)</code> - * stored in the specified data buffer. - * - * @param x the x-coordinate. - * @param y the y-coordinate. - * @param iArray an array that will be populated with the sample values and - * returned as the result. The size of this array should be equal to the - * number of bands in the model. If the array is <code>null</code>, a new - * array is created. - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The samples for the specified pixel. - * - * @see #setPixel(int, int, int[], DataBuffer) - */ - public int[] getPixel(int x, int y, int[] iArray, DataBuffer data) - { - if (iArray == null) - iArray = new int[numBands]; - for (int i = 0; i < numBands; i++) - iArray[i] = getSample(x, y, i, data); - - return iArray; - } - - /** - * Copy pixels from a region into an array. - * - * Copies the samples of the pixels in the rectangle starting at x, y that - * is w pixels wide and h scanlines high. When there is more than one band, - * the samples stored in order before the next pixel. This ordering isn't - * well specified in Sun's docs as of 1.4.2. - * - * If iArray is null, a new array is allocated, filled, and returned. - * - * @param x The x-coordinate of the pixel rectangle to store in - * <code>iArray</code>. - * @param y The y-coordinate of the pixel rectangle to store in - * <code>iArray</code>. - * @param w The width in pixels of the rectangle. - * @param h The height in pixels of the rectangle. - * @param iArray The int 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. - */ - public int[] getPixels(int x, int y, int w, int h, int[] iArray, - DataBuffer data) - { - if (x < 0 || y < 0) - throw new ArrayIndexOutOfBoundsException( - "x and y must not be less than 0."); - if (iArray == null) - iArray = new int[w * h * numBands]; - int outOffset = 0; - int maxX = x + w; - int maxY = y + h; - for (int yy = x; yy < maxY; yy++) - { - for (int xx = x; xx < maxX; xx++) - { - for (int b = 0; b < numBands; b++) - { - int offset = bandOffsets[b] + yy * scanlineStride + xx; - iArray[outOffset++] = - data.getElem(bankIndices[b], offset); - } - } - } - return iArray; - } - - /** - * Returns a sample value for the pixel at (x, y) in the specified data - * buffer. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The sample value. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public int getSample(int x, int y, int b, DataBuffer data) - { - int offset = bandOffsets[b] + y * scanlineStride + x; - return data.getElem(bankIndices[b], offset); - } - - /** - * Returns a sample value for the pixel at (x, y) in the specified data - * buffer. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The sample value. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - * - * @see #getSample(int, int, int, DataBuffer) - */ - public float getSampleFloat(int x, int y, int b, DataBuffer data) - { - int offset = bandOffsets[b] + y * scanlineStride + x; - return data.getElemFloat(bankIndices[b], offset); - } - - /** - * Returns the sample value for the pixel at (x, y) in the specified data - * buffer. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The sample value. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - * - * @see #getSample(int, int, int, DataBuffer) - */ - public double getSampleDouble(int x, int y, int b, DataBuffer data) - { - int offset = bandOffsets[b] + y * scanlineStride + x; - return data.getElemDouble(bankIndices[b], offset); - } - - /** - * Copy one band's samples from a region into an array. - * - * Copies from one band the samples of the pixels in the rectangle starting - * at x, y that is w pixels wide and h scanlines high. - * - * If iArray is null, a new array is allocated, filled, and returned. - * - * @param x The x-coordinate of the pixel rectangle to store in - * <code>iArray</code>. - * @param y The y-coordinate of the pixel rectangle to store in - * <code>iArray</code>. - * @param w The width in pixels of the rectangle. - * @param h The height in pixels of the rectangle. - * @param b The band to retrieve. - * @param iArray The int 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. - */ - public int[] getSamples(int x, int y, int w, int h, int b, int[] iArray, - DataBuffer data) - { - if (x < 0 || y < 0) - throw new ArrayIndexOutOfBoundsException( - "x and y must not be less than 0."); - if (iArray == null) - iArray = new int[w * h]; - int outOffset = 0; - int maxX = x + w; - int maxY = y + h; - for (int yy = y; yy < maxY; yy++) - { - for (int xx = x; xx < maxX; xx++) - { - int offset = bandOffsets[b] + yy * scanlineStride + xx; - iArray[outOffset++] = - data.getElem(bankIndices[b], offset); - } - } - return iArray; - } - - /** - * Set the pixel at x, y to the value in the first element of the primitive - * array obj. - * - * @param x The x-coordinate of the data elements in <code>obj</code>. - * @param y The y-coordinate of the data elements in <code>obj</code>. - * @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, Object obj, DataBuffer data) - { - int transferType = getTransferType(); - if (getTransferType() != data.getDataType()) - { - throw new IllegalArgumentException("transfer type ("+ - getTransferType()+"), "+ - "does not match data "+ - "buffer type (" + - data.getDataType() + - ")."); - } - - int offset = y * scanlineStride + x; - - try - { - switch (transferType) - { - case DataBuffer.TYPE_BYTE: - { - DataBufferByte out = (DataBufferByte) data; - byte[] in = (byte[]) obj; - for (int i = 0; i < numBands; i++) - out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i]; - return; - } - case DataBuffer.TYPE_SHORT: - { - DataBufferShort out = (DataBufferShort) data; - short[] in = (short[]) obj; - for (int i = 0; i < numBands; i++) - out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i]; - return; - } - case DataBuffer.TYPE_USHORT: - { - DataBufferUShort out = (DataBufferUShort) data; - short[] in = (short[]) obj; - for (int i = 0; i < numBands; i++) - out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i]; - return; - } - case DataBuffer.TYPE_INT: - { - DataBufferInt out = (DataBufferInt) data; - int[] in = (int[]) obj; - for (int i = 0; i < numBands; i++) - out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i]; - return; - } - case DataBuffer.TYPE_FLOAT: - { - DataBufferFloat out = (DataBufferFloat) data; - float[] in = (float[]) obj; - for (int i = 0; i < numBands; i++) - out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i]; - return; - } - case DataBuffer.TYPE_DOUBLE: - { - DataBufferDouble out = (DataBufferDouble) data; - double[] in = (double[]) obj; - for (int i = 0; i < numBands; i++) - out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i]; - return; - } - default: - throw new ClassCastException("Unsupported data type"); - } - } - catch (ArrayIndexOutOfBoundsException aioobe) - { - String msg = "While writing data elements" - + ", x=" + x + ", y=" + y - + ", width=" + width + ", height=" + height - + ", scanlineStride=" + scanlineStride - + ", offset=" + offset - + ", data.getSize()=" + data.getSize() - + ", data.getOffset()=" + data.getOffset() - + ": " + aioobe; - throw new ArrayIndexOutOfBoundsException(msg); - } - } - - /** - * Sets the samples for the pixel at (x, y) in the specified data buffer to - * the specified values. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param iArray the sample values (<code>null</code> not permitted). - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if either <code>iArray</code> or - * <code>data</code> is <code>null</code>. - */ - public void setPixel(int x, int y, int[] iArray, DataBuffer data) - { - for (int b = 0; b < numBands; b++) - data.setElem(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, - iArray[b]); - } - - /** - * Sets the sample values for the pixels in the region specified by - * (x, y, w, h) in the specified data buffer. The array is - * ordered by pixels (that is, all the samples for the first pixel are - * grouped together, followed by all the samples for the second pixel, and so - * on). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param iArray the pixel sample values (<code>null</code> not permitted). - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if either <code>iArray</code> or - * <code>data</code> is <code>null</code>. - */ - public void setPixels(int x, int y, int w, int h, int[] iArray, - DataBuffer data) - { - int inOffset = 0; - for (int hh = 0; hh < h; hh++) - { - for (int ww = 0; ww < w; ww++) - { - int offset = y * scanlineStride + (x + ww); - for (int b = 0; b < numBands; b++) - data.setElem(bankIndices[b], bandOffsets[b] + offset, - iArray[inOffset++]); - } - y++; - } - } - - /** - * Sets the sample value for band <code>b</code> of the pixel at location - * <code>(x, y)</code> in the specified data buffer. - * - * @param x the x-coordinate. - * @param y the y-coordinate. - * @param b the band index. - * @param s the sample value. - * @param data the data buffer (<code>null</code> not permitted). - * - * @see #getSample(int, int, int, DataBuffer) - */ - public void setSample(int x, int y, int b, int s, DataBuffer data) - { - data.setElem(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, s); - } - - /** - * Sets the sample value for a band for the pixel at (x, y) in the - * specified data buffer. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * @param s the sample value. - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public void setSample(int x, int y, int b, float s, DataBuffer data) - { - data.setElemFloat(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, - s); - } - - /** - * Sets the sample value for a band for the pixel at (x, y) in the - * specified data buffer. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * @param s the sample value. - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public void setSample(int x, int y, int b, double s, DataBuffer data) - { - data.setElemDouble(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, - s); - } - - /** - * Sets the sample values for one band for the pixels in the region - * specified by (x, y, w, h) in the specified data buffer. - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param b the band (in the range <code>0</code> to - * </code>getNumBands() - 1</code>). - * @param iArray the sample values (<code>null</code> not permitted). - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if either <code>iArray</code> or - * <code>data</code> is <code>null</code>. - */ - public void setSamples(int x, int y, int w, int h, int b, int[] iArray, - DataBuffer data) - { - if (x < 0 || y < 0) - throw new ArrayIndexOutOfBoundsException( - "x and y must not be less than 0."); - int inOffset = 0; - - switch (getTransferType()) - { - case DataBuffer.TYPE_BYTE: - { - DataBufferByte out = (DataBufferByte) data; - byte[] bank = out.getData(bankIndices[b]); - for (int hh = 0; hh < h; hh++) - { - for (int ww = 0; ww < w; ww++) - { - int offset = bandOffsets[b] + y * scanlineStride + (x + ww); - bank[offset] = (byte)iArray[inOffset++]; - } - y++; - } - return; - } - case DataBuffer.TYPE_SHORT: - { - DataBufferShort out = (DataBufferShort) data; - short[] bank = out.getData(bankIndices[b]); - for (int hh = 0; hh < h; hh++) - { - for (int ww = 0; ww < w; ww++) - { - int offset = bandOffsets[b] + y * scanlineStride + (x + ww); - bank[offset] = (short)iArray[inOffset++]; - } - y++; - } - return; - } - case DataBuffer.TYPE_USHORT: - { - DataBufferShort out = (DataBufferShort) data; - short[] bank = out.getData(bankIndices[b]); - for (int hh = 0; hh < h; hh++) - { - for (int ww = 0; ww < w; ww++) - { - int offset = bandOffsets[b] + y * scanlineStride + (x + ww); - bank[offset] = (short)iArray[inOffset++]; - } - y++; - } - return; - } - case DataBuffer.TYPE_INT: - { - DataBufferInt out = (DataBufferInt) data; - int[] bank = out.getData(bankIndices[b]); - for (int hh = 0; hh < h; hh++) - { - for (int ww = 0; ww < w; ww++) - { - int offset = bandOffsets[b] + y * scanlineStride + (x + ww); - bank[offset] = iArray[inOffset++]; - } - y++; - } - return; - } - case DataBuffer.TYPE_FLOAT: - case DataBuffer.TYPE_DOUBLE: - break; - default: - throw new ClassCastException("Unsupported data type"); - } - - // Default implementation probably slower for float and double - for (int hh = 0; hh < h; hh++) - { - for (int ww = 0; ww < w; ww++) - { - int offset = bandOffsets[b] + y * scanlineStride + (x + ww); - data.setElem(bankIndices[b], offset, iArray[inOffset++]); - } - y++; - } - } - - /** - * Creates a String with some information about this SampleModel. - * @return A String describing this SampleModel. - * @see java.lang.Object#toString() - */ - public String toString() - { - StringBuffer result = new StringBuffer(); - result.append(getClass().getName()); - result.append("["); - result.append("scanlineStride=").append(scanlineStride); - for(int i = 0; i < bitMasks.length; i+=1) - { - result.append(", mask[").append(i).append("]=0x").append( - Integer.toHexString(bitMasks[i])); - } - - result.append("]"); - return result.toString(); - } -}
--- a/rt/java/awt/image/ColorConvertOp.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,537 +0,0 @@ -/* ColorConvertOp.java -- - Copyright (C) 2004, 2006 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import gnu.java.awt.Buffers; - -import java.awt.Graphics2D; -import java.awt.Point; -import java.awt.RenderingHints; -import java.awt.color.ColorSpace; -import java.awt.color.ICC_ColorSpace; -import java.awt.color.ICC_Profile; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; - -/** - * ColorConvertOp is a filter for converting images or rasters between - * colorspaces, either through a sequence of colorspaces or just from source to - * destination. - * - * Color conversion is done on the color components without alpha. Thus - * if a BufferedImage has alpha premultiplied, this is divided out before - * color conversion, and premultiplication applied if the destination - * requires it. - * - * Color rendering and dithering hints may be applied if specified. This is - * likely platform-dependent. - * - * @author jlquinn@optonline.net - */ -public class ColorConvertOp implements BufferedImageOp, RasterOp -{ - private RenderingHints hints; - private ICC_Profile[] profiles = null; - private ColorSpace[] spaces; - - - /** - * Convert a BufferedImage through a ColorSpace. - * - * Objects created with this constructor can be used to convert - * BufferedImage's to a destination ColorSpace. Attempts to convert Rasters - * with this constructor will result in an IllegalArgumentException when the - * filter(Raster, WritableRaster) method is called. - * - * @param cspace The target color space. - * @param hints Rendering hints to use in conversion, if any (may be null) - * @throws NullPointerException if the ColorSpace is null. - */ - public ColorConvertOp(ColorSpace cspace, RenderingHints hints) - { - if (cspace == null) - throw new NullPointerException(); - spaces = new ColorSpace[]{cspace}; - this.hints = hints; - } - - /** - * Convert from a source colorspace to a destination colorspace. - * - * This constructor takes two ColorSpace arguments as the source and - * destination color spaces. It is usually used with the - * filter(Raster, WritableRaster) method, in which case the source colorspace - * is assumed to correspond to the source Raster, and the destination - * colorspace with the destination Raster. - * - * If used with BufferedImages that do not match the source or destination - * colorspaces specified here, there is an implicit conversion from the - * source image to the source ColorSpace, or the destination ColorSpace to - * the destination image. - * - * @param srcCspace The source ColorSpace. - * @param dstCspace The destination ColorSpace. - * @param hints Rendering hints to use in conversion, if any (may be null). - * @throws NullPointerException if any ColorSpace is null. - */ - public ColorConvertOp(ColorSpace srcCspace, ColorSpace dstCspace, - RenderingHints hints) - { - if (srcCspace == null || dstCspace == null) - throw new NullPointerException(); - spaces = new ColorSpace[]{srcCspace, dstCspace}; - this.hints = hints; - } - - /** - * Convert from a source colorspace to a destinatino colorspace. - * - * This constructor builds a ColorConvertOp from an array of ICC_Profiles. - * The source will be converted through the sequence of color spaces - * defined by the profiles. If the sequence of profiles doesn't give a - * well-defined conversion, an IllegalArgumentException is thrown. - * - * If used with BufferedImages that do not match the source or destination - * colorspaces specified here, there is an implicit conversion from the - * source image to the source ColorSpace, or the destination ColorSpace to - * the destination image. - * - * For Rasters, the first and last profiles must have the same number of - * bands as the source and destination Rasters, respectively. If this is - * not the case, or there fewer than 2 profiles, an IllegalArgumentException - * will be thrown. - * - * @param profiles An array of ICC_Profile's to convert through. - * @param hints Rendering hints to use in conversion, if any (may be null). - * @throws NullPointerException if the profile array is null. - * @throws IllegalArgumentException if the array is not a well-defined - * conversion. - */ - public ColorConvertOp(ICC_Profile[] profiles, RenderingHints hints) - { - if (profiles == null) - throw new NullPointerException(); - - this.hints = hints; - this.profiles = profiles; - - // Create colorspace array with space for src and dest colorspace - // Note that the ICC_ColorSpace constructor will throw an - // IllegalArgumentException if the profile is invalid; thus we check - // for a "well defined conversion" - spaces = new ColorSpace[profiles.length]; - for (int i = 0; i < profiles.length; i++) - spaces[i] = new ICC_ColorSpace(profiles[i]); - } - - /** - * Convert from source color space to destination color space. - * - * Only valid for BufferedImage objects, this Op converts from the source - * image's color space to the destination image's color space. - * - * The destination in the filter(BufferedImage, BufferedImage) method cannot - * be null for this operation, and it also cannot be used with the - * filter(Raster, WritableRaster) method. - * - * @param hints Rendering hints to use in conversion, if any (may be null). - */ - public ColorConvertOp(RenderingHints hints) - { - this.hints = hints; - spaces = new ColorSpace[0]; - } - - /** - * Converts the source image using the conversion path specified in the - * constructor. The resulting image is stored in the destination image if one - * is provided; otherwise a new BufferedImage is created and returned. - * - * The source and destination BufferedImage (if one is supplied) must have - * the same dimensions. - * - * @param src The source image. - * @param dst The destination image. - * @throws IllegalArgumentException if the rasters and/or color spaces are - * incompatible. - * @return The transformed image. - */ - public final BufferedImage filter(BufferedImage src, BufferedImage dst) - { - // TODO: The plan is to create a scanline buffer for intermediate buffers. - // For now we just suck it up and create intermediate buffers. - - if (dst == null && spaces.length == 0) - throw new IllegalArgumentException("Not enough color space information " - + "to complete conversion."); - - if (dst != null - && (src.getHeight() != dst.getHeight() || src.getWidth() != dst.getWidth())) - throw new IllegalArgumentException("Source and destination images have " - + "different dimensions"); - - // Make sure input isn't premultiplied by alpha - if (src.isAlphaPremultiplied()) - { - BufferedImage tmp = createCompatibleDestImage(src, src.getColorModel()); - copyimage(src, tmp); - tmp.coerceData(false); - src = tmp; - } - - // Convert through defined intermediate conversions - BufferedImage tmp; - for (int i = 0; i < spaces.length; i++) - { - if (src.getColorModel().getColorSpace().getType() != spaces[i].getType()) - { - tmp = createCompatibleDestImage(src, - createCompatibleColorModel(src, - spaces[i])); - copyimage(src, tmp); - src = tmp; - } - } - - // No implicit conversion to destination type needed; return result from the - // last intermediate conversions (which was left in src) - if (dst == null) - dst = src; - - // Implicit conversion to destination image's color space - else - copyimage(src, dst); - - return dst; - } - - /** - * Converts the source raster using the conversion path specified in the - * constructor. The resulting raster is stored in the destination raster if - * one is provided; otherwise a new WritableRaster is created and returned. - * - * This operation is not valid with every constructor of this class; see - * the constructors for details. Further, the source raster must have the - * same number of bands as the source ColorSpace, and the destination raster - * must have the same number of bands as the destination ColorSpace. - * - * The source and destination raster (if one is supplied) must also have the - * same dimensions. - * - * @param src The source raster. - * @param dest The destination raster. - * @throws IllegalArgumentException if the rasters and/or color spaces are - * incompatible. - * @return The transformed raster. - */ - public final WritableRaster filter(Raster src, WritableRaster dest) - { - // Various checks to ensure that the rasters and color spaces are compatible - if (spaces.length < 2) - throw new IllegalArgumentException("Not enough information about " + - "source and destination colorspaces."); - - if (spaces[0].getNumComponents() != src.getNumBands() - || (dest != null && spaces[spaces.length - 1].getNumComponents() != dest.getNumBands())) - throw new IllegalArgumentException("Source or destination raster " + - "contains the wrong number of bands."); - - if (dest != null - && (src.getHeight() != dest.getHeight() || src.getWidth() != dest.getWidth())) - throw new IllegalArgumentException("Source and destination rasters " + - "have different dimensions"); - - // Need to iterate through each color space. - // spaces[0] corresponds to the ColorSpace of the source raster, and - // spaces[spaces.length - 1] corresponds to the ColorSpace of the - // destination, with any number (or zero) of intermediate conversions. - - for (int i = 0; i < spaces.length - 2; i++) - { - WritableRaster tmp = createCompatibleDestRaster(src, spaces[i + 1], - false, - src.getTransferType()); - copyraster(src, spaces[i], tmp, spaces[i + 1]); - src = tmp; - } - - // The last conversion is done outside of the loop so that we can - // use the dest raster supplied, instead of creating our own temp raster - if (dest == null) - dest = createCompatibleDestRaster(src, spaces[spaces.length - 1], false, - DataBuffer.TYPE_BYTE); - copyraster(src, spaces[spaces.length - 2], dest, spaces[spaces.length - 1]); - - return dest; - } - - /** - * Creates an empty BufferedImage with the size equal to the source and the - * correct number of bands for the conversion defined in this Op. The newly - * created image is created with the specified ColorModel, or if no ColorModel - * is supplied, an appropriate one is chosen. - * - * @param src The source image. - * @param dstCM A color model for the destination image (may be null). - * @throws IllegalArgumentException if an appropriate colormodel cannot be - * chosen with the information given. - * @return The new compatible destination image. - */ - public BufferedImage createCompatibleDestImage(BufferedImage src, - ColorModel dstCM) - { - if (dstCM == null && spaces.length == 0) - throw new IllegalArgumentException("Don't know the destination " + - "colormodel"); - - if (dstCM == null) - { - dstCM = createCompatibleColorModel(src, spaces[spaces.length - 1]); - } - - return new BufferedImage(dstCM, - createCompatibleDestRaster(src.getRaster(), - dstCM.getColorSpace(), - src.getColorModel().hasAlpha(), - dstCM.getTransferType()), - src.isAlphaPremultiplied(), null); - } - - /** - * Creates a new WritableRaster with the size equal to the source and the - * correct number of bands. - * - * Note, the new Raster will always use a BYTE storage size, regardless of - * the color model or defined destination; this is for compatibility with - * the reference implementation. - * - * @param src The source Raster. - * @throws IllegalArgumentException if there isn't enough colorspace - * information to create a compatible Raster. - * @return The new compatible destination raster. - */ - public WritableRaster createCompatibleDestRaster(Raster src) - { - if (spaces.length < 2) - throw new IllegalArgumentException("Not enough destination colorspace " + - "information"); - - // Create a new raster with the last ColorSpace in the conversion - // chain, and with no alpha (implied) - return createCompatibleDestRaster(src, spaces[spaces.length-1], false, - DataBuffer.TYPE_BYTE); - } - - /** - * Returns the array of ICC_Profiles used to create this Op, or null if the - * Op was created using ColorSpace arguments. - * - * @return The array of ICC_Profiles, or null. - */ - public final ICC_Profile[] getICC_Profiles() - { - return profiles; - } - - /** - * Returns the rendering hints for this op. - * - * @return The rendering hints for this Op, or null. - */ - public final RenderingHints getRenderingHints() - { - return hints; - } - - /** - * Returns the corresponding destination point for a source point. - * Because this is not a geometric operation, the destination and source - * points will be identical. - * - * @param src The source point. - * @param dst The transformed destination point. - * @return The transformed destination point. - */ - public final Point2D getPoint2D(Point2D src, Point2D dst) - { - if (dst == null) - return (Point2D)src.clone(); - - dst.setLocation(src); - return dst; - } - - /** - * Returns the corresponding destination boundary of a source boundary. - * Because this is not a geometric operation, the destination and source - * boundaries will be identical. - * - * @param src The source boundary. - * @return The boundaries of the destination. - */ - public final Rectangle2D getBounds2D(BufferedImage src) - { - return src.getRaster().getBounds(); - } - - /** - * Returns the corresponding destination boundary of a source boundary. - * Because this is not a geometric operation, the destination and source - * boundaries will be identical. - * - * @param src The source boundary. - * @return The boundaries of the destination. - */ - public final Rectangle2D getBounds2D(Raster src) - { - return src.getBounds(); - } - - /** - * Copy a source image to a destination image, respecting their colorspaces - * and performing colorspace conversions if necessary. - * - * @param src The source image. - * @param dst The destination image. - */ - private void copyimage(BufferedImage src, BufferedImage dst) - { - // This is done using Graphics2D in order to respect the rendering hints. - Graphics2D gg = dst.createGraphics(); - - // If no hints are set there is no need to call - // setRenderingHints on the Graphics2D object. - if (hints != null) - gg.setRenderingHints(hints); - - gg.drawImage(src, 0, 0, null); - gg.dispose(); - } - - /** - * Copy a source raster to a destination raster, performing a colorspace - * conversion between the two. The conversion will respect the - * KEY_COLOR_RENDERING rendering hint if one is present. - * - * @param src The source raster. - * @param scs The colorspace of the source raster. - * @dst The destination raster. - * @dcs The colorspace of the destination raster. - */ - private void copyraster(Raster src, ColorSpace scs, WritableRaster dst, ColorSpace dcs) - { - float[] sbuf = new float[src.getNumBands()]; - - if (hints != null - && hints.get(RenderingHints.KEY_COLOR_RENDERING) == - RenderingHints.VALUE_COLOR_RENDER_QUALITY) - { - // use cie for accuracy - for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++) - for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++) - dst.setPixel(x, y, - dcs.fromCIEXYZ(scs.toCIEXYZ(src.getPixel(x, y, sbuf)))); - } - else - { - // use rgb - it's probably faster - for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++) - for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++) - dst.setPixel(x, y, - dcs.fromRGB(scs.toRGB(src.getPixel(x, y, sbuf)))); - } - } - - /** - * This method creates a color model with the same colorspace and alpha - * settings as the source image. The created color model will always be a - * ComponentColorModel and have a BYTE transfer type. - * - * @param img The source image. - * @param cs The ColorSpace to use. - * @return A color model compatible with the source image. - */ - private ColorModel createCompatibleColorModel(BufferedImage img, ColorSpace cs) - { - // The choice of ComponentColorModel and DataBuffer.TYPE_BYTE is based on - // Mauve testing of the reference implementation. - return new ComponentColorModel(cs, - img.getColorModel().hasAlpha(), - img.isAlphaPremultiplied(), - img.getColorModel().getTransparency(), - DataBuffer.TYPE_BYTE); - } - - /** - * This method creates a compatible Raster, given a source raster, colorspace, - * alpha value, and transfer type. - * - * @param src The source raster. - * @param cs The ColorSpace to use. - * @param hasAlpha Whether the raster should include a component for an alpha. - * @param transferType The size of a single data element. - * @return A compatible WritableRaster. - */ - private WritableRaster createCompatibleDestRaster(Raster src, ColorSpace cs, - boolean hasAlpha, - int transferType) - { - // The use of a PixelInterleavedSampleModel weas determined using mauve - // tests, based on the reference implementation - - int numComponents = cs.getNumComponents(); - if (hasAlpha) - numComponents++; - - int[] offsets = new int[numComponents]; - for (int i = 0; i < offsets.length; i++) - offsets[i] = i; - - DataBuffer db = Buffers.createBuffer(transferType, - src.getWidth() * src.getHeight() * numComponents, - 1); - return new WritableRaster(new PixelInterleavedSampleModel(transferType, - src.getWidth(), - src.getHeight(), - numComponents, - numComponents * src.getWidth(), - offsets), - db, new Point(src.getMinX(), src.getMinY())); - } -}
--- a/rt/java/awt/image/ComponentSampleModel.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,762 +0,0 @@ -/* Copyright (C) 2000, 2002, 2006, Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -import java.util.Arrays; - -/** - * ComponentSampleModel supports a flexible organization of pixel samples in - * memory, permitting pixel samples to be interleaved by band, by scanline, - * and by pixel. - * - * A DataBuffer for this sample model has K banks of data. Pixels have N - * samples, so there are N bands in the DataBuffer. Each band is completely - * contained in one bank of data, but a bank may contain more than one band. - * Each pixel sample is stored in a single data element. - * - * Within a bank, each band begins at an offset stored in bandOffsets. The - * banks containing the band is given by bankIndices. Within the bank, there - * are three dimensions - band, pixel, and scanline. The dimension ordering - * is controlled by bandOffset, pixelStride, and scanlineStride, which means - * that any combination of interleavings is supported. - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public class ComponentSampleModel extends SampleModel -{ - /** The offsets to the first sample for each band. */ - protected int[] bandOffsets; - - /** The indices of the bank used to store each band in a data buffer. */ - protected int[] bankIndices; - - /** - * The number of bands in the image. - * @specnote This field shadows the protected numBands in SampleModel. - */ - protected int numBands; - - /** Used when creating data buffers. */ - protected int numBanks; - - /** - * The number of data elements between a sample in one row and the - * corresponding sample in the next row. - */ - protected int scanlineStride; - - /** - * The number of data elements between a sample for one pixel and the - * corresponding sample for the next pixel in the same row. - */ - protected int pixelStride; - - static private native void initIDs(); - static - { - ColorModel.loadLibraries(); - initIDs(); - } - - /** - * Creates a new sample model that assumes that all bands are stored in a - * single bank of the {@link DataBuffer}. - * <p> - * Note that the <code>bandOffsets</code> array is copied to internal storage - * to prevent subsequent changes to the array from affecting this object. - * - * @param dataType the data type (one of {@link DataBuffer#TYPE_BYTE}, - * {@link DataBuffer#TYPE_USHORT}, {@link DataBuffer#TYPE_SHORT}, - * {@link DataBuffer#TYPE_INT}, {@link DataBuffer#TYPE_FLOAT} or - * {@link DataBuffer#TYPE_DOUBLE}). - * @param w the width in pixels. - * @param h the height in pixels. - * @param pixelStride the number of data elements in the step from a sample - * in one pixel to the corresponding sample in the next pixel. - * @param scanlineStride the number of data elements in the step from a - * sample in a pixel to the corresponding sample in the pixel in the next - * row. - * @param bandOffsets the offset to the first element for each band, with - * the size of the array defining the number of bands (<code>null</code> - * not permitted). - * - * @throws IllegalArgumentException if <code>dataType</code> is not one of - * the specified values. - * @throws IllegalArgumentException if <code>w</code> is less than or equal - * to zero. - * @throws IllegalArgumentException if <code>h</code> is less than or equal - * to zero. - * @throws IllegalArgumentException if <code>w * h</code> exceeds - * {@link Integer#MAX_VALUE}. - * @throws IllegalArgumentException if <code>pixelStride</code> is negative. - * @throws IllegalArgumentException if <code>scanlineStride</code> is less - * than or equal to zero. - * @throws IllegalArgumentException if <code>bandOffsets</code> has zero - * length. - */ - public ComponentSampleModel(int dataType, - int w, int h, - int pixelStride, - int scanlineStride, - int[] bandOffsets) - { - this(dataType, w, h, pixelStride, scanlineStride, - new int[bandOffsets.length], bandOffsets); - } - - /** - * Creates a new sample model that assumes that all bands are stored in a - * single bank of the {@link DataBuffer}. - * - * @param dataType the data type (one of {@link DataBuffer#TYPE_BYTE}, - * {@link DataBuffer#TYPE_USHORT}, {@link DataBuffer#TYPE_SHORT}, - * {@link DataBuffer#TYPE_INT}, {@link DataBuffer#TYPE_FLOAT} or - * {@link DataBuffer#TYPE_DOUBLE}). - * @param w the width in pixels. - * @param h the height in pixels. - * @param pixelStride the number of data elements in the step from a sample - * in one pixel to the corresponding sample in the next pixel. - * @param scanlineStride the number of data elements in the step from a - * sample in a pixel to the corresponding sample in the pixel in the next - * row. - * @param bankIndices the index of the bank in which each band is stored - * (<code>null</code> not permitted). This array is copied to internal - * storage so that subsequent updates to the array do not affect the sample - * model. - * @param bandOffsets the offset to the first element for each band, with - * the size of the array defining the number of bands (<code>null</code> - * not permitted). This array is copied to internal storage so that - * subsequent updates to the array do not affect the sample model. - * - * @throws IllegalArgumentException if <code>dataType</code> is not one of - * the specified values. - * @throws IllegalArgumentException if <code>w</code> is less than or equal - * to zero. - * @throws IllegalArgumentException if <code>h</code> is less than or equal - * to zero. - * @throws IllegalArgumentException if <code>w * h</code> exceeds - * {@link Integer#MAX_VALUE}. - * @throws IllegalArgumentException if <code>pixelStride</code> is negative. - * @throws IllegalArgumentException if <code>scanlineStride</code> is less - * than or equal to zero. - * @throws IllegalArgumentException if <code>bandOffsets</code> has zero - * length. - */ - public ComponentSampleModel(int dataType, - int w, int h, - int pixelStride, - int scanlineStride, - int[] bankIndices, - int[] bandOffsets) - { - super(dataType, w, h, bandOffsets.length); - - // super permits DataBuffer.TYPE_UNDEFINED but this class doesn't... - if (dataType == DataBuffer.TYPE_UNDEFINED) - throw new IllegalArgumentException("Unsupported dataType."); - - if ((pixelStride < 0) || (scanlineStride < 0) || (bandOffsets.length < 1) - || (bandOffsets.length != bankIndices.length)) - throw new IllegalArgumentException(); - - this.bandOffsets = (int[]) bandOffsets.clone(); - this.bankIndices = (int[]) bankIndices.clone(); - this.numBands = bandOffsets.length; - - this.numBanks = 0; - for (int b = 0; b < bankIndices.length; b++) - this.numBanks = Math.max(this.numBanks, bankIndices[b] + 1); - - this.scanlineStride = scanlineStride; - this.pixelStride = pixelStride; - - } - - /** - * Creates a new sample model that is compatible with this one, but with the - * specified dimensions. - * - * @param w the width (must be greater than zero). - * @param h the height (must be greater than zero). - * - * @return A new sample model. - */ - public SampleModel createCompatibleSampleModel(int w, int h) - { - return new ComponentSampleModel(dataType, w, h, pixelStride, - scanlineStride, bankIndices, - bandOffsets); - } - - /** - * Creates a new sample model that provides access to a subset of the bands - * that this sample model supports. - * - * @param bands the bands (<code>null</code> not permitted). - * - * @return The new sample model. - */ - public SampleModel createSubsetSampleModel(int[] bands) - { - int numBands = bands.length; - - int[] bankIndices = new int[numBands]; - int[] bandOffsets = new int[numBands]; - for (int b = 0; b < numBands; b++) - { - bankIndices[b] = this.bankIndices[bands[b]]; - bandOffsets[b] = this.bandOffsets[bands[b]]; - } - - return new ComponentSampleModel(dataType, width, height, pixelStride, - scanlineStride, bankIndices, - bandOffsets); - } - - /** - * Creates a new data buffer that is compatible with this sample model. - * - * @return The new data buffer. - */ - public DataBuffer createDataBuffer() - { - // Maybe this value should be precalculated in the constructor? - int highestOffset = 0; - for (int b = 0; b < numBands; b++) - highestOffset = Math.max(highestOffset, bandOffsets[b]); - int size = pixelStride * (width - 1) + scanlineStride * (height - 1) - + highestOffset + 1; - - 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; - } - - /** - * Returns the offset of the sample in band 0 for the pixel at location - * <code>(x, y)</code>. This offset can be used to read a sample value from - * a {@link DataBuffer}. - * - * @param x the x-coordinate. - * @param y the y-coordinate. - * - * @return The offset. - * - * @see #getOffset(int, int, int) - */ - public int getOffset(int x, int y) - { - return getOffset(x, y, 0); - } - - /** - * Returns the offset of the sample in band <code>b</code> for the pixel at - * location <code>(x, y)</code>. This offset can be used to read a sample - * value from a {@link DataBuffer}. - * - * @param x the x-coordinate. - * @param y the y-coordinate. - * @param b the band index. - * - * @return The offset. - */ - public int getOffset(int x, int y, int b) - { - return bandOffsets[b] + pixelStride * x + scanlineStride * y; - } - - /** - * Returns the size in bits for each sample (one per band). For this sample - * model, each band has the same sample size and this is determined by the - * data type for the sample model. - * - * @return The sample sizes. - * - * @see SampleModel#getDataType() - */ - public final int[] getSampleSize() - { - int size = DataBuffer.getDataTypeSize(getDataType()); - int[] sizes = new int[numBands]; - - java.util.Arrays.fill(sizes, size); - return sizes; - } - - /** - * Returns the size in bits for the samples in the specified band. In this - * class, the sample size is the same for every band and is determined from - * the data type for the model. - * - * @param band the band index (ignored here). - * - * @return The sample size in bits. - * - * @see SampleModel#getDataType() - */ - public final int getSampleSize(int band) - { - return DataBuffer.getDataTypeSize(getDataType()); - } - - /** - * Returns the indices of the bank(s) in the {@link DataBuffer} used to - * store the samples for each band. The returned array is a copy, so that - * altering it will not impact the sample model. - * - * @return The bank indices. - */ - public final int[] getBankIndices() - { - return (int[]) bankIndices.clone(); - } - - /** - * Returns the offsets to the first sample in each band. The returned array - * is a copy, so that altering it will not impact the sample model. - * - * @return The offsets. - */ - public final int[] getBandOffsets() - { - return (int[]) bandOffsets.clone(); - } - - /** - * Returns the distance (in terms of element indices) between the sample for - * one pixel and the corresponding sample for the equivalent pixel in the - * next row. This is used in the calculation of the element offset for - * retrieving samples from a {@link DataBuffer}. - * - * @return The distance between pixel samples in consecutive rows. - */ - public final int getScanlineStride() - { - return scanlineStride; - } - - /** - * Returns the distance (in terms of element indices) between the sample for - * one pixel and the corresponding sample for the next pixel in a row. This - * is used in the calculation of the element offset for retrieving samples - * from a {@link DataBuffer}. - * - * @return The distance between pixel samples in the same row. - */ - public final int getPixelStride() - { - return pixelStride; - } - - /** - * Returns the number of data elements used to store the samples for one - * pixel. In this model, this is the same as the number of bands. - * - * @return The number of data elements used to store the samples for one - * pixel. - */ - public final int getNumDataElements() - { - return numBands; - } - - /** - * Returns the samples for the pixel at location <code>(x, y)</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 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 pixel. - */ - public Object getDataElements(int x, int y, Object obj, DataBuffer data) - { - int type = getTransferType(); - int numDataEls = getNumDataElements(); - int offset = y * scanlineStride + x * pixelStride; - switch (type) - { - case DataBuffer.TYPE_BYTE: - byte[] bData; - if (obj == null) - bData = new byte[numDataEls]; - else - bData = (byte[]) obj; - for (int i = 0; i < numDataEls; i++) - { - bData[i] = (byte) data.getElem(bankIndices[i], - offset + bandOffsets[i]); - } - 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; - } - - - /** - * Returns all the samples for the pixel at location <code>(x, y)</code> - * stored in the specified data buffer. - * - * @param x the x-coordinate. - * @param y the y-coordinate. - * @param iArray an array that will be populated with the sample values and - * returned as the result. The size of this array should be equal to the - * number of bands in the model. If the array is <code>null</code>, a new - * array is created. - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The samples for the specified pixel. - * - * @see #setPixel(int, int, int[], DataBuffer) - */ - public int[] getPixel(int x, int y, int[] iArray, DataBuffer data) - { - if (x < 0 || x >= width || y < 0 || y >= height) - throw new ArrayIndexOutOfBoundsException("Pixel (" + x + ", " + y - + ") is out of bounds."); - int offset = pixelStride * x + scanlineStride * y; - if (iArray == null) - iArray = new int[numBands]; - for (int b = 0; b < numBands; b++) - { - iArray[b] = data.getElem(bankIndices[b], offset + bandOffsets[b]); - } - return iArray; - } - - /** - * Returns the samples for all the pixels in a rectangular region. - * - * @param x the x-coordinate. - * @param y the y-coordinate. - * @param w the width. - * @param h the height. - * @param iArray an array that if non-<code>null</code> will be populated - * with the sample values and returned as the result. - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The samples for all the pixels in the rectangle. - */ - public int[] getPixels(int x, int y, int w, int h, int[] iArray, - DataBuffer data) - { - int offset = pixelStride * x + scanlineStride * y; - if (iArray == null) - iArray = new int[numBands * w * h]; - int outOffset = 0; - for (y = 0; y < h; y++) - { - int lineOffset = offset; - for (x = 0; x < w; x++) - { - for (int b = 0; b < numBands; b++) - { - iArray[outOffset++] - = data.getElem(bankIndices[b], lineOffset+bandOffsets[b]); - } - lineOffset += pixelStride; - } - offset += scanlineStride; - } - return iArray; - } - - /** - * Returns the sample for band <code>b</code> of the pixel at - * <code>(x, y)</code> that is stored in the specified data buffer. - * - * @param x the x-coordinate. - * @param y the y-coordinate. - * @param b the band index. - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The sample value. - * - * @throws ArrayIndexOutOfBoundsException if <code>(x, y)</code> is outside - * the bounds <code>[0, 0, width, height]</code>. - * - * @see #setSample(int, int, int, int, DataBuffer) - */ - public int getSample(int x, int y, int b, DataBuffer data) - { - if (x < 0 || x >= width || y < 0 || y >= height) - throw new ArrayIndexOutOfBoundsException("Sample (" + x + ", " + y - + ") is out of bounds."); - return data.getElem(bankIndices[b], getOffset(x, y, b)); - } - - /** - * Sets the samples for the pixel at location <code>(x, y)</code> from the - * 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 obj a primitive array containing the pixel's sample values. - * @param data the data buffer (<code>null</code> not permitted). - * - * @see #setDataElements(int, int, Object, DataBuffer) - */ - public void setDataElements(int x, int y, Object obj, DataBuffer data) - { - int type = getTransferType(); - int numDataEls = getNumDataElements(); - int offset = y * scanlineStride + x * pixelStride; - switch (type) - { - case DataBuffer.TYPE_BYTE: - 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: - 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: - 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: - 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: - double[] dData = (double[]) obj; - for (int i = 0; i < numDataEls; i++) - { - data.setElemDouble(bankIndices[i], offset + bandOffsets[i], - dData[i]); - } - break; - } - } - - /** - * Sets the sample values for the pixel at location <code>(x, y)</code> - * stored in the specified data buffer. - * - * @param x the x-coordinate. - * @param y the y-coordinate. - * @param iArray the pixel sample values (<code>null</code> not permitted). - * @param data the data buffer (<code>null</code> not permitted). - * - * @see #getPixel(int, int, int[], DataBuffer) - */ - public void setPixel(int x, int y, int[] iArray, DataBuffer data) - { - int offset = pixelStride * x + scanlineStride * y; - for (int b = 0; b < numBands; b++) - data.setElem(bankIndices[b], offset + bandOffsets[b], iArray[b]); - } - - /** - * Sets the sample value for band <code>b</code> of the pixel at location - * <code>(x, y)</code> in the specified data buffer. - * - * @param x the x-coordinate. - * @param y the y-coordinate. - * @param b the band index. - * @param s the sample value. - * @param data the data buffer (<code>null</code> not permitted). - * - * @see #getSample(int, int, int, DataBuffer) - */ - public void setSample(int x, int y, int b, int s, DataBuffer data) - { - data.setElem(bankIndices[b], getOffset(x, y, b), s); - } - - /** - * Tests this sample model for equality with an arbitrary object. Returns - * <code>true</code> if and only if: - * <ul> - * <li><code>obj</code> is not <code>null</code>;</li> - * <li><code>obj</code> is an instance of <code>ComponentSampleModel</code>; - * </li> - * <li>both models have the same values for the <code>dataType</code>, - * <code>width</code>, <code>height</code>, <code>pixelStride</code>, - * <code>scanlineStride</code>, <code>bandOffsets</code> and - * <code>bankIndices</code> fields.</li> - * </ul> - * - * @param obj the object to test (<code>null</code> permitted). - * - * @return <code>true</code> if this sample model is equal to - * <code>obj</code>, and <code>false</code> otherwise. - */ - public boolean equals(Object obj) - { - if (obj == null) - return false; - if (! (obj instanceof ComponentSampleModel)) - return false; - ComponentSampleModel that = (ComponentSampleModel) obj; - if (this.dataType != that.dataType) - return false; - if (this.width != that.width) - return false; - if (this.height != that.height) - return false; - if (this.pixelStride != that.pixelStride) - return false; - if (this.scanlineStride != that.scanlineStride) - return false; - if (! Arrays.equals(this.bandOffsets, that.bandOffsets)) - return false; - if (! Arrays.equals(this.bankIndices, that.bankIndices)) - return false; - // couldn't find any difference, so... - return true; - } - - /** - * Returns a hash code for this sample model. - * - * @return The hash code. - */ - public int hashCode() - { - // this computation is based on the method described in Chapter 3 - // of Joshua Bloch's Effective Java... - int result = 17; - result = 37 * result + dataType; - result = 37 * result + width; - result = 37 * result + height; - result = 37 * result + pixelStride; - result = 37 * result + scanlineStride; - for (int i = 0; i < bandOffsets.length; i++) - result = 37 * result + bandOffsets[i]; - for (int i = 0; i < bankIndices.length; i++) - result = 37 * result + bankIndices[i]; - return result; - } -}
--- a/rt/java/awt/image/DataBuffer.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,473 +0,0 @@ -/* Copyright (C) 2000, 2002, 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -import sun.java2d.StateTrackable; -import sun.java2d.StateTrackableDelegate; - -/** - * Class that manages arrays of data elements. A data buffer consists - * of one or more banks. A bank is a continuous region of data - * elements. - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public abstract class DataBuffer -{ - /** - * A constant representing a data type that uses <code>byte</code> primitives - * as the storage unit. - */ - public static final int TYPE_BYTE = 0; - - /** - * A constant representing a data type that uses <code>short</code> - * primitives as the storage unit. - */ - public static final int TYPE_USHORT = 1; - - /** - * A constant representing a data type that uses <code>short</code> - * primitives as the storage unit. - */ - public static final int TYPE_SHORT = 2; - - /** - * A constant representing a data type that uses <code>int</code> - * primitives as the storage unit. - */ - public static final int TYPE_INT = 3; - - /** - * A constant representing a data type that uses <code>float</code> - * primitives as the storage unit. - */ - public static final int TYPE_FLOAT = 4; - - /** - * A constant representing a data type that uses <code>double</code> - * primitives as the storage unit. - */ - public static final int TYPE_DOUBLE = 5; - - /** - * A constant representing an undefined data type. - */ - public static final int TYPE_UNDEFINED = 32; - - /** The type of the data elements stored in the data buffer. */ - protected int dataType; - - /** The number of banks in this buffer. */ - protected int banks = 1; - - /** Offset into the default (0'th) bank). */ - protected int offset; // FIXME: Is offsets[0] always mirrored in offset? - - /** The size of the banks. */ - protected int size; - - /** Offset into each bank. */ - protected int[] offsets; - - // TODO: IcedTea: use me! - StateTrackableDelegate theTrackable = null; - - /** - * Creates a new <code>DataBuffer</code> with the specified data type and - * size. The <code>dataType</code> should be one of the constants - * {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, {@link #TYPE_USHORT}, - * {@link #TYPE_INT}, {@link #TYPE_FLOAT} and {@link #TYPE_DOUBLE}. - * <p> - * The physical (array-based) storage is allocated by a subclass. - * - * @param dataType the data type. - * @param size the number of elements in the buffer. - */ - protected DataBuffer(int dataType, int size) - { - this(dataType, size, 1); - } - - /** - * Creates a new <code>DataBuffer</code> with the specified data type, - * size and number of banks. The <code>dataType</code> should be one of - * the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, - * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and - * {@link #TYPE_DOUBLE}. - * <p> - * The physical (array-based) storage is allocated by a subclass. - * - * @param dataType the data type. - * @param size the number of elements in the buffer. - * @param numBanks the number of data banks. - */ - protected DataBuffer(int dataType, int size, int numBanks) { - this(dataType, size, numBanks, 0); - } - - /** - * Creates a new <code>DataBuffer</code> with the specified data type, - * size and number of banks. An offset (which applies to all banks) is - * also specified. The <code>dataType</code> should be one of - * the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, - * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and - * {@link #TYPE_DOUBLE}. - * <p> - * The physical (array-based) storage is allocated by a subclass. - * - * @param dataType the data type. - * @param size the number of elements in the buffer. - * @param numBanks the number of data banks. - * @param offset the offset to the first element for all banks. - */ - protected DataBuffer(int dataType, int size, int numBanks, int offset) { - banks = numBanks; - this.dataType = dataType; - this.size = size; - this.offset = offset; - - offsets = new int[ numBanks ]; - for(int i = 0; i < numBanks; i++ ) - offsets[i] = offset; - } - - /** - * Creates a new <code>DataBuffer</code> with the specified data type, - * size and number of banks. An offset (which applies to all banks) is - * also specified. The <code>dataType</code> should be one of - * the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, - * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and - * {@link #TYPE_DOUBLE}. - * <p> - * The physical (array-based) storage is allocated by a subclass. - * - * @param dataType the data type. - * @param size the number of elements in the buffer. - * @param numBanks the number of data banks. - * @param offsets the offsets to the first element for all banks. - * - * @throws ArrayIndexOutOfBoundsException if - * <code>numBanks != offsets.length</code>. - */ - protected DataBuffer(int dataType, int size, int numBanks, int[] offsets) { - if (numBanks != offsets.length) - throw new ArrayIndexOutOfBoundsException(); - - this.dataType = dataType; - this.size = size; - banks = numBanks; - this.offsets = offsets; - - offset = offsets[0]; - } - - // TODO: IcedTea: implement me - DataBuffer(StateTrackable.State s, int i, int j) - { - throw new RuntimeException("Not Implemented"); - } - - // TODO: IcedTea: implement me - DataBuffer(StateTrackable.State s, int i, int j, int k) - { - throw new RuntimeException("Not Implemented"); - } - - // TODO: IcedTea: implement me - DataBuffer(StateTrackable.State s, int i, int j, int k, int l) - { - throw new RuntimeException("Not Implemented"); - } - - // TODO: IcedTea: implement me - DataBuffer(StateTrackable.State s, int i, int j, int k, int l[]) - { - throw new RuntimeException("Not Implemented"); - } - - /** - * Returns the size (number of bits) of the specified data type. Valid types - * are defined by the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, - * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and - * {@link #TYPE_DOUBLE}. - * - * @param dataType the data type. - * @return The number of bits for the specified data type. - * @throws IllegalArgumentException if <code>dataType < 0</code> or - * <code>dataType > TYPE_DOUBLE</code>. - */ - public static int getDataTypeSize(int dataType) { - // Maybe this should be a lookup table instead. - switch (dataType) - { - case TYPE_BYTE: - return 8; - case TYPE_USHORT: - case TYPE_SHORT: - return 16; - case TYPE_INT: - case TYPE_FLOAT: - return 32; - case TYPE_DOUBLE: - return 64; - default: - throw new IllegalArgumentException(); - } - } - - /** - * Returns the type of the data elements in the data buffer. Valid types - * are defined by the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, - * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and - * {@link #TYPE_DOUBLE}. - * - * @return The type. - */ - public int getDataType() - { - return dataType; - } - - /** - * Returns the size of the data buffer. - * - * @return The size. - */ - public int getSize() - { - return size; - } - - /** - * Returns the element offset for the first data bank. - * - * @return The element offset. - */ - public int getOffset() - { - return offset; - } - - /** - * Returns the offsets for all the data banks used by this - * <code>DataBuffer</code>. - * - * @return The offsets. - */ - public int[] getOffsets() - { - if (offsets == null) - { - // is this necessary? - offsets = new int[1]; - offsets[0] = offset; - } - return offsets; - } - - /** - * Returns the number of data banks for this <code>DataBuffer</code>. - * @return The number of data banks. - */ - public int getNumBanks() - { - return banks; - } - - /** - * Returns an element from the first data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param i the element index. - * @return The element. - */ - public int getElem(int i) - { - return getElem(0, i); - } - - /** - * Returns an element from a particular data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param bank the bank index. - * @param i the element index. - * @return The element. - */ - public abstract int getElem(int bank, int i); - - /** - * Sets an element in the first data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int i, int val) - { - setElem(0, i, val); - } - - /** - * Sets an element in a particular data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param bank the data bank index. - * @param i the element index. - * @param val the new element value. - */ - public abstract void setElem(int bank, int i, int val); - - /** - * Returns an element from the first data bank, converted to a - * <code>float</code>. The offset (specified in the constructor) is added - * to <code>i</code> before accessing the underlying data array. - * - * @param i the element index. - * @return The element. - */ - public float getElemFloat(int i) - { - return getElem(i); - } - - /** - * Returns an element from a particular data bank, converted to a - * <code>float</code>. The offset (specified in the constructor) is - * added to <code>i</code> before accessing the underlying data array. - * - * @param bank the bank index. - * @param i the element index. - * @return The element. - */ - public float getElemFloat(int bank, int i) - { - return getElem(bank, i); - } - - /** - * Sets an element in the first data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param i the element index. - * @param val the new element value. - */ - public void setElemFloat(int i, float val) - { - setElem(i, (int) val); - } - - /** - * Sets an element in a particular data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param bank the data bank index. - * @param i the element index. - * @param val the new element value. - */ - public void setElemFloat(int bank, int i, float val) - { - setElem(bank, i, (int) val); - } - - /** - * Returns an element from the first data bank, converted to a - * <code>double</code>. The offset (specified in the constructor) is added - * to <code>i</code> before accessing the underlying data array. - * - * @param i the element index. - * @return The element. - */ - public double getElemDouble(int i) - { - return getElem(i); - } - - /** - * Returns an element from a particular data bank, converted to a - * <code>double</code>. The offset (specified in the constructor) is - * added to <code>i</code> before accessing the underlying data array. - * - * @param bank the bank index. - * @param i the element index. - * @return The element. - */ - public double getElemDouble(int bank, int i) - { - return getElem(bank, i); - } - - /** - * Sets an element in the first data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param i the element index. - * @param val the new element value. - */ - public void setElemDouble(int i, double val) - { - setElem(i, (int) val); - } - - /** - * Sets an element in a particular data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param bank the data bank index. - * @param i the element index. - * @param val the new element value. - */ - public void setElemDouble(int bank, int i, double val) - { - setElem(bank, i, (int) val); - } - - // TODO: IcedTea: implement me! - static int[] toIntArray(Object o) - { - throw new RuntimeException("Not implemented"); - } -}
--- a/rt/java/awt/image/DataBufferByte.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,245 +0,0 @@ -/* Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -/* This is one of several classes that are nearly identical. Maybe we - should have a central template and generate all these files. This - is one of the cases where templates or macros would have been - useful to have in Java. - - This file has been created using search-replace. My only fear is - that these classes will grow out-of-sync as of a result of changes - that are not propagated to the other files. As always, mirroring - code is a maintenance nightmare. */ - -/** - * A {@link DataBuffer} that uses an array of <code>byte</code> primitives - * to represent each of its banks. - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public final class DataBufferByte extends DataBuffer -{ - private byte[] data; - private byte[][] bankData; - - /** - * Creates a new data buffer with a single data bank containing the - * specified number of <code>byte</code> elements. - * - * @param size the number of elements in the data bank. - */ - public DataBufferByte(int size) - { - super(TYPE_BYTE, size, 1, 0); - bankData = new byte[1][]; - data = new byte[size]; - bankData[0] = data; - } - - /** - * Creates a new data buffer with the specified number of data banks, - * each containing the specified number of <code>byte</code> elements. - * - * @param size the number of elements in the data bank. - * @param numBanks the number of data banks. - */ - public DataBufferByte(int size, int numBanks) - { - super(TYPE_BYTE, size, numBanks); - bankData = new byte[numBanks][size]; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data bank. - * <p> - * Note: there is no exception when <code>dataArray</code> is - * <code>null</code>, but in that case an exception will be thrown - * later if you attempt to access the data buffer. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - */ - public DataBufferByte(byte[] dataArray, int size) - { - super(TYPE_BYTE, size, 1, 0); - bankData = new byte[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data bank, with - * the specified offset to the first element. - * <p> - * Note: there is no exception when <code>dataArray</code> is - * <code>null</code>, but in that case an exception will be thrown - * later if you attempt to access the data buffer. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - * @param offset the offset to the first element in the array. - */ - public DataBufferByte(byte[] dataArray, int size, int offset) - { - super(TYPE_BYTE, size, 1, offset); - bankData = new byte[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data banks. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferByte(byte[][] dataArray, int size) - { - super(TYPE_BYTE, size, dataArray.length); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data banks, with - * the specified offsets to the first element in each bank. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * @param offsets the offsets to the first element in each data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferByte(byte[][] dataArray, int size, int[] offsets) - { - super(TYPE_BYTE, size, dataArray.length, offsets); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Returns the first data bank. - * - * @return The first data bank. - */ - public byte[] getData() - { - return data; - } - - /** - * Returns a data bank. - * - * @param bank the bank index. - * @return A data bank. - */ - public byte[] getData(int bank) - { - return bankData[bank]; - } - - /** - * Returns the array underlying this <code>DataBuffer</code>. - * - * @return The data banks. - */ - public byte[][] getBankData() - { - return bankData; - } - - /** - * Returns an element from the first data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param i the element index. - * @return The element. - */ - public int getElem(int i) - { - return data[i+offset] & 0xff; // get unsigned byte as int - } - - /** - * Returns an element from a particular data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param bank the bank index. - * @param i the element index. - * @return The element. - */ - public int getElem(int bank, int i) - { - // get unsigned byte as int - return bankData[bank][i+offsets[bank]] & 0xff; - } - - /** - * Sets an element in the first data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int i, int val) - { - data[i+offset] = (byte) val; - } - - /** - * Sets an element in a particular data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param bank the data bank index. - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int bank, int i, int val) - { - bankData[bank][i+offsets[bank]] = (byte) val; - } -}
--- a/rt/java/awt/image/DataBufferInt.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,244 +0,0 @@ -/* Copyright (C) 2000, 2002, 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -/* This is one of several classes that are nearly identical. Maybe we - should have a central template and generate all these files. This - is one of the cases where templates or macros would have been - useful to have in Java. - - This file has been created using search-replace. My only fear is - that these classes will grow out-of-sync as of a result of changes - that are not propagated to the other files. As always, mirroring - code is a maintenance nightmare. */ - -/** - * A {@link DataBuffer} that uses an array of <code>int</code> primitives - * to represent each of its banks. - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public final class DataBufferInt extends DataBuffer -{ - private int[] data; - private int[][] bankData; - - /** - * Creates a new data buffer with a single data bank containing the - * specified number of <code>int</code> elements. - * - * @param size the number of elements in the data bank. - */ - public DataBufferInt(int size) - { - super(TYPE_INT, size, 1, 0); - bankData = new int[1][]; - data = new int[size]; - bankData[0] = data; - } - - /** - * Creates a new data buffer with the specified number of data banks, - * each containing the specified number of <code>int</code> elements. - * - * @param size the number of elements in the data bank. - * @param numBanks the number of data banks. - */ - public DataBufferInt(int size, int numBanks) - { - super(TYPE_INT, size, numBanks); - bankData = new int[numBanks][size]; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data bank. - * <p> - * Note: there is no exception when <code>dataArray</code> is - * <code>null</code>, but in that case an exception will be thrown - * later if you attempt to access the data buffer. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - */ - public DataBufferInt(int[] dataArray, int size) - { - super(TYPE_INT, size, 1, 0); - bankData = new int[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data bank, with - * the specified offset to the first element. - * <p> - * Note: there is no exception when <code>dataArray</code> is - * <code>null</code>, but in that case an exception will be thrown - * later if you attempt to access the data buffer. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - * @param offset the offset to the first element in the array. - */ - public DataBufferInt(int[] dataArray, int size, int offset) - { - super(TYPE_INT, size, 1, offset); - bankData = new int[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data banks. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferInt(int[][] dataArray, int size) - { - super(TYPE_INT, size, dataArray.length); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data banks, with - * the specified offsets to the first element in each bank. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * @param offsets the offsets to the first element in each data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferInt(int[][] dataArray, int size, int[] offsets) - { - super(TYPE_INT, size, dataArray.length, offsets); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Returns the first data bank. - * - * @return The first data bank. - */ - public int[] getData() - { - return data; - } - - /** - * Returns a data bank. - * - * @param bank the bank index. - * @return A data bank. - */ - public int[] getData(int bank) - { - return bankData[bank]; - } - - /** - * Returns the array underlying this <code>DataBuffer</code>. - * - * @return The data banks. - */ - public int[][] getBankData() - { - return bankData; - } - - /** - * Returns an element from the first data bank. The <code>offset</code> is - * added to the specified index before accessing the underlying data array. - * - * @param i the element index. - * @return The element. - */ - public int getElem(int i) - { - return data[i+offset]; - } - - /** - * Returns an element from a particular data bank. The <code>offset</code> - * is added to the specified index before accessing the underlying data - * array. - * - * @param bank the bank index. - * @param i the element index. - * @return The element. - */ - public int getElem(int bank, int i) - { - // get unsigned int as int - return bankData[bank][i+offsets[bank]]; - } - - /** - * Sets an element in the first data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int i, int val) - { - data[i+offset] = val; - } - - /** - * Sets an element in a particular data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param bank the data bank index. - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int bank, int i, int val) - { - bankData[bank][i+offsets[bank]] = val; - } -}
--- a/rt/java/awt/image/DataBufferShort.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,245 +0,0 @@ -/* DataBufferShort.java -- - Copyright (C) 2004, 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -/* This is one of several classes that are nearly identical. Maybe we - should have a central template and generate all these files. This - is one of the cases where templates or macros would have been - useful to have in Java. - - This file has been created using search-replace. My only fear is - that these classes will grow out-of-sync as of a result of changes - that are not propagated to the other files. As always, mirroring - code is a maintenance nightmare. */ - -/** - * A {@link DataBuffer} that uses an array of <code>short</code> primitives - * to represent each of its banks. - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public final class DataBufferShort extends DataBuffer -{ - private short[] data; - private short[][] bankData; - - /** - * Creates a new data buffer with a single data bank containing the - * specified number of <code>short</code> elements. - * - * @param size the number of elements in the data bank. - */ - public DataBufferShort(int size) - { - super(TYPE_SHORT, size, 1, 0); - bankData = new short[1][]; - data = new short[size]; - bankData[0] = data; - } - - /** - * Creates a new data buffer with the specified number of data banks, - * each containing the specified number of <code>short</code> elements. - * - * @param size the number of elements in the data bank. - * @param numBanks the number of data banks. - */ - public DataBufferShort(int size, int numBanks) - { - super(TYPE_SHORT, size, numBanks); - bankData = new short[numBanks][size]; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data bank. - * <p> - * Note: there is no exception when <code>dataArray</code> is - * <code>null</code>, but in that case an exception will be thrown - * later if you attempt to access the data buffer. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - */ - public DataBufferShort(short[] dataArray, int size) - { - super(TYPE_SHORT, size, 1, 0); - bankData = new short[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data bank, with - * the specified offset to the first element. - * <p> - * Note: there is no exception when <code>dataArray</code> is - * <code>null</code>, but in that case an exception will be thrown - * later if you attempt to access the data buffer. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - * @param offset the offset to the first element in the array. - */ - public DataBufferShort(short[] dataArray, int size, int offset) - { - super(TYPE_SHORT, size, 1, offset); - bankData = new short[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data banks. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferShort(short[][] dataArray, int size) - { - super(TYPE_SHORT, size, dataArray.length); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data banks, with - * the specified offsets to the first element in each bank. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * @param offsets the offsets to the first element in each data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferShort(short[][] dataArray, int size, int[] offsets) - { - super(TYPE_SHORT, size, dataArray.length, offsets); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Returns the first data bank. - * - * @return The first data bank. - */ - public short[] getData() - { - return data; - } - - /** - * Returns a data bank. - * - * @param bank the bank index. - * @return A data bank. - */ - public short[] getData(int bank) - { - return bankData[bank]; - } - - /** - * Returns the array underlying this <code>DataBuffer</code>. - * - * @return The data banks. - */ - public short[][] getBankData() - { - return bankData; - } - - /** - * Returns an element from the first data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param i the element index. - * @return The element. - */ - public int getElem(int i) - { - return data[i+offset]; - } - - /** - * Returns an element from a particular data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param bank the bank index. - * @param i the element index. - * @return The element. - */ - public int getElem(int bank, int i) - { - return bankData[bank][i+offsets[bank]]; - } - - /** - * Sets an element in the first data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int i, int val) - { - data[i+offset] = (short) val; - } - - /** - * Sets an element in a particular data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param bank the data bank index. - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int bank, int i, int val) - { - bankData[bank][i+offsets[bank]] = (short) val; - } -}
--- a/rt/java/awt/image/DataBufferUShort.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,246 +0,0 @@ -/* DataBufferUShort.java -- - Copyright (C) 2000, 2002, 2004, 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -/* This is one of several classes that are nearly identical. Maybe we - should have a central template and generate all these files. This - is one of the cases where templates or macros would have been - useful to have in Java. - - This file has been created using search-replace. My only fear is - that these classes will grow out-of-sync as of a result of changes - that are not propagated to the other files. As always, mirroring - code is a maintenance nightmare. */ - -/** - * A {@link DataBuffer} that uses an array of <code>short</code> primitives - * to represent each of its banks. - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public final class DataBufferUShort extends DataBuffer -{ - private short[] data; - private short[][] bankData; - - /** - * Creates a new data buffer with a single data bank containing the - * specified number of <code>short</code> elements. - * - * @param size the number of elements in the data bank. - */ - public DataBufferUShort(int size) - { - super(TYPE_USHORT, size, 1, 0); - bankData = new short[1][]; - data = new short[size]; - bankData[0] = data; - } - - /** - * Creates a new data buffer with the specified number of data banks, - * each containing the specified number of <code>short</code> elements. - * - * @param size the number of elements in the data bank. - * @param numBanks the number of data banks. - */ - public DataBufferUShort(int size, int numBanks) - { - super(TYPE_USHORT, size, numBanks); - bankData = new short[numBanks][size]; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data bank. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - * - * @throws NullPointerException if dataArray is null - */ - public DataBufferUShort(short[] dataArray, int size) - { - super(TYPE_USHORT, size, 1, 0); - if (dataArray == null) - throw new NullPointerException(); - bankData = new short[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data bank, with - * the specified offset to the first element. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - * @param offset the offset to the first element in the array. - * - * @throws NullPointerException if dataArray is null - */ - public DataBufferUShort(short[] dataArray, int size, int offset) - { - super(TYPE_USHORT, size, 1, offset); - if (dataArray == null) - throw new NullPointerException(); - bankData = new short[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data banks. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferUShort(short[][] dataArray, int size) - { - super(TYPE_USHORT, size, dataArray.length); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data banks, with - * the specified offsets to the first element in each bank. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * @param offsets the offsets to the first element in each data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferUShort(short[][] dataArray, int size, int[] offsets) - { - super(TYPE_USHORT, size, dataArray.length, offsets); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Returns the first data bank. - * - * @return The first data bank. - */ - public short[] getData() - { - return data; - } - - /** - * Returns a data bank. - * - * @param bank the bank index. - * @return A data bank. - */ - public short[] getData(int bank) - { - return bankData[bank]; - } - - /** - * Returns the array underlying this <code>DataBuffer</code>. - * - * @return The data banks. - */ - public short[][] getBankData() - { - return bankData; - } - - /** - * Returns an element from the first data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param i the element index. - * @return The element. - */ - public int getElem(int i) - { - return data[i+offset] & 0xffff; // get unsigned short as int - } - - /** - * Returns an element from a particular data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param bank the bank index. - * @param i the element index. - * @return The element. - */ - public int getElem(int bank, int i) - { - // get unsigned short as int - return bankData[bank][i+offsets[bank]] & 0xffff; - } - - /** - * Sets an element in the first data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int i, int val) - { - data[i+offset] = (short) val; - } - - /** - * Sets an element in a particular data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param bank the data bank index. - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int bank, int i, int val) - { - bankData[bank][i+offsets[bank]] = (short) val; - } -}
--- a/rt/java/awt/image/MultiPixelPackedSampleModel.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,602 +0,0 @@ -/* Copyright (C) 2004, 2006, Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -import gnu.java.awt.Buffers; - -/** - * MultiPixelPackedSampleModel provides a single band model that supports - * multiple pixels in a single unit. Pixels have 2^n bits and 2^k pixels fit - * per data element. - * - * @author Jerry Quinn (jlquinn@optonline.net) - */ -public class MultiPixelPackedSampleModel extends SampleModel -{ - private int scanlineStride; - private int[] bitMasks; - private int[] bitOffsets; - private int[] sampleSize; - private int dataBitOffset; - private int elemBits; - private int numberOfBits; - private int numElems; - - /** - * Creates a new <code>MultiPixelPackedSampleModel</code> with the specified - * data type, which should be one of: - * <ul> - * <li>{@link DataBuffer#TYPE_BYTE};</li> - * <li>{@link DataBuffer#TYPE_USHORT};</li> - * <li>{@link DataBuffer#TYPE_INT};</li> - * </ul> - * - * @param dataType the data type. - * @param w the width (in pixels). - * @param h the height (in pixels). - * @param numberOfBits the number of bits per pixel (must be a power of 2). - */ - public MultiPixelPackedSampleModel(int dataType, int w, int h, - int numberOfBits) - { - this(dataType, w, h, numberOfBits, 0, 0); - } - - /** - * Creates a new <code>MultiPixelPackedSampleModel</code> with the specified - * data type, which should be one of: - * <ul> - * <li>{@link DataBuffer#TYPE_BYTE};</li> - * <li>{@link DataBuffer#TYPE_USHORT};</li> - * <li>{@link DataBuffer#TYPE_INT};</li> - * </ul> - * - * @param dataType the data type. - * @param w the width (in pixels). - * @param h the height (in pixels). - * @param numberOfBits the number of bits per pixel (must be a power of 2). - * @param scanlineStride the number of data elements from a pixel on one - * row to the corresponding pixel in the next row. - * @param dataBitOffset the offset to the first data bit. - */ - public MultiPixelPackedSampleModel(int dataType, int w, int h, - int numberOfBits, int scanlineStride, - int dataBitOffset) - { - super(dataType, w, h, 1); - - switch (dataType) - { - case DataBuffer.TYPE_BYTE: - elemBits = 8; - break; - case DataBuffer.TYPE_USHORT: - elemBits = 16; - break; - case DataBuffer.TYPE_INT: - elemBits = 32; - break; - default: - throw new IllegalArgumentException("MultiPixelPackedSampleModel" - + " unsupported dataType"); - } - - this.dataBitOffset = dataBitOffset; - - this.numberOfBits = numberOfBits; - if (numberOfBits > elemBits) - throw new RasterFormatException("MultiPixelPackedSampleModel pixel size" - + " larger than dataType"); - switch (numberOfBits) - { - case 1: case 2: case 4: case 8: case 16: case 32: break; - default: - throw new RasterFormatException("MultiPixelPackedSampleModel pixel" - + " size not 2^n bits"); - } - numElems = elemBits / numberOfBits; - - // Compute scan line large enough for w pixels. - if (scanlineStride == 0) - scanlineStride = ((dataBitOffset + w * numberOfBits) - 1) / elemBits + 1; - this.scanlineStride = scanlineStride; - - - sampleSize = new int[1]; - sampleSize[0] = numberOfBits; - - bitMasks = new int[numElems]; - bitOffsets = new int[numElems]; - for (int i=0; i < numElems; i++) - { - bitOffsets[numElems - i- 1] = numberOfBits * i; - bitMasks[numElems - i - 1] = ((1 << numberOfBits) - 1) << - bitOffsets[numElems - i - 1]; - } - } - - /** - * Creates a new <code>MultiPixelPackedSample</code> model with the same - * data type and bits per pixel as this model, but with the specified - * dimensions. - * - * @param w the width (in pixels). - * @param h the height (in pixels). - * - * @return The new sample model. - */ - public SampleModel createCompatibleSampleModel(int w, int h) - { - /* FIXME: We can avoid recalculation of bit offsets and sample - sizes here by passing these from the current instance to a - special private constructor. */ - return new MultiPixelPackedSampleModel(dataType, w, h, numberOfBits); - } - - /** - * Creates a DataBuffer for holding pixel data in the format and - * layout described by this SampleModel. The returned buffer will - * consist of one single bank. - * - * @return A new data buffer. - */ - public DataBuffer createDataBuffer() - { - int size = scanlineStride * height; - if (dataBitOffset > 0) - size += (dataBitOffset - 1) / elemBits + 1; - return Buffers.createBuffer(getDataType(), size); - } - - /** - * Returns the number of data elements required to transfer a pixel in the - * get/setDataElements() methods. - * - * @return <code>1</code>. - */ - public int getNumDataElements() - { - return 1; - } - - /** - * Returns an array containing the size (in bits) of the samples in each - * band. The <code>MultiPixelPackedSampleModel</code> class supports only - * one band, so this method returns an array with length <code>1</code>. - * - * @return An array containing the size (in bits) of the samples in band zero. - * - * @see #getSampleSize(int) - */ - public int[] getSampleSize() - { - return (int[]) sampleSize.clone(); - } - - /** - * Returns the size of the samples in the specified band. Note that the - * <code>MultiPixelPackedSampleModel</code> supports only one band -- this - * method ignored the <code>band</code> argument, and always returns the size - * of band zero. - * - * @param band the band (this parameter is ignored). - * - * @return The size of the samples in band zero. - * - * @see #getSampleSize() - */ - public int getSampleSize(int band) - { - return sampleSize[0]; - } - - /** - * Returns the index in the data buffer that stores the pixel at (x, y). - * - * @param x the x-coordinate. - * @param y the y-coordinate. - * - * @return The index in the data buffer that stores the pixel at (x, y). - * - * @see #getBitOffset(int) - */ - public int getOffset(int x, int y) - { - return scanlineStride * y + ((dataBitOffset + x * numberOfBits) / elemBits); - } - - /** - * The bit offset (within an element in the data buffer) of the pixels with - * the specified x-coordinate. - * - * @param x the x-coordinate. - * - * @return The bit offset. - */ - public int getBitOffset(int x) - { - return (dataBitOffset + x * numberOfBits) % elemBits; - } - - /** - * Returns the offset to the first data bit. - * - * @return The offset to the first data bit. - */ - public int getDataBitOffset() - { - return dataBitOffset; - } - - /** - * Returns the number of data elements from a pixel in one row to the - * corresponding pixel in the next row. - * - * @return The scanline stride. - */ - public int getScanlineStride() - { - return scanlineStride; - } - - /** - * Returns the number of bits per pixel. - * - * @return The number of bits per pixel. - */ - public int getPixelBitStride() - { - return numberOfBits; - } - - /** - * Returns the transfer type, which is one of the following (depending on - * the number of bits per sample for this model): - * <ul> - * <li>{@link DataBuffer#TYPE_BYTE};</li> - * <li>{@link DataBuffer#TYPE_USHORT};</li> - * <li>{@link DataBuffer#TYPE_INT};</li> - * </ul> - * - * @return The transfer type. - */ - public int getTransferType() - { - if (numberOfBits <= DataBuffer.getDataTypeSize(DataBuffer.TYPE_BYTE)) - return DataBuffer.TYPE_BYTE; - else if (numberOfBits <= DataBuffer.getDataTypeSize(DataBuffer.TYPE_USHORT)) - return DataBuffer.TYPE_USHORT; - return DataBuffer.TYPE_INT; - } - - /** - * Normally this method returns a sample model for accessing a subset of - * bands of image data, but since <code>MultiPixelPackedSampleModel</code> - * only supports a single band, this overridden implementation just returns - * a new instance of <code>MultiPixelPackedSampleModel</code>, with the same - * attributes as this instance. - * - * @param bands the bands to include in the subset (this is ignored, except - * that if it is non-<code>null</code> a check is made to ensure that the - * array length is equal to <code>1</code>). - * - * @throws RasterFormatException if <code>bands</code> is not - * <code>null</code> and <code>bands.length != 1</code>. - */ - public SampleModel createSubsetSampleModel(int[] bands) - { - if (bands != null && bands.length != 1) - throw new RasterFormatException("MultiPixelPackedSampleModel only" - + " supports one band"); - return new MultiPixelPackedSampleModel(dataType, width, height, - numberOfBits, scanlineStride, dataBitOffset); - } - - /** - * Extract one pixel and return in an array of transfer type. - * - * Extracts the pixel at x, y from data and stores into the 0th index of the - * array obj, since there is only one band. If obj is null, a new array of - * getTransferType() is created. - * - * @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 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, Object, - * DataBuffer) - */ - public Object getDataElements(int x, int y, Object obj, DataBuffer data) - { - int pixel = getSample(x, y, 0, data); - switch (getTransferType()) - { - case DataBuffer.TYPE_BYTE: - if (obj == null) - obj = new byte[1]; - ((byte[]) obj)[0] = (byte) pixel; - return obj; - case DataBuffer.TYPE_USHORT: - if (obj == null) - obj = new short[1]; - ((short[]) obj)[0] = (short) pixel; - return obj; - case DataBuffer.TYPE_INT: - if (obj == null) - obj = new int[1]; - ((int[]) obj)[0] = pixel; - return obj; - default: - // Seems like the only sensible thing to do. - throw new ClassCastException(); - } - } - - /** - * Returns an array (of length 1) containing the sample for the pixel at - * (x, y) in the specified data buffer. If <code>iArray</code> is not - * <code>null</code>, it will be populated with the sample value and - * returned as the result of this function (this avoids allocating a new - * array instance). - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param iArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return An array containing the pixel sample value. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public int[] getPixel(int x, int y, int[] iArray, DataBuffer data) - { - if (iArray == null) - iArray = new int[1]; - iArray[0] = getSample(x, y, 0, data); - return iArray; - } - - /** - * Returns the sample value for the pixel at (x, y) in the specified data - * buffer. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The sample value. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public int getSample(int x, int y, int b, DataBuffer data) - { - int pos = - ((dataBitOffset + x * numberOfBits) % elemBits) / numberOfBits; - int offset = getOffset(x, y); - int samples = data.getElem(offset); - return (samples & bitMasks[pos]) >>> bitOffsets[pos]; - } - - /** - * Set the pixel at x, y to the value in the first element of the primitive - * array obj. - * - * @param x The x-coordinate of the data elements in <code>obj</code>. - * @param y The y-coordinate of the data elements in <code>obj</code>. - * @param obj The primitive array containing the data elements to set. - * @param data The DataBuffer to store the data elements into. - */ - public void setDataElements(int x, int y, Object obj, DataBuffer data) - { - int transferType = getTransferType(); - try - { - switch (transferType) - { - case DataBuffer.TYPE_BYTE: - { - byte[] in = (byte[]) obj; - setSample(x, y, 0, in[0] & 0xFF, data); - return; - } - case DataBuffer.TYPE_USHORT: - { - short[] in = (short[]) obj; - setSample(x, y, 0, in[0] & 0xFFFF, data); - return; - } - case DataBuffer.TYPE_INT: - { - int[] in = (int[]) obj; - setSample(x, y, 0, in[0], data); - return; - } - default: - throw new ClassCastException("Unsupported data type"); - } - } - catch (ArrayIndexOutOfBoundsException aioobe) - { - String msg = "While writing data elements" + - ", x=" + x + ", y=" + y + - ", width=" + width + ", height=" + height + - ", scanlineStride=" + scanlineStride + - ", offset=" + getOffset(x, y) + - ", data.getSize()=" + data.getSize() + - ", data.getOffset()=" + data.getOffset() + - ": " + aioobe; - throw new ArrayIndexOutOfBoundsException(msg); - } - } - - /** - * Sets the sample value for the pixel at (x, y) in the specified data - * buffer to the specified value. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param iArray the sample value (<code>null</code> not permitted). - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if either <code>iArray</code> or - * <code>data</code> is <code>null</code>. - * - * @see #setSample(int, int, int, int, DataBuffer) - */ - public void setPixel(int x, int y, int[] iArray, DataBuffer data) - { - setSample(x, y, 0, iArray[0], data); - } - - /** - * Sets the sample value for a band for the pixel at (x, y) in the - * specified data buffer. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * @param s the sample value. - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public void setSample(int x, int y, int b, int s, DataBuffer data) - { - int bitpos = - ((dataBitOffset + x * numberOfBits) % elemBits) / numberOfBits; - int offset = getOffset(x, y); - - s = s << bitOffsets[bitpos]; - s = s & bitMasks[bitpos]; - - int sample = data.getElem(offset); - sample |= s; - data.setElem(offset, sample); - } - - /** - * Tests this sample model for equality with an arbitrary object. This - * method returns <code>true</code> if and only if: - * <ul> - * <li><code>obj</code> is not <code>null</code>; - * <li><code>obj</code> is an instance of - * <code>MultiPixelPackedSampleModel</code>; - * <li>both models have the same: - * <ul> - * <li><code>dataType</code>; - * <li><code>width</code>; - * <li><code>height</code>; - * <li><code>numberOfBits</code>; - * <li><code>scanlineStride</code>; - * <li><code>dataBitOffsets</code>. - * </ul> - * </li> - * </ul> - * - * @param obj the object (<code>null</code> permitted) - * - * @return <code>true</code> if this model is equal to <code>obj</code>, and - * <code>false</code> otherwise. - */ - public boolean equals(Object obj) - { - if (this == obj) - return true; - if (! (obj instanceof MultiPixelPackedSampleModel)) - return false; - MultiPixelPackedSampleModel that = (MultiPixelPackedSampleModel) obj; - if (this.dataType != that.dataType) - return false; - if (this.width != that.width) - return false; - if (this.height != that.height) - return false; - if (this.numberOfBits != that.numberOfBits) - return false; - if (this.scanlineStride != that.scanlineStride) - return false; - if (this.dataBitOffset != that.dataBitOffset) - return false; - return true; - } - - /** - * Returns a hash code for this <code>MultiPixelPackedSampleModel</code>. - * - * @return A hash code. - */ - public int hashCode() - { - // this hash code won't match Sun's, but that shouldn't matter... - int result = 193; - result = 37 * result + dataType; - result = 37 * result + width; - result = 37 * result + height; - result = 37 * result + numberOfBits; - result = 37 * result + scanlineStride; - result = 37 * result + dataBitOffset; - return result; - } - - /** - * Creates a String with some information about this SampleModel. - * @return A String describing this SampleModel. - * @see java.lang.Object#toString() - */ - public String toString() - { - StringBuffer result = new StringBuffer(); - result.append(getClass().getName()); - result.append("["); - result.append("scanlineStride=").append(scanlineStride); - for(int i=0; i < bitMasks.length; i+=1) - { - result.append(", mask[").append(i).append("]=0x").append(Integer.toHexString(bitMasks[i])); - } - - result.append("]"); - return result.toString(); - } -}
--- a/rt/java/awt/image/Raster.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1156 +0,0 @@ -/* Copyright (C) 2000, 2002, 2003, 2006, Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.Point; -import java.awt.Rectangle; - -import sun.awt.image.ByteBandedRaster; -import sun.awt.image.ByteComponentRaster; -import sun.awt.image.ByteInterleavedRaster; -import sun.awt.image.BytePackedRaster; -import sun.awt.image.IntegerComponentRaster; -import sun.awt.image.IntegerInterleavedRaster; -import sun.awt.image.ShortBandedRaster; -import sun.awt.image.ShortComponentRaster; -import sun.awt.image.ShortInterleavedRaster; -import sun.awt.image.SunWritableRaster; - - -/** - * A rectangular collection of pixels composed from a {@link DataBuffer} which - * stores the pixel values, and a {@link SampleModel} which is used to retrieve - * the pixel values. - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public class Raster -{ - /** The sample model used to access the pixel values. */ - protected SampleModel sampleModel; - - /** The data buffer used to store the pixel values. */ - protected DataBuffer dataBuffer; - - /** The x-coordinate of the top left corner of the raster. */ - protected int minX; - - /** The y-coordinate of the top left corner of the raster. */ - protected int minY; - - /** The width of the raster. */ - protected int width; - - /** The height of the raster. */ - protected int height; - - protected int sampleModelTranslateX; - - protected int sampleModelTranslateY; - - /** The number of bands. */ - protected int numBands; - - protected int numDataElements; - - /** The raster's parent. */ - protected Raster parent; - - static private native void initIDs(); - static - { - ColorModel.loadLibraries(); - initIDs(); - } - - /** - * Creates a new raster. - * - * @param sampleModel the sample model. - * @param origin the origin. - */ - protected Raster(SampleModel sampleModel, Point origin) - { - this(sampleModel, sampleModel.createDataBuffer(), origin); - } - - /** - * Creates a new raster. - * - * @param sampleModel the sample model. - * @param dataBuffer the data buffer. - * @param origin the origin. - */ - protected Raster(SampleModel sampleModel, DataBuffer dataBuffer, - Point origin) - { - this(sampleModel, dataBuffer, new Rectangle(origin.x, origin.y, - sampleModel.getWidth(), sampleModel.getHeight()), origin, null); - } - - /** - * Creates a new raster. - * - * @param sampleModel the sample model. - * @param dataBuffer the data buffer. - * @param aRegion the raster's bounds. - * @param sampleModelTranslate the translation (<code>null</code> permitted). - * @param parent the raster's parent. - */ - protected Raster(SampleModel sampleModel, DataBuffer dataBuffer, - Rectangle aRegion, Point sampleModelTranslate, Raster parent) - { - this.sampleModel = sampleModel; - this.dataBuffer = dataBuffer; - this.minX = aRegion.x; - this.minY = aRegion.y; - this.width = aRegion.width; - this.height = aRegion.height; - - // If sampleModelTranslate is null, use (0,0). Methods such as - // Raster.createRaster are specified to allow for a null argument. - if (sampleModelTranslate != null) - { - this.sampleModelTranslateX = sampleModelTranslate.x; - this.sampleModelTranslateY = sampleModelTranslate.y; - } - - this.numBands = sampleModel.getNumBands(); - this.numDataElements = sampleModel.getNumDataElements(); - this.parent = parent; - } - - /** - * Creates an interleaved raster using the specified data type. - * - * @param dataType the data type. - * @param w the width. - * @param h the height. - * @param bands the number of bands. - * @param location - * - * @return The new raster. - */ - public static WritableRaster createInterleavedRaster(int dataType, - int w, int h, int bands, Point location) - { - int[] bandOffsets = new int[bands]; - // TODO: Maybe not generate this every time. - for (int b = 0; b < bands; b++) - bandOffsets[b] = b; - - int scanlineStride = bands * w; - return createInterleavedRaster(dataType, w, h, scanlineStride, bands, - bandOffsets, location); - } - - /** - * Creates an interleaved raster. - * - * @param dataType the data type. - * @param w the width. - * @param h the height. - * @param scanlineStride the number of data elements from a sample on one - * row to the corresponding sample on the next row. - * @param pixelStride the number of elements from a sample in one pixel to - * the corresponding sample in the next pixel. - * @param bandOffsets the band offsets. - * @param location - * - * @return The new raster. - */ - public static WritableRaster createInterleavedRaster(int dataType, - int w, int h, int scanlineStride, int pixelStride, int[] bandOffsets, - Point location) - { - SampleModel sm = new PixelInterleavedSampleModel(dataType, w, h, pixelStride, - scanlineStride, bandOffsets); - - if (location == null) - location = new Point(0,0); - - if (dataType == DataBuffer.TYPE_BYTE) - return new ByteInterleavedRaster(sm, location); - else if (dataType == DataBuffer.TYPE_SHORT) - return new ShortInterleavedRaster(sm, location); - else - throw new IllegalArgumentException("Data type is not supported."); - } - - /** - * Creates a new banded raster. - * - * @param dataType the data type. - * @param w the width. - * @param h the height. - * @param bands the number of bands. - * @param location - * - * @return The new raster. - */ - public static WritableRaster createBandedRaster(int dataType, int w, int h, - int bands, Point location) - { - SampleModel sm = new BandedSampleModel(dataType, w, h, bands); - - if (location == null) - location = new Point(0,0); - - if (dataType == DataBuffer.TYPE_BYTE) - return new ByteBandedRaster(sm, location); - else if (dataType == DataBuffer.TYPE_USHORT) - return new ShortBandedRaster(sm, location); - else if (dataType == DataBuffer.TYPE_INT) - return new SunWritableRaster(sm, location); - else - throw new IllegalArgumentException("Data type is not supported."); - } - - /** - * Creates a new banded raster. - * - * @param dataType the data type. - * @param w the width. - * @param h the height. - * @param scanlineStride the number of data elements from a sample on one - * row to the corresponding sample on the next row. - * @param bankIndices the index for each bank. - * @param bandOffsets the offset for each band. - * @param location - * - * @return The new raster. - */ - public static WritableRaster createBandedRaster(int dataType, int w, int h, - int scanlineStride, int[] bankIndices, int[] bandOffsets, Point location) - { - SampleModel sm = new BandedSampleModel(dataType, w, h, scanlineStride, - bankIndices, bandOffsets); - - if (location == null) - location = new Point(0,0); - - if (dataType == DataBuffer.TYPE_BYTE) - return new ByteBandedRaster(sm, location); - else if (dataType == DataBuffer.TYPE_USHORT) - return new ShortBandedRaster(sm, location); - else if (dataType == DataBuffer.TYPE_INT) - return new SunWritableRaster(sm, location); - else - throw new IllegalArgumentException("Data type is not supported."); - } - - /** - * Creates a new packed raster. - * - * @param dataType the data type. - * @param w the width. - * @param h the height. - * @param bandMasks the bit mask for each band. - * @param location - * - * @return The new raster. - */ - public static WritableRaster createPackedRaster(int dataType, int w, int h, - int[] bandMasks, Point location) - { - SampleModel sm = new SinglePixelPackedSampleModel(dataType, w, h, - bandMasks); - - if (location == null) - location = new Point(0,0); - - if (dataType == DataBuffer.TYPE_BYTE) - return new ByteInterleavedRaster(sm, location); - else if (dataType == DataBuffer.TYPE_USHORT) - return new ShortInterleavedRaster(sm, location); - else if (dataType == DataBuffer.TYPE_INT) - return new IntegerInterleavedRaster(sm, location); - else - throw new IllegalArgumentException("Data type is not supported."); - } - - /** - * Creates a new raster. - * - * @param dataType the data type. - * @param w the width. - * @param h the height. - * @param bands the number of bands. - * @param bitsPerBand the number of bits per band. - * @param location - * - * @return The new raster. - */ - public static WritableRaster createPackedRaster(int dataType, - int w, int h, int bands, int bitsPerBand, Point location) - { - if (bands <= 0 || (bands * bitsPerBand > getTypeBits(dataType))) - throw new IllegalArgumentException(); - - if (location == null) - location = new Point(0,0); - - if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_USHORT && - dataType != DataBuffer.TYPE_INT) - throw new IllegalArgumentException("Data type is not supported."); - - if (bands == 1) - { - SampleModel sm = new MultiPixelPackedSampleModel(dataType, w, h, bitsPerBand); - - if ((dataType == DataBuffer.TYPE_BYTE) && - (bitsPerBand == 1 || bitsPerBand == 2 || bitsPerBand == 4)) - return new BytePackedRaster(sm, location); - else - return new SunWritableRaster(sm, location); - } - else - { - int[] bandMasks = new int[bands]; - int mask = 0x1; - for (int bits = bitsPerBand; --bits != 0;) - mask = (mask << 1) | 0x1; - for (int i = 0; i < bands; i++) - { - bandMasks[i] = mask; - mask <<= bitsPerBand; - } - - SampleModel sm = new SinglePixelPackedSampleModel(dataType, w, h, bandMasks); - - if (dataType == DataBuffer.TYPE_BYTE) - return new ByteInterleavedRaster(sm, location); - else if (dataType == DataBuffer.TYPE_USHORT) - return new ShortInterleavedRaster(sm, location); - else - return new IntegerInterleavedRaster(sm, location); - } - } - - /** - * Creates a new interleaved raster. - * - * @param dataBuffer the data buffer. - * @param w the width. - * @param h the height. - * @param scanlineStride the number of data elements from a sample on one - * row to the corresponding sample on the next row. - * @param pixelStride the number of elements from a sample in one pixel to - * the corresponding sample in the next pixel. - * @param bandOffsets the offset for each band. - * @param location - * - * @return The new raster. - */ - public static WritableRaster createInterleavedRaster(DataBuffer dataBuffer, - int w, int h, int scanlineStride, int pixelStride, int[] bandOffsets, - Point location) - { - SampleModel sm = new PixelInterleavedSampleModel(dataBuffer.getDataType(), - w, h, pixelStride, scanlineStride, bandOffsets); - - if (location == null) - location = new Point(0,0); - - if (dataBuffer.getDataType() == DataBuffer.TYPE_BYTE) - return new ByteInterleavedRaster(sm, dataBuffer, location); - else if (dataBuffer.getDataType() == DataBuffer.TYPE_USHORT) - return new ShortInterleavedRaster(sm, dataBuffer, location); - else - throw new IllegalArgumentException("Data type is not supported."); - } - - /** - * Creates a new banded raster. - * - * @param dataBuffer the data buffer. - * @param w the width. - * @param h the height. - * @param scanlineStride the number of data elements from a sample on one - * row to the corresponding sample on the next row. - * @param bankIndices the index for each bank. - * @param bandOffsets the band offsets. - * @param location - * - * @return The new raster. - */ - public static WritableRaster createBandedRaster(DataBuffer dataBuffer, - int w, int h, int scanlineStride, int[] bankIndices, int[] bandOffsets, - Point location) - { - SampleModel sm = new BandedSampleModel(dataBuffer.getDataType(), - w, h, scanlineStride, bankIndices, bandOffsets); - - if (location == null) - location = new Point(0,0); - - if (dataBuffer.getDataType() == DataBuffer.TYPE_BYTE) - return new ByteBandedRaster(sm, dataBuffer, location); - else if (dataBuffer.getDataType() == DataBuffer.TYPE_USHORT) - return new ShortBandedRaster(sm, dataBuffer, location); - else if (dataBuffer.getDataType() == DataBuffer.TYPE_INT) - return new SunWritableRaster(sm, dataBuffer, location); - else - throw new IllegalArgumentException("Data type is not supported."); - } - - /** - * Creates a new packed raster. - * - * @param dataBuffer the data buffer. - * @param w the width. - * @param h the height. - * @param scanlineStride the number of data elements from a sample on one - * row to the corresponding sample on the next row. - * @param bandMasks the bit mask for each band. - * @param location - * - * @return The new raster. - */ - public static WritableRaster createPackedRaster(DataBuffer dataBuffer, - int w, int h, int scanlineStride, int[] bandMasks, Point location) - { - SampleModel sm = new SinglePixelPackedSampleModel(dataBuffer.getDataType(), - w, h, scanlineStride, bandMasks); - - if (location == null) - location = new Point(0,0); - - if (dataBuffer.getDataType() == DataBuffer.TYPE_BYTE) - return new ByteInterleavedRaster(sm, dataBuffer, location); - else if (dataBuffer.getDataType() == DataBuffer.TYPE_USHORT) - return new ShortInterleavedRaster(sm, dataBuffer, location); - else if (dataBuffer.getDataType() == DataBuffer.TYPE_INT) - return new IntegerInterleavedRaster(sm, dataBuffer, location); - else - throw new IllegalArgumentException("Data type is not supported."); - } - - /** - * Creates a new packed raster. - * - * @param dataBuffer the data buffer. - * @param w the width. - * @param h the height. - * @param bitsPerPixel the number of bits per pixel. - * @param location - * - * @return The new raster. - */ - public static WritableRaster createPackedRaster(DataBuffer dataBuffer, - int w, int h, int bitsPerPixel, Point location) - { - SampleModel sm = new MultiPixelPackedSampleModel(dataBuffer.getDataType(), - w, h, bitsPerPixel); - - if (location == null) - location = new Point(0,0); - - int dataType = dataBuffer.getDataType(); - if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_USHORT && - dataType != DataBuffer.TYPE_INT) - throw new IllegalArgumentException("Data type is not supported."); - - if ((dataType == DataBuffer.TYPE_BYTE) && - (bitsPerPixel == 1 || bitsPerPixel == 2 || bitsPerPixel == 4)) - return new BytePackedRaster(sm, dataBuffer, location); - else - return new SunWritableRaster(sm, dataBuffer, location); - } - - /** - * Creates a new raster. - * - * @param sm the sample model. - * @param db the data buffer. - * @param location - * - * @return The new raster. - */ - public static Raster createRaster(SampleModel sm, DataBuffer db, - Point location) - { - return new Raster(sm, db, location); - } - - /** - * Creates a new writable raster. - * - * @param sm the sample model. - * @param location - * - * @return The new writable raster. - */ - public static WritableRaster createWritableRaster(SampleModel sm, - Point location) - { - if (sm instanceof PixelInterleavedSampleModel) - { - if (sm.dataType == DataBuffer.TYPE_BYTE) - return new ByteInterleavedRaster(sm, location); - else if (sm.dataType == DataBuffer.TYPE_SHORT) - return new ShortInterleavedRaster(sm, location); - } - else if (sm instanceof BandedSampleModel) - { - if (sm.dataType == DataBuffer.TYPE_BYTE) - return new ByteBandedRaster(sm, location); - else if (sm.dataType == DataBuffer.TYPE_USHORT) - return new ShortBandedRaster(sm, location); - } - else if (sm instanceof SinglePixelPackedSampleModel - || sm instanceof MultiPixelPackedSampleModel) - { - if (sm.numBands == 1) - { - if (sm.dataType == DataBuffer.TYPE_BYTE) - return new BytePackedRaster(sm, location); - } - else - { - if (sm.dataType == DataBuffer.TYPE_BYTE) - return new ByteInterleavedRaster(sm, location); - else if (sm.dataType == DataBuffer.TYPE_USHORT) - return new ShortInterleavedRaster(sm, location); - else if (sm.dataType == DataBuffer.TYPE_INT) - return new IntegerInterleavedRaster(sm, location); - } - } - - return new SunWritableRaster(sm, location); - } - - /** - * Creates a new writable raster. - * - * @param sm the sample model. - * @param db the data buffer. - * @param location - * - * @return The new writable raster. - */ - public static WritableRaster createWritableRaster(SampleModel sm, - DataBuffer db, Point location) - { - if (sm instanceof PixelInterleavedSampleModel) - { - if (sm.dataType == DataBuffer.TYPE_BYTE) - return new ByteInterleavedRaster(sm, db, location); - else if (sm.dataType == DataBuffer.TYPE_SHORT) - return new ShortInterleavedRaster(sm, db, location); - } - else if (sm instanceof BandedSampleModel) - { - if (sm.dataType == DataBuffer.TYPE_BYTE) - return new ByteBandedRaster(sm, db, location); - else if (sm.dataType == DataBuffer.TYPE_USHORT) - return new ShortBandedRaster(sm, db, location); - } - else if (sm instanceof SinglePixelPackedSampleModel - || sm instanceof MultiPixelPackedSampleModel) - { - if (sm.numBands == 1) - { - if (sm.dataType == DataBuffer.TYPE_BYTE) - return new BytePackedRaster(sm, db, location); - } - else - { - if (sm.dataType == DataBuffer.TYPE_BYTE) - return new ByteInterleavedRaster(sm, db, location); - else if (sm.dataType == DataBuffer.TYPE_USHORT) - return new ShortInterleavedRaster(sm, db, location); - else if (sm.dataType == DataBuffer.TYPE_INT) - return new IntegerInterleavedRaster(sm, db, location); - } - } - - return new SunWritableRaster(sm, db, location); - } - - /** - * Returns the raster's parent. - * - * @return The raster's parent. - */ - public Raster getParent() - { - return parent; - } - - /** - * Returns the x-translation. - * - * @return The x-translation. - */ - public final int getSampleModelTranslateX() - { - return sampleModelTranslateX; - } - - /** - * Returns the y-translation. - * - * @return The y-translation. - */ - public final int getSampleModelTranslateY() - { - return sampleModelTranslateY; - } - - /** - * Creates a new writable raster that is compatible with this raster. - * - * @return A new writable raster. - */ - public WritableRaster createCompatibleWritableRaster() - { - return new SunWritableRaster(getSampleModel(), new Point(minX, minY)); - } - - /** - * Creates a new writable raster that is compatible with this raster. - * - * @param w the width. - * @param h the height. - * - * @return A new writable raster. - */ - public WritableRaster createCompatibleWritableRaster(int w, int h) - { - return createCompatibleWritableRaster(minX, minY, w, h); - } - - /** - * Creates a new writable raster that is compatible with this raster, with - * the specified bounds. - * - * @param rect the raster bounds. - * - * @return A new writable raster. - */ - public WritableRaster createCompatibleWritableRaster(Rectangle rect) - { - return createCompatibleWritableRaster(rect.x, rect.y, - rect.width, rect.height); - } - - /** - * Creates a new writable raster that is compatible with this raster, with - * the specified bounds. - * - * @param x the x-coordinate of the top-left corner of the raster. - * @param y the y-coordinate of the top-left corner of the raster. - * @param w the raster width. - * @param h the raster height. - * - * @return A new writable raster. - */ - public WritableRaster createCompatibleWritableRaster(int x, int y, - int w, int h) - { - SampleModel sm = getSampleModel().createCompatibleSampleModel(w, h); - return new SunWritableRaster(sm, sm.createDataBuffer(), new Point(x, y)); - } - - public Raster createTranslatedChild(int childMinX, int childMinY) { - return createChild(minX, minY, width, height, childMinX, childMinY, null); - } - - public Raster createChild(int parentX, int parentY, int width, - int height, int childMinX, int childMinY, - int[] bandList) - { - if (parentX < minX || parentX + width > minX + this.width - || parentY < minY || parentY + height > minY + this.height) - throw new RasterFormatException("Child raster extends beyond parent"); - - SampleModel sm = (bandList == null) ? - sampleModel : - sampleModel.createSubsetSampleModel(bandList); - - /* - data origin - / - +------------------------- - |\. __ parent trans - | \`. - | \ `. parent origin - | \ `. / - | /\ +-------- - - - |trans\ /<\-- deltaTrans - |child +-+-\---- - - - | /|`| \__ parent [x, y] - |child | |`. \ - |origin| : `.\ - | | / `\ - | : / + - | child [x, y] - - parent_xy - parent_trans = child_xy - child_trans - - child_trans = parent_trans + child_xy - parent_xy - */ - - return new Raster(sm, dataBuffer, - new Rectangle(childMinX, childMinY, width, height), - new Point(sampleModelTranslateX + childMinX - parentX, - sampleModelTranslateY + childMinY - parentY), - this); - } - - /** - * Returns a new rectangle containing the bounds of this raster. - * - * @return A new rectangle containing the bounds of this raster. - */ - public Rectangle getBounds() - { - return new Rectangle(minX, minY, width, height); - } - - /** - * Returns the x-coordinate of the top left corner of the raster. - * - * @return The x-coordinate of the top left corner of the raster. - */ - public final int getMinX() - { - return minX; - } - - /** - * Returns the t-coordinate of the top left corner of the raster. - * - * @return The t-coordinate of the top left corner of the raster. - */ - public final int getMinY() - { - return minY; - } - - /** - * Returns the width of the raster. - * - * @return The width of the raster. - */ - public final int getWidth() - { - return width; - } - - /** - * Returns the height of the raster. - * - * @return The height of the raster. - */ - public final int getHeight() - { - return height; - } - - /** - * Returns the number of bands for this raster. - * - * @return The number of bands. - */ - public final int getNumBands() - { - return numBands; - } - - public final int getNumDataElements() - { - return numDataElements; - } - - /** - * Returns the transfer type for the raster (this is determined by the - * raster's sample model). - * - * @return The transfer type. - */ - public final int getTransferType() - { - return sampleModel.getTransferType(); - } - - /** - * Returns the data buffer that stores the pixel data for this raster. - * - * @return The data buffer. - */ - public DataBuffer getDataBuffer() - { - return dataBuffer; - } - - /** - * Returns the sample model that accesses the data buffer (to extract pixel - * data) for this raster. - * - * @return The sample model. - */ - public SampleModel getSampleModel() - { - return sampleModel; - } - - public Object getDataElements(int x, int y, Object outData) - { - return sampleModel.getDataElements(x - sampleModelTranslateX, - y - sampleModelTranslateY, outData, dataBuffer); - } - - public Object getDataElements(int x, int y, int w, int h, Object outData) - { - return sampleModel.getDataElements(x - sampleModelTranslateX, - y - sampleModelTranslateY, w, h, outData, dataBuffer); - } - - /** - * Returns an array containing the samples for the pixel at (x, y) in the - * raster. If <code>iArray</code> is not <code>null</code>, it will be - * populated with the sample values and returned as the result of - * this function (this avoids allocating a new array instance). - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param iArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * - * @return The pixel sample values. - */ - public int[] getPixel(int x, int y, int[] iArray) - { - return sampleModel.getPixel(x - sampleModelTranslateX, - y - sampleModelTranslateY, iArray, dataBuffer); - } - - /** - * Returns an array containing the samples for the pixel at (x, y) in the - * raster. If <code>fArray</code> is not <code>null</code>, it will be - * populated with the sample values and returned as the result of - * this function (this avoids allocating a new array instance). - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param fArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * - * @return The pixel sample values. - */ - public float[] getPixel(int x, int y, float[] fArray) - { - return sampleModel.getPixel(x - sampleModelTranslateX, - y - sampleModelTranslateY, fArray, dataBuffer); - } - - /** - * Returns an array containing the samples for the pixel at (x, y) in the - * raster. If <code>dArray</code> is not <code>null</code>, it will be - * populated with the sample values and returned as the result of - * this function (this avoids allocating a new array instance). - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param dArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * - * @return The pixel sample values. - */ - public double[] getPixel(int x, int y, double[] dArray) - { - return sampleModel.getPixel(x - sampleModelTranslateX, - y - sampleModelTranslateY, dArray, dataBuffer); - } - - /** - * Returns an array containing the samples for the pixels in the region - * specified by (x, y, w, h) in the raster. The array is ordered by pixels - * (that is, all the samples for the first pixel are grouped together, - * followed by all the samples for the second pixel, and so on). - * If <code>iArray</code> is not <code>null</code>, it will be populated - * with the sample values and returned as the result of this function (this - * avoids allocating a new array instance). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param iArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * - * @return The pixel sample values. - */ - public int[] getPixels(int x, int y, int w, int h, int[] iArray) - { - return sampleModel.getPixels(x - sampleModelTranslateX, - y - sampleModelTranslateY, w, h, iArray, dataBuffer); - } - - /** - * Returns an array containing the samples for the pixels in the region - * specified by (x, y, w, h) in the raster. The array is ordered by pixels - * (that is, all the samples for the first pixel are grouped together, - * followed by all the samples for the second pixel, and so on). - * If <code>fArray</code> is not <code>null</code>, it will be populated - * with the sample values and returned as the result of this function (this - * avoids allocating a new array instance). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param fArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * - * @return The pixel sample values. - */ - public float[] getPixels(int x, int y, int w, int h, float[] fArray) - { - return sampleModel.getPixels(x - sampleModelTranslateX, - y - sampleModelTranslateY, w, h, fArray, dataBuffer); - } - - /** - * Returns an array containing the samples for the pixels in the region - * specified by (x, y, w, h) in the raster. The array is ordered by pixels - * (that is, all the samples for the first pixel are grouped together, - * followed by all the samples for the second pixel, and so on). - * If <code>dArray</code> is not <code>null</code>, it will be populated - * with the sample values and returned as the result of this function (this - * avoids allocating a new array instance). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param dArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * - * @return The pixel sample values. - */ - public double[] getPixels(int x, int y, int w, int h, double[] dArray) - { - return sampleModel.getPixels(x - sampleModelTranslateX, - y - sampleModelTranslateY, w, h, dArray, dataBuffer); - } - - /** - * Returns the sample value for the pixel at (x, y) in the raster. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * - * @return The sample value. - */ - public int getSample(int x, int y, int b) - { - return sampleModel.getSample(x - sampleModelTranslateX, - y - sampleModelTranslateY, b, dataBuffer); - } - - /** - * Returns the sample value for the pixel at (x, y) in the raster. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * - * @return The sample value. - * - * @see #getSample(int, int, int) - */ - public float getSampleFloat(int x, int y, int b) - { - return sampleModel.getSampleFloat(x - sampleModelTranslateX, - y - sampleModelTranslateY, b, dataBuffer); - } - - /** - * Returns the sample value for the pixel at (x, y) in the raster. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * - * @return The sample value. - * - * @see #getSample(int, int, int) - */ - public double getSampleDouble(int x, int y, int b) - { - return sampleModel.getSampleDouble(x - sampleModelTranslateX, - y - sampleModelTranslateY, b, dataBuffer); - } - - /** - * Returns an array containing the samples from one band for the pixels in - * the region specified by (x, y, w, h) in the raster. If - * <code>iArray</code> is not <code>null</code>, it will be - * populated with the sample values and returned as the result of this - * function (this avoids allocating a new array instance). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param b the band (in the range <code>0</code> to - * </code>getNumBands() - 1</code>). - * @param iArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * - * @return The sample values. - */ - public int[] getSamples(int x, int y, int w, int h, int b, - int[] iArray) - { - return sampleModel.getSamples(x - sampleModelTranslateX, - y - sampleModelTranslateY, w, h, b, iArray, dataBuffer); - } - - /** - * Returns an array containing the samples from one band for the pixels in - * the region specified by (x, y, w, h) in the raster. If - * <code>fArray</code> is not <code>null</code>, it will be - * populated with the sample values and returned as the result of this - * function (this avoids allocating a new array instance). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param b the band (in the range <code>0</code> to - * </code>getNumBands() - 1</code>). - * @param fArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * - * @return The sample values. - */ - public float[] getSamples(int x, int y, int w, int h, int b, float[] fArray) - { - return sampleModel.getSamples(x - sampleModelTranslateX, - y - sampleModelTranslateY, w, h, b, fArray, dataBuffer); - } - - /** - * Returns an array containing the samples from one band for the pixels in - * the region specified by (x, y, w, h) in the raster. If - * <code>dArray</code> is not <code>null</code>, it will be - * populated with the sample values and returned as the result of this - * function (this avoids allocating a new array instance). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param b the band (in the range <code>0</code> to - * </code>getNumBands() - 1</code>). - * @param dArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * - * @return The sample values. - */ - public double[] getSamples(int x, int y, int w, int h, int b, - double[] dArray) - { - return sampleModel.getSamples(x - sampleModelTranslateX, - y - sampleModelTranslateY, w, h, b, dArray, dataBuffer); - } - - /** - * Create a String representing the state of this Raster. - * - * @return A String representing the stat of this Raster. - */ - public String toString() - { - StringBuffer result = new StringBuffer(); - - result.append(getClass().getName()); - result.append("[("); - result.append(minX).append(",").append(minY).append("), "); - result.append(width).append(" x ").append(height).append(","); - result.append(sampleModel).append(","); - result.append(dataBuffer); - result.append("]"); - - return result.toString(); - } - - /** - * Returns the number of bits used to represent the specified data type. - * Valid types are: - * <ul> - * <li>{@link DataBuffer#TYPE_BYTE};</li> - * <li>{@link DataBuffer#TYPE_USHORT};</li> - * <li>{@link DataBuffer#TYPE_SHORT};</li> - * <li>{@link DataBuffer#TYPE_INT};</li> - * <li>{@link DataBuffer#TYPE_FLOAT};</li> - * <li>{@link DataBuffer#TYPE_DOUBLE};</li> - * </ul> - * This method returns 0 for invalid data types. - * - * @param dataType the data type. - * - * @return The number of bits used to represent the specified data type. - */ - private static int getTypeBits(int dataType) - { - switch (dataType) - { - case DataBuffer.TYPE_BYTE: - return 8; - case DataBuffer.TYPE_USHORT: - case DataBuffer.TYPE_SHORT: - return 16; - case DataBuffer.TYPE_INT: - case DataBuffer.TYPE_FLOAT: - return 32; - case DataBuffer.TYPE_DOUBLE: - return 64; - default: - return 0; - } - } -}
--- a/rt/java/awt/image/RenderedImage.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/* RenderedImage.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.Rectangle; -import java.util.Vector; - -/** - * NEEDS DOCUMENTATION - */ -public interface RenderedImage -{ - Vector<RenderedImage> getSources(); - Object getProperty(String name); - String[] getPropertyNames(); - ColorModel getColorModel(); - SampleModel getSampleModel(); - int getWidth(); - int getHeight(); - int getMinX(); - int getMinY(); - int getNumXTiles(); - int getNumYTiles(); - int getMinTileX(); - int getMinTileY(); - int getTileWidth(); - int getTileHeight(); - int getTileGridXOffset(); - int getTileGridYOffset(); - Raster getTile(int x, int y); - Raster getData(); - Raster getData(Rectangle r); - WritableRaster copyData(WritableRaster raster); -} // interface RenderedImage
--- a/rt/java/awt/image/SampleModel.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,981 +0,0 @@ -/* Copyright (C) 2000, 2001, 2002, 2005, 2006, Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -/** - * A <code>SampleModel</code> is used to access pixel data from a - * {@link DataBuffer}. This is used by the {@link Raster} class. - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public abstract class SampleModel -{ - /** Width of image described. */ - protected int width; - - /** Height of image described. */ - protected int height; - - /** Number of bands in the image described. Package-private here, - shadowed by ComponentSampleModel. */ - protected int numBands; - - /** - * The DataBuffer type that is used to store the data of the image - * described. - */ - protected int dataType; - - static private native void initIDs(); - static - { - ColorModel.loadLibraries(); - initIDs(); - } - - /** - * Creates a new sample model with the specified attributes. - * - * @param dataType the data type (one of {@link DataBuffer#TYPE_BYTE}, - * {@link DataBuffer#TYPE_USHORT}, {@link DataBuffer#TYPE_SHORT}, - * {@link DataBuffer#TYPE_INT}, {@link DataBuffer#TYPE_FLOAT}, - * {@link DataBuffer#TYPE_DOUBLE} or {@link DataBuffer#TYPE_UNDEFINED}). - * @param w the width in pixels (must be greater than zero). - * @param h the height in pixels (must be greater than zero). - * @param numBands the number of bands (must be greater than zero). - * - * @throws IllegalArgumentException if <code>dataType</code> is not one of - * the listed values. - * @throws IllegalArgumentException if <code>w</code> is less than or equal - * to zero. - * @throws IllegalArgumentException if <code>h</code> is less than or equal - * to zero. - * @throws IllegalArgumentException if <code>w * h</code> is greater than - * {@link Integer#MAX_VALUE}. - */ - public SampleModel(int dataType, int w, int h, int numBands) - { - if (dataType != DataBuffer.TYPE_UNDEFINED) - if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_DOUBLE) - throw new IllegalArgumentException("Unrecognised 'dataType' argument."); - - if ((w <= 0) || (h <= 0)) - throw new IllegalArgumentException((w <= 0 ? " width<=0" : " width is ok") - + (h <= 0 ? " height<=0" : " height is ok")); - - long area = (long) w * (long) h; - if (area > Integer.MAX_VALUE) - throw new IllegalArgumentException("w * h exceeds Integer.MAX_VALUE."); - - if (numBands <= 0) - throw new IllegalArgumentException("Requires numBands > 0."); - - this.dataType = dataType; - this.width = w; - this.height = h; - this.numBands = numBands; - } - - /** - * Returns the width of the pixel data accessible via this - * <code>SampleModel</code>. - * - * @return The width. - * - * @see #getHeight() - */ - public final int getWidth() - { - return width; - } - - /** - * Returns the height of the pixel data accessible via this - * <code>SampleModel</code>. - * - * @return The height. - * - * @see #getWidth() - */ - public final int getHeight() - { - return height; - } - - /** - * Returns the number of bands for this <code>SampleModel</code>. - * - * @return The number of bands. - */ - public final int getNumBands() - { - return numBands; - } - - public abstract int getNumDataElements(); - - /** - * Returns the type of the {@link DataBuffer} that this - * <code>SampleModel</code> accesses. - * - * @return The data buffer type. - */ - public final int getDataType() - { - return dataType; - } - - public int getTransferType() - { - // FIXME: Is this a reasonable default implementation? - return dataType; - } - - /** - * Returns an array containing the samples for the pixel at (x, y) in the - * specified data buffer. If <code>iArray</code> is not <code>null</code>, - * it will be populated with the sample values and returned as the result of - * this function (this avoids allocating a new array instance). - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param iArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The pixel sample values. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public int[] getPixel(int x, int y, int[] iArray, DataBuffer data) - { - if (iArray == null) - iArray = new int[numBands]; - for (int b = 0; b < numBands; b++) - iArray[b] = getSample(x, y, b, data); - return iArray; - } - - /** - * - * This method is provided as a faster alternative to getPixel(), - * that can be used when there is no need to decode the pixel into - * separate sample values. - * - * @param obj An array to return the pixel data in. If null, an - * array of the right type and size will be created. - * - * @return A single pixel as an array object of a primitive type, - * based on the transfer type. Eg. if transfer type is - * DataBuffer.TYPE_USHORT, then a short[] object is returned. - */ - public abstract Object getDataElements(int x, int y, Object obj, - DataBuffer data); - - - public Object getDataElements(int x, int y, int w, int h, Object obj, - DataBuffer data) - { - int size = w * h; - int numDataElements = getNumDataElements(); - int dataSize = numDataElements * size; - - if (obj == null) - { - switch (getTransferType()) - { - case DataBuffer.TYPE_BYTE: - obj = new byte[dataSize]; - break; - case DataBuffer.TYPE_USHORT: - obj = new short[dataSize]; - break; - case DataBuffer.TYPE_INT: - obj = new int[dataSize]; - break; - default: - // Seems like the only sensible thing to do. - throw new ClassCastException(); - } - } - Object pixelData = null; - int outOffset = 0; - for (int yy = y; yy < (y + h); yy++) - { - for (int xx = x; xx < (x + w); xx++) - { - pixelData = getDataElements(xx, yy, pixelData, data); - System.arraycopy(pixelData, 0, obj, outOffset, - numDataElements); - outOffset += numDataElements; - } - } - return obj; - } - - public abstract void setDataElements(int x, int y, Object obj, - DataBuffer data); - - public void setDataElements(int x, int y, int w, int h, - Object obj, DataBuffer data) - { - int numDataElements = getNumDataElements(); - - Object pixelData; - switch (getTransferType()) - { - case DataBuffer.TYPE_BYTE: - pixelData = new byte[numDataElements]; - break; - case DataBuffer.TYPE_USHORT: - case DataBuffer.TYPE_SHORT: - pixelData = new short[numDataElements]; - break; - case DataBuffer.TYPE_INT: - pixelData = new int[numDataElements]; - break; - case DataBuffer.TYPE_FLOAT: - pixelData = new float[numDataElements]; - break; - case DataBuffer.TYPE_DOUBLE: - pixelData = new double[numDataElements]; - break; - default: - // The RI silently igores invalid types. - pixelData = null; - } - - int inOffset = 0; - if (pixelData != null) - { - for (int yy=y; yy<(y+h); yy++) - { - for (int xx=x; xx<(x+w); xx++) - { - System.arraycopy(obj, inOffset, pixelData, 0, numDataElements); - setDataElements(xx, yy, pixelData, data); - inOffset += numDataElements; - } - } - } - } - - /** - * Returns an array containing the samples for the pixel at (x, y) in the - * specified data buffer. If <code>fArray</code> is not <code>null</code>, - * it will be populated with the sample values and returned as the result of - * this function (this avoids allocating a new array instance). - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param fArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The pixel sample values. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public float[] getPixel(int x, int y, float[] fArray, DataBuffer data) - { - if (fArray == null) - fArray = new float[numBands]; - - for (int b = 0; b < numBands; b++) - { - fArray[b] = getSampleFloat(x, y, b, data); - } - return fArray; - } - - /** - * Returns an array containing the samples for the pixel at (x, y) in the - * specified data buffer. If <code>dArray</code> is not <code>null</code>, - * it will be populated with the sample values and returned as the result of - * this function (this avoids allocating a new array instance). - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param dArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The pixel sample values. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public double[] getPixel(int x, int y, double[] dArray, DataBuffer data) { - if (dArray == null) - dArray = new double[numBands]; - for (int b = 0; b < numBands; b++) - { - dArray[b] = getSampleDouble(x, y, b, data); - } - return dArray; - } - - /** - * Returns an array containing the samples for the pixels in the region - * specified by (x, y, w, h) in the specified data buffer. The array is - * ordered by pixels (that is, all the samples for the first pixel are - * grouped together, followed by all the samples for the second pixel, and so - * on). If <code>iArray</code> is not <code>null</code>, it will be - * populated with the sample values and returned as the result of this - * function (this avoids allocating a new array instance). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param iArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The pixel sample values. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public int[] getPixels(int x, int y, int w, int h, int[] iArray, - DataBuffer data) - { - int size = w * h; - int outOffset = 0; - int[] pixel = null; - if (iArray == null) - iArray = new int[w * h * numBands]; - for (int yy = y; yy < (y + h); yy++) - { - for (int xx = x; xx < (x + w); xx++) - { - pixel = getPixel(xx, yy, pixel, data); - System.arraycopy(pixel, 0, iArray, outOffset, numBands); - outOffset += numBands; - } - } - return iArray; - } - - /** - * Returns an array containing the samples for the pixels in the region - * specified by (x, y, w, h) in the specified data buffer. The array is - * ordered by pixels (that is, all the samples for the first pixel are - * grouped together, followed by all the samples for the second pixel, and so - * on). If <code>fArray</code> is not <code>null</code>, it will be - * populated with the sample values and returned as the result of this - * function (this avoids allocating a new array instance). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param fArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The pixel sample values. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public float[] getPixels(int x, int y, int w, int h, float[] fArray, - DataBuffer data) - { - int size = w * h; - int outOffset = 0; - float[] pixel = null; - if (fArray == null) fArray = new float[w * h * numBands]; - for (int yy = y; yy < (y + h); yy++) - { - for (int xx = x; xx < (x + w); xx++) - { - pixel = getPixel(xx, yy, pixel, data); - System.arraycopy(pixel, 0, fArray, outOffset, numBands); - outOffset += numBands; - } - } - return fArray; - } - - /** - * Returns an array containing the samples for the pixels in the region - * specified by (x, y, w, h) in the specified data buffer. The array is - * ordered by pixels (that is, all the samples for the first pixel are - * grouped together, followed by all the samples for the second pixel, and so - * on). If <code>dArray</code> is not <code>null</code>, it will be - * populated with the sample values and returned as the result of this - * function (this avoids allocating a new array instance). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param dArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The pixel sample values. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public double[] getPixels(int x, int y, int w, int h, double[] dArray, - DataBuffer data) - { - int size = w * h; - int outOffset = 0; - double[] pixel = null; - if (dArray == null) - dArray = new double[w * h * numBands]; - for (int yy = y; yy < (y + h); yy++) - { - for (int xx = x; xx < (x + w); xx++) - { - pixel = getPixel(xx, yy, pixel, data); - System.arraycopy(pixel, 0, dArray, outOffset, numBands); - outOffset += numBands; - } - } - return dArray; - } - - /** - * Returns the sample value for the pixel at (x, y) in the specified data - * buffer. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The sample value. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public abstract int getSample(int x, int y, int b, DataBuffer data); - - /** - * Returns the sample value for the pixel at (x, y) in the specified data - * buffer. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The sample value. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - * - * @see #getSample(int, int, int, DataBuffer) - */ - public float getSampleFloat(int x, int y, int b, DataBuffer data) - { - return getSample(x, y, b, data); - } - - /** - * Returns the sample value for the pixel at (x, y) in the specified data - * buffer. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The sample value. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - * - * @see #getSample(int, int, int, DataBuffer) - */ - public double getSampleDouble(int x, int y, int b, DataBuffer data) - { - return getSampleFloat(x, y, b, data); - } - - /** - * Returns an array containing the samples from one band for the pixels in - * the region specified by (x, y, w, h) in the specified data buffer. If - * <code>iArray</code> is not <code>null</code>, it will be - * populated with the sample values and returned as the result of this - * function (this avoids allocating a new array instance). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param b the band (in the range <code>0</code> to - * </code>getNumBands() - 1</code>). - * @param iArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The sample values. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public int[] getSamples(int x, int y, int w, int h, int b, - int[] iArray, DataBuffer data) - { - int size = w * h; - int outOffset = 0; - if (iArray == null) - iArray = new int[size]; - for (int yy = y; yy < (y + h); yy++) - { - for (int xx = x; xx < (x + w); xx++) - { - iArray[outOffset++] = getSample(xx, yy, b, data); - } - } - return iArray; - } - - /** - * Returns an array containing the samples from one band for the pixels in - * the region specified by (x, y, w, h) in the specified data buffer. If - * <code>fArray</code> is not <code>null</code>, it will be - * populated with the sample values and returned as the result of this - * function (this avoids allocating a new array instance). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param b the band (in the range <code>0</code> to - * </code>getNumBands() - 1</code>). - * @param fArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The sample values. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public float[] getSamples(int x, int y, int w, int h, int b, - float[] fArray, DataBuffer data) - { - int size = w * h; - int outOffset = 0; - if (fArray == null) - fArray = new float[size]; - for (int yy = y; yy < (y + h); yy++) - { - for (int xx = x; xx < (x + w); xx++) - { - fArray[outOffset++] = getSampleFloat(xx, yy, b, data); - } - } - return fArray; - } - - /** - * Returns an array containing the samples from one band for the pixels in - * the region specified by (x, y, w, h) in the specified data buffer. If - * <code>dArray</code> is not <code>null</code>, it will be - * populated with the sample values and returned as the result of this - * function (this avoids allocating a new array instance). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param b the band (in the range <code>0</code> to - * </code>getNumBands() - 1</code>). - * @param dArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The sample values. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public double[] getSamples(int x, int y, int w, int h, int b, - double[] dArray, DataBuffer data) - { - int size = w * h; - int outOffset = 0; - if (dArray == null) - dArray = new double[size]; - for (int yy = y; yy < (y + h); yy++) - { - for (int xx = x; xx < (x + w); xx++) - { - dArray[outOffset++] = getSampleDouble(xx, yy, b, data); - } - } - return dArray; - } - - /** - * Sets the samples for the pixel at (x, y) in the specified data buffer to - * the specified values. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param iArray the sample values (<code>null</code> not permitted). - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if either <code>iArray</code> or - * <code>data</code> is <code>null</code>. - */ - public void setPixel(int x, int y, int[] iArray, DataBuffer data) - { - for (int b = 0; b < numBands; b++) - setSample(x, y, b, iArray[b], data); - } - - /** - * Sets the samples for the pixel at (x, y) in the specified data buffer to - * the specified values. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param fArray the sample values (<code>null</code> not permitted). - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if either <code>fArray</code> or - * <code>data</code> is <code>null</code>. - */ - public void setPixel(int x, int y, float[] fArray, DataBuffer data) - { - for (int b = 0; b < numBands; b++) - setSample(x, y, b, fArray[b], data); - } - - /** - * Sets the samples for the pixel at (x, y) in the specified data buffer to - * the specified values. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param dArray the sample values (<code>null</code> not permitted). - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if either <code>dArray</code> or - * <code>data</code> is <code>null</code>. - */ - public void setPixel(int x, int y, double[] dArray, DataBuffer data) - { - for (int b = 0; b < numBands; b++) - setSample(x, y, b, dArray[b], data); - } - - /** - * Sets the sample values for the pixels in the region specified by - * (x, y, w, h) in the specified data buffer. The array is - * ordered by pixels (that is, all the samples for the first pixel are - * grouped together, followed by all the samples for the second pixel, and so - * on). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param iArray the pixel sample values (<code>null</code> not permitted). - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if either <code>iArray</code> or - * <code>data</code> is <code>null</code>. - */ - 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++) - { - for (int xx = x; xx < (x + w); xx++) - { - System.arraycopy(iArray, inOffset, pixel, 0, numBands); - setPixel(xx, yy, pixel, data); - inOffset += numBands; - } - } - } - - /** - * Sets the sample values for the pixels in the region specified by - * (x, y, w, h) in the specified data buffer. The array is - * ordered by pixels (that is, all the samples for the first pixel are - * grouped together, followed by all the samples for the second pixel, and so - * on). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param fArray the pixel sample values (<code>null</code> not permitted). - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if either <code>fArray</code> or - * <code>data</code> is <code>null</code>. - */ - public void setPixels(int x, int y, int w, int h, float[] fArray, - DataBuffer data) - { - int inOffset = 0; - float[] pixel = new float[numBands]; - for (int yy = y; yy < (y + h); yy++) - { - for (int xx = x; xx < (x + w); xx++) - { - System.arraycopy(fArray, inOffset, pixel, 0, numBands); - setPixel(xx, yy, pixel, data); - inOffset += numBands; - } - } - } - - /** - * Sets the sample values for the pixels in the region specified by - * (x, y, w, h) in the specified data buffer. The array is - * ordered by pixels (that is, all the samples for the first pixel are - * grouped together, followed by all the samples for the second pixel, and so - * on). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param dArray the pixel sample values (<code>null</code> not permitted). - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if either <code>dArray</code> or - * <code>data</code> is <code>null</code>. - */ - public void setPixels(int x, int y, int w, int h, double[] dArray, - DataBuffer data) - { - int inOffset = 0; - double[] pixel = new double[numBands]; - for (int yy = y; yy < (y + h); yy++) - { - for (int xx = x; xx < (x + w); xx++) - { - System.arraycopy(dArray, inOffset, pixel, 0, numBands); - setPixel(xx, yy, pixel, data); - inOffset += numBands; - } - } - } - - /** - * Sets the sample value for a band for the pixel at (x, y) in the - * specified data buffer. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * @param s the sample value. - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public abstract void setSample(int x, int y, int b, int s, - DataBuffer data); - - /** - * Sets the sample value for a band for the pixel at (x, y) in the - * specified data buffer. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * @param s the sample value. - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public void setSample(int x, int y, int b, float s, - DataBuffer data) - { - setSample(x, y, b, (int) s, data); - } - - /** - * Sets the sample value for a band for the pixel at (x, y) in the - * specified data buffer. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * @param s the sample value. - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public void setSample(int x, int y, int b, double s, - DataBuffer data) - { - setSample(x, y, b, (float) s, data); - } - - /** - * Sets the sample values for one band for the pixels in the region - * specified by (x, y, w, h) in the specified data buffer. - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param b the band (in the range <code>0</code> to - * </code>getNumBands() - 1</code>). - * @param iArray the sample values (<code>null</code> not permitted). - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if either <code>iArray</code> or - * <code>data</code> is <code>null</code>. - */ - public void setSamples(int x, int y, int w, int h, int b, - int[] iArray, DataBuffer data) - { - int size = w * h; - int inOffset = 0; - for (int yy = y; yy < (y + h); yy++) - for (int xx = x; xx < (x + w); xx++) - setSample(xx, yy, b, iArray[inOffset++], data); - } - - /** - * Sets the sample values for one band for the pixels in the region - * specified by (x, y, w, h) in the specified data buffer. - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param b the band (in the range <code>0</code> to - * </code>getNumBands() - 1</code>). - * @param fArray the sample values (<code>null</code> not permitted). - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if either <code>iArray</code> or - * <code>data</code> is <code>null</code>. - */ - public void setSamples(int x, int y, int w, int h, int b, - float[] fArray, DataBuffer data) - { - int size = w * h; - int inOffset = 0; - for (int yy = y; yy < (y + h); yy++) - for (int xx = x; xx < (x + w); xx++) - setSample(xx, yy, b, fArray[inOffset++], data); - - } - - /** - * Sets the sample values for one band for the pixels in the region - * specified by (x, y, w, h) in the specified data buffer. - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param b the band (in the range <code>0</code> to - * </code>getNumBands() - 1</code>). - * @param dArray the sample values (<code>null</code> not permitted). - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if either <code>iArray</code> or - * <code>data</code> is <code>null</code>. - */ - public void setSamples(int x, int y, int w, int h, int b, - double[] dArray, DataBuffer data) { - int size = w * h; - int inOffset = 0; - for (int yy = y; yy < (y + h); yy++) - for (int xx = x; xx < (x + w); xx++) - setSample(xx, yy, b, dArray[inOffset++], data); - } - - /** - * Creates a new <code>SampleModel</code> that is compatible with this - * model and has the specified width and height. - * - * @param w the width (in pixels). - * @param h the height (in pixels). - * - * @return The new sample model. - */ - public abstract SampleModel createCompatibleSampleModel(int w, int h); - - /** - * Return a SampleModel with a subset of the bands in this model. - * - * Selects bands.length bands from this sample model. The bands chosen - * are specified in the indices of bands[]. This also permits permuting - * the bands as well as taking a subset. Thus, giving an array with - * 1, 2, 3, ..., numbands, will give an identical sample model. - * - * @param bands Array with band indices to include. - * @return A new sample model - */ - public abstract SampleModel createSubsetSampleModel(int[] bands); - - /** - * Creates a new {@link DataBuffer} of the correct type and size for this - * <code>SampleModel</code>. - * - * @return The data buffer. - */ - public abstract DataBuffer createDataBuffer(); - - /** - * Returns an array containing the size (in bits) for each band accessed by - * the <code>SampleModel</code>. - * - * @return An array. - * - * @see #getSampleSize(int) - */ - public abstract int[] getSampleSize(); - - /** - * Returns the size (in bits) of the samples for the specified band. - * - * @param band the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * - * @return The sample size (in bits). - */ - public abstract int getSampleSize(int band); -}
--- a/rt/java/awt/image/SinglePixelPackedSampleModel.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,597 +0,0 @@ -/* Copyright (C) 2000, 2002, 2003, 2004, 2006, Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -import java.util.Arrays; - -import gnu.java.awt.BitMaskExtent; - -/** - * A <code>SampleModel</code> used when all samples are stored in a single - * data element in the {@link DataBuffer}, and each data element contains - * samples for one pixel only. - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public class SinglePixelPackedSampleModel extends SampleModel -{ - private int scanlineStride; - private int[] bitMasks; - private int[] bitOffsets; - private int[] sampleSize; - private int maxBitSize; - - static private native void initIDs(); - static - { - ColorModel.loadLibraries(); - initIDs(); - } - - /** - * Creates a new <code>SinglePixelPackedSampleModel</code>. - * - * @param dataType the data buffer type. - * @param w the width (in pixels). - * @param h the height (in pixels). - * @param bitMasks an array containing the bit mask used to extract the - * sample value for each band. - */ - public SinglePixelPackedSampleModel(int dataType, int w, int h, - int[] bitMasks) - { - this(dataType, w, h, w, bitMasks); - } - - /** - * Creates a new <code>SinglePixelPackedSampleModel</code>. - * - * @param dataType the data buffer type. - * @param w the width (in pixels). - * @param h the height (in pixels). - * @param scanlineStride the number of data elements between a pixel on one - * row and the corresponding pixel on the next row. - * @param bitMasks an array containing the bit mask used to extract the - * sample value for each band. - */ - public SinglePixelPackedSampleModel(int dataType, int w, int h, - int scanlineStride, int[] bitMasks) - { - super(dataType, w, h, bitMasks.length); - - switch (dataType) - { - case DataBuffer.TYPE_BYTE: - case DataBuffer.TYPE_USHORT: - case DataBuffer.TYPE_INT: - break; - default: - throw new IllegalArgumentException( - "SinglePixelPackedSampleModel unsupported dataType"); - } - - this.scanlineStride = scanlineStride; - this.bitMasks = bitMasks; - - bitOffsets = new int[numBands]; - sampleSize = new int[numBands]; - - BitMaskExtent extent = new BitMaskExtent(); - maxBitSize = 0; - for (int b = 0; b < numBands; b++) - { - // the mask is an unsigned integer - long mask = bitMasks[b] & 0xFFFFFFFFL; - extent.setMask(mask); - sampleSize[b] = extent.bitWidth; - bitOffsets[b] = extent.leastSignificantBit; - - if (sampleSize[b] > maxBitSize) - maxBitSize = sampleSize[b]; - } - } - - /** - * Returns the number of data elements. - * - * @return <code>1</code>. - */ - public int getNumDataElements() - { - return 1; - } - - /** - * Creates a new <code>SampleModel</code> that is compatible with this - * model and has the specified width and height. - * - * @param w the width (in pixels). - * @param h the height (in pixels). - * - * @return The new sample model. - */ - public SampleModel createCompatibleSampleModel(int w, int h) - { - /* FIXME: We can avoid recalculation of bit offsets and sample - sizes here by passing these from the current instance to a - special private constructor. */ - return new SinglePixelPackedSampleModel(dataType, w, h, bitMasks); - } - - - /** - * Creates a DataBuffer for holding pixel data in the format and - * layout described by this SampleModel. The returned buffer will - * consist of one single bank. - * - * @return The data buffer. - */ - public DataBuffer createDataBuffer() - { - // 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. - int size = scanlineStride * (height - 1) + width; - - 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; - } - - /** - * Returns an array containing the size (in bits) for each band accessed by - * the <code>SampleModel</code>. - * - * @return An array. - * - * @see #getSampleSize(int) - */ - public int[] getSampleSize() - { - return (int[]) sampleSize.clone(); - } - - /** - * Returns the size (in bits) of the samples for the specified band. - * - * @param band the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * - * @return The sample size (in bits). - */ - public int getSampleSize(int band) - { - return sampleSize[band]; - } - - /** - * Returns the index in the data buffer that stores the pixel at (x, y). - * - * @param x the x-coordinate. - * @param y the y-coordinate. - * - * @return The index in the data buffer that stores the pixel at (x, y). - */ - public int getOffset(int x, int y) - { - return scanlineStride*y + x; - } - - public int[] getBitOffsets() - { - return bitOffsets; - } - - public int[] getBitMasks() - { - return bitMasks; - } - - /** - * Returns the number of data elements from a pixel in one row to the - * corresponding pixel in the next row. - * - * @return The scanline stride. - */ - public int getScanlineStride() - { - return scanlineStride; - } - - /** - * Creates a new <code>SinglePixelPackedSampleModel</code> that accesses - * the specified subset of bands. - * - * @param bands an array containing band indices (<code>null</code> not - * permitted). - * - * @return A new sample model. - * - * @throws NullPointerException if <code>bands</code> is <code>null</code>. - * @throws RasterFormatException if <code>bands.length</code> is greater - * than the number of bands in this model. - */ - public SampleModel createSubsetSampleModel(int[] bands) - { - if (bands.length > numBands) - throw new RasterFormatException("Too many bands."); - - int numBands = bands.length; - - int[] bitMasks = new int[numBands]; - - for (int b = 0; b < numBands; b++) - bitMasks[b] = this.bitMasks[bands[b]]; - - return new SinglePixelPackedSampleModel(dataType, width, height, - scanlineStride, bitMasks); - } - - public Object getDataElements(int x, int y, Object obj, - DataBuffer data) - { - int type = getTransferType(); - Object ret = null; - switch (type) - { - case DataBuffer.TYPE_BYTE: - { - 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: - { - 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: - { - int[] in = (int[]) obj; - if (in == null) - in = new int[1]; - in[0] = data.getElem(x + y * scanlineStride); - ret = in; - } - break; - } - return ret; - } - - /** - * Returns an array containing the samples for the pixel at (x, y) in the - * specified data buffer. If <code>iArray</code> is not <code>null</code>, - * it will be populated with the sample values and returned as the result of - * this function (this avoids allocating a new array instance). - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param iArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The pixel sample values. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public int[] getPixel(int x, int y, int[] iArray, DataBuffer data) - { - int offset = scanlineStride*y + x; - if (iArray == null) iArray = new int[numBands]; - int samples = data.getElem(offset); - - for (int b = 0; b < numBands; b++) - iArray[b] = (samples & bitMasks[b]) >>> bitOffsets[b]; - - return iArray; - } - - /** - * Returns an array containing the samples for the pixels in the region - * specified by (x, y, w, h) in the specified data buffer. The array is - * ordered by pixels (that is, all the samples for the first pixel are - * grouped together, followed by all the samples for the second pixel, and so - * on). If <code>iArray</code> is not <code>null</code>, it will be - * populated with the sample values and returned as the result of this - * function (this avoids allocating a new array instance). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param iArray an array to populate with the sample values and return as - * the result (if <code>null</code>, a new array will be allocated). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The pixel sample values. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public int[] getPixels(int x, int y, int w, int h, int[] iArray, - DataBuffer data) - { - int offset = scanlineStride*y + x; - if (iArray == null) iArray = new int[numBands*w*h]; - int outOffset = 0; - for (y = 0; y < h; y++) - { - int lineOffset = offset; - for (x = 0; x < w; x++) - { - int samples = data.getElem(lineOffset++); - for (int b = 0; b < numBands; b++) - iArray[outOffset++] = (samples & bitMasks[b]) >>> bitOffsets[b]; - } - offset += scanlineStride; - } - return iArray; - } - - /** - * Returns the sample value for the pixel at (x, y) in the specified data - * buffer. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * @param data the data buffer (<code>null</code> not permitted). - * - * @return The sample value. - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public int getSample(int x, int y, int b, DataBuffer data) - { - int offset = scanlineStride*y + x; - int samples = data.getElem(offset); - return (samples & bitMasks[b]) >>> bitOffsets[b]; - } - - 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; - data.setElem(y * scanlineStride + x, ((int) in[0]) & 0xffff); - } - 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 - * the specified values. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param iArray the sample values (<code>null</code> not permitted). - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if either <code>iArray</code> or - * <code>data</code> is <code>null</code>. - */ - public void setPixel(int x, int y, int[] iArray, DataBuffer data) - { - int offset = scanlineStride*y + x; - - int samples = 0; - for (int b = 0; b < numBands; b++) - samples |= (iArray[b] << bitOffsets[b]) & bitMasks[b]; - - 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 <code>obj</code>. - * @param y The y-coordinate of the pixel rectangle in <code>obj</code>. - * @param w The width of the pixel rectangle in <code>obj</code>. - * @param h The height of the pixel rectangle in <code>obj</code>. - * @param iArray 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; - 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 < numBands; b++) - samples |= (iArray[inOffset+b] << bitOffsets[b]) & bitMasks[b]; - data.setElem(0, offset, samples); - inOffset += numBands; - offset += 1; - } - } - } - - /** - * Sets the sample value for a band for the pixel at (x, y) in the - * specified data buffer. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * @param s the sample value. - * @param data the data buffer (<code>null</code> not permitted). - * - * @throws NullPointerException if <code>data</code> is <code>null</code>. - */ - public void setSample(int x, int y, int b, int s, DataBuffer data) - { - int offset = scanlineStride*y + x; - int samples = data.getElem(offset); - int bitMask = bitMasks[b]; - samples &= ~bitMask; - samples |= (s << bitOffsets[b]) & bitMask; - data.setElem(offset, samples); - } - - /** - * Tests this sample model for equality with an arbitrary object. This - * method returns <code>true</code> if and only if: - * <ul> - * <li><code>obj</code> is not <code>null</code>; - * <li><code>obj</code> is an instance of - * <code>SinglePixelPackedSampleModel</code>; - * <li>both models have the same: - * <ul> - * <li><code>dataType</code>; - * <li><code>width</code>; - * <li><code>height</code>; - * <li><code>numBands</code>; - * <li><code>scanlineStride</code>; - * <li><code>bitMasks</code>; - * <li><code>bitOffsets</code>. - * </ul> - * </li> - * </ul> - * - * @param obj the object (<code>null</code> permitted) - * - * @return <code>true</code> if this model is equal to <code>obj</code>, and - * <code>false</code> otherwise. - */ - public boolean equals(Object obj) - { - if (this == obj) - return true; - if (! (obj instanceof SinglePixelPackedSampleModel)) - return false; - SinglePixelPackedSampleModel that = (SinglePixelPackedSampleModel) obj; - if (this.dataType != that.dataType) - return false; - if (this.width != that.width) - return false; - if (this.height != that.height) - return false; - if (this.numBands != that.numBands) - return false; - if (this.scanlineStride != that.scanlineStride) - return false; - if (!Arrays.equals(this.bitMasks, that.bitMasks)) - return false; - if (!Arrays.equals(this.bitOffsets, that.bitOffsets)) - return false; - return true; - } - - /** - * Returns a hash code for this <code>SinglePixelPackedSampleModel</code>. - * - * @return A hash code. - */ - public int hashCode() - { - // this hash code won't match Sun's, but that shouldn't matter... - int result = 193; - result = 37 * result + dataType; - result = 37 * result + width; - result = 37 * result + height; - result = 37 * result + numBands; - result = 37 * result + scanlineStride; - for (int i = 0; i < bitMasks.length; i++) - result = 37 * result + bitMasks[i]; - for (int i = 0; i < bitOffsets.length; i++) - result = 37 * result + bitOffsets[i]; - return result; - } - - /** - * Creates a String with some information about this SampleModel. - * @return A String describing this SampleModel. - * @see java.lang.Object#toString() - */ - public String toString() - { - StringBuffer result = new StringBuffer(); - result.append(getClass().getName()); - result.append("["); - result.append("scanlineStride=").append(scanlineStride); - for(int i = 0; i < bitMasks.length; i+=1) - { - result.append(", mask[").append(i).append("]=0x").append( - Integer.toHexString(bitMasks[i])); - } - - result.append("]"); - return result.toString(); - } -}
--- a/rt/java/awt/image/WritableRaster.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,436 +0,0 @@ -/* Copyright (C) 2000, 2002, 2003, 2006, Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.Point; -import java.awt.Rectangle; -import sun.awt.image.SunWritableRaster; - -/** - * A raster with methods to support updating pixel values. - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public class WritableRaster extends Raster -{ - /** - * Creates a new <code>WritableRaster</code>. - * - * @param sampleModel the sample model. - * @param origin the origin. - */ - protected WritableRaster(SampleModel sampleModel, Point origin) - { - this(sampleModel, sampleModel.createDataBuffer(), origin); - } - - /** - * Creates a new <code>WritableRaster</code> instance. - * - * @param sampleModel the sample model. - * @param dataBuffer the data buffer. - * @param origin the origin. - */ - protected WritableRaster(SampleModel sampleModel, DataBuffer dataBuffer, - Point origin) - { - this(sampleModel, dataBuffer, - new Rectangle(origin != null ? origin.x : 0, - origin != null ? origin.y : 0, - sampleModel.getWidth(), sampleModel.getHeight()), - origin, null); - } - - /** - * Creates a new <code>WritableRaster</code> instance. - * - * @param sampleModel the sample model. - * @param dataBuffer the data buffer. - * @param aRegion the raster's bounds. - * @param sampleModelTranslate the translation. - * @param parent the parent. - */ - protected WritableRaster(SampleModel sampleModel, - DataBuffer dataBuffer, - Rectangle aRegion, - Point sampleModelTranslate, - WritableRaster parent) - { - super(sampleModel, dataBuffer, aRegion, sampleModelTranslate, parent); - } - - /** - * Returns the raster's parent, cast as a {@link WritableRaster}. - * - * @return The raster's parent. - */ - public WritableRaster getWritableParent() - { - return (WritableRaster) getParent(); - } - - /** - * @param childMinX - * @param childMinY - * @return - */ - public WritableRaster createWritableTranslatedChild(int childMinX, - int childMinY) - { - return createWritableChild(minX, minY, width, height, - childMinX, childMinY, null); - } - - /** - * - * @param parentX - * @param parentY - * @param w - * @param h - * @param childMinX - * @param childMinY - * @param bandList - * @return - */ - public WritableRaster createWritableChild(int parentX, int parentY, - int w, int h, int childMinX, int childMinY, int[] bandList) - { - // This mirrors the code from the super class - - if (parentX < minX || parentX + w > minX + width - || parentY < minY || parentY + h > minY + height) - throw new RasterFormatException("Child raster extends beyond parent"); - - SampleModel sm = (bandList == null) ? - sampleModel : - sampleModel.createSubsetSampleModel(bandList); - - return new SunWritableRaster(sm, dataBuffer, - new Rectangle(childMinX, childMinY, w, h), - new Point(sampleModelTranslateX + childMinX - parentX, - sampleModelTranslateY + childMinY - parentY), - this); - } - - public Raster createChild(int parentX, int parentY, int width, - int height, int childMinX, int childMinY, - int[] bandList) - { - return createWritableChild(parentX, parentY, width, height, - childMinX, childMinY, bandList); - } - - public void setDataElements(int x, int y, Object inData) - { - sampleModel.setDataElements(x - sampleModelTranslateX, - y - sampleModelTranslateY, inData, dataBuffer); - } - - public void setDataElements(int x, int y, Raster inRaster) - { - Object dataElements = getDataElements(0, 0, inRaster.getWidth(), - inRaster.getHeight(), null); - setDataElements(x, y, dataElements); - } - - public void setDataElements(int x, int y, int w, int h, Object inData) - { - sampleModel.setDataElements(x - sampleModelTranslateX, - y - sampleModelTranslateY, w, h, inData, dataBuffer); - } - - /** - * - * @param srcRaster - */ - public void setRect(Raster srcRaster) - { - setRect(0, 0, srcRaster); - } - - /** - * - * @param dx - * @param dy - * @param srcRaster - */ - public void setRect(int dx, int dy, Raster srcRaster) - { - Rectangle targetUnclipped = new Rectangle(srcRaster.getMinX() + dx, - srcRaster.getMinY() + dy, srcRaster.getWidth(), srcRaster.getHeight()); - - Rectangle target = getBounds().intersection(targetUnclipped); - - if (target.isEmpty()) return; - - int sx = target.x - dx; - int sy = target.y - dy; - - // FIXME: Do tests on rasters and use get/set data instead. - - /* The JDK documentation seems to imply this implementation. - (the trucation of higher bits), but an implementation using - get/setDataElements would be more efficient. None of the - implementations would do anything sensible when the sample - models don't match. - - But this is probably not the place to consider such - optimizations.*/ - - int[] pixels = srcRaster.getPixels(sx, sy, target.width, target.height, - (int[]) null); - - setPixels(target.x, target.y, target.width, target.height, pixels); - } - - /** - * Sets the samples for the pixel at (x, y) in the raster to the specified - * values. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param iArray the sample values (<code>null</code> not permitted). - * - * @throws NullPointerException if <code>iArray</code> is <code>null</code>. - */ - public void setPixel(int x, int y, int[] iArray) - { - sampleModel.setPixel(x - sampleModelTranslateX, y - sampleModelTranslateY, - iArray, dataBuffer); - } - - /** - * Sets the samples for the pixel at (x, y) in the raster to the specified - * values. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param fArray the sample values (<code>null</code> not permitted). - * - * @throws NullPointerException if <code>fArray</code> is <code>null</code>. - */ - public void setPixel(int x, int y, float[] fArray) - { - sampleModel.setPixel(x - sampleModelTranslateX, y - sampleModelTranslateY, - fArray, dataBuffer); - } - - /** - * Sets the samples for the pixel at (x, y) in the raster to the specified - * values. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param dArray the sample values (<code>null</code> not permitted). - * - * @throws NullPointerException if <code>dArray</code> is <code>null</code>. - */ - public void setPixel(int x, int y, double[] dArray) - { - sampleModel.setPixel(x - sampleModelTranslateX, y - sampleModelTranslateY, - dArray, dataBuffer); - } - - /** - * Sets the sample values for the pixels in the region specified by - * (x, y, w, h) in the raster. The array is ordered by pixels (that is, all - * the samples for the first pixel are grouped together, followed by all the - * samples for the second pixel, and so on). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param iArray the pixel sample values (<code>null</code> not permitted). - * - * @throws NullPointerException if <code>iArray</code> is <code>null</code>. - */ - public void setPixels(int x, int y, int w, int h, int[] iArray) - { - sampleModel.setPixels(x - sampleModelTranslateX, y - sampleModelTranslateY, - w, h, iArray, dataBuffer); - } - - /** - * Sets the sample values for the pixels in the region specified by - * (x, y, w, h) in the raster. The array is ordered by pixels (that is, all - * the samples for the first pixel are grouped together, followed by all the - * samples for the second pixel, and so on). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param fArray the pixel sample values (<code>null</code> not permitted). - * - * @throws NullPointerException if <code>fArray</code> is <code>null</code>. - */ - public void setPixels(int x, int y, int w, int h, float[] fArray) - { - sampleModel.setPixels(x - sampleModelTranslateX, y - sampleModelTranslateY, - w, h, fArray, dataBuffer); - } - - /** - * Sets the sample values for the pixels in the region specified by - * (x, y, w, h) in the raster. The array is ordered by pixels (that is, all - * the samples for the first pixel are grouped together, followed by all the - * samples for the second pixel, and so on). - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param dArray the pixel sample values (<code>null</code> not permitted). - * - * @throws NullPointerException if <code>dArray</code> is <code>null</code>. - */ - public void setPixels(int x, int y, int w, int h, double[] dArray) - { - sampleModel.setPixels(x - sampleModelTranslateX, y - sampleModelTranslateY, - w, h, dArray, dataBuffer); - } - - /** - * Sets the sample value for a band for the pixel at (x, y) in the raster. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * @param s the sample value. - */ - public void setSample(int x, int y, int b, int s) - { - sampleModel.setSample(x - sampleModelTranslateX, y - sampleModelTranslateY, - b, s, dataBuffer); - } - - /** - * Sets the sample value for a band for the pixel at (x, y) in the raster. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * @param s the sample value. - */ - public void setSample(int x, int y, int b, float s) - { - sampleModel.setSample(x - sampleModelTranslateX, y - sampleModelTranslateY, - b, s, dataBuffer); - } - - /** - * Sets the sample value for a band for the pixel at (x, y) in the raster. - * - * @param x the x-coordinate of the pixel. - * @param y the y-coordinate of the pixel. - * @param b the band (in the range <code>0</code> to - * <code>getNumBands() - 1</code>). - * @param s the sample value. - */ - public void setSample(int x, int y, int b, double s) - { - sampleModel.setSample(x - sampleModelTranslateX, y - sampleModelTranslateY, - b, s, dataBuffer); - } - - /** - * Sets the sample values for one band for the pixels in the region - * specified by (x, y, w, h) in the raster. - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param b the band (in the range <code>0</code> to - * </code>getNumBands() - 1</code>). - * @param iArray the sample values (<code>null</code> not permitted). - * - * @throws NullPointerException if <code>iArray</code> is <code>null</code>. - */ - public void setSamples(int x, int y, int w, int h, int b, - int[] iArray) - { - sampleModel.setSamples(x - sampleModelTranslateX, y - sampleModelTranslateY, - w, h, b, iArray, dataBuffer); - } - - /** - * Sets the sample values for one band for the pixels in the region - * specified by (x, y, w, h) in the raster. - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param b the band (in the range <code>0</code> to - * </code>getNumBands() - 1</code>). - * @param fArray the sample values (<code>null</code> not permitted). - * - * @throws NullPointerException if <code>fArray</code> is <code>null</code>. - */ - public void setSamples(int x, int y, int w, int h, int b, - float[] fArray) - { - sampleModel.setSamples(x - sampleModelTranslateX, y - sampleModelTranslateY, - w, h, b, fArray, dataBuffer); - } - - /** - * Sets the sample values for one band for the pixels in the region - * specified by (x, y, w, h) in the raster. - * - * @param x the x-coordinate of the top-left pixel. - * @param y the y-coordinate of the top-left pixel. - * @param w the width of the region of pixels. - * @param h the height of the region of pixels. - * @param b the band (in the range <code>0</code> to - * </code>getNumBands() - 1</code>). - * @param dArray the sample values (<code>null</code> not permitted). - * - * @throws NullPointerException if <code>dArray</code> is <code>null</code>. - */ - public void setSamples(int x, int y, int w, int h, int b, - double[] dArray) - { - sampleModel.setSamples(x - sampleModelTranslateX, y - sampleModelTranslateY, - w, h, b, dArray, dataBuffer); - } -}
--- a/rt/java/awt/image/WritableRenderedImage.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* WritableRenderedImage.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.Point; - -/** - * NEEDS DOCUMENTATION - */ -public interface WritableRenderedImage extends RenderedImage -{ - void addTileObserver(TileObserver to); - void removeTileObserver(TileObserver to); - WritableRaster getWritableTile(int x, int y); - void releaseWritableTile(int x, int y); - boolean isTileWritable(int x, int y); - Point[] getWritableTileIndices(); - boolean hasTileWriters(); - void setData(Raster r); -} // interface WritableRenderedImage
--- a/rt/java/awt/image/renderable/ContextualRenderedImageFactory.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* ContextualRenderedImageFactory.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image.renderable; - -import java.awt.geom.Rectangle2D; -import java.awt.image.RenderedImage; - -/** - * STUBBED - */ -public interface ContextualRenderedImageFactory extends RenderedImageFactory -{ - RenderContext mapRenderContext(int i, RenderContext context, - ParameterBlock block, RenderableImage image); - RenderedImage create(RenderContext context, ParameterBlock block); - Rectangle2D getBounds2D(ParameterBlock block); - Object getProperty(ParameterBlock block, String name); - String[] getPropertyNames(); - boolean isDynamic(); -} // interface ContextualRenderedImageFactory
--- a/rt/java/awt/image/renderable/RenderContext.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,141 +0,0 @@ -/* RenderContext.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image.renderable; - -import java.awt.RenderingHints; -import java.awt.Shape; -import java.awt.geom.AffineTransform; - -public class RenderContext implements Cloneable -{ - private AffineTransform xform; - private Shape aoi; - private RenderingHints hints; - - public RenderContext(AffineTransform xform, Shape aoi, RenderingHints hints) - { - this.xform = xform; - this.aoi = aoi; - this.hints = hints; - } - - public RenderContext(AffineTransform xform) - { - this(xform, null, null); - } - - public RenderContext(AffineTransform xform, RenderingHints hints) - { - this(xform, null, hints); - } - - public RenderContext(AffineTransform xform, Shape aoi) - { - this(xform, aoi, null); - } - - public RenderingHints getRenderingHints() - { - return hints; - } - - public void setRenderingHints(RenderingHints hints) - { - this.hints = hints; - } - - public void setTransform(AffineTransform xform) - { - this.xform = xform; - } - - public void preConcatenateTransform(AffineTransform pre) - { - preConcetenateTransform (pre); - } - - /** @deprecated */ - public void preConcetenateTransform(AffineTransform pre) - { - xform.preConcatenate (pre); - } - - public void concatenateTransform(AffineTransform post) - { - concetenateTransform (post); - } - - /** @deprecated */ - public void concetenateTransform(AffineTransform post) - { - xform.concatenate (post); - } - - public AffineTransform getTransform() - { - return xform; - } - - public void setAreaOfInterest(Shape aoi) - { - this.aoi = aoi; - } - - public Shape getAreaOfInterest() - { - return aoi; - } - - public Object clone() - { - try - { - RenderContext copy = (RenderContext) super.clone(); - if (xform != null) - copy.xform = (AffineTransform) xform.clone(); - if (hints != null) - copy.hints = (RenderingHints) hints.clone(); - return copy; - } - catch (CloneNotSupportedException e) - { - throw (Error) new InternalError().initCause(e); // impossible - } - } -} // class RenderContext
--- a/rt/java/awt/image/renderable/RenderableImage.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -/* RenderableImage.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image.renderable; - -import java.awt.RenderingHints; -import java.awt.image.RenderedImage; -import java.util.Vector; - -public interface RenderableImage -{ - String HINTS_OBSERVED = "HINTS_OBSERVED"; - - Vector<RenderableImage> getSources(); - Object getProperty(String name); - String[] getPropertyNames(); - boolean isDynamic(); - float getWidth(); - float getHeight(); - float getMinX(); - float getMinY(); - RenderedImage createScaledRendering(int w, int h, RenderingHints hints); - RenderedImage createDefaultRendering(); - RenderedImage createRendering(RenderContext context); - -} // interface RenderableImage -
--- a/rt/java/awt/image/renderable/RenderableImageOp.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,157 +0,0 @@ -/* RenderableImageOp.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image.renderable; - -import java.awt.RenderingHints; -import java.awt.geom.AffineTransform; -import java.awt.image.RenderedImage; -import java.util.Vector; - -public class RenderableImageOp implements RenderableImage -{ - private final ContextualRenderedImageFactory crif; - private ParameterBlock block; - - public RenderableImageOp(ContextualRenderedImageFactory crif, - ParameterBlock block) - { - this.crif = crif; - this.block = (ParameterBlock) block.clone(); - } - - public Vector<RenderableImage> getSources() - { - if (block.sources == null) - return null; - int size = block.sources.size(); - Vector v = new Vector(); - for (int i = 0; i < size; i++) - { - Object o = block.sources.get(i); - if (o instanceof RenderableImage) - v.add(o); - } - return v; - } - - public Object getProperty(String name) - { - return crif.getProperty(block, name); - } - - public String[] getPropertyNames() - { - return crif.getPropertyNames(); - } - - public boolean isDynamic() - { - return crif.isDynamic(); - } - - public float getWidth() - { - return (float) crif.getBounds2D(block).getWidth(); - } - - public float getHeight() - { - return (float) crif.getBounds2D(block).getHeight(); - } - - public float getMinX() - { - return (float) crif.getBounds2D(block).getX(); - } - - public float getMinY() - { - return (float) crif.getBounds2D(block).getY(); - } - - public ParameterBlock setParameterBlock(ParameterBlock block) - { - ParameterBlock result = this.block; - this.block = (ParameterBlock) block.clone(); - return result; - } - - public ParameterBlock getParameterBlock() - { - return block; - } - - public RenderedImage createScaledRendering(int w, int h, - RenderingHints hints) - { - if (w == 0) - if (h == 0) - throw new IllegalArgumentException(); - else - w = Math.round(h * getWidth() / getHeight()); - if (h == 0) - h = Math.round(w * getHeight() / getWidth()); - AffineTransform xform = AffineTransform.getScaleInstance(w * getWidth(), - h * getHeight()); - return createRendering(new RenderContext(xform, hints)); - } - - public RenderedImage createDefaultRendering() - { - return createRendering(new RenderContext(new AffineTransform())); - } - - public RenderedImage createRendering(RenderContext context) - { - ParameterBlock copy = (ParameterBlock) block.clone(); - int i = block.sources.size(); - while (--i >= 0) - { - Object o = block.sources.get(i); - if (o instanceof RenderableImage) - { - RenderableImage ri = (RenderableImage) o; - RenderContext rc = crif.mapRenderContext(i, context, block, ri); - copy.sources.set(i, ri.createRendering(rc)); - } - } - // Now copy.sources should be only RenderedImages. - return crif.create(context, copy); - } -} // class RenderableImageOp
--- a/rt/java/awt/image/renderable/RenderableImageProducer.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,166 +0,0 @@ -/* RenderableImageProducer.java -- - Copyright (C) 2002, 2006 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image.renderable; - -import java.awt.image.ColorModel; -import java.awt.image.DataBuffer; -import java.awt.image.ImageConsumer; -import java.awt.image.ImageProducer; -import java.awt.image.Raster; -import java.awt.image.RenderedImage; -import java.awt.image.SampleModel; -import java.util.ArrayList; -import java.util.Iterator; - -public class RenderableImageProducer implements ImageProducer, Runnable -{ - private RenderableImage image; - private RenderContext context; - private ArrayList consumers = new ArrayList(); - - public RenderableImageProducer(RenderableImage image, RenderContext context) - { - this.image = image; - this.context = context; - } - - public void setRenderContext(RenderContext context) - { - this.context = context; - } - - public void addConsumer(ImageConsumer consumer) - { - synchronized (consumers) - { - if (! consumers.contains(consumer)) - consumers.add(consumer); - } - } - - public boolean isConsumer(ImageConsumer consumer) - { - synchronized (consumers) - { - return consumers.contains(consumer); - } - } - - public void removeConsumer(ImageConsumer consumer) - { - synchronized (consumers) - { - consumers.remove(consumer); - } - } - - public void startProduction(ImageConsumer consumer) - { - addConsumer(consumer); - Thread t = new Thread(this, "RenderableImageProducerWorker"); - t.start(); - } - - public void requestTopDownLeftRightResend(ImageConsumer consumer) - { - // Do nothing. The contract says we can ignore this call, so we do. - } - - public void run() - { - // This isn't ideal but it avoids fail-fast problems. - // Alternatively, we could clone 'consumers' here. - synchronized (consumers) - { - RenderedImage newImage; - if (context == null) - newImage = image.createDefaultRendering(); - else - newImage = image.createRendering(context); - Raster newData = newImage.getData(); - ColorModel colorModel = newImage.getColorModel(); - if (colorModel == null) - colorModel = ColorModel.getRGBdefault(); - SampleModel sampleModel = newData.getSampleModel(); - DataBuffer dataBuffer = newData.getDataBuffer(); - int width = newData.getWidth(); - int height = newData.getHeight(); - - // Initialize the consumers. - Iterator it = consumers.iterator(); - while (it.hasNext()) - { - ImageConsumer target = (ImageConsumer) it.next(); - target.setHints(ImageConsumer.COMPLETESCANLINES - | ImageConsumer.SINGLEFRAME - | ImageConsumer.SINGLEPASS - | ImageConsumer.TOPDOWNLEFTRIGHT); - target.setDimensions(width, height); - } - - // Work in scan-line order. - int[] newLine = new int[width]; - int[] bands = new int[sampleModel.getNumBands()]; - for (int y = 0; y < height; ++y) - { - for (int x = 0; x < width; ++x) - { - sampleModel.getPixel(x, y, bands, dataBuffer); - newLine[x] = colorModel.getDataElement(bands, 0); - } - - // Tell the consumers about the new scan line. - it = consumers.iterator(); - while (it.hasNext()) - { - ImageConsumer target = (ImageConsumer) it.next(); - target.setPixels(0, y, width, 1, colorModel, newLine, 0, width); - } - } - - // Tell the consumers that we're done. - it = consumers.iterator(); - while (it.hasNext()) - { - ImageConsumer target = (ImageConsumer) it.next(); - target.imageComplete(ImageConsumer.STATICIMAGEDONE); - } - } - } -} // class RenderableImageProducer
--- a/rt/java/awt/image/renderable/RenderedImageFactory.java Thu Feb 28 13:34:20 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* RenderedImageFactory.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image.renderable; - -import java.awt.RenderingHints; -import java.awt.image.RenderedImage; - -public interface RenderedImageFactory -{ - RenderedImage create(ParameterBlock block, RenderingHints hints); -} // interface RenderedImageFactory