Merge branch 'main' into beta

This commit is contained in:
David Capello 2022-08-23 15:24:02 -03:00
commit e87cb2dd8f
27 changed files with 106 additions and 75 deletions

View File

@ -91,7 +91,7 @@ public:
}
// FileAbstractImage impl
doc::ImageSpec spec() const override {
const doc::ImageSpec& spec() const override {
return m_spec;
}

View File

@ -104,7 +104,11 @@ namespace app {
class FileAbstractImage {
public:
virtual ~FileAbstractImage() { }
virtual doc::ImageSpec spec() const = 0;
virtual int width() const { return spec().width(); }
virtual int height() const { return spec().height(); }
virtual const doc::ImageSpec& spec() const = 0;
virtual os::ColorSpaceRef osColorSpace() const = 0;
virtual bool needAlpha() const = 0;
virtual bool isOpaque() const = 0;

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -48,7 +48,8 @@ class FliFormat : public FileFormat {
FILE_SUPPORT_SAVE |
FILE_SUPPORT_INDEXED |
FILE_SUPPORT_FRAMES |
FILE_SUPPORT_PALETTES;
FILE_SUPPORT_PALETTES |
FILE_ENCODE_ABSTRACT_IMAGE;
}
bool onLoad(FileOp* fop) override;
@ -174,7 +175,7 @@ bool FliFormat::onLoad(FileOp* fop)
#ifdef ENABLE_SAVE
static int get_time_precision(const Sprite* sprite,
static int get_time_precision(const FileAbstractImage* sprite,
const doc::SelectedFrames& selFrames)
{
// Check if all frames have the same duration
@ -205,7 +206,7 @@ static int get_time_precision(const Sprite* sprite,
bool FliFormat::onSave(FileOp* fop)
{
const Sprite* sprite = fop->document()->sprite();
const FileAbstractImage* sprite = fop->abstractImage();
// Open the file to write in binary mode
FileHandle handle(open_file_with_exception_sync_on_close(fop->filename(), "wb"));
@ -250,7 +251,7 @@ bool FliFormat::onSave(FileOp* fop)
}
// Render the frame in the bitmap
render.renderSprite(bmp.get(), sprite, frame);
sprite->renderFrame(frame, bmp.get());
// How many times this frame should be written to get the same
// time that it has in the sprite

View File

@ -52,11 +52,12 @@ base::paths get_writable_palette_extensions()
return paths;
}
Palette* load_palette(const char* filename,
const FileOpConfig* config)
std::unique_ptr<doc::Palette> load_palette(
const char* filename,
const FileOpConfig* config)
{
dio::FileFormat dioFormat = dio::detect_format(filename);
Palette* pal = nullptr;
std::unique_ptr<Palette> pal = nullptr;
switch (dioFormat) {
@ -100,7 +101,7 @@ Palette* load_palette(const char* filename,
if (fop->document() &&
fop->document()->sprite() &&
fop->document()->sprite()->palette(frame_t(0))) {
pal = new Palette(
pal = std::make_unique<Palette>(
*fop->document()->sprite()->palette(frame_t(0)));
}

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -12,6 +12,8 @@
#include "base/paths.h"
#include "gfx/color_space.h"
#include <memory>
namespace doc {
class Palette;
}
@ -22,8 +24,9 @@ namespace app {
base::paths get_readable_palette_extensions();
base::paths get_writable_palette_extensions();
doc::Palette* load_palette(const char *filename,
const FileOpConfig* config = nullptr);
std::unique_ptr<doc::Palette> load_palette(
const char *filename,
const FileOpConfig* config = nullptr);
bool save_palette(const char *filename,
const doc::Palette* pal,
int columns,

View File

@ -23,7 +23,6 @@
#include "base/convert_to.h"
#include "base/file_handle.h"
#include "doc/doc.h"
#include "render/render.h"
#include "ui/manager.h"
#include "webp_options.xml.h"
@ -61,7 +60,8 @@ class WebPFormat : public FileFormat {
FILE_SUPPORT_RGB |
FILE_SUPPORT_RGBA |
FILE_SUPPORT_FRAMES |
FILE_SUPPORT_GET_FORMAT_OPTIONS;
FILE_SUPPORT_GET_FORMAT_OPTIONS |
FILE_ENCODE_ABSTRACT_IMAGE;
}
bool onLoad(FileOp* fop) override;
@ -256,7 +256,8 @@ bool WebPFormat::onSave(FileOp* fop)
FileHandle handle(open_file_with_exception_sync_on_close(fop->filename(), "wb"));
FILE* fp = handle.get();
const Sprite* sprite = fop->document()->sprite();
const FileAbstractImage* sprite = fop->abstractImage();
const doc::frame_t totalFrames = sprite->frames();
const int w = sprite->width();
const int h = sprite->height();
@ -300,9 +301,8 @@ bool WebPFormat::onSave(FileOp* fop)
1); // 1 = loop once
ImageRef image(Image::create(IMAGE_RGB, w, h));
render::Render render;
WriterData wd(fp, fop, 0, sprite->totalFrames(), 0.0);
WriterData wd(fp, fop, 0, totalFrames, 0.0);
WebPPicture pic;
WebPPictureInit(&pic);
pic.width = w;
@ -313,13 +313,12 @@ bool WebPFormat::onSave(FileOp* fop)
pic.user_data = &wd;
pic.progress_hook = progress_report;
WebPAnimEncoder* enc = WebPAnimEncoderNew(sprite->width(),
sprite->height(),
&enc_options);
WebPAnimEncoder* enc = WebPAnimEncoderNew(w, h, &enc_options);
int timestamp_ms = 0;
for (frame_t f=0; f<sprite->totalFrames(); ++f) {
for (frame_t f=0; f<totalFrames; ++f) {
// Render the frame in the bitmap
render.renderSprite(image.get(), sprite, f);
clear_image(image.get(), image->maskColor());
sprite->renderFrame(f, image.get());
// Switch R <-> B channels because WebPAnimEncoderAssemble()
// expects MODE_BGRA pictures.

View File

@ -52,7 +52,7 @@ void load_default_palette()
// If there is no palette in command line, we use the default one.
std::string palFile = defaultPalName;
if (base::is_file(palFile)) {
pal.reset(load_palette(palFile.c_str()));
pal = load_palette(palFile.c_str());
}
else {
// Migrate old default.gpl to default.ase format
@ -60,7 +60,7 @@ void load_default_palette()
get_default_palette_preset_name(), ".gpl");
if (base::is_file(palFile)) {
pal.reset(load_palette(palFile.c_str()));
pal = load_palette(palFile.c_str());
// Remove duplicate black entries at the end (as old palettes
// contains 256 colors)
@ -104,7 +104,7 @@ void load_default_palette()
if (path.empty())
path = App::instance()->extensions().palettePath("VGA 13h");
if (!path.empty())
pal.reset(load_palette(path.c_str()));
pal = load_palette(path.c_str());
}
// Save default.ase file

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2022 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
@ -9,6 +10,9 @@
#pragma once
#include "app/res/resource.h"
#include "doc/palette.h"
#include <memory>
namespace doc {
class Palette;
@ -20,20 +24,20 @@ namespace app {
public:
PaletteResource(const std::string& id,
const std::string& path,
doc::Palette* palette)
std::unique_ptr<doc::Palette>&& palette)
: m_id(id)
, m_path(path)
, m_palette(palette) {
, m_palette(std::move(palette)) {
}
virtual ~PaletteResource() { }
virtual const std::string& id() const override { return m_id; }
virtual const std::string& path() const override { return m_path; }
virtual doc::Palette* palette() { return m_palette; }
virtual const doc::Palette* palette() { return m_palette.get(); }
private:
std::string m_id;
std::string m_path;
doc::Palette* m_palette;
std::unique_ptr<doc::Palette> m_palette;
};
} // namespace app

View File

@ -63,9 +63,9 @@ void PalettesLoaderDelegate::getResourcesPaths(std::map<std::string, std::string
Resource* PalettesLoaderDelegate::loadResource(const std::string& id,
const std::string& path)
{
doc::Palette* palette = load_palette(path.c_str(), &m_config);
auto palette = load_palette(path.c_str(), &m_config);
if (palette)
return new PaletteResource(id, path, palette);
return new PaletteResource(id, path, std::move(palette));
else
return nullptr;
}

View File

@ -20,8 +20,8 @@
namespace app {
ResourcesLoader::ResourcesLoader(ResourcesLoaderDelegate* delegate)
: m_delegate(delegate)
ResourcesLoader::ResourcesLoader(std::unique_ptr<ResourcesLoaderDelegate>&& delegate)
: m_delegate(std::move(delegate))
, m_done(false)
, m_cancel(false)
, m_thread(new base::thread([this]{ threadLoadResources(); }))

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -20,7 +21,7 @@ namespace app {
class ResourcesLoader {
public:
ResourcesLoader(ResourcesLoaderDelegate* delegate);
ResourcesLoader(std::unique_ptr<ResourcesLoaderDelegate>&& delegate);
~ResourcesLoader();
void cancel();
@ -34,7 +35,7 @@ namespace app {
typedef base::concurrent_queue<Resource*> Queue;
ResourcesLoaderDelegate* m_delegate;
std::unique_ptr<ResourcesLoaderDelegate> m_delegate;
bool m_done;
bool m_cancel;
Queue m_queue;

View File

@ -80,9 +80,9 @@ int Palette_new(lua_State* L)
return luaL_error(L, "script doesn't have access to open file %s",
absFn.c_str());
Palette* pal = load_palette(absFn.c_str());
auto pal = load_palette(absFn.c_str());
if (pal)
push_new<PaletteObj>(L, nullptr, pal);
push_new<PaletteObj>(L, nullptr, pal.release());
else
lua_pushnil(L);
return 1;
@ -109,9 +109,9 @@ int Palette_new(lua_State* L)
return luaL_error(L, "script doesn't have access to open file %s",
absFn.c_str());
Palette* pal = load_palette(absFn.c_str());
auto pal = load_palette(absFn.c_str());
if (pal)
push_new<PaletteObj>(L, nullptr, pal);
push_new<PaletteObj>(L, nullptr, pal.release());
else
lua_pushnil(L);
return 1;

View File

@ -189,7 +189,7 @@ ColorPopup::ColorPopup(const ColorButtonOptions& options)
ResourceFinder rf;
rf.includeDataDir("palettes/tags.gpl");
if (rf.findFirst())
g_simplePal.reset(load_palette(rf.filename().c_str()));
g_simplePal = load_palette(rf.filename().c_str());
}
if (g_simplePal)

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2020-2021 Igara Studio S.A.
// Copyright (C) 2020-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -78,7 +78,7 @@ void PalettePopup::showPopup(ui::Display* display,
openWindowInForeground();
}
void PalettePopup::onPalChange(doc::Palette* palette)
void PalettePopup::onPalChange(const doc::Palette* palette)
{
const bool state =
(UIContext::instance()->activeDocument() &&
@ -114,7 +114,7 @@ void PalettePopup::onSearchChange()
void PalettePopup::onLoadPal()
{
doc::Palette* palette = m_paletteListBox.selectedPalette();
const doc::Palette* palette = m_paletteListBox.selectedPalette();
if (!palette)
return;

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2021 Igara Studio S.A.
// Copyright (C) 2021-2022 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
@ -31,7 +31,7 @@ namespace app {
const gfx::Rect& buttonPos);
protected:
void onPalChange(doc::Palette* palette);
void onPalChange(const doc::Palette* palette);
void onSearchChange();
void onLoadPal();
void onOpenFolder();

View File

@ -118,7 +118,9 @@ private:
};
PalettesListBox::PalettesListBox()
: ResourcesListBox(new ResourcesLoader(new PalettesLoaderDelegate))
: ResourcesListBox(
new ResourcesLoader(
std::make_unique<PalettesLoaderDelegate>()))
{
addChild(&m_tooltips);
@ -130,7 +132,7 @@ PalettesListBox::PalettesListBox()
[this]{ reload(); });
}
doc::Palette* PalettesListBox::selectedPalette()
const doc::Palette* PalettesListBox::selectedPalette()
{
Resource* resource = selectedResource();
if (!resource)
@ -146,14 +148,14 @@ ResourceListItem* PalettesListBox::onCreateResourceItem(Resource* resource)
void PalettesListBox::onResourceChange(Resource* resource)
{
doc::Palette* palette = static_cast<PaletteResource*>(resource)->palette();
const doc::Palette* palette = static_cast<PaletteResource*>(resource)->palette();
PalChange(palette);
}
void PalettesListBox::onPaintResource(Graphics* g, gfx::Rect& bounds, Resource* resource)
{
auto theme = SkinTheme::get(this);
doc::Palette* palette = static_cast<PaletteResource*>(resource)->palette();
const doc::Palette* palette = static_cast<PaletteResource*>(resource)->palette();
os::Surface* tick = theme->parts.checkSelected()->bitmap(0);
// Draw tick (to say "this palette matches the active sprite

View File

@ -22,9 +22,9 @@ namespace app {
public:
PalettesListBox();
doc::Palette* selectedPalette();
const doc::Palette* selectedPalette();
obs::signal<void(doc::Palette*)> PalChange;
obs::signal<void(const doc::Palette*)> PalChange;
protected:
virtual ResourceListItem* onCreateResourceItem(Resource* resource) override;

View File

@ -1,5 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2020 Igara Studio S.A.
// Copyright (c) 2020-2022 Igara Studio S.A.
// Copyright (c) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -25,7 +25,7 @@ using namespace base::serialization::big_endian;
const int ActMaxColors = 256;
Palette* load_act_file(const char *filename)
std::unique_ptr<Palette> load_act_file(const char *filename)
{
std::ifstream f(FSTREAM_PATH(filename), std::ios::binary);
if (f.bad())
@ -52,7 +52,7 @@ Palette* load_act_file(const char *filename)
pal->setEntry(i, rgba(r, g, b, 255));
}
return pal.release();
return pal;
}
bool save_act_file(const Palette *pal, const char *filename)

View File

@ -1,4 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2022 Igara Studio S.A.
// Copyright (c) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
@ -8,13 +9,15 @@
#define DOC_FILE_ACT_FILE_H_INCLUDED
#pragma once
#include <memory>
namespace doc {
class Palette;
namespace file {
Palette* load_act_file(const char* filename);
std::unique_ptr<Palette> load_act_file(const char* filename);
bool save_act_file(const Palette* pal, const char* filename);
} // namespace file

View File

@ -17,6 +17,7 @@
#include <cstdio>
#include <cstdlib>
#include <memory>
#define PROCOL_MAGIC_NUMBER 0xB123
@ -26,15 +27,13 @@ namespace file {
using namespace base;
// Loads a COL file (Animator and Animator Pro format)
Palette* load_col_file(const char* filename)
std::unique_ptr<Palette> load_col_file(const char* filename)
{
Palette *pal = NULL;
int c, r, g, b;
FILE* f;
f = std::fopen(filename, "rb");
FILE* f = std::fopen(filename, "rb");
if (!f)
return NULL;
return nullptr;
// Get file size.
std::fseek(f, 0, SEEK_END);
@ -49,8 +48,9 @@ Palette* load_col_file(const char* filename)
}
// Animator format
std::unique_ptr<Palette> pal = nullptr;
if (!pro) {
pal = new Palette(frame_t(0), 256);
pal = std::make_unique<Palette>(frame_t(0), 256);
for (c=0; c<256; c++) {
r = fgetc(f);
@ -75,10 +75,10 @@ Palette* load_col_file(const char* filename)
// Unknown format
if (magic != PROCOL_MAGIC_NUMBER || version != 0) {
fclose(f);
return NULL;
return nullptr;
}
pal = new Palette(frame_t(0), std::min(d.quot, 256));
pal = std::make_unique<Palette>(frame_t(0), std::min(d.quot, 256));
for (c=0; c<pal->size(); c++) {
r = fgetc(f);

View File

@ -1,4 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2022 Igara Studio S.A.
// Copyright (c) 2001-2014 David Capello
//
// This file is released under the terms of the MIT license.
@ -8,13 +9,15 @@
#define DOC_FILE_COL_FILE_H_INCLUDED
#pragma once
#include <memory>
namespace doc {
class Palette;
namespace file {
Palette* load_col_file(const char* filename);
std::unique_ptr<Palette> load_col_file(const char* filename);
bool save_col_file(const Palette* pal, const char* filename);
} // namespace file

View File

@ -26,7 +26,7 @@
namespace doc {
namespace file {
Palette* load_gpl_file(const char* filename)
std::unique_ptr<Palette> load_gpl_file(const char* filename)
{
std::ifstream f(FSTREAM_PATH(filename));
if (f.bad()) return NULL;
@ -98,7 +98,7 @@ Palette* load_gpl_file(const char* filename)
pal->setComment(comment);
}
return pal.release();
return pal;
}
bool save_gpl_file(const Palette* pal, const char* filename)

View File

@ -8,13 +8,15 @@
#define DOC_FILE_GPL_FILE_H_INCLUDED
#pragma once
#include <memory>
namespace doc {
class Palette;
namespace file {
Palette* load_gpl_file(const char* filename);
std::unique_ptr<Palette> load_gpl_file(const char* filename);
bool save_gpl_file(const Palette* pal, const char* filename);
} // namespace file

View File

@ -1,4 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2022 Igara Studio S.A.
// Copyright (c) 2016-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -23,7 +24,7 @@
namespace doc {
namespace file {
Palette* load_hex_file(const char *filename)
std::unique_ptr<Palette> load_hex_file(const char *filename)
{
std::ifstream f(FSTREAM_PATH(filename));
if (f.bad())
@ -64,7 +65,7 @@ Palette* load_hex_file(const char *filename)
}
}
return pal.release();
return pal;
}
bool save_hex_file(const Palette *pal, const char *filename)

View File

@ -1,4 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2022 Igara Studio S.A.
// Copyright (c) 2016 David Capello
//
// This file is released under the terms of the MIT license.
@ -8,13 +9,15 @@
#define DOC_FILE_HEX_FILE_H_INCLUDED
#pragma once
#include <memory>
namespace doc {
class Palette;
namespace file {
Palette* load_hex_file(const char* filename);
std::unique_ptr<Palette> load_hex_file(const char* filename);
bool save_hex_file(const Palette* pal, const char* filename);
} // namespace file

View File

@ -1,4 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2022 Igara Studio S.A.
// Copyright (c) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -24,7 +25,7 @@
namespace doc {
namespace file {
Palette* load_pal_file(const char *filename)
std::unique_ptr<Palette> load_pal_file(const char *filename)
{
std::ifstream f(FSTREAM_PATH(filename));
if (f.bad())
@ -65,7 +66,7 @@ Palette* load_pal_file(const char *filename)
pal->addEntry(rgba(r, g, b, a));
}
return pal.release();
return pal;
}
bool save_pal_file(const Palette *pal, const char *filename)

View File

@ -1,4 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2022 Igara Studio S.A.
// Copyright (c) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
@ -8,13 +9,15 @@
#define DOC_FILE_PAL_FILE_H_INCLUDED
#pragma once
#include <memory>
namespace doc {
class Palette;
namespace file {
Palette* load_pal_file(const char* filename);
std::unique_ptr<Palette> load_pal_file(const char* filename);
bool save_pal_file(const Palette* pal, const char* filename);
} // namespace file