2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2021-07-27 01:12:53 +02:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
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>
|
2021-12-21 01:17:13 +01:00
|
|
|
#include <LibGfx/QOILoader.h>
|
2019-10-19 19:56:49 +02:00
|
|
|
|
2020-02-06 11:56:38 +01:00
|
|
|
namespace Gfx {
|
|
|
|
|
2021-07-27 01:12:53 +02:00
|
|
|
RefPtr<ImageDecoder> ImageDecoder::try_create(ReadonlyBytes bytes)
|
2019-10-19 19:56:49 +02:00
|
|
|
{
|
2021-07-27 01:12:53 +02:00
|
|
|
auto* data = bytes.data();
|
|
|
|
auto size = bytes.size();
|
2020-04-25 14:05:05 +01:00
|
|
|
|
2021-07-27 01:12:53 +02:00
|
|
|
auto plugin = [](auto* data, auto size) -> OwnPtr<ImageDecoderPlugin> {
|
|
|
|
OwnPtr<ImageDecoderPlugin> plugin;
|
2020-06-13 15:28:04 +02:00
|
|
|
|
2021-07-27 01:12:53 +02:00
|
|
|
plugin = make<PNGImageDecoderPlugin>(data, size);
|
|
|
|
if (plugin->sniff())
|
|
|
|
return plugin;
|
2020-06-17 12:37:16 -07:00
|
|
|
|
2021-07-27 01:12:53 +02:00
|
|
|
plugin = make<GIFImageDecoderPlugin>(data, size);
|
|
|
|
if (plugin->sniff())
|
|
|
|
return plugin;
|
2020-06-21 12:00:22 +03:00
|
|
|
|
2021-07-27 01:12:53 +02:00
|
|
|
plugin = make<BMPImageDecoderPlugin>(data, size);
|
|
|
|
if (plugin->sniff())
|
|
|
|
return plugin;
|
2020-06-22 15:19:57 +03:00
|
|
|
|
2021-07-27 01:12:53 +02:00
|
|
|
plugin = make<PBMImageDecoderPlugin>(data, size);
|
|
|
|
if (plugin->sniff())
|
|
|
|
return plugin;
|
2020-06-22 11:58:04 +03:00
|
|
|
|
2021-07-27 01:12:53 +02:00
|
|
|
plugin = make<PGMImageDecoderPlugin>(data, size);
|
|
|
|
if (plugin->sniff())
|
|
|
|
return plugin;
|
2020-06-15 21:36:05 -04:00
|
|
|
|
2021-07-27 01:12:53 +02:00
|
|
|
plugin = make<PPMImageDecoderPlugin>(data, size);
|
|
|
|
if (plugin->sniff())
|
|
|
|
return plugin;
|
2020-05-18 13:28:27 +05:30
|
|
|
|
2021-07-27 01:12:53 +02:00
|
|
|
plugin = make<ICOImageDecoderPlugin>(data, size);
|
|
|
|
if (plugin->sniff())
|
|
|
|
return plugin;
|
2021-05-15 17:02:40 +02:00
|
|
|
|
2021-07-27 01:12:53 +02:00
|
|
|
plugin = make<JPGImageDecoderPlugin>(data, size);
|
|
|
|
if (plugin->sniff())
|
|
|
|
return plugin;
|
|
|
|
|
|
|
|
plugin = make<DDSImageDecoderPlugin>(data, size);
|
|
|
|
if (plugin->sniff())
|
|
|
|
return plugin;
|
|
|
|
|
2021-12-21 01:17:13 +01:00
|
|
|
plugin = make<QOIImageDecoderPlugin>(data, size);
|
|
|
|
if (plugin->sniff())
|
|
|
|
return plugin;
|
|
|
|
|
2021-07-27 01:12:53 +02:00
|
|
|
return {};
|
|
|
|
}(data, size);
|
|
|
|
|
|
|
|
if (!plugin)
|
|
|
|
return {};
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ImageDecoder(plugin.release_nonnull()));
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageDecoder::ImageDecoder(NonnullOwnPtr<ImageDecoderPlugin> plugin)
|
|
|
|
: m_plugin(move(plugin))
|
|
|
|
{
|
2019-10-19 19:56:49 +02:00
|
|
|
}
|
|
|
|
|
2020-02-06 11:56:38 +01:00
|
|
|
}
|