jdk/src/share/classes/java/awt/image/SinglePixelPackedSampleModel.java
changeset 22584 eed64ee05369
parent 19169 1807a84c3d63
equal deleted inserted replaced
22583:e7d5af0b11e9 22584:eed64ee05369
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2014, 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
   147             dataType != DataBuffer.TYPE_INT) {
   147             dataType != DataBuffer.TYPE_INT) {
   148             throw new IllegalArgumentException("Unsupported data type "+
   148             throw new IllegalArgumentException("Unsupported data type "+
   149                                                dataType);
   149                                                dataType);
   150         }
   150         }
   151         this.dataType = dataType;
   151         this.dataType = dataType;
   152         this.bitMasks = (int[]) bitMasks.clone();
   152         this.bitMasks = bitMasks.clone();
   153         this.scanlineStride = scanlineStride;
   153         this.scanlineStride = scanlineStride;
   154 
   154 
   155         this.bitOffsets = new int[numBands];
   155         this.bitOffsets = new int[numBands];
   156         this.bitSizes = new int[numBands];
   156         this.bitSizes = new int[numBands];
   157 
   157 
   274     /** Returns the bit offsets into the data array element representing
   274     /** Returns the bit offsets into the data array element representing
   275      *  a pixel for all bands.
   275      *  a pixel for all bands.
   276      *  @return the bit offsets representing a pixel for all bands.
   276      *  @return the bit offsets representing a pixel for all bands.
   277      */
   277      */
   278     public int [] getBitOffsets() {
   278     public int [] getBitOffsets() {
   279       return (int[])bitOffsets.clone();
   279       return bitOffsets.clone();
   280     }
   280     }
   281 
   281 
   282     /** Returns the bit masks for all bands.
   282     /** Returns the bit masks for all bands.
   283      *  @return the bit masks for all bands.
   283      *  @return the bit masks for all bands.
   284      */
   284      */
   285     public int [] getBitMasks() {
   285     public int [] getBitMasks() {
   286       return (int[])bitMasks.clone();
   286       return bitMasks.clone();
   287     }
   287     }
   288 
   288 
   289     /** Returns the scanline stride of this SinglePixelPackedSampleModel.
   289     /** Returns the scanline stride of this SinglePixelPackedSampleModel.
   290      *  @return the scanline stride of this
   290      *  @return the scanline stride of this
   291      *          <code>SinglePixelPackedSampleModel</code>.
   291      *          <code>SinglePixelPackedSampleModel</code>.
   744         for (int i = 0; i < h; i++) {
   744         for (int i = 0; i < h; i++) {
   745            for (int j = 0; j < w; j++) {
   745            for (int j = 0; j < w; j++) {
   746               int value = data.getElem(lineOffset+j);
   746               int value = data.getElem(lineOffset+j);
   747               value &= ~bitMasks[b];
   747               value &= ~bitMasks[b];
   748               int sample = iArray[srcOffset++];
   748               int sample = iArray[srcOffset++];
   749               value |= ((int)sample << bitOffsets[b]) & bitMasks[b];
   749               value |= (sample << bitOffsets[b]) & bitMasks[b];
   750               data.setElem(lineOffset+j,value);
   750               data.setElem(lineOffset+j,value);
   751            }
   751            }
   752            lineOffset += scanlineStride;
   752            lineOffset += scanlineStride;
   753         }
   753         }
   754     }
   754     }