001/* BMPImageWriteParam.java --
002   Copyright (C) 2006 Free Software Foundation, Inc.
003
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038
039package javax.imageio.plugins.bmp;
040
041import java.util.Locale;
042
043import javax.imageio.ImageWriteParam;
044
045/**
046 * A class to encode images in the BMP format.
047 * By default, the data layout is bottom-up, such that the pixels are stored in
048 * bottom-up order.
049 *
050 * The compression scheme can be specified by using setCompressionType()
051 * appropriate type string. The compression scheme specified will be honored
052 * if it is compatible with the type of image being written. If the
053 * compression scheme is not compatible with the type of image being written,
054 * then an IOException will be thrown by the BMP image writer. If the
055 * compression type is not set, then getCompressionType() will return null.
056 * In this case the BMP image writer will select a compression type that
057 * supports encoding of the given image without loss of the color resolution.
058 *
059 * The compression type strings and the image type each supports are:
060 * Uncompressed RLE: BI_RGB, image type: <= 8-bits/sample.
061 * 8-bit Run Length Encoding: BI_RLE8, image type: <= 8-bits/sample
062 * 4-bit Run Length Encoding: BI_RLE4, image type: <= 4-bits/sample
063 * Packed data: BI_BITFIELDS, image type: 16 or 32 bits/sample
064 *
065 * @author Lillian Angel (langel at redhat dot com)
066 */
067public class BMPImageWriteParam
068    extends ImageWriteParam
069{
070
071  /**
072   * This boolean is true if the data will be written in a topdown manner.
073   */
074  private boolean topDown;
075
076  /**
077   * Compression type strings.
078   */
079  String rgb = "BI_RGB";
080  String rle8 = "BI_RLE8";
081  String rle4 = "BI_RLE4";
082  String bitfields = "BI_BITFIELDS";
083
084  /**
085   * Constants to represent image types.
086   */
087  static final int BI_RGB = 0;
088  static final int BI_RLE8 = 1;
089  static final int BI_RLE4 = 2;
090  static final int BI_BITFIELDS = 3;
091
092  /**
093   * Constructs an <code>BMPImageWriteParam</code> object with default values
094   * and a <code>null Locale</code>.
095   */
096  public BMPImageWriteParam()
097  {
098    this(null);
099  }
100
101  /**
102   * Constructs a <code>BMPImageWriteParam</code> set to use a given
103   * <code>Locale</code> and with default values for all parameters.
104   *
105   * @param locale - a <code>Locale</code> to be used to localize compression
106   *          type names and quality descriptions, or <code>null</code>.
107   */
108  public BMPImageWriteParam(Locale locale)
109  {
110    super(locale);
111    topDown = false;
112    canWriteCompressed = true;
113
114    compressionTypes = new String[4];
115    compressionTypes[BI_RGB] = rgb;
116    compressionTypes[BI_RLE8] = rle8;
117    compressionTypes[BI_RLE4] = rle4;
118    compressionTypes[BI_BITFIELDS] = bitfields;
119
120    compressionType = compressionTypes[BI_RGB];
121  }
122
123  /**
124   * If set, the data will be written out in a top-down manner, the first
125   * scanline being written first.
126   *
127   * @param topDown - whether the data are written in top-down order.
128   */
129  public void setTopDown(boolean topDown)
130  {
131    this.topDown = topDown;
132  }
133
134  /**
135   * Returns the value of the <code>topDown</code> parameter. The default is
136   * false.
137   *
138   * @return whether the data are written in top-down order.
139   */
140  public boolean isTopDown()
141  {
142    return topDown;
143  }
144}