mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:27:43 +00:00
image: Allow saving CMYK jpegs
`image` can't transform from RGB to CMYK yet, so the only way to do this is by having a CMYK input. For example, this works now (and it does a full decode and re-encode): Build/lagom/bin/image -o out.jpg \ Tests/LibGfx/test-inputs/jpg/buggie-cmyk.jpg Using this to convert `.pam` files written by `mutool extract` to jpegs is a somewhat convenient method of looking at these .pam files.
This commit is contained in:
parent
2298aac1d1
commit
6dc5608d95
1 changed files with 13 additions and 4 deletions
|
@ -125,15 +125,24 @@ static ErrorOr<OwnPtr<Core::MappedFile>> convert_image_profile(LoadedImage& imag
|
|||
|
||||
static ErrorOr<void> save_image(LoadedImage& image, StringView out_path, bool ppm_ascii, u8 jpeg_quality)
|
||||
{
|
||||
if (!image.bitmap.has<RefPtr<Gfx::Bitmap>>())
|
||||
return Error::from_string_view("Can't save CMYK bitmaps yet, convert to RGB first with --convert-to-color-profile"sv);
|
||||
auto& frame = image.bitmap.get<RefPtr<Gfx::Bitmap>>();
|
||||
|
||||
auto stream = [out_path]() -> ErrorOr<NonnullOwnPtr<Core::OutputBufferedFile>> {
|
||||
auto output_stream = TRY(Core::File::open(out_path, Core::File::OpenMode::Write));
|
||||
return Core::OutputBufferedFile::create(move(output_stream));
|
||||
};
|
||||
|
||||
if (image.bitmap.has<RefPtr<Gfx::CMYKBitmap>>()) {
|
||||
auto& cmyk_frame = image.bitmap.get<RefPtr<Gfx::CMYKBitmap>>();
|
||||
|
||||
if (out_path.ends_with(".jpg"sv, CaseSensitivity::CaseInsensitive) || out_path.ends_with(".jpeg"sv, CaseSensitivity::CaseInsensitive)) {
|
||||
TRY(Gfx::JPEGWriter::encode(*TRY(stream()), *cmyk_frame, { .icc_data = image.icc_data, .quality = jpeg_quality }));
|
||||
return {};
|
||||
}
|
||||
|
||||
return Error::from_string_view("Can save CMYK bitmaps only as .jpg, convert to RGB first with --convert-to-color-profile"sv);
|
||||
}
|
||||
|
||||
auto& frame = image.bitmap.get<RefPtr<Gfx::Bitmap>>();
|
||||
|
||||
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 {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue