jdk/src/java.desktop/share/classes/sun/awt/image/ShortComponentRaster.java
changeset 37544 d07afcfa7730
parent 32865 f9cb6e427f9e
equal deleted inserted replaced
37543:fdca34c493ba 37544:d07afcfa7730
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    28 import java.awt.image.WritableRaster;
    28 import java.awt.image.WritableRaster;
    29 import java.awt.image.RasterFormatException;
    29 import java.awt.image.RasterFormatException;
    30 import java.awt.image.SampleModel;
    30 import java.awt.image.SampleModel;
    31 import java.awt.image.ComponentSampleModel;
    31 import java.awt.image.ComponentSampleModel;
    32 import java.awt.image.SinglePixelPackedSampleModel;
    32 import java.awt.image.SinglePixelPackedSampleModel;
    33 import java.awt.image.DataBuffer;
       
    34 import java.awt.image.DataBufferUShort;
    33 import java.awt.image.DataBufferUShort;
    35 import java.awt.Rectangle;
    34 import java.awt.Rectangle;
    36 import java.awt.Point;
    35 import java.awt.Point;
    37 
    36 
    38 /**
    37 /**
    92      *  @param sampleModel     The SampleModel that specifies the layout.
    91      *  @param sampleModel     The SampleModel that specifies the layout.
    93      *  @param origin          The Point that specified the origin.
    92      *  @param origin          The Point that specified the origin.
    94      */
    93      */
    95     public ShortComponentRaster(SampleModel sampleModel, Point origin) {
    94     public ShortComponentRaster(SampleModel sampleModel, Point origin) {
    96         this(sampleModel,
    95         this(sampleModel,
    97              sampleModel.createDataBuffer(),
    96              (DataBufferUShort) sampleModel.createDataBuffer(),
    98              new Rectangle(origin.x,
    97              new Rectangle(origin.x,
    99                            origin.y,
    98                            origin.y,
   100                            sampleModel.getWidth(),
    99                            sampleModel.getWidth(),
   101                            sampleModel.getHeight()),
   100                            sampleModel.getHeight()),
   102              origin,
   101              origin,
   113      * @param sampleModel     The SampleModel that specifies the layout.
   112      * @param sampleModel     The SampleModel that specifies the layout.
   114      * @param dataBuffer      The DataBufferUShort that contains the image data.
   113      * @param dataBuffer      The DataBufferUShort that contains the image data.
   115      * @param origin          The Point that specifies the origin.
   114      * @param origin          The Point that specifies the origin.
   116      */
   115      */
   117     public ShortComponentRaster(SampleModel sampleModel,
   116     public ShortComponentRaster(SampleModel sampleModel,
   118                                    DataBuffer dataBuffer,
   117                                 DataBufferUShort dataBuffer,
   119                                    Point origin) {
   118                                 Point origin)
       
   119     {
   120         this(sampleModel,
   120         this(sampleModel,
   121              dataBuffer,
   121              dataBuffer,
   122              new Rectangle(origin.x,
   122              new Rectangle(origin.x,
   123                            origin.y,
   123                            origin.y,
   124                            sampleModel.getWidth(),
   124                            sampleModel.getWidth(),
   144      * @param aRegion         The Rectangle that specifies the image area.
   144      * @param aRegion         The Rectangle that specifies the image area.
   145      * @param origin          The Point that specifies the origin.
   145      * @param origin          The Point that specifies the origin.
   146      * @param parent          The parent (if any) of this raster.
   146      * @param parent          The parent (if any) of this raster.
   147      */
   147      */
   148     public ShortComponentRaster(SampleModel sampleModel,
   148     public ShortComponentRaster(SampleModel sampleModel,
   149                                    DataBuffer dataBuffer,
   149                                 DataBufferUShort dataBuffer,
   150                                    Rectangle aRegion,
   150                                 Rectangle aRegion,
   151                                    Point origin,
   151                                 Point origin,
   152                                    ShortComponentRaster parent) {
   152                                 ShortComponentRaster parent)
   153 
   153     {
   154         super(sampleModel, dataBuffer, aRegion, origin, parent);
   154         super(sampleModel, dataBuffer, aRegion, origin, parent);
   155         this.maxX = minX + width;
   155         this.maxX = minX + width;
   156         this.maxY = minY + height;
   156         this.maxY = minY + height;
   157 
   157 
   158         if(!(dataBuffer instanceof DataBufferUShort)) {
   158         this.data = stealData(dataBuffer, 0);
   159             throw new RasterFormatException("ShortComponentRasters must have "+
   159         if (dataBuffer.getNumBanks() != 1) {
   160                                             "short DataBuffers");
       
   161         }
       
   162 
       
   163         DataBufferUShort dbus = (DataBufferUShort)dataBuffer;
       
   164         this.data = stealData(dbus, 0);
       
   165         if (dbus.getNumBanks() != 1) {
       
   166             throw new
   160             throw new
   167                 RasterFormatException("DataBuffer for ShortComponentRasters"+
   161                 RasterFormatException("DataBuffer for ShortComponentRasters"+
   168                                       " must only have 1 bank.");
   162                                       " must only have 1 bank.");
   169         }
   163         }
   170         int dbOffset = dbus.getOffset();
   164         int dbOffset = dataBuffer.getOffset();
   171 
   165 
   172         if (sampleModel instanceof ComponentSampleModel) {
   166         if (sampleModel instanceof ComponentSampleModel) {
   173             ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
   167             ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
   174             this.type = IntegerComponentRaster.TYPE_USHORT_SAMPLES;
   168             this.type = IntegerComponentRaster.TYPE_USHORT_SAMPLES;
   175             this.scanlineStride = csm.getScanlineStride();
   169             this.scanlineStride = csm.getScanlineStride();
   756 
   750 
   757         int deltaX = x0 - x;
   751         int deltaX = x0 - x;
   758         int deltaY = y0 - y;
   752         int deltaY = y0 - y;
   759 
   753 
   760         return new ShortComponentRaster(sm,
   754         return new ShortComponentRaster(sm,
   761                                        dataBuffer,
   755                                        (DataBufferUShort) dataBuffer,
   762                                        new Rectangle(x0, y0, width, height),
   756                                        new Rectangle(x0, y0, width, height),
   763                                        new Point(sampleModelTranslateX+deltaX,
   757                                        new Point(sampleModelTranslateX+deltaX,
   764                                                  sampleModelTranslateY+deltaY),
   758                                                  sampleModelTranslateY+deltaY),
   765                                        this);
   759                                        this);
   766     }
   760     }