2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2020-06-17 12:37:16 -07:00
|
|
|
#include <LibGfx/BMPLoader.h>
|
2021-05-15 17:02:40 +02:00
|
|
|
#include <LibGfx/DDSLoader.h>
|
2020-04-25 14:05:05 +01:00
|
|
|
#include <LibGfx/GIFLoader.h>
|
2020-06-15 21:36:05 -04:00
|
|
|
#include <LibGfx/ICOLoader.h>
|
2020-06-22 11:58:04 +03:00
|
|
|
#include <LibGfx/ImageDecoder.h>
|
2020-05-18 13:28:27 +05:30
|
|
|
#include <LibGfx/JPGLoader.h>
|
2020-06-21 12:00:22 +03:00
|
|
|
#include <LibGfx/PBMLoader.h>
|
2020-06-22 15:19:57 +03:00
|
|
|
#include <LibGfx/PGMLoader.h>
|
2020-02-06 12:04:00 +01:00
|
|
|
#include <LibGfx/PNGLoader.h>
|
2020-06-22 11:58:04 +03:00
|
|
|
#include <LibGfx/PPMLoader.h>
|
2019-10-19 19:56:49 +02:00
|
|
|
|
2020-02-06 11:56:38 +01:00
|
|
|
namespace Gfx {
|
|
|
|
|
2019-10-19 19:56:49 +02:00
|
|
|
ImageDecoder::ImageDecoder(const u8* data, size_t size)
|
|
|
|
{
|
|
|
|
m_plugin = make<PNGImageDecoderPlugin>(data, size);
|
2020-06-13 15:28:04 +02:00
|
|
|
if (m_plugin->sniff())
|
2020-04-25 14:05:05 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
m_plugin = make<GIFImageDecoderPlugin>(data, size);
|
2020-06-13 15:28:04 +02:00
|
|
|
if (m_plugin->sniff())
|
2020-04-25 14:05:05 +01:00
|
|
|
return;
|
2020-06-13 15:28:04 +02:00
|
|
|
|
2020-06-17 12:37:16 -07:00
|
|
|
m_plugin = make<BMPImageDecoderPlugin>(data, size);
|
|
|
|
if (m_plugin->sniff())
|
|
|
|
return;
|
|
|
|
|
2020-06-21 12:00:22 +03:00
|
|
|
m_plugin = make<PBMImageDecoderPlugin>(data, size);
|
|
|
|
if (m_plugin->sniff())
|
|
|
|
return;
|
|
|
|
|
2020-06-22 15:19:57 +03:00
|
|
|
m_plugin = make<PGMImageDecoderPlugin>(data, size);
|
|
|
|
if (m_plugin->sniff())
|
|
|
|
return;
|
|
|
|
|
2020-06-22 11:58:04 +03:00
|
|
|
m_plugin = make<PPMImageDecoderPlugin>(data, size);
|
|
|
|
if (m_plugin->sniff())
|
|
|
|
return;
|
|
|
|
|
2020-06-15 21:36:05 -04:00
|
|
|
m_plugin = make<ICOImageDecoderPlugin>(data, size);
|
|
|
|
if (m_plugin->sniff())
|
|
|
|
return;
|
|
|
|
|
2020-05-18 13:28:27 +05:30
|
|
|
m_plugin = make<JPGImageDecoderPlugin>(data, size);
|
|
|
|
if (m_plugin->sniff())
|
|
|
|
return;
|
|
|
|
|
2021-05-15 17:02:40 +02:00
|
|
|
m_plugin = make<DDSImageDecoderPlugin>(data, size);
|
|
|
|
if (m_plugin->sniff())
|
|
|
|
return;
|
|
|
|
|
2020-06-13 15:28:04 +02:00
|
|
|
m_plugin = nullptr;
|
2019-10-19 19:56:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ImageDecoder::~ImageDecoder()
|
|
|
|
{
|
|
|
|
}
|
2020-02-15 00:58:14 +01:00
|
|
|
|
|
|
|
RefPtr<Gfx::Bitmap> ImageDecoder::bitmap() const
|
|
|
|
{
|
2020-06-13 15:28:04 +02:00
|
|
|
if (!m_plugin)
|
|
|
|
return nullptr;
|
2020-02-15 00:58:14 +01:00
|
|
|
return m_plugin->bitmap();
|
|
|
|
}
|
|
|
|
|
2020-02-06 11:56:38 +01:00
|
|
|
}
|