summaryrefslogtreecommitdiffstats
path: root/o3d
diff options
context:
space:
mode:
Diffstat (limited to 'o3d')
-rw-r--r--o3d/core/cross/bitmap_png.cc5
-rw-r--r--o3d/core/cross/bitmap_test.cc59
-rw-r--r--o3d/tests/bitmap_test/png-20x14-4bit-palette.pngbin0 -> 267 bytes
-rw-r--r--o3d/tests/bitmap_test/png-256x256-32bit.pngbin52154 -> 74812 bytes
4 files changed, 58 insertions, 6 deletions
diff --git a/o3d/core/cross/bitmap_png.cc b/o3d/core/cross/bitmap_png.cc
index de86a5d..ea8a9ac 100644
--- a/o3d/core/cross/bitmap_png.cc
+++ b/o3d/core/cross/bitmap_png.cc
@@ -164,9 +164,8 @@ bool Bitmap::LoadFromPNGStream(MemoryReadStream *stream,
if (png_color_type == PNG_COLOR_TYPE_PALETTE) {
// Expand paletted colors into RGB{A} triplets
png_set_palette_to_rgb(png_ptr);
- }
// Gray vs RGB.
- if ((png_color_type & PNG_COLOR_MASK_COLOR) == PNG_COLOR_TYPE_RGB) {
+ } else if ((png_color_type & PNG_COLOR_MASK_COLOR) == PNG_COLOR_TYPE_RGB) {
if (png_bits_per_channel != 8) {
png_error(png_ptr, "PNG image type not recognized");
}
@@ -176,7 +175,7 @@ bool Bitmap::LoadFromPNGStream(MemoryReadStream *stream,
png_error(png_ptr, "PNG image type not recognized");
}
// Expand grayscale images to the full 8 bits from 2, or 4 bits/pixel
- // TODO: Do we want to expose L/A/LA texture formats ?
+ // TODO(o3d): Do we want to expose L/A/LA texture formats ?
png_set_gray_1_2_4_to_8(png_ptr);
png_set_gray_to_rgb(png_ptr);
}
diff --git a/o3d/core/cross/bitmap_test.cc b/o3d/core/cross/bitmap_test.cc
index 0a3e5c4..0c3766d 100644
--- a/o3d/core/cross/bitmap_test.cc
+++ b/o3d/core/cross/bitmap_test.cc
@@ -137,6 +137,25 @@ static unsigned char kpng256x256_24bit_interlaced_BGRX[128] = {
0x1d, 0x8d, 0x96, 0xff, 0x1b, 0x8f, 0x90, 0xff,
};
+static unsigned char kpng256x256_32bit_BGRA[128] = {
+ 0x36, 0x87, 0xbc, 0xd4, 0x36, 0x87, 0xbc, 0xfa,
+ 0x35, 0x83, 0xb5, 0xff, 0x34, 0x83, 0xb5, 0xfe,
+ 0x35, 0x83, 0xb5, 0xf3, 0x35, 0x82, 0xb5, 0xcf,
+ 0x35, 0x82, 0xb4, 0x9a, 0x35, 0x82, 0xb4, 0x75,
+ 0x35, 0x82, 0xb4, 0x67, 0x35, 0x82, 0xb4, 0x7d,
+ 0x35, 0x82, 0xb4, 0xa8, 0x35, 0x82, 0xb4, 0xdd,
+ 0x35, 0x82, 0xb4, 0xf7, 0x35, 0x82, 0xb4, 0xff,
+ 0x35, 0x82, 0xb4, 0xff, 0x35, 0x82, 0xb4, 0xf8,
+ 0x35, 0x82, 0xb4, 0xaf, 0x35, 0x82, 0xb4, 0x68,
+ 0x35, 0x83, 0xb5, 0x5a, 0x37, 0x85, 0xb8, 0x6a,
+ 0x36, 0x85, 0xb8, 0xaf, 0x35, 0x86, 0xb7, 0xf8,
+ 0x35, 0x87, 0xb7, 0xff, 0x35, 0x88, 0xb7, 0xff,
+ 0x35, 0x89, 0xb7, 0xff, 0x34, 0x8a, 0xb7, 0xff,
+ 0x34, 0x8b, 0xb7, 0xff, 0x32, 0x8c, 0xb5, 0xff,
+ 0x31, 0x8c, 0xb1, 0xff, 0x2f, 0x8d, 0xaf, 0xff,
+ 0x1d, 0x8d, 0x96, 0xff, 0x1b, 0x8f, 0x90, 0xff,
+};
+
static unsigned char kpng256x256_8bit_palette_BGRX[128] = {
0x36, 0x89, 0xbb, 0xff, 0x36, 0x89, 0xbb, 0xff,
0x35, 0x81, 0xb5, 0xff, 0x32, 0x84, 0xb5, 0xff,
@@ -156,6 +175,25 @@ static unsigned char kpng256x256_8bit_palette_BGRX[128] = {
0x1f, 0x8d, 0x91, 0xff, 0x1f, 0x8d, 0x91, 0xff,
};
+static unsigned char kpng20x14_4bit_palette_BGRX[128] = {
+ 0xed, 0xed, 0xed, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xed, 0xed, 0xed, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0x54, 0x54, 0x54, 0xff,
+ 0x33, 0x33, 0x33, 0xff, 0x33, 0x33, 0x33, 0xff,
+ 0x33, 0x33, 0x33, 0xff, 0x33, 0x33, 0x33, 0xff,
+ 0x33, 0x33, 0x33, 0xff, 0x33, 0x33, 0x33, 0xff,
+ 0x33, 0x33, 0x33, 0xff, 0x33, 0x33, 0x33, 0xff,
+ 0x54, 0x54, 0x54, 0xff, 0x33, 0x33, 0x33, 0xff,
+};
+
static unsigned char kdxt1_256x256[128] = {
0x47, 0xbc, 0x06, 0xb4, 0x5a, 0x6a, 0x6a, 0xea,
0x27, 0xb4, 0x06, 0xb4, 0x57, 0x57, 0x57, 0x5e,
@@ -413,8 +451,6 @@ TEST_F(BitmapTest, LoadPNGFile24bitInterlaced) {
EXPECT_TRUE(TestBitmapData(bitmap, kpng256x256_24bit_interlaced_BGRX));
}
-// NOTE: unable to get Photoshop to export an PNG file with alpha.
-/*
TEST_F(BitmapTest, LoadPNGFile32bit) {
String filename = *g_program_path + "/bitmap_test/png-256x256-32bit.png";
FilePath filepath = UTF8ToFilePath(filename);
@@ -426,8 +462,8 @@ TEST_F(BitmapTest, LoadPNGFile32bit) {
EXPECT_EQ(256, bitmap.width());
EXPECT_EQ(256, bitmap.height());
EXPECT_EQ(1, bitmap.num_mipmaps());
+ EXPECT_TRUE(TestBitmapData(bitmap, kpng256x256_32bit_BGRA));
}
-*/
// Loads a palettized PNG file, checks it against the known data.
TEST_F(BitmapTest, LoadPNGFile8bitPalette) {
@@ -445,6 +481,23 @@ TEST_F(BitmapTest, LoadPNGFile8bitPalette) {
EXPECT_TRUE(TestBitmapData(bitmap, kpng256x256_8bit_palette_BGRX));
}
+// Loads a palettized PNG file, checks it against the known data.
+TEST_F(BitmapTest, LoadPNGFile4bitPalette) {
+ String filename = *g_program_path +
+ "/bitmap_test/png-20x14-4bit-palette.png";
+ FilePath filepath = UTF8ToFilePath(filename);
+ Bitmap bitmap;
+ EXPECT_TRUE(bitmap.LoadFromFile(filepath, Bitmap::PNG, false));
+ EXPECT_TRUE(bitmap.image_data() != NULL);
+ EXPECT_FALSE(bitmap.is_cubemap());
+ EXPECT_EQ(Texture::XRGB8, bitmap.format());
+ EXPECT_EQ(20, bitmap.width());
+ EXPECT_EQ(14, bitmap.height());
+ EXPECT_EQ(1, bitmap.num_mipmaps());
+ EXPECT_TRUE(TestBitmapData(bitmap, kpng20x14_4bit_palette_BGRX));
+}
+
+
// Tries to load a 5kx5k PNG file, which should fail.
TEST_F(BitmapTest, LoadPNGFileTooLarge) {
String filename = *g_program_path + "/bitmap_test/5kx5k.png";
diff --git a/o3d/tests/bitmap_test/png-20x14-4bit-palette.png b/o3d/tests/bitmap_test/png-20x14-4bit-palette.png
new file mode 100644
index 0000000..3f04186
--- /dev/null
+++ b/o3d/tests/bitmap_test/png-20x14-4bit-palette.png
Binary files differ
diff --git a/o3d/tests/bitmap_test/png-256x256-32bit.png b/o3d/tests/bitmap_test/png-256x256-32bit.png
index 8f858f9..3ed12c2 100644
--- a/o3d/tests/bitmap_test/png-256x256-32bit.png
+++ b/o3d/tests/bitmap_test/png-256x256-32bit.png
Binary files differ