Minor refactor in FileOp's format options

This commit is contained in:
David Capello 2016-06-01 15:01:07 -03:00
parent da856f432e
commit 2a112f693a
6 changed files with 27 additions and 26 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Copyright (C) 2001-2016 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
@ -693,7 +693,7 @@ bool BmpFormat::onLoad(FileOp *fop)
}
// Setup the file-data.
if (!fop->sequenceGetFormatOptions()) {
if (!fop->formatOptions()) {
base::SharedPtr<BmpOptions> bmp_options(new BmpOptions());
bmp_options->format = format;
@ -703,7 +703,7 @@ bool BmpFormat::onLoad(FileOp *fop)
bmp_options->green_mask = gmask;
bmp_options->blue_mask = bmask;
fop->sequenceSetFormatOptions(bmp_options);
fop->setFormatOptions(bmp_options);
}
return true;

View File

@ -480,15 +480,15 @@ FileOp* FileOp::createSaveDocumentOperation(const Context* context,
// Configure output format?
if (fop->m_format->support(FILE_SUPPORT_GET_FORMAT_OPTIONS)) {
base::SharedPtr<FormatOptions> format_options =
base::SharedPtr<FormatOptions> opts =
fop->m_format->getFormatOptions(fop);
// Does the user cancelled the operation?
if (!format_options)
if (!opts)
return nullptr;
fop->m_seq.format_options = format_options;
fop->m_document->setFormatOptions(format_options);
fop->m_formatOptions = opts;
fop->m_document->setFormatOptions(opts);
}
return fop.release();
@ -615,7 +615,7 @@ void FileOp::operate(IFileOpProgress* progress)
// Sets special options from the specific format (e.g. BMP
// file can contain the number of bits per pixel).
m_document->setFormatOptions(m_seq.format_options);
m_document->setFormatOptions(m_formatOptions);
}
}
// Direct load from one file.
@ -762,15 +762,15 @@ void FileOp::postLoad()
m_document->markAsSaved();
}
base::SharedPtr<FormatOptions> FileOp::sequenceGetFormatOptions() const
base::SharedPtr<FormatOptions> FileOp::formatOptions() const
{
return m_seq.format_options;
return m_formatOptions;
}
void FileOp::sequenceSetFormatOptions(const base::SharedPtr<FormatOptions>& format_options)
void FileOp::setFormatOptions(const base::SharedPtr<FormatOptions>& opts)
{
ASSERT(!m_seq.format_options);
m_seq.format_options = format_options;
ASSERT(!m_formatOptions);
m_formatOptions = opts;
}
void FileOp::sequenceSetNColors(int ncolors)
@ -960,7 +960,7 @@ FileOp::FileOp(FileOpType type, Context* context)
void FileOp::prepareForSequence()
{
m_seq.palette = new Palette(frame_t(0), 256);
m_seq.format_options.reset();
m_formatOptions.reset();
}
} // namespace app

View File

@ -121,10 +121,12 @@ namespace app {
// Does extra post-load processing which may require user intervention.
void postLoad();
// Special options specific to the file format.
base::SharedPtr<FormatOptions> formatOptions() const;
void setFormatOptions(const base::SharedPtr<FormatOptions>& opts);
// Helpers for file decoder/encoder (FileFormat) with
// FILE_SUPPORT_SEQUENCES flag.
base::SharedPtr<FormatOptions> sequenceGetFormatOptions() const;
void sequenceSetFormatOptions(const base::SharedPtr<FormatOptions>& formatOptions);
void sequenceSetNColors(int ncolors);
int sequenceGetNColors() const;
void sequenceSetColor(int index, int r, int g, int b);
@ -173,6 +175,8 @@ namespace app {
// that support animation like
// GIF/FLI/ASE).
base::SharedPtr<FormatOptions> m_formatOptions;
// Data for sequences.
struct {
std::vector<std::string> filename_list; // All file names to load/save.
@ -186,7 +190,6 @@ namespace app {
bool has_alpha;
LayerImage* layer;
Cel* last_cel;
base::SharedPtr<FormatOptions> format_options;
} m_seq;
void prepareForSequence();

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Copyright (C) 2001-2016 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
@ -870,7 +870,7 @@ public:
else
m_clearColor = rgba(0, 0, 0, 0);
const base::SharedPtr<GifOptions> gifOptions = fop->sequenceGetFormatOptions();
const base::SharedPtr<GifOptions> gifOptions = fop->formatOptions();
m_interlaced = gifOptions->interlaced();
m_loop = (gifOptions->loop() ? 0: -1);

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Copyright (C) 2001-2016 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
@ -237,8 +237,7 @@ bool JpegFormat::onSave(FileOp* fop)
const Image* image = fop->sequenceImage();
JSAMPARRAY buffer;
JDIMENSION buffer_height;
const base::SharedPtr<JpegOptions> jpeg_options =
fop->sequenceGetFormatOptions();
const base::SharedPtr<JpegOptions> jpeg_options = fop->formatOptions();
int c;
// Open the file for write in it.

View File

@ -1,6 +1,6 @@
// Aseprite
// Copyright (C) 2015 Gabriel Rauter
// Copyright (C) 2015 David Capello
// Copyright (C) 2015-2016 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
@ -154,7 +154,7 @@ bool WebPFormat::onLoad(FileOp* fop)
break;
}
if (!fop->sequenceGetFormatOptions()) {
if (!fop->formatOptions()) {
base::SharedPtr<WebPOptions> webPOptions(new WebPOptions());
webPOptions->setLossless(std::min(config.input.format - 1, 1));
fop->sequenceSetFormatOptions(webPOptions);
@ -251,8 +251,7 @@ bool WebPFormat::onSave(FileOp* fop)
return false;
}
base::SharedPtr<WebPOptions> webp_options =
fop->sequenceGetFormatOptions();
base::SharedPtr<WebPOptions> webp_options = fop->formatOptions();
WebPConfig config;