mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-17 09:20:28 +03:00
image: Support exporting GIF files
This commit is contained in:
parent
f43bf1086b
commit
cd486a7040
Notes:
sideshowbarker
2024-07-16 17:05:37 +09:00
Author: https://github.com/LucasChollet Commit: https://github.com/SerenityOS/serenity/commit/cd486a7040 Pull-request: https://github.com/SerenityOS/serenity/pull/24191 Reviewed-by: https://github.com/nico ✅ Reviewed-by: https://github.com/timschumi
@ -9,6 +9,7 @@
|
||||
#include <LibCore/MappedFile.h>
|
||||
#include <LibGfx/ICC/Profile.h>
|
||||
#include <LibGfx/ImageFormats/BMPWriter.h>
|
||||
#include <LibGfx/ImageFormats/GIFWriter.h>
|
||||
#include <LibGfx/ImageFormats/ImageDecoder.h>
|
||||
#include <LibGfx/ImageFormats/JPEGWriter.h>
|
||||
#include <LibGfx/ImageFormats/PNGWriter.h>
|
||||
@ -168,6 +169,10 @@ static ErrorOr<void> save_image(LoadedImage& image, StringView out_path, bool pp
|
||||
|
||||
auto& frame = image.bitmap.get<RefPtr<Gfx::Bitmap>>();
|
||||
|
||||
if (out_path.ends_with(".gif"sv, CaseSensitivity::CaseInsensitive)) {
|
||||
TRY(Gfx::GIFWriter::encode(*TRY(stream()), *frame));
|
||||
return {};
|
||||
}
|
||||
if (out_path.ends_with(".jpg"sv, CaseSensitivity::CaseInsensitive) || out_path.ends_with(".jpeg"sv, CaseSensitivity::CaseInsensitive)) {
|
||||
TRY(Gfx::JPEGWriter::encode(*TRY(stream()), *frame, { .icc_data = image.icc_data, .quality = jpeg_quality }));
|
||||
return {};
|
||||
@ -190,7 +195,7 @@ static ErrorOr<void> save_image(LoadedImage& image, StringView out_path, bool pp
|
||||
} else if (out_path.ends_with(".qoi"sv, CaseSensitivity::CaseInsensitive)) {
|
||||
bytes = TRY(Gfx::QOIWriter::encode(*frame));
|
||||
} else {
|
||||
return Error::from_string_view("can only write .bmp, .jpg, .png, .ppm, .qoi, and .webp"sv);
|
||||
return Error::from_string_view("can only write .bmp, .gif, .jpg, .png, .ppm, .qoi, and .webp"sv);
|
||||
}
|
||||
TRY(TRY(stream())->write_until_depleted(bytes));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user