2013-08-31 22:31:38 +00:00
|
|
|
/* FasTC
|
|
|
|
* Copyright (c) 2013 University of North Carolina at Chapel Hill.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software and its
|
|
|
|
* documentation for educational, research, and non-profit purposes, without
|
|
|
|
* fee, and without a written agreement is hereby granted, provided that the
|
|
|
|
* above copyright notice, this paragraph, and the following four paragraphs
|
|
|
|
* appear in all copies.
|
|
|
|
*
|
|
|
|
* Permission to incorporate this software into commercial products may be
|
|
|
|
* obtained by contacting the authors or the Office of Technology Development
|
|
|
|
* at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
|
|
|
*
|
|
|
|
* This software program and documentation are copyrighted by the University of
|
|
|
|
* North Carolina at Chapel Hill. The software program and documentation are
|
|
|
|
* supplied "as is," without any accompanying services from the University of
|
|
|
|
* North Carolina at Chapel Hill or the authors. The University of North
|
|
|
|
* Carolina at Chapel Hill and the authors do not warrant that the operation of
|
|
|
|
* the program will be uninterrupted or error-free. The end-user understands
|
|
|
|
* that the program was developed for research purposes and is advised not to
|
|
|
|
* rely exclusively on the program for any reason.
|
|
|
|
*
|
|
|
|
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
|
|
|
* AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
|
|
|
* OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA
|
|
|
|
* AT CHAPEL HILL OR THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
|
|
|
*
|
|
|
|
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
|
|
|
|
* DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
|
|
|
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON
|
|
|
|
* AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND
|
|
|
|
* THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
|
|
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
*
|
|
|
|
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
|
|
|
*
|
|
|
|
* The authors may be contacted via:
|
|
|
|
*
|
|
|
|
* Pavel Krajcevski
|
|
|
|
* Dept of Computer Science
|
|
|
|
* 201 S Columbia St
|
|
|
|
* Frederick P. Brooks, Jr. Computer Science Bldg
|
|
|
|
* Chapel Hill, NC 27599-3175
|
|
|
|
* USA
|
|
|
|
*
|
|
|
|
* <http://gamma.cs.unc.edu/FasTC/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "Image.h"
|
|
|
|
#include "Pixel.h"
|
2013-09-06 06:02:34 +00:00
|
|
|
#include "TestUtils.h"
|
|
|
|
|
|
|
|
#include <cstdlib>
|
2013-08-31 22:31:38 +00:00
|
|
|
|
|
|
|
TEST(Image, NonSpecificConstructor) {
|
|
|
|
PVRTCC::Pixel p;
|
|
|
|
|
|
|
|
PVRTCC::Image img (4, 4);
|
2013-09-15 18:56:09 +00:00
|
|
|
for(uint32 i = 0; i < 4; i++) {
|
|
|
|
for(uint32 j = 0; j < 4; j++) {
|
2013-08-31 22:31:38 +00:00
|
|
|
EXPECT_TRUE(img(i, j) == p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Image, SpecificConstructor) {
|
|
|
|
PVRTCC::Pixel pxs[16];
|
2013-09-15 18:56:09 +00:00
|
|
|
for(uint32 i = 0; i < 4; i++) {
|
|
|
|
for(uint32 j = 0; j < 4; j++) {
|
2013-08-31 22:31:38 +00:00
|
|
|
pxs[j*4 + i].R() = i;
|
|
|
|
pxs[j*4 + i].G() = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PVRTCC::Image img(4, 4, pxs);
|
2013-09-15 18:56:09 +00:00
|
|
|
for(uint32 i = 0; i < 4; i++) {
|
|
|
|
for(uint32 j = 0; j < 4; j++) {
|
2013-08-31 22:31:38 +00:00
|
|
|
EXPECT_TRUE(img(i, j) == pxs[j*4 + i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Image, CopyConstructor) {
|
|
|
|
PVRTCC::Pixel pxs[16];
|
2013-09-15 18:56:09 +00:00
|
|
|
for(uint32 i = 0; i < 4; i++) {
|
|
|
|
for(uint32 j = 0; j < 4; j++) {
|
2013-08-31 22:31:38 +00:00
|
|
|
pxs[j*4 + i].R() = i;
|
|
|
|
pxs[j*4 + i].G() = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PVRTCC::Image img(4, 4, pxs);
|
|
|
|
PVRTCC::Image img2(img);
|
2013-09-15 18:56:09 +00:00
|
|
|
for(uint32 i = 0; i < 4; i++) {
|
|
|
|
for(uint32 j = 0; j < 4; j++) {
|
2013-08-31 22:31:38 +00:00
|
|
|
EXPECT_TRUE(img2(i, j) == pxs[j*4 + i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Image, AssignmentOperator) {
|
|
|
|
PVRTCC::Pixel pxs[16];
|
2013-09-15 18:56:09 +00:00
|
|
|
for(uint32 i = 0; i < 4; i++) {
|
|
|
|
for(uint32 j = 0; j < 4; j++) {
|
2013-08-31 22:31:38 +00:00
|
|
|
pxs[j*4 + i].R() = i;
|
|
|
|
pxs[j*4 + i].G() = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PVRTCC::Image img(4, 4, pxs);
|
|
|
|
PVRTCC::Image img2 = img;
|
2013-09-15 18:56:09 +00:00
|
|
|
for(uint32 i = 0; i < 4; i++) {
|
|
|
|
for(uint32 j = 0; j < 4; j++) {
|
2013-08-31 22:31:38 +00:00
|
|
|
EXPECT_TRUE(img2(i, j) == pxs[j*4 + i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Image, BilinearUpscale) {
|
|
|
|
PVRTCC::Pixel pxs[16];
|
2013-09-15 18:56:09 +00:00
|
|
|
for(uint32 i = 0; i < 4; i++) {
|
|
|
|
for(uint32 j = 0; j < 4; j++) {
|
2013-08-31 22:31:38 +00:00
|
|
|
pxs[j*4 + i].R() = i*2;
|
|
|
|
pxs[j*4 + i].G() = j*2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PVRTCC::Image img(4, 4, pxs);
|
2013-09-18 22:00:59 +00:00
|
|
|
img.BilinearUpscale(1, 1, PVRTCC::eWrapMode_Clamp);
|
2013-08-31 22:31:38 +00:00
|
|
|
EXPECT_EQ(img.GetWidth(), static_cast<uint32>(8));
|
|
|
|
EXPECT_EQ(img.GetHeight(), static_cast<uint32>(8));
|
|
|
|
|
|
|
|
for(uint32 i = 0; i < img.GetWidth(); i++) {
|
|
|
|
for(uint32 j = 0; j < img.GetHeight(); j++) {
|
|
|
|
if(i == 0) {
|
|
|
|
EXPECT_EQ(img(i, j).R(), i);
|
|
|
|
} else {
|
|
|
|
EXPECT_EQ(img(i, j).R(), i-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(j == 0) {
|
|
|
|
EXPECT_EQ(img(i, j).G(), j);
|
|
|
|
} else {
|
|
|
|
EXPECT_EQ(img(i, j).G(), j-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-06 06:02:34 +00:00
|
|
|
|
|
|
|
TEST(Image, BilinearUpscaleMaintainsPixels) {
|
|
|
|
|
|
|
|
srand(0xabd1ca7e);
|
|
|
|
|
|
|
|
const uint32 w = 4;
|
|
|
|
const uint32 h = 4;
|
|
|
|
|
|
|
|
PVRTCC::Pixel pxs[16];
|
2013-09-15 18:56:09 +00:00
|
|
|
for(uint32 i = 0; i < w; i++) {
|
|
|
|
for(uint32 j = 0; j < h; j++) {
|
2013-09-06 06:02:34 +00:00
|
|
|
pxs[j*w + i].R() = rand() % 256;
|
|
|
|
pxs[j*w + i].G() = rand() % 256;
|
|
|
|
pxs[j*w + i].B() = rand() % 256;
|
|
|
|
pxs[j*w + i].A() = rand() % 256;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PVRTCC::Image img(w, h, pxs);
|
2013-09-18 22:00:59 +00:00
|
|
|
img.BilinearUpscale(2, 2, PVRTCC::eWrapMode_Clamp);
|
2013-09-06 06:02:34 +00:00
|
|
|
EXPECT_EQ(img.GetWidth(), w << 2);
|
|
|
|
EXPECT_EQ(img.GetHeight(), h << 2);
|
|
|
|
|
|
|
|
for(uint32 i = 2; i < img.GetWidth(); i+=4) {
|
|
|
|
for(uint32 j = 2; j < img.GetHeight(); j+=4) {
|
|
|
|
PVRTCC::Pixel p = img(i, j);
|
|
|
|
uint32 idx = ((j - 2) / 4) * w + ((i-2)/4);
|
|
|
|
EXPECT_EQ(PixelPrinter(p.PackRGBA()), PixelPrinter(pxs[idx].PackRGBA()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-12 18:44:54 +00:00
|
|
|
|
|
|
|
TEST(Image, NonuniformBilinearUpscale) {
|
|
|
|
|
|
|
|
const uint32 kWidth = 4;
|
|
|
|
const uint32 kHeight = 8;
|
|
|
|
|
|
|
|
PVRTCC::Pixel pxs[kWidth * kHeight];
|
2013-09-15 18:56:09 +00:00
|
|
|
for(uint32 i = 0; i < kWidth; i++) {
|
|
|
|
for(uint32 j = 0; j < kHeight; j++) {
|
2013-09-12 18:44:54 +00:00
|
|
|
pxs[j*kWidth + i].R() = i*4;
|
|
|
|
pxs[j*kWidth + i].G() = j*2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PVRTCC::Image img(kHeight, kWidth, pxs);
|
2013-09-18 22:00:59 +00:00
|
|
|
img.BilinearUpscale(2, 1, PVRTCC::eWrapMode_Clamp);
|
2013-09-12 18:44:54 +00:00
|
|
|
EXPECT_EQ(img.GetWidth(), static_cast<uint32>(kWidth << 2));
|
|
|
|
EXPECT_EQ(img.GetHeight(), static_cast<uint32>(kHeight << 1));
|
|
|
|
|
|
|
|
for(uint32 i = 0; i < img.GetWidth(); i++) {
|
|
|
|
for(uint32 j = 0; j < img.GetHeight(); j++) {
|
|
|
|
if(i <= 2) {
|
|
|
|
EXPECT_EQ(img(i, j).R(), 0);
|
|
|
|
} else if(i == 15) {
|
|
|
|
EXPECT_EQ(img(i, j).R(), 12);
|
|
|
|
} else {
|
|
|
|
EXPECT_EQ(img(i, j).R(), i-2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(j == 0) {
|
|
|
|
EXPECT_EQ(img(i, j).G(), 0);
|
|
|
|
} else {
|
|
|
|
EXPECT_EQ(img(i, j).G(), j-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-31 22:31:38 +00:00
|
|
|
TEST(Image, BilinearUpscaleWrapped) {
|
|
|
|
PVRTCC::Pixel pxs[16];
|
2013-09-02 23:14:31 +00:00
|
|
|
|
|
|
|
// Make sure that our bit depth is less than full...
|
2013-09-15 18:56:09 +00:00
|
|
|
for(uint32 i = 0; i < 16; i++) {
|
2013-09-02 23:14:31 +00:00
|
|
|
const uint8 newBitDepth[4] = { 6, 5, 6, 5 };
|
|
|
|
pxs[i].ChangeBitDepth(newBitDepth);
|
|
|
|
}
|
|
|
|
|
2013-09-15 18:56:09 +00:00
|
|
|
for(uint32 i = 0; i < 4; i++) {
|
|
|
|
for(uint32 j = 0; j < 4; j++) {
|
2013-08-31 22:31:38 +00:00
|
|
|
pxs[j*4 + i].R() = i*4;
|
|
|
|
pxs[j*4 + i].G() = j*4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PVRTCC::Image img(4, 4, pxs);
|
2013-09-12 18:44:54 +00:00
|
|
|
img.BilinearUpscale(2, 2, PVRTCC::eWrapMode_Wrap);
|
2013-08-31 22:31:38 +00:00
|
|
|
EXPECT_EQ(img.GetWidth(), static_cast<uint32>(16));
|
|
|
|
EXPECT_EQ(img.GetHeight(), static_cast<uint32>(16));
|
|
|
|
|
|
|
|
for(uint32 i = 0; i < img.GetWidth(); i++) {
|
|
|
|
for(uint32 j = 0; j < img.GetHeight(); j++) {
|
|
|
|
const PVRTCC::Pixel &p = img(i, j);
|
2013-09-02 23:14:31 +00:00
|
|
|
|
|
|
|
// First make sure that the bit depth didn't change
|
|
|
|
uint8 depth[4];
|
|
|
|
p.GetBitDepth(depth);
|
|
|
|
EXPECT_EQ(depth[0], 6);
|
|
|
|
EXPECT_EQ(depth[1], 5);
|
|
|
|
EXPECT_EQ(depth[2], 6);
|
|
|
|
EXPECT_EQ(depth[3], 5);
|
|
|
|
|
|
|
|
// Now make sure that the values are correct.
|
2013-08-31 22:31:38 +00:00
|
|
|
if(i == 0) {
|
|
|
|
EXPECT_EQ(p.R(), 6);
|
|
|
|
} else if(i == 1) {
|
|
|
|
EXPECT_EQ(p.R(), 3);
|
|
|
|
} else if(i == 15) {
|
|
|
|
EXPECT_EQ(p.R(), 9);
|
|
|
|
} else {
|
|
|
|
EXPECT_EQ(p.R(), i-2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(j == 0) {
|
|
|
|
EXPECT_EQ(p.G(), 6);
|
|
|
|
} else if(j == 1) {
|
|
|
|
EXPECT_EQ(p.G(), 3);
|
|
|
|
} else if(j == 15) {
|
|
|
|
EXPECT_EQ(p.G(), 9);
|
|
|
|
} else {
|
|
|
|
EXPECT_EQ(p.G(), j-2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-03 18:12:41 +00:00
|
|
|
TEST(Image, AverageDownscale) {
|
|
|
|
PVRTCC::Image img(8, 8);
|
|
|
|
for(uint32 j = 0; j < img.GetHeight(); j++) {
|
|
|
|
for(uint32 i = 0; i < img.GetWidth(); i++) {
|
|
|
|
if((i ^ j) & 1) {
|
|
|
|
img(i, j) = PVRTCC::Pixel(0xFF000000);
|
|
|
|
} else {
|
|
|
|
img(i, j) = PVRTCC::Pixel(0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
img.AverageDownscale(1, 2);
|
|
|
|
EXPECT_EQ(img.GetWidth(), static_cast<uint32>(4));
|
|
|
|
EXPECT_EQ(img.GetHeight(), static_cast<uint32>(2));
|
|
|
|
|
|
|
|
for(uint32 j = 0; j < img.GetHeight(); j++) {
|
|
|
|
for(uint32 i = 0; i < img.GetWidth(); i++) {
|
|
|
|
EXPECT_EQ(PixelPrinter(0xFF7F7F7F), PixelPrinter(img(i, j).PackRGBA()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-19 21:47:36 +00:00
|
|
|
TEST(Image, ContentAwareDownscale) {
|
|
|
|
PVRTCC::Image img(8, 8);
|
|
|
|
for(uint32 j = 0; j < img.GetHeight(); j++) {
|
|
|
|
for(uint32 i = 0; i < img.GetWidth(); i++) {
|
|
|
|
if(j < 4) {
|
|
|
|
img(i, j) = PVRTCC::Pixel( 0xFF000000 );
|
|
|
|
} else {
|
|
|
|
img(i, j) = PVRTCC::Pixel( 0xFF0000FF );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
img.ContentAwareDownscale(1, 1);
|
|
|
|
EXPECT_EQ(img.GetWidth(), static_cast<uint32>(4));
|
|
|
|
EXPECT_EQ(img.GetHeight(), static_cast<uint32>(4));
|
|
|
|
|
|
|
|
for(uint32 j = 0; j < img.GetHeight(); j++) {
|
|
|
|
for(uint32 i = 0; i < img.GetWidth(); i++) {
|
|
|
|
if(j < 2) {
|
|
|
|
EXPECT_EQ(img(i, j).R(), 0);
|
|
|
|
} else {
|
|
|
|
EXPECT_EQ(img(i, j).R(), 255);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-31 22:31:38 +00:00
|
|
|
TEST(Image, ChangeBitDepth) {
|
|
|
|
PVRTCC::Image img(4, 4);
|
|
|
|
|
|
|
|
uint8 testDepth[4] = { 2, 3, 5, 0 };
|
|
|
|
img.ChangeBitDepth(testDepth);
|
|
|
|
|
|
|
|
uint8 depth[4];
|
|
|
|
for(uint32 j = 0; j < img.GetHeight(); j++) {
|
|
|
|
for(uint32 i = 0; i < img.GetWidth(); i++) {
|
|
|
|
img(i, j).GetBitDepth(depth);
|
|
|
|
|
|
|
|
for(int d = 0; d < 4; d++) {
|
|
|
|
EXPECT_EQ(testDepth[d], depth[d]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|