Path: blob/master/src/java.desktop/macosx/classes/sun/java2d/IntegerNIORaster.java
41152 views
/*1* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d;2627import java.awt.*;28import java.awt.image.*;29import java.nio.IntBuffer;30import sun.awt.image.SunWritableRaster;3132public class IntegerNIORaster extends SunWritableRaster {3334protected IntBuffer data;3536public static WritableRaster createNIORaster(int w, int h, int[] bandMasks, Point location) {37if ((w <= 0) || (h <= 0)) {38throw new IllegalArgumentException("Width (" + w + ") and height (" + h +39") cannot be <= 0");40}41// This is cribbed from java.awt.image.Raster.42DataBufferNIOInt db = new DataBufferNIOInt(w * h);43if (location == null) {44location = new Point(0, 0);45}46SinglePixelPackedSampleModel sppsm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, w, h, w, bandMasks);47return new IntegerNIORaster(sppsm, db, location);48}4950public IntegerNIORaster(SampleModel sampleModel, DataBufferNIOInt dataBuffer, Point origin) {51// This is all cribbed from sun.awt.image.IntegerInterleavedRaster & sun.awt.image.IntegerComponentRaster52super(sampleModel, dataBuffer, new Rectangle(origin.x, origin.y, sampleModel.getWidth(), sampleModel.getHeight()), origin, null);5354this.data = dataBuffer.getBuffer();55}5657public WritableRaster createCompatibleWritableRaster() {58return new IntegerNIORaster(sampleModel, new DataBufferNIOInt(sampleModel.getWidth() * sampleModel.getHeight()), new Point(0,0));59}6061public WritableRaster createCompatibleWritableRaster(int w, int h) {62if (w <= 0 || h <=0) {63throw new RasterFormatException("negative " + ((w <= 0) ? "width" : "height"));64}6566SampleModel sm = sampleModel.createCompatibleSampleModel(w,h);6768return new IntegerNIORaster(sm, new DataBufferNIOInt(w * h), new Point(0,0));69}7071public WritableRaster createCompatibleWritableRaster(Rectangle rect) {72if (rect == null) {73throw new NullPointerException("Rect cannot be null");74}75return createCompatibleWritableRaster(rect.x, rect.y, rect.width, rect.height);76}7778public WritableRaster createCompatibleWritableRaster(int x, int y, int w, int h) {79WritableRaster ret = createCompatibleWritableRaster(w, h);80return ret.createWritableChild(0,0,w,h,x,y,null);81}828384public IntBuffer getBuffer() {85return data;86}8788public String toString() {89return new String ("IntegerNIORaster: width = "+width90+" height = " + height91+" #Bands = " + numBands92+" xOff = "+sampleModelTranslateX93+" yOff = "+sampleModelTranslateY);94}95}969798