1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 12:27:35 +00:00

LibGfx: Remove all load_FORMAT_from_memory() decoder wrappers

There are no more clients of these APIs, now that everyone has been made
to use ImageDecoderPlugin objects instead.
This commit is contained in:
Andreas Kling 2021-11-12 15:51:53 +01:00
parent 481e7b7971
commit 47edd6ae89
16 changed files with 2 additions and 146 deletions

View file

@ -6,6 +6,7 @@
#include <AK/Debug.h> #include <AK/Debug.h>
#include <AK/Function.h> #include <AK/Function.h>
#include <AK/String.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibGfx/BMPLoader.h> #include <LibGfx/BMPLoader.h>
@ -163,16 +164,6 @@ struct BMPLoadingContext {
} }
}; };
static RefPtr<Bitmap> load_bmp_impl(const u8*, size_t);
RefPtr<Gfx::Bitmap> load_bmp_from_memory(u8 const* data, size_t length, String const& mmap_name)
{
auto bitmap = load_bmp_impl(data, length);
if (bitmap)
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded BMP: {}", bitmap->size(), mmap_name));
return bitmap;
}
class InputStreamer { class InputStreamer {
public: public:
InputStreamer(const u8* data, size_t size) InputStreamer(const u8* data, size_t size)
@ -1308,21 +1299,6 @@ static bool decode_bmp_pixel_data(BMPLoadingContext& context)
return true; return true;
} }
static RefPtr<Bitmap> load_bmp_impl(const u8* data, size_t data_size)
{
BMPLoadingContext context;
context.file_bytes = data;
context.file_size = data_size;
// Forces a decode of the header, dib, and color table as well
if (!decode_bmp_pixel_data(context)) {
context.state = BMPLoadingContext::State::Error;
return nullptr;
}
return context.bitmap;
}
BMPImageDecoderPlugin::BMPImageDecoderPlugin(const u8* data, size_t data_size) BMPImageDecoderPlugin::BMPImageDecoderPlugin(const u8* data, size_t data_size)
{ {
m_context = make<BMPLoadingContext>(); m_context = make<BMPLoadingContext>();

View file

@ -6,14 +6,10 @@
#pragma once #pragma once
#include <AK/String.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/ImageDecoder.h> #include <LibGfx/ImageDecoder.h>
namespace Gfx { namespace Gfx {
RefPtr<Gfx::Bitmap> load_bmp_from_memory(u8 const*, size_t, String const& mmap_name = "<memory>");
struct BMPLoadingContext; struct BMPLoadingContext;
class BMPImageDecoderPlugin final : public ImageDecoderPlugin { class BMPImageDecoderPlugin final : public ImageDecoderPlugin {

View file

@ -7,6 +7,7 @@
#include <AK/Debug.h> #include <AK/Debug.h>
#include <AK/Endian.h> #include <AK/Endian.h>
#include <AK/MemoryStream.h> #include <AK/MemoryStream.h>
#include <AK/String.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibGfx/DDSLoader.h> #include <LibGfx/DDSLoader.h>
@ -936,26 +937,6 @@ void DDSLoadingContext::dump_debug()
dbgln("{}", builder.to_string()); dbgln("{}", builder.to_string());
} }
static RefPtr<Gfx::Bitmap> load_dds_impl(const u8* data, size_t length)
{
DDSLoadingContext context;
context.data = data;
context.data_size = length;
if (!decode_dds(context))
return nullptr;
return context.bitmap;
}
RefPtr<Gfx::Bitmap> load_dds_from_memory(u8 const* data, size_t length, String const& mmap_name)
{
auto bitmap = load_dds_impl(data, length);
if (bitmap)
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded DDS: {}", bitmap->size(), mmap_name));
return bitmap;
}
DDSImageDecoderPlugin::DDSImageDecoderPlugin(const u8* data, size_t size) DDSImageDecoderPlugin::DDSImageDecoderPlugin(const u8* data, size_t size)
{ {
m_context = make<DDSLoadingContext>(); m_context = make<DDSLoadingContext>();

View file

@ -6,8 +6,6 @@
#pragma once #pragma once
#include <AK/String.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/ImageDecoder.h> #include <LibGfx/ImageDecoder.h>
namespace Gfx { namespace Gfx {
@ -233,8 +231,6 @@ struct DDSHeaderDXT10 {
u32 misc_flag2 {}; u32 misc_flag2 {};
}; };
RefPtr<Gfx::Bitmap> load_dds_from_memory(u8 const*, size_t, String const& mmap_name = "<memory>");
struct DDSLoadingContext; struct DDSLoadingContext;
class DDSImageDecoderPlugin final : public ImageDecoderPlugin { class DDSImageDecoderPlugin final : public ImageDecoderPlugin {

View file

@ -89,15 +89,6 @@ struct ICOLoadingContext {
size_t largest_index; size_t largest_index;
}; };
RefPtr<Gfx::Bitmap> load_ico_from_memory(u8 const* data, size_t length, String const& mmap_name)
{
ICOImageDecoderPlugin decoder(data, length);
auto bitmap = decoder.bitmap();
if (bitmap)
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded ICO: {}", bitmap->size(), mmap_name));
return bitmap;
}
static Optional<size_t> decode_ico_header(InputMemoryStream& stream) static Optional<size_t> decode_ico_header(InputMemoryStream& stream)
{ {
ICONDIR header; ICONDIR header;

View file

@ -6,14 +6,10 @@
#pragma once #pragma once
#include <AK/String.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/ImageDecoder.h> #include <LibGfx/ImageDecoder.h>
namespace Gfx { namespace Gfx {
RefPtr<Gfx::Bitmap> load_ico_from_memory(u8 const*, size_t, String const& mmap_name = "<memory>");
struct ICOLoadingContext; struct ICOLoadingContext;
class ICOImageDecoderPlugin final : public ImageDecoderPlugin { class ICOImageDecoderPlugin final : public ImageDecoderPlugin {

View file

@ -4,15 +4,11 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <AK/Bitmap.h>
#include <AK/ByteBuffer.h>
#include <AK/Debug.h> #include <AK/Debug.h>
#include <AK/HashMap.h> #include <AK/HashMap.h>
#include <AK/Math.h> #include <AK/Math.h>
#include <AK/MemoryStream.h> #include <AK/MemoryStream.h>
#include <AK/String.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/JPGLoader.h> #include <LibGfx/JPGLoader.h>
#define JPG_INVALID 0X0000 #define JPG_INVALID 0X0000
@ -1222,26 +1218,6 @@ static bool decode_jpg(JPGLoadingContext& context)
return true; return true;
} }
static RefPtr<Gfx::Bitmap> load_jpg_impl(const u8* data, size_t data_size)
{
JPGLoadingContext context;
context.data = data;
context.data_size = data_size;
if (!decode_jpg(context))
return nullptr;
return context.bitmap;
}
RefPtr<Gfx::Bitmap> load_jpg_from_memory(u8 const* data, size_t length, String const& mmap_name)
{
auto bitmap = load_jpg_impl(data, length);
if (bitmap)
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded jpg: {}", bitmap->size(), mmap_name));
return bitmap;
}
JPGImageDecoderPlugin::JPGImageDecoderPlugin(const u8* data, size_t size) JPGImageDecoderPlugin::JPGImageDecoderPlugin(const u8* data, size_t size)
{ {
m_context = make<JPGLoadingContext>(); m_context = make<JPGLoadingContext>();

View file

@ -6,13 +6,10 @@
#pragma once #pragma once
#include <AK/String.h>
#include <LibGfx/ImageDecoder.h> #include <LibGfx/ImageDecoder.h>
namespace Gfx { namespace Gfx {
RefPtr<Gfx::Bitmap> load_jpg_from_memory(u8 const* data, size_t length, String const& mmap_name = "<memory>");
struct JPGLoadingContext; struct JPGLoadingContext;
class JPGImageDecoderPlugin : public ImageDecoderPlugin { class JPGImageDecoderPlugin : public ImageDecoderPlugin {

View file

@ -94,11 +94,6 @@ static bool read_image_data(PBMLoadingContext& context, Streamer& streamer)
return true; return true;
} }
RefPtr<Gfx::Bitmap> load_pbm_from_memory(u8 const* data, size_t length, String const& mmap_name)
{
return load_from_memory<PBMLoadingContext>(data, length, mmap_name);
}
PBMImageDecoderPlugin::PBMImageDecoderPlugin(const u8* data, size_t size) PBMImageDecoderPlugin::PBMImageDecoderPlugin(const u8* data, size_t size)
{ {
m_context = make<PBMLoadingContext>(); m_context = make<PBMLoadingContext>();

View file

@ -6,13 +6,10 @@
#pragma once #pragma once
#include <AK/String.h>
#include <LibGfx/ImageDecoder.h> #include <LibGfx/ImageDecoder.h>
namespace Gfx { namespace Gfx {
RefPtr<Gfx::Bitmap> load_pbm_from_memory(u8 const*, size_t, String const& mmap_name = "<memory>");
struct PBMLoadingContext; struct PBMLoadingContext;
class PBMImageDecoderPlugin final : public ImageDecoderPlugin { class PBMImageDecoderPlugin final : public ImageDecoderPlugin {

View file

@ -97,11 +97,6 @@ static bool read_image_data(PGMLoadingContext& context, Streamer& streamer)
return true; return true;
} }
RefPtr<Gfx::Bitmap> load_pgm_from_memory(u8 const* data, size_t length, String const& mmap_name)
{
return load_from_memory<PGMLoadingContext>(data, length, mmap_name);
}
PGMImageDecoderPlugin::PGMImageDecoderPlugin(const u8* data, size_t size) PGMImageDecoderPlugin::PGMImageDecoderPlugin(const u8* data, size_t size)
{ {
m_context = make<PGMLoadingContext>(); m_context = make<PGMLoadingContext>();

View file

@ -6,14 +6,10 @@
#pragma once #pragma once
#include <AK/String.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/ImageDecoder.h> #include <LibGfx/ImageDecoder.h>
namespace Gfx { namespace Gfx {
RefPtr<Gfx::Bitmap> load_pgm_from_memory(u8 const*, size_t, String const& mmap_name = "<memory>");
struct PGMLoadingContext; struct PGMLoadingContext;
class PGMImageDecoderPlugin final : public ImageDecoderPlugin { class PGMImageDecoderPlugin final : public ImageDecoderPlugin {

View file

@ -165,17 +165,8 @@ private:
size_t m_size_remaining { 0 }; size_t m_size_remaining { 0 };
}; };
static RefPtr<Gfx::Bitmap> load_png_impl(const u8*, size_t);
static bool process_chunk(Streamer&, PNGLoadingContext& context); static bool process_chunk(Streamer&, PNGLoadingContext& context);
RefPtr<Gfx::Bitmap> load_png_from_memory(u8 const* data, size_t length, String const& mmap_name)
{
auto bitmap = load_png_impl(data, length);
if (bitmap)
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded PNG: {}", bitmap->size(), mmap_name));
return bitmap;
}
ALWAYS_INLINE static u8 paeth_predictor(int a, int b, int c) ALWAYS_INLINE static u8 paeth_predictor(int a, int b, int c)
{ {
int p = a + b - c; int p = a + b - c;
@ -775,21 +766,6 @@ static bool decode_png_bitmap(PNGLoadingContext& context)
return true; return true;
} }
static RefPtr<Gfx::Bitmap> load_png_impl(const u8* data, size_t data_size)
{
PNGLoadingContext context;
context.data = data;
context.data_size = data_size;
if (!decode_png_chunks(context))
return nullptr;
if (!decode_png_bitmap(context))
return nullptr;
return context.bitmap;
}
static bool is_valid_compression_method(u8 compression_method) static bool is_valid_compression_method(u8 compression_method)
{ {
return compression_method == 0; return compression_method == 0;

View file

@ -6,13 +6,10 @@
#pragma once #pragma once
#include <AK/String.h>
#include <LibGfx/ImageDecoder.h> #include <LibGfx/ImageDecoder.h>
namespace Gfx { namespace Gfx {
RefPtr<Gfx::Bitmap> load_png_from_memory(u8 const*, size_t, String const& mmap_name = "<memory>");
struct PNGLoadingContext; struct PNGLoadingContext;
class PNGImageDecoderPlugin final : public ImageDecoderPlugin { class PNGImageDecoderPlugin final : public ImageDecoderPlugin {

View file

@ -101,11 +101,6 @@ static bool read_image_data(PPMLoadingContext& context, Streamer& streamer)
return true; return true;
} }
RefPtr<Gfx::Bitmap> load_ppm_from_memory(u8 const* data, size_t length, String const& mmap_name)
{
return load_from_memory<PPMLoadingContext>(data, length, mmap_name);
}
PPMImageDecoderPlugin::PPMImageDecoderPlugin(const u8* data, size_t size) PPMImageDecoderPlugin::PPMImageDecoderPlugin(const u8* data, size_t size)
{ {
m_context = make<PPMLoadingContext>(); m_context = make<PPMLoadingContext>();

View file

@ -6,14 +6,10 @@
#pragma once #pragma once
#include <AK/String.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/ImageDecoder.h> #include <LibGfx/ImageDecoder.h>
namespace Gfx { namespace Gfx {
RefPtr<Gfx::Bitmap> load_ppm_from_memory(u8 const*, size_t, String const& mmap_name = "<memory>");
struct PPMLoadingContext; struct PPMLoadingContext;
class PPMImageDecoderPlugin final : public ImageDecoderPlugin { class PPMImageDecoderPlugin final : public ImageDecoderPlugin {