1. /*
  2. * @(#)BMPImageWriteParam.java 1.4 04/01/06
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.imageio.plugins.bmp;
  8. import java.util.Locale;
  9. import javax.imageio.ImageWriteParam;
  10. import com.sun.imageio.plugins.bmp.BMPConstants;
  11. /**
  12. * A subclass of <code>ImageWriteParam</code> for encoding images in
  13. * the BMP format.
  14. *
  15. * <p> This class allows for the specification of various parameters
  16. * while writing a BMP format image file. By default, the data layout
  17. * is bottom-up, such that the pixels are stored in bottom-up order,
  18. * the first scanline being stored last.
  19. *
  20. * <p>The particular compression scheme to be used can be specified by using
  21. * the <code>setCompressionType()</code> method with the appropriate type
  22. * string. The compression scheme specified will be honored if and only if it
  23. * is compatible with the type of image being written. If the specified
  24. * compression scheme is not compatible with the type of image being written
  25. * then the <code>IOException</code> will be thrown by the BMP image writer.
  26. * If the compression type is not set explicitly then <code>getCompressionType()</code>
  27. * will return <code>null</code>. In this case the BMP image writer will select
  28. * a compression type that supports encoding of the given image without loss
  29. * of the color resolution.
  30. * <p>The compression type strings and the image type(s) each supports are
  31. * listed in the following
  32. * table:
  33. *
  34. * <p><table border=1>
  35. * <caption><b>Compression Types</b></caption>
  36. * <tr><th>Type String</th> <th>Description</th> <th>Image Types</th></tr>
  37. * <tr><td>BI_RGB</td> <td>Uncompressed RLE</td> <td><= 8-bits/sample</td></tr>
  38. * <tr><td>BI_RLE8</td> <td>8-bit Run Length Encoding</td> <td><= 8-bits/sample</td></tr>
  39. * <tr><td>BI_RLE4</td> <td>4-bit Run Length Encoding</td> <td><= 4-bits/sample</td></tr>
  40. * <tr><td>BI_BITFIELDS</td> <td>Packed data</td> <td> 16 or 32 bits/sample</td></tr>
  41. * </table>
  42. */
  43. public class BMPImageWriteParam extends ImageWriteParam {
  44. private boolean topDown = false;
  45. /**
  46. * Constructs a <code>BMPImageWriteParam</code> set to use a given
  47. * <code>Locale</code> and with default values for all parameters.
  48. *
  49. * @param locale a <code>Locale</code> to be used to localize
  50. * compression type names and quality descriptions, or
  51. * <code>null</code>.
  52. */
  53. public BMPImageWriteParam(Locale locale) {
  54. super(locale);
  55. // Set compression types ("BI_RGB" denotes uncompressed).
  56. compressionTypes = BMPConstants.compressionTypeNames;
  57. // Set compression flag.
  58. canWriteCompressed = true;
  59. compressionMode = MODE_COPY_FROM_METADATA;
  60. compressionType = compressionTypes[BMPConstants.BI_RGB];
  61. }
  62. /**
  63. * Constructs an <code>BMPImageWriteParam</code> object with default
  64. * values for all parameters and a <code>null</code> <code>Locale</code>.
  65. */
  66. public BMPImageWriteParam() {
  67. this(null);
  68. }
  69. /**
  70. * If set, the data will be written out in a top-down manner, the first
  71. * scanline being written first.
  72. *
  73. * @param topDown whether the data are written in top-down order.
  74. */
  75. public void setTopDown(boolean topDown) {
  76. this.topDown = topDown;
  77. }
  78. /**
  79. * Returns the value of the <code>topDown</code> parameter.
  80. * The default is <code>false</code>.
  81. *
  82. * @return whether the data are written in top-down order.
  83. */
  84. public boolean isTopDown() {
  85. return topDown;
  86. }
  87. }