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 23 * questions. 24 */ 25 package com.sun.imageio.plugins.tiff; 26 27 import java.io.IOException; 28 29 public class TIFFLSBDecompressor extends TIFFDecompressor { 30 31 /** 32 * Table for flipping bytes from LSB-to-MSB to MSB-to-LSB. 33 */ 34 private static final byte[] flipTable = TIFFFaxDecompressor.flipTable; 35 TIFFLSBDecompressor()36 public TIFFLSBDecompressor() {} 37 decodeRaw(byte[] b, int dstOffset, int bitsPerPixel, int scanlineStride)38 public void decodeRaw(byte[] b, 39 int dstOffset, 40 int bitsPerPixel, 41 int scanlineStride) throws IOException { 42 stream.seek(offset); 43 44 int bytesPerRow = (srcWidth*bitsPerPixel + 7)/8; 45 if(bytesPerRow == scanlineStride) { 46 int numBytes = bytesPerRow*srcHeight; 47 stream.readFully(b, dstOffset, numBytes); 48 int xMax = dstOffset + numBytes; 49 for (int x = dstOffset; x < xMax; x++) { 50 b[x] = flipTable[b[x]&0xff]; 51 } 52 } else { 53 for (int y = 0; y < srcHeight; y++) { 54 stream.readFully(b, dstOffset, bytesPerRow); 55 int xMax = dstOffset + bytesPerRow; 56 for (int x = dstOffset; x < xMax; x++) { 57 b[x] = flipTable[b[x]&0xff]; 58 } 59 dstOffset += scanlineStride; 60 } 61 } 62 } 63 } 64