src/share/classes/java/awt/image/DataBuffer.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  24  */
  25 
  26 /* ****************************************************************
  27  ******************************************************************
  28  ******************************************************************
  29  *** COPYRIGHT (c) Eastman Kodak Company, 1997
  30  *** As  an unpublished  work pursuant to Title 17 of the United
  31  *** States Code.  All rights reserved.
  32  ******************************************************************
  33  ******************************************************************
  34  ******************************************************************/
  35 
  36 package java.awt.image;
  37 
  38 import sun.java2d.StateTrackable.State;
  39 import static sun.java2d.StateTrackable.State.*;
  40 import sun.java2d.StateTrackableDelegate;
  41 
  42 import sun.awt.image.SunWritableRaster;
  43 
  44 import javax.tools.annotation.GenerateNativeHeader;
  45 
  46 /**
  47  * This class exists to wrap one or more data arrays.  Each data array in
  48  * the DataBuffer is referred to as a bank.  Accessor methods for getting
  49  * and setting elements of the DataBuffer's banks exist with and without
  50  * a bank specifier.  The methods without a bank specifier use the default 0th
  51  * bank.  The DataBuffer can optionally take an offset per bank, so that
  52  * data in an existing array can be used even if the interesting data
  53  * doesn't start at array location zero.  Getting or setting the 0th
  54  * element of a bank, uses the (0+offset)th element of the array.  The
  55  * size field specifies how much of the data array is available for
  56  * use.  Size + offset for a given bank should never be greater
  57  * than the length of the associated data array.  The data type of
  58  * a data buffer indicates the type of the data array(s) and may also
  59  * indicate additional semantics, e.g. storing unsigned 8-bit data
  60  * in elements of a byte array.  The data type may be TYPE_UNDEFINED
  61  * or one of the types defined below.  Other types may be added in
  62  * the future.  Generally, an object of class DataBuffer will be cast down
  63  * to one of its data type specific subclasses to access data type specific
  64  * methods for improved performance.  Currently, the Java 2D(tm) API
  65  * image classes use TYPE_BYTE, TYPE_USHORT, TYPE_INT, TYPE_SHORT,
  66  * TYPE_FLOAT, and TYPE_DOUBLE DataBuffers to store image data.
  67  * @see java.awt.image.Raster
  68  * @see java.awt.image.SampleModel
  69  */
  70 /* No native methods here, but the constants are needed in the supporting JNI code */
  71 @GenerateNativeHeader
  72 public abstract class DataBuffer {
  73 
  74     /** Tag for unsigned byte data. */
  75     public static final int TYPE_BYTE  = 0;
  76 
  77     /** Tag for unsigned short data. */
  78     public static final int TYPE_USHORT = 1;
  79 
  80     /** Tag for signed short data.  Placeholder for future use. */
  81     public static final int TYPE_SHORT = 2;
  82 
  83     /** Tag for int data. */
  84     public static final int TYPE_INT   = 3;
  85 
  86     /** Tag for float data.  Placeholder for future use. */
  87     public static final int TYPE_FLOAT  = 4;
  88 
  89     /** Tag for double data.  Placeholder for future use. */
  90     public static final int TYPE_DOUBLE  = 5;
  91 
  92     /** Tag for undefined data. */
  93     public static final int TYPE_UNDEFINED = 32;
  94 
  95     /** The data type of this DataBuffer. */
  96     protected int dataType;
  97 
  98     /** The number of banks in this DataBuffer. */
  99     protected int banks;
 100 
 101     /** Offset into default (first) bank from which to get the first element. */
 102     protected int offset;
 103 
 104     /** Usable size of all banks. */
 105     protected int size;
 106 
 107     /** Offsets into all banks. */
 108     protected int offsets[];
 109 
 110     /* The current StateTrackable state. */
 111     StateTrackableDelegate theTrackable;
 112 
 113     /** Size of the data types indexed by DataType tags defined above. */


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  24  */
  25 
  26 /* ****************************************************************
  27  ******************************************************************
  28  ******************************************************************
  29  *** COPYRIGHT (c) Eastman Kodak Company, 1997
  30  *** As  an unpublished  work pursuant to Title 17 of the United
  31  *** States Code.  All rights reserved.
  32  ******************************************************************
  33  ******************************************************************
  34  ******************************************************************/
  35 
  36 package java.awt.image;
  37 
  38 import sun.java2d.StateTrackable.State;
  39 import static sun.java2d.StateTrackable.State.*;
  40 import sun.java2d.StateTrackableDelegate;
  41 
  42 import sun.awt.image.SunWritableRaster;
  43 
  44 import java.lang.annotation.Native;
  45 
  46 /**
  47  * This class exists to wrap one or more data arrays.  Each data array in
  48  * the DataBuffer is referred to as a bank.  Accessor methods for getting
  49  * and setting elements of the DataBuffer's banks exist with and without
  50  * a bank specifier.  The methods without a bank specifier use the default 0th
  51  * bank.  The DataBuffer can optionally take an offset per bank, so that
  52  * data in an existing array can be used even if the interesting data
  53  * doesn't start at array location zero.  Getting or setting the 0th
  54  * element of a bank, uses the (0+offset)th element of the array.  The
  55  * size field specifies how much of the data array is available for
  56  * use.  Size + offset for a given bank should never be greater
  57  * than the length of the associated data array.  The data type of
  58  * a data buffer indicates the type of the data array(s) and may also
  59  * indicate additional semantics, e.g. storing unsigned 8-bit data
  60  * in elements of a byte array.  The data type may be TYPE_UNDEFINED
  61  * or one of the types defined below.  Other types may be added in
  62  * the future.  Generally, an object of class DataBuffer will be cast down
  63  * to one of its data type specific subclasses to access data type specific
  64  * methods for improved performance.  Currently, the Java 2D(tm) API
  65  * image classes use TYPE_BYTE, TYPE_USHORT, TYPE_INT, TYPE_SHORT,
  66  * TYPE_FLOAT, and TYPE_DOUBLE DataBuffers to store image data.
  67  * @see java.awt.image.Raster
  68  * @see java.awt.image.SampleModel
  69  */


  70 public abstract class DataBuffer {
  71 
  72     /** Tag for unsigned byte data. */
  73     @Native public static final int TYPE_BYTE  = 0;
  74 
  75     /** Tag for unsigned short data. */
  76     @Native public static final int TYPE_USHORT = 1;
  77 
  78     /** Tag for signed short data.  Placeholder for future use. */
  79     @Native public static final int TYPE_SHORT = 2;
  80 
  81     /** Tag for int data. */
  82     @Native public static final int TYPE_INT   = 3;
  83 
  84     /** Tag for float data.  Placeholder for future use. */
  85     @Native public static final int TYPE_FLOAT  = 4;
  86 
  87     /** Tag for double data.  Placeholder for future use. */
  88     @Native public static final int TYPE_DOUBLE  = 5;
  89 
  90     /** Tag for undefined data. */
  91     @Native public static final int TYPE_UNDEFINED = 32;
  92 
  93     /** The data type of this DataBuffer. */
  94     protected int dataType;
  95 
  96     /** The number of banks in this DataBuffer. */
  97     protected int banks;
  98 
  99     /** Offset into default (first) bank from which to get the first element. */
 100     protected int offset;
 101 
 102     /** Usable size of all banks. */
 103     protected int size;
 104 
 105     /** Offsets into all banks. */
 106     protected int offsets[];
 107 
 108     /* The current StateTrackable state. */
 109     StateTrackableDelegate theTrackable;
 110 
 111     /** Size of the data types indexed by DataType tags defined above. */