PixelPaint: Guess image type based on its filename

We do this in ImageViewer so it understands TGA images; let's do it in
PixelPaint as well :^)
This commit is contained in:
Jelle Raaijmakers 2023-08-08 20:22:54 +02:00 committed by Daniel Bertalan
commit 1c19c2bc92
Notes: sideshowbarker 2024-07-16 21:39:23 +09:00
5 changed files with 13 additions and 9 deletions

View file

@ -8,20 +8,22 @@
#include "Image.h"
#include "Layer.h"
#include <AK/JsonObject.h>
#include <LibCore/MimeData.h>
#include <LibImageDecoderClient/Client.h>
namespace PixelPaint {
ErrorOr<void> ProjectLoader::load_from_file(NonnullOwnPtr<Core::File> file)
ErrorOr<void> ProjectLoader::load_from_file(StringView filename, NonnullOwnPtr<Core::File> file)
{
auto contents = TRY(file->read_until_eof());
auto json_or_error = JsonValue::from_string(contents);
if (json_or_error.is_error()) {
m_is_raw_image = true;
auto guessed_mime_type = Core::guess_mime_type_based_on_filename(filename);
// FIXME: Find a way to avoid the memory copy here.
auto bitmap = TRY(Image::decode_bitmap(contents));
auto bitmap = TRY(Image::decode_bitmap(contents, guessed_mime_type));
auto image = TRY(Image::create_from_bitmap(move(bitmap)));
m_image = image;