ImageDecoder.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include <LibGfx/BMPLoader.h>
  27. #include <LibGfx/GIFLoader.h>
  28. #include <LibGfx/ICOLoader.h>
  29. #include <LibGfx/ImageDecoder.h>
  30. #include <LibGfx/JPGLoader.h>
  31. #include <LibGfx/PBMLoader.h>
  32. #include <LibGfx/PNGLoader.h>
  33. #include <LibGfx/PPMLoader.h>
  34. namespace Gfx {
  35. ImageDecoder::ImageDecoder(const u8* data, size_t size)
  36. {
  37. m_plugin = make<PNGImageDecoderPlugin>(data, size);
  38. if (m_plugin->sniff())
  39. return;
  40. m_plugin = make<GIFImageDecoderPlugin>(data, size);
  41. if (m_plugin->sniff())
  42. return;
  43. m_plugin = make<BMPImageDecoderPlugin>(data, size);
  44. if (m_plugin->sniff())
  45. return;
  46. m_plugin = make<PBMImageDecoderPlugin>(data, size);
  47. if (m_plugin->sniff())
  48. return;
  49. m_plugin = make<PPMImageDecoderPlugin>(data, size);
  50. if (m_plugin->sniff())
  51. return;
  52. m_plugin = make<ICOImageDecoderPlugin>(data, size);
  53. if (m_plugin->sniff())
  54. return;
  55. m_plugin = make<JPGImageDecoderPlugin>(data, size);
  56. if (m_plugin->sniff())
  57. return;
  58. m_plugin = nullptr;
  59. }
  60. ImageDecoder::~ImageDecoder()
  61. {
  62. }
  63. RefPtr<Gfx::Bitmap> ImageDecoder::bitmap() const
  64. {
  65. if (!m_plugin)
  66. return nullptr;
  67. return m_plugin->bitmap();
  68. }
  69. }