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 // 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 // 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 // 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. // Setup the file-data.
if (!fop->sequenceGetFormatOptions()) { if (!fop->formatOptions()) {
base::SharedPtr<BmpOptions> bmp_options(new BmpOptions()); base::SharedPtr<BmpOptions> bmp_options(new BmpOptions());
bmp_options->format = format; bmp_options->format = format;
@ -703,7 +703,7 @@ bool BmpFormat::onLoad(FileOp *fop)
bmp_options->green_mask = gmask; bmp_options->green_mask = gmask;
bmp_options->blue_mask = bmask; bmp_options->blue_mask = bmask;
fop->sequenceSetFormatOptions(bmp_options); fop->setFormatOptions(bmp_options);
} }
return true; return true;

View File

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

View File

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

View File

@ -1,5 +1,5 @@
// Aseprite // 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 // 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 // it under the terms of the GNU General Public License version 2 as
@ -870,7 +870,7 @@ public:
else else
m_clearColor = rgba(0, 0, 0, 0); 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_interlaced = gifOptions->interlaced();
m_loop = (gifOptions->loop() ? 0: -1); m_loop = (gifOptions->loop() ? 0: -1);

View File

@ -1,5 +1,5 @@
// Aseprite // 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 // 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 // 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(); const Image* image = fop->sequenceImage();
JSAMPARRAY buffer; JSAMPARRAY buffer;
JDIMENSION buffer_height; JDIMENSION buffer_height;
const base::SharedPtr<JpegOptions> jpeg_options = const base::SharedPtr<JpegOptions> jpeg_options = fop->formatOptions();
fop->sequenceGetFormatOptions();
int c; int c;
// Open the file for write in it. // Open the file for write in it.

View File

@ -1,6 +1,6 @@
// Aseprite // Aseprite
// Copyright (C) 2015 Gabriel Rauter // 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 // 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 // it under the terms of the GNU General Public License version 2 as
@ -154,7 +154,7 @@ bool WebPFormat::onLoad(FileOp* fop)
break; break;
} }
if (!fop->sequenceGetFormatOptions()) { if (!fop->formatOptions()) {
base::SharedPtr<WebPOptions> webPOptions(new WebPOptions()); base::SharedPtr<WebPOptions> webPOptions(new WebPOptions());
webPOptions->setLossless(std::min(config.input.format - 1, 1)); webPOptions->setLossless(std::min(config.input.format - 1, 1));
fop->sequenceSetFormatOptions(webPOptions); fop->sequenceSetFormatOptions(webPOptions);
@ -251,8 +251,7 @@ bool WebPFormat::onSave(FileOp* fop)
return false; return false;
} }
base::SharedPtr<WebPOptions> webp_options = base::SharedPtr<WebPOptions> webp_options = fop->formatOptions();
fop->sequenceGetFormatOptions();
WebPConfig config; WebPConfig config;