1
0
mirror of https://github.com/aseprite/aseprite.git synced 2025-04-15 11:42:30 +00:00
David Capello 413288a014 Improve flip_image() performance (x10 from old impl, x2 from new slow impl)
The old impl was using get/put_pixel(), the new slow one is using the
get/put_pixel_fast(), and the new default flip_image() is using just
raw pointers.

Added some utilites like random_image() for testing purposes, and
DOC_DISPATCH_BY_COLOR_MODE() macros to avoid switch/case for each
color mode. In a future these might use generic lambdas.
2023-08-02 17:35:20 -03:00

59 lines
1.7 KiB
C++

// Aseprite Document Library
// Copyright (c) 2023 Igara Studio S.A.
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#include "gtest/gtest.h"
#include "doc/algorithm/flip_image.h"
#include "doc/algorithm/random_image.h"
#include "doc/image.h"
#include "doc/image_ref.h"
#include "doc/primitives.h"
using namespace doc;
using namespace gfx;
TEST(Flip, Image)
{
for (auto pf : { IMAGE_RGB, IMAGE_GRAYSCALE, IMAGE_INDEXED, IMAGE_BITMAP, IMAGE_TILEMAP }) {
for (int h=2; h<200; h+=5) {
for (int w=2; w<200; w+=5) {
ImageRef a(Image::create(pf, w, h));
doc::algorithm::random_image(a.get());
// random_image() shouldn't generate a plain image
//ASSERT_FALSE(is_plain_image(a.get(), get_pixel(a.get(), 0, 0)));
ImageRef b(Image::createCopy(a.get()));
ImageRef c(Image::createCopy(a.get()));
ASSERT_TRUE(is_same_image(b.get(), c.get()));
for (auto ft : { doc::algorithm::FlipHorizontal,
doc::algorithm::FlipVertical }) {
doc::algorithm::flip_image(b.get(), b->bounds(), ft);
doc::algorithm::flip_image_slow(c.get(), c->bounds(), ft);
ASSERT_TRUE(is_same_image(b.get(), c.get()))
<< "Pixel format=" << pf << " Size=" << w << "x" << h
<< "\nFlip type=" << ft;
doc::algorithm::flip_image(b.get(), b->bounds(), ft);
doc::algorithm::flip_image_slow(c.get(), c->bounds(), ft);
ASSERT_TRUE(is_same_image(a.get(), b.get()));
ASSERT_TRUE(is_same_image(a.get(), c.get()));
}
}
}
}
}
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}