diff options
Diffstat (limited to 'external/ikvm/openjdk/sun/awt')
-rw-r--r-- | external/ikvm/openjdk/sun/awt/AppContext.java | 214 | ||||
-rw-r--r-- | external/ikvm/openjdk/sun/awt/AppContextDC.java | 45 | ||||
-rw-r--r-- | external/ikvm/openjdk/sun/awt/SunToolkit.java | 142 | ||||
-rw-r--r-- | external/ikvm/openjdk/sun/awt/image/ByteComponentRaster.java | 919 | ||||
-rw-r--r-- | external/ikvm/openjdk/sun/awt/image/BytePackedRaster.java | 1389 | ||||
-rw-r--r-- | external/ikvm/openjdk/sun/awt/image/IntegerComponentRaster.java | 685 | ||||
-rw-r--r-- | external/ikvm/openjdk/sun/awt/image/OffScreenImageSource.java | 195 | ||||
-rw-r--r-- | external/ikvm/openjdk/sun/awt/image/ShortComponentRaster.java | 829 |
8 files changed, 231 insertions, 4187 deletions
diff --git a/external/ikvm/openjdk/sun/awt/AppContext.java b/external/ikvm/openjdk/sun/awt/AppContext.java index be6734e492..23c86c90f0 100644 --- a/external/ikvm/openjdk/sun/awt/AppContext.java +++ b/external/ikvm/openjdk/sun/awt/AppContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -46,6 +46,7 @@ import sun.util.logging.PlatformLogger; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import java.util.concurrent.atomic.AtomicInteger; /** * The AppContext is a table referenced by ThreadGroup which stores @@ -129,7 +130,7 @@ import java.util.concurrent.locks.ReentrantLock; * @author Thomas Ball * @author Fred Ecks */ -public final class AppContext extends AppContextDC { +public final class AppContext { private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.AppContext"); /* Since the contents of an AppContext are unique to each Java @@ -161,8 +162,9 @@ public final class AppContext extends AppContextDC { } /* The main "system" AppContext, used by everything not otherwise - contained in another AppContext. - */ + contained in another AppContext. It is implicitly created for + standalone apps only (i.e. not applets) + */ private static volatile AppContext mainAppContext = null; /* @@ -188,31 +190,16 @@ public final class AppContext extends AppContextDC { public static final String DISPOSED_PROPERTY_NAME = "disposed"; public static final String GUI_DISPOSED = "guidisposed"; - private volatile boolean isDisposed = false; // true if AppContext is disposed + private enum State { + VALID, + BEING_DISPOSED, + DISPOSED + }; - public boolean isDisposed() { - return isDisposed; - } + private volatile State state = State.VALID; - static { - // On the main Thread, we get the ThreadGroup, make a corresponding - // AppContext, and instantiate the Java EventQueue. This way, legacy - // code is unaffected by the move to multiple AppContext ability. - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - ThreadGroup currentThreadGroup = - Thread.currentThread().getThreadGroup(); - ThreadGroup parentThreadGroup = currentThreadGroup.getParent(); - while (parentThreadGroup != null) { - // Find the root ThreadGroup to construct our main AppContext - currentThreadGroup = parentThreadGroup; - parentThreadGroup = currentThreadGroup.getParent(); - } - mainAppContext = new AppContext(currentThreadGroup); - numAppContexts = 1; - return mainAppContext; - } - }); + public boolean isDisposed() { + return state == State.DISPOSED; } /* @@ -222,7 +209,7 @@ public final class AppContext extends AppContextDC { * number is 1. If so, it returns the sole AppContext without * checking Thread.currentThread(). */ - private static volatile int numAppContexts; + private static final AtomicInteger numAppContexts = new AtomicInteger(0); /* * The context ClassLoader that was used to create this AppContext. @@ -243,7 +230,7 @@ public final class AppContext extends AppContextDC { * @since 1.2 */ AppContext(ThreadGroup threadGroup) { - numAppContexts++; + numAppContexts.incrementAndGet(); this.threadGroup = threadGroup; threadGroup2appContext.put(threadGroup, this); @@ -266,6 +253,27 @@ public final class AppContext extends AppContextDC { private static final ThreadLocal<AppContext> threadAppContext = new ThreadLocal<AppContext>(); + private final static void initMainAppContext() { + // On the main Thread, we get the ThreadGroup, make a corresponding + // AppContext, and instantiate the Java EventQueue. This way, legacy + // code is unaffected by the move to multiple AppContext ability. + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { + ThreadGroup currentThreadGroup = + Thread.currentThread().getThreadGroup(); + ThreadGroup parentThreadGroup = currentThreadGroup.getParent(); + while (parentThreadGroup != null) { + // Find the root ThreadGroup to construct our main AppContext + currentThreadGroup = parentThreadGroup; + parentThreadGroup = currentThreadGroup.getParent(); + } + + mainAppContext = SunToolkit.createNewAppContext(currentThreadGroup); + return null; + } + }); + } + /** * Returns the appropriate AppContext for the caller, * as determined by its ThreadGroup. If the main "system" AppContext @@ -278,8 +286,10 @@ public final class AppContext extends AppContextDC { * @since 1.2 */ public final static AppContext getAppContext() { - if (numAppContexts == 1) // If there's only one system-wide, - return mainAppContext; // return the main system AppContext. + // we are standalone app, return the main app context + if (numAppContexts.get() == 1 && mainAppContext != null) { + return mainAppContext; + } AppContext appContext = threadAppContext.get(); @@ -293,29 +303,37 @@ public final class AppContext extends AppContextDC { // when new AppContext objects are created. ThreadGroup currentThreadGroup = Thread.currentThread().getThreadGroup(); ThreadGroup threadGroup = currentThreadGroup; + + // Special case: we implicitly create the main app context + // if no contexts have been created yet. This covers standalone apps + // and excludes applets because by the time applet starts + // a number of contexts have already been created by the plugin. + if (numAppContexts.get() == 0) { + // This check is not necessary, its purpose is to help + // Plugin devs to catch all the cases of main AC creation. + if (System.getProperty("javaplugin.version") == null && + System.getProperty("javawebstart.version") == null) { + initMainAppContext(); + } + } + AppContext context = threadGroup2appContext.get(threadGroup); while (context == null) { threadGroup = threadGroup.getParent(); if (threadGroup == null) { - // If we get here, we're running under a ThreadGroup that - // has no AppContext associated with it. This should never - // happen, because createNewContext() should be used by the - // toolkit to create the ThreadGroup that everything runs - // under. - throw new RuntimeException("Invalid ThreadGroup"); + return null; } context = threadGroup2appContext.get(threadGroup); } + // In case we did anything in the above while loop, we add // all the intermediate ThreadGroups to threadGroup2appContext // so we won't spin again. for (ThreadGroup tg = currentThreadGroup; tg != threadGroup; tg = tg.getParent()) { threadGroup2appContext.put(tg, context); } + // Now we're done, so we cache the latest key/value pair. - // (we do this before checking with any AWTSecurityManager, so if - // this Thread equates with the main AppContext in the cache, it - // still will) threadAppContext.set(context); return context; @@ -323,33 +341,30 @@ public final class AppContext extends AppContextDC { }); } - if (appContext == mainAppContext) { - // Before we return the main "system" AppContext, check to - // see if there's an AWTSecurityManager installed. If so, - // allow it to choose the AppContext to return. - SecurityManager securityManager = System.getSecurityManager(); - if ((securityManager != null) && - (securityManager instanceof AWTSecurityManager)) - { - AWTSecurityManager awtSecMgr = (AWTSecurityManager)securityManager; - AppContext secAppContext = awtSecMgr.getAppContext(); - if (secAppContext != null) { - appContext = secAppContext; // Return what we're told - } - } - } - return appContext; } /** - * Returns the main ("system") AppContext. + * Returns true if the specified AppContext is the main AppContext. * - * @return the main AppContext + * @param ctx the context to compare with the main context + * @return true if the specified AppContext is the main AppContext. * @since 1.8 */ - final static AppContext getMainAppContext() { - return mainAppContext; + public final static boolean isMainContext(AppContext ctx) { + return (ctx != null && ctx == mainAppContext); + } + + private final static AppContext getExecutionAppContext() { + SecurityManager securityManager = System.getSecurityManager(); + if ((securityManager != null) && + (securityManager instanceof AWTSecurityManager)) + { + AWTSecurityManager awtSecMgr = (AWTSecurityManager) securityManager; + AppContext secAppContext = awtSecMgr.getAppContext(); + return secAppContext; // Return what we're told + } + return null; } private long DISPOSAL_TIMEOUT = 5000; // Default to 5-second timeout @@ -383,10 +398,11 @@ public final class AppContext extends AppContextDC { } synchronized(this) { - if (this.isDisposed) { - return; // If already disposed, bail. + if (this.state != State.VALID) { + return; // If already disposed or being disposed, bail. } - this.isDisposed = true; + + this.state = State.BEING_DISPOSED; } final PropertyChangeSupport changeSupport = this.changeSupport; @@ -401,6 +417,27 @@ public final class AppContext extends AppContextDC { Runnable runnable = new Runnable() { public void run() { + Window[] windowsToDispose = Window.getOwnerlessWindows(); + for (Window w : windowsToDispose) { + try { + w.dispose(); + } catch (Throwable t) { + log.finer("exception occured while disposing app context", t); + } + } + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + if (!GraphicsEnvironment.isHeadless() && SystemTray.isSupported()) + { + SystemTray systemTray = SystemTray.getSystemTray(); + TrayIcon[] trayIconsToDispose = systemTray.getTrayIcons(); + for (TrayIcon ti : trayIconsToDispose) { + systemTray.remove(ti); + } + } + return null; + } + }); // Alert PropertyChangeListeners that the GUI has been disposed. if (changeSupport != null) { changeSupport.firePropertyChange(GUI_DISPOSED, false, true); @@ -435,6 +472,11 @@ public final class AppContext extends AppContextDC { } catch (InterruptedException e) { } } + // We are done with posting events, so change the state to disposed + synchronized(this) { + this.state = State.DISPOSED; + } + // Next, we interrupt all Threads in the ThreadGroup this.threadGroup.interrupt(); // Note, the EventDispatchThread we've interrupted may dump an @@ -492,7 +534,7 @@ public final class AppContext extends AppContextDC { this.table.clear(); // Clear out the Hashtable to ease garbage collection } - numAppContexts--; + numAppContexts.decrementAndGet(); mostRecentKeyValue = null; } @@ -766,6 +808,50 @@ public final class AppContext extends AppContextDC { } return changeSupport.getPropertyChangeListeners(propertyName); } + + // Set up JavaAWTAccess in SharedSecrets + static { + sun.misc.SharedSecrets.setJavaAWTAccess(new sun.misc.JavaAWTAccess() { + public Object get(Object key) { + AppContext ac = getAppContext(); + return (ac == null) ? null : ac.get(key); + } + public void put(Object key, Object value) { + AppContext ac = getAppContext(); + if (ac != null) { + ac.put(key, value); + } + } + public void remove(Object key) { + AppContext ac = getAppContext(); + if (ac != null) { + ac.remove(key); + } + } + public boolean isDisposed() { + AppContext ac = getAppContext(); + return (ac == null) ? true : ac.isDisposed(); + } + public boolean isMainAppContext() { + return (numAppContexts.get() == 1 && mainAppContext != null); + } + public Object getContext() { + return getAppContext(); + } + public Object getExecutionContext() { + return getExecutionAppContext(); + } + public Object get(Object context, Object key) { + return ((AppContext)context).get(key); + } + public void put(Object context, Object key, Object value) { + ((AppContext)context).put(key, value); + } + public void remove(Object context, Object key) { + ((AppContext)context).remove(key); + } + }); + } } final class MostRecentKeyValue { diff --git a/external/ikvm/openjdk/sun/awt/AppContextDC.java b/external/ikvm/openjdk/sun/awt/AppContextDC.java deleted file mode 100644 index 47e71d627d..0000000000 --- a/external/ikvm/openjdk/sun/awt/AppContextDC.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - Copyright (C) 2012 Jeroen Frijters - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jeroen Frijters - jeroen@frijters.net - -*/ -package sun.awt; - -/* This class exists to decouple java.util.TimeZone from sun.awt.AppContext */ -public abstract class AppContextDC -{ - public abstract boolean isDisposed(); - public abstract Object get(Object key); - public abstract Object put(Object key, Object value); - public abstract Object remove(Object key); - - public static AppContextDC getAppContext() - { - try - { - return (AppContextDC)Class.forName("sun.awt.AppContext").getMethod("getAppContext").invoke(null); - } - catch (Exception _) - { - return null; - } - } -} diff --git a/external/ikvm/openjdk/sun/awt/SunToolkit.java b/external/ikvm/openjdk/sun/awt/SunToolkit.java index fa457d5309..11612ec1ee 100644 --- a/external/ikvm/openjdk/sun/awt/SunToolkit.java +++ b/external/ikvm/openjdk/sun/awt/SunToolkit.java @@ -64,7 +64,7 @@ public abstract class SunToolkit extends Toolkit implements WindowClosingSupport, WindowClosingListener, ComponentFactory, InputMethodSupport, KeyboardFocusManagerPeerProvider { - private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.SunToolkit"); + // 8014736: logging has been removed from SunToolkit /** * Special mask for the UngrabEvent events, in addition to the @@ -97,6 +97,14 @@ public abstract class SunToolkit extends Toolkit */ public final static int MAX_BUTTONS_SUPPORTED = 20; + /** + * Creates and initializes EventQueue instance for the specified + * AppContext. + * Note that event queue must be created from createNewAppContext() + * only in order to ensure that EventQueue constructor obtains + * the correct AppContext. + * @param appContext AppContext to associate with the event queue + */ private static void initEQ(AppContext appContext) { EventQueue eventQueue; @@ -117,8 +125,6 @@ public abstract class SunToolkit extends Toolkit } public SunToolkit() { - // 7122796: Always create an EQ for the main AppContext - initEQ(AppContext.getMainAppContext()); } public boolean useBufferPerWindow() { @@ -277,11 +283,14 @@ public abstract class SunToolkit extends Toolkit */ public static AppContext createNewAppContext() { ThreadGroup threadGroup = Thread.currentThread().getThreadGroup(); + return createNewAppContext(threadGroup); + } + + static final AppContext createNewAppContext(ThreadGroup threadGroup) { // Create appContext before initialization of EventQueue, so all // the calls to AppContext.getAppContext() from EventQueue ctor // return correct values AppContext appContext = new AppContext(threadGroup); - initEQ(appContext); return appContext; @@ -512,10 +521,6 @@ public abstract class SunToolkit extends Toolkit // otherwise have to be modified to precisely identify // system-generated events. setSystemGenerated(event); - AppContext eventContext = targetToAppContext(event.getSource()); - if (eventContext != null && !eventContext.equals(appContext)) { - log.fine("Event posted on wrong app context : " + event); - } PostEventQueue postEventQueue = (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY); if (postEventQueue != null) { @@ -544,20 +549,28 @@ public abstract class SunToolkit extends Toolkit * EventQueue yet. */ public static void flushPendingEvents() { + AppContext appContext = AppContext.getAppContext(); + flushPendingEvents(appContext); + } + + public static void flushPendingEvents(AppContext appContext) { flushLock.lock(); try { // Don't call flushPendingEvents() recursively if (!isFlushingPendingEvents) { isFlushingPendingEvents = true; - AppContext appContext = AppContext.getAppContext(); - PostEventQueue postEventQueue = - (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY); - if (postEventQueue != null) { - postEventQueue.flush(); + try { + PostEventQueue postEventQueue = + (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY); + if (postEventQueue != null) { + postEventQueue.flush(); + } + } + finally { + isFlushingPendingEvents = false; } } } finally { - isFlushingPendingEvents = false; flushLock.unlock(); } } @@ -798,10 +811,6 @@ public abstract class SunToolkit extends Toolkit //with scale factors x1, x3/4, x2/3, xN, x1/N. Image im = i.next(); if (im == null) { - if (log.isLoggable(PlatformLogger.FINER)) { - log.finer("SunToolkit.getScaledIconImage: " + - "Skipping the image passed into Java because it's null."); - } continue; } if (im instanceof ToolkitImage) { @@ -814,10 +823,6 @@ public abstract class SunToolkit extends Toolkit iw = im.getWidth(null); ih = im.getHeight(null); } catch (Exception e){ - if (log.isLoggable(PlatformLogger.FINER)) { - log.finer("SunToolkit.getScaledIconImage: " + - "Perhaps the image passed into Java is broken. Skipping this icon."); - } continue; } if (iw > 0 && ih > 0) { @@ -889,14 +894,6 @@ public abstract class SunToolkit extends Toolkit try { int x = (width - bestWidth) / 2; int y = (height - bestHeight) / 2; - if (log.isLoggable(PlatformLogger.FINER)) { - log.finer("WWindowPeer.getScaledIconData() result : " + - "w : " + width + " h : " + height + - " iW : " + bestImage.getWidth(null) + " iH : " + bestImage.getHeight(null) + - " sim : " + bestSimilarity + " sf : " + bestScaleFactor + - " adjW : " + bestWidth + " adjH : " + bestHeight + - " x : " + x + " y : " + y); - } g.drawImage(bestImage, x, y, bestWidth, bestHeight, null); } finally { g.dispose(); @@ -907,10 +904,6 @@ public abstract class SunToolkit extends Toolkit public static DataBufferInt getScaledIconData(java.util.List<Image> imageList, int width, int height) { BufferedImage bimage = getScaledIconImage(imageList, width, height); if (bimage == null) { - if (log.isLoggable(PlatformLogger.FINER)) { - log.finer("SunToolkit.getScaledIconData: " + - "Perhaps the image passed into Java is broken. Skipping this icon."); - } return null; } Raster raster = bimage.getRaster(); @@ -1768,25 +1761,6 @@ public abstract class SunToolkit extends Toolkit return (Window)comp; } - /** - * Returns the value of the system property indicated by the specified key. - */ - public static String getSystemProperty(final String key) { - return (String)AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(key); - } - }); - } - - /** - * Returns the boolean value of the system property indicated by the specified key. - */ - protected static Boolean getBooleanSystemProperty(String key) { - return Boolean.valueOf(AccessController. - doPrivileged(new GetBooleanAction(key))); - } - private static Boolean sunAwtDisableMixing = null; /** @@ -1795,7 +1769,8 @@ public abstract class SunToolkit extends Toolkit */ public synchronized static boolean getSunAwtDisableMixing() { if (sunAwtDisableMixing == null) { - sunAwtDisableMixing = getBooleanSystemProperty("sun.awt.disableMixing"); + sunAwtDisableMixing = AccessController.doPrivileged( + new GetBooleanAction("sun.awt.disableMixing")); } return sunAwtDisableMixing.booleanValue(); } @@ -1809,6 +1784,28 @@ public abstract class SunToolkit extends Toolkit return false; } + private static final Object DEACTIVATION_TIMES_MAP_KEY = new Object(); + + public synchronized void setWindowDeactivationTime(Window w, long time) { + AppContext ctx = getAppContext(w); + WeakHashMap<Window, Long> map = (WeakHashMap<Window, Long>)ctx.get(DEACTIVATION_TIMES_MAP_KEY); + if (map == null) { + map = new WeakHashMap<Window, Long>(); + ctx.put(DEACTIVATION_TIMES_MAP_KEY, map); + } + map.put(w, time); + } + + public synchronized long getWindowDeactivationTime(Window w) { + AppContext ctx = getAppContext(w); + WeakHashMap<Window, Long> map = (WeakHashMap<Window, Long>)ctx.get(DEACTIVATION_TIMES_MAP_KEY); + if (map == null) { + return -1; + } + Long time = map.get(w); + return time == null ? -1 : time; + } + // Cosntant alpha public boolean isWindowOpacitySupported() { return false; @@ -1829,6 +1826,13 @@ public abstract class SunToolkit extends Toolkit } /** + * Returns true if swing backbuffer should be translucent. + */ + public boolean isSwingBackbufferTranslucencySupported() { + return false; + } + + /** * Returns whether or not a containing top level window for the passed * component is * {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT PERPIXEL_TRANSLUCENT}. @@ -1949,25 +1953,41 @@ class PostEventQueue { private EventQueueItem queueTail = null; private final EventQueue eventQueue; + // For the case when queue is cleared but events are not posted + private volatile boolean isFlushing = false; + PostEventQueue(EventQueue eq) { eventQueue = eq; } public synchronized boolean noEvents() { - return queueHead == null; + return queueHead == null && !isFlushing; } /* * Continually post pending AWTEvents to the Java EventQueue. The method * is synchronized to ensure the flush is completed before a new event * can be posted to this queue. + * + * 7177040: The method couldn't be wholly synchronized because of calls + * of EventQueue.postEvent() that uses pushPopLock, otherwise it could + * potentially lead to deadlock */ - public synchronized void flush() { - EventQueueItem tempQueue = queueHead; - queueHead = queueTail = null; - while (tempQueue != null) { - eventQueue.postEvent(tempQueue.event); - tempQueue = tempQueue.next; + public void flush() { + EventQueueItem tempQueue; + synchronized (this) { + tempQueue = queueHead; + queueHead = queueTail = null; + isFlushing = (tempQueue != null); + } + try { + while (tempQueue != null) { + eventQueue.postEvent(tempQueue.event); + tempQueue = tempQueue.next; + } + } + finally { + isFlushing = false; } } diff --git a/external/ikvm/openjdk/sun/awt/image/ByteComponentRaster.java b/external/ikvm/openjdk/sun/awt/image/ByteComponentRaster.java deleted file mode 100644 index 912542a7bf..0000000000 --- a/external/ikvm/openjdk/sun/awt/image/ByteComponentRaster.java +++ /dev/null @@ -1,919 +0,0 @@ -/* - * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code 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 - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package sun.awt.image; -import java.awt.image.Raster; -import java.awt.image.WritableRaster; -import java.awt.image.RasterFormatException; -import java.awt.image.SampleModel; -import java.awt.image.ComponentSampleModel; -import java.awt.image.SinglePixelPackedSampleModel; -import java.awt.image.DataBuffer; -import java.awt.image.DataBufferByte; -import java.awt.Rectangle; -import java.awt.Point; - -/** - * This class defines a Raster with pixels consisting of one or more 8-bit - * data elements stored in close proximity to each other in a single byte - * array. - * The bit precision per data element is that - * of the data type (that is, the bit precision for this Raster is 8). - * There is only one pixel stride and one scanline stride for all - * bands. This type of Raster can be used with a - * ComponentColorModel if there are multiple bands, or an - * IndexColorModel if there is only one band. - * <p> - * For example, 3-3-2 RGB image data can be represented by a - * ByteComponentRaster using a SinglePixelPackedSampleModel and - * a ComponentColorModel. - * - */ -public class ByteComponentRaster extends SunWritableRaster { - - /** private band offset for use by native code */ - protected int bandOffset; - - /** Data offsets for each band of image data. */ - protected int[] dataOffsets; - - /** Scanline stride of the image data contained in this Raster. */ - protected int scanlineStride; - - /** Pixel stride of the image data contained in this Raster. */ - protected int pixelStride; - - /** The image data array. */ - protected byte[] data; - - int type; - - /** A cached copy of minX + width for use in bounds checks. */ - private int maxX; - - /** A cached copy of minY + height for use in bounds checks. */ - private int maxY; - - /** - * Constructs a ByteComponentRaster with the given SampleModel. - * The Raster's upper left corner is origin and it is the same - * size as the SampleModel. A DataBuffer large enough to describe the - * Raster is automatically created. SampleModel must be of type - * SinglePixelPackedSampleModel or ComponentSampleModel. - * @param sampleModel The SampleModel that specifies the layout. - * @param origin The Point that specified the origin. - */ - public ByteComponentRaster(SampleModel sampleModel, Point origin) { - this(sampleModel, - sampleModel.createDataBuffer(), - new Rectangle(origin.x, - origin.y, - sampleModel.getWidth(), - sampleModel.getHeight()), - origin, - null); - } - - /** - * Constructs a ByteComponentRaster with the given SampleModel - * and DataBuffer. The Raster's upper left corner is origin and - * it is the same size as the SampleModel. The DataBuffer is not - * initialized and must be a DataBufferByte compatible with SampleModel. - * SampleModel must be of type SinglePixelPackedSampleModel - * or ComponentSampleModel. - * @param sampleModel The SampleModel that specifies the layout. - * @param dataBuffer The DataBufferShort that contains the image data. - * @param origin The Point that specifies the origin. - */ - public ByteComponentRaster(SampleModel sampleModel, - DataBuffer dataBuffer, - Point origin) { - this(sampleModel, - dataBuffer, - new Rectangle(origin.x, - origin.y, - sampleModel.getWidth(), - sampleModel.getHeight()), - origin, - null); - } - - /** - * Constructs a ByteComponentRaster with the given SampleModel, - * DataBuffer, and parent. DataBuffer must be a DataBufferByte and - * SampleModel must be of type SinglePixelPackedSampleModel - * or ComponentSampleModel. - * When translated into the base Raster's - * coordinate system, aRegion must be contained by the base Raster. - * Origin is the coordinate in the new Raster's coordinate system of - * the origin of the base Raster. (The base Raster is the Raster's - * ancestor which has no parent.) - * - * Note that this constructor should generally be called by other - * constructors or create methods, it should not be used directly. - * @param sampleModel The SampleModel that specifies the layout. - * @param dataBuffer The DataBufferShort that contains the image data. - * @param aRegion The Rectangle that specifies the image area. - * @param origin The Point that specifies the origin. - * @param parent The parent (if any) of this raster. - */ - public ByteComponentRaster(SampleModel sampleModel, - DataBuffer dataBuffer, - Rectangle aRegion, - Point origin, - ByteComponentRaster parent) { - super(sampleModel, dataBuffer, aRegion, origin, parent); - this.maxX = minX + width; - this.maxY = minY + height; - - if (!(dataBuffer instanceof DataBufferByte)) { - throw new RasterFormatException("ByteComponentRasters must have " + - "byte DataBuffers"); - } - - DataBufferByte dbb = (DataBufferByte)dataBuffer; - this.data = stealData(dbb, 0); - if (dbb.getNumBanks() != 1) { - throw new - RasterFormatException("DataBuffer for ByteComponentRasters"+ - " must only have 1 bank."); - } - int dbOffset = dbb.getOffset(); - - if (sampleModel instanceof ComponentSampleModel) { - ComponentSampleModel ism = (ComponentSampleModel)sampleModel; - this.type = IntegerComponentRaster.TYPE_BYTE_SAMPLES; - this.scanlineStride = ism.getScanlineStride(); - this.pixelStride = ism.getPixelStride(); - this.dataOffsets = ism.getBandOffsets(); - int xOffset = aRegion.x - origin.x; - int yOffset = aRegion.y - origin.y; - for (int i = 0; i < getNumDataElements(); i++) { - dataOffsets[i] += dbOffset + - xOffset*pixelStride+yOffset*scanlineStride; - } - } else if (sampleModel instanceof SinglePixelPackedSampleModel) { - SinglePixelPackedSampleModel sppsm = - (SinglePixelPackedSampleModel)sampleModel; - this.type = IntegerComponentRaster.TYPE_BYTE_PACKED_SAMPLES; - this.scanlineStride = sppsm.getScanlineStride(); - this.pixelStride = 1; - this.dataOffsets = new int[1]; - this.dataOffsets[0] = dbOffset; - int xOffset = aRegion.x - origin.x; - int yOffset = aRegion.y - origin.y; - dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride; - } else { - throw new RasterFormatException("IntegerComponentRasters must " + - "have ComponentSampleModel or SinglePixelPackedSampleModel"); - } - this.bandOffset = this.dataOffsets[0]; - - verify(false); - } - - /** - * Returns a copy of the data offsets array. For each band the data offset - * is the index into the band's data array, of the first sample of the - * band. - */ - public int[] getDataOffsets() { - return (int[]) dataOffsets.clone(); - } - - /** - * Returns the data offset for the specified band. The data offset - * is the index into the data array - * in which the first sample of the first scanline is stored. - * @param band The band whose offset is returned. - */ - public int getDataOffset(int band) { - return dataOffsets[band]; - } - - /** - * Returns the scanline stride -- the number of data array elements between - * a given sample and the sample in the same column of the next row in the - * same band. - */ - public int getScanlineStride() { - return scanlineStride; - } - - /** - * Returns pixel stride -- the number of data array elements between two - * samples for the same band on the same scanline. - */ - public int getPixelStride() { - return pixelStride; - } - - /** - * Returns a reference to the data array. - */ - public byte[] getDataStorage() { - return data; - } - - /** - * Returns the data elements for all bands at the specified - * location. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinate is out of bounds. - * A ClassCastException will be thrown if the input object is non null - * and references anything other than an array of transferType. - * @param x The X coordinate of the pixel location. - * @param y The Y coordinate of the pixel location. - * @param outData An object reference to an array of type defined by - * getTransferType() and length getNumDataElements(). - * If null an array of appropriate type and size will be - * allocated. - * @return An object reference to an array of type defined by - * getTransferType() with the request pixel data. - */ - public Object getDataElements(int x, int y, Object obj) { - if ((x < this.minX) || (y < this.minY) || - (x >= this.maxX) || (y >= this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - byte outData[]; - if (obj == null) { - outData = new byte[numDataElements]; - } else { - outData = (byte[])obj; - } - int off = (y-minY)*scanlineStride + - (x-minX)*pixelStride; - - for (int band = 0; band < numDataElements; band++) { - outData[band] = data[dataOffsets[band] + off]; - } - - return outData; - } - - /** - * Returns an array of data elements from the specified rectangular - * region. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * A ClassCastException will be thrown if the input object is non null - * and references anything other than an array of transferType. - * <pre> - * byte[] bandData = (byte[])raster.getDataElements(x, y, w, h, null); - * int numDataElements = raster.getNumDataElements(); - * byte[] pixel = new byte[numDataElements]; - * // To find a data element at location (x2, y2) - * System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements, - * pixel, 0, numDataElements); - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param width Width of the pixel rectangle. - * @param height Height of the pixel rectangle. - * @param outData An object reference to an array of type defined by - * getTransferType() and length w*h*getNumDataElements(). - * If null an array of appropriate type and size will be - * allocated. - * @return An object reference to an array of type defined by - * getTransferType() with the request pixel data. - */ - public Object getDataElements(int x, int y, int w, int h, Object obj) { - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - byte outData[]; - if (obj == null) { - outData = new byte[w*h*numDataElements]; - } else { - outData = (byte[])obj; - } - - int yoff = (y-minY)*scanlineStride + - (x-minX)*pixelStride; - int xoff; - int off = 0; - int xstart; - int ystart; - - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - xoff = yoff; - for (xstart=0; xstart < w; xstart++, xoff += pixelStride) { - for (int c = 0; c < numDataElements; c++) { - outData[off++] = data[dataOffsets[c] + xoff]; - } - } - } - - return outData; - } - - /** - * Returns a byte array of data elements from the specified rectangular - * region for the specified band. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * <pre> - * byte[] bandData = raster.getByteData(x, y, w, h, null); - * // To find the data element at location (x2, y2) - * byte bandElement = bandData[((y2-y)*w + (x2-x))]; - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param width Width of the pixel rectangle. - * @param height Height of the pixel rectangle. - * @param band The band to return. - * @param outData If non-null, data elements for all bands - * at the specified location are returned in this array. - * @return Data array with data elements for all bands. - */ - public byte[] getByteData(int x, int y, int w, int h, - int band, byte[] outData) { - // Bounds check for 'band' will be performed automatically - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - if (outData == null) { - outData = new byte[scanlineStride*h]; - } - int yoff = (y-minY)*scanlineStride + - (x-minX)*pixelStride + dataOffsets[band]; - int xoff; - int off = 0; - int xstart; - int ystart; - - if (pixelStride == 1) { - if (scanlineStride == w) { - System.arraycopy(data, yoff, outData, 0, w*h); - } - else { - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - System.arraycopy(data, yoff, outData, off, w); - off += w; - } - } - } - else { - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - xoff = yoff; - for (xstart=0; xstart < w; xstart++, xoff += pixelStride) { - outData[off++] = data[xoff]; - } - } - } - - return outData; - } - - /** - * Returns a byte array of data elements from the specified rectangular - * region. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * <pre> - * byte[] bandData = raster.getByteData(x, y, w, h, null); - * int numDataElements = raster.getnumDataElements(); - * byte[] pixel = new byte[numDataElements]; - * // To find a data element at location (x2, y2) - * System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements, - * pixel, 0, numDataElements); - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param width Width of the pixel rectangle. - * @param height Height of the pixel rectangle. - * @param outData If non-null, data elements for all bands - * at the specified location are returned in this array. - * @return Data array with data elements for all bands. - */ - public byte[] getByteData(int x, int y, int w, int h, byte[] outData) { - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - if (outData == null) { - outData = new byte[numDataElements*scanlineStride*h]; - } - int yoff = (y-minY)*scanlineStride + - (x-minX)*pixelStride; - int xoff; - int off = 0; - int xstart; - int ystart; - - // REMIND: Should keep track if dataOffsets are in a nice order - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - xoff = yoff; - for (xstart=0; xstart < w; xstart++, xoff += pixelStride) { - for (int c = 0; c < numDataElements; c++) { - outData[off++] = data[dataOffsets[c] + xoff]; - } - } - } - - return outData; - } - - /** - * Stores the data elements for all bands at the specified location. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinate is out of bounds. - * A ClassCastException will be thrown if the input object is non null - * and references anything other than an array of transferType. - * @param x The X coordinate of the pixel location. - * @param y The Y coordinate of the pixel location. - * @param inData An object reference to an array of type defined by - * getTransferType() and length getNumDataElements() - * containing the pixel data to place at x,y. - */ - public void setDataElements(int x, int y, Object obj) { - if ((x < this.minX) || (y < this.minY) || - (x >= this.maxX) || (y >= this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - byte inData[] = (byte[])obj; - int off = (y-minY)*scanlineStride + - (x-minX)*pixelStride; - - for (int i = 0; i < numDataElements; i++) { - data[dataOffsets[i] + off] = inData[i]; - } - - markDirty(); - } - - /** - * Stores the Raster data at the specified location. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * @param x The X coordinate of the pixel location. - * @param y The Y coordinate of the pixel location. - * @param inRaster Raster of data to place at x,y location. - */ - public void setDataElements(int x, int y, Raster inRaster) { - int dstOffX = inRaster.getMinX() + x; - int dstOffY = inRaster.getMinY() + y; - int width = inRaster.getWidth(); - int height = inRaster.getHeight(); - if ((dstOffX < this.minX) || (dstOffY < this.minY) || - (dstOffX + width > this.maxX) || (dstOffY + height > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - - setDataElements(dstOffX, dstOffY, width, height, inRaster); - } - - /** - * Stores the Raster data at the specified location. - * @param dstX The absolute X coordinate of the destination pixel - * that will receive a copy of the upper-left pixel of the - * inRaster - * @param dstY The absolute Y coordinate of the destination pixel - * that will receive a copy of the upper-left pixel of the - * inRaster - * @param width The number of pixels to store horizontally - * @param height The number of pixels to store vertically - * @param inRaster Raster of data to place at x,y location. - */ - private void setDataElements(int dstX, int dstY, - int width, int height, - Raster inRaster) { - // Assume bounds checking has been performed previously - if (width <= 0 || height <= 0) { - return; - } - - int srcOffX = inRaster.getMinX(); - int srcOffY = inRaster.getMinY(); - Object tdata = null; - - if (inRaster instanceof ByteComponentRaster) { - ByteComponentRaster bct = (ByteComponentRaster) inRaster; - byte[] bdata = bct.getDataStorage(); - // REMIND: Do something faster! - if (numDataElements == 1) { - int toff = bct.getDataOffset(0); - int tss = bct.getScanlineStride(); - - int srcOffset = toff; - int dstOffset = dataOffsets[0]+(dstY-minY)*scanlineStride+ - (dstX-minX); - - - if (pixelStride == bct.getPixelStride()) { - width *= pixelStride; - for (int tmpY=0; tmpY < height; tmpY++) { - System.arraycopy(bdata, srcOffset, - data, dstOffset, width); - srcOffset += tss; - dstOffset += scanlineStride; - } - markDirty(); - return; - } - } - } - - for (int startY=0; startY < height; startY++) { - // Grab one scanline at a time - tdata = inRaster.getDataElements(srcOffX, srcOffY+startY, - width, 1, tdata); - setDataElements(dstX, dstY+startY, width, 1, tdata); - } - } - - /** - * Stores an array of data elements into the specified rectangular - * region. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * A ClassCastException will be thrown if the input object is non null - * and references anything other than an array of transferType. - * The data elements in the - * data array are assumed to be packed. That is, a data element - * for the nth band at location (x2, y2) would be found at: - * <pre> - * inData[((y2-y)*w + (x2-x))*numDataElements + n] - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param w Width of the pixel rectangle. - * @param h Height of the pixel rectangle. - * @param inData An object reference to an array of type defined by - * getTransferType() and length w*h*getNumDataElements() - * containing the pixel data to place between x,y and - * x+h, y+h. - */ - public void setDataElements(int x, int y, int w, int h, Object obj) { - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - byte inData[] = (byte[])obj; - int yoff = (y-minY)*scanlineStride + - (x-minX)*pixelStride; - int xoff; - int off = 0; - int xstart; - int ystart; - - if (numDataElements == 1) { - int srcOffset = 0; - int dstOffset = yoff + dataOffsets[0]; - for (ystart=0; ystart < h; ystart++) { - xoff = yoff; - System.arraycopy(inData, srcOffset, - data, dstOffset, w); - - srcOffset += w; - dstOffset += scanlineStride; - } - markDirty(); - return; - } - - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - xoff = yoff; - for (xstart=0; xstart < w; xstart++, xoff += pixelStride) { - for (int c = 0; c < numDataElements; c++) { - data[dataOffsets[c] + xoff] = inData[off++]; - } - } - } - - markDirty(); - } - - /** - * Stores a byte array of data elements into the specified rectangular - * region for the specified band. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * The data elements in the - * data array are assumed to be packed. That is, a data element - * at location (x2, y2) would be found at: - * <pre> - * inData[((y2-y)*w + (x2-x)) + n] - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param w Width of the pixel rectangle. - * @param h Height of the pixel rectangle. - * @param band The band to set. - * @param inData The data elements to be stored. - */ - public void putByteData(int x, int y, int w, int h, - int band, byte[] inData) { - // Bounds check for 'band' will be performed automatically - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - int yoff = (y-minY)*scanlineStride + - (x-minX)*pixelStride + dataOffsets[band]; - int xoff; - int off = 0; - int xstart; - int ystart; - - if (pixelStride == 1) { - if (scanlineStride == w) { - System.arraycopy(inData, 0, data, yoff, w*h); - } - else { - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - System.arraycopy(inData, off, data, yoff, w); - off += w; - } - } - } - else { - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - xoff = yoff; - for (xstart=0; xstart < w; xstart++, xoff += pixelStride) { - data[xoff] = inData[off++]; - } - } - } - - markDirty(); - } - - /** - * Stores a byte array of data elements into the specified rectangular - * region. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * The data elements in the - * data array are assumed to be packed. That is, a data element - * for the nth band at location (x2, y2) would be found at: - * <pre> - * inData[((y2-y)*w + (x2-x))*numDataElements + n] - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param w Width of the pixel rectangle. - * @param h Height of the pixel rectangle. - * @param inData The data elements to be stored. - */ - public void putByteData(int x, int y, int w, int h, byte[] inData) { - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - int yoff = (y-minY)*scanlineStride + - (x-minX)*pixelStride; - - int xoff; - int off = 0; - int xstart; - int ystart; - - if (numDataElements == 1) { - yoff += dataOffsets[0]; - if (pixelStride == 1) { - if (scanlineStride == w) { - System.arraycopy(inData, 0, data, yoff, w*h); - } - else { - for (ystart=0; ystart < h; ystart++) { - System.arraycopy(inData, off, data, yoff, w); - off += w; - yoff += scanlineStride; - } - } - } - else { - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - xoff = yoff; - for (xstart=0; xstart < w; xstart++, xoff += pixelStride) { - data[xoff] = inData[off++]; - } - } - } - } - else { - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - xoff = yoff; - for (xstart=0; xstart < w; xstart++, xoff += pixelStride) { - for (int c = 0; c < numDataElements; c++) { - data[dataOffsets[c] + xoff] = inData[off++]; - } - } - } - } - - markDirty(); - } - - /** - * Creates a subraster given a region of the raster. The x and y - * coordinates specify the horizontal and vertical offsets - * from the upper-left corner of this raster to the upper-left corner - * of the subraster. A subset of the bands of the parent Raster may - * be specified. If this is null, then all the bands are present in the - * subRaster. A translation to the subRaster may also be specified. - * Note that the subraster will reference the same - * DataBuffer as the parent raster, but using different offsets. - * @param x X offset. - * @param y Y offset. - * @param width Width (in pixels) of the subraster. - * @param height Height (in pixels) of the subraster. - * @param x0 Translated X origin of the subraster. - * @param y0 Translated Y origin of the subraster. - * @param bandList Array of band indices. - * @exception RasterFormatException - * if the specified bounding box is outside of the parent raster. - */ - public Raster createChild(int x, int y, - int width, int height, - int x0, int y0, int[] bandList) { - WritableRaster newRaster = createWritableChild(x, y, - width, height, - x0, y0, - bandList); - return (Raster) newRaster; - } - - /** - * Creates a Writable subRaster given a region of the Raster. The x and y - * coordinates specify the horizontal and vertical offsets - * from the upper-left corner of this Raster to the upper-left corner - * of the subRaster. A subset of the bands of the parent Raster may - * be specified. If this is null, then all the bands are present in the - * subRaster. A translation to the subRaster may also be specified. - * Note that the subRaster will reference the same - * DataBuffer as the parent Raster, but using different offsets. - * @param x X offset. - * @param y Y offset. - * @param width Width (in pixels) of the subraster. - * @param height Height (in pixels) of the subraster. - * @param x0 Translated X origin of the subraster. - * @param y0 Translated Y origin of the subraster. - * @param bandList Array of band indices. - * @exception RasterFormatException - * if the specified bounding box is outside of the parent Raster. - */ - public WritableRaster createWritableChild(int x, int y, - int width, int height, - int x0, int y0, - int[] bandList) { - if (x < this.minX) { - throw new RasterFormatException("x lies outside the raster"); - } - if (y < this.minY) { - throw new RasterFormatException("y lies outside the raster"); - } - if ((x+width < x) || (x+width > this.minX + this.width)) { - throw new RasterFormatException("(x + width) is outside of Raster"); - } - if ((y+height < y) || (y+height > this.minY + this.height)) { - throw new RasterFormatException("(y + height) is outside of Raster"); - } - - SampleModel sm; - - if (bandList != null) - sm = sampleModel.createSubsetSampleModel(bandList); - else - sm = sampleModel; - - int deltaX = x0 - x; - int deltaY = y0 - y; - - return new ByteComponentRaster(sm, - dataBuffer, - new Rectangle(x0, y0, width, height), - new Point(sampleModelTranslateX+deltaX, - sampleModelTranslateY+deltaY), - this); - } - - /** - * Creates a Raster with the same layout but using a different - * width and height, and with new zeroed data arrays. - */ - public WritableRaster createCompatibleWritableRaster(int w, int h) { - if (w <= 0 || h <=0) { - throw new RasterFormatException("negative "+ - ((w <= 0) ? "width" : "height")); - } - - SampleModel sm = sampleModel.createCompatibleSampleModel(w, h); - - return new ByteComponentRaster(sm , new Point(0,0)); - - } - - /** - * Creates a Raster with the same layout and the same - * width and height, and with new zeroed data arrays. If - * the Raster is a subRaster, this will call - * createCompatibleRaster(width, height). - */ - public WritableRaster createCompatibleWritableRaster() { - return createCompatibleWritableRaster(width,height); - } - - /** - * Verify that the layout parameters are consistent with - * the data. If strictCheck - * is false, this method will check for ArrayIndexOutOfBounds conditions. If - * strictCheck is true, this method will check for additional error - * conditions such as line wraparound (width of a line greater than - * the scanline stride). - * @return String Error string, if the layout is incompatible with - * the data. Otherwise returns null. - */ - private void verify (boolean strictCheck) { - // Make sure data for Raster is in a legal range - for (int i=0; i < dataOffsets.length; i++) { - if (dataOffsets[i] < 0) { - throw new RasterFormatException("Data offsets for band "+i+ - "("+dataOffsets[i]+ - ") must be >= 0"); - } - } - - int maxSize = 0; - int size; - - for (int i=0; i < numDataElements; i++) { - size = (height-1)*scanlineStride + (width-1)*pixelStride + - dataOffsets[i]; - if (size > maxSize) { - maxSize = size; - } - } - if (data.length < maxSize) { - throw new RasterFormatException("Data array too small (should be "+ - maxSize+" )"); - } - } - - public String toString() { - return new String ("ByteComponentRaster: width = "+width+" height = " - + height - +" #numDataElements "+numDataElements - // +" xOff = "+xOffset+" yOff = "+yOffset - +" dataOff[0] = "+dataOffsets[0]); - } - -// /** -// * For debugging... prints a region of a one-band ByteComponentRaster -// */ -// public void print(int x, int y, int w, int h) { -// // REMIND: Only works for 1 band! -// System.out.println(this); -// int offset = dataOffsets[0] + y*scanlineStride + x*pixelStride; -// int off; -// for (int yoff=0; yoff < h; yoff++, offset += scanlineStride) { -// off = offset; -// System.out.print("Line "+(y+yoff)+": "); -// for (int xoff = 0; xoff < w; xoff++, off+= pixelStride) { -// String s = Integer.toHexString(data[off]); -// if (s.length() == 8) { -// s = s.substring(6,8); -// } -// System.out.print(s+" "); -// } -// System.out.println(""); -// } -// } - - -} diff --git a/external/ikvm/openjdk/sun/awt/image/BytePackedRaster.java b/external/ikvm/openjdk/sun/awt/image/BytePackedRaster.java deleted file mode 100644 index 25c84f42a0..0000000000 --- a/external/ikvm/openjdk/sun/awt/image/BytePackedRaster.java +++ /dev/null @@ -1,1389 +0,0 @@ -/* - * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code 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 - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package sun.awt.image; -import java.awt.image.Raster; -import java.awt.image.WritableRaster; -import java.awt.image.RasterFormatException; -import java.awt.image.SampleModel; -import java.awt.image.MultiPixelPackedSampleModel; -import java.awt.image.DataBuffer; -import java.awt.image.DataBufferByte; -import java.awt.Rectangle; -import java.awt.Point; - -/** - * This class is useful for describing 1, 2, or 4 bit image data - * elements. This raster has one band whose pixels are packed - * together into individual bytes in a single byte array. This type - * of raster can be used with an IndexColorModel. This raster uses a - * MultiPixelPackedSampleModel. - * - */ -public class BytePackedRaster extends SunWritableRaster { - - /** The data bit offset for each pixel. */ - int dataBitOffset; - - /** Scanline stride of the image data contained in this Raster. */ - int scanlineStride; - - /** - * The bit stride of a pixel, equal to the total number of bits - * required to store a pixel. - */ - int pixelBitStride; - - /** The bit mask for extracting the pixel. */ - int bitMask; - - /** The image data array. */ - byte[] data; - - /** 8 minus the pixel bit stride. */ - int shiftOffset; - - int type; - - /** A cached copy of minX + width for use in bounds checks. */ - private int maxX; - - /** A cached copy of minY + height for use in bounds checks. */ - private int maxY; - - /** - * Constructs a BytePackedRaster with the given SampleModel. - * The Raster's upper left corner is origin and it is the same - * size as the SampleModel. A DataBuffer large enough to describe the - * Raster is automatically created. SampleModel must be of type - * MultiPixelPackedSampleModel. - * @param sampleModel The SampleModel that specifies the layout. - * @param origin The Point that specified the origin. - */ - public BytePackedRaster(SampleModel sampleModel, - Point origin) { - this(sampleModel, - sampleModel.createDataBuffer(), - new Rectangle(origin.x, - origin.y, - sampleModel.getWidth(), - sampleModel.getHeight()), - origin, - null); - } - - /** - * Constructs a BytePackedRaster with the given SampleModel - * and DataBuffer. The Raster's upper left corner is origin and - * it is the same size as the SampleModel. The DataBuffer is not - * initialized and must be a DataBufferByte compatible with SampleModel. - * SampleModel must be of type MultiPixelPackedSampleModel. - * @param sampleModel The SampleModel that specifies the layout. - * @param dataBuffer The DataBufferShort that contains the image data. - * @param origin The Point that specifies the origin. - */ - public BytePackedRaster(SampleModel sampleModel, - DataBuffer dataBuffer, - Point origin) { - this(sampleModel, - dataBuffer, - new Rectangle(origin.x, - origin.y, - sampleModel.getWidth(), - sampleModel.getHeight()), - origin, - null); - } - - /** - * Constructs a BytePackedRaster with the given SampleModel, - * DataBuffer, and parent. DataBuffer must be a DataBufferByte and - * SampleModel must be of type MultiPixelPackedSampleModel. - * When translated into the base Raster's - * coordinate system, aRegion must be contained by the base Raster. - * Origin is the coordinate in the new Raster's coordinate system of - * the origin of the base Raster. (The base Raster is the Raster's - * ancestor which has no parent.) - * - * Note that this constructor should generally be called by other - * constructors or create methods, it should not be used directly. - * @param sampleModel The SampleModel that specifies the layout. - * @param dataBuffer The DataBufferShort that contains the image data. - * @param aRegion The Rectangle that specifies the image area. - * @param origin The Point that specifies the origin. - * @param parent The parent (if any) of this raster. - * - * @exception RasterFormatException if the parameters do not conform - * to requirements of this Raster type. - */ - public BytePackedRaster(SampleModel sampleModel, - DataBuffer dataBuffer, - Rectangle aRegion, - Point origin, - BytePackedRaster parent){ - super(sampleModel,dataBuffer,aRegion,origin, parent); - this.maxX = minX + width; - this.maxY = minY + height; - - if (!(dataBuffer instanceof DataBufferByte)) { - throw new RasterFormatException("BytePackedRasters must have" + - "byte DataBuffers"); - } - DataBufferByte dbb = (DataBufferByte)dataBuffer; - this.data = stealData(dbb, 0); - if (dbb.getNumBanks() != 1) { - throw new - RasterFormatException("DataBuffer for BytePackedRasters"+ - " must only have 1 bank."); - } - int dbOffset = dbb.getOffset(); - - if (sampleModel instanceof MultiPixelPackedSampleModel) { - MultiPixelPackedSampleModel mppsm = - (MultiPixelPackedSampleModel)sampleModel; - this.type = IntegerComponentRaster.TYPE_BYTE_BINARY_SAMPLES; - pixelBitStride = mppsm.getPixelBitStride(); - if (pixelBitStride != 1 && - pixelBitStride != 2 && - pixelBitStride != 4) { - throw new RasterFormatException - ("BytePackedRasters must have a bit depth of 1, 2, or 4"); - } - scanlineStride = mppsm.getScanlineStride(); - dataBitOffset = mppsm.getDataBitOffset() + dbOffset*8; - int xOffset = aRegion.x - origin.x; - int yOffset = aRegion.y - origin.y; - dataBitOffset += xOffset*pixelBitStride + yOffset*scanlineStride*8; - bitMask = (1 << pixelBitStride) -1; - shiftOffset = 8 - pixelBitStride; - } else { - throw new RasterFormatException("BytePackedRasters must have"+ - "MultiPixelPackedSampleModel"); - } - verify(false); - } - - /** - * Returns the data bit offset for the Raster. The data - * bit offset is the bit index into the data array element - * corresponding to the first sample of the first scanline. - */ - public int getDataBitOffset() { - return dataBitOffset; - } - - /** - * Returns the scanline stride -- the number of data array elements between - * a given sample and the sample in the same column - * of the next row. - */ - public int getScanlineStride() { - return scanlineStride; - } - - /** - * Returns pixel bit stride -- the number of bits between two - * samples on the same scanline. - */ - public int getPixelBitStride() { - return pixelBitStride; - } - - /** - * Returns a reference to the entire data array. - */ - public byte[] getDataStorage() { - return data; - } - - /** - * Returns the data element at the specified - * location. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinate is out of bounds. - * A ClassCastException will be thrown if the input object is non null - * and references anything other than an array of transferType. - * @param x The X coordinate of the pixel location. - * @param y The Y coordinate of the pixel location. - * @param outData An object reference to an array of type defined by - * getTransferType() and length getNumDataElements(). - * If null an array of appropriate type and size will be - * allocated. - * @return An object reference to an array of type defined by - * getTransferType() with the request pixel data. - */ - public Object getDataElements(int x, int y, Object obj) { - if ((x < this.minX) || (y < this.minY) || - (x >= this.maxX) || (y >= this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - byte outData[]; - if (obj == null) { - outData = new byte[numDataElements]; - } else { - outData = (byte[])obj; - } - int bitnum = dataBitOffset + (x-minX) * pixelBitStride; - // Fix 4184283 - int element = data[(y-minY) * scanlineStride + (bitnum >> 3)] & 0xff; - int shift = shiftOffset - (bitnum & 7); - outData[0] = (byte)((element >> shift) & bitMask); - return outData; - } - - /** - * Returns the pixel data for the specified rectangle of pixels in a - * primitive array of type TransferType. - * For image data supported by the Java 2D API, this - * will be one of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or - * DataBuffer.TYPE_INT. Data may be returned in a packed format, - * thus increasing efficiency for data transfers. - * - * An ArrayIndexOutOfBoundsException may be thrown - * if the coordinates are not in bounds. - * A ClassCastException will be thrown if the input object is non null - * and references anything other than an array of TransferType. - * @see java.awt.image.SampleModel#getDataElements(int, int, int, int, Object, DataBuffer) - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param w Width of the pixel rectangle. - * @param h Height of the pixel rectangle. - * @param outData An object reference to an array of type defined by - * getTransferType() and length w*h*getNumDataElements(). - * If null, an array of appropriate type and size will be - * allocated. - * @return An object reference to an array of type defined by - * getTransferType() with the requested pixel data. - */ - public Object getDataElements(int x, int y, int w, int h, - Object outData) { - return getByteData(x, y, w, h, (byte[])outData); - } - - /** - * Returns an array of data elements from the specified rectangular - * region. - * - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * A ClassCastException will be thrown if the input object is non null - * and references anything other than an array of transferType. - * <pre> - * byte[] bandData = (byte[])raster.getPixelData(x, y, w, h, null); - * int pixel; - * // To find a data element at location (x2, y2) - * pixel = bandData[((y2-y)*w + (x2-x))]; - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param width Width of the pixel rectangle. - * @param height Height of the pixel rectangle. - * @param outData An object reference to an array of type defined by - * getTransferType() and length w*h*getNumDataElements(). - * If null an array of appropriate type and size will be - * allocated. - * @return An object reference to an array of type defined by - * getTransferType() with the request pixel data. - */ - public Object getPixelData(int x, int y, int w, int h, Object obj) { - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - byte outData[]; - if (obj == null) { - outData = new byte[numDataElements*w*h]; - } else { - outData = (byte[])obj; - } - int pixbits = pixelBitStride; - int scanbit = dataBitOffset + (x-minX) * pixbits; - int index = (y-minY) * scanlineStride; - int outindex = 0; - byte data[] = this.data; - - for (int j = 0; j < h; j++) { - int bitnum = scanbit; - for (int i = 0; i < w; i++) { - int shift = shiftOffset - (bitnum & 7); - outData[outindex++] = - (byte)(bitMask & (data[index + (bitnum >> 3)] >> shift)); - bitnum += pixbits; - } - index += scanlineStride; - } - return outData; - } - - /** - * Returns a byte array containing the specified data elements - * from the data array. The band index will be ignored. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * <pre> - * byte[] byteData = getByteData(x, y, band, w, h, null); - * // To find a data element at location (x2, y2) - * byte element = byteData[(y2-y)*w + (x2-x)]; - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param width Width of the pixel rectangle. - * @param height Height of the pixel rectangle. - * @param band The band to return, is ignored. - * @param outData If non-null, data elements - * at the specified locations are returned in this array. - * @return Byte array with data elements. - */ - public byte[] getByteData(int x, int y, int w, int h, - int band, byte[] outData) { - return getByteData(x, y, w, h, outData); - } - - /** - * Returns a byte array containing the specified data elements - * from the data array. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * <pre> - * byte[] byteData = raster.getByteData(x, y, w, h, null); - * byte pixel; - * // To find a data element at location (x2, y2) - * pixel = byteData[((y2-y)*w + (x2-x))]; - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param width Width of the pixel rectangle. - * @param height Height of the pixel rectangle. - * @param outData If non-null, data elements - * at the specified locations are returned in this array. - * @return Byte array with data elements. - */ - public byte[] getByteData(int x, int y, int w, int h, byte[] outData) { - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - if (outData == null) { - outData = new byte[w * h]; - } - int pixbits = pixelBitStride; - int scanbit = dataBitOffset + (x-minX) * pixbits; - int index = (y-minY) * scanlineStride; - int outindex = 0; - byte data[] = this.data; - - for (int j = 0; j < h; j++) { - int bitnum = scanbit; - int element; - - // Process initial portion of scanline - int i = 0; - while ((i < w) && ((bitnum & 7) != 0)) { - int shift = shiftOffset - (bitnum & 7); - outData[outindex++] = - (byte)(bitMask & (data[index + (bitnum >> 3)] >> shift)); - bitnum += pixbits; - i++; - } - - // Process central portion of scanline 8 pixels at a time - int inIndex = index + (bitnum >> 3); - switch (pixbits) { - case 1: - for (; i < w - 7; i += 8) { - element = data[inIndex++]; - outData[outindex++] = (byte)((element >> 7) & 1); - outData[outindex++] = (byte)((element >> 6) & 1); - outData[outindex++] = (byte)((element >> 5) & 1); - outData[outindex++] = (byte)((element >> 4) & 1); - outData[outindex++] = (byte)((element >> 3) & 1); - outData[outindex++] = (byte)((element >> 2) & 1); - outData[outindex++] = (byte)((element >> 1) & 1); - outData[outindex++] = (byte)(element & 1); - bitnum += 8; - } - break; - - case 2: - for (; i < w - 7; i += 8) { - element = data[inIndex++]; - outData[outindex++] = (byte)((element >> 6) & 3); - outData[outindex++] = (byte)((element >> 4) & 3); - outData[outindex++] = (byte)((element >> 2) & 3); - outData[outindex++] = (byte)(element & 3); - - element = data[inIndex++]; - outData[outindex++] = (byte)((element >> 6) & 3); - outData[outindex++] = (byte)((element >> 4) & 3); - outData[outindex++] = (byte)((element >> 2) & 3); - outData[outindex++] = (byte)(element & 3); - - bitnum += 16; - } - break; - - case 4: - for (; i < w - 7; i += 8) { - element = data[inIndex++]; - outData[outindex++] = (byte)((element >> 4) & 0xf); - outData[outindex++] = (byte)(element & 0xf); - - element = data[inIndex++]; - outData[outindex++] = (byte)((element >> 4) & 0xf); - outData[outindex++] = (byte)(element & 0xf); - - element = data[inIndex++]; - outData[outindex++] = (byte)((element >> 4) & 0xf); - outData[outindex++] = (byte)(element & 0xf); - - element = data[inIndex++]; - outData[outindex++] = (byte)((element >> 4) & 0xf); - outData[outindex++] = (byte)(element & 0xf); - - bitnum += 32; - } - break; - } - - // Process final portion of scanline - for (; i < w; i++) { - int shift = shiftOffset - (bitnum & 7); - outData[outindex++] = - (byte) (bitMask & (data[index + (bitnum >> 3)] >> shift)); - bitnum += pixbits; - } - - index += scanlineStride; - } - - return outData; - } - - /** - * Stores the data elements at the specified location. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinate is out of bounds. - * A ClassCastException will be thrown if the input object is non null - * and references anything other than an array of transferType. - * @param x The X coordinate of the pixel location. - * @param y The Y coordinate of the pixel location. - * @param inData An object reference to an array of type defined by - * getTransferType() and length getNumDataElements() - * containing the pixel data to place at x,y. - */ - public void setDataElements(int x, int y, Object obj) { - if ((x < this.minX) || (y < this.minY) || - (x >= this.maxX) || (y >= this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - byte inData[] = (byte[])obj; - int bitnum = dataBitOffset + (x-minX) * pixelBitStride; - int index = (y-minY) * scanlineStride + (bitnum >> 3); - int shift = shiftOffset - (bitnum & 7); - - byte element = data[index]; - element &= ~(bitMask << shift); - element |= (inData[0] & bitMask) << shift; - data[index] = element; - - markDirty(); - } - - /** - * Stores the Raster data at the specified location. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * @param x The X coordinate of the pixel location. - * @param y The Y coordinate of the pixel location. - * @param inRaster Raster of data to place at x,y location. - */ - public void setDataElements(int x, int y, Raster inRaster) { - // Check if we can use fast code - if (!(inRaster instanceof BytePackedRaster) || - ((BytePackedRaster)inRaster).pixelBitStride != pixelBitStride) { - super.setDataElements(x, y, inRaster); - return; - } - - int srcOffX = inRaster.getMinX(); - int srcOffY = inRaster.getMinY(); - int dstOffX = srcOffX + x; - int dstOffY = srcOffY + y; - int width = inRaster.getWidth(); - int height = inRaster.getHeight(); - if ((dstOffX < this.minX) || (dstOffY < this.minY) || - (dstOffX + width > this.maxX) || (dstOffY + height > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - setDataElements(dstOffX, dstOffY, - srcOffX, srcOffY, - width, height, - (BytePackedRaster)inRaster); - } - - /** - * Stores the Raster data at the specified location. - * @param dstX The absolute X coordinate of the destination pixel - * that will receive a copy of the upper-left pixel of the - * inRaster - * @param dstY The absolute Y coordinate of the destination pixel - * that will receive a copy of the upper-left pixel of the - * inRaster - * @param srcX The absolute X coordinate of the upper-left source - * pixel that will be copied into this Raster - * @param srcY The absolute Y coordinate of the upper-left source - * pixel that will be copied into this Raster - * @param width The number of pixels to store horizontally - * @param height The number of pixels to store vertically - * @param inRaster BytePackedRaster of data to place at x,y location. - */ - private void setDataElements(int dstX, int dstY, - int srcX, int srcY, - int width, int height, - BytePackedRaster inRaster) { - // Assume bounds checking has been performed previously - if (width <= 0 || height <= 0) { - return; - } - - byte[] inData = inRaster.data; - byte[] outData = this.data; - - int inscan = inRaster.scanlineStride; - int outscan = this.scanlineStride; - int inbit = inRaster.dataBitOffset + - 8 * (srcY - inRaster.minY) * inscan + - (srcX - inRaster.minX) * inRaster.pixelBitStride; - int outbit = (this.dataBitOffset + - 8 * (dstY - minY) * outscan + - (dstX - minX) * this.pixelBitStride); - int copybits = width * pixelBitStride; - - // Check whether the same bit alignment is present in both - // Rasters; if so, we can copy whole bytes using - // System.arraycopy. If not, we must do a "funnel shift" - // where adjacent bytes contribute to each destination byte. - if ((inbit & 7) == (outbit & 7)) { - // copy is bit aligned - int bitpos = outbit & 7; - if (bitpos != 0) { - int bits = 8 - bitpos; - // Copy partial bytes on left - int inbyte = inbit >> 3; - int outbyte = outbit >> 3; - int mask = 0xff >> bitpos; - if (copybits < bits) { - // Fix bug 4399076: previously had '8 - copybits' instead - // of 'bits - copybits'. - // - // Prior to the this expression, 'mask' has its rightmost - // 'bits' bits set to '1'. We want it to have a total - // of 'copybits' bits set, therefore we want to introduce - // 'bits - copybits' zeroes on the right. - mask &= 0xff << (bits - copybits); - bits = copybits; - } - for (int j = 0; j < height; j++) { - int element = outData[outbyte]; - element &= ~mask; - element |= (inData[inbyte] & mask); - outData[outbyte] = (byte) element; - inbyte += inscan; - outbyte += outscan; - } - inbit += bits; - outbit += bits; - copybits -= bits; - } - if (copybits >= 8) { - // Copy whole bytes - int inbyte = inbit >> 3; - int outbyte = outbit >> 3; - int copybytes = copybits >> 3; - if (copybytes == inscan && inscan == outscan) { - System.arraycopy(inData, inbyte, - outData, outbyte, - inscan * height); - } else { - for (int j = 0; j < height; j++) { - System.arraycopy(inData, inbyte, - outData, outbyte, - copybytes); - inbyte += inscan; - outbyte += outscan; - } - } - - int bits = copybytes*8; - inbit += bits; - outbit += bits; - copybits -= bits; - } - if (copybits > 0) { - // Copy partial bytes on right - int inbyte = inbit >> 3; - int outbyte = outbit >> 3; - int mask = (0xff00 >> copybits) & 0xff; - for (int j = 0; j < height; j++) { - int element = outData[outbyte]; - element &= ~mask; - element |= (inData[inbyte] & mask); - outData[outbyte] = (byte) element; - inbyte += inscan; - outbyte += outscan; - } - } - } else { - // Unaligned case, see RFE #4284166 - // Note that the code in that RFE is not correct - - // Insert bits into the first byte of the output - // if either the starting bit position is not zero or - // we are writing fewer than 8 bits in total - int bitpos = outbit & 7; - if (bitpos != 0 || copybits < 8) { - int bits = 8 - bitpos; - int inbyte = inbit >> 3; - int outbyte = outbit >> 3; - - int lshift = inbit & 7; - int rshift = 8 - lshift; - int mask = 0xff >> bitpos; - if (copybits < bits) { - // Fix mask if we're only writing a partial byte - mask &= 0xff << (bits - copybits); - bits = copybits; - } - int lastByte = inData.length - 1; - for (int j = 0; j < height; j++) { - // Read two bytes from the source if possible - // Don't worry about going over a scanline boundary - // since any extra bits won't get used anyway - byte inData0 = inData[inbyte]; - byte inData1 = (byte)0; - if (inbyte < lastByte) { - inData1 = inData[inbyte + 1]; - } - - // Insert the new bits into the output - int element = outData[outbyte]; - element &= ~mask; - element |= (((inData0 << lshift) | - ((inData1 & 0xff) >> rshift)) - >> bitpos) & mask; - outData[outbyte] = (byte)element; - inbyte += inscan; - outbyte += outscan; - } - - inbit += bits; - outbit += bits; - copybits -= bits; - } - - // Now we have outbit & 7 == 0 so we can write - // complete bytes for a while - - // Make sure we have work to do in the central loop - // to avoid reading past the end of the scanline - if (copybits >= 8) { - int inbyte = inbit >> 3; - int outbyte = outbit >> 3; - int copybytes = copybits >> 3; - int lshift = inbit & 7; - int rshift = 8 - lshift; - - for (int j = 0; j < height; j++) { - int ibyte = inbyte + j*inscan; - int obyte = outbyte + j*outscan; - - int inData0 = inData[ibyte]; - // Combine adjacent bytes while 8 or more bits left - for (int i = 0; i < copybytes; i++) { - int inData1 = inData[ibyte + 1]; - int val = (inData0 << lshift) | - ((inData1 & 0xff) >> rshift); - outData[obyte] = (byte)val; - inData0 = inData1; - - ++ibyte; - ++obyte; - } - } - - int bits = copybytes*8; - inbit += bits; - outbit += bits; - copybits -= bits; - } - - // Finish last byte - if (copybits > 0) { - int inbyte = inbit >> 3; - int outbyte = outbit >> 3; - int mask = (0xff00 >> copybits) & 0xff; - int lshift = inbit & 7; - int rshift = 8 - lshift; - - int lastByte = inData.length - 1; - for (int j = 0; j < height; j++) { - byte inData0 = inData[inbyte]; - byte inData1 = (byte)0; - if (inbyte < lastByte) { - inData1 = inData[inbyte + 1]; - } - - // Insert the new bits into the output - int element = outData[outbyte]; - element &= ~mask; - element |= ((inData0 << lshift) | - ((inData1 & 0xff) >> rshift)) & mask; - outData[outbyte] = (byte)element; - - inbyte += inscan; - outbyte += outscan; - } - } - } - - markDirty(); - } - - /** - * Copies pixels from Raster srcRaster to this WritableRaster. - * For each (x, y) address in srcRaster, the corresponding pixel - * is copied to address (x+dx, y+dy) in this WritableRaster, - * unless (x+dx, y+dy) falls outside the bounds of this raster. - * srcRaster must have the same number of bands as this WritableRaster. - * The copy is a simple copy of source samples to the corresponding - * destination samples. For details, see - * {@link WritableRaster#setRect(Raster)}. - * - * @param dx The X translation factor from src space to dst space - * of the copy. - * @param dy The Y translation factor from src space to dst space - * of the copy. - * @param srcRaster The Raster from which to copy pixels. - */ - public void setRect(int dx, int dy, Raster srcRaster) { - // Check if we can use fast code - if (!(srcRaster instanceof BytePackedRaster) || - ((BytePackedRaster)srcRaster).pixelBitStride != pixelBitStride) { - super.setRect(dx, dy, srcRaster); - return; - } - - int width = srcRaster.getWidth(); - int height = srcRaster.getHeight(); - int srcOffX = srcRaster.getMinX(); - int srcOffY = srcRaster.getMinY(); - int dstOffX = dx+srcOffX; - int dstOffY = dy+srcOffY; - - // Clip to this raster - if (dstOffX < this.minX) { - int skipX = this.minX - dstOffX; - width -= skipX; - srcOffX += skipX; - dstOffX = this.minX; - } - if (dstOffY < this.minY) { - int skipY = this.minY - dstOffY; - height -= skipY; - srcOffY += skipY; - dstOffY = this.minY; - } - if (dstOffX+width > this.maxX) { - width = this.maxX - dstOffX; - } - if (dstOffY+height > this.maxY) { - height = this.maxY - dstOffY; - } - - setDataElements(dstOffX, dstOffY, - srcOffX, srcOffY, - width, height, - (BytePackedRaster)srcRaster); - } - - /** - * Stores an array of data elements into the specified rectangular - * region. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * A ClassCastException will be thrown if the input object is non null - * and references anything other than an array of transferType. - * The data elements in the - * data array are assumed to be packed. That is, a data element - * at location (x2, y2) would be found at: - * <pre> - * inData[((y2-y)*w + (x2-x))] - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param w Width of the pixel rectangle. - * @param h Height of the pixel rectangle. - * @param inData An object reference to an array of type defined by - * getTransferType() and length w*h*getNumDataElements() - * containing the pixel data to place between x,y and - * x+h, y+h. - */ - public void setDataElements(int x, int y, int w, int h, Object obj) { - putByteData(x, y, w, h, (byte[])obj); - } - - /** - * Stores a byte array of data elements into the specified rectangular - * region. The band index will be ignored. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * The data elements in the - * data array are assumed to be packed. That is, a data element - * at location (x2, y2) would be found at: - * <pre> - * inData[((y2-y)*w + (x2-x))] - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param w Width of the pixel rectangle. - * @param h Height of the pixel rectangle. - * @param band The band to set, is ignored. - * @param inData The data elements to be stored. - */ - public void putByteData(int x, int y, int w, int h, - int band, byte[] inData) { - putByteData(x, y, w, h, inData); - } - - /** - * Stores a byte array of data elements into the specified rectangular - * region. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * The data elements in the - * data array are assumed to be packed. That is, a data element - * at location (x2, y2) would be found at: - * <pre> - * inData[((y2-y)*w + (x2-x))] - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param w Width of the pixel rectangle. - * @param h Height of the pixel rectangle. - * @param inData The data elements to be stored. - */ - public void putByteData(int x, int y, int w, int h, byte[] inData) { - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - if (w == 0 || h == 0) { - return; - } - - int pixbits = pixelBitStride; - int scanbit = dataBitOffset + (x - minX) * pixbits; - int index = (y - minY) * scanlineStride; - int outindex = 0; - byte data[] = this.data; - for (int j = 0; j < h; j++) { - int bitnum = scanbit; - int element; - - // Process initial portion of scanline - int i = 0; - while ((i < w) && ((bitnum & 7) != 0)) { - int shift = shiftOffset - (bitnum & 7); - element = data[index + (bitnum >> 3)]; - element &= ~(bitMask << shift); - element |= (inData[outindex++] & bitMask) << shift; - data[index + (bitnum >> 3)] = (byte)element; - - bitnum += pixbits; - i++; - } - - // Process central portion of scanline 8 pixels at a time - int inIndex = index + (bitnum >> 3); - switch (pixbits) { - case 1: - for (; i < w - 7; i += 8) { - element = (inData[outindex++] & 1) << 7; - element |= (inData[outindex++] & 1) << 6; - element |= (inData[outindex++] & 1) << 5; - element |= (inData[outindex++] & 1) << 4; - element |= (inData[outindex++] & 1) << 3; - element |= (inData[outindex++] & 1) << 2; - element |= (inData[outindex++] & 1) << 1; - element |= (inData[outindex++] & 1); - - data[inIndex++] = (byte)element; - - bitnum += 8; - } - break; - - case 2: - for (; i < w - 7; i += 8) { - element = (inData[outindex++] & 3) << 6; - element |= (inData[outindex++] & 3) << 4; - element |= (inData[outindex++] & 3) << 2; - element |= (inData[outindex++] & 3); - data[inIndex++] = (byte)element; - - element = (inData[outindex++] & 3) << 6; - element |= (inData[outindex++] & 3) << 4; - element |= (inData[outindex++] & 3) << 2; - element |= (inData[outindex++] & 3); - data[inIndex++] = (byte)element; - - bitnum += 16; - } - break; - - case 4: - for (; i < w - 7; i += 8) { - element = (inData[outindex++] & 0xf) << 4; - element |= (inData[outindex++] & 0xf); - data[inIndex++] = (byte)element; - - element = (inData[outindex++] & 0xf) << 4; - element |= (inData[outindex++] & 0xf); - data[inIndex++] = (byte)element; - - element = (inData[outindex++] & 0xf) << 4; - element |= (inData[outindex++] & 0xf); - data[inIndex++] = (byte)element; - - element = (inData[outindex++] & 0xf) << 4; - element |= (inData[outindex++] & 0xf); - data[inIndex++] = (byte)element; - - bitnum += 32; - } - break; - } - - // Process final portion of scanline - for (; i < w; i++) { - int shift = shiftOffset - (bitnum & 7); - - element = data[index + (bitnum >> 3)]; - element &= ~(bitMask << shift); - element |= (inData[outindex++] & bitMask) << shift; - data[index + (bitnum >> 3)] = (byte)element; - - bitnum += pixbits; - } - - index += scanlineStride; - } - - markDirty(); - } - - /** - * Returns an int array containing all samples for a rectangle of pixels, - * one sample per array element. - * An ArrayIndexOutOfBoundsException may be thrown - * if the coordinates are not in bounds. - * @param x, y the coordinates of the upper-left pixel location - * @param w Width of the pixel rectangle - * @param h Height of the pixel rectangle - * @param iArray An optionally pre-allocated int array - * @return the samples for the specified rectangle of pixels. - */ - public int[] getPixels(int x, int y, int w, int h, int iArray[]) { - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - if (iArray == null) { - iArray = new int[w * h]; - } - int pixbits = pixelBitStride; - int scanbit = dataBitOffset + (x-minX) * pixbits; - int index = (y-minY) * scanlineStride; - int outindex = 0; - byte data[] = this.data; - - for (int j = 0; j < h; j++) { - int bitnum = scanbit; - int element; - - // Process initial portion of scanline - int i = 0; - while ((i < w) && ((bitnum & 7) != 0)) { - int shift = shiftOffset - (bitnum & 7); - iArray[outindex++] = - bitMask & (data[index + (bitnum >> 3)] >> shift); - bitnum += pixbits; - i++; - } - - // Process central portion of scanline 8 pixels at a time - int inIndex = index + (bitnum >> 3); - switch (pixbits) { - case 1: - for (; i < w - 7; i += 8) { - element = data[inIndex++]; - iArray[outindex++] = (element >> 7) & 1; - iArray[outindex++] = (element >> 6) & 1; - iArray[outindex++] = (element >> 5) & 1; - iArray[outindex++] = (element >> 4) & 1; - iArray[outindex++] = (element >> 3) & 1; - iArray[outindex++] = (element >> 2) & 1; - iArray[outindex++] = (element >> 1) & 1; - iArray[outindex++] = element & 1; - bitnum += 8; - } - break; - - case 2: - for (; i < w - 7; i += 8) { - element = data[inIndex++]; - iArray[outindex++] = (element >> 6) & 3; - iArray[outindex++] = (element >> 4) & 3; - iArray[outindex++] = (element >> 2) & 3; - iArray[outindex++] = element & 3; - - element = data[inIndex++]; - iArray[outindex++] = (element >> 6) & 3; - iArray[outindex++] = (element >> 4) & 3; - iArray[outindex++] = (element >> 2) & 3; - iArray[outindex++] = element & 3; - - bitnum += 16; - } - break; - - case 4: - for (; i < w - 7; i += 8) { - element = data[inIndex++]; - iArray[outindex++] = (element >> 4) & 0xf; - iArray[outindex++] = element & 0xf; - - element = data[inIndex++]; - iArray[outindex++] = (element >> 4) & 0xf; - iArray[outindex++] = element & 0xf; - - element = data[inIndex++]; - iArray[outindex++] = (element >> 4) & 0xf; - iArray[outindex++] = element & 0xf; - - element = data[inIndex++]; - iArray[outindex++] = (element >> 4) & 0xf; - iArray[outindex++] = element & 0xf; - - bitnum += 32; - } - break; - } - - // Process final portion of scanline - for (; i < w; i++) { - int shift = shiftOffset - (bitnum & 7); - iArray[outindex++] = - bitMask & (data[index + (bitnum >> 3)] >> shift); - bitnum += pixbits; - } - - index += scanlineStride; - } - - return iArray; - } - - /** - * Sets all samples for a rectangle of pixels from an int array containing - * one sample per array element. - * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are - * not in bounds. - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param w Width of the pixel rectangle. - * @param h Height of the pixel rectangle. - * @param iArray The input int pixel array. - */ - public void setPixels(int x, int y, int w, int h, int iArray[]) { - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - int pixbits = pixelBitStride; - int scanbit = dataBitOffset + (x - minX) * pixbits; - int index = (y - minY) * scanlineStride; - int outindex = 0; - byte data[] = this.data; - for (int j = 0; j < h; j++) { - int bitnum = scanbit; - int element; - - // Process initial portion of scanline - int i = 0; - while ((i < w) && ((bitnum & 7) != 0)) { - int shift = shiftOffset - (bitnum & 7); - element = data[index + (bitnum >> 3)]; - element &= ~(bitMask << shift); - element |= (iArray[outindex++] & bitMask) << shift; - data[index + (bitnum >> 3)] = (byte)element; - - bitnum += pixbits; - i++; - } - - // Process central portion of scanline 8 pixels at a time - int inIndex = index + (bitnum >> 3); - switch (pixbits) { - case 1: - for (; i < w - 7; i += 8) { - element = (iArray[outindex++] & 1) << 7; - element |= (iArray[outindex++] & 1) << 6; - element |= (iArray[outindex++] & 1) << 5; - element |= (iArray[outindex++] & 1) << 4; - element |= (iArray[outindex++] & 1) << 3; - element |= (iArray[outindex++] & 1) << 2; - element |= (iArray[outindex++] & 1) << 1; - element |= (iArray[outindex++] & 1); - data[inIndex++] = (byte)element; - - bitnum += 8; - } - break; - - case 2: - for (; i < w - 7; i += 8) { - element = (iArray[outindex++] & 3) << 6; - element |= (iArray[outindex++] & 3) << 4; - element |= (iArray[outindex++] & 3) << 2; - element |= (iArray[outindex++] & 3); - data[inIndex++] = (byte)element; - - element = (iArray[outindex++] & 3) << 6; - element |= (iArray[outindex++] & 3) << 4; - element |= (iArray[outindex++] & 3) << 2; - element |= (iArray[outindex++] & 3); - data[inIndex++] = (byte)element; - - bitnum += 16; - } - break; - - case 4: - for (; i < w - 7; i += 8) { - element = (iArray[outindex++] & 0xf) << 4; - element |= (iArray[outindex++] & 0xf); - data[inIndex++] = (byte)element; - - element = (iArray[outindex++] & 0xf) << 4; - element |= (iArray[outindex++] & 0xf); - data[inIndex++] = (byte)element; - - element = (iArray[outindex++] & 0xf) << 4; - element |= (iArray[outindex++] & 0xf); - data[inIndex++] = (byte)element; - - element = (iArray[outindex++] & 0xf) << 4; - element |= (iArray[outindex++] & 0xf); - data[inIndex++] = (byte)element; - - bitnum += 32; - } - break; - } - - // Process final portion of scanline - for (; i < w; i++) { - int shift = shiftOffset - (bitnum & 7); - - element = data[index + (bitnum >> 3)]; - element &= ~(bitMask << shift); - element |= (iArray[outindex++] & bitMask) << shift; - data[index + (bitnum >> 3)] = (byte)element; - - bitnum += pixbits; - } - - index += scanlineStride; - } - - markDirty(); - } - - /** - * Creates a subraster given a region of the raster. The x and y - * coordinates specify the horizontal and vertical offsets - * from the upper-left corner of this raster to the upper-left corner - * of the subraster. Note that the subraster will reference the same - * DataBuffer as the parent raster, but using different offsets. The - * bandList is ignored. - * @param x X offset. - * @param y Y offset. - * @param width Width (in pixels) of the subraster. - * @param height Height (in pixels) of the subraster. - * @param x0 Translated X origin of the subraster. - * @param y0 Translated Y origin of the subraster. - * @param bandList Array of band indices. - * @exception RasterFormatException - * if the specified bounding box is outside of the parent raster. - */ - public Raster createChild(int x, int y, - int width, int height, - int x0, int y0, int[] bandList) { - WritableRaster newRaster = createWritableChild(x, y, - width, height, - x0, y0, - bandList); - return (Raster) newRaster; - } - - /** - * Creates a Writable subRaster given a region of the Raster. The x and y - * coordinates specify the horizontal and vertical offsets - * from the upper-left corner of this Raster to the upper-left corner - * of the subRaster. The bandList is ignored. - * A translation to the subRaster may also be specified. - * Note that the subRaster will reference the same - * DataBuffer as the parent Raster, but using different offsets. - * @param x X offset. - * @param y Y offset. - * @param width Width (in pixels) of the subraster. - * @param height Height (in pixels) of the subraster. - * @param x0 Translated X origin of the subraster. - * @param y0 Translated Y origin of the subraster. - * @param bandList Array of band indices. - * @exception RasterFormatException - * if the specified bounding box is outside of the parent Raster. - */ - public WritableRaster createWritableChild(int x, int y, - int width, int height, - int x0, int y0, - int[] bandList) { - if (x < this.minX) { - throw new RasterFormatException("x lies outside the raster"); - } - if (y < this.minY) { - throw new RasterFormatException("y lies outside the raster"); - } - if ((x+width < x) || (x+width > this.minX + this.width)) { - throw new RasterFormatException("(x + width) is outside of Raster"); - } - if ((y+height < y) || (y+height > this.minY + this.height)) { - throw new RasterFormatException("(y + height) is outside of Raster"); - } - - SampleModel sm; - - if (bandList != null) { - sm = sampleModel.createSubsetSampleModel(bandList); - } - else { - sm = sampleModel; - } - - int deltaX = x0 - x; - int deltaY = y0 - y; - - return new BytePackedRaster(sm, - dataBuffer, - new Rectangle(x0, y0, width, height), - new Point(sampleModelTranslateX+deltaX, - sampleModelTranslateY+deltaY), - this); - } - - /** - * Creates a raster with the same layout but using a different - * width and height, and with new zeroed data arrays. - */ - public WritableRaster createCompatibleWritableRaster(int w, int h) { - if (w <= 0 || h <=0) { - throw new RasterFormatException("negative "+ - ((w <= 0) ? "width" : "height")); - } - - SampleModel sm = sampleModel.createCompatibleSampleModel(w,h); - - return new BytePackedRaster(sm, new Point(0,0)); - } - - /** - * Creates a raster with the same layout and the same - * width and height, and with new zeroed data arrays. - */ - public WritableRaster createCompatibleWritableRaster () { - return createCompatibleWritableRaster(width,height); - } - - /** - * Verify that the layout parameters are consistent with - * the data. If strictCheck - * is false, this method will check for ArrayIndexOutOfBounds conditions. - * If strictCheck is true, this method will check for additional error - * conditions such as line wraparound (width of a line greater than - * the scanline stride). - * @return String Error string, if the layout is incompatible with - * the data. Otherwise returns null. - */ - private void verify (boolean strictCheck) { - // Make sure data for Raster is in a legal range - if (dataBitOffset < 0) { - throw new RasterFormatException("Data offsets must be >= 0"); - } - - int lastbit = (dataBitOffset - + (height-1) * scanlineStride * 8 - + (width-1) * pixelBitStride - + pixelBitStride - 1); - if (lastbit / 8 >= data.length) { - throw new RasterFormatException("raster dimensions overflow " + - "array bounds"); - } - if (strictCheck) { - if (height > 1) { - lastbit = width * pixelBitStride - 1; - if (lastbit / 8 >= scanlineStride) { - throw new RasterFormatException("data for adjacent" + - " scanlines overlaps"); - } - } - } - } - - public String toString() { - return new String ("BytePackedRaster: width = "+width+" height = "+height - +" #channels "+numBands - +" xOff = "+sampleModelTranslateX - +" yOff = "+sampleModelTranslateY); - } -} diff --git a/external/ikvm/openjdk/sun/awt/image/IntegerComponentRaster.java b/external/ikvm/openjdk/sun/awt/image/IntegerComponentRaster.java deleted file mode 100644 index 7c44c6f993..0000000000 --- a/external/ikvm/openjdk/sun/awt/image/IntegerComponentRaster.java +++ /dev/null @@ -1,685 +0,0 @@ -/* - * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code 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 - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package sun.awt.image; -import java.awt.image.Raster; -import java.awt.image.WritableRaster; -import java.awt.image.RasterFormatException; -import java.awt.image.SampleModel; -import java.awt.image.SinglePixelPackedSampleModel; -import java.awt.image.DataBuffer; -import java.awt.image.DataBufferInt; -import java.awt.Rectangle; -import java.awt.Point; - -/** - * This class defines a Raster with pixels consisting of one or more 32-bit - * data elements stored in close proximity to each other in a integer array. - * The bit precision per data element is that - * of the data type (that is, the bit precision for this raster is 32). - * There is only one pixel stride and one scanline stride for all - * bands. For a given pixel, all samples fit in N data elements and these - * N data elements hold samples for only one pixel. This type of Raster - * can be used with a PackedColorModel. - * <p> - * For example, if there is only one data element per pixel, a - * SinglePixelPackedSampleModel can be used to represent multiple - * bands with a PackedColorModel (including a DirectColorModel) for - * color interpretation. - * - */ -public class IntegerComponentRaster extends SunWritableRaster { - - static final int TYPE_CUSTOM = 0; - static final int TYPE_BYTE_SAMPLES = 1; - static final int TYPE_USHORT_SAMPLES = 2; - static final int TYPE_INT_SAMPLES = 3; - static final int TYPE_BYTE_BANDED_SAMPLES = 4; - static final int TYPE_USHORT_BANDED_SAMPLES = 5; - static final int TYPE_INT_BANDED_SAMPLES = 6; - static final int TYPE_BYTE_PACKED_SAMPLES = 7; - static final int TYPE_USHORT_PACKED_SAMPLES = 8; - static final int TYPE_INT_PACKED_SAMPLES = 9; - static final int TYPE_INT_8BIT_SAMPLES = 10; - static final int TYPE_BYTE_BINARY_SAMPLES = 11; - - /** private band offset for use by native code */ - protected int bandOffset; - - /** Data offsets for each band of image data. */ - protected int[] dataOffsets; - - /** Scanline stride of the image data contained in this Raster. */ - protected int scanlineStride; - - /** Pixel stride of the image data contained in this Raster. */ - protected int pixelStride; - - /** The image data array. */ - protected int[] data; - - /** The number of data elements required to store a pixel. */ - protected int numDataElems; - - int type; - - /** A cached copy of minX + width for use in bounds checks. */ - private int maxX; - - /** A cached copy of minY + height for use in bounds checks. */ - private int maxY; - - /** - * Constructs a IntegerComponentRaster with the given SampleModel. - * The Raster's upper left corner is origin and it is the same - * size as the SampleModel. A DataBuffer large enough to describe the - * Raster is automatically created. SampleModel must be of type - * SinglePixelPackedSampleModel. - * @param sampleModel The SampleModel that specifies the layout. - * @param origin The Point that specified the origin. - */ - public IntegerComponentRaster(SampleModel sampleModel, - Point origin) { - this(sampleModel, - sampleModel.createDataBuffer(), - new Rectangle(origin.x, - origin.y, - sampleModel.getWidth(), - sampleModel.getHeight()), - origin, - null); - } - - /** - * Constructs a IntegerComponentRaster with the given SampleModel - * and DataBuffer. The Raster's upper left corner is origin and - * it is the same sizes the SampleModel. The DataBuffer is not - * initialized and must be a DataBufferInt compatible with SampleModel. - * SampleModel must be of type SinglePixelPackedSampleModel. - * @param sampleModel The SampleModel that specifies the layout. - * @param dataBuffer The DataBufferInt that contains the image data. - * @param origin The Point that specifies the origin. - */ - public IntegerComponentRaster(SampleModel sampleModel, - DataBuffer dataBuffer, - Point origin) { - this(sampleModel, - dataBuffer, - new Rectangle(origin.x, - origin.y, - sampleModel.getWidth(), - sampleModel.getHeight()), - origin, - null); - } - - /** - * Constructs a IntegerComponentRaster with the given SampleModel, - * DataBuffer, and parent. DataBuffer must be a DataBufferInt and - * SampleModel must be of type SinglePixelPackedSampleModel. - * When translated into the base Raster's - * coordinate system, aRegion must be contained by the base Raster. - * Origin is the coodinate in the new Raster's coordinate system of - * the origin of the base Raster. (The base Raster is the Raster's - * ancestor which has no parent.) - * - * Note that this constructor should generally be called by other - * constructors or create methods, it should not be used directly. - * @param sampleModel The SampleModel that specifies the layout. - * @param dataBuffer The DataBufferInt that contains the image data. - * @param aRegion The Rectangle that specifies the image area. - * @param origin The Point that specifies the origin. - * @param parent The parent (if any) of this raster. - */ - public IntegerComponentRaster(SampleModel sampleModel, - DataBuffer dataBuffer, - Rectangle aRegion, - Point origin, - IntegerComponentRaster parent){ - super(sampleModel,dataBuffer,aRegion,origin,parent); - this.maxX = minX + width; - this.maxY = minY + height; - if (!(dataBuffer instanceof DataBufferInt)) { - throw new RasterFormatException("IntegerComponentRasters must have" + - "integer DataBuffers"); - } - DataBufferInt dbi = (DataBufferInt)dataBuffer; - if (dbi.getNumBanks() != 1) { - throw new - RasterFormatException("DataBuffer for IntegerComponentRasters"+ - " must only have 1 bank."); - } - this.data = stealData(dbi, 0); - - if (sampleModel instanceof SinglePixelPackedSampleModel) { - SinglePixelPackedSampleModel sppsm = - (SinglePixelPackedSampleModel)sampleModel; - int[] boffsets = sppsm.getBitOffsets(); - boolean notByteBoundary = false; - for (int i=1; i < boffsets.length; i++) { - if ((boffsets[i]%8) != 0) { - notByteBoundary = true; - } - } - this.type = (notByteBoundary - ? IntegerComponentRaster.TYPE_INT_PACKED_SAMPLES - : IntegerComponentRaster.TYPE_INT_8BIT_SAMPLES); - - this.scanlineStride = sppsm.getScanlineStride(); - this.pixelStride = 1; - this.dataOffsets = new int[1]; - this.dataOffsets[0] = dbi.getOffset(); - this.bandOffset = this.dataOffsets[0]; - int xOffset = aRegion.x - origin.x; - int yOffset = aRegion.y - origin.y; - dataOffsets[0] += xOffset+yOffset*scanlineStride; - this.numDataElems = sppsm.getNumDataElements(); - } else { - throw new RasterFormatException("IntegerComponentRasters must have"+ - " SinglePixelPackedSampleModel"); - } - - verify(false); - } - - - /** - * Returns a copy of the data offsets array. For each band the data offset - * is the index into the band's data array, of the first sample of the - * band. - */ - public int[] getDataOffsets() { - return (int[]) dataOffsets.clone(); - } - - /** - * Returns data offset for the specified band. The data offset - * is the index into the data array in which the first sample - * of the first scanline is stored. - */ - public int getDataOffset(int band) { - return dataOffsets[band]; - } - - - /** - * Returns the scanline stride -- the number of data array elements between - * a given sample and the sample in the same column of the next row. - */ - public int getScanlineStride() { - return scanlineStride; - } - - /** - * Returns pixel stride -- the number of data array elements between two - * samples for the same band on the same scanline. - */ - public int getPixelStride() { - return pixelStride; - } - - /** - * Returns a reference to the data array. - */ - public int[] getDataStorage() { - return data; - } - - /** - * Returns the data elements for all bands at the specified - * location. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinate is out of bounds. - * A ClassCastException will be thrown if the input object is non null - * and references anything other than an array of transferType. - * @param x The X coordinate of the pixel location. - * @param y The Y coordinate of the pixel location. - * @param outData An object reference to an array of type defined by - * getTransferType() and length getNumDataElements(). - * If null an array of appropriate type and size will be - * allocated. - * @return An object reference to an array of type defined by - * getTransferType() with the request pixel data. - */ - public Object getDataElements(int x, int y, Object obj) { - if ((x < this.minX) || (y < this.minY) || - (x >= this.maxX) || (y >= this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - int outData[]; - if (obj == null) { - outData = new int[numDataElements]; - } else { - outData = (int[])obj; - } - int off = (y-minY)*scanlineStride + - (x-minX)*pixelStride; - for (int band = 0; band < numDataElements; band++) { - outData[band] = data[dataOffsets[band] + off]; - } - - return outData; - } - - - /** - * Returns an array of data elements from the specified rectangular - * region. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * A ClassCastException will be thrown if the input object is non null - * and references anything other than an array of transferType. - <pre> - * int[] bandData = (int[])raster.getDataElements(x, y, w, h, null); - * int numDataElements = raster.getNumDataElements(); - * int[] pixel = new int[numDataElements]; - * // To find a data element at location (x2, y2) - * System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements, - * pixel, 0, numDataElements); - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param width Width of the pixel rectangle. - * @param height Height of the pixel rectangle. - * @param outData An object reference to an array of type defined by - * getTransferType() and length w*h*getNumDataElements(). - * If null an array of appropriate type and size will be - * allocated. - * @return An object reference to an array of type defined by - * getTransferType() with the request pixel data. - */ - public Object getDataElements(int x, int y, int w, int h, Object obj) { - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - int outData[]; - if (obj instanceof int[]) { - outData = (int[])obj; - } else { - outData = new int[numDataElements*w*h]; - } - int yoff = (y-minY)*scanlineStride + - (x-minX)*pixelStride; - int xoff; - int off = 0; - int xstart; - int ystart; - - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - xoff = yoff; - for (xstart=0; xstart < w; xstart++, xoff += pixelStride) { - for (int c = 0; c < numDataElements; c++) { - outData[off++] = data[dataOffsets[c] + xoff]; - } - } - } - - return outData; - } - - - /** - * Stores the data elements for all bands at the specified location. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinate is out of bounds. - * A ClassCastException will be thrown if the input object is non null - * and references anything other than an array of transferType. - * @param x The X coordinate of the pixel location. - * @param y The Y coordinate of the pixel location. - * @param inData An object reference to an array of type defined by - * getTransferType() and length getNumDataElements() - * containing the pixel data to place at x,y. - */ - public void setDataElements(int x, int y, Object obj) { - if ((x < this.minX) || (y < this.minY) || - (x >= this.maxX) || (y >= this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - int inData[] = (int[])obj; - - int off = (y-minY)*scanlineStride + - (x-minX)*pixelStride; - - for (int i = 0; i < numDataElements; i++) { - data[dataOffsets[i] + off] = inData[i]; - } - - markDirty(); - } - - - /** - * Stores the Raster data at the specified location. - * The transferType of the inputRaster must match this raster. - * An ArrayIndexOutOfBoundsException will be thrown at runtime - * if the pixel coordinates are out of bounds. - * @param x The X coordinate of the pixel location. - * @param y The Y coordinate of the pixel location. - * @param inRaster Raster of data to place at x,y location. - */ - public void setDataElements(int x, int y, Raster inRaster) { - int dstOffX = x + inRaster.getMinX(); - int dstOffY = y + inRaster.getMinY(); - int width = inRaster.getWidth(); - int height = inRaster.getHeight(); - if ((dstOffX < this.minX) || (dstOffY < this.minY) || - (dstOffX + width > this.maxX) || (dstOffY + height > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - setDataElements(dstOffX, dstOffY, width, height, inRaster); - } - - /** - * Stores the Raster data at the specified location. - * @param dstX The absolute X coordinate of the destination pixel - * that will receive a copy of the upper-left pixel of the - * inRaster - * @param dstY The absolute Y coordinate of the destination pixel - * that will receive a copy of the upper-left pixel of the - * inRaster - * @param width The number of pixels to store horizontally - * @param height The number of pixels to store vertically - * @param inRaster Raster of data to place at x,y location. - */ - private void setDataElements(int dstX, int dstY, - int width, int height, - Raster inRaster) { - // Assume bounds checking has been performed previously - if (width <= 0 || height <= 0) { - return; - } - - // Write inRaster (minX, minY) to (dstX, dstY) - - int srcOffX = inRaster.getMinX(); - int srcOffY = inRaster.getMinY(); - int tdata[] = null; - - if (inRaster instanceof IntegerComponentRaster && - (pixelStride == 1) && (numDataElements == 1)) { - IntegerComponentRaster ict = (IntegerComponentRaster) inRaster; - if (ict.getNumDataElements() != 1) { - throw new ArrayIndexOutOfBoundsException("Number of bands"+ - " does not match"); - } - - // Extract the raster parameters - tdata = ict.getDataStorage(); - int tss = ict.getScanlineStride(); - int toff = ict.getDataOffset(0); - - int srcOffset = toff; - - int dstOffset = dataOffsets[0]+(dstY-minY)*scanlineStride+ - (dstX-minX); - - - // Fastest case. We can copy scanlines - if (ict.getPixelStride() == pixelStride) { - width *= pixelStride; - - // Loop through all of the scanlines and copy the data - for (int startY=0; startY < height; startY++) { - System.arraycopy(tdata, srcOffset, data, dstOffset, width); - srcOffset += tss; - dstOffset += scanlineStride; - } - markDirty(); - return; - } - } - - Object odata = null; - for (int startY=0; startY < height; startY++) { - odata = inRaster.getDataElements(srcOffX, srcOffY+startY, - width, 1, odata); - setDataElements(dstX, dstY+startY, - width, 1, odata); - } - } - - /** - * Stores an array of data elements into the specified rectangular - * region. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * A ClassCastException will be thrown if the input object is non null - * and references anything other than an array of transferType. - * The data elements in the - * data array are assumed to be packed. That is, a data element - * for the nth band at location (x2, y2) would be found at: - * <pre> - * inData[((y2-y)*w + (x2-x))*numDataElements + n] - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param w Width of the pixel rectangle. - * @param h Height of the pixel rectangle. - * @param inData An object reference to an array of type defined by - * getTransferType() and length w*h*getNumDataElements() - * containing the pixel data to place between x,y and - * x+h, y+h. - */ - public void setDataElements(int x, int y, int w, int h, Object obj) { - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - int inData[] = (int[])obj; - - int yoff = (y-minY)*scanlineStride + - (x-minX)*pixelStride; - int xoff; - int off = 0; - int xstart; - int ystart; - - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - xoff = yoff; - for (xstart=0; xstart < w; xstart++, xoff += pixelStride) { - for (int c = 0; c < numDataElements; c++) { - data[dataOffsets[c] + xoff] = inData[off++]; - } - } - } - - markDirty(); - } - - - /** - * Creates a subraster given a region of the raster. The x and y - * coordinates specify the horizontal and vertical offsets - * from the upper-left corner of this raster to the upper-left corner - * of the subraster. A subset of the bands of the parent Raster may - * be specified. If this is null, then all the bands are present in the - * subRaster. A translation to the subRaster may also be specified. - * Note that the subraster will reference the same - * DataBuffer as the parent raster, but using different offsets. - * @param x X offset. - * @param y Y offset. - * @param width Width (in pixels) of the subraster. - * @param height Height (in pixels) of the subraster. - * @param x0 Translated X origin of the subraster. - * @param y0 Translated Y origin of the subraster. - * @param bandList Array of band indices. - * @exception RasterFormatException - * if the specified bounding box is outside of the parent raster. - */ - public WritableRaster createWritableChild (int x, int y, - int width, int height, - int x0, int y0, - int bandList[]) { - if (x < this.minX) { - throw new RasterFormatException("x lies outside raster"); - } - if (y < this.minY) { - throw new RasterFormatException("y lies outside raster"); - } - if ((x+width < x) || (x+width > this.minX + this.width)) { - throw new RasterFormatException("(x + width) is outside raster"); - } - if ((y+height < y) || (y+height > this.minY + this.height)) { - throw new RasterFormatException("(y + height) is outside raster"); - } - - SampleModel sm; - - if (bandList != null) - sm = sampleModel.createSubsetSampleModel(bandList); - else - sm = sampleModel; - - int deltaX = x0 - x; - int deltaY = y0 - y; - - return new IntegerComponentRaster(sm, - dataBuffer, - new Rectangle(x0,y0,width,height), - new Point(sampleModelTranslateX+deltaX, - sampleModelTranslateY+deltaY), - this); - } - - - /** - * Creates a subraster given a region of the raster. The x and y - * coordinates specify the horizontal and vertical offsets - * from the upper-left corner of this raster to the upper-left corner - * of the subraster. A subset of the bands of the parent raster may - * be specified. If this is null, then all the bands are present in the - * subRaster. Note that the subraster will reference the same - * DataBuffer as the parent raster, but using different offsets. - * @param x X offset. - * @param y Y offset. - * @param width Width (in pixels) of the subraster. - * @param height Height (in pixels) of the subraster. - * @param x0 Translated X origin of the subRaster. - * @param y0 Translated Y origin of the subRaster. - * @param bandList Array of band indices. - * @exception RasterFormatException - * if the specified bounding box is outside of the parent raster. - */ - public Raster createChild (int x, int y, - int width, int height, - int x0, int y0, - int bandList[]) { - return createWritableChild(x, y, width, height, x0, y0, bandList); - } - - - /** - * Creates a raster with the same band layout but using a different - * width and height, and with new zeroed data arrays. - */ - public WritableRaster createCompatibleWritableRaster(int w, int h) { - if (w <= 0 || h <=0) { - throw new RasterFormatException("negative "+ - ((w <= 0) ? "width" : "height")); - } - - SampleModel sm = sampleModel.createCompatibleSampleModel(w,h); - - return new IntegerComponentRaster(sm, new Point(0,0)); - } - - /** - * Creates a raster with the same data layout and the same - * width and height, and with new zeroed data arrays. If - * the raster is a subraster, this will call - * createCompatibleRaster(width, height). - */ - public WritableRaster createCompatibleWritableRaster() { - return createCompatibleWritableRaster(width,height); - } - - /** - * Verify that the layout parameters are consistent with - * the data. If strictCheck - * is false, this method will check for ArrayIndexOutOfBounds conditions. If - * strictCheck is true, this method will check for additional error - * conditions such as line wraparound (width of a line greater than - * the scanline stride). - * @return String Error string, if the layout is incompatible with - * the data. Otherwise returns null. - */ - private void verify (boolean strictCheck) { - if (dataOffsets[0] < 0) { - throw new RasterFormatException("Data offset ("+dataOffsets[0]+ - ") must be >= 0"); - } - - int maxSize = 0; - int size; - - for (int i=0; i < numDataElements; i++) { - size = (height-1)*scanlineStride + (width-1)*pixelStride + - dataOffsets[i]; - if (size > maxSize) { - maxSize = size; - } - } - if (data.length < maxSize) { - throw new RasterFormatException("Data array too small (should be "+ - maxSize - +" but is "+data.length+" )"); - } - } - - public String toString() { - return new String ("IntegerComponentRaster: width = "+width - +" height = " + height - +" #Bands = " + numBands - +" #DataElements "+numDataElements - +" xOff = "+sampleModelTranslateX - +" yOff = "+sampleModelTranslateY - +" dataOffset[0] "+dataOffsets[0]); - } - -// /** -// * For debugging... prints a region of a one-band IntegerComponentRaster -// */ -// public void print(int x, int y, int w, int h) { -// // REMIND: Only works for 1 band! -// System.out.println(this); -// int offset = dataOffsets[0] + y*scanlineStride + x*pixelStride; -// int off; -// for (int yoff=0; yoff < h; yoff++, offset += scanlineStride) { -// off = offset; -// System.out.print("Line "+(sampleModelTranslateY+y+yoff)+": "); -// for (int xoff = 0; xoff < w; xoff++, off+= pixelStride) { -// System.out.print(Integer.toHexString(data[off])+" "); -// } -// System.out.println(""); -// } -// } - -} diff --git a/external/ikvm/openjdk/sun/awt/image/OffScreenImageSource.java b/external/ikvm/openjdk/sun/awt/image/OffScreenImageSource.java deleted file mode 100644 index 7e8e2dbc79..0000000000 --- a/external/ikvm/openjdk/sun/awt/image/OffScreenImageSource.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code 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 - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package sun.awt.image; - -import java.util.Hashtable; -import java.awt.image.ImageConsumer; -import java.awt.image.ImageProducer; -import java.awt.image.Raster; -import java.awt.image.WritableRaster; -import java.awt.image.ColorModel; -import java.awt.image.IndexColorModel; -import java.awt.image.DirectColorModel; -import java.awt.image.BufferedImage; -import java.awt.image.DataBuffer; - -public class OffScreenImageSource implements ImageProducer { - BufferedImage image; - int width; - int height; - Hashtable properties; - - public OffScreenImageSource(BufferedImage image, - Hashtable properties) { - this.image = image; - if (properties != null) { - this.properties = properties; - } else { - this.properties = new Hashtable(); - } - width = image.getWidth(); - height = image.getHeight(); - } - - public OffScreenImageSource(BufferedImage image) { - this(image, null); - } - - // We can only have one consumer since we immediately return the data... - private ImageConsumer theConsumer; - - public synchronized void addConsumer(ImageConsumer ic) { - theConsumer = ic; - produce(); - } - - public synchronized boolean isConsumer(ImageConsumer ic) { - return (ic == theConsumer); - } - - public synchronized void removeConsumer(ImageConsumer ic) { - if (theConsumer == ic) { - theConsumer = null; - } - } - - public void startProduction(ImageConsumer ic) { - addConsumer(ic); - } - - public void requestTopDownLeftRightResend(ImageConsumer ic) { - } - - private void sendPixels() { - ColorModel cm = image.getColorModel(); - WritableRaster raster = image.getRaster(); - int numDataElements = raster.getNumDataElements(); - int dataType = raster.getDataBuffer().getDataType(); - int[] scanline = new int[width*numDataElements]; - boolean needToCvt = true; - - if (cm instanceof IndexColorModel) { - byte[] pixels = new byte[width]; - theConsumer.setColorModel(cm); - - if (raster instanceof ByteComponentRaster) { - needToCvt = false; - for (int y=0; y < height; y++) { - raster.getDataElements(0, y, width, 1, pixels); - theConsumer.setPixels(0, y, width, 1, cm, pixels, 0, - width); - } - } - else if (raster instanceof BytePackedRaster) { - needToCvt = false; - // Binary image. Need to unpack it - for (int y=0; y < height; y++) { - raster.getPixels(0, y, width, 1, scanline); - for (int x=0; x < width; x++) { - pixels[x] = (byte) scanline[x]; - } - theConsumer.setPixels(0, y, width, 1, cm, pixels, 0, - width); - } - } - else if (dataType == DataBuffer.TYPE_SHORT || - dataType == DataBuffer.TYPE_INT) - { - // Probably a short or int "GRAY" image - needToCvt = false; - for (int y=0; y < height; y++) { - raster.getPixels(0, y, width, 1, scanline); - theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, - width); - } - } - } - else if (cm instanceof DirectColorModel) { - theConsumer.setColorModel(cm); - needToCvt = false; - switch (dataType) { - case DataBuffer.TYPE_INT: - for (int y=0; y < height; y++) { - raster.getDataElements(0, y, width, 1, scanline); - theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, - width); - } - break; - case DataBuffer.TYPE_BYTE: - byte[] bscanline = new byte[width]; - for (int y=0; y < height; y++) { - raster.getDataElements(0, y, width, 1, bscanline); - for (int x=0; x < width; x++) { - scanline[x] = bscanline[x]&0xff; - } - theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, - width); - } - break; - case DataBuffer.TYPE_USHORT: - short[] sscanline = new short[width]; - for (int y=0; y < height; y++) { - raster.getDataElements(0, y, width, 1, sscanline); - for (int x=0; x < width; x++) { - scanline[x] = sscanline[x]&0xffff; - } - theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, - width); - } - break; - default: - needToCvt = true; - } - } - - if (needToCvt) { - // REMIND: Need to add other types of CMs here - ColorModel newcm = ColorModel.getRGBdefault(); - theConsumer.setColorModel(newcm); - - for (int y=0; y < height; y++) { - for (int x=0; x < width; x++) { - scanline[x] = image.getRGB(x, y); - } - theConsumer.setPixels(0, y, width, 1, newcm, scanline, 0, - width); - } - } - } - - private void produce() { - try { - theConsumer.setDimensions(image.getWidth(), image.getHeight()); - theConsumer.setProperties(properties); - sendPixels(); - theConsumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE); - } catch (NullPointerException e) { - if (theConsumer != null) { - theConsumer.imageComplete(ImageConsumer.IMAGEERROR); - } - } - } -} diff --git a/external/ikvm/openjdk/sun/awt/image/ShortComponentRaster.java b/external/ikvm/openjdk/sun/awt/image/ShortComponentRaster.java deleted file mode 100644 index f353fa8c8a..0000000000 --- a/external/ikvm/openjdk/sun/awt/image/ShortComponentRaster.java +++ /dev/null @@ -1,829 +0,0 @@ -/* - * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code 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 - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package sun.awt.image; -import java.awt.image.Raster; -import java.awt.image.WritableRaster; -import java.awt.image.RasterFormatException; -import java.awt.image.SampleModel; -import java.awt.image.ComponentSampleModel; -import java.awt.image.SinglePixelPackedSampleModel; -import java.awt.image.DataBuffer; -import java.awt.image.DataBufferUShort; -import java.awt.Rectangle; -import java.awt.Point; - -/** - * This class defines a Raster with pixels consisting of one or more 16-bit - * data elements stored in close proximity to each other in a short integer - * array. The bit precision per data element is that - * of the data type (that is, the bit precision for this Raster is 16). - * There is only one pixel stride and one scanline stride for all - * bands. This type of Raster can be used with a - * ComponentColorModel if there are multiple bands, or a - * IndexColorModel if there is only one band. - * <p> - * For example, 5-6-5 RGB image data can be represented by a - * ShortComponentRaster using a SinglePixelPackedSampleModel and - * a ComponentColorModel. - * - * - */ -public class ShortComponentRaster extends SunWritableRaster { - - /** private band offset for use by native code */ - protected int bandOffset; - - /** Data offsets for each band of image data. */ - protected int[] dataOffsets; - - /** Scanline stride of the image data contained in this Raster. */ - protected int scanlineStride; - - /** Pixel stride of the image data contained in this Raster. */ - protected int pixelStride; - - /** The image data array. */ - protected short[] data; - - int type; - - /** A cached copy of minX + width for use in bounds checks. */ - private int maxX; - - /** A cached copy of minY + height for use in bounds checks. */ - private int maxY; - - /** - * Constructs a ShortComponentRaster with the given SampleModel. - * The Raster's upper left corner is origin and it is the same - * size as the SampleModel. A DataBuffer large enough to describe the - * Raster is automatically created. SampleModel must be of type - * ComponentSampleModel or SinglePixelPackedSampleModel. - * @param sampleModel The SampleModel that specifies the layout. - * @param origin The Point that specified the origin. - */ - public ShortComponentRaster(SampleModel sampleModel, Point origin) { - this(sampleModel, - sampleModel.createDataBuffer(), - new Rectangle(origin.x, - origin.y, - sampleModel.getWidth(), - sampleModel.getHeight()), - origin, - null); - } - - /** - * Constructs a ShortComponentRaster with the given SampleModel - * and DataBuffer. The Raster's upper left corner is origin and - * it is the same sizes the SampleModel. The DataBuffer is not - * initialized and must be a DataBufferUShort compatible with SampleModel. - * SampleModel must be of type ComponentSampleModel or - * SinglePixelPackedSampleModel. - * @param sampleModel The SampleModel that specifies the layout. - * @param dataBuffer The DataBufferUShort that contains the image data. - * @param origin The Point that specifies the origin. - */ - public ShortComponentRaster(SampleModel sampleModel, - DataBuffer dataBuffer, - Point origin) { - this(sampleModel, - dataBuffer, - new Rectangle(origin.x, - origin.y, - sampleModel.getWidth(), - sampleModel.getHeight()), - origin, - null); - } - - /** - * Constructs a ShortComponentRaster with the given SampleModel, - * DataBuffer, and parent. DataBuffer must be a DataBufferUShort and - * SampleModel must be of type ComponentSampleModel or - * SinglePixelPackedSampleModel. When translated into the base Raster's - * coordinate system, aRegion must be contained by the base Raster. - * Origin is the coodinate in the new Raster's coordinate system of - * the origin of the base Raster. (The base Raster is the Raster's - * ancestor which has no parent.) - * - * Note that this constructor should generally be called by other - * constructors or create methods, it should not be used directly. - * @param sampleModel The SampleModel that specifies the layout. - * @param dataBuffer The DataBufferUShort that contains the image data. - * @param aRegion The Rectangle that specifies the image area. - * @param origin The Point that specifies the origin. - * @param parent The parent (if any) of this raster. - */ - public ShortComponentRaster(SampleModel sampleModel, - DataBuffer dataBuffer, - Rectangle aRegion, - Point origin, - ShortComponentRaster parent) { - - super(sampleModel, dataBuffer, aRegion, origin, parent); - this.maxX = minX + width; - this.maxY = minY + height; - - if(!(dataBuffer instanceof DataBufferUShort)) { - throw new RasterFormatException("ShortComponentRasters must have "+ - "short DataBuffers"); - } - - DataBufferUShort dbus = (DataBufferUShort)dataBuffer; - this.data = stealData(dbus, 0); - if (dbus.getNumBanks() != 1) { - throw new - RasterFormatException("DataBuffer for ShortComponentRasters"+ - " must only have 1 bank."); - } - int dbOffset = dbus.getOffset(); - - if (sampleModel instanceof ComponentSampleModel) { - ComponentSampleModel csm = (ComponentSampleModel)sampleModel; - this.type = IntegerComponentRaster.TYPE_USHORT_SAMPLES; - this.scanlineStride = csm.getScanlineStride(); - this.pixelStride = csm.getPixelStride(); - this.dataOffsets = csm.getBandOffsets(); - int xOffset = aRegion.x - origin.x; - int yOffset = aRegion.y - origin.y; - for (int i = 0; i < getNumDataElements(); i++) { - dataOffsets[i] += dbOffset + - xOffset*pixelStride+yOffset*scanlineStride; - } - } else if (sampleModel instanceof SinglePixelPackedSampleModel) { - SinglePixelPackedSampleModel sppsm = - (SinglePixelPackedSampleModel)sampleModel; - this.type = IntegerComponentRaster.TYPE_USHORT_PACKED_SAMPLES; - this.scanlineStride = sppsm.getScanlineStride(); - this.pixelStride = 1; - this.dataOffsets = new int[1]; - this.dataOffsets[0] = dbOffset; - int xOffset = aRegion.x - origin.x; - int yOffset = aRegion.y - origin.y; - dataOffsets[0] += xOffset+yOffset*scanlineStride; - } else { - throw new RasterFormatException("ShortComponentRasters must have"+ - "ComponentSampleModel or SinglePixelPackedSampleModel"); - } - this.bandOffset = this.dataOffsets[0]; - - verify(false); - } - - /** - * Returns a copy of the data offsets array. For each band the data offset - * is the index into the band's data array, of the first sample of the - * band. - */ - public int[] getDataOffsets() { - return (int[]) dataOffsets.clone(); - } - - /** - * Returns the data offset for the specified band. The data offset - * is the index into the data array in which the first sample - * of the first scanline is stored. - * @param band The band whose offset is returned. - */ - public int getDataOffset(int band) { - return dataOffsets[band]; - } - - /** - * Returns the scanline stride -- the number of data array elements between - * a given sample and the same sample in the same column of the next row. - */ - public int getScanlineStride() { - return scanlineStride; - } - - /** - * Returns pixel stride -- the number of data array elements between two - * samples for the same band on the same scanline. - */ - public int getPixelStride() { - return pixelStride; - } - - /** - * Returns a reference to the data array. - */ - public short[] getDataStorage() { - return data; - } - - /** - * Returns the data elements for all bands at the specified - * location. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinate is out of bounds. - * A ClassCastException will be thrown if the input object is non null - * and references anything other than an array of transferType. - * @param x The X coordinate of the pixel location. - * @param y The Y coordinate of the pixel location. - * @param outData An object reference to an array of type defined by - * getTransferType() and length getNumDataElements(). - * If null an array of appropriate type and size will be - * allocated. - * @return An object reference to an array of type defined by - * getTransferType() with the request pixel data. - */ - public Object getDataElements(int x, int y, Object obj) { - if ((x < this.minX) || (y < this.minY) || - (x >= this.maxX) || (y >= this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - short outData[]; - if (obj == null) { - outData = new short[numDataElements]; - } else { - outData = (short[])obj; - } - int off = (y-minY)*scanlineStride + - (x-minX)*pixelStride; - - for (int band = 0; band < numDataElements; band++) { - outData[band] = data[dataOffsets[band] + off]; - } - - return outData; - } - - /** - * Returns an array of data elements from the specified rectangular - * region. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * A ClassCastException will be thrown if the input object is non null - * and references anything other than an array of transferType. - * <pre> - * short[] bandData = (short[])Raster.getDataElements(x, y, w, h, null); - * int numDataElements = Raster.getBands(); - * short[] pixel = new short[numDataElements]; - * // To find the data element at location (x2, y2) - * System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements, - * pixel, 0, numDataElements); - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param width Width of the pixel rectangle. - * @param height Height of the pixel rectangle. - * @param outData An object reference to an array of type defined by - * getTransferType() and length w*h*getNumDataElements(). - * If null an array of appropriate type and size will be - * allocated. - * @return An object reference to an array of type defined by - * getTransferType() with the request pixel data. - */ - public Object getDataElements(int x, int y, int w, int h, Object obj) { - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - short outData[]; - if (obj == null) { - outData = new short[w*h*numDataElements]; - } else { - outData = (short[])obj; - } - int yoff = (y-minY)*scanlineStride + - (x-minX)*pixelStride; - - int xoff; - int off = 0; - int xstart; - int ystart; - - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - xoff = yoff; - for (xstart=0; xstart < w; xstart++, xoff += pixelStride) { - for (int c = 0; c < numDataElements; c++) { - outData[off++] = data[dataOffsets[c] + xoff]; - } - } - } - - return outData; - } - - /** - * Returns a short integer array of data elements from the - * specified rectangular region. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * <pre> - * short[] bandData = Raster.getShortData(x, y, w, h, null); - * // To find the data element at location (x2, y2) - * short dataElenent = bandData[((y2-y)*w + (x2-x))]; - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param width Width of the sample rectangle. - * @param height Height of the sample rectangle. - * @param band The band to return. - * @param outData If non-null, data elements for all bands - * at the specified location are returned in this array. - * @return Data array with data elements for all bands. - */ - public short[] getShortData(int x, int y, int w, int h, - int band, short[] outData) { - // Bounds check for 'band' will be performed automatically - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - if (outData == null) { - outData = new short[numDataElements*w*h]; - } - int yoff = (y-minY)*scanlineStride + - (x-minX)*pixelStride+ dataOffsets[band]; - int xoff; - int off = 0; - int xstart; - int ystart; - - if (pixelStride == 1) { - if (scanlineStride == w) { - System.arraycopy(data, yoff, outData, 0, w*h); - } - else { - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - System.arraycopy(data, yoff, outData, off, w); - off += w; - } - } - } - else { - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - xoff = yoff; - for (xstart=0; xstart < w; xstart++, xoff += pixelStride) { - outData[off++] = data[xoff]; - } - } - } - - return outData; - } - - /** - * Returns a short integer array of data elements from the - * specified rectangular region. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * <pre> - * short[] bandData = Raster.getShortData(x, y, w, h, null); - * int numDataElements = Raster.getNumBands(); - * short[] pixel = new short[numDataElements]; - * // To find the data element at location (x2, y2) - * System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements, - * pixel, 0, numDataElements); - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param width Width of the pixel rectangle. - * @param height Height of the pixel rectangle. - * @param outData If non-null, data elements for all bands - * at the specified location are returned in this array. - * @return Data array with data elements for all bands. - */ - public short[] getShortData(int x, int y, int w, int h, short[] outData) { - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - if (outData == null) { - outData = new short[numDataElements*w*h]; - } - int yoff = (y-minY)*scanlineStride + - (x-minX)*pixelStride; - int xoff; - int off = 0; - int xstart; - int ystart; - - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - xoff = yoff; - for (xstart=0; xstart < w; xstart++, xoff += pixelStride) { - for (int c = 0; c < numDataElements; c++) { - outData[off++] = data[dataOffsets[c] + xoff]; - } - } - } - - return outData; - } - - /** - * Stores the data elements for all bands at the specified location. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinate is out of bounds. - * A ClassCastException will be thrown if the input object is non null - * and references anything other than an array of transferType. - * @param x The X coordinate of the pixel location. - * @param y The Y coordinate of the pixel location. - * @param inData An object reference to an array of type defined by - * getTransferType() and length getNumDataElements() - * containing the pixel data to place at x,y. - */ - public void setDataElements(int x, int y, Object obj) { - if ((x < this.minX) || (y < this.minY) || - (x >= this.maxX) || (y >= this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - short inData[] = (short[])obj; - int off = (y-minY)*scanlineStride + - (x-minX)*pixelStride; - for (int i = 0; i < numDataElements; i++) { - data[dataOffsets[i] + off] = (short) inData[i]; - } - - markDirty(); - } - - /** - * Stores the Raster data at the specified location. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * @param x The X coordinate of the pixel location. - * @param y The Y coordinate of the pixel location. - * @param inRaster Raster of data to place at x,y location. - */ - public void setDataElements(int x, int y, Raster inRaster) { - int dstOffX = x + inRaster.getMinX(); - int dstOffY = y + inRaster.getMinY(); - int width = inRaster.getWidth(); - int height = inRaster.getHeight(); - if ((dstOffX < this.minX) || (dstOffY < this.minY) || - (dstOffX + width > this.maxX) || (dstOffY + height > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - - setDataElements(dstOffX, dstOffY, width, height, inRaster); - } - - /** - * Stores the Raster data at the specified location. - * @param dstX The absolute X coordinate of the destination pixel - * that will receive a copy of the upper-left pixel of the - * inRaster - * @param dstY The absolute Y coordinate of the destination pixel - * that will receive a copy of the upper-left pixel of the - * inRaster - * @param width The number of pixels to store horizontally - * @param height The number of pixels to store vertically - * @param inRaster Raster of data to place at x,y location. - */ - private void setDataElements(int dstX, int dstY, - int width, int height, - Raster inRaster) { - // Assume bounds checking has been performed previously - if (width <= 0 || height <= 0) { - return; - } - - // Write inRaster (minX, minY) to (dstX, dstY) - - int srcOffX = inRaster.getMinX(); - int srcOffY = inRaster.getMinY(); - Object tdata = null; - -// // REMIND: Do something faster! -// if (inRaster instanceof ShortComponentRaster) { -// } - - for (int startY=0; startY < height; startY++) { - // Grab one scanline at a time - tdata = inRaster.getDataElements(srcOffX, srcOffY+startY, - width, 1, tdata); - setDataElements(dstX, dstY + startY, width, 1, tdata); - } - } - - /** - * Stores an array of data elements into the specified rectangular - * region. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * A ClassCastException will be thrown if the input object is non null - * and references anything other than an array of transferType. - * The data elements in the - * data array are assumed to be packed. That is, a data element - * for the nth band at location (x2, y2) would be found at: - * <pre> - * inData[((y2-y)*w + (x2-x))*numDataElements + n] - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param w Width of the pixel rectangle. - * @param h Height of the pixel rectangle. - * @param inData An object reference to an array of type defined by - * getTransferType() and length w*h*getNumDataElements() - * containing the pixel data to place between x,y and - * x+h, y+h. - */ - public void setDataElements(int x, int y, int w, int h, Object obj) { - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - short inData[] = (short[])obj; - int yoff = (y-minY)*scanlineStride + - (x-minX)*pixelStride; - int xoff; - int off = 0; - int xstart; - int ystart; - - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - xoff = yoff; - for (xstart=0; xstart < w; xstart++, xoff += pixelStride) { - for (int c = 0; c < numDataElements; c++) { - data[dataOffsets[c] + xoff] = (short) inData[off++]; - } - } - } - - markDirty(); - } - - /** - * Stores a short integer array of data elements into the - * specified rectangular region. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * The data elements in the - * data array are assumed to be packed. That is, a data element - * at location (x2, y2) would be found at: - * <pre> - * inData[((y2-y)*w + (x2-x))] - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param w Width of the pixel rectangle. - * @param h Height of the pixel rectangle. - * @param band The band to set. - * @param inData The data elements to be stored. - */ - public void putShortData(int x, int y, int w, int h, - int band, short[] inData) { - // Bounds check for 'band' will be performed automatically - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - int yoff = (y-minY)*scanlineStride + - (x-minX)*pixelStride + dataOffsets[band]; - int xoff; - int off = 0; - int xstart; - int ystart; - - if (pixelStride == 1) { - if (scanlineStride == w) { - System.arraycopy(inData, 0, data, yoff, w*h); - } - else { - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - System.arraycopy(inData, off, data, yoff, w); - off += w; - } - } - } - else { - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - xoff = yoff; - for (xstart=0; xstart < w; xstart++, xoff += pixelStride) { - data[xoff] = inData[off++]; - } - } - } - - markDirty(); - } - - /** - * Stores a short integer array of data elements into the - * specified rectangular region. - * An ArrayIndexOutOfBounds exception will be thrown at runtime - * if the pixel coordinates are out of bounds. - * The data elements in the - * data array are assumed to be packed. That is, a data element - * for the nth band at location (x2, y2) would be found at: - * <pre> - * inData[((y2-y)*w + (x2-x))*numDataElements + n] - * </pre> - * @param x The X coordinate of the upper left pixel location. - * @param y The Y coordinate of the upper left pixel location. - * @param w Width of the pixel rectangle. - * @param h Height of the pixel rectangle. - * @param inData The data elements to be stored. - */ - public void putShortData(int x, int y, int w, int h, short[] inData) { - if ((x < this.minX) || (y < this.minY) || - (x + w > this.maxX) || (y + h > this.maxY)) { - throw new ArrayIndexOutOfBoundsException - ("Coordinate out of bounds!"); - } - int yoff = (y-minY)*scanlineStride + - (x-minX)*pixelStride; - int xoff; - int off = 0; - int xstart; - int ystart; - - for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) { - xoff = yoff; - for (xstart=0; xstart < w; xstart++, xoff += pixelStride) { - for (int c = 0; c < numDataElements; c++) { - data[dataOffsets[c] + xoff] = inData[off++]; - } - } - } - - markDirty(); - } - - /** - * Creates a subraster given a region of the raster. The x and y - * coordinates specify the horizontal and vertical offsets - * from the upper-left corner of this raster to the upper-left corner - * of the subraster. A subset of the bands of the parent Raster may - * be specified. If this is null, then all the bands are present in the - * subRaster. A translation to the subRaster may also be specified. - * Note that the subraster will reference the same - * band objects as the parent raster, but using different offsets. - * @param x X offset. - * @param y Y offset. - * @param width Width (in pixels) of the subraster. - * @param height Height (in pixels) of the subraster. - * @param x0 Translated X origin of the subraster. - * @param y0 Translated Y origin of the subraster. - * @param bandList Array of band indices. - * @exception RasterFormatException - * if the specified bounding box is outside of the parent raster. - */ - public Raster createChild (int x, int y, - int width, int height, - int x0, int y0, int[] bandList) { - WritableRaster newRaster = createWritableChild(x, y, - width, height, - x0, y0, - bandList); - return (Raster) newRaster; - } - - /** - * Creates a Writable subRaster given a region of the Raster. The x and y - * coordinates specify the horizontal and vertical offsets - * from the upper-left corner of this Raster to the upper-left corner - * of the subRaster. A subset of the bands of the parent Raster may - * be specified. If this is null, then all the bands are present in the - * subRaster. A translation to the subRaster may also be specified. - * Note that the subRaster will reference the same - * DataBuffers as the parent Raster, but using different offsets. - * @param x X offset. - * @param y Y offset. - * @param width Width (in pixels) of the subraster. - * @param height Height (in pixels) of the subraster. - * @param x0 Translated X origin of the subraster. - * @param y0 Translated Y origin of the subraster. - * @param bandList Array of band indices. - * @exception RasterFormatException - * if the specified bounding box is outside of the parent Raster. - */ - public WritableRaster createWritableChild(int x, int y, - int width, int height, - int x0, int y0, - int[] bandList) { - if (x < this.minX) { - throw new RasterFormatException("x lies outside the raster"); - } - if (y < this.minY) { - throw new RasterFormatException("y lies outside the raster"); - } - if ((x+width < x) || (x+width > this.minX + this.width)) { - throw new RasterFormatException("(x + width) is outside of Raster"); - } - if ((y+height < y) || (y+height > this.minY + this.height)) { - throw new RasterFormatException("(y + height) is outside of Raster"); - } - - SampleModel sm; - - if (bandList != null) - sm = sampleModel.createSubsetSampleModel(bandList); - else - sm = sampleModel; - - int deltaX = x0 - x; - int deltaY = y0 - y; - - return new ShortComponentRaster(sm, - dataBuffer, - new Rectangle(x0, y0, width, height), - new Point(sampleModelTranslateX+deltaX, - sampleModelTranslateY+deltaY), - this); - } - - /** - * Creates a Raster with the same layout but using a different - * width and height, and with new zeroed data arrays. - */ - public WritableRaster createCompatibleWritableRaster(int w, int h) { - if (w <= 0 || h <=0) { - throw new RasterFormatException("negative "+ - ((w <= 0) ? "width" : "height")); - } - - SampleModel sm = sampleModel.createCompatibleSampleModel(w, h); - - return new ShortComponentRaster(sm, new Point(0, 0)); - } - - /** - * Creates a Raster with the same layout and the same - * width and height, and with new zeroed data arrays. If - * the Raster is a subRaster, this will call - * createCompatibleRaster(width, height). - */ - public WritableRaster createCompatibleWritableRaster() { - return createCompatibleWritableRaster(width,height); - } - - /** - * Verify that the layout parameters are consistent with - * the data. If strictCheck - * is false, this method will check for ArrayIndexOutOfBounds conditions. If - * strictCheck is true, this method will check for additional error - * conditions such as line wraparound (width of a line greater than - * the scanline stride). - * @return String Error string, if the layout is incompatible with - * the data. Otherwise returns null. - */ - private void verify (boolean strictCheck) { - // Make sure data for Raster is in a legal range - for (int i=0; i < dataOffsets.length; i++) { - if (dataOffsets[i] < 0) { - throw new RasterFormatException("Data offsets for band "+i+ - "("+dataOffsets[i]+ - ") must be >= 0"); - } - } - - int maxSize = 0; - int size; - - for (int i=0; i < numDataElements; i++) { - size = (height-1)*scanlineStride + (width-1)*pixelStride + - dataOffsets[i]; - if (size > maxSize) { - maxSize = size; - } - } - if (data.length < maxSize) { - throw new RasterFormatException("Data array too small (should be "+ - maxSize+" )"); - } - } - - public String toString() { - return new String ("ShortComponentRaster: width = "+width - +" height = " + height - +" #numDataElements "+numDataElements); - // +" xOff = "+xOffset+" yOff = "+yOffset); - } - -} |