1. /*
  2. * @(#)BMPImageReaderSpi.java 1.5 04/05/05 05:42:00
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.imageio.plugins.bmp;
  8. import java.util.Locale;
  9. import javax.imageio.spi.ImageReaderSpi;
  10. import javax.imageio.stream.ImageInputStream;
  11. import javax.imageio.spi.IIORegistry;
  12. import javax.imageio.spi.ServiceRegistry;
  13. import java.io.IOException;
  14. import javax.imageio.ImageReader;
  15. import javax.imageio.IIOException;
  16. public class BMPImageReaderSpi extends ImageReaderSpi {
  17. private static String [] writerSpiNames =
  18. {"com.sun.imageio.plugins.bmp.BMPImageWriterSpi"};
  19. private static String[] formatNames = {"bmp", "BMP"};
  20. private static String[] entensions = {"bmp"};
  21. private static String[] mimeType = {"image/bmp"};
  22. private boolean registered = false;
  23. public BMPImageReaderSpi() {
  24. super("Sun Microsystems, Inc.",
  25. "1.0",
  26. formatNames,
  27. entensions,
  28. mimeType,
  29. "com.sun.imageio.plugins.bmp.BMPImageReader",
  30. STANDARD_INPUT_TYPE,
  31. writerSpiNames,
  32. false,
  33. null, null, null, null,
  34. true,
  35. BMPMetadata.nativeMetadataFormatName,
  36. "com.sun.imageio.plugins.bmp.BMPMetadataFormat",
  37. null, null);
  38. }
  39. public void onRegistration(ServiceRegistry registry,
  40. Class<?> category) {
  41. if (registered) {
  42. return;
  43. }
  44. registered = true;
  45. }
  46. public String getDescription(Locale locale) {
  47. return "Standard BMP Image Reader";
  48. }
  49. public boolean canDecodeInput(Object source) throws IOException {
  50. if (!(source instanceof ImageInputStream)) {
  51. return false;
  52. }
  53. ImageInputStream stream = (ImageInputStream)source;
  54. byte[] b = new byte[2];
  55. stream.mark();
  56. stream.readFully(b);
  57. stream.reset();
  58. return (b[0] == 0x42) && (b[1] == 0x4d);
  59. }
  60. public ImageReader createReaderInstance(Object extension)
  61. throws IIOException {
  62. return new BMPImageReader(this);
  63. }
  64. }