1. /*
  2. * @(#)WBMPImageReaderSpi.java 1.6 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.wbmp;
  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 WBMPImageReaderSpi extends ImageReaderSpi {
  17. private static String [] writerSpiNames =
  18. {"com.sun.imageio.plugins.wbmp.WBMPImageWriterSpi"};
  19. private static String[] formatNames = {"wbmp", "WBMP"};
  20. private static String[] entensions = {"wbmp"};
  21. private static String[] mimeType = {"image/vnd.wap.wbmp"};
  22. private boolean registered = false;
  23. public WBMPImageReaderSpi() {
  24. super("Sun Microsystems, Inc.",
  25. "1.0",
  26. formatNames,
  27. entensions,
  28. mimeType,
  29. "com.sun.imageio.plugins.wbmp.WBMPImageReader",
  30. STANDARD_INPUT_TYPE,
  31. writerSpiNames,
  32. true,
  33. null, null, null, null,
  34. true,
  35. WBMPMetadata.nativeMetadataFormatName,
  36. "com.sun.imageio.plugins.wbmp.WBMPMetadataFormat",
  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 WBMP 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[3];
  55. stream.mark();
  56. stream.readFully(b);
  57. stream.reset();
  58. return ((b[0] == (byte)0) && // TypeField == 0
  59. b[1] == 0 && // FixHeaderField == 0xxx00000; not support ext header
  60. ((b[2] & 0x8f) != 0 || (b[2] & 0x7f) != 0)); // First width byte
  61. //XXX: b[2] & 0x8f) != 0 for the bug in Sony Ericsson encoder.
  62. }
  63. public ImageReader createReaderInstance(Object extension)
  64. throws IIOException {
  65. return new WBMPImageReader(this);
  66. }
  67. }