< prev index next >

src/java.desktop/share/classes/com/sun/imageio/plugins/gif/GIFImageReader.java

Print this page


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


 333         int code = (next32Bits >> bitPos) & codeMask;
 334         bitPos += codeSize;
 335 
 336         // Shift in a byte of new data at a time
 337         while (bitPos >= 8 && !lastBlockFound) {
 338             next32Bits >>>= 8;
 339             bitPos -= 8;
 340 
 341             // Check if current block is out of bytes
 342             if (nextByte >= blockLength) {
 343                 // Get next block size
 344                 blockLength = stream.readUnsignedByte();
 345                 if (blockLength == 0) {
 346                     lastBlockFound = true;
 347                     return code;
 348                 } else {
 349                     int left = blockLength;
 350                     int off = 0;
 351                     while (left > 0) {
 352                         int nbytes = stream.read(block, off, left);




 353                         off += nbytes;
 354                         left -= nbytes;
 355                     }
 356                     nextByte = 0;
 357                 }
 358             }
 359 
 360             next32Bits |= block[nextByte++] << 24;
 361         }
 362 
 363         return code;
 364     }
 365 
 366     public void initializeStringTable(int[] prefix,
 367                                       byte[] suffix,
 368                                       byte[] initial,
 369                                       int[] length) {
 370         int numEntries = 1 << initCodeSize;
 371         for (int i = 0; i < numEntries; i++) {
 372             prefix[i] = -1;


 913             return theImage;
 914         }
 915         startPass(0);
 916 
 917         this.rowBuf = new byte[width];
 918 
 919         try {
 920             // Read and decode the image data, fill in theImage
 921             this.initCodeSize = stream.readUnsignedByte();
 922             // GIF allows max 8 bpp, so anything larger is bogus for the roots.
 923             if (this.initCodeSize < 1 || this.initCodeSize > 8) {
 924                 throw new IIOException("Bad code size:" + this.initCodeSize);
 925             }
 926 
 927             // Read first data block
 928             this.blockLength = stream.readUnsignedByte();
 929             int left = blockLength;
 930             int off = 0;
 931             while (left > 0) {
 932                 int nbytes = stream.read(block, off, left);




 933                 left -= nbytes;
 934                 off += nbytes;
 935             }
 936 
 937             this.bitPos = 0;
 938             this.nextByte = 0;
 939             this.lastBlockFound = false;
 940             this.interlacePass = 0;
 941 
 942             // Init 32-bit buffer
 943             initNext32Bits();
 944 
 945             this.clearCode = 1 << initCodeSize;
 946             this.eofCode = clearCode + 1;
 947 
 948             int code, oldCode = 0;
 949 
 950             int[] prefix = new int[4096];
 951             byte[] suffix = new byte[4096];
 952             byte[] initial = new byte[4096];


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


 333         int code = (next32Bits >> bitPos) & codeMask;
 334         bitPos += codeSize;
 335 
 336         // Shift in a byte of new data at a time
 337         while (bitPos >= 8 && !lastBlockFound) {
 338             next32Bits >>>= 8;
 339             bitPos -= 8;
 340 
 341             // Check if current block is out of bytes
 342             if (nextByte >= blockLength) {
 343                 // Get next block size
 344                 blockLength = stream.readUnsignedByte();
 345                 if (blockLength == 0) {
 346                     lastBlockFound = true;
 347                     return code;
 348                 } else {
 349                     int left = blockLength;
 350                     int off = 0;
 351                     while (left > 0) {
 352                         int nbytes = stream.read(block, off, left);
 353                         if (nbytes == -1 && left > 0) {
 354                             throw new IIOException("Invalid block length for " +
 355                                     "LZW encoded image data");
 356                         }
 357                         off += nbytes;
 358                         left -= nbytes;
 359                     }
 360                     nextByte = 0;
 361                 }
 362             }
 363 
 364             next32Bits |= block[nextByte++] << 24;
 365         }
 366 
 367         return code;
 368     }
 369 
 370     public void initializeStringTable(int[] prefix,
 371                                       byte[] suffix,
 372                                       byte[] initial,
 373                                       int[] length) {
 374         int numEntries = 1 << initCodeSize;
 375         for (int i = 0; i < numEntries; i++) {
 376             prefix[i] = -1;


 917             return theImage;
 918         }
 919         startPass(0);
 920 
 921         this.rowBuf = new byte[width];
 922 
 923         try {
 924             // Read and decode the image data, fill in theImage
 925             this.initCodeSize = stream.readUnsignedByte();
 926             // GIF allows max 8 bpp, so anything larger is bogus for the roots.
 927             if (this.initCodeSize < 1 || this.initCodeSize > 8) {
 928                 throw new IIOException("Bad code size:" + this.initCodeSize);
 929             }
 930 
 931             // Read first data block
 932             this.blockLength = stream.readUnsignedByte();
 933             int left = blockLength;
 934             int off = 0;
 935             while (left > 0) {
 936                 int nbytes = stream.read(block, off, left);
 937                 if (nbytes == -1 && left > 0) {
 938                     throw new IIOException("Invalid block length for " +
 939                             "LZW encoded image data");
 940                 }
 941                 left -= nbytes;
 942                 off += nbytes;
 943             }
 944 
 945             this.bitPos = 0;
 946             this.nextByte = 0;
 947             this.lastBlockFound = false;
 948             this.interlacePass = 0;
 949 
 950             // Init 32-bit buffer
 951             initNext32Bits();
 952 
 953             this.clearCode = 1 << initCodeSize;
 954             this.eofCode = clearCode + 1;
 955 
 956             int code, oldCode = 0;
 957 
 958             int[] prefix = new int[4096];
 959             byte[] suffix = new byte[4096];
 960             byte[] initial = new byte[4096];


< prev index next >