mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-14 04:19:12 +00:00
Merge branch 'main' into beta
This commit is contained in:
commit
c40993e284
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2022 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -86,7 +86,7 @@ doc::color_t color_from_hex(const char* str)
|
||||
template<typename Container,
|
||||
typename ChildNameGetterFunc,
|
||||
typename UpdateXmlChildFunc>
|
||||
void update_xml_collection(Container& container,
|
||||
void update_xml_collection(const Container& container,
|
||||
TiXmlElement* xmlParent,
|
||||
const char* childElemName,
|
||||
const char* idAttrName,
|
||||
@ -111,7 +111,7 @@ void update_xml_collection(Container& container,
|
||||
continue;
|
||||
|
||||
bool found = false;
|
||||
for (auto child : container) {
|
||||
for (const auto& child : container) {
|
||||
std::string thisChildName = childNameGetter(child);
|
||||
if (thisChildName == xmlChildName) {
|
||||
existent.insert(thisChildName);
|
||||
@ -128,7 +128,7 @@ void update_xml_collection(Container& container,
|
||||
}
|
||||
|
||||
// Add new children
|
||||
for (auto child : container) {
|
||||
for (const auto& child : container) {
|
||||
std::string thisChildName = childNameGetter(child);
|
||||
if (existent.find(thisChildName) == existent.end()) {
|
||||
TiXmlElement xmlChild(childElemName);
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2022 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -13,6 +14,8 @@ using namespace app;
|
||||
|
||||
TEST(IniFile, Basic)
|
||||
{
|
||||
ConfigModule cm;
|
||||
|
||||
if (base::is_file("_test.ini"))
|
||||
base::delete_file("_test.ini");
|
||||
|
||||
@ -36,6 +39,8 @@ TEST(IniFile, Basic)
|
||||
|
||||
TEST(IniFile, PushPop)
|
||||
{
|
||||
ConfigModule cm;
|
||||
|
||||
if (base::is_file("_a.ini")) base::delete_file("_a.ini");
|
||||
if (base::is_file("_b.ini")) base::delete_file("_b.ini");
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2022 Igara Studio S.A.
|
||||
// Copyright (c) 2017 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -10,6 +11,7 @@
|
||||
|
||||
#include "doc/frame.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace doc {
|
||||
@ -19,14 +21,22 @@ namespace doc {
|
||||
public:
|
||||
class Key {
|
||||
public:
|
||||
Key(const frame_t frame, T* value) : m_frame(frame), m_value(value) { }
|
||||
Key(const frame_t frame,
|
||||
std::unique_ptr<T>&& value)
|
||||
: m_frame(frame)
|
||||
, m_value(std::move(value)) { }
|
||||
Key(const Key& o)
|
||||
: m_frame(o.m_frame)
|
||||
, m_value(o.m_value ? new T(*o.m_value): nullptr) { }
|
||||
Key(Key&& o) = default;
|
||||
Key& operator=(Key&& o) = default;
|
||||
frame_t frame() const { return m_frame; }
|
||||
T* value() const { return m_value; }
|
||||
T* value() const { return m_value.get(); }
|
||||
void setFrame(const frame_t frame) { m_frame = frame; }
|
||||
void setValue(T* value) { m_value = value; }
|
||||
void setValue(std::unique_ptr<T>&& value) { m_value = std::move(value); }
|
||||
private:
|
||||
frame_t m_frame;
|
||||
T* m_value;
|
||||
frame_t m_frame = 0;
|
||||
std::unique_ptr<T> m_value = nullptr;
|
||||
};
|
||||
|
||||
typedef std::vector<Key> List;
|
||||
@ -112,30 +122,30 @@ namespace doc {
|
||||
|
||||
Keyframes(const Keyframes& other) {
|
||||
for (const auto& key : other.m_keys)
|
||||
m_keys.push_back(Key(key.frame(), new T(*key.value())));
|
||||
m_keys.push_back(Key(key.frame(), std::make_unique<T>(*key.value())));
|
||||
}
|
||||
|
||||
void insert(const frame_t frame, T* value) {
|
||||
void insert(const frame_t frame, std::unique_ptr<T>&& value) {
|
||||
auto it = getIterator(frame);
|
||||
if (it == end())
|
||||
m_keys.push_back(Key(frame, value));
|
||||
m_keys.push_back(Key(frame, std::move(value)));
|
||||
else if (it->frame() == frame)
|
||||
it->setValue(value);
|
||||
it->setValue(std::move(value));
|
||||
else {
|
||||
++it;
|
||||
m_keys.insert(it, Key(frame, value));
|
||||
// We must insert keys in order. So if "frame" is less than
|
||||
// the "it" frame, insert() will insert the new key before the
|
||||
// iterator just as we want. In other case we have to use the
|
||||
// next iterator (++it).
|
||||
if (frame > it->frame())
|
||||
++it;
|
||||
m_keys.insert(it, Key(frame, std::move(value)));
|
||||
}
|
||||
}
|
||||
|
||||
T* remove(const frame_t frame) {
|
||||
void remove(const frame_t frame) {
|
||||
auto it = getIterator(frame);
|
||||
if (it != end()) {
|
||||
T* value = it->value();
|
||||
if (it != end())
|
||||
m_keys.erase(it);
|
||||
return value;
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
T* operator[](const frame_t frame) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2022 Igara Studio S.A.
|
||||
// Copyright (c) 2017 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -21,7 +22,7 @@ TEST(Keyframes, Operations)
|
||||
EXPECT_TRUE(k.empty());
|
||||
EXPECT_EQ(0, k.size());
|
||||
|
||||
k.insert(0, new int(5));
|
||||
k.insert(0, std::make_unique<int>(5));
|
||||
EXPECT_FALSE(k.empty());
|
||||
EXPECT_EQ(1, k.size());
|
||||
EXPECT_EQ(0, k.fromFrame());
|
||||
@ -31,7 +32,7 @@ TEST(Keyframes, Operations)
|
||||
EXPECT_EQ(5, *k[1]);
|
||||
EXPECT_EQ(5, *k[2]);
|
||||
|
||||
k.insert(2, new int(6));
|
||||
k.insert(2, std::make_unique<int>(6));
|
||||
EXPECT_EQ(2, k.size());
|
||||
EXPECT_EQ(0, k.fromFrame());
|
||||
EXPECT_EQ(2, k.toFrame());
|
||||
@ -41,7 +42,7 @@ TEST(Keyframes, Operations)
|
||||
EXPECT_EQ(6, *k[2]);
|
||||
EXPECT_EQ(6, *k[3]);
|
||||
|
||||
k.insert(1, new int(3));
|
||||
k.insert(1, std::make_unique<int>(3));
|
||||
EXPECT_EQ(3, k.size());
|
||||
EXPECT_EQ(0, k.fromFrame());
|
||||
EXPECT_EQ(2, k.toFrame());
|
||||
@ -72,10 +73,10 @@ TEST(Keyframes, Operations)
|
||||
TEST(Keyframes, Range)
|
||||
{
|
||||
Keyframes<int> k;
|
||||
k.insert(0, new int(5));
|
||||
k.insert(0, std::make_unique<int>(5));
|
||||
k.insert(2, nullptr);
|
||||
k.insert(4, new int(8));
|
||||
k.insert(6, new int(2));
|
||||
k.insert(4, std::make_unique<int>(8));
|
||||
k.insert(6, std::make_unique<int>(2));
|
||||
|
||||
EXPECT_EQ(0, k.fromFrame());
|
||||
EXPECT_EQ(6, k.toFrame());
|
||||
@ -131,7 +132,7 @@ TEST(Keyframes, Range)
|
||||
TEST(Keyframes, BugEmptyCount)
|
||||
{
|
||||
Keyframes<int> k;
|
||||
k.insert(7, new int(5));
|
||||
k.insert(7, std::make_unique<int>(5));
|
||||
EXPECT_EQ(0, k.range(-1, 6).countKeys());
|
||||
EXPECT_EQ(1, k.range(0, 7).countKeys());
|
||||
EXPECT_EQ(1, k.range(8, 9).countKeys());
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2022 Igara Studio S.A.
|
||||
// Copyright (c) 2001-2016 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -13,6 +14,7 @@
|
||||
#include "doc/algorithm/resize_image.h"
|
||||
#include "doc/color.h"
|
||||
#include "doc/image.h"
|
||||
#include "doc/image_ref.h"
|
||||
#include "doc/primitives.h"
|
||||
|
||||
using namespace std;
|
||||
@ -56,41 +58,46 @@ color_t test_image_scaled_9x9_bilinear[81] =
|
||||
0x000000, 0x000000, 0x565656, 0xa9a9a9, 0xffffff, 0xa9a9a9, 0x565656, 0x000000, 0x000000
|
||||
};
|
||||
|
||||
Image* create_image_from_data(PixelFormat format, color_t* data, int width, int height)
|
||||
ImageRef create_image_from_data(PixelFormat format, color_t* data, int width, int height)
|
||||
{
|
||||
Image* new_image = Image::create(format, width, height);
|
||||
ImageRef new_image(Image::create(format, width, height));
|
||||
for (int i = 0; i < width * height; i++) {
|
||||
new_image->putPixel(i % width, i / width, data[i]);
|
||||
}
|
||||
|
||||
return new_image;
|
||||
}
|
||||
|
||||
TEST(ResizeImage, NearestNeighborInterp)
|
||||
{
|
||||
Image* src = create_image_from_data(IMAGE_RGB, test_image_base_3x3, 3, 3);
|
||||
Image* dst_expected = create_image_from_data(IMAGE_RGB, test_image_scaled_9x9_nearest, 9, 9);
|
||||
ImageRef src(create_image_from_data(IMAGE_RGB, test_image_base_3x3, 3, 3));
|
||||
ImageRef dst_expected(create_image_from_data(IMAGE_RGB, test_image_scaled_9x9_nearest, 9, 9));
|
||||
|
||||
Image* dst = Image::create(IMAGE_RGB, 9, 9);
|
||||
algorithm::resize_image(src, dst, algorithm::RESIZE_METHOD_NEAREST_NEIGHBOR, NULL, NULL, -1);
|
||||
ImageRef dst(Image::create(IMAGE_RGB, 9, 9));
|
||||
algorithm::resize_image(src.get(), dst.get(),
|
||||
algorithm::RESIZE_METHOD_NEAREST_NEIGHBOR,
|
||||
nullptr, nullptr, -1);
|
||||
|
||||
ASSERT_EQ(0, count_diff_between_images(dst, dst_expected));
|
||||
ASSERT_EQ(0, count_diff_between_images(dst.get(), dst_expected.get()));
|
||||
|
||||
Image* dst2 = Image::create(IMAGE_RGB, 3, 3);
|
||||
algorithm::resize_image(dst, dst2, algorithm::RESIZE_METHOD_NEAREST_NEIGHBOR, NULL, NULL, -1);
|
||||
ASSERT_EQ(0, count_diff_between_images(src, dst2));
|
||||
ImageRef dst2(Image::create(IMAGE_RGB, 3, 3));
|
||||
algorithm::resize_image(dst.get(), dst2.get(),
|
||||
algorithm::RESIZE_METHOD_NEAREST_NEIGHBOR,
|
||||
nullptr, nullptr, -1);
|
||||
ASSERT_EQ(0, count_diff_between_images(src.get(), dst2.get()));
|
||||
}
|
||||
|
||||
#if 0 // TODO complete this test
|
||||
TEST(ResizeImage, BilinearInterpRGBType)
|
||||
{
|
||||
Image* src = create_image_from_data(IMAGE_RGB, test_image_base_3x3, 3, 3);
|
||||
Image* dst_expected = create_image_from_data(IMAGE_RGB, test_image_scaled_9x9_bilinear, 9, 9);
|
||||
ImageRef src(create_image_from_data(IMAGE_RGB, test_image_base_3x3, 3, 3));
|
||||
ImageRef dst_expected(create_image_from_data(IMAGE_RGB, test_image_scaled_9x9_bilinear, 9, 9));
|
||||
|
||||
Image* dst = Image::create(IMAGE_RGB, 9, 9);
|
||||
algorithm::resize_image(src, dst, algorithm::RESIZE_METHOD_BILINEAR, NULL, NULL);
|
||||
ImageRef dst(Image::create(IMAGE_RGB, 9, 9));
|
||||
algorithm::resize_image(src.get(), dst.get(),
|
||||
algorithm::RESIZE_METHOD_BILINEAR,
|
||||
nullptr, nullptr, -1);
|
||||
|
||||
ASSERT_EQ(0, count_diff_between_images(dst, dst_expected));
|
||||
ASSERT_EQ(0, count_diff_between_images(dst.get(), dst_expected.get()));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2020 Igara Studio S.A.
|
||||
// Copyright (c) 2020-2022 Igara Studio S.A.
|
||||
// Copyright (c) 2017 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -62,12 +62,12 @@ int Slice::getMemSize() const
|
||||
|
||||
void Slice::insert(const frame_t frame, const SliceKey& key)
|
||||
{
|
||||
m_keys.insert(frame, new SliceKey(key));
|
||||
m_keys.insert(frame, std::make_unique<SliceKey>(key));
|
||||
}
|
||||
|
||||
void Slice::remove(const frame_t frame)
|
||||
{
|
||||
delete m_keys.remove(frame);
|
||||
m_keys.remove(frame);
|
||||
}
|
||||
|
||||
const SliceKey* Slice::getByFrame(const frame_t frame) const
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2018-2019 Igara Studio S.A.
|
||||
// Copyright (c) 2018-2022 Igara Studio S.A.
|
||||
// Copyright (c) 2001-2016 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -17,11 +17,15 @@
|
||||
#include "doc/pixel_format.h"
|
||||
#include "doc/sprite.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
using namespace doc;
|
||||
|
||||
TEST(Sprite, Layers)
|
||||
{
|
||||
Sprite* spr = new Sprite(ImageSpec(ColorMode::RGB, 32, 32), 256);
|
||||
std::shared_ptr<Sprite> sprPtr(std::make_shared<Sprite>(
|
||||
ImageSpec(ColorMode::RGB, 32, 32), 256));
|
||||
Sprite* spr = sprPtr.get();
|
||||
|
||||
LayerImage* lay1 = new LayerImage(spr);
|
||||
LayerImage* lay2 = new LayerImage(spr);
|
||||
@ -90,7 +94,9 @@ TEST(Sprite, Layers)
|
||||
// - lay3: F G~H
|
||||
TEST(Sprite, CelsRange)
|
||||
{
|
||||
Sprite* spr = new Sprite(ImageSpec(ColorMode::RGB, 32, 32), 256);
|
||||
std::shared_ptr<Sprite> sprPtr(std::make_shared<Sprite>(
|
||||
ImageSpec(ColorMode::RGB, 32, 32), 256));
|
||||
Sprite* spr = sprPtr.get();
|
||||
spr->setTotalFrames(3);
|
||||
|
||||
LayerImage* lay1 = new LayerImage(spr);
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2019 Igara Studio S.A.
|
||||
// Copyright (c) 2019-2022 Igara Studio S.A.
|
||||
// Copyright (c) 2001-2018 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -66,7 +66,7 @@ TYPED_TEST_CASE(RenderAllModes, ImageAllTraits);
|
||||
|
||||
TEST(Render, Basic)
|
||||
{
|
||||
Document* doc = new Document;
|
||||
std::shared_ptr<Document> doc = std::make_shared<Document>();
|
||||
doc->sprites().add(Sprite::MakeStdSprite(ImageSpec(ColorMode::INDEXED, 2, 2)));
|
||||
|
||||
Image* src = doc->sprite()->root()->firstLayer()->cel(0)->image();
|
||||
@ -85,7 +85,7 @@ TYPED_TEST(RenderAllModes, CheckDefaultBackgroundMode)
|
||||
{
|
||||
typedef TypeParam ImageTraits;
|
||||
|
||||
Document* doc = new Document;
|
||||
std::shared_ptr<Document> doc = std::make_shared<Document>();
|
||||
doc->sprites().add(Sprite::MakeStdSprite(ImageSpec(ImageTraits::color_mode, 2, 2)));
|
||||
|
||||
EXPECT_TRUE(!doc->sprite()->root()->firstLayer()->isBackground());
|
||||
@ -105,7 +105,7 @@ TYPED_TEST(RenderAllModes, CheckDefaultBackgroundMode)
|
||||
|
||||
TEST(Render, DefaultBackgroundModeWithNonzeroTransparentIndex)
|
||||
{
|
||||
Document* doc = new Document;
|
||||
std::shared_ptr<Document> doc = std::make_shared<Document>();
|
||||
doc->sprites().add(Sprite::MakeStdSprite(ImageSpec(ColorMode::INDEXED, 2, 2)));
|
||||
doc->sprite()->setTransparentColor(2); // Transparent color is index 2
|
||||
|
||||
@ -133,7 +133,7 @@ TEST(Render, DefaultBackgroundModeWithNonzeroTransparentIndex)
|
||||
|
||||
TEST(Render, CheckedBackground)
|
||||
{
|
||||
Document* doc = new Document;
|
||||
std::shared_ptr<Document> doc = std::make_shared<Document>();
|
||||
doc->sprites().add(Sprite::MakeStdSprite(ImageSpec(ColorMode::INDEXED, 4, 4)));
|
||||
|
||||
std::unique_ptr<Image> dst(Image::create(IMAGE_INDEXED, 4, 4));
|
||||
@ -185,7 +185,7 @@ TEST(Render, ZoomAndDstBounds)
|
||||
// 0 0 0
|
||||
// 0 4 4
|
||||
// 0 4 4
|
||||
Document* doc = new Document;
|
||||
std::shared_ptr<Document> doc = std::make_shared<Document>();
|
||||
doc->sprites().add(Sprite::MakeStdSprite(ImageSpec(ColorMode::INDEXED, 3, 3)));
|
||||
Image* src = doc->sprite()->root()->firstLayer()->cel(0)->image();
|
||||
clear_image(src, 0);
|
||||
@ -213,7 +213,7 @@ TEST(Render, ZoomAndDstBounds)
|
||||
|
||||
TEST(Render, BugWithMultiplesOf3ZoomFactors)
|
||||
{
|
||||
Document* doc = new Document;
|
||||
std::shared_ptr<Document> doc = std::make_shared<Document>();
|
||||
doc->sprites().add(Sprite::MakeStdSprite(ImageSpec(ColorMode::RGB, 4, 4)));
|
||||
Image* src = doc->sprite()->root()->firstLayer()->cel(0)->image();
|
||||
clear_image(src, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user