Add frame duration warnings saving animated GIF files (fix #1504)

This commit is contained in:
Gaspar Capello 2022-11-29 14:23:18 -03:00 committed by David Capello
parent 63de8edfdf
commit 18c56ae638
4 changed files with 23 additions and 3 deletions

View File

@ -115,6 +115,8 @@ file_format_indexed_mode = Indexed mode
file_format_layers = Layers
file_format_palette_changes = Palette changes between frames
file_format_rgb_mode = RGB mode
file_format_20ms_min_duration = Frame duration less than 20ms
file_format_10ms_duration_precision = Frame duration other than a multiple of 10ms
invalid_chars_in_filename = <<<END
Error
<<The file name cannot contain the following character(s):

View File

@ -607,6 +607,22 @@ FileOp* FileOp::createSaveDocumentOperation(const Context* context,
}
}
// GIF doesn't support frame duration less than 20ms, also
// the duration of each frame will be floored to 10ms multiples.
if (fop->m_format->support(FILE_GIF_ANI_LIMITATIONS)) {
bool durationLessThan20 = false;
bool milisecPrecision = false;
for (int i=0; i<fop->document()->sprite()->totalFrames(); ++i) {
int frameDuration = fop->document()->sprite()->frameDuration(i);
if (frameDuration < 20) durationLessThan20 = true;
if (frameDuration % 10) milisecPrecision = true;
}
if (durationLessThan20)
warnings += "<<- " + Strings::alerts_file_format_20ms_min_duration();
if (milisecPrecision)
warnings += "<<- " + Strings::alerts_file_format_10ms_duration_precision();
}
// Show the confirmation alert
if (!warnings.empty()) {
#ifdef ENABLE_UI

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2019-2023 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -31,6 +31,7 @@
#define FILE_SUPPORT_BIG_PALETTES 0x00002000 // Palettes w/more than 256 colors
#define FILE_SUPPORT_PALETTE_WITH_ALPHA 0x00004000
#define FILE_ENCODE_ABSTRACT_IMAGE 0x00008000 // Use the new FileAbstractImage
#define FILE_GIF_ANI_LIMITATIONS 0x00010000
namespace app {

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2018-2023 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -94,7 +94,8 @@ class GifFormat : public FileFormat {
FILE_SUPPORT_FRAMES |
FILE_SUPPORT_PALETTES |
FILE_SUPPORT_GET_FORMAT_OPTIONS |
FILE_ENCODE_ABSTRACT_IMAGE;
FILE_ENCODE_ABSTRACT_IMAGE |
FILE_GIF_ANI_LIMITATIONS;
}
bool onLoad(FileOp* fop) override;