mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 15:32:38 +00:00
Don't crash when saving palettes to .jpg format (fix #2654)
Now .jpg is not even show in the list of available format to save palettes (same for other file format that don't support indexed color mode).
This commit is contained in:
parent
5ecebff375
commit
341408e902
@ -53,6 +53,7 @@ Import Sprite Sheet
|
||||
END
|
||||
error_loading_file = Error<<Error loading file: {0}||&OK
|
||||
error_saving_file = Error<<Error saving file: {0}||&OK
|
||||
file_format_doesnt_support_palette = Error<<Cannot save a color palette in {0} format||&OK
|
||||
export_animation_in_sequence = <<<END
|
||||
Notice
|
||||
<<Do you want to export the animation in {0} files?
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2021 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -50,7 +51,7 @@ void SavePaletteCommand::onLoadParams(const Params& params)
|
||||
m_saveAsPreset = (params.get("saveAsPreset") == "true");
|
||||
}
|
||||
|
||||
void SavePaletteCommand::onExecute(Context* context)
|
||||
void SavePaletteCommand::onExecute(Context* ctx)
|
||||
{
|
||||
const doc::Palette* palette = get_current_palette();
|
||||
std::string filename;
|
||||
@ -68,6 +69,18 @@ void SavePaletteCommand::onExecute(Context* context)
|
||||
return;
|
||||
|
||||
filename = selFilename.front();
|
||||
|
||||
// Check that the file format supports saving indexed images/color
|
||||
// palettes (e.g. if the user specified .jpg we should show that
|
||||
// that file format is not supported to save color palettes)
|
||||
if (!base::has_file_extension(filename, exts)) {
|
||||
if (ctx->isUIAvailable()) {
|
||||
ui::Alert::show(
|
||||
fmt::format(Strings::alerts_file_format_doesnt_support_palette(),
|
||||
base::get_file_extension(filename)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!save_palette(filename.c_str(), palette, 16)) // TODO 16 should be configurable
|
||||
@ -75,7 +88,7 @@ void SavePaletteCommand::onExecute(Context* context)
|
||||
|
||||
if (m_preset == get_default_palette_preset_name()) {
|
||||
set_default_palette(palette);
|
||||
if (!context->activeDocument())
|
||||
if (!ctx->activeDocument())
|
||||
set_current_palette(palette, false);
|
||||
}
|
||||
if (m_saveAsPreset) {
|
||||
|
@ -63,11 +63,13 @@ base::paths get_readable_extensions()
|
||||
return paths;
|
||||
}
|
||||
|
||||
base::paths get_writable_extensions()
|
||||
base::paths get_writable_extensions(const int requiredFormatFlag)
|
||||
{
|
||||
base::paths paths;
|
||||
for (const FileFormat* format : *FileFormatsManager::instance()) {
|
||||
if (format->support(FILE_SUPPORT_SAVE))
|
||||
if (format->support(FILE_SUPPORT_SAVE) &&
|
||||
(requiredFormatFlag == 0 ||
|
||||
format->support(requiredFormatFlag)))
|
||||
format->getExtensions(paths);
|
||||
}
|
||||
return paths;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2018-2020 Igara Studio S.A.
|
||||
// Copyright (C) 2018-2021 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -281,7 +281,7 @@ namespace app {
|
||||
|
||||
// Available extensions for each load/save operation.
|
||||
base::paths get_readable_extensions();
|
||||
base::paths get_writable_extensions();
|
||||
base::paths get_writable_extensions(const int requiredFormatFlag = 0);
|
||||
|
||||
// High-level routines to load/save documents.
|
||||
Doc* load_document(Context* context, const std::string& filename);
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2018-2020 Igara Studio S.A.
|
||||
// Copyright (C) 2018-2021 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -357,7 +357,9 @@ bool JpegFormat::onSave(FileOp* fop)
|
||||
JSAMPARRAY buffer;
|
||||
JDIMENSION buffer_height;
|
||||
const auto jpeg_options = std::static_pointer_cast<JpegOptions>(fop->formatOptions());
|
||||
const int qualityValue = (int)base::clamp(100.0f * jpeg_options->quality, 0.f, 100.f);
|
||||
const int qualityValue =
|
||||
(jpeg_options ? (int)base::clamp(100.0f * jpeg_options->quality, 0.f, 100.f):
|
||||
100);
|
||||
|
||||
int c;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2018-2019 Igara Studio S.A.
|
||||
// Copyright (C) 2018-2021 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -47,7 +47,7 @@ base::paths get_readable_palette_extensions()
|
||||
|
||||
base::paths get_writable_palette_extensions()
|
||||
{
|
||||
base::paths paths = get_writable_extensions();
|
||||
base::paths paths = get_writable_extensions(FILE_SUPPORT_INDEXED);
|
||||
for (const char* s : palExts)
|
||||
paths.push_back(s);
|
||||
return paths;
|
||||
|
Loading…
x
Reference in New Issue
Block a user