src/share/classes/javax/imageio/ImageTypeSpecifier.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 2003, 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


 279             }
 280             if (bandOffsets == null) {
 281                 throw new IllegalArgumentException("bandOffsets == null!");
 282             }
 283             int numBands = colorSpace.getNumComponents() +
 284                 (hasAlpha ? 1 : 0);
 285             if (bandOffsets.length != numBands) {
 286                 throw new IllegalArgumentException
 287                     ("bandOffsets.length is wrong!");
 288             }
 289             if (dataType != DataBuffer.TYPE_BYTE &&
 290                 dataType != DataBuffer.TYPE_SHORT &&
 291                 dataType != DataBuffer.TYPE_USHORT &&
 292                 dataType != DataBuffer.TYPE_INT &&
 293                 dataType != DataBuffer.TYPE_FLOAT &&
 294                 dataType != DataBuffer.TYPE_DOUBLE) {
 295                 throw new IllegalArgumentException
 296                     ("Bad value for dataType!");
 297             }
 298             this.colorSpace = colorSpace;
 299             this.bandOffsets = (int[])bandOffsets.clone();
 300             this.dataType = dataType;
 301             this.hasAlpha = hasAlpha;
 302             this.isAlphaPremultiplied = isAlphaPremultiplied;
 303 
 304             this.colorModel =
 305                 ImageTypeSpecifier.createComponentCM(colorSpace,
 306                                                      bandOffsets.length,
 307                                                      dataType,
 308                                                      hasAlpha,
 309                                                      isAlphaPremultiplied);
 310 
 311             int minBandOffset = bandOffsets[0];
 312             int maxBandOffset = minBandOffset;
 313             for (int i = 0; i < bandOffsets.length; i++) {
 314                 int offset = bandOffsets[i];
 315                 minBandOffset = Math.min(offset, minBandOffset);
 316                 maxBandOffset = Math.max(offset, maxBandOffset);
 317             }
 318             int pixelStride = maxBandOffset - minBandOffset + 1;
 319 


 432                 throw new IllegalArgumentException
 433                     ("bankIndices.length != bandOffsets.length!");
 434             }
 435             if (dataType != DataBuffer.TYPE_BYTE &&
 436                 dataType != DataBuffer.TYPE_SHORT &&
 437                 dataType != DataBuffer.TYPE_USHORT &&
 438                 dataType != DataBuffer.TYPE_INT &&
 439                 dataType != DataBuffer.TYPE_FLOAT &&
 440                 dataType != DataBuffer.TYPE_DOUBLE) {
 441                 throw new IllegalArgumentException
 442                     ("Bad value for dataType!");
 443             }
 444             int numBands = colorSpace.getNumComponents() +
 445                 (hasAlpha ? 1 : 0);
 446             if (bandOffsets.length != numBands) {
 447                 throw new IllegalArgumentException
 448                     ("bandOffsets.length is wrong!");
 449             }
 450 
 451             this.colorSpace = colorSpace;
 452             this.bankIndices = (int[])bankIndices.clone();
 453             this.bandOffsets = (int[])bandOffsets.clone();
 454             this.dataType = dataType;
 455             this.hasAlpha = hasAlpha;
 456             this.isAlphaPremultiplied = isAlphaPremultiplied;
 457 
 458             this.colorModel =
 459                 ImageTypeSpecifier.createComponentCM(colorSpace,
 460                                                      bankIndices.length,
 461                                                      dataType,
 462                                                      hasAlpha,
 463                                                      isAlphaPremultiplied);
 464 
 465             int w = 1;
 466             int h = 1;
 467             this.sampleModel = new BandedSampleModel(dataType,
 468                                                      w, h,
 469                                                      w,
 470                                                      bankIndices,
 471                                                      bandOffsets);
 472         }
 473 


 752             if (dataType != DataBuffer.TYPE_BYTE &&
 753                 dataType != DataBuffer.TYPE_SHORT &&
 754                 dataType != DataBuffer.TYPE_USHORT &&
 755                 dataType != DataBuffer.TYPE_INT) {
 756                 throw new IllegalArgumentException
 757                     ("Bad value for dataType!");
 758             }
 759             if ((bits > 8 && dataType == DataBuffer.TYPE_BYTE) ||
 760                 (bits > 16 && dataType != DataBuffer.TYPE_INT)) {
 761                 throw new IllegalArgumentException
 762                     ("Too many bits for dataType!");
 763             }
 764 
 765             int len = 1 << bits;
 766             if (redLUT.length != len ||
 767                 greenLUT.length != len ||
 768                 blueLUT.length != len ||
 769                 (alphaLUT != null && alphaLUT.length != len)) {
 770                 throw new IllegalArgumentException("LUT has improper length!");
 771             }
 772             this.redLUT = (byte[])redLUT.clone();
 773             this.greenLUT = (byte[])greenLUT.clone();
 774             this.blueLUT = (byte[])blueLUT.clone();
 775             if (alphaLUT != null) {
 776                 this.alphaLUT = (byte[])alphaLUT.clone();
 777             }
 778             this.bits = bits;
 779             this.dataType = dataType;
 780 
 781             if (alphaLUT == null) {
 782                 this.colorModel = new IndexColorModel(bits,
 783                                                       redLUT.length,
 784                                                       redLUT,
 785                                                       greenLUT,
 786                                                       blueLUT);
 787             } else {
 788                 this.colorModel = new IndexColorModel(bits,
 789                                                       redLUT.length,
 790                                                       redLUT,
 791                                                       greenLUT,
 792                                                       blueLUT,
 793                                                       alphaLUT);
 794             }
 795 
 796             if ((bits == 8 && dataType == DataBuffer.TYPE_BYTE) ||


   1 /*
   2  * Copyright (c) 2000, 2014, 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


 279             }
 280             if (bandOffsets == null) {
 281                 throw new IllegalArgumentException("bandOffsets == null!");
 282             }
 283             int numBands = colorSpace.getNumComponents() +
 284                 (hasAlpha ? 1 : 0);
 285             if (bandOffsets.length != numBands) {
 286                 throw new IllegalArgumentException
 287                     ("bandOffsets.length is wrong!");
 288             }
 289             if (dataType != DataBuffer.TYPE_BYTE &&
 290                 dataType != DataBuffer.TYPE_SHORT &&
 291                 dataType != DataBuffer.TYPE_USHORT &&
 292                 dataType != DataBuffer.TYPE_INT &&
 293                 dataType != DataBuffer.TYPE_FLOAT &&
 294                 dataType != DataBuffer.TYPE_DOUBLE) {
 295                 throw new IllegalArgumentException
 296                     ("Bad value for dataType!");
 297             }
 298             this.colorSpace = colorSpace;
 299             this.bandOffsets = bandOffsets.clone();
 300             this.dataType = dataType;
 301             this.hasAlpha = hasAlpha;
 302             this.isAlphaPremultiplied = isAlphaPremultiplied;
 303 
 304             this.colorModel =
 305                 ImageTypeSpecifier.createComponentCM(colorSpace,
 306                                                      bandOffsets.length,
 307                                                      dataType,
 308                                                      hasAlpha,
 309                                                      isAlphaPremultiplied);
 310 
 311             int minBandOffset = bandOffsets[0];
 312             int maxBandOffset = minBandOffset;
 313             for (int i = 0; i < bandOffsets.length; i++) {
 314                 int offset = bandOffsets[i];
 315                 minBandOffset = Math.min(offset, minBandOffset);
 316                 maxBandOffset = Math.max(offset, maxBandOffset);
 317             }
 318             int pixelStride = maxBandOffset - minBandOffset + 1;
 319 


 432                 throw new IllegalArgumentException
 433                     ("bankIndices.length != bandOffsets.length!");
 434             }
 435             if (dataType != DataBuffer.TYPE_BYTE &&
 436                 dataType != DataBuffer.TYPE_SHORT &&
 437                 dataType != DataBuffer.TYPE_USHORT &&
 438                 dataType != DataBuffer.TYPE_INT &&
 439                 dataType != DataBuffer.TYPE_FLOAT &&
 440                 dataType != DataBuffer.TYPE_DOUBLE) {
 441                 throw new IllegalArgumentException
 442                     ("Bad value for dataType!");
 443             }
 444             int numBands = colorSpace.getNumComponents() +
 445                 (hasAlpha ? 1 : 0);
 446             if (bandOffsets.length != numBands) {
 447                 throw new IllegalArgumentException
 448                     ("bandOffsets.length is wrong!");
 449             }
 450 
 451             this.colorSpace = colorSpace;
 452             this.bankIndices = bankIndices.clone();
 453             this.bandOffsets = bandOffsets.clone();
 454             this.dataType = dataType;
 455             this.hasAlpha = hasAlpha;
 456             this.isAlphaPremultiplied = isAlphaPremultiplied;
 457 
 458             this.colorModel =
 459                 ImageTypeSpecifier.createComponentCM(colorSpace,
 460                                                      bankIndices.length,
 461                                                      dataType,
 462                                                      hasAlpha,
 463                                                      isAlphaPremultiplied);
 464 
 465             int w = 1;
 466             int h = 1;
 467             this.sampleModel = new BandedSampleModel(dataType,
 468                                                      w, h,
 469                                                      w,
 470                                                      bankIndices,
 471                                                      bandOffsets);
 472         }
 473 


 752             if (dataType != DataBuffer.TYPE_BYTE &&
 753                 dataType != DataBuffer.TYPE_SHORT &&
 754                 dataType != DataBuffer.TYPE_USHORT &&
 755                 dataType != DataBuffer.TYPE_INT) {
 756                 throw new IllegalArgumentException
 757                     ("Bad value for dataType!");
 758             }
 759             if ((bits > 8 && dataType == DataBuffer.TYPE_BYTE) ||
 760                 (bits > 16 && dataType != DataBuffer.TYPE_INT)) {
 761                 throw new IllegalArgumentException
 762                     ("Too many bits for dataType!");
 763             }
 764 
 765             int len = 1 << bits;
 766             if (redLUT.length != len ||
 767                 greenLUT.length != len ||
 768                 blueLUT.length != len ||
 769                 (alphaLUT != null && alphaLUT.length != len)) {
 770                 throw new IllegalArgumentException("LUT has improper length!");
 771             }
 772             this.redLUT = redLUT.clone();
 773             this.greenLUT = greenLUT.clone();
 774             this.blueLUT = blueLUT.clone();
 775             if (alphaLUT != null) {
 776                 this.alphaLUT = alphaLUT.clone();
 777             }
 778             this.bits = bits;
 779             this.dataType = dataType;
 780 
 781             if (alphaLUT == null) {
 782                 this.colorModel = new IndexColorModel(bits,
 783                                                       redLUT.length,
 784                                                       redLUT,
 785                                                       greenLUT,
 786                                                       blueLUT);
 787             } else {
 788                 this.colorModel = new IndexColorModel(bits,
 789                                                       redLUT.length,
 790                                                       redLUT,
 791                                                       greenLUT,
 792                                                       blueLUT,
 793                                                       alphaLUT);
 794             }
 795 
 796             if ((bits == 8 && dataType == DataBuffer.TYPE_BYTE) ||