[core] Add image tests
This commit is contained in:
BIN
test/fixtures/image/no_profile.png
vendored
Normal file
BIN
test/fixtures/image/no_profile.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 82 B |
BIN
test/fixtures/image/no_profile_alpha.png
vendored
Normal file
BIN
test/fixtures/image/no_profile_alpha.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 82 B |
BIN
test/fixtures/image/profile.png
vendored
Normal file
BIN
test/fixtures/image/profile.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 83 B |
BIN
test/fixtures/image/profile_alpha.png
vendored
Normal file
BIN
test/fixtures/image/profile_alpha.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 83 B |
BIN
test/fixtures/image/tile.jpeg
vendored
Normal file
BIN
test/fixtures/image/tile.jpeg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
BIN
test/fixtures/image/tile.png
vendored
Normal file
BIN
test/fixtures/image/tile.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 48 KiB |
93
test/miscellaneous/image.cpp
Normal file
93
test/miscellaneous/image.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#include "../fixtures/util.hpp"
|
||||
|
||||
#include <mbgl/util/premultiply.hpp>
|
||||
#include <mbgl/util/image.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
TEST(Image, PNGRoundTrip) {
|
||||
UnassociatedImage rgba { 1, 1 };
|
||||
rgba.data[0] = 128;
|
||||
rgba.data[1] = 0;
|
||||
rgba.data[2] = 0;
|
||||
rgba.data[3] = 255;
|
||||
|
||||
PremultipliedImage image = decodeImage(encodePNG(rgba));
|
||||
EXPECT_EQ(128, image.data[0]);
|
||||
EXPECT_EQ(0, image.data[1]);
|
||||
EXPECT_EQ(0, image.data[2]);
|
||||
EXPECT_EQ(255, image.data[3]);
|
||||
}
|
||||
|
||||
TEST(Image, PNGRoundTripAlpha) {
|
||||
UnassociatedImage rgba { 1, 1 };
|
||||
rgba.data[0] = 128;
|
||||
rgba.data[1] = 0;
|
||||
rgba.data[2] = 0;
|
||||
rgba.data[3] = 128;
|
||||
|
||||
PremultipliedImage image = decodeImage(encodePNG(rgba));
|
||||
EXPECT_EQ(64, image.data[0]);
|
||||
EXPECT_EQ(0, image.data[1]);
|
||||
EXPECT_EQ(0, image.data[2]);
|
||||
EXPECT_EQ(128, image.data[3]);
|
||||
}
|
||||
|
||||
TEST(Image, PNGReadNoProfile) {
|
||||
PremultipliedImage image = decodeImage(util::read_file("test/fixtures/image/no_profile.png"));
|
||||
EXPECT_EQ(128, image.data[0]);
|
||||
EXPECT_EQ(0, image.data[1]);
|
||||
EXPECT_EQ(0, image.data[2]);
|
||||
EXPECT_EQ(255, image.data[3]);
|
||||
}
|
||||
|
||||
TEST(Image, PNGReadNoProfileAlpha) {
|
||||
PremultipliedImage image = decodeImage(util::read_file("test/fixtures/image/no_profile_alpha.png"));
|
||||
EXPECT_EQ(64, image.data[0]);
|
||||
EXPECT_EQ(0, image.data[1]);
|
||||
EXPECT_EQ(0, image.data[2]);
|
||||
EXPECT_EQ(128, image.data[3]);
|
||||
}
|
||||
|
||||
TEST(Image, PNGReadProfile) {
|
||||
PremultipliedImage image = decodeImage(util::read_file("test/fixtures/image/profile.png"));
|
||||
EXPECT_EQ(128, image.data[0]);
|
||||
EXPECT_EQ(0, image.data[1]);
|
||||
EXPECT_EQ(0, image.data[2]);
|
||||
EXPECT_EQ(255, image.data[3]);
|
||||
}
|
||||
|
||||
TEST(Image, PNGReadProfileAlpha) {
|
||||
PremultipliedImage image = decodeImage(util::read_file("test/fixtures/image/profile_alpha.png"));
|
||||
EXPECT_EQ(64, image.data[0]);
|
||||
EXPECT_EQ(0, image.data[1]);
|
||||
EXPECT_EQ(0, image.data[2]);
|
||||
EXPECT_EQ(128, image.data[3]);
|
||||
}
|
||||
|
||||
TEST(Image, PNGTile) {
|
||||
PremultipliedImage image = decodeImage(util::read_file("test/fixtures/image/tile.png"));
|
||||
EXPECT_EQ(256, image.width);
|
||||
EXPECT_EQ(256, image.height);
|
||||
}
|
||||
|
||||
TEST(Image, JPEGTile) {
|
||||
PremultipliedImage image = decodeImage(util::read_file("test/fixtures/image/tile.jpeg"));
|
||||
EXPECT_EQ(256, image.width);
|
||||
EXPECT_EQ(256, image.height);
|
||||
}
|
||||
|
||||
TEST(Image, Premultiply) {
|
||||
UnassociatedImage rgba { 1, 1 };
|
||||
rgba.data[0] = 255;
|
||||
rgba.data[1] = 254;
|
||||
rgba.data[2] = 253;
|
||||
rgba.data[3] = 128;
|
||||
|
||||
PremultipliedImage image = util::premultiply(std::move(rgba));
|
||||
EXPECT_EQ(128, image.data[0]);
|
||||
EXPECT_EQ(127, image.data[1]);
|
||||
EXPECT_EQ(127, image.data[2]);
|
||||
EXPECT_EQ(128, image.data[3]);
|
||||
}
|
||||
@@ -52,6 +52,7 @@
|
||||
'miscellaneous/enums.cpp',
|
||||
'miscellaneous/functions.cpp',
|
||||
'miscellaneous/geo.cpp',
|
||||
'miscellaneous/image.cpp',
|
||||
'miscellaneous/map.cpp',
|
||||
'miscellaneous/map_context.cpp',
|
||||
'miscellaneous/mapbox.cpp',
|
||||
|
||||
Reference in New Issue
Block a user