1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 /* $Id$ */ 19 20 package org.apache.fop.render.bitmap; 21 22 import java.awt.image.BufferedImage; 23 24 /** 25 * Compression constants for TIFF image output. 26 */ 27 public enum TIFFCompressionValue { 28 /** No compression */ 29 NONE("NONE"), 30 /** JPEG compression */ 31 JPEG("JPEG"), 32 /** Packbits (RLE) compression */ 33 PACKBITS("PackBits"), 34 /** Deflate compression */ 35 DEFLATE("Deflate"), 36 /** LZW compression */ 37 LZW("LZW"), 38 /** ZLib compression */ 39 ZLIB("ZLib"), 40 /** CCITT Group 3 (T.4) compression */ 41 CCITT_T4("CCITT T.4", BufferedImage.TYPE_BYTE_BINARY, true), 42 /** CCITT Group 4 (T.6) compression */ 43 CCITT_T6("CCITT T.6", BufferedImage.TYPE_BYTE_BINARY, true); 44 45 private final String name; 46 private final int imageType; 47 private boolean isCcitt; 48 TIFFCompressionValue(String name, int imageType, boolean isCcitt)49 private TIFFCompressionValue(String name, int imageType, boolean isCcitt) { 50 this.name = name; 51 this.imageType = imageType; 52 this.isCcitt = isCcitt; 53 } 54 TIFFCompressionValue(String name)55 private TIFFCompressionValue(String name) { 56 this(name, BufferedImage.TYPE_INT_ARGB, false); 57 } 58 59 /** 60 * Returns the name of this compression type. 61 * @return the compression name 62 */ getName()63 String getName() { 64 return name; 65 } 66 67 /** 68 * Returns an image type for this compression type, a constant from {@link BufferedImage} e.g. 69 * {@link BufferedImage#TYPE_INT_ARGB} for {@link #ZLIB} 70 * @return the image type 71 */ getImageType()72 int getImageType() { 73 return imageType; 74 } 75 76 /** 77 * Returns whether or not this compression type is a CCITT type. 78 * @return true if the compression type is CCITT 79 */ hasCCITTCompression()80 boolean hasCCITTCompression() { 81 return isCcitt; 82 } 83 84 /** 85 * Return the TIFF compression constant given the string representing the type. In the case that 86 * the name doesn't match any of the compression values, <code>null</code> is returned. 87 * @param name the compression type name 88 * @return the compression constant 89 */ getType(String name)90 static TIFFCompressionValue getType(String name) { 91 for (TIFFCompressionValue tiffConst : TIFFCompressionValue.values()) { 92 if (tiffConst.name.equalsIgnoreCase(name)) { 93 return tiffConst; 94 } 95 } 96 return null; 97 } 98 } 99