< prev index next >

src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFDeflateDecompressor.java

Print this page


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


  84             buf = new byte[bytesPerRow*srcHeight];
  85             bufOffset = 0;
  86         }
  87 
  88         // Set the input to the Inflater.
  89         inflater.setInput(srcData);
  90 
  91         // Inflate the data.
  92         try {
  93             inflater.inflate(buf, bufOffset, bytesPerRow*srcHeight);
  94         } catch(DataFormatException dfe) {
  95             throw new IIOException("Error inflating data",
  96                                    dfe);
  97         }
  98 
  99         // Reset the Inflater.
 100         inflater.reset();
 101 
 102         if (predictor ==
 103             BaselineTIFFTagSet.PREDICTOR_HORIZONTAL_DIFFERENCING) {


 104 

 105             for (int j = 0; j < srcHeight; j++) {
 106                 int count = bufOffset + samplesPerPixel * (j * srcWidth + 1);
 107                 for (int i=samplesPerPixel; i<srcWidth*samplesPerPixel; i++) {
 108                     buf[count] += buf[count - samplesPerPixel];
 109                     count++;
 110                 }

 111             }
 112         }
 113 
 114         if(bytesPerRow != scanlineStride) {
 115             int off = 0;
 116             for (int y = 0; y < srcHeight; y++) {
 117                 System.arraycopy(buf, off, b, dstOffset, bytesPerRow);
 118                 off += bytesPerRow;
 119                 dstOffset += scanlineStride;
 120             }
 121         }
 122     }
 123 }
   1 /*
   2  * Copyright (c) 2005, 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


  84             buf = new byte[bytesPerRow*srcHeight];
  85             bufOffset = 0;
  86         }
  87 
  88         // Set the input to the Inflater.
  89         inflater.setInput(srcData);
  90 
  91         // Inflate the data.
  92         try {
  93             inflater.inflate(buf, bufOffset, bytesPerRow*srcHeight);
  94         } catch(DataFormatException dfe) {
  95             throw new IIOException("Error inflating data",
  96                                    dfe);
  97         }
  98 
  99         // Reset the Inflater.
 100         inflater.reset();
 101 
 102         if (predictor ==
 103             BaselineTIFFTagSet.PREDICTOR_HORIZONTAL_DIFFERENCING) {
 104             int step = planar || samplesPerPixel == 1 ? 1 : samplesPerPixel;
 105             int samplesPerRow = step * srcWidth;
 106 
 107             int off = bufOffset + step;
 108             for (int j = 0; j < srcHeight; j++) {
 109                 int count = off;
 110                 for (int i = step; i < samplesPerRow; i++) {
 111                     buf[count] += buf[count - step];
 112                     count++;
 113                 }
 114                 off += samplesPerRow;
 115             }
 116         }
 117 
 118         if(bytesPerRow != scanlineStride) {
 119             int off = 0;
 120             for (int y = 0; y < srcHeight; y++) {
 121                 System.arraycopy(buf, off, b, dstOffset, bytesPerRow);
 122                 off += bytesPerRow;
 123                 dstOffset += scanlineStride;
 124             }
 125         }
 126     }
 127 }
< prev index next >