mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2025-01-09 15:15:38 +00:00
Merge SplitCoreLibrary
This commit is contained in:
commit
3e35fb2c0d
|
@ -52,12 +52,23 @@
|
||||||
SET( SOURCES
|
SET( SOURCES
|
||||||
"src/Image.cpp"
|
"src/Image.cpp"
|
||||||
"src/CompressionJob.cpp"
|
"src/CompressionJob.cpp"
|
||||||
|
"src/Pixel.cpp"
|
||||||
|
"src/Color.cpp"
|
||||||
)
|
)
|
||||||
|
|
||||||
SET( HEADERS
|
SET( HEADERS
|
||||||
"include/TexCompTypes.h"
|
"include/TexCompTypes.h"
|
||||||
"include/Image.h"
|
"include/Image.h"
|
||||||
|
"include/Color.h"
|
||||||
"include/CompressionJob.h"
|
"include/CompressionJob.h"
|
||||||
|
"include/Pixel.h"
|
||||||
|
"include/VectorBase.h"
|
||||||
|
"include/Vector2.h"
|
||||||
|
"include/Vector3.h"
|
||||||
|
"include/Vector4.h"
|
||||||
|
"include/MatrixBase.h"
|
||||||
|
"include/MatrixSquare.h"
|
||||||
|
"include/Matrix3x3.h"
|
||||||
)
|
)
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(${FasTC_SOURCE_DIR}/Base/include)
|
INCLUDE_DIRECTORIES(${FasTC_SOURCE_DIR}/Base/include)
|
||||||
|
|
101
Base/include/Color.h
Normal file
101
Base/include/Color.h
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
/* 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/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BASE_INCLUDE_COLOR_H_
|
||||||
|
#define BASE_INCLUDE_COLOR_H_
|
||||||
|
|
||||||
|
#include "TexCompTypes.h"
|
||||||
|
#include "Vector4.h"
|
||||||
|
|
||||||
|
namespace FasTC {
|
||||||
|
|
||||||
|
class Color : public Vec4f {
|
||||||
|
public:
|
||||||
|
Color(float r, float g, float b, float a) : Vec4f(a, r, g, b) { }
|
||||||
|
Color() : Vec4f(0, 0, 0, 0) { }
|
||||||
|
|
||||||
|
// Let's allow us to use the operators...
|
||||||
|
template<typename T>
|
||||||
|
Color &operator=(const Vector4<T> &other) {
|
||||||
|
Vec4f::operator=(other);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Color(const Vector4<T> &other) : Vec4f(other) { }
|
||||||
|
|
||||||
|
const float &A() const { return vec[0]; }
|
||||||
|
float &A() { return vec[0]; }
|
||||||
|
const float &R() const { return vec[1]; }
|
||||||
|
float &R() { return vec[1]; }
|
||||||
|
const float &G() const { return vec[2]; }
|
||||||
|
float &G() { return vec[2]; }
|
||||||
|
const float &B() const { return vec[3]; }
|
||||||
|
float &B() { return vec[3]; }
|
||||||
|
const float &Component(uint32 idx) const { return vec[idx]; }
|
||||||
|
float &Component(uint32 idx) { return vec[idx]; }
|
||||||
|
|
||||||
|
// Take all of the components, transform them to their 8-bit variants,
|
||||||
|
// and then pack each channel into an R8G8B8A8 32-bit integer. We assume
|
||||||
|
// that the architecture is little-endian, so the alpha channel will end
|
||||||
|
// up in the most-significant byte.
|
||||||
|
uint32 Pack() const;
|
||||||
|
void Unpack(uint32 rgba);
|
||||||
|
|
||||||
|
// Tests for equality by comparing the values and the bit depths.
|
||||||
|
bool operator==(const Color &) const;
|
||||||
|
};
|
||||||
|
REGISTER_VECTOR_TYPE(Color);
|
||||||
|
|
||||||
|
} // namespace FasTC
|
||||||
|
|
||||||
|
#endif // BASE_INCLUDE_COLOR_H_
|
|
@ -41,29 +41,48 @@
|
||||||
* <http://gamma.cs.unc.edu/FasTC/>
|
* <http://gamma.cs.unc.edu/FasTC/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TEXCOMP_IMAGE_H__
|
#ifndef FASTC_BASE_INCLUDE_IMAGE_H_
|
||||||
#define __TEXCOMP_IMAGE_H__
|
#define FASTC_BASE_INCLUDE_IMAGE_H_
|
||||||
|
|
||||||
#include "TexCompTypes.h"
|
#include "TexCompTypes.h"
|
||||||
|
#include "ImageFwd.h"
|
||||||
|
|
||||||
|
namespace FasTC {
|
||||||
|
|
||||||
|
template<typename U, typename V>
|
||||||
|
extern double ComputePSNR(Image<U> *img1, Image<V> *img2);
|
||||||
|
|
||||||
|
// Forward declare
|
||||||
|
template<typename PixelType>
|
||||||
class Image {
|
class Image {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Image(uint32 width, uint32 height);
|
||||||
|
Image(uint32 width, uint32 height,
|
||||||
|
const PixelType *pixels,
|
||||||
|
bool bBlockStreamOrder = false);
|
||||||
Image(uint32 width, uint32 height,
|
Image(uint32 width, uint32 height,
|
||||||
const uint32 *pixels,
|
const uint32 *pixels,
|
||||||
bool bBlockStreamOrder = false);
|
bool bBlockStreamOrder = false);
|
||||||
Image(const Image &);
|
Image(const Image<PixelType> &);
|
||||||
Image &operator=(const Image &);
|
Image &operator=(const Image<PixelType> &);
|
||||||
virtual ~Image();
|
virtual ~Image();
|
||||||
|
|
||||||
virtual Image *Clone() const {
|
virtual Image *Clone() const {
|
||||||
return new Image(*this);
|
return new Image(*this);
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint8 *RawData() const { return m_Data; }
|
PixelType &operator()(uint32 i, uint32 j);
|
||||||
|
const PixelType &operator()(uint32 i, uint32 j) const;
|
||||||
|
|
||||||
|
// Reads a buffer full of pixels and stores them in the
|
||||||
|
// data associated with this image.
|
||||||
|
virtual bool ReadPixels(const uint32 *rgba);
|
||||||
|
const PixelType *GetPixels() const { return m_Pixels; }
|
||||||
|
|
||||||
uint32 GetWidth() const { return m_Width; }
|
uint32 GetWidth() const { return m_Width; }
|
||||||
uint32 GetHeight() const { return m_Height; }
|
uint32 GetHeight() const { return m_Height; }
|
||||||
|
uint32 GetNumPixels() const { return GetWidth() * GetHeight(); }
|
||||||
|
|
||||||
void SetBlockStreamOrder(bool flag) {
|
void SetBlockStreamOrder(bool flag) {
|
||||||
if(flag) {
|
if(flag) {
|
||||||
|
@ -74,25 +93,34 @@ class Image {
|
||||||
}
|
}
|
||||||
bool GetBlockStreamOrder() const { return m_bBlockStreamOrder; }
|
bool GetBlockStreamOrder() const { return m_bBlockStreamOrder; }
|
||||||
|
|
||||||
double ComputePSNR(Image *other);
|
template<typename OtherPixelType>
|
||||||
|
double ComputePSNR(Image<OtherPixelType> *other) {
|
||||||
virtual void ComputeRGBA() { }
|
return FasTC::ComputePSNR(this, other);
|
||||||
virtual const uint32 *GetRGBA() const {
|
|
||||||
return reinterpret_cast<const uint32 *>(RawData());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to allow derived classes to populate the pixel array.
|
||||||
|
// This may involve decompressing a compressed image or otherwise
|
||||||
|
// processing some data in order to populate the m_Pixels pointer.
|
||||||
|
// This function should use SetImageData in order to set all of the
|
||||||
|
// appropriate pixels.
|
||||||
|
virtual void ComputePixels() { }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32 m_Width;
|
uint32 m_Width;
|
||||||
uint32 m_Height;
|
uint32 m_Height;
|
||||||
|
|
||||||
bool m_bBlockStreamOrder;
|
bool m_bBlockStreamOrder;
|
||||||
|
|
||||||
|
PixelType *m_Pixels;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32 m_DataSz;
|
|
||||||
uint8 *m_Data;
|
void SetImageData(uint32 width, uint32 height, PixelType *data);
|
||||||
|
|
||||||
void ConvertToBlockStreamOrder();
|
void ConvertToBlockStreamOrder();
|
||||||
void ConvertFromBlockStreamOrder();
|
void ConvertFromBlockStreamOrder();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace FasTC
|
||||||
|
|
||||||
#endif // __TEXCOMP_IMAGE_H__
|
#endif // __TEXCOMP_IMAGE_H__
|
||||||
|
|
63
Base/include/ImageFwd.h
Normal file
63
Base/include/ImageFwd.h
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/* 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/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FASTC_BASE_INCLUDE_IMAGEFWD_H_
|
||||||
|
#define FASTC_BASE_INCLUDE_IMAGEFWD_H_
|
||||||
|
|
||||||
|
#include "TexCompTypes.h"
|
||||||
|
|
||||||
|
namespace FasTC {
|
||||||
|
class Pixel;
|
||||||
|
template<typename PixelType = Pixel> class Image;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // FASTC_BASE_INCLUDE_IMAGEFWD_H_
|
47
Base/include/Matrix3x3.h
Normal file
47
Base/include/Matrix3x3.h
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2012 Pavel Krajcevski
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef BASE_INCLUDE_MATRIX3X3_H_
|
||||||
|
#define BASE_INCLUDE_MATRIX3X3_H_
|
||||||
|
|
||||||
|
#include "MatrixSquare.h"
|
||||||
|
|
||||||
|
namespace FasTC {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class Matrix3x3 : public MatrixSquare<T, 3> {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
Matrix3x3() { }
|
||||||
|
Matrix3x3(const MatrixSquare<T, 3> &other) {
|
||||||
|
for(int i = 0; i < kNumElements; i++) {
|
||||||
|
mat[i] = other[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BASE_INCLUDE_MATRIX3X3_H_
|
191
Base/include/MatrixBase.h
Normal file
191
Base/include/MatrixBase.h
Normal file
|
@ -0,0 +1,191 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2012 Pavel Krajcevski
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef BASE_INCLUDE_MATRIXBASE_H__
|
||||||
|
#define BASE_INCLUDE_MATRIXBASE_H__
|
||||||
|
|
||||||
|
#include "VectorBase.h"
|
||||||
|
|
||||||
|
namespace FasTC {
|
||||||
|
|
||||||
|
template <typename T, const int nRows, const int nCols>
|
||||||
|
class MatrixBase {
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Vector representation
|
||||||
|
static const int kNumElements = nRows * nCols;
|
||||||
|
T mat[kNumElements];
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
MatrixBase() { }
|
||||||
|
MatrixBase(const MatrixBase<T, nRows, nCols> &other) {
|
||||||
|
for(int i = 0; i < kNumElements; i++) {
|
||||||
|
mat[i] = other[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accessors
|
||||||
|
T &operator()(int idx) { return mat[idx]; }
|
||||||
|
const T &operator()(int idx) const { return mat[idx]; }
|
||||||
|
T &operator()(int r, int c) { return mat[r * nCols + c]; }
|
||||||
|
const T &operator() const (int r, int c) { return mat[r * nCols + c]; }
|
||||||
|
|
||||||
|
T &operator[](int idx) { return mat[idx]; }
|
||||||
|
const T &operator[](int idx) const { return mat[idx]; }
|
||||||
|
|
||||||
|
// Operators
|
||||||
|
template<typename _T>
|
||||||
|
MatrixBase<T, nRows, nCols> operator+(const MatrixBase<_T, nRows, nCols> &m) {
|
||||||
|
MatrixBase<T, nRows, nCols> a;
|
||||||
|
for(int i = 0; i < kNumElements; i++) {
|
||||||
|
a[i] = mat[i] + m[i];
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _T>
|
||||||
|
MatrixBase<T, nRows, nCols> &operator+=(const MatrixBase<_T, nRows, nCols> &m) {
|
||||||
|
for(int i = 0; i < kNumElements; i++) {
|
||||||
|
mat[i] += m[i];
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _T>
|
||||||
|
MatrixBase<T, nRows, nCols> operator-(const MatrixBase<_T, nRows, nCols> &m) {
|
||||||
|
MatrixBase<T, nRows, nCols> a;
|
||||||
|
for(int i = 0; i < kNumElements; i++) {
|
||||||
|
a[i] = mat[i] - m[i];
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _T>
|
||||||
|
MatrixBase<T, nRows, nCols> &operator-=(const MatrixBase<_T, nRows, nCols> &m) {
|
||||||
|
for(int i = 0; i < kNumElements; i++) {
|
||||||
|
mat[i] -= m[i];
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _T>
|
||||||
|
MatrixBase<T, nRows, nCols> operator*(_T s) {
|
||||||
|
MatrixBase<T, nRows, nCols> a;
|
||||||
|
for(int i = 0; i < kNumElements; i++) {
|
||||||
|
a[i] = mat[i] * s;
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _T>
|
||||||
|
MatrixBase<T, nRows, nCols> &operator*=(_T s) {
|
||||||
|
for(int i = 0; i < kNumElements; i++) {
|
||||||
|
mat[i] *= s;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _T>
|
||||||
|
MatrixBase<T, nRows, nCols> operator/(_T s) {
|
||||||
|
MatrixBase<T, nRows, nCols> a;
|
||||||
|
for(int i = 0; i < kNumElements; i++) {
|
||||||
|
a[i] = mat[i] / s;
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _T>
|
||||||
|
MatrixBase<T, nRows, nCols> &operator/=(_T s) {
|
||||||
|
for(int i = 0; i < kNumElements; i++) {
|
||||||
|
mat[i] /= s;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Matrix multiplication
|
||||||
|
template<typename _T, const int nTarget>
|
||||||
|
MatrixBase<T, nRows, nTarget> operator*(const MatrixBase<_T, nCols, nTarget> &m) {
|
||||||
|
MatrixBase<T, nRows, nTarget> result;
|
||||||
|
for(int r = 0; r < nRows; r++)
|
||||||
|
for(int c = 0; c < nTarget; c++) {
|
||||||
|
result(r, c) = 0;
|
||||||
|
for(int j = 0; j < nCols; j++) {
|
||||||
|
result(r, c) += (*this)(r, j) * m(j, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vector multiplication -- treat vectors as Nx1 matrices...
|
||||||
|
template<typename _T>
|
||||||
|
VectorBase<T, nCols> operator*(const VectorBase<_T, nCols> &v) {
|
||||||
|
VectorBase<T, nCols> result;
|
||||||
|
for(int r = 0; r < nRows; r++) {
|
||||||
|
result(r) = 0;
|
||||||
|
for(int j = 0; j < nCols; j++) {
|
||||||
|
result(r) += (*this)(r, j) * v(j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Outer product...
|
||||||
|
template<typename _T, typename _U, const int N, const int M>
|
||||||
|
friend MatrixBase<_T, N, M> operator^(
|
||||||
|
const VectorBase<_T, N> &a,
|
||||||
|
const VectorBase<_U, M> &b
|
||||||
|
) {
|
||||||
|
MatrixBase<_T, N, M> result;
|
||||||
|
|
||||||
|
for(int i = 0; i < N; i++)
|
||||||
|
for(int j = 0; j < M; j++)
|
||||||
|
result(i, j) = a[i] * b[j];
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _T, typename _U, const int N, const int M>
|
||||||
|
friend MatrixBase<_T, N, M> OuterProduct(
|
||||||
|
const VectorBase<_T, N> &a,
|
||||||
|
const VectorBase<_U, M> &b
|
||||||
|
) {
|
||||||
|
return a ^ b;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Double dot product
|
||||||
|
template<typename _T>
|
||||||
|
T DDot(const MatrixBase<_T, nRows, nCols> &m) {
|
||||||
|
T result = 0;
|
||||||
|
for(int i = 0; i < kNumElements; i++) {
|
||||||
|
result += mat[i] * m[i];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BASE_INCLUDE_MATRIXBASE_H_
|
46
Base/include/MatrixSquare.h
Normal file
46
Base/include/MatrixSquare.h
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2012 Pavel Krajcevski
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef BASE_INCLUDE_MATRIXSQUARE_H_
|
||||||
|
#define BASE_INCLUDE_MATRIXSQUARE_H_
|
||||||
|
|
||||||
|
#include "MatrixBase.h"
|
||||||
|
|
||||||
|
namespace FasTC {
|
||||||
|
|
||||||
|
template <typename T, const int N>
|
||||||
|
class MatrixSquare : public MatrixBase<T, N, N> {
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
MatrixSquare() { }
|
||||||
|
MatrixSquare(const MatrixBase<T, N, N> &other) {
|
||||||
|
for(int i = 0; i < kNumElements; i++) {
|
||||||
|
mat[i] = other[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BASE_INCLUDE_MATRIXSQUARE_H_
|
|
@ -50,27 +50,35 @@
|
||||||
* <http://gamma.cs.unc.edu/FasTC/>
|
* <http://gamma.cs.unc.edu/FasTC/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PVRTCENCODER_SRC_PIXEL_H_
|
#ifndef BASE_INCLUDE_PIXEL_H_
|
||||||
#define PVRTCENCODER_SRC_PIXEL_H_
|
#define BASE_INCLUDE_PIXEL_H_
|
||||||
|
|
||||||
#include "TexCompTypes.h"
|
#include "TexCompTypes.h"
|
||||||
|
#include "Vector4.h"
|
||||||
|
|
||||||
namespace PVRTCC {
|
namespace FasTC {
|
||||||
|
|
||||||
|
class Pixel : public Vector4<uint16> {
|
||||||
|
private:
|
||||||
|
typedef uint16 ChannelType;
|
||||||
|
typedef Vector4<ChannelType> VectorType;
|
||||||
|
uint8 m_BitDepth[4];
|
||||||
|
|
||||||
class Pixel {
|
|
||||||
public:
|
public:
|
||||||
Pixel(): m_A(0), m_R(0), m_G(0), m_B(0) {
|
Pixel() : VectorType(0, 0, 0, 0) {
|
||||||
for(int i = 0; i < 4; i++) m_BitDepth[i] = 8;
|
for(int i = 0; i < 4; i++)
|
||||||
|
m_BitDepth[i] = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit Pixel(uint32 rgba) {
|
explicit Pixel(uint32 rgba) : VectorType() {
|
||||||
for(int i = 0; i < 4; i++) m_BitDepth[i] = 8;
|
for(int i = 0; i < 4; i++)
|
||||||
UnpackRGBA(rgba);
|
m_BitDepth[i] = 8;
|
||||||
|
Unpack(rgba);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pixel(const uint8 *bits,
|
Pixel(const uint8 *bits,
|
||||||
const uint8 channelDepth[4] = static_cast<uint8 *>(0),
|
const uint8 channelDepth[4] = static_cast<uint8 *>(0),
|
||||||
uint8 bitOffset = 0) {
|
uint8 bitOffset = 0) : VectorType() {
|
||||||
FromBits(bits, channelDepth, bitOffset);
|
FromBits(bits, channelDepth, bitOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,18 +116,18 @@ class Pixel {
|
||||||
|
|
||||||
// Changes the bit depth of a single component. See the comment
|
// Changes the bit depth of a single component. See the comment
|
||||||
// above for how we do this.
|
// above for how we do this.
|
||||||
static uint8 ChangeBitDepth(uint8 val, uint8 oldDepth, uint8 newDepth);
|
static ChannelType ChangeBitDepth(ChannelType val, uint8 oldDepth, uint8 newDepth);
|
||||||
|
|
||||||
const uint8 &A() const { return m_A; }
|
const ChannelType &A() const { return X(); }
|
||||||
uint8 &A() { return m_A; }
|
ChannelType &A() { return X(); }
|
||||||
const uint8 &R() const { return m_R; }
|
const ChannelType &R() const { return Y(); }
|
||||||
uint8 &R() { return m_R; }
|
ChannelType &R() { return Y(); }
|
||||||
const uint8 &G() const { return m_G; }
|
const ChannelType &G() const { return Z(); }
|
||||||
uint8 &G() { return m_G; }
|
ChannelType &G() { return Z(); }
|
||||||
const uint8 &B() const { return m_B; }
|
const ChannelType &B() const { return W(); }
|
||||||
uint8 &B() { return m_B; }
|
ChannelType &B() { return W(); }
|
||||||
const uint8 &Component(uint32 idx) const { return m_Component[idx]; }
|
const ChannelType &Component(uint32 idx) const { return vec[idx]; }
|
||||||
uint8 &Component(uint32 idx) { return m_Component[idx]; }
|
ChannelType &Component(uint32 idx) { return vec[idx]; }
|
||||||
|
|
||||||
void GetBitDepth(uint8 (&outDepth)[4]) const {
|
void GetBitDepth(uint8 (&outDepth)[4]) const {
|
||||||
for(int i = 0; i < 4; i++) {
|
for(int i = 0; i < 4; i++) {
|
||||||
|
@ -131,27 +139,49 @@ class Pixel {
|
||||||
// and then pack each channel into an R8G8B8A8 32-bit integer. We assume
|
// and then pack each channel into an R8G8B8A8 32-bit integer. We assume
|
||||||
// that the architecture is little-endian, so the alpha channel will end
|
// that the architecture is little-endian, so the alpha channel will end
|
||||||
// up in the most-significant byte.
|
// up in the most-significant byte.
|
||||||
uint32 PackRGBA() const;
|
uint32 Pack() const;
|
||||||
void UnpackRGBA(uint32 rgba);
|
void Unpack(uint32 rgba);
|
||||||
|
|
||||||
// Tests for equality by comparing the values and the bit depths.
|
// Tests for equality by comparing the values and the bit depths.
|
||||||
bool operator==(const Pixel &) const;
|
bool operator==(const Pixel &) const;
|
||||||
|
|
||||||
private:
|
|
||||||
union {
|
|
||||||
struct {
|
|
||||||
uint8 m_A;
|
|
||||||
uint8 m_R;
|
|
||||||
uint8 m_G;
|
|
||||||
uint8 m_B;
|
|
||||||
};
|
|
||||||
uint8 m_Component[4];
|
|
||||||
};
|
};
|
||||||
|
REGISTER_VECTOR_TYPE(Pixel);
|
||||||
|
|
||||||
// This contains the number of bits that each pixel has.
|
// Overload operators so that we can preserve bit depths...
|
||||||
uint8 m_BitDepth[4];
|
template<typename ScalarType>
|
||||||
};
|
static inline Pixel ScalarMultiply(const Pixel &p, const ScalarType &s) {
|
||||||
|
Pixel a(p);
|
||||||
|
for(int i = 0; i < Pixel::Size; i++)
|
||||||
|
a(i) = p(i) * s;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace PVRTCC
|
template<typename ScalarType>
|
||||||
|
static inline Pixel ScalarDivide(const Pixel &p, const ScalarType &s) {
|
||||||
|
Pixel a(p);
|
||||||
|
for(int i = 0; i < Pixel::Size; i++)
|
||||||
|
a(i) = p(i) / s;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // PVRTCENCODER_SRC_PIXEL_H_
|
template<typename VectorType>
|
||||||
|
static inline Pixel VectorAddition(const Pixel &p, const VectorType &v) {
|
||||||
|
Pixel a(p);
|
||||||
|
for(int i = 0; i < Pixel::Size; i++) {
|
||||||
|
a(i) += v(i);
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename VectorType>
|
||||||
|
static inline Pixel VectorSubtraction(const Pixel &p, const VectorType &v) {
|
||||||
|
Pixel a(p);
|
||||||
|
for(int i = 0; i < Pixel::Size; i++) {
|
||||||
|
a(i) -= v(i);
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace FasTC
|
||||||
|
|
||||||
|
#endif // BASE_INCLUDE_PIXEL_H_
|
81
Base/include/Vector2.h
Normal file
81
Base/include/Vector2.h
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2012 Pavel Krajcevski
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef BASE_INCLUDE_VECTOR2_H_
|
||||||
|
#define BASE_INCLUDE_VECTOR2_H_
|
||||||
|
|
||||||
|
#include "VectorBase.h"
|
||||||
|
|
||||||
|
#ifdef _VEX_ENABLE_SWIZZLE_
|
||||||
|
# define _VEX_VEC2_SWIZZLE_DEF(X, Y) \
|
||||||
|
Vector2<T> X##Y() const { return Vector2<T>( X(), Y() ); }
|
||||||
|
#endif // _VEX_ENABLE_SWIZZLE_
|
||||||
|
|
||||||
|
namespace FasTC {
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class Vector2 : public VectorBase<T, 2> {
|
||||||
|
public:
|
||||||
|
// Ideally, we would be able to do this with initialization
|
||||||
|
// lists, but I'm not really sure how to do that without gross
|
||||||
|
// code duplication.
|
||||||
|
Vector2() { }
|
||||||
|
Vector2(T x, T y) {
|
||||||
|
X() = x;
|
||||||
|
Y() = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overloaded functions
|
||||||
|
template<typename _T>
|
||||||
|
Vector2(const Vector2<_T> &v) : VectorBase<T, 2>(v) { }
|
||||||
|
|
||||||
|
template<typename _T>
|
||||||
|
Vector2<T> &operator=(const Vector2<_T> &v) {
|
||||||
|
VectorBase<T, 2>::operator=(v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accessors
|
||||||
|
T &X() { return (*this)[0]; }
|
||||||
|
const T &X() const { return (*this)[0]; }
|
||||||
|
|
||||||
|
T &Y() { return (*this)[1]; }
|
||||||
|
const T &Y() const { return (*this)[1]; }
|
||||||
|
|
||||||
|
// Swizzle
|
||||||
|
#ifdef _VEX_ENABLE_SWIZZLE_
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(X, X)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(X, Y)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(Y, X)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(Y, Y)
|
||||||
|
#endif //_VEX_ENABLE_SWIZZLE_
|
||||||
|
};
|
||||||
|
REGISTER_ONE_TEMPLATE_VECTOR_TYPE(Vector2);
|
||||||
|
|
||||||
|
typedef Vector2<float> Vec2f;
|
||||||
|
typedef Vector2<double> Vec2d;
|
||||||
|
typedef Vector2<int> Vec2i;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BASE_INCLUDE_VECTOR2_H_
|
125
Base/include/Vector3.h
Normal file
125
Base/include/Vector3.h
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2012 Pavel Krajcevski
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef BASE_INCLUDE_VECTOR3_H_
|
||||||
|
#define BASE_INCLUDE_VECTOR3_H_
|
||||||
|
|
||||||
|
#include "Vector2.h"
|
||||||
|
|
||||||
|
#ifdef _VEX_ENABLE_SWIZZLE_
|
||||||
|
# define _VEX_VEC3_SWIZZLE_DEF(X, Y, Z) \
|
||||||
|
Vector3<T> X##Y##Z() const { return Vector3<T>( X(), Y(), Z() ); }
|
||||||
|
#endif // _VEX_ENABLE_SWIZZLE_
|
||||||
|
|
||||||
|
namespace FasTC {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class Vector3 : public VectorBase<T, 3> {
|
||||||
|
public:
|
||||||
|
Vector3() { }
|
||||||
|
Vector3(T x, T y, T z) {
|
||||||
|
X() = x;
|
||||||
|
Y() = y;
|
||||||
|
Z() = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overloaded functions
|
||||||
|
template<typename _T>
|
||||||
|
Vector3(const Vector3<_T> &v) : VectorBase<T, 3>(v) { }
|
||||||
|
|
||||||
|
template<typename _T>
|
||||||
|
Vector3<T> &operator=(const Vector3<_T> &v) {
|
||||||
|
VectorBase<T, 3>::operator=(v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accessors
|
||||||
|
T &X() { return (*this)[0]; }
|
||||||
|
const T &X() const { return (*this)[0]; }
|
||||||
|
|
||||||
|
T &Y() { return (*this)[1]; }
|
||||||
|
const T &Y() const { return (*this)[1]; }
|
||||||
|
|
||||||
|
T &Z() { return (*this)[2]; }
|
||||||
|
const T &Z() const { return (*this)[2]; }
|
||||||
|
|
||||||
|
// Vector operations
|
||||||
|
template<typename _T>
|
||||||
|
Vector3<T> Cross(const Vector3<_T> &v) {
|
||||||
|
return Vector3<T>(
|
||||||
|
Y() * v.Z() - v.Y() * Z(),
|
||||||
|
Z() * v.X() - v.Z() * X(),
|
||||||
|
X() * v.Y() - v.X() * Y()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Swizzle
|
||||||
|
#ifdef _VEX_ENABLE_SWIZZLE_
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(X, X)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(X, Y)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(X, Z)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(Y, X)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(Y, Y)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(Y, Z)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(Z, X)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(Z, Y)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(Z, Z)
|
||||||
|
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, X, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, X, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, X, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, Y, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, Y, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, Y, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, Z, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, Z, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, Z, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, X, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, X, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, X, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, Y, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, Y, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, Y, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, Z, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, Z, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, Z, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, X, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, X, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, X, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, Y, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, Y, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, Y, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, Z, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, Z, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, Z, Z)
|
||||||
|
#endif // _VEX_ENABLE_SWIZZLE_
|
||||||
|
};
|
||||||
|
REGISTER_ONE_TEMPLATE_VECTOR_TYPE(Vector3);
|
||||||
|
|
||||||
|
typedef Vector3<float> Vec3f;
|
||||||
|
typedef Vector3<double> Vec3d;
|
||||||
|
typedef Vector3<int> Vec3i;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BASE_INCLUDE_VECTOR3_H_
|
421
Base/include/Vector4.h
Normal file
421
Base/include/Vector4.h
Normal file
|
@ -0,0 +1,421 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2012 Pavel Krajcevski
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef BASE_INCLUDE_VECTOR4_H_
|
||||||
|
#define BASE_INCLUDE_VECTOR4_H_
|
||||||
|
|
||||||
|
#include "TexCompTypes.h"
|
||||||
|
#include "Vector3.h"
|
||||||
|
|
||||||
|
#ifdef _VEX_ENABLE_SWIZZLE_
|
||||||
|
#define _VEX_VEC4_SWIZZLE_DEF(X, Y, Z, W) \
|
||||||
|
Vector4<T> X##Y##Z##W() const { return Vector4<T>( X(), Y(), Z(), W() ); }
|
||||||
|
#endif // _VEX_ENABLE_SWIZZLE_
|
||||||
|
|
||||||
|
namespace FasTC {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class Vector4 : public VectorBase<T, 4> {
|
||||||
|
public:
|
||||||
|
Vector4() { }
|
||||||
|
Vector4(T x, T y, T z, T w) {
|
||||||
|
X() = x;
|
||||||
|
Y() = y;
|
||||||
|
Z() = z;
|
||||||
|
W() = w;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overloaded functions
|
||||||
|
template<typename _T>
|
||||||
|
Vector4(const Vector4<_T> &v) : VectorBase<T, 4>(v) { }
|
||||||
|
|
||||||
|
template<typename _T>
|
||||||
|
Vector4<T> &operator=(const Vector4<_T> &v) {
|
||||||
|
VectorBase<T, 4>::operator=(v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accessors
|
||||||
|
T &X() { return (*this)[0]; }
|
||||||
|
const T &X() const { return (*this)[0]; }
|
||||||
|
|
||||||
|
T &Y() { return (*this)[1]; }
|
||||||
|
const T &Y() const { return (*this)[1]; }
|
||||||
|
|
||||||
|
T &Z() { return (*this)[2]; }
|
||||||
|
const T &Z() const { return (*this)[2]; }
|
||||||
|
|
||||||
|
T &W() { return (*this)[3]; }
|
||||||
|
const T &W() const { return (*this)[3]; }
|
||||||
|
|
||||||
|
// Swizzle
|
||||||
|
#ifdef _VEX_ENABLE_SWIZZLE_
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(X, X)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(X, Y)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(X, Z)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(X, W)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(Y, X)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(Y, Y)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(Y, Z)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(Y, W)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(Z, X)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(Z, Y)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(Z, Z)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(Z, W)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(W, X)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(W, Y)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(W, Z)
|
||||||
|
_VEX_VEC2_SWIZZLE_DEF(W, W)
|
||||||
|
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, X, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, X, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, X, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, X, W)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, Y, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, Y, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, Y, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, Y, W)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, Z, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, Z, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, Z, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, Z, W)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, W, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, W, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, W, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(X, W, W)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, X, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, X, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, X, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, X, W)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, Y, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, Y, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, Y, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, Y, W)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, Z, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, Z, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, Z, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, Z, W)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, W, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, W, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, W, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Y, W, W)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, X, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, X, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, X, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, X, W)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, Y, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, Y, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, Y, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, Y, W)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, Z, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, Z, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, Z, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, Z, W)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, W, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, W, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, W, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(Z, W, W)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(W, X, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(W, X, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(W, X, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(W, X, W)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(W, Y, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(W, Y, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(W, Y, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(W, Y, W)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(W, Z, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(W, Z, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(W, Z, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(W, Z, W)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(W, W, X)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(W, W, Y)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(W, W, Z)
|
||||||
|
_VEX_VEC3_SWIZZLE_DEF(W, W, W)
|
||||||
|
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, X, X, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, X, X, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, X, X, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, X, X, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, X, Y, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, X, Y, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, X, Y, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, X, Y, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, X, Z, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, X, Z, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, X, Z, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, X, Z, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, X, W, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, X, W, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, X, W, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, X, W, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Y, X, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Y, X, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Y, X, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Y, X, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Y, Y, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Y, Y, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Y, Y, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Y, Y, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Y, Z, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Y, Z, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Y, Z, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Y, Z, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Y, W, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Y, W, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Y, W, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Y, W, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Z, X, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Z, X, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Z, X, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Z, X, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Z, Y, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Z, Y, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Z, Y, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Z, Y, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Z, Z, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Z, Z, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Z, Z, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Z, Z, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Z, W, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Z, W, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Z, W, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, Z, W, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, W, X, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, W, X, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, W, X, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, W, X, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, W, Y, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, W, Y, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, W, Y, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, W, Y, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, W, Z, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, W, Z, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, W, Z, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, W, Z, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, W, W, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, W, W, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, W, W, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(X, W, W, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, X, X, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, X, X, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, X, X, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, X, X, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, X, Y, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, X, Y, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, X, Y, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, X, Y, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, X, Z, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, X, Z, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, X, Z, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, X, Z, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, X, W, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, X, W, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, X, W, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, X, W, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Y, X, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Y, X, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Y, X, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Y, X, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Y, Y, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Y, Y, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Y, Y, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Y, Y, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Y, Z, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Y, Z, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Y, Z, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Y, Z, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Y, W, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Y, W, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Y, W, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Y, W, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Z, X, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Z, X, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Z, X, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Z, X, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Z, Y, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Z, Y, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Z, Y, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Z, Y, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Z, Z, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Z, Z, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Z, Z, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Z, Z, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Z, W, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Z, W, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Z, W, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, Z, W, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, W, X, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, W, X, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, W, X, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, W, X, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, W, Y, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, W, Y, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, W, Y, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, W, Y, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, W, Z, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, W, Z, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, W, Z, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, W, Z, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, W, W, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, W, W, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, W, W, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Y, W, W, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, X, X, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, X, X, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, X, X, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, X, X, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, X, Y, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, X, Y, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, X, Y, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, X, Y, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, X, Z, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, X, Z, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, X, Z, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, X, Z, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, X, W, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, X, W, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, X, W, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, X, W, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Y, X, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Y, X, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Y, X, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Y, X, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Y, Y, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Y, Y, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Y, Y, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Y, Y, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Y, Z, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Y, Z, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Y, Z, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Y, Z, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Y, W, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Y, W, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Y, W, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Y, W, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Z, X, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Z, X, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Z, X, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Z, X, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Z, Y, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Z, Y, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Z, Y, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Z, Y, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Z, Z, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Z, Z, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Z, Z, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Z, Z, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Z, W, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Z, W, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Z, W, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, Z, W, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, W, X, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, W, X, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, W, X, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, W, X, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, W, Y, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, W, Y, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, W, Y, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, W, Y, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, W, Z, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, W, Z, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, W, Z, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, W, Z, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, W, W, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, W, W, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, W, W, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(Z, W, W, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, X, X, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, X, X, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, X, X, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, X, X, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, X, Y, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, X, Y, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, X, Y, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, X, Y, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, X, Z, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, X, Z, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, X, Z, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, X, Z, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, X, W, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, X, W, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, X, W, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, X, W, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Y, X, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Y, X, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Y, X, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Y, X, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Y, Y, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Y, Y, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Y, Y, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Y, Y, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Y, Z, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Y, Z, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Y, Z, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Y, Z, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Y, W, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Y, W, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Y, W, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Y, W, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Z, X, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Z, X, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Z, X, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Z, X, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Z, Y, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Z, Y, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Z, Y, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Z, Y, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Z, Z, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Z, Z, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Z, Z, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Z, Z, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Z, W, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Z, W, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Z, W, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, Z, W, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, W, X, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, W, X, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, W, X, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, W, X, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, W, Y, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, W, Y, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, W, Y, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, W, Y, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, W, Z, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, W, Z, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, W, Z, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, W, Z, W)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, W, W, X)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, W, W, Y)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, W, W, Z)
|
||||||
|
_VEX_VEC4_SWIZZLE_DEF(W, W, W, W)
|
||||||
|
#endif // _VEX_ENABLE_SWIZZLE_
|
||||||
|
};
|
||||||
|
REGISTER_ONE_TEMPLATE_VECTOR_TYPE(Vector4);
|
||||||
|
|
||||||
|
typedef Vector4<float> Vec4f;
|
||||||
|
typedef Vector4<double> Vec4d;
|
||||||
|
typedef Vector4<uint32> Vec4i;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BASE_INCLUDE_VECTOR4_H_
|
238
Base/include/VectorBase.h
Normal file
238
Base/include/VectorBase.h
Normal file
|
@ -0,0 +1,238 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2012 Pavel Krajcevski
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef BASE_INCLUDE_VECTORBASE_H_
|
||||||
|
#define BASE_INCLUDE_VECTORBASE_H_
|
||||||
|
|
||||||
|
// !FIXME! For sqrt function. This increases compilation time by a LOT
|
||||||
|
// but I couldn't guarantee any faster general-purpose implementation
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace FasTC {
|
||||||
|
|
||||||
|
template <typename T, const int N>
|
||||||
|
class VectorBase {
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Vector representation
|
||||||
|
T vec[N];
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
VectorBase() { }
|
||||||
|
VectorBase(const VectorBase<T, N> &other) {
|
||||||
|
for(int i = 0; i < N; i++) vec[i] = other[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit VectorBase(T *_vec) {
|
||||||
|
for(int i = 0; i < N; i++) {
|
||||||
|
vec[i] = _vec[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const int Size = N;
|
||||||
|
|
||||||
|
// Accessors
|
||||||
|
T &operator()(int idx) { return vec[idx]; }
|
||||||
|
T &operator[](int idx) { return vec[idx]; }
|
||||||
|
const T &operator()(int idx) const { return vec[idx]; }
|
||||||
|
const T &operator[](int idx) const { return vec[idx]; }
|
||||||
|
|
||||||
|
// Allow casts to the respective array representation...
|
||||||
|
operator T *() const { return vec; }
|
||||||
|
VectorBase<T, N> &operator=(const T *v) {
|
||||||
|
for(int i = 0; i < N; i++)
|
||||||
|
vec[i] = v[i];
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allows casting to other vector types if the underlying type system does as well...
|
||||||
|
template<typename _T>
|
||||||
|
operator VectorBase<_T, N>() const {
|
||||||
|
return VectorBase<_T, N>(vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vector operations
|
||||||
|
template<typename _T>
|
||||||
|
T Dot(const VectorBase<_T, N> &v) const {
|
||||||
|
T sum = 0;
|
||||||
|
for(int i = 0; i < N; i++)
|
||||||
|
sum += vec[i] * v[i];
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
T LengthSq() const { return this->Dot(*this); }
|
||||||
|
T Length() const { return sqrt(LengthSq()); }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Operators
|
||||||
|
template<typename VectorTypeOne, typename VectorTypeTwo>
|
||||||
|
static inline VectorTypeOne VectorAddition(const VectorTypeOne &v1,
|
||||||
|
const VectorTypeTwo &v2) {
|
||||||
|
VectorTypeOne a;
|
||||||
|
for(int i = 0; i < VectorTypeOne::Size; i++) {
|
||||||
|
a(i) = v1(i) + v2(i);
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename VectorTypeOne, typename VectorTypeTwo>
|
||||||
|
static inline VectorTypeOne operator+(const VectorTypeOne &v1,
|
||||||
|
const VectorTypeTwo &v2) {
|
||||||
|
return VectorAddition(v1, v2);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename VectorTypeOne, typename VectorTypeTwo>
|
||||||
|
static inline VectorTypeOne &operator+=(VectorTypeOne &v1,
|
||||||
|
const VectorTypeTwo &v2) {
|
||||||
|
return v1 = VectorAddition(v1, v2);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename VectorTypeOne, typename VectorTypeTwo>
|
||||||
|
static inline VectorTypeOne VectorSubtraction(const VectorTypeOne &v1,
|
||||||
|
const VectorTypeTwo &v2) {
|
||||||
|
VectorTypeOne a;
|
||||||
|
for(int i = 0; i < VectorTypeOne::Size; i++) {
|
||||||
|
a(i) = v1(i) - v2(i);
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename VectorTypeOne, typename VectorTypeTwo>
|
||||||
|
static inline VectorTypeOne operator-(const VectorTypeOne &v1,
|
||||||
|
const VectorTypeTwo &v2) {
|
||||||
|
return VectorSubtraction(v1, v2);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename VectorTypeOne, typename VectorTypeTwo>
|
||||||
|
static inline VectorTypeOne &operator-=(VectorTypeOne &v1,
|
||||||
|
const VectorTypeTwo &v2) {
|
||||||
|
return v1 = VectorSubtraction(v1, v2);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class VectorTraits {
|
||||||
|
public:
|
||||||
|
static const bool IsVector = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T, const int N>
|
||||||
|
class VectorTraits<VectorBase<T, N> > {
|
||||||
|
public:
|
||||||
|
static const bool IsVector = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define REGISTER_VECTOR_TYPE(TYPE) \
|
||||||
|
template<> \
|
||||||
|
class VectorTraits< TYPE > { \
|
||||||
|
public: \
|
||||||
|
static const bool IsVector = true; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define REGISTER_ONE_TEMPLATE_VECTOR_TYPE(TYPE) \
|
||||||
|
template<typename T> \
|
||||||
|
class VectorTraits< TYPE <T> > { \
|
||||||
|
public: \
|
||||||
|
static const bool IsVector = true; \
|
||||||
|
}
|
||||||
|
|
||||||
|
template<bool condition, typename TypeOne, typename TypeTwo>
|
||||||
|
class VectorSwitch {
|
||||||
|
private:
|
||||||
|
const TypeOne &m_A;
|
||||||
|
const TypeTwo &m_B;
|
||||||
|
public:
|
||||||
|
typedef TypeOne VectorType;
|
||||||
|
typedef TypeTwo ScalarType;
|
||||||
|
|
||||||
|
VectorSwitch(const TypeOne &a, const TypeTwo &b)
|
||||||
|
: m_A(a), m_B(b) { }
|
||||||
|
|
||||||
|
const TypeOne &GetVector() { return m_A; }
|
||||||
|
const TypeTwo &GetScalar() { return m_B; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename TypeOne, typename TypeTwo>
|
||||||
|
class VectorSwitch<false, TypeOne, TypeTwo> {
|
||||||
|
private:
|
||||||
|
const TypeOne &m_A;
|
||||||
|
const TypeTwo &m_B;
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef TypeTwo VectorType;
|
||||||
|
typedef TypeOne ScalarType;
|
||||||
|
|
||||||
|
VectorSwitch(const TypeOne &a, const TypeTwo &b)
|
||||||
|
: m_A(a), m_B(b) { }
|
||||||
|
|
||||||
|
const TypeOne &GetVector() { return m_B; }
|
||||||
|
const TypeTwo &GetScalar() { return m_A; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename VectorType, typename ScalarType>
|
||||||
|
static inline VectorType ScalarMultiply(const VectorType &v, const ScalarType &s) {
|
||||||
|
VectorType a;
|
||||||
|
for(int i = 0; i < VectorType::Size; i++)
|
||||||
|
a(i) = v(i) * s;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename TypeOne, typename TypeTwo>
|
||||||
|
static inline
|
||||||
|
typename VectorSwitch< VectorTraits<TypeOne>::IsVector, TypeOne, TypeTwo >::VectorType
|
||||||
|
operator*(const TypeOne &v1, const TypeTwo &v2) {
|
||||||
|
typedef VectorSwitch< VectorTraits<TypeOne>::IsVector, TypeOne, TypeTwo > VSwitch;
|
||||||
|
VSwitch s(v1, v2);
|
||||||
|
return ScalarMultiply(s.GetVector(), s.GetScalar());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename VectorType, typename ScalarType>
|
||||||
|
static inline VectorType ScalarDivide(const VectorType &v, const ScalarType &s) {
|
||||||
|
VectorType a;
|
||||||
|
for(int i = 0; i < VectorType::Size; i++)
|
||||||
|
a(i) = v(i) / s;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename TypeOne, typename TypeTwo>
|
||||||
|
static inline
|
||||||
|
typename VectorSwitch< VectorTraits<TypeOne>::IsVector, TypeOne, TypeTwo >::VectorType
|
||||||
|
operator/(const TypeOne &v1, const TypeTwo &v2) {
|
||||||
|
typedef VectorSwitch< VectorTraits<TypeOne>::IsVector, TypeOne, TypeTwo > VSwitch;
|
||||||
|
VSwitch s(v1, v2);
|
||||||
|
return ScalarDivide(s.GetVector(), s.GetScalar());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename VectorType, typename ScalarType>
|
||||||
|
static inline VectorType &operator*=(VectorType &v, const ScalarType &s) {
|
||||||
|
return v = ScalarMultiply(v, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename VectorType, typename ScalarType>
|
||||||
|
static inline VectorType &operator/=(VectorType &v, const ScalarType &s) {
|
||||||
|
return v = ScalarDivide(v, s);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BASE_INCLUDE_VECTORBASE_H_
|
87
Base/src/Color.cpp
Normal file
87
Base/src/Color.cpp
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
/* 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 "Color.h"
|
||||||
|
|
||||||
|
namespace FasTC {
|
||||||
|
|
||||||
|
uint32 Color::Pack() const {
|
||||||
|
uint32 result = 0;
|
||||||
|
result = static_cast<uint32>((A() + 0.5f) * 255.0f);
|
||||||
|
result <<= 8;
|
||||||
|
result = static_cast<uint32>((B() + 0.5f) * 255.0f);
|
||||||
|
result <<= 8;
|
||||||
|
result = static_cast<uint32>((G() + 0.5f) * 255.0f);
|
||||||
|
result <<= 8;
|
||||||
|
result = static_cast<uint32>((R() + 0.5f) * 255.0f);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Color::Unpack(uint32 rgba) {
|
||||||
|
R() = static_cast<float>(rgba & 0xFF) / 255.0f;
|
||||||
|
G() = static_cast<float>((rgba >> 8) & 0xFF) / 255.0f;
|
||||||
|
B() = static_cast<float>((rgba >> 16) & 0xFF) / 255.0f;
|
||||||
|
A() = static_cast<float>((rgba >> 24) & 0xFF) / 255.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tests for equality by comparing the values and the bit depths.
|
||||||
|
bool Color::operator==(const Color &other) const {
|
||||||
|
static const float kEpsilon = 0.001;
|
||||||
|
for(uint32 c = 0; c < 4; c++) {
|
||||||
|
if(fabs(Component(c) - other.Component(c)) > kEpsilon) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} // namespace FasTC
|
|
@ -49,107 +49,157 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
#include "Color.h"
|
||||||
|
#include "Pixel.h"
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static inline T sad( const T &a, const T &b ) {
|
static inline T sad( const T &a, const T &b ) {
|
||||||
return (a > b)? a - b : b - a;
|
return (a > b)? a - b : b - a;
|
||||||
}
|
}
|
||||||
|
|
||||||
Image::Image(const Image &other)
|
namespace FasTC {
|
||||||
|
|
||||||
|
template<typename PixelType>
|
||||||
|
Image<PixelType>::Image(uint32 width, uint32 height)
|
||||||
|
: m_Width(width)
|
||||||
|
, m_Height(height)
|
||||||
|
, m_bBlockStreamOrder(false)
|
||||||
|
, m_Pixels(new PixelType[GetNumPixels()])
|
||||||
|
{ }
|
||||||
|
|
||||||
|
template<typename PixelType>
|
||||||
|
Image<PixelType>::Image(uint32 width, uint32 height,
|
||||||
|
const PixelType *pixels,
|
||||||
|
bool bBlockStreamOrder)
|
||||||
|
: m_Width(width)
|
||||||
|
, m_Height(height)
|
||||||
|
, m_bBlockStreamOrder(false)
|
||||||
|
{
|
||||||
|
if(pixels) {
|
||||||
|
m_Pixels = new PixelType[GetNumPixels()];
|
||||||
|
memcpy(m_Pixels, pixels, GetNumPixels() * sizeof(PixelType));
|
||||||
|
} else {
|
||||||
|
m_Pixels = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename PixelType>
|
||||||
|
Image<PixelType>::Image(const Image<PixelType> &other)
|
||||||
: m_Width(other.m_Width)
|
: m_Width(other.m_Width)
|
||||||
, m_Height(other.m_Height)
|
, m_Height(other.m_Height)
|
||||||
, m_bBlockStreamOrder(other.GetBlockStreamOrder())
|
, m_bBlockStreamOrder(other.GetBlockStreamOrder())
|
||||||
, m_DataSz(other.m_DataSz)
|
, m_Pixels(new PixelType[GetNumPixels()])
|
||||||
, m_Data(new uint8[m_DataSz])
|
|
||||||
{
|
{
|
||||||
if(m_Data) {
|
memcpy(m_Pixels, other.m_Pixels, GetNumPixels() * sizeof(PixelType));
|
||||||
memcpy(m_Data, other.m_Data, m_DataSz);
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "Out of memory!\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Image::Image(uint32 width, uint32 height, const uint32 *pixels, bool bBlockStreamOrder)
|
template<typename PixelType>
|
||||||
|
bool Image<PixelType>::ReadPixels(const uint32 *rgba) {
|
||||||
|
|
||||||
|
assert(m_Pixels);
|
||||||
|
for(uint32 i = 0; i < GetNumPixels(); i++) {
|
||||||
|
m_Pixels[i].Unpack(rgba[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename PixelType>
|
||||||
|
Image<PixelType>::Image(uint32 width, uint32 height, const uint32 *pixels, bool bBlockStreamOrder)
|
||||||
: m_Width(width)
|
: m_Width(width)
|
||||||
, m_Height(height)
|
, m_Height(height)
|
||||||
, m_bBlockStreamOrder(bBlockStreamOrder)
|
, m_bBlockStreamOrder(bBlockStreamOrder)
|
||||||
, m_DataSz(m_Width * m_Height * sizeof(uint32))
|
|
||||||
{
|
{
|
||||||
if(pixels) {
|
if(pixels) {
|
||||||
m_Data = new uint8[m_DataSz];
|
m_Pixels = new PixelType[GetNumPixels()];
|
||||||
memcpy(m_Data, pixels, m_DataSz);
|
ReadPixels(pixels);
|
||||||
} else {
|
} else {
|
||||||
m_Data = NULL;
|
m_Pixels = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Image::~Image() {
|
template<typename PixelType>
|
||||||
if(m_Data) {
|
Image<PixelType>::~Image() {
|
||||||
delete [] m_Data;
|
if(m_Pixels) {
|
||||||
m_Data = 0;
|
delete [] m_Pixels;
|
||||||
|
m_Pixels = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Image &Image::operator=(const Image &other) {
|
template<typename PixelType>
|
||||||
|
Image<PixelType> &Image<PixelType>::operator=(const Image &other) {
|
||||||
|
|
||||||
m_Width = other.m_Width;
|
m_Width = other.m_Width;
|
||||||
m_Height = other.m_Height;
|
m_Height = other.m_Height;
|
||||||
m_bBlockStreamOrder = other.GetBlockStreamOrder();
|
m_bBlockStreamOrder = other.GetBlockStreamOrder();
|
||||||
m_DataSz = other.m_DataSz;
|
|
||||||
|
|
||||||
if(m_Data) {
|
if(m_Pixels) {
|
||||||
delete [] m_Data;
|
delete [] m_Pixels;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(other.m_Data) {
|
if(other.m_Pixels) {
|
||||||
m_Data = new uint8[m_DataSz];
|
m_Pixels = new PixelType[GetNumPixels()];
|
||||||
if(m_Data)
|
if(m_Pixels)
|
||||||
memcpy(m_Data, other.m_Data, m_DataSz);
|
memcpy(m_Pixels, other.m_Pixels, GetNumPixels() * sizeof(PixelType));
|
||||||
else
|
else
|
||||||
fprintf(stderr, "Out of memory!\n");
|
fprintf(stderr, "Out of memory!\n");
|
||||||
}
|
} else {
|
||||||
else {
|
m_Pixels = NULL;
|
||||||
m_Data = other.m_Data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Image::ComputePSNR(Image *other) {
|
template<typename PixelType>
|
||||||
if(!other)
|
PixelType & Image<PixelType>::operator()(uint32 i, uint32 j) {
|
||||||
|
assert(i < GetWidth());
|
||||||
|
assert(j < GetHeight());
|
||||||
|
return m_Pixels[j * GetWidth() + i];
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename PixelType>
|
||||||
|
const PixelType & Image<PixelType>::operator()(uint32 i, uint32 j) const {
|
||||||
|
assert(i < GetWidth());
|
||||||
|
assert(j < GetHeight());
|
||||||
|
return m_Pixels[j * GetWidth() + i];
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename PixelTypeOne, typename PixelTypeTwo>
|
||||||
|
double ComputePSNR(Image<PixelTypeOne> *img1, Image<PixelTypeTwo> *img2) {
|
||||||
|
if(!img1 || !img2)
|
||||||
return -1.0;
|
return -1.0;
|
||||||
|
|
||||||
if(other->GetWidth() != GetWidth() ||
|
if(img1->GetWidth() != img2->GetWidth() ||
|
||||||
other->GetHeight() != GetHeight()) {
|
img1->GetHeight() != img2->GetHeight()) {
|
||||||
return -1.0;
|
return -1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute raw 8-bit RGBA data...
|
// Compute raw 8-bit RGBA data...
|
||||||
other->ComputeRGBA();
|
img1->ComputePixels();
|
||||||
ComputeRGBA();
|
img2->ComputePixels();
|
||||||
|
|
||||||
const uint8 *ourData =
|
const PixelTypeOne *ourPixels = img1->GetPixels();
|
||||||
reinterpret_cast<const uint8 *>(GetRGBA());
|
const PixelTypeTwo *otherPixels = img2->GetPixels();
|
||||||
const uint8 *otherData =
|
|
||||||
reinterpret_cast<const uint8 *>(other->GetRGBA());
|
|
||||||
|
|
||||||
// const double w[3] = { 0.2126, 0.7152, 0.0722 };
|
// const double w[3] = { 0.2126, 0.7152, 0.0722 };
|
||||||
const double w[3] = { 1.0, 1.0, 1.0 };
|
const double w[3] = { 1.0, 1.0, 1.0 };
|
||||||
|
|
||||||
double mse = 0.0;
|
double mse = 0.0;
|
||||||
const uint32 imageSz = GetWidth() * GetHeight() * 4;
|
const uint32 imageSz = img1->GetNumPixels();
|
||||||
for(uint32 i = 0; i < imageSz; i+=4) {
|
for(uint32 i = 0; i < imageSz; i++) {
|
||||||
|
|
||||||
const unsigned char *pixelDataRaw = ourData + i;
|
uint32 ourPixel = ourPixels[i].Pack();
|
||||||
const unsigned char *pixelDataUncomp = otherData + i;
|
uint32 otherPixel = otherPixels[i].Pack();
|
||||||
|
|
||||||
double r[4], u[4];
|
double r[4], u[4];
|
||||||
for(uint32 c = 0; c < 4; c++) {
|
for(uint32 c = 0; c < 4; c++) {
|
||||||
|
uint32 shift = c * 8;
|
||||||
if(c == 3) {
|
if(c == 3) {
|
||||||
r[c] = pixelDataRaw[c] / 255.0;
|
r[c] = static_cast<double>((ourPixel >> shift) & 0xFF) / 255.0;
|
||||||
u[c] = pixelDataUncomp[c] / 255.0;
|
u[c] = static_cast<double>((otherPixel >> shift) & 0xFF) / 255.0;
|
||||||
} else {
|
} else {
|
||||||
r[c] = static_cast<double>(pixelDataRaw[c]) * w[c];
|
r[c] = static_cast<double>((ourPixel >> shift) & 0xFF) * w[c];
|
||||||
u[c] = static_cast<double>(pixelDataUncomp[c]) * w[c];
|
u[c] = static_cast<double>((otherPixel >> shift) & 0xFF) * w[c];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,19 +209,22 @@ double Image::ComputePSNR(Image *other) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mse /= GetWidth() * GetHeight();
|
mse /= img1->GetWidth() * img1->GetHeight();
|
||||||
|
|
||||||
const double C = 255.0 * 255.0;
|
const double C = 255.0 * 255.0;
|
||||||
double maxi = (w[0]*w[0] + w[1]*w[1] + w[2]*w[2]) * C;
|
double maxi = (w[0]*w[0] + w[1]*w[1] + w[2]*w[2]) * C;
|
||||||
return 10 * log10(maxi/mse);
|
return 10 * log10(maxi/mse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template double ComputePSNR(Image<Pixel> *, Image<Pixel> *);
|
||||||
|
|
||||||
// !FIXME! These won't work for non-RGBA8 data.
|
// !FIXME! These won't work for non-RGBA8 data.
|
||||||
void Image::ConvertToBlockStreamOrder() {
|
template<typename PixelType>
|
||||||
if(m_bBlockStreamOrder || !m_Data)
|
void Image<PixelType>::ConvertToBlockStreamOrder() {
|
||||||
|
if(m_bBlockStreamOrder || !m_Pixels)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint32 *newPixelData = new uint32[GetWidth() * GetHeight() * 4];
|
PixelType *newPixelData = new PixelType[GetWidth() * GetHeight()];
|
||||||
for(uint32 j = 0; j < GetHeight(); j+=4) {
|
for(uint32 j = 0; j < GetHeight(); j+=4) {
|
||||||
for(uint32 i = 0; i < GetWidth(); i+=4) {
|
for(uint32 i = 0; i < GetWidth(); i+=4) {
|
||||||
uint32 blockX = i / 4;
|
uint32 blockX = i / 4;
|
||||||
|
@ -182,22 +235,22 @@ void Image::ConvertToBlockStreamOrder() {
|
||||||
for(uint32 t = 0; t < 16; t++) {
|
for(uint32 t = 0; t < 16; t++) {
|
||||||
uint32 x = i + t % 4;
|
uint32 x = i + t % 4;
|
||||||
uint32 y = j + t / 4;
|
uint32 y = j + t / 4;
|
||||||
newPixelData[offset + t] =
|
newPixelData[offset + t] = m_Pixels[y*GetWidth() + x];
|
||||||
reinterpret_cast<uint32 *>(m_Data)[y*GetWidth() + x];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete m_Data;
|
delete m_Pixels;
|
||||||
m_Data = reinterpret_cast<uint8 *>(newPixelData);
|
m_Pixels = newPixelData;
|
||||||
m_bBlockStreamOrder = true;
|
m_bBlockStreamOrder = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::ConvertFromBlockStreamOrder() {
|
template<typename PixelType>
|
||||||
if(!m_bBlockStreamOrder || !m_Data)
|
void Image<PixelType>::ConvertFromBlockStreamOrder() {
|
||||||
|
if(!m_bBlockStreamOrder || !m_Pixels)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint32 *newPixelData = new uint32[GetWidth() * GetHeight() * 4];
|
PixelType *newPixelData = new PixelType[GetWidth() * GetHeight()];
|
||||||
for(uint32 j = 0; j < GetHeight(); j+=4) {
|
for(uint32 j = 0; j < GetHeight(); j+=4) {
|
||||||
for(uint32 i = 0; i < GetWidth(); i+=4) {
|
for(uint32 i = 0; i < GetWidth(); i+=4) {
|
||||||
uint32 blockX = i / 4;
|
uint32 blockX = i / 4;
|
||||||
|
@ -208,13 +261,34 @@ void Image::ConvertFromBlockStreamOrder() {
|
||||||
for(uint32 t = 0; t < 16; t++) {
|
for(uint32 t = 0; t < 16; t++) {
|
||||||
uint32 x = i + t % 4;
|
uint32 x = i + t % 4;
|
||||||
uint32 y = j + t / 4;
|
uint32 y = j + t / 4;
|
||||||
newPixelData[y*GetWidth() + x] =
|
newPixelData[y*GetWidth() + x] = m_Pixels[offset + t];
|
||||||
reinterpret_cast<uint32 *>(m_Data)[offset + t];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete m_Data;
|
delete m_Pixels;
|
||||||
m_Data = reinterpret_cast<uint8 *>(newPixelData);
|
m_Pixels = newPixelData;
|
||||||
m_bBlockStreamOrder = false;
|
m_bBlockStreamOrder = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename PixelType>
|
||||||
|
void Image<PixelType>::SetImageData(uint32 width, uint32 height, PixelType *data) {
|
||||||
|
if(m_Pixels) {
|
||||||
|
delete m_Pixels;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!data) {
|
||||||
|
width = 0;
|
||||||
|
height = 0;
|
||||||
|
m_Pixels = NULL;
|
||||||
|
} else {
|
||||||
|
m_Width = width;
|
||||||
|
m_Height = height;
|
||||||
|
m_Pixels = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template class Image<Pixel>;
|
||||||
|
template class Image<Color>;
|
||||||
|
|
||||||
|
} // namespace FasTC
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace PVRTCC {
|
namespace FasTC {
|
||||||
|
|
||||||
void Pixel::FromBits(const uint8 *bits,
|
void Pixel::FromBits(const uint8 *bits,
|
||||||
const uint8 channelDepth[4],
|
const uint8 channelDepth[4],
|
||||||
|
@ -82,7 +82,7 @@ namespace PVRTCC {
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int32 i = 0; i < 4; i++) {
|
for(int32 i = 0; i < 4; i++) {
|
||||||
uint8 &channel = m_Component[i];
|
ChannelType &channel = Component(i);
|
||||||
uint32 depth = m_BitDepth[i];
|
uint32 depth = m_BitDepth[i];
|
||||||
|
|
||||||
assert(depth <= 8);
|
assert(depth <= 8);
|
||||||
|
@ -125,7 +125,7 @@ namespace PVRTCC {
|
||||||
|
|
||||||
uint8 bitIdx = bitOffset;
|
uint8 bitIdx = bitOffset;
|
||||||
for(int i = 3; i >= 0; i--) {
|
for(int i = 3; i >= 0; i--) {
|
||||||
uint8 val = Component(i);
|
ChannelType val = Component(i);
|
||||||
uint8 depth = m_BitDepth[i];
|
uint8 depth = m_BitDepth[i];
|
||||||
|
|
||||||
if(depth + bitIdx > 8) {
|
if(depth + bitIdx > 8) {
|
||||||
|
@ -146,7 +146,7 @@ namespace PVRTCC {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 Pixel::ChangeBitDepth(uint8 val, uint8 oldDepth, uint8 newDepth) {
|
Pixel::ChannelType Pixel::ChangeBitDepth(Pixel::ChannelType val, uint8 oldDepth, uint8 newDepth) {
|
||||||
assert(newDepth <= 8);
|
assert(newDepth <= 8);
|
||||||
assert(oldDepth <= 8);
|
assert(oldDepth <= 8);
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ namespace PVRTCC {
|
||||||
|
|
||||||
void Pixel::ChangeBitDepth(const uint8 (&depth)[4]) {
|
void Pixel::ChangeBitDepth(const uint8 (&depth)[4]) {
|
||||||
for(uint32 i = 0; i < 4; i++) {
|
for(uint32 i = 0; i < 4; i++) {
|
||||||
m_Component[i] = ChangeBitDepth(m_Component[i], m_BitDepth[i], depth[i]);
|
Component(i) = ChangeBitDepth(Component(i), m_BitDepth[i], depth[i]);
|
||||||
m_BitDepth[i] = depth[i];
|
m_BitDepth[i] = depth[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ namespace PVRTCC {
|
||||||
return r * 0.21f + g * 0.71f + b * 0.07f;
|
return r * 0.21f + g * 0.71f + b * 0.07f;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 Pixel::PackRGBA() const {
|
uint32 Pixel::Pack() const {
|
||||||
Pixel eightBit(*this);
|
Pixel eightBit(*this);
|
||||||
const uint8 eightBitDepth[4] = { 8, 8, 8, 8 };
|
const uint8 eightBitDepth[4] = { 8, 8, 8, 8 };
|
||||||
eightBit.ChangeBitDepth(eightBitDepth);
|
eightBit.ChangeBitDepth(eightBitDepth);
|
||||||
|
@ -215,7 +215,7 @@ namespace PVRTCC {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pixel::UnpackRGBA(uint32 rgba) {
|
void Pixel::Unpack(uint32 rgba) {
|
||||||
A() = ChangeBitDepth((rgba >> 24) & 0xFF, 8, m_BitDepth[0]);
|
A() = ChangeBitDepth((rgba >> 24) & 0xFF, 8, m_BitDepth[0]);
|
||||||
R() = ChangeBitDepth(rgba & 0xFF, 8, m_BitDepth[1]);
|
R() = ChangeBitDepth(rgba & 0xFF, 8, m_BitDepth[1]);
|
||||||
G() = ChangeBitDepth((rgba >> 8) & 0xFF, 8, m_BitDepth[2]);
|
G() = ChangeBitDepth((rgba >> 8) & 0xFF, 8, m_BitDepth[2]);
|
||||||
|
@ -231,10 +231,10 @@ namespace PVRTCC {
|
||||||
ok = ok && m_BitDepth[i] == depths[i];
|
ok = ok && m_BitDepth[i] == depths[i];
|
||||||
|
|
||||||
uint8 mask = (1 << depths[i]) - 1;
|
uint8 mask = (1 << depths[i]) - 1;
|
||||||
const uint8 c = other.Component(i) & mask;
|
const ChannelType c = other.Component(i) & mask;
|
||||||
ok = ok && (c == (Component(i) & mask));
|
ok = ok && (c == (Component(i) & mask));
|
||||||
}
|
}
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace PVRTCC
|
} // namespace FasTC
|
66
Base/test/CMakeLists.txt
Normal file
66
Base/test/CMakeLists.txt
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
# 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_DIRECTORIES(${FasTC_SOURCE_DIR}/Base/include)
|
||||||
|
INCLUDE_DIRECTORIES(${FasTC_SOURCE_DIR}/GTest/include)
|
||||||
|
|
||||||
|
SET(TESTS
|
||||||
|
Pixel Image Color
|
||||||
|
)
|
||||||
|
|
||||||
|
FOREACH(TEST ${TESTS})
|
||||||
|
SET(TEST_NAME Test_Base_${TEST})
|
||||||
|
SET(TEST_MODULE Test${TEST}.cpp)
|
||||||
|
ADD_EXECUTABLE(${TEST_NAME} ${TEST_MODULE})
|
||||||
|
TARGET_LINK_LIBRARIES(${TEST_NAME} FasTCBase)
|
||||||
|
TARGET_LINK_LIBRARIES(${TEST_NAME} gtest_main)
|
||||||
|
ADD_TEST(${TEST_NAME} ${TEST_NAME})
|
||||||
|
ENDFOREACH()
|
|
@ -54,7 +54,7 @@
|
||||||
#include "Pixel.h"
|
#include "Pixel.h"
|
||||||
|
|
||||||
TEST(Pixel, DefaultConstructor) {
|
TEST(Pixel, DefaultConstructor) {
|
||||||
PVRTCC::Pixel p;
|
FasTC::Pixel p;
|
||||||
EXPECT_EQ(p.R(), 0);
|
EXPECT_EQ(p.R(), 0);
|
||||||
EXPECT_EQ(p.G(), 0);
|
EXPECT_EQ(p.G(), 0);
|
||||||
EXPECT_EQ(p.B(), 0);
|
EXPECT_EQ(p.B(), 0);
|
||||||
|
@ -70,12 +70,12 @@ TEST(Pixel, DefaultConstructor) {
|
||||||
|
|
||||||
TEST(Pixel, FromBitsAndAssociatedConstructor) {
|
TEST(Pixel, FromBitsAndAssociatedConstructor) {
|
||||||
const uint8 bits[8] = { 0xA8, 0xB3, 0x7C, 0x21, 0xBD, 0xD4, 0x09, 0x92 };
|
const uint8 bits[8] = { 0xA8, 0xB3, 0x7C, 0x21, 0xBD, 0xD4, 0x09, 0x92 };
|
||||||
PVRTCC::Pixel ps[2];
|
FasTC::Pixel ps[2];
|
||||||
ps[0] = PVRTCC::Pixel(bits);
|
ps[0] = FasTC::Pixel(bits);
|
||||||
ps[1].FromBits(bits);
|
ps[1].FromBits(bits);
|
||||||
|
|
||||||
for(int i = 0; i < 2; i++) {
|
for(int i = 0; i < 2; i++) {
|
||||||
PVRTCC::Pixel &p = ps[i];
|
FasTC::Pixel &p = ps[i];
|
||||||
|
|
||||||
EXPECT_EQ(p.A(), 0xA8);
|
EXPECT_EQ(p.A(), 0xA8);
|
||||||
EXPECT_EQ(p.R(), 0xB3);
|
EXPECT_EQ(p.R(), 0xB3);
|
||||||
|
@ -90,11 +90,11 @@ TEST(Pixel, FromBitsAndAssociatedConstructor) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8 depth1[4] = { 3, 2, 0, 8 };
|
const uint8 depth1[4] = { 3, 2, 0, 8 };
|
||||||
ps[0] = PVRTCC::Pixel(bits + 3, depth1);
|
ps[0] = FasTC::Pixel(bits + 3, depth1);
|
||||||
ps[1].FromBits(bits + 3, depth1);
|
ps[1].FromBits(bits + 3, depth1);
|
||||||
|
|
||||||
for(int i = 0; i < 2; i++) {
|
for(int i = 0; i < 2; i++) {
|
||||||
PVRTCC::Pixel &p = ps[i];
|
FasTC::Pixel &p = ps[i];
|
||||||
|
|
||||||
EXPECT_EQ(p.A(), 0x01);
|
EXPECT_EQ(p.A(), 0x01);
|
||||||
EXPECT_EQ(p.R(), 0x00);
|
EXPECT_EQ(p.R(), 0x00);
|
||||||
|
@ -112,11 +112,11 @@ TEST(Pixel, FromBitsAndAssociatedConstructor) {
|
||||||
|
|
||||||
|
|
||||||
const uint8 depth2[4] = { 5, 6, 2, 4 };
|
const uint8 depth2[4] = { 5, 6, 2, 4 };
|
||||||
ps[0] = PVRTCC::Pixel(bits + 4, depth2, 2);
|
ps[0] = FasTC::Pixel(bits + 4, depth2, 2);
|
||||||
ps[1].FromBits(bits + 4, depth2, 2);
|
ps[1].FromBits(bits + 4, depth2, 2);
|
||||||
|
|
||||||
for(int i = 0; i < 2; i++) {
|
for(int i = 0; i < 2; i++) {
|
||||||
PVRTCC::Pixel &p = ps[i];
|
FasTC::Pixel &p = ps[i];
|
||||||
|
|
||||||
EXPECT_EQ(p.A(), 0x1E);
|
EXPECT_EQ(p.A(), 0x1E);
|
||||||
EXPECT_EQ(p.R(), 0x3A);
|
EXPECT_EQ(p.R(), 0x3A);
|
||||||
|
@ -134,7 +134,7 @@ TEST(Pixel, FromBitsAndAssociatedConstructor) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Pixel, ToBits) {
|
TEST(Pixel, ToBits) {
|
||||||
PVRTCC::Pixel p;
|
FasTC::Pixel p;
|
||||||
|
|
||||||
uint8 bitDepth[4] = { 2, 8, 1, 7 };
|
uint8 bitDepth[4] = { 2, 8, 1, 7 };
|
||||||
p.ChangeBitDepth(bitDepth);
|
p.ChangeBitDepth(bitDepth);
|
||||||
|
@ -163,39 +163,39 @@ TEST(Pixel, ChangeChannelBitDepth) {
|
||||||
uint8 val = 0x43;
|
uint8 val = 0x43;
|
||||||
uint8 depth = 7;
|
uint8 depth = 7;
|
||||||
|
|
||||||
EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 8), 0x87);
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 8), 0x87);
|
||||||
EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 7), 0x43);
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 7), 0x43);
|
||||||
EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 6), 0x22);
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 6), 0x22);
|
||||||
EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 2), 0x2);
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 2), 0x2);
|
||||||
EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 0), 0xFF);
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 0), 0xFF);
|
||||||
|
|
||||||
val = 0x3;
|
val = 0x3;
|
||||||
depth = 3;
|
depth = 3;
|
||||||
|
|
||||||
EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 8), 0x6D);
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 8), 0x6D);
|
||||||
EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 6), 0x1B);
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 6), 0x1B);
|
||||||
EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 3), 0x03);
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 3), 0x03);
|
||||||
EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 2), 0x02);
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 2), 0x02);
|
||||||
EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 0), 0xFF);
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 0), 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Pixel, ChangeChannelBitDepthFromZero) {
|
TEST(Pixel, ChangeChannelBitDepthFromZero) {
|
||||||
uint8 val = 0x43;
|
uint8 val = 0x43;
|
||||||
uint8 depth = 0;
|
uint8 depth = 0;
|
||||||
|
|
||||||
EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 8), 0xFF);
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 8), 0xFF);
|
||||||
EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 7), 0x7F);
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 7), 0x7F);
|
||||||
EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 6), 0x3F);
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 6), 0x3F);
|
||||||
EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 2), 0x03);
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 2), 0x03);
|
||||||
|
|
||||||
// Shouldn't change it...
|
// Shouldn't change it...
|
||||||
EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 0), 0x43);
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 0), 0x43);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Pixel, ChangePixelBitDepth) {
|
TEST(Pixel, ChangePixelBitDepth) {
|
||||||
const uint8 bits[4] = { 0x86, 0xC0, 0x0, 0x0 };
|
const uint8 bits[4] = { 0x86, 0xC0, 0x0, 0x0 };
|
||||||
const uint8 depth[4] = {7, 3, 0, 0};
|
const uint8 depth[4] = {7, 3, 0, 0};
|
||||||
PVRTCC::Pixel p(bits, depth);
|
FasTC::Pixel p(bits, depth);
|
||||||
|
|
||||||
const uint8 newDepth[4] = { 8, 8, 8, 8 };
|
const uint8 newDepth[4] = { 8, 8, 8, 8 };
|
||||||
p.ChangeBitDepth(newDepth);
|
p.ChangeBitDepth(newDepth);
|
||||||
|
@ -216,7 +216,7 @@ TEST(Pixel, ChangePixelBitDepth) {
|
||||||
TEST(Pixel, PackRGBA) {
|
TEST(Pixel, PackRGBA) {
|
||||||
const uint8 bits[4] = { 0x86, 0xC0, 0x0, 0x0 };
|
const uint8 bits[4] = { 0x86, 0xC0, 0x0, 0x0 };
|
||||||
const uint8 depth[4] = {7, 3, 0, 0};
|
const uint8 depth[4] = {7, 3, 0, 0};
|
||||||
PVRTCC::Pixel p(bits, depth);
|
FasTC::Pixel p(bits, depth);
|
||||||
|
|
||||||
uint32 val = p.PackRGBA();
|
uint32 val = p.PackRGBA();
|
||||||
EXPECT_EQ(val, 0x87FFFF6D);
|
EXPECT_EQ(val, 0x87FFFF6D);
|
||||||
|
@ -224,7 +224,7 @@ TEST(Pixel, PackRGBA) {
|
||||||
|
|
||||||
TEST(Pixel, UnpackRGBA) {
|
TEST(Pixel, UnpackRGBA) {
|
||||||
uint32 rgba = 0x4619B3FE;
|
uint32 rgba = 0x4619B3FE;
|
||||||
PVRTCC::Pixel p;
|
FasTC::Pixel p;
|
||||||
|
|
||||||
p.UnpackRGBA(rgba);
|
p.UnpackRGBA(rgba);
|
||||||
EXPECT_EQ(p.A(), 0x46);
|
EXPECT_EQ(p.A(), 0x46);
|
||||||
|
@ -232,13 +232,13 @@ TEST(Pixel, UnpackRGBA) {
|
||||||
EXPECT_EQ(p.G(), 0xB3);
|
EXPECT_EQ(p.G(), 0xB3);
|
||||||
EXPECT_EQ(p.R(), 0xFE);
|
EXPECT_EQ(p.R(), 0xFE);
|
||||||
|
|
||||||
p = PVRTCC::Pixel(rgba);
|
p = FasTC::Pixel(rgba);
|
||||||
EXPECT_EQ(p.A(), 0x46);
|
EXPECT_EQ(p.A(), 0x46);
|
||||||
EXPECT_EQ(p.B(), 0x19);
|
EXPECT_EQ(p.B(), 0x19);
|
||||||
EXPECT_EQ(p.G(), 0xB3);
|
EXPECT_EQ(p.G(), 0xB3);
|
||||||
EXPECT_EQ(p.R(), 0xFE);
|
EXPECT_EQ(p.R(), 0xFE);
|
||||||
|
|
||||||
p = PVRTCC::Pixel();
|
p = FasTC::Pixel();
|
||||||
uint8 newBitDepth[4] = { 3, 5, 2, 1 }; // A R G B
|
uint8 newBitDepth[4] = { 3, 5, 2, 1 }; // A R G B
|
||||||
p.ChangeBitDepth(newBitDepth);
|
p.ChangeBitDepth(newBitDepth);
|
||||||
p.UnpackRGBA(rgba);
|
p.UnpackRGBA(rgba);
|
98
Base/test/TestColor.cpp
Normal file
98
Base/test/TestColor.cpp
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
/* 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 "Color.h"
|
||||||
|
|
||||||
|
static const float kEpsilon = 1e-6;
|
||||||
|
|
||||||
|
TEST(Color, DefaultConstructor) {
|
||||||
|
FasTC::Color c;
|
||||||
|
EXPECT_EQ(c.R(), 0.0f);
|
||||||
|
EXPECT_EQ(c.G(), 0.0f);
|
||||||
|
EXPECT_EQ(c.B(), 0.0f);
|
||||||
|
EXPECT_EQ(c.A(), 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Color, AssignmentConstructor) {
|
||||||
|
FasTC::Color c(1.0f, 0.0f, 3.0f, -1.0f);
|
||||||
|
EXPECT_EQ(c.R(), 1.0f);
|
||||||
|
EXPECT_EQ(c.G(), 0.0f);
|
||||||
|
EXPECT_EQ(c.B(), 3.0f);
|
||||||
|
EXPECT_EQ(c.A(), -1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Color, VectorOperators) {
|
||||||
|
FasTC::Color a(0.1, 0.2, 0.3, 0.4);
|
||||||
|
FasTC::Color b(0.2, 0.3, 0.4, 0.5);
|
||||||
|
FasTC::Color c = a + b;
|
||||||
|
|
||||||
|
EXPECT_NEAR(c.R(), 0.3, kEpsilon);
|
||||||
|
EXPECT_NEAR(c.G(), 0.5, kEpsilon);
|
||||||
|
EXPECT_NEAR(c.B(), 0.7, kEpsilon);
|
||||||
|
EXPECT_NEAR(c.A(), 0.9, kEpsilon);
|
||||||
|
|
||||||
|
FasTC::Color d = a - b;
|
||||||
|
|
||||||
|
EXPECT_NEAR(d.R(), -0.1, kEpsilon);
|
||||||
|
EXPECT_NEAR(d.G(), -0.1, kEpsilon);
|
||||||
|
EXPECT_NEAR(d.B(), -0.1, kEpsilon);
|
||||||
|
EXPECT_NEAR(d.A(), -0.1, kEpsilon);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Color, EqualityComparison) {
|
||||||
|
FasTC::Color a(0.1, 0.2, 0.3, 0.4);
|
||||||
|
FasTC::Color b(0.2, 0.3, 0.4, 0.5);
|
||||||
|
|
||||||
|
EXPECT_TRUE(a == a && b == b);
|
||||||
|
EXPECT_FALSE(a == b && b == a);
|
||||||
|
}
|
121
Base/test/TestImage.cpp
Normal file
121
Base/test/TestImage.cpp
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
/* 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"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
TEST(Image, NonSpecificConstructor) {
|
||||||
|
FasTC::Pixel p;
|
||||||
|
FasTC::Image<FasTC::Pixel> img (4, 4);
|
||||||
|
for(uint32 i = 0; i < 4; i++) {
|
||||||
|
for(uint32 j = 0; j < 4; j++) {
|
||||||
|
EXPECT_TRUE(img(i, j) == p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Image, SpecificConstructor) {
|
||||||
|
FasTC::Pixel pxs[16];
|
||||||
|
for(uint32 i = 0; i < 4; i++) {
|
||||||
|
for(uint32 j = 0; j < 4; j++) {
|
||||||
|
pxs[j*4 + i].R() = i;
|
||||||
|
pxs[j*4 + i].G() = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FasTC::Image<FasTC::Pixel> img(4, 4, pxs);
|
||||||
|
for(uint32 i = 0; i < 4; i++) {
|
||||||
|
for(uint32 j = 0; j < 4; j++) {
|
||||||
|
EXPECT_TRUE(img(i, j) == pxs[j*4 + i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Image, CopyConstructor) {
|
||||||
|
FasTC::Pixel pxs[16];
|
||||||
|
for(uint32 i = 0; i < 4; i++) {
|
||||||
|
for(uint32 j = 0; j < 4; j++) {
|
||||||
|
pxs[j*4 + i].R() = i;
|
||||||
|
pxs[j*4 + i].G() = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FasTC::Image<FasTC::Pixel> img(4, 4, pxs);
|
||||||
|
FasTC::Image<FasTC::Pixel> img2(img);
|
||||||
|
for(uint32 i = 0; i < 4; i++) {
|
||||||
|
for(uint32 j = 0; j < 4; j++) {
|
||||||
|
EXPECT_TRUE(img2(i, j) == pxs[j*4 + i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Image, AssignmentOperator) {
|
||||||
|
FasTC::Pixel pxs[16];
|
||||||
|
for(uint32 i = 0; i < 4; i++) {
|
||||||
|
for(uint32 j = 0; j < 4; j++) {
|
||||||
|
pxs[j*4 + i].R() = i;
|
||||||
|
pxs[j*4 + i].G() = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FasTC::Image<FasTC::Pixel> img(4, 4, pxs);
|
||||||
|
FasTC::Image<FasTC::Pixel> img2 = img;
|
||||||
|
for(uint32 i = 0; i < 4; i++) {
|
||||||
|
for(uint32 j = 0; j < 4; j++) {
|
||||||
|
EXPECT_TRUE(img2(i, j) == pxs[j*4 + i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
250
Base/test/TestPixel.cpp
Normal file
250
Base/test/TestPixel.cpp
Normal file
|
@ -0,0 +1,250 @@
|
||||||
|
/* 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 "Pixel.h"
|
||||||
|
|
||||||
|
TEST(Pixel, DefaultConstructor) {
|
||||||
|
FasTC::Pixel p;
|
||||||
|
EXPECT_EQ(p.R(), 0);
|
||||||
|
EXPECT_EQ(p.G(), 0);
|
||||||
|
EXPECT_EQ(p.B(), 0);
|
||||||
|
EXPECT_EQ(p.A(), 0);
|
||||||
|
|
||||||
|
uint8 depth[4];
|
||||||
|
p.GetBitDepth(depth);
|
||||||
|
|
||||||
|
for(int i = 0; i < 4; i++) {
|
||||||
|
EXPECT_EQ(depth[i], 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Pixel, FromBitsAndAssociatedConstructor) {
|
||||||
|
const uint8 bits[8] = { 0xA8, 0xB3, 0x7C, 0x21, 0xBD, 0xD4, 0x09, 0x92 };
|
||||||
|
FasTC::Pixel ps[2];
|
||||||
|
ps[0] = FasTC::Pixel(bits);
|
||||||
|
ps[1].FromBits(bits);
|
||||||
|
|
||||||
|
for(int i = 0; i < 2; i++) {
|
||||||
|
FasTC::Pixel &p = ps[i];
|
||||||
|
|
||||||
|
EXPECT_EQ(p.A(), 0xA8);
|
||||||
|
EXPECT_EQ(p.R(), 0xB3);
|
||||||
|
EXPECT_EQ(p.G(), 0x7C);
|
||||||
|
EXPECT_EQ(p.B(), 0x21);
|
||||||
|
|
||||||
|
uint8 depth[4];
|
||||||
|
p.GetBitDepth(depth);
|
||||||
|
for(int j = 0; j < 4; j++) {
|
||||||
|
EXPECT_EQ(depth[j], 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8 depth1[4] = { 3, 2, 0, 8 };
|
||||||
|
ps[0] = FasTC::Pixel(bits + 3, depth1);
|
||||||
|
ps[1].FromBits(bits + 3, depth1);
|
||||||
|
|
||||||
|
for(int i = 0; i < 2; i++) {
|
||||||
|
FasTC::Pixel &p = ps[i];
|
||||||
|
|
||||||
|
EXPECT_EQ(p.A(), 0x01);
|
||||||
|
EXPECT_EQ(p.R(), 0x00);
|
||||||
|
EXPECT_EQ(p.G(), 0xFF);
|
||||||
|
EXPECT_EQ(p.B(), 0x37);
|
||||||
|
|
||||||
|
uint8 depth[4];
|
||||||
|
p.GetBitDepth(depth);
|
||||||
|
|
||||||
|
EXPECT_EQ(depth[0], 3);
|
||||||
|
EXPECT_EQ(depth[1], 2);
|
||||||
|
EXPECT_EQ(depth[2], 0);
|
||||||
|
EXPECT_EQ(depth[3], 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const uint8 depth2[4] = { 5, 6, 2, 4 };
|
||||||
|
ps[0] = FasTC::Pixel(bits + 4, depth2, 2);
|
||||||
|
ps[1].FromBits(bits + 4, depth2, 2);
|
||||||
|
|
||||||
|
for(int i = 0; i < 2; i++) {
|
||||||
|
FasTC::Pixel &p = ps[i];
|
||||||
|
|
||||||
|
EXPECT_EQ(p.A(), 0x1E);
|
||||||
|
EXPECT_EQ(p.R(), 0x3A);
|
||||||
|
EXPECT_EQ(p.G(), 0x02);
|
||||||
|
EXPECT_EQ(p.B(), 0x00);
|
||||||
|
|
||||||
|
uint8 depth[4];
|
||||||
|
p.GetBitDepth(depth);
|
||||||
|
|
||||||
|
EXPECT_EQ(depth[0], 5);
|
||||||
|
EXPECT_EQ(depth[1], 6);
|
||||||
|
EXPECT_EQ(depth[2], 2);
|
||||||
|
EXPECT_EQ(depth[3], 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Pixel, ToBits) {
|
||||||
|
FasTC::Pixel p;
|
||||||
|
|
||||||
|
uint8 bitDepth[4] = { 2, 8, 1, 7 };
|
||||||
|
p.ChangeBitDepth(bitDepth);
|
||||||
|
|
||||||
|
p.A() = 0x2;
|
||||||
|
p.R() = 0x56;
|
||||||
|
p.G() = 0;
|
||||||
|
p.B() = 0x4F;
|
||||||
|
|
||||||
|
uint8 bits[3];
|
||||||
|
memset(bits, 0, sizeof(bits));
|
||||||
|
p.ToBits(bits, sizeof(bits));
|
||||||
|
|
||||||
|
EXPECT_EQ(bits[0], 0x4F);
|
||||||
|
EXPECT_EQ(bits[1], 0x56);
|
||||||
|
EXPECT_EQ(bits[2], 0x2);
|
||||||
|
|
||||||
|
memset(bits, 0, sizeof(bits));
|
||||||
|
p.ToBits(bits, 3, 2);
|
||||||
|
EXPECT_EQ(bits[0], 0x3C);
|
||||||
|
EXPECT_EQ(bits[1], 0x59);
|
||||||
|
EXPECT_EQ(bits[2], 0x09);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Pixel, ChangeChannelBitDepth) {
|
||||||
|
uint8 val = 0x43;
|
||||||
|
uint8 depth = 7;
|
||||||
|
|
||||||
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 8), 0x87);
|
||||||
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 7), 0x43);
|
||||||
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 6), 0x22);
|
||||||
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 2), 0x2);
|
||||||
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 0), 0xFF);
|
||||||
|
|
||||||
|
val = 0x3;
|
||||||
|
depth = 3;
|
||||||
|
|
||||||
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 8), 0x6D);
|
||||||
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 6), 0x1B);
|
||||||
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 3), 0x03);
|
||||||
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 2), 0x02);
|
||||||
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 0), 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Pixel, ChangeChannelBitDepthFromZero) {
|
||||||
|
uint8 val = 0x43;
|
||||||
|
uint8 depth = 0;
|
||||||
|
|
||||||
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 8), 0xFF);
|
||||||
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 7), 0x7F);
|
||||||
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 6), 0x3F);
|
||||||
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 2), 0x03);
|
||||||
|
|
||||||
|
// Shouldn't change it...
|
||||||
|
EXPECT_EQ(FasTC::Pixel::ChangeBitDepth(val, depth, 0), 0x43);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Pixel, ChangePixelBitDepth) {
|
||||||
|
const uint8 bits[4] = { 0x86, 0xC0, 0x0, 0x0 };
|
||||||
|
const uint8 depth[4] = {7, 3, 0, 0};
|
||||||
|
FasTC::Pixel p(bits, depth);
|
||||||
|
|
||||||
|
const uint8 newDepth[4] = { 8, 8, 8, 8 };
|
||||||
|
p.ChangeBitDepth(newDepth);
|
||||||
|
|
||||||
|
EXPECT_EQ(p.A(), 0x87);
|
||||||
|
EXPECT_EQ(p.R(), 0x6D);
|
||||||
|
EXPECT_EQ(p.G(), 0xFF);
|
||||||
|
EXPECT_EQ(p.B(), 0xFF);
|
||||||
|
|
||||||
|
uint8 outDepth[4];
|
||||||
|
p.GetBitDepth(outDepth);
|
||||||
|
|
||||||
|
for(uint32 i = 0; i < 4; i++) {
|
||||||
|
EXPECT_EQ(outDepth[i], 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Pixel, PackRGBA) {
|
||||||
|
const uint8 bits[4] = { 0x86, 0xC0, 0x0, 0x0 };
|
||||||
|
const uint8 depth[4] = {7, 3, 0, 0};
|
||||||
|
FasTC::Pixel p(bits, depth);
|
||||||
|
|
||||||
|
uint32 val = p.Pack();
|
||||||
|
EXPECT_EQ(val, 0x87FFFF6D);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Pixel, UnpackRGBA) {
|
||||||
|
uint32 rgba = 0x4619B3FE;
|
||||||
|
FasTC::Pixel p;
|
||||||
|
|
||||||
|
p.Unpack(rgba);
|
||||||
|
EXPECT_EQ(p.A(), 0x46);
|
||||||
|
EXPECT_EQ(p.B(), 0x19);
|
||||||
|
EXPECT_EQ(p.G(), 0xB3);
|
||||||
|
EXPECT_EQ(p.R(), 0xFE);
|
||||||
|
|
||||||
|
p = FasTC::Pixel(rgba);
|
||||||
|
EXPECT_EQ(p.A(), 0x46);
|
||||||
|
EXPECT_EQ(p.B(), 0x19);
|
||||||
|
EXPECT_EQ(p.G(), 0xB3);
|
||||||
|
EXPECT_EQ(p.R(), 0xFE);
|
||||||
|
|
||||||
|
p = FasTC::Pixel();
|
||||||
|
uint8 newBitDepth[4] = { 3, 5, 2, 1 }; // A R G B
|
||||||
|
p.ChangeBitDepth(newBitDepth);
|
||||||
|
p.Unpack(rgba);
|
||||||
|
|
||||||
|
EXPECT_EQ(p.A(), 0x2);
|
||||||
|
EXPECT_EQ(p.B(), 0x0);
|
||||||
|
EXPECT_EQ(p.G(), 0x3);
|
||||||
|
EXPECT_EQ(p.R(), 0x1f);
|
||||||
|
}
|
82
Base/test/Utils.h
Normal file
82
Base/test/Utils.h
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
/* 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/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PVRTCENCODER_TEST_TESTUTILS_H_
|
||||||
|
#define PVRTCENCODER_TEST_TESTUTILS_H_
|
||||||
|
|
||||||
|
#include "TexCompTypes.h"
|
||||||
|
|
||||||
|
class PixelPrinter {
|
||||||
|
private:
|
||||||
|
uint32 m_PixelValue;
|
||||||
|
public:
|
||||||
|
explicit PixelPrinter(uint32 p) : m_PixelValue(p) { }
|
||||||
|
bool operator==(const PixelPrinter &other) const {
|
||||||
|
return other.m_PixelValue == this->m_PixelValue;
|
||||||
|
}
|
||||||
|
uint32 Value() const { return m_PixelValue; }
|
||||||
|
};
|
||||||
|
|
||||||
|
inline ::std::ostream& operator<<(::std::ostream& os, const PixelPrinter& pp) {
|
||||||
|
uint32 p = pp.Value();
|
||||||
|
uint32 r = p & 0xFF;
|
||||||
|
uint32 g = (p >> 8) & 0xFF;
|
||||||
|
uint32 b = (p >> 16) & 0xFF;
|
||||||
|
uint32 a = (p >> 24) & 0xFF;
|
||||||
|
return os <<
|
||||||
|
"R: 0x" << ::std::hex << r << " " <<
|
||||||
|
"G: 0x" << ::std::hex << g << " " <<
|
||||||
|
"B: 0x" << ::std::hex << b << " " <<
|
||||||
|
"A: 0x" << ::std::hex << a;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // PVRTCENCODER_TEST_TESTUTILS_H_
|
|
@ -217,7 +217,7 @@ int main(int argc, char **argv) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Image img = Image(*file.GetImage());
|
FasTC::Image<> img(*file.GetImage());
|
||||||
if(format == eCompressionFormat_PVRTC) {
|
if(format == eCompressionFormat_PVRTC) {
|
||||||
img.SetBlockStreamOrder(false);
|
img.SetBlockStreamOrder(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ SET(CMAKE_MODULE_PATH "${FasTC_SOURCE_DIR}/CMakeModules" ${CMAKE_MODULE_PATH})
|
||||||
FIND_PACKAGE(PVRTexLib)
|
FIND_PACKAGE(PVRTexLib)
|
||||||
|
|
||||||
SET(FASTC_DIRECTORIES
|
SET(FASTC_DIRECTORIES
|
||||||
BPTCEncoder PVRTCEncoder IO Core Base
|
Base Core IO BPTCEncoder PVRTCEncoder
|
||||||
)
|
)
|
||||||
|
|
||||||
FOREACH(DIR ${FASTC_DIRECTORIES})
|
FOREACH(DIR ${FASTC_DIRECTORIES})
|
||||||
|
|
|
@ -57,10 +57,10 @@ enum ECompressionFormat {
|
||||||
|
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
|
|
||||||
class CompressedImage : public Image {
|
class CompressedImage : public FasTC::Image<FasTC::Pixel> {
|
||||||
private:
|
private:
|
||||||
ECompressionFormat m_Format;
|
ECompressionFormat m_Format;
|
||||||
uint32 *m_RGBAData;
|
uint8 *m_CompressedData;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CompressedImage(const CompressedImage &);
|
CompressedImage(const CompressedImage &);
|
||||||
|
@ -78,12 +78,11 @@ class CompressedImage : public Image {
|
||||||
|
|
||||||
virtual ~CompressedImage();
|
virtual ~CompressedImage();
|
||||||
|
|
||||||
virtual Image *Clone() const {
|
virtual FasTC::Image<FasTC::Pixel> *Clone() const {
|
||||||
return new CompressedImage(*this);
|
return new CompressedImage(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ComputeRGBA();
|
virtual void ComputePixels();
|
||||||
virtual const uint32 *GetRGBA() const { return m_RGBAData; }
|
|
||||||
|
|
||||||
static uint32 GetCompressedSize(uint32 uncompressedSize, ECompressionFormat format);
|
static uint32 GetCompressedSize(uint32 uncompressedSize, ECompressionFormat format);
|
||||||
static uint32 GetUncompressedSize(uint32 compressedSize, ECompressionFormat format) {
|
static uint32 GetUncompressedSize(uint32 compressedSize, ECompressionFormat format) {
|
||||||
|
@ -91,6 +90,13 @@ class CompressedImage : public Image {
|
||||||
return compressedSize * (compressedSize / cmp);
|
return compressedSize * (compressedSize / cmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32 GetCompressedSize() const {
|
||||||
|
return GetCompressedSize(GetUncompressedSize(), m_Format);
|
||||||
|
}
|
||||||
|
uint32 GetUncompressedSize() const {
|
||||||
|
return GetWidth() * GetHeight() * sizeof(uint32);
|
||||||
|
}
|
||||||
|
|
||||||
// Decompress the compressed image data into outBuf. outBufSz is expected
|
// Decompress the compressed image data into outBuf. outBufSz is expected
|
||||||
// to be the proper size determined by the width, height, and format.
|
// to be the proper size determined by the width, height, and format.
|
||||||
// !FIXME! We should have a function to explicitly return the in/out buf
|
// !FIXME! We should have a function to explicitly return the in/out buf
|
||||||
|
|
|
@ -48,9 +48,9 @@
|
||||||
#include "CompressionJob.h"
|
#include "CompressionJob.h"
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
#include "ImageFwd.h"
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
class Image;
|
|
||||||
class ImageFile;
|
class ImageFile;
|
||||||
|
|
||||||
struct SCompressionSettings {
|
struct SCompressionSettings {
|
||||||
|
@ -96,7 +96,8 @@ struct SCompressionSettings {
|
||||||
std::ostream *logStream;
|
std::ostream *logStream;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern CompressedImage *CompressImage(Image *img, const SCompressionSettings &settings);
|
template<typename PixelType>
|
||||||
|
extern CompressedImage *CompressImage(FasTC::Image<PixelType> *img, const SCompressionSettings &settings);
|
||||||
|
|
||||||
extern bool CompressImageData(
|
extern bool CompressImageData(
|
||||||
const unsigned char *data,
|
const unsigned char *data,
|
||||||
|
|
|
@ -48,6 +48,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "Pixel.h"
|
||||||
|
|
||||||
#include "TexCompTypes.h"
|
#include "TexCompTypes.h"
|
||||||
#include "BC7Compressor.h"
|
#include "BC7Compressor.h"
|
||||||
#include "PVRTCCompressor.h"
|
#include "PVRTCCompressor.h"
|
||||||
|
@ -55,11 +57,12 @@
|
||||||
CompressedImage::CompressedImage( const CompressedImage &other )
|
CompressedImage::CompressedImage( const CompressedImage &other )
|
||||||
: Image(other)
|
: Image(other)
|
||||||
, m_Format(other.m_Format)
|
, m_Format(other.m_Format)
|
||||||
, m_RGBAData(0)
|
, m_CompressedData(0)
|
||||||
{
|
{
|
||||||
if(other.m_RGBAData) {
|
if(other.m_CompressedData) {
|
||||||
m_RGBAData = new uint32[GetWidth() * GetHeight()];
|
uint32 compressedSz = GetCompressedSize();
|
||||||
memcpy(m_RGBAData, other.m_RGBAData, sizeof(uint32) * GetWidth() * GetHeight());
|
m_CompressedData = new uint8[compressedSz];
|
||||||
|
memcpy(m_CompressedData, other.m_CompressedData, compressedSz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,47 +72,44 @@ CompressedImage::CompressedImage(
|
||||||
const ECompressionFormat format,
|
const ECompressionFormat format,
|
||||||
const unsigned char *data
|
const unsigned char *data
|
||||||
)
|
)
|
||||||
: Image(width, height, NULL, format != eCompressionFormat_PVRTC)
|
: FasTC::Image<>(width, height,
|
||||||
|
reinterpret_cast<uint32 *>(NULL),
|
||||||
|
format != eCompressionFormat_PVRTC)
|
||||||
, m_Format(format)
|
, m_Format(format)
|
||||||
, m_RGBAData(0)
|
, m_CompressedData(0)
|
||||||
{
|
{
|
||||||
m_DataSz = GetCompressedSize(GetWidth() * GetHeight() * 4, m_Format);
|
uint32 cmpSz = GetCompressedSize();
|
||||||
if(m_DataSz > 0) {
|
if(cmpSz > 0) {
|
||||||
assert(!m_Data);
|
assert(!m_CompressedData);
|
||||||
m_Data = new unsigned char[m_DataSz];
|
m_CompressedData = new uint8[cmpSz];
|
||||||
memcpy(m_Data, data, m_DataSz);
|
memcpy(m_CompressedData, data, cmpSz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CompressedImage &CompressedImage::operator=(const CompressedImage &other) {
|
CompressedImage &CompressedImage::operator=(const CompressedImage &other) {
|
||||||
Image::operator=(other);
|
Image::operator=(other);
|
||||||
m_Format = other.m_Format;
|
m_Format = other.m_Format;
|
||||||
if(other.m_RGBAData) {
|
if(other.m_CompressedData) {
|
||||||
m_RGBAData = new uint32[GetWidth() * GetHeight()];
|
uint32 cmpSz = GetCompressedSize();
|
||||||
memcpy(m_RGBAData, other.m_RGBAData, sizeof(uint32) * GetWidth() * GetHeight());
|
m_CompressedData = new uint8[cmpSz];
|
||||||
|
memcpy(m_CompressedData, other.m_CompressedData, cmpSz);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompressedImage::~CompressedImage() {
|
CompressedImage::~CompressedImage() {
|
||||||
if(m_RGBAData) {
|
if(m_CompressedData) {
|
||||||
delete m_RGBAData;
|
delete m_CompressedData;
|
||||||
m_RGBAData = NULL;
|
m_CompressedData = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompressedImage::DecompressImage(unsigned char *outBuf, unsigned int outBufSz) const {
|
bool CompressedImage::DecompressImage(unsigned char *outBuf, unsigned int outBufSz) const {
|
||||||
|
|
||||||
// First make sure that we have enough data
|
assert(outBufSz == GetUncompressedSize());
|
||||||
uint32 dataSz = GetUncompressedSize(m_DataSz, m_Format);
|
|
||||||
if(dataSz > outBufSz) {
|
|
||||||
fprintf(stderr, "Not enough space to store entire decompressed image! "
|
|
||||||
"Got %d bytes, but need %d!\n", outBufSz, dataSz);
|
|
||||||
assert(false);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
DecompressionJob dj (m_Data, outBuf, GetWidth(), GetHeight());
|
uint8 *byteData = reinterpret_cast<uint8 *>(m_CompressedData);
|
||||||
|
DecompressionJob dj (byteData, outBuf, GetWidth(), GetHeight());
|
||||||
switch(m_Format) {
|
switch(m_Format) {
|
||||||
case eCompressionFormat_PVRTC:
|
case eCompressionFormat_PVRTC:
|
||||||
{
|
{
|
||||||
|
@ -135,15 +135,20 @@ bool CompressedImage::DecompressImage(unsigned char *outBuf, unsigned int outBuf
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompressedImage::ComputeRGBA() {
|
void CompressedImage::ComputePixels() {
|
||||||
|
|
||||||
if(m_RGBAData) {
|
uint32 unCompSz = GetWidth() * GetHeight() * 4;
|
||||||
delete m_RGBAData;
|
uint8 *unCompBuf = new uint8[unCompSz];
|
||||||
|
DecompressImage(unCompBuf, unCompSz);
|
||||||
|
|
||||||
|
uint32 * newPixelBuf = reinterpret_cast<uint32 *>(unCompBuf);
|
||||||
|
|
||||||
|
FasTC::Pixel *newPixels = new FasTC::Pixel[GetWidth() * GetHeight()];
|
||||||
|
for(uint32 i = 0; i < GetWidth() * GetHeight(); i++) {
|
||||||
|
newPixels[i].Unpack(newPixelBuf[i]);
|
||||||
}
|
}
|
||||||
m_RGBAData = new uint32[GetWidth() * GetHeight()];
|
|
||||||
|
|
||||||
uint8 *pixelData = reinterpret_cast<uint8 *>(m_RGBAData);
|
SetImageData(GetWidth(), GetHeight(), newPixels);
|
||||||
DecompressImage(pixelData, GetWidth() * GetHeight() * 4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 CompressedImage::GetCompressedSize(uint32 uncompressedSize, ECompressionFormat format) {
|
uint32 CompressedImage::GetCompressedSize(uint32 uncompressedSize, ECompressionFormat format) {
|
||||||
|
@ -167,4 +172,3 @@ uint32 CompressedImage::GetCompressedSize(uint32 uncompressedSize, ECompressionF
|
||||||
|
|
||||||
return cmpDataSzNeeded;
|
return cmpDataSzNeeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@
|
||||||
#include "CompressionFuncs.h"
|
#include "CompressionFuncs.h"
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
#include "ImageFile.h"
|
#include "ImageFile.h"
|
||||||
|
#include "Pixel.h"
|
||||||
#include "PVRTCCompressor.h"
|
#include "PVRTCCompressor.h"
|
||||||
#include "Thread.h"
|
#include "Thread.h"
|
||||||
#include "ThreadGroup.h"
|
#include "ThreadGroup.h"
|
||||||
|
@ -358,8 +359,9 @@ static double CompressImageWithWorkerQueue(
|
||||||
return cmpTimeTotal / double(settings.iNumCompressions);
|
return cmpTimeTotal / double(settings.iNumCompressions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename PixelType>
|
||||||
CompressedImage *CompressImage(
|
CompressedImage *CompressImage(
|
||||||
Image *img, const SCompressionSettings &settings
|
FasTC::Image<PixelType> *img, const SCompressionSettings &settings
|
||||||
) {
|
) {
|
||||||
if(!img) return NULL;
|
if(!img) return NULL;
|
||||||
|
|
||||||
|
@ -368,6 +370,7 @@ CompressedImage *CompressImage(
|
||||||
|
|
||||||
CompressedImage *outImg = NULL;
|
CompressedImage *outImg = NULL;
|
||||||
const unsigned int dataSz = w * h * 4;
|
const unsigned int dataSz = w * h * 4;
|
||||||
|
uint32 *data = new uint32[dataSz / 4];
|
||||||
|
|
||||||
assert(dataSz > 0);
|
assert(dataSz > 0);
|
||||||
|
|
||||||
|
@ -375,24 +378,33 @@ CompressedImage *CompressImage(
|
||||||
uint32 cmpDataSz = CompressedImage::GetCompressedSize(dataSz, settings.format);
|
uint32 cmpDataSz = CompressedImage::GetCompressedSize(dataSz, settings.format);
|
||||||
|
|
||||||
// Make sure that we have RGBA data...
|
// Make sure that we have RGBA data...
|
||||||
img->ComputeRGBA();
|
img->ComputePixels();
|
||||||
|
const PixelType *pixels = img->GetPixels();
|
||||||
|
for(uint32 i = 0; i < img->GetNumPixels(); i++) {
|
||||||
|
data[i] = pixels[i].Pack();
|
||||||
|
}
|
||||||
|
|
||||||
unsigned char *cmpData = new unsigned char[cmpDataSz];
|
unsigned char *cmpData = new unsigned char[cmpDataSz];
|
||||||
const uint8 *pixelData = reinterpret_cast<const uint8 *>(img->GetRGBA());
|
CompressImageData(reinterpret_cast<uint8 *>(data), w, h, cmpData, cmpDataSz, settings);
|
||||||
CompressImageData(pixelData, w, h, cmpData, cmpDataSz, settings);
|
|
||||||
|
|
||||||
outImg = new CompressedImage(w, h, settings.format, cmpData);
|
outImg = new CompressedImage(w, h, settings.format, cmpData);
|
||||||
|
|
||||||
|
delete [] data;
|
||||||
delete [] cmpData;
|
delete [] cmpData;
|
||||||
return outImg;
|
return outImg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// !FIXME! Ideally, we wouldn't have to do this because there would be a way to instantiate this
|
||||||
|
// function in the header or using some fancy template metaprogramming. I can't think of the way
|
||||||
|
// at the moment.
|
||||||
|
template CompressedImage *CompressImage(FasTC::Image<FasTC::Pixel> *, const SCompressionSettings &settings);
|
||||||
|
|
||||||
bool CompressImageData(
|
bool CompressImageData(
|
||||||
const unsigned char *data,
|
const uint8 *data,
|
||||||
const unsigned int width,
|
const uint32 width,
|
||||||
const unsigned int height,
|
const uint32 height,
|
||||||
unsigned char *cmpData,
|
uint8 *compressedData,
|
||||||
const unsigned int cmpDataSz,
|
const uint32 cmpDataSz,
|
||||||
const SCompressionSettings &settings
|
const SCompressionSettings &settings
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
@ -426,14 +438,14 @@ bool CompressImageData(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate data based on the compression method
|
// Allocate data based on the compression method
|
||||||
uint32 cmpDataSzNeeded =
|
uint32 compressedDataSzNeeded =
|
||||||
CompressedImage::GetCompressedSize(dataSz, settings.format);
|
CompressedImage::GetCompressedSize(dataSz, settings.format);
|
||||||
|
|
||||||
if(cmpDataSzNeeded == 0) {
|
if(compressedDataSzNeeded == 0) {
|
||||||
ReportError("Unknown compression format");
|
ReportError("Unknown compression format");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if(cmpDataSzNeeded > cmpDataSz) {
|
else if(compressedDataSzNeeded > cmpDataSz) {
|
||||||
ReportError("Not enough space for compressed data!");
|
ReportError("Not enough space for compressed data!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -445,15 +457,15 @@ bool CompressImageData(
|
||||||
|
|
||||||
if(numThreads > 1) {
|
if(numThreads > 1) {
|
||||||
if(settings.bUseAtomics) {
|
if(settings.bUseAtomics) {
|
||||||
cmpMSTime = CompressImageWithAtomics(data, width, height, settings, cmpData);
|
cmpMSTime = CompressImageWithAtomics(data, width, height, settings, compressedData);
|
||||||
} else if(settings.iJobSize > 0) {
|
} else if(settings.iJobSize > 0) {
|
||||||
cmpMSTime = CompressImageWithWorkerQueue(data, dataSz, settings, cmpData);
|
cmpMSTime = CompressImageWithWorkerQueue(data, dataSz, settings, compressedData);
|
||||||
} else {
|
} else {
|
||||||
cmpMSTime = CompressImageWithThreads(data, dataSz, settings, cmpData);
|
cmpMSTime = CompressImageWithThreads(data, dataSz, settings, compressedData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cmpMSTime = CompressImageInSerial(data, width, height, settings, cmpData);
|
cmpMSTime = CompressImageInSerial(data, width, height, settings, compressedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report compression time
|
// Report compression time
|
||||||
|
|
|
@ -47,19 +47,23 @@
|
||||||
#include "ImageFileFormat.h"
|
#include "ImageFileFormat.h"
|
||||||
#include "TexCompTypes.h"
|
#include "TexCompTypes.h"
|
||||||
|
|
||||||
|
namespace FasTC {
|
||||||
|
class Pixel;
|
||||||
|
}
|
||||||
|
|
||||||
class ImageWriter {
|
class ImageWriter {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
const uint8 *m_PixelData;
|
const FasTC::Pixel *m_Pixels;
|
||||||
uint32 m_RawFileDataSz;
|
uint32 m_RawFileDataSz;
|
||||||
uint8 *m_RawFileData;
|
uint8 *m_RawFileData;
|
||||||
|
|
||||||
uint32 m_Width;
|
uint32 m_Width;
|
||||||
uint32 m_Height;
|
uint32 m_Height;
|
||||||
|
|
||||||
ImageWriter(const int width, const int height, const uint8 *rawData)
|
ImageWriter(const int width, const int height, const FasTC::Pixel *rawData)
|
||||||
: m_PixelData(rawData)
|
: m_Pixels(rawData)
|
||||||
, m_RawFileDataSz(256)
|
, m_RawFileDataSz(256)
|
||||||
, m_RawFileData(new uint8[m_RawFileDataSz])
|
, m_RawFileData(new uint8[m_RawFileDataSz])
|
||||||
, m_Width(width), m_Height(height)
|
, m_Width(width), m_Height(height)
|
||||||
|
@ -77,7 +81,7 @@ class ImageWriter {
|
||||||
|
|
||||||
uint32 GetWidth() const { return m_Width; }
|
uint32 GetWidth() const { return m_Width; }
|
||||||
uint32 GetHeight() const { return m_Height; }
|
uint32 GetHeight() const { return m_Height; }
|
||||||
uint32 GetImageDataSz() const { return m_Width * m_Height * 4; }
|
uint32 GetImageDataSz() const { return m_Width * m_Height * sizeof(uint32); }
|
||||||
uint32 GetRawFileDataSz() const { return m_RawFileDataSz; }
|
uint32 GetRawFileDataSz() const { return m_RawFileDataSz; }
|
||||||
uint8 *GetRawFileData() const { return m_RawFileData; }
|
uint8 *GetRawFileData() const { return m_RawFileData; }
|
||||||
virtual bool WriteImage() = 0;
|
virtual bool WriteImage() = 0;
|
||||||
|
|
|
@ -46,9 +46,9 @@
|
||||||
|
|
||||||
#include "TexCompTypes.h"
|
#include "TexCompTypes.h"
|
||||||
#include "ImageFileFormat.h"
|
#include "ImageFileFormat.h"
|
||||||
|
#include "ImageFwd.h"
|
||||||
|
|
||||||
// Forward declare
|
// Forward declare
|
||||||
class Image;
|
|
||||||
class CompressedImage;
|
class CompressedImage;
|
||||||
struct SCompressionSettings;
|
struct SCompressionSettings;
|
||||||
|
|
||||||
|
@ -66,13 +66,13 @@ public:
|
||||||
|
|
||||||
// Creates an imagefile with the corresponding image data. This is ready
|
// Creates an imagefile with the corresponding image data. This is ready
|
||||||
// to be written to disk with the passed filename.
|
// to be written to disk with the passed filename.
|
||||||
ImageFile(const char *filename, EImageFileFormat format, const Image &);
|
ImageFile(const char *filename, EImageFileFormat format, const FasTC::Image<> &);
|
||||||
|
|
||||||
~ImageFile();
|
~ImageFile();
|
||||||
|
|
||||||
unsigned int GetWidth() const { return m_Width; }
|
unsigned int GetWidth() const { return m_Width; }
|
||||||
unsigned int GetHeight() const { return m_Height; }
|
unsigned int GetHeight() const { return m_Height; }
|
||||||
Image *GetImage() const { return m_Image; }
|
FasTC::Image<> *GetImage() const { return m_Image; }
|
||||||
|
|
||||||
// Loads the image into memory. If this function returns true, then a valid
|
// Loads the image into memory. If this function returns true, then a valid
|
||||||
// m_Image will be created and available.
|
// m_Image will be created and available.
|
||||||
|
@ -91,12 +91,12 @@ public:
|
||||||
|
|
||||||
const EImageFileFormat m_FileFormat;
|
const EImageFileFormat m_FileFormat;
|
||||||
|
|
||||||
Image *m_Image;
|
FasTC::Image<> *m_Image;
|
||||||
|
|
||||||
static unsigned char *ReadFileData(const CHAR *filename);
|
static unsigned char *ReadFileData(const CHAR *filename);
|
||||||
static bool WriteImageDataToFile(const uint8 *data, const uint32 dataSz, const CHAR *filename);
|
static bool WriteImageDataToFile(const uint8 *data, const uint32 dataSz, const CHAR *filename);
|
||||||
static EImageFileFormat DetectFileFormat(const CHAR *filename);
|
static EImageFileFormat DetectFileFormat(const CHAR *filename);
|
||||||
|
|
||||||
Image *LoadImage(const unsigned char *rawImageData) const;
|
FasTC::Image<> *LoadImage(const unsigned char *rawImageData) const;
|
||||||
};
|
};
|
||||||
#endif // _IMAGE_FILE_H_
|
#endif // _IMAGE_FILE_H_
|
||||||
|
|
|
@ -105,7 +105,7 @@ ImageFile::ImageFile(const CHAR *filename, EImageFileFormat format)
|
||||||
strncpy(m_Filename, filename, kMaxFilenameSz);
|
strncpy(m_Filename, filename, kMaxFilenameSz);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageFile::ImageFile(const char *filename, EImageFileFormat format, const Image &image)
|
ImageFile::ImageFile(const char *filename, EImageFileFormat format, const FasTC::Image<> &image)
|
||||||
: m_FileFormat(format)
|
: m_FileFormat(format)
|
||||||
, m_Image(image.Clone())
|
, m_Image(image.Clone())
|
||||||
{
|
{
|
||||||
|
@ -165,7 +165,7 @@ bool ImageFile::Write() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Image *ImageFile::LoadImage(const unsigned char *rawImageData) const {
|
FasTC::Image<> *ImageFile::LoadImage(const unsigned char *rawImageData) const {
|
||||||
|
|
||||||
ImageLoader *loader = NULL;
|
ImageLoader *loader = NULL;
|
||||||
switch(m_FileFormat) {
|
switch(m_FileFormat) {
|
||||||
|
@ -207,7 +207,7 @@ Image *ImageFile::LoadImage(const unsigned char *rawImageData) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 *pixels = reinterpret_cast<uint32 *>(pixelData);
|
uint32 *pixels = reinterpret_cast<uint32 *>(pixelData);
|
||||||
Image *i = new Image(loader->GetWidth(), loader->GetHeight(), pixels, true);
|
FasTC::Image<> *i = new FasTC::Image<>(loader->GetWidth(), loader->GetHeight(), pixels, true);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
delete loader;
|
delete loader;
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ImageWriter.h"
|
#include "ImageWriter.h"
|
||||||
|
#include "Pixel.h"
|
||||||
|
|
||||||
uint32 ImageWriter::GetChannelForPixel(uint32 x, uint32 y, uint32 ch) {
|
uint32 ImageWriter::GetChannelForPixel(uint32 x, uint32 y, uint32 ch) {
|
||||||
|
|
||||||
|
@ -58,10 +59,8 @@ uint32 ImageWriter::GetChannelForPixel(uint32 x, uint32 y, uint32 ch) {
|
||||||
const uint32 blockOffsetY = y % 4;
|
const uint32 blockOffsetY = y % 4;
|
||||||
const uint32 pixelOffset = blockOffsetY * 4 + blockOffsetX;
|
const uint32 pixelOffset = blockOffsetY * 4 + blockOffsetX;
|
||||||
|
|
||||||
// There are 16 pixels per block and bytes per pixel...
|
// There are 16 pixels per block...
|
||||||
uint32 dataOffset = blockIdx * 4 * 16;
|
uint32 dataOffset = blockIdx * 16 + pixelOffset;
|
||||||
dataOffset += 4 * pixelOffset;
|
|
||||||
dataOffset += ch;
|
|
||||||
|
|
||||||
return m_PixelData[dataOffset];
|
return m_Pixels[dataOffset].Component(ch);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,14 +43,15 @@
|
||||||
|
|
||||||
#include "ImageWriterPNG.h"
|
#include "ImageWriterPNG.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <cstdlib>
|
||||||
#include <stdio.h>
|
#include <cstdio>
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
|
|
||||||
#include "Image.h"
|
|
||||||
|
|
||||||
#include <png.h>
|
#include <png.h>
|
||||||
|
|
||||||
|
#include "Image.h"
|
||||||
|
#include "Pixel.h"
|
||||||
|
|
||||||
class PNGStreamWriter {
|
class PNGStreamWriter {
|
||||||
public:
|
public:
|
||||||
static void WriteDataToStream(
|
static void WriteDataToStream(
|
||||||
|
@ -84,13 +85,13 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ImageWriterPNG::ImageWriterPNG(Image &im)
|
ImageWriterPNG::ImageWriterPNG(FasTC::Image<> &im)
|
||||||
: ImageWriter(im.GetWidth(), im.GetHeight(), im.RawData())
|
: ImageWriter(im.GetWidth(), im.GetHeight(), im.GetPixels())
|
||||||
, m_bBlockStreamOrder(im.GetBlockStreamOrder())
|
, m_bBlockStreamOrder(im.GetBlockStreamOrder())
|
||||||
, m_StreamPosition(0)
|
, m_StreamPosition(0)
|
||||||
{
|
{
|
||||||
im.ComputeRGBA();
|
im.ComputePixels();
|
||||||
m_PixelData = reinterpret_cast<const uint8 *>(im.GetRGBA());
|
m_Pixels = im.GetPixels();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImageWriterPNG::WriteImage() {
|
bool ImageWriterPNG::WriteImage() {
|
||||||
|
@ -136,8 +137,7 @@ bool ImageWriterPNG::WriteImage() {
|
||||||
*row++ = GetChannelForPixel(x, y, ch);
|
*row++ = GetChannelForPixel(x, y, ch);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
reinterpret_cast<uint32 *>(row)[x] =
|
reinterpret_cast<uint32 *>(row)[x] = m_Pixels[y * m_Width + x].Pack();
|
||||||
reinterpret_cast<const uint32 *>(m_PixelData)[y * m_Width + x];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,12 +45,12 @@
|
||||||
#define _IMAGE_WRITER_PNG_H_
|
#define _IMAGE_WRITER_PNG_H_
|
||||||
|
|
||||||
#include "ImageWriter.h"
|
#include "ImageWriter.h"
|
||||||
|
#include "ImageFwd.h"
|
||||||
|
|
||||||
// Forward Declare
|
// Forward Declare
|
||||||
class Image;
|
|
||||||
class ImageWriterPNG : public ImageWriter {
|
class ImageWriterPNG : public ImageWriter {
|
||||||
public:
|
public:
|
||||||
ImageWriterPNG(Image &);
|
ImageWriterPNG(FasTC::Image<> &);
|
||||||
virtual ~ImageWriterPNG() { }
|
virtual ~ImageWriterPNG() { }
|
||||||
|
|
||||||
virtual bool WriteImage();
|
virtual bool WriteImage();
|
||||||
|
|
|
@ -56,17 +56,15 @@ INCLUDE_DIRECTORIES(${FasTC_SOURCE_DIR}/Base/include)
|
||||||
|
|
||||||
SET( HEADERS
|
SET( HEADERS
|
||||||
include/PVRTCCompressor.h
|
include/PVRTCCompressor.h
|
||||||
src/Pixel.h
|
|
||||||
src/Block.h
|
src/Block.h
|
||||||
src/Image.h
|
src/PVRTCImage.h
|
||||||
)
|
)
|
||||||
|
|
||||||
SET( SOURCES
|
SET( SOURCES
|
||||||
src/Compressor.cpp
|
src/Compressor.cpp
|
||||||
src/Decompressor.cpp
|
src/Decompressor.cpp
|
||||||
src/Pixel.cpp
|
|
||||||
src/Block.cpp
|
src/Block.cpp
|
||||||
src/Image.cpp
|
src/PVRTCImage.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
CONFIGURE_FILE(
|
CONFIGURE_FILE(
|
||||||
|
@ -87,6 +85,7 @@ ADD_LIBRARY( PVRTCEncoder
|
||||||
${SOURCES}
|
${SOURCES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
TARGET_LINK_LIBRARIES( PVRTCEncoder FasTCBase )
|
||||||
TARGET_LINK_LIBRARIES( PVRTCEncoder FasTCCore )
|
TARGET_LINK_LIBRARIES( PVRTCEncoder FasTCCore )
|
||||||
TARGET_LINK_LIBRARIES( PVRTCEncoder FasTCIO )
|
TARGET_LINK_LIBRARIES( PVRTCEncoder FasTCIO )
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
|
|
||||||
namespace PVRTCC {
|
namespace PVRTCC {
|
||||||
|
|
||||||
|
using FasTC::Pixel;
|
||||||
class Block {
|
class Block {
|
||||||
public:
|
public:
|
||||||
Block(): m_LongData(0) { }
|
Block(): m_LongData(0) { }
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Pixel.h"
|
#include "Pixel.h"
|
||||||
#include "Image.h"
|
#include "PVRTCImage.h"
|
||||||
#include "Block.h"
|
#include "Block.h"
|
||||||
|
|
||||||
namespace PVRTCC {
|
namespace PVRTCC {
|
||||||
|
@ -130,7 +130,7 @@ namespace PVRTCC {
|
||||||
uint32 y = i / dcj.width;
|
uint32 y = i / dcj.width;
|
||||||
|
|
||||||
const uint32 *pixels = reinterpret_cast<const uint32 *>(dcj.inBuf);
|
const uint32 *pixels = reinterpret_cast<const uint32 *>(dcj.inBuf);
|
||||||
img(x, y).UnpackRGBA(pixels[i]);
|
img(x, y).Unpack(pixels[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Image original = img;
|
Image original = img;
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
|
|
||||||
#include "Pixel.h"
|
#include "Pixel.h"
|
||||||
#include "Block.h"
|
#include "Block.h"
|
||||||
#include "Image.h"
|
#include "PVRTCImage.h"
|
||||||
|
|
||||||
namespace PVRTCC {
|
namespace PVRTCC {
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ namespace PVRTCC {
|
||||||
assert(imgA.GetWidth() == imgB.GetWidth());
|
assert(imgA.GetWidth() == imgB.GetWidth());
|
||||||
assert(imgA.GetHeight() == imgB.GetHeight());
|
assert(imgA.GetHeight() == imgB.GetHeight());
|
||||||
|
|
||||||
Image debugModulation(h, w);
|
Image debugModulation(w, h);
|
||||||
const uint8 debugModulationBitDepth[4] = { 8, 4, 4, 4 };
|
const uint8 debugModulationBitDepth[4] = { 8, 4, 4, 4 };
|
||||||
debugModulation.ChangeBitDepth(debugModulationBitDepth);
|
debugModulation.ChangeBitDepth(debugModulationBitDepth);
|
||||||
|
|
||||||
|
@ -113,7 +113,6 @@ namespace PVRTCC {
|
||||||
const Pixel &pa = imgA(i, j);
|
const Pixel &pa = imgA(i, j);
|
||||||
const Pixel &pb = imgB(i, j);
|
const Pixel &pb = imgB(i, j);
|
||||||
|
|
||||||
Pixel result;
|
|
||||||
bool punchThrough = false;
|
bool punchThrough = false;
|
||||||
uint8 lerpVal = 0;
|
uint8 lerpVal = 0;
|
||||||
if(b.GetModeBit()) {
|
if(b.GetModeBit()) {
|
||||||
|
@ -147,20 +146,13 @@ namespace PVRTCC {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint32 c = 0; c < 4; c++) {
|
Pixel result = (pa * (8 - lerpVal) + pb * lerpVal) / 8;
|
||||||
uint16 va = static_cast<uint16>(pa.Component(c));
|
|
||||||
uint16 vb = static_cast<uint16>(pb.Component(c));
|
|
||||||
|
|
||||||
uint16 res = (va * (8 - lerpVal) + vb * lerpVal) / 8;
|
|
||||||
result.Component(c) = static_cast<uint8>(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(punchThrough) {
|
if(punchThrough) {
|
||||||
result.A() = 0;
|
result.A() = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 *outPixels = reinterpret_cast<uint32 *>(outBuf);
|
uint32 *outPixels = reinterpret_cast<uint32 *>(outBuf);
|
||||||
outPixels[(j * w) + i] = result.PackRGBA();
|
outPixels[(j * w) + i] = result.Pack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,22 +251,14 @@ namespace PVRTCC {
|
||||||
const Pixel &pa = imgA(i, j);
|
const Pixel &pa = imgA(i, j);
|
||||||
const Pixel &pb = imgB(i, j);
|
const Pixel &pb = imgB(i, j);
|
||||||
|
|
||||||
Pixel result;
|
Pixel result = (pa * (8 - lerpVal) + pb * lerpVal) / 8;
|
||||||
for(uint32 c = 0; c < 4; c++) {
|
|
||||||
uint16 va = static_cast<uint16>(pa.Component(c));
|
|
||||||
uint16 vb = static_cast<uint16>(pb.Component(c));
|
|
||||||
|
|
||||||
uint16 res = (va * (8 - lerpVal) + vb * lerpVal) / 8;
|
|
||||||
result.Component(c) = static_cast<uint8>(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32 *outPixels = reinterpret_cast<uint32 *>(outBuf);
|
uint32 *outPixels = reinterpret_cast<uint32 *>(outBuf);
|
||||||
outPixels[(j * w) + i] = result.PackRGBA();
|
outPixels[(j * w) + i] = result.Pack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bDebugImages) {
|
if(bDebugImages) {
|
||||||
Image dbgMod(h, w);
|
Image dbgMod(w, h);
|
||||||
for(uint32 i = 0; i < h*w; i++) {
|
for(uint32 i = 0; i < h*w; i++) {
|
||||||
float fb = static_cast<float>(modValues[i]);
|
float fb = static_cast<float>(modValues[i]);
|
||||||
uint8 val = static_cast<uint8>((fb / 8.0f) * 15.0f);
|
uint8 val = static_cast<uint8>((fb / 8.0f) * 15.0f);
|
||||||
|
@ -324,8 +308,8 @@ namespace PVRTCC {
|
||||||
assert(blocks.size() > 0);
|
assert(blocks.size() > 0);
|
||||||
|
|
||||||
// Extract the endpoints into A and B images
|
// Extract the endpoints into A and B images
|
||||||
Image imgA(blocksH, blocksW);
|
Image imgA(blocksW, blocksH);
|
||||||
Image imgB(blocksH, blocksW);
|
Image imgB(blocksW, blocksH);
|
||||||
|
|
||||||
for(uint32 j = 0; j < blocksH; j++) {
|
for(uint32 j = 0; j < blocksH; j++) {
|
||||||
for(uint32 i = 0; i < blocksW; i++) {
|
for(uint32 i = 0; i < blocksW; i++) {
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
# define snprintf _snprintf
|
# define snprintf _snprintf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Image.h"
|
#include "PVRTCImage.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
@ -64,6 +64,7 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "Pixel.h"
|
#include "Pixel.h"
|
||||||
|
using FasTC::Pixel;
|
||||||
|
|
||||||
#include "../../Base/include/Image.h"
|
#include "../../Base/include/Image.h"
|
||||||
#include "../../IO/include/ImageFile.h"
|
#include "../../IO/include/ImageFile.h"
|
||||||
|
@ -75,55 +76,39 @@ inline T Clamp(const T &v, const T &a, const T &b) {
|
||||||
|
|
||||||
namespace PVRTCC {
|
namespace PVRTCC {
|
||||||
|
|
||||||
Image::Image(uint32 height, uint32 width)
|
Image::Image(uint32 width, uint32 height)
|
||||||
: m_Width(width)
|
: FasTC::Image<FasTC::Pixel>(width, height)
|
||||||
, m_Height(height)
|
, m_FractionalPixels(new FasTC::Pixel[width * height]) {
|
||||||
, m_Pixels(new Pixel[width * height])
|
|
||||||
, m_FractionalPixels(new Pixel[width * height]) {
|
|
||||||
assert(width > 0);
|
assert(width > 0);
|
||||||
assert(height > 0);
|
assert(height > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Image::Image(uint32 height, uint32 width, const Pixel *pixels)
|
Image::Image(uint32 width, uint32 height, const FasTC::Pixel *pixels)
|
||||||
: m_Width(width)
|
: FasTC::Image<FasTC::Pixel>(width, height, pixels)
|
||||||
, m_Height(height)
|
, m_FractionalPixels(new FasTC::Pixel[width * height]) {
|
||||||
, m_Pixels(new Pixel[width * height])
|
|
||||||
, m_FractionalPixels(new Pixel[width * height]) {
|
|
||||||
assert(width > 0);
|
assert(width > 0);
|
||||||
assert(height > 0);
|
assert(height > 0);
|
||||||
memcpy(m_Pixels, pixels, width * height * sizeof(Pixel));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Image::Image(const Image &other)
|
Image::Image(const Image &other)
|
||||||
: m_Width(other.GetWidth())
|
: FasTC::Image<FasTC::Pixel>(other)
|
||||||
, m_Height(other.GetHeight())
|
, m_FractionalPixels(new FasTC::Pixel[other.GetWidth() * other.GetHeight()]) {
|
||||||
, m_Pixels(new Pixel[other.GetWidth() * other.GetHeight()])
|
memcpy(m_FractionalPixels, other.m_FractionalPixels, GetWidth() * GetHeight() * sizeof(FasTC::Pixel));
|
||||||
, m_FractionalPixels(new Pixel[other.GetWidth() * other.GetHeight()]) {
|
|
||||||
memcpy(m_Pixels, other.m_Pixels, GetWidth() * GetHeight() * sizeof(Pixel));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Image &Image::operator=(const Image &other) {
|
Image &Image::operator=(const Image &other) {
|
||||||
m_Width = other.GetWidth();
|
FasTC::Image<FasTC::Pixel>::operator=(other);
|
||||||
m_Height = other.GetHeight();
|
|
||||||
|
|
||||||
assert(m_Pixels);
|
|
||||||
delete m_Pixels;
|
|
||||||
m_Pixels = new Pixel[other.GetWidth() * other.GetHeight()];
|
|
||||||
memcpy(m_Pixels, other.m_Pixels, GetWidth() * GetHeight() * sizeof(Pixel));
|
|
||||||
|
|
||||||
assert(m_FractionalPixels);
|
assert(m_FractionalPixels);
|
||||||
delete m_FractionalPixels;
|
delete m_FractionalPixels;
|
||||||
m_FractionalPixels = new Pixel[other.GetWidth() * other.GetHeight()];
|
m_FractionalPixels = new FasTC::Pixel[other.GetWidth() * other.GetHeight()];
|
||||||
memcpy(m_FractionalPixels, other.m_FractionalPixels,
|
memcpy(m_FractionalPixels, other.m_FractionalPixels,
|
||||||
GetWidth() * GetHeight() * sizeof(Pixel));
|
GetWidth() * GetHeight() * sizeof(FasTC::Pixel));
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Image::~Image() {
|
Image::~Image() {
|
||||||
assert(m_Pixels);
|
|
||||||
delete [] m_Pixels;
|
|
||||||
|
|
||||||
assert(m_FractionalPixels);
|
assert(m_FractionalPixels);
|
||||||
delete [] m_FractionalPixels;
|
delete [] m_FractionalPixels;
|
||||||
}
|
}
|
||||||
|
@ -150,18 +135,18 @@ void Image::BilinearUpscale(uint32 xtimes, uint32 ytimes,
|
||||||
const uint32 yscale = 1 << ytimes;
|
const uint32 yscale = 1 << ytimes;
|
||||||
const uint32 yoffset = yscale >> 1;
|
const uint32 yoffset = yscale >> 1;
|
||||||
|
|
||||||
Pixel *upscaledPixels = new Pixel[newWidth * newHeight];
|
FasTC::Pixel *upscaledPixels = new FasTC::Pixel[newWidth * newHeight];
|
||||||
|
|
||||||
assert(m_FractionalPixels);
|
assert(m_FractionalPixels);
|
||||||
delete m_FractionalPixels;
|
delete m_FractionalPixels;
|
||||||
m_FractionalPixels = new Pixel[newWidth * newHeight];
|
m_FractionalPixels = new FasTC::Pixel[newWidth * newHeight];
|
||||||
|
|
||||||
for(uint32 j = 0; j < newHeight; j++) {
|
for(uint32 j = 0; j < newHeight; j++) {
|
||||||
for(uint32 i = 0; i < newWidth; i++) {
|
for(uint32 i = 0; i < newWidth; i++) {
|
||||||
|
|
||||||
const uint32 pidx = j * newWidth + i;
|
const uint32 pidx = j * newWidth + i;
|
||||||
Pixel &p = upscaledPixels[pidx];
|
FasTC::Pixel &p = upscaledPixels[pidx];
|
||||||
Pixel &fp = m_FractionalPixels[pidx];
|
FasTC::Pixel &fp = m_FractionalPixels[pidx];
|
||||||
|
|
||||||
const int32 highXIdx = (i + xoffset) / xscale;
|
const int32 highXIdx = (i + xoffset) / xscale;
|
||||||
const int32 lowXIdx = highXIdx - 1;
|
const int32 lowXIdx = highXIdx - 1;
|
||||||
|
@ -178,10 +163,10 @@ void Image::BilinearUpscale(uint32 xtimes, uint32 ytimes,
|
||||||
const uint32 bottomLeftWeight = lowXWeight * highYWeight;
|
const uint32 bottomLeftWeight = lowXWeight * highYWeight;
|
||||||
const uint32 bottomRightWeight = highXWeight * highYWeight;
|
const uint32 bottomRightWeight = highXWeight * highYWeight;
|
||||||
|
|
||||||
const Pixel &topLeft = GetPixel(lowXIdx, lowYIdx, wrapMode);
|
const FasTC::Pixel &topLeft = GetPixel(lowXIdx, lowYIdx, wrapMode);
|
||||||
const Pixel &topRight = GetPixel(highXIdx, lowYIdx, wrapMode);
|
const FasTC::Pixel &topRight = GetPixel(highXIdx, lowYIdx, wrapMode);
|
||||||
const Pixel &bottomLeft = GetPixel(lowXIdx, highYIdx, wrapMode);
|
const FasTC::Pixel &bottomLeft = GetPixel(lowXIdx, highYIdx, wrapMode);
|
||||||
const Pixel &bottomRight = GetPixel(highXIdx, highYIdx, wrapMode);
|
const FasTC::Pixel &bottomRight = GetPixel(highXIdx, highYIdx, wrapMode);
|
||||||
|
|
||||||
// Make sure the bit depth matches the original...
|
// Make sure the bit depth matches the original...
|
||||||
uint8 bitDepth[4];
|
uint8 bitDepth[4];
|
||||||
|
@ -207,22 +192,21 @@ void Image::BilinearUpscale(uint32 xtimes, uint32 ytimes,
|
||||||
for(uint32 c = 0; c < 4; c++) fpDepths[c] = xtimes + ytimes;
|
for(uint32 c = 0; c < 4; c++) fpDepths[c] = xtimes + ytimes;
|
||||||
fp.ChangeBitDepth(fpDepths);
|
fp.ChangeBitDepth(fpDepths);
|
||||||
|
|
||||||
|
const FasTC::Pixel tl = topLeft * topLeftWeight;
|
||||||
|
const FasTC::Pixel tr = topRight * topRightWeight;
|
||||||
|
const FasTC::Pixel bl = bottomLeft * bottomLeftWeight;
|
||||||
|
const FasTC::Pixel br = bottomRight * bottomRightWeight;
|
||||||
|
const FasTC::Pixel sum = tl + tr + bl + br;
|
||||||
|
|
||||||
for(uint32 c = 0; c < 4; c++) {
|
for(uint32 c = 0; c < 4; c++) {
|
||||||
const uint32 tl = topLeft.Component(c) * topLeftWeight;
|
fp.Component(c) = sum.Component(c) & scaleMask;
|
||||||
const uint32 tr = topRight.Component(c) * topRightWeight;
|
|
||||||
const uint32 bl = bottomLeft.Component(c) * bottomLeftWeight;
|
|
||||||
const uint32 br = bottomRight.Component(c) * bottomRightWeight;
|
|
||||||
const uint32 sum = tl + tr + bl + br;
|
|
||||||
fp.Component(c) = sum & scaleMask;
|
|
||||||
p.Component(c) = sum / (xscale * yscale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p = sum / (xscale * yscale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete m_Pixels;
|
SetImageData(newWidth, newHeight, upscaledPixels);
|
||||||
m_Pixels = upscaledPixels;
|
|
||||||
m_Width = newWidth;
|
|
||||||
m_Height = newHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Pixel AveragePixels(const ::std::vector<Pixel> &pixels) {
|
static Pixel AveragePixels(const ::std::vector<Pixel> &pixels) {
|
||||||
|
@ -256,7 +240,7 @@ void Image::AverageDownscale(uint32 xtimes, uint32 ytimes) {
|
||||||
Pixel *downscaledPixels = new Pixel[newWidth * newHeight];
|
Pixel *downscaledPixels = new Pixel[newWidth * newHeight];
|
||||||
|
|
||||||
uint8 bitDepth[4];
|
uint8 bitDepth[4];
|
||||||
m_Pixels[0].GetBitDepth(bitDepth);
|
GetPixel(0, 0).GetBitDepth(bitDepth);
|
||||||
|
|
||||||
uint32 pixelsX = 1 << xtimes;
|
uint32 pixelsX = 1 << xtimes;
|
||||||
uint32 pixelsY = 1 << ytimes;
|
uint32 pixelsY = 1 << ytimes;
|
||||||
|
@ -279,10 +263,7 @@ void Image::AverageDownscale(uint32 xtimes, uint32 ytimes) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete m_Pixels;
|
SetImageData(newWidth, newHeight, downscaledPixels);
|
||||||
m_Pixels = downscaledPixels;
|
|
||||||
m_Width = newWidth;
|
|
||||||
m_Height = newHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::ContentAwareDownscale(uint32 xtimes, uint32 ytimes,
|
void Image::ContentAwareDownscale(uint32 xtimes, uint32 ytimes,
|
||||||
|
@ -293,11 +274,11 @@ void Image::ContentAwareDownscale(uint32 xtimes, uint32 ytimes,
|
||||||
const uint32 newWidth = w >> xtimes;
|
const uint32 newWidth = w >> xtimes;
|
||||||
const uint32 newHeight = h >> ytimes;
|
const uint32 newHeight = h >> ytimes;
|
||||||
|
|
||||||
Pixel *downscaledPixels = new Pixel[newWidth * newHeight];
|
FasTC::Pixel *downscaledPixels = new FasTC::Pixel[newWidth * newHeight];
|
||||||
const uint32 numDownscaledPixels = newWidth * newHeight;
|
const uint32 numDownscaledPixels = newWidth * newHeight;
|
||||||
|
|
||||||
uint8 bitDepth[4];
|
uint8 bitDepth[4];
|
||||||
m_Pixels[0].GetBitDepth(bitDepth);
|
GetPixels()[0].GetBitDepth(bitDepth);
|
||||||
|
|
||||||
for(uint32 i = 0; i < numDownscaledPixels; i++) {
|
for(uint32 i = 0; i < numDownscaledPixels; i++) {
|
||||||
downscaledPixels[i].ChangeBitDepth(bitDepth);
|
downscaledPixels[i].ChangeBitDepth(bitDepth);
|
||||||
|
@ -335,7 +316,7 @@ void Image::ContentAwareDownscale(uint32 xtimes, uint32 ytimes,
|
||||||
|
|
||||||
// Then, compute the intensity of the image
|
// Then, compute the intensity of the image
|
||||||
for(uint32 i = 0; i < w * h; i++) {
|
for(uint32 i = 0; i < w * h; i++) {
|
||||||
I[i] = m_Pixels[i].ToIntensity();
|
I[i] = GetPixels()[i].ToIntensity();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use central differences to calculate Ix, Iy, Ixx, Iyy...
|
// Use central differences to calculate Ix, Iy, Ixx, Iyy...
|
||||||
|
@ -356,7 +337,7 @@ void Image::ContentAwareDownscale(uint32 xtimes, uint32 ytimes,
|
||||||
Iy[idx] = (I[yphidx] - I[ymhidx]) / 2.0f;
|
Iy[idx] = (I[yphidx] - I[ymhidx]) / 2.0f;
|
||||||
|
|
||||||
for(uint32 c = 0; c <= 3; c++) {
|
for(uint32 c = 0; c <= 3; c++) {
|
||||||
#define CPNT(dx) Pixel::ConvertChannelToFloat(m_Pixels[dx].Component(c), bitDepth[c])
|
#define CPNT(dx) Pixel::ConvertChannelToFloat(GetPixels()[dx].Component(c), bitDepth[c])
|
||||||
Ix[c][idx] = (CPNT(xphidx) - CPNT(xmhidx)) / 2.0f;
|
Ix[c][idx] = (CPNT(xphidx) - CPNT(xmhidx)) / 2.0f;
|
||||||
Ixx[c][idx] = (CPNT(xphidx) - 2.0f*CPNT(idx) + CPNT(xmhidx)) / 2.0f;
|
Ixx[c][idx] = (CPNT(xphidx) - 2.0f*CPNT(idx) + CPNT(xmhidx)) / 2.0f;
|
||||||
Iyy[c][idx] = (CPNT(yphidx) - 2.0f*CPNT(idx) + CPNT(ymhidx)) / 2.0f;
|
Iyy[c][idx] = (CPNT(yphidx) - 2.0f*CPNT(idx) + CPNT(ymhidx)) / 2.0f;
|
||||||
|
@ -387,9 +368,9 @@ void Image::ContentAwareDownscale(uint32 xtimes, uint32 ytimes,
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 idx = GetPixelIndex(x, y);
|
uint32 idx = GetPixelIndex(x, y);
|
||||||
Pixel current = m_Pixels[idx];
|
FasTC::Pixel current = GetPixels()[idx];
|
||||||
|
|
||||||
Pixel result;
|
FasTC::Pixel result;
|
||||||
result.ChangeBitDepth(bitDepth);
|
result.ChangeBitDepth(bitDepth);
|
||||||
|
|
||||||
float Ixsq = Ix[4][idx] * Ix[4][idx];
|
float Ixsq = Ix[4][idx] * Ix[4][idx];
|
||||||
|
@ -412,11 +393,7 @@ void Image::ContentAwareDownscale(uint32 xtimes, uint32 ytimes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete m_Pixels;
|
SetImageData(newWidth, newHeight, downscaledPixels);
|
||||||
m_Pixels = downscaledPixels;
|
|
||||||
m_Width = newWidth;
|
|
||||||
m_Height = newHeight;
|
|
||||||
|
|
||||||
delete [] imgData;
|
delete [] imgData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,15 +461,14 @@ void Image::ComputeHessianEigenvalues(::std::vector<float> &eigOne,
|
||||||
void Image::ChangeBitDepth(const uint8 (&depths)[4]) {
|
void Image::ChangeBitDepth(const uint8 (&depths)[4]) {
|
||||||
for(uint32 j = 0; j < GetHeight(); j++) {
|
for(uint32 j = 0; j < GetHeight(); j++) {
|
||||||
for(uint32 i = 0; i < GetWidth(); i++) {
|
for(uint32 i = 0; i < GetWidth(); i++) {
|
||||||
uint32 pidx = GetPixelIndex(i, j);
|
(*this)(i, j).ChangeBitDepth(depths);
|
||||||
m_Pixels[pidx].ChangeBitDepth(depths);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::ExpandTo8888() {
|
void Image::ExpandTo8888() {
|
||||||
uint8 currentDepth[4];
|
uint8 currentDepth[4];
|
||||||
m_Pixels[0].GetBitDepth(currentDepth);
|
GetPixels()[0].GetBitDepth(currentDepth);
|
||||||
|
|
||||||
uint8 fractionDepth[4];
|
uint8 fractionDepth[4];
|
||||||
const uint8 fullDepth[4] = { 8, 8, 8, 8 };
|
const uint8 fullDepth[4] = { 8, 8, 8, 8 };
|
||||||
|
@ -500,8 +476,10 @@ void Image::ExpandTo8888() {
|
||||||
for(uint32 j = 0; j < GetHeight(); j++) {
|
for(uint32 j = 0; j < GetHeight(); j++) {
|
||||||
for(uint32 i = 0; i < GetWidth(); i++) {
|
for(uint32 i = 0; i < GetWidth(); i++) {
|
||||||
|
|
||||||
|
FasTC::Pixel &p = (*this)(i, j);
|
||||||
|
p.ChangeBitDepth(fullDepth);
|
||||||
|
|
||||||
uint32 pidx = j * GetWidth() + i;
|
uint32 pidx = j * GetWidth() + i;
|
||||||
m_Pixels[pidx].ChangeBitDepth(fullDepth);
|
|
||||||
m_FractionalPixels[pidx].GetBitDepth(fractionDepth);
|
m_FractionalPixels[pidx].GetBitDepth(fractionDepth);
|
||||||
|
|
||||||
for(uint32 c = 0; c < 4; c++) {
|
for(uint32 c = 0; c < 4; c++) {
|
||||||
|
@ -511,17 +489,17 @@ void Image::ExpandTo8888() {
|
||||||
uint32 shift = fractionDepth[c] - (fullDepth[c] - currentDepth[c]);
|
uint32 shift = fractionDepth[c] - (fullDepth[c] - currentDepth[c]);
|
||||||
uint32 fractionBits = m_FractionalPixels[pidx].Component(c) >> shift;
|
uint32 fractionBits = m_FractionalPixels[pidx].Component(c) >> shift;
|
||||||
|
|
||||||
uint32 component = m_Pixels[pidx].Component(c);
|
uint32 component = p.Component(c);
|
||||||
component += ((fractionBits * numerator) / denominator);
|
component += ((fractionBits * numerator) / denominator);
|
||||||
|
|
||||||
m_Pixels[pidx].Component(c) = component;
|
p.Component(c) = component;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Pixel &Image::GetPixel(int32 i, int32 j, EWrapMode wrapMode) const {
|
const FasTC::Pixel &Image::GetPixel(int32 i, int32 j, EWrapMode wrapMode) const {
|
||||||
return m_Pixels[GetPixelIndex(i, j, wrapMode)];
|
return GetPixels()[GetPixelIndex(i, j, wrapMode)];
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32 Image::GetPixelIndex(int32 i, int32 j, EWrapMode wrapMode) const {
|
const uint32 Image::GetPixelIndex(int32 i, int32 j, EWrapMode wrapMode) const {
|
||||||
|
@ -563,33 +541,20 @@ const uint32 Image::GetPixelIndex(int32 i, int32 j, EWrapMode wrapMode) const {
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pixel & Image::operator()(uint32 i, uint32 j) {
|
|
||||||
assert(i < GetWidth());
|
|
||||||
assert(j < GetHeight());
|
|
||||||
return m_Pixels[j * GetWidth() + i];
|
|
||||||
}
|
|
||||||
|
|
||||||
const Pixel & Image::operator()(uint32 i, uint32 j) const {
|
|
||||||
assert(i < GetWidth());
|
|
||||||
assert(j < GetHeight());
|
|
||||||
return m_Pixels[j * GetWidth() + i];
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::DebugOutput(const char *filename) const {
|
void Image::DebugOutput(const char *filename) const {
|
||||||
uint32 *outPixels = new uint32[GetWidth() * GetHeight()];
|
uint32 *outPixels = new uint32[GetWidth() * GetHeight()];
|
||||||
const uint8 fullDepth[4] = { 8, 8, 8, 8 };
|
const uint8 fullDepth[4] = { 8, 8, 8, 8 };
|
||||||
for(uint32 j = 0; j < GetHeight(); j++) {
|
for(uint32 j = 0; j < GetHeight(); j++) {
|
||||||
for(uint32 i = 0; i < GetWidth(); i++) {
|
for(uint32 i = 0; i < GetWidth(); i++) {
|
||||||
uint32 idx = j * GetWidth() + i;
|
FasTC::Pixel p = (*this)(i, j);
|
||||||
Pixel p = m_Pixels[idx];
|
|
||||||
p.ChangeBitDepth(fullDepth);
|
p.ChangeBitDepth(fullDepth);
|
||||||
p.A() = 255;
|
p.A() = 255;
|
||||||
|
|
||||||
outPixels[idx] = p.PackRGBA();
|
outPixels[j*GetWidth() + i] = p.Pack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
::Image img(GetWidth(), GetHeight(), outPixels);
|
FasTC::Image<> img(GetWidth(), GetHeight(), outPixels);
|
||||||
|
|
||||||
char debugFilename[256];
|
char debugFilename[256];
|
||||||
snprintf(debugFilename, sizeof(debugFilename), "%s.png", filename);
|
snprintf(debugFilename, sizeof(debugFilename), "%s.png", filename);
|
|
@ -55,21 +55,24 @@
|
||||||
|
|
||||||
#include "TexCompTypes.h"
|
#include "TexCompTypes.h"
|
||||||
#include "PVRTCCompressor.h"
|
#include "PVRTCCompressor.h"
|
||||||
|
#include "Image.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
// Forward include
|
||||||
|
namespace FasTC {
|
||||||
|
class Pixel;
|
||||||
|
}
|
||||||
|
|
||||||
namespace PVRTCC {
|
namespace PVRTCC {
|
||||||
|
|
||||||
class Pixel;
|
class Image : public FasTC::Image<FasTC::Pixel> {
|
||||||
|
|
||||||
class Image {
|
|
||||||
public:
|
public:
|
||||||
Image(uint32 height, uint32 width);
|
Image(uint32 width, uint32 height);
|
||||||
Image(uint32 height, uint32 width, const Pixel *pixels);
|
Image(uint32 width, uint32 height, const FasTC::Pixel *pixels);
|
||||||
Image(const Image &);
|
Image(const Image &);
|
||||||
Image &operator=(const Image &);
|
Image &operator=(const Image &);
|
||||||
~Image();
|
virtual ~Image();
|
||||||
|
|
||||||
void BilinearUpscale(uint32 xtimes, uint32 ytimes,
|
void BilinearUpscale(uint32 xtimes, uint32 ytimes,
|
||||||
EWrapMode wrapMode = eWrapMode_Wrap);
|
EWrapMode wrapMode = eWrapMode_Wrap);
|
||||||
|
|
||||||
|
@ -90,24 +93,15 @@ class Image {
|
||||||
EWrapMode wrapMode = eWrapMode_Wrap);
|
EWrapMode wrapMode = eWrapMode_Wrap);
|
||||||
|
|
||||||
void ChangeBitDepth(const uint8 (&depths)[4]);
|
void ChangeBitDepth(const uint8 (&depths)[4]);
|
||||||
|
|
||||||
void ExpandTo8888();
|
void ExpandTo8888();
|
||||||
|
|
||||||
Pixel &operator()(uint32 i, uint32 j);
|
|
||||||
const Pixel &operator()(uint32 i, uint32 j) const;
|
|
||||||
|
|
||||||
uint32 GetWidth() const { return m_Width; }
|
|
||||||
uint32 GetHeight() const { return m_Height; }
|
|
||||||
|
|
||||||
void DebugOutput(const char *filename) const;
|
void DebugOutput(const char *filename) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32 m_Width;
|
FasTC::Pixel *m_FractionalPixels;
|
||||||
uint32 m_Height;
|
|
||||||
Pixel *m_Pixels;
|
|
||||||
Pixel *m_FractionalPixels;
|
|
||||||
|
|
||||||
const uint32 GetPixelIndex(int32 i, int32 j, EWrapMode wrapMode = eWrapMode_Clamp) const;
|
const uint32 GetPixelIndex(int32 i, int32 j, EWrapMode wrapMode = eWrapMode_Clamp) const;
|
||||||
const Pixel &GetPixel(int32 i, int32 j, EWrapMode wrapMode = eWrapMode_Clamp) const;
|
const FasTC::Pixel &GetPixel(int32 i, int32 j, EWrapMode wrapMode = eWrapMode_Clamp) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace PVRTCC
|
} // namespace PVRTCC
|
|
@ -57,11 +57,11 @@ INCLUDE_DIRECTORIES(${FasTC_SOURCE_DIR}/Base/include)
|
||||||
INCLUDE_DIRECTORIES(${FasTC_SOURCE_DIR}/GTest/include)
|
INCLUDE_DIRECTORIES(${FasTC_SOURCE_DIR}/GTest/include)
|
||||||
|
|
||||||
SET(TESTS
|
SET(TESTS
|
||||||
Block Pixel Image Decompressor
|
Block Image Decompressor
|
||||||
)
|
)
|
||||||
|
|
||||||
FOREACH(TEST ${TESTS})
|
FOREACH(TEST ${TESTS})
|
||||||
SET(TEST_NAME Test${TEST})
|
SET(TEST_NAME Test_PVRTCEncoder_${TEST})
|
||||||
SET(TEST_MODULE ${TEST}Test.cpp)
|
SET(TEST_MODULE ${TEST}Test.cpp)
|
||||||
ADD_EXECUTABLE(${TEST_NAME} ${TEST_MODULE})
|
ADD_EXECUTABLE(${TEST_NAME} ${TEST_MODULE})
|
||||||
TARGET_LINK_LIBRARIES(${TEST_NAME} PVRTCEncoder)
|
TARGET_LINK_LIBRARIES(${TEST_NAME} PVRTCEncoder)
|
||||||
|
@ -72,7 +72,7 @@ ENDFOREACH()
|
||||||
# Test the decompressor against the included PVR Texture library....
|
# Test the decompressor against the included PVR Texture library....
|
||||||
IF(PVRTEXLIB_FOUND)
|
IF(PVRTEXLIB_FOUND)
|
||||||
|
|
||||||
SET(TEST_NAME TestDecompVersusPVRLib)
|
SET(TEST_NAME Test_PVRTCEncoder_DecompVersusPVRLib)
|
||||||
|
|
||||||
# Copy the .pvr files that we will use for testing...
|
# Copy the .pvr files that we will use for testing...
|
||||||
SET(TEST_IMAGES
|
SET(TEST_IMAGES
|
||||||
|
|
|
@ -51,78 +51,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "Image.h"
|
#include "PVRTCImage.h"
|
||||||
#include "Pixel.h"
|
#include "Pixel.h"
|
||||||
#include "TestUtils.h"
|
#include "TestUtils.h"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
TEST(Image, NonSpecificConstructor) {
|
|
||||||
PVRTCC::Pixel p;
|
|
||||||
|
|
||||||
PVRTCC::Image img (4, 4);
|
|
||||||
for(uint32 i = 0; i < 4; i++) {
|
|
||||||
for(uint32 j = 0; j < 4; j++) {
|
|
||||||
EXPECT_TRUE(img(i, j) == p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Image, SpecificConstructor) {
|
|
||||||
PVRTCC::Pixel pxs[16];
|
|
||||||
for(uint32 i = 0; i < 4; i++) {
|
|
||||||
for(uint32 j = 0; j < 4; j++) {
|
|
||||||
pxs[j*4 + i].R() = i;
|
|
||||||
pxs[j*4 + i].G() = j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PVRTCC::Image img(4, 4, pxs);
|
|
||||||
for(uint32 i = 0; i < 4; i++) {
|
|
||||||
for(uint32 j = 0; j < 4; j++) {
|
|
||||||
EXPECT_TRUE(img(i, j) == pxs[j*4 + i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Image, CopyConstructor) {
|
|
||||||
PVRTCC::Pixel pxs[16];
|
|
||||||
for(uint32 i = 0; i < 4; i++) {
|
|
||||||
for(uint32 j = 0; j < 4; j++) {
|
|
||||||
pxs[j*4 + i].R() = i;
|
|
||||||
pxs[j*4 + i].G() = j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PVRTCC::Image img(4, 4, pxs);
|
|
||||||
PVRTCC::Image img2(img);
|
|
||||||
for(uint32 i = 0; i < 4; i++) {
|
|
||||||
for(uint32 j = 0; j < 4; j++) {
|
|
||||||
EXPECT_TRUE(img2(i, j) == pxs[j*4 + i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Image, AssignmentOperator) {
|
|
||||||
PVRTCC::Pixel pxs[16];
|
|
||||||
for(uint32 i = 0; i < 4; i++) {
|
|
||||||
for(uint32 j = 0; j < 4; j++) {
|
|
||||||
pxs[j*4 + i].R() = i;
|
|
||||||
pxs[j*4 + i].G() = j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PVRTCC::Image img(4, 4, pxs);
|
|
||||||
PVRTCC::Image img2 = img;
|
|
||||||
for(uint32 i = 0; i < 4; i++) {
|
|
||||||
for(uint32 j = 0; j < 4; j++) {
|
|
||||||
EXPECT_TRUE(img2(i, j) == pxs[j*4 + i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Image, BilinearUpscale) {
|
TEST(Image, BilinearUpscale) {
|
||||||
PVRTCC::Pixel pxs[16];
|
FasTC::Pixel pxs[16];
|
||||||
for(uint32 i = 0; i < 4; i++) {
|
for(uint32 i = 0; i < 4; i++) {
|
||||||
for(uint32 j = 0; j < 4; j++) {
|
for(uint32 j = 0; j < 4; j++) {
|
||||||
pxs[j*4 + i].R() = i*2;
|
pxs[j*4 + i].R() = i*2;
|
||||||
|
@ -152,7 +88,6 @@ TEST(Image, BilinearUpscale) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(Image, BilinearUpscaleMaintainsPixels) {
|
TEST(Image, BilinearUpscaleMaintainsPixels) {
|
||||||
|
|
||||||
srand(0xabd1ca7e);
|
srand(0xabd1ca7e);
|
||||||
|
@ -160,7 +95,7 @@ TEST(Image, BilinearUpscaleMaintainsPixels) {
|
||||||
const uint32 w = 4;
|
const uint32 w = 4;
|
||||||
const uint32 h = 4;
|
const uint32 h = 4;
|
||||||
|
|
||||||
PVRTCC::Pixel pxs[16];
|
FasTC::Pixel pxs[16];
|
||||||
for(uint32 i = 0; i < w; i++) {
|
for(uint32 i = 0; i < w; i++) {
|
||||||
for(uint32 j = 0; j < h; j++) {
|
for(uint32 j = 0; j < h; j++) {
|
||||||
pxs[j*w + i].R() = rand() % 256;
|
pxs[j*w + i].R() = rand() % 256;
|
||||||
|
@ -177,9 +112,9 @@ TEST(Image, BilinearUpscaleMaintainsPixels) {
|
||||||
|
|
||||||
for(uint32 i = 2; i < img.GetWidth(); i+=4) {
|
for(uint32 i = 2; i < img.GetWidth(); i+=4) {
|
||||||
for(uint32 j = 2; j < img.GetHeight(); j+=4) {
|
for(uint32 j = 2; j < img.GetHeight(); j+=4) {
|
||||||
PVRTCC::Pixel p = img(i, j);
|
FasTC::Pixel p = img(i, j);
|
||||||
uint32 idx = ((j - 2) / 4) * w + ((i-2)/4);
|
uint32 idx = ((j - 2) / 4) * w + ((i-2)/4);
|
||||||
EXPECT_EQ(PixelPrinter(p.PackRGBA()), PixelPrinter(pxs[idx].PackRGBA()));
|
EXPECT_EQ(PixelPrinter(p.Pack()), PixelPrinter(pxs[idx].Pack()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,7 +125,7 @@ TEST(Image, NonuniformBilinearUpscale) {
|
||||||
const uint32 kWidth = 4;
|
const uint32 kWidth = 4;
|
||||||
const uint32 kHeight = 8;
|
const uint32 kHeight = 8;
|
||||||
|
|
||||||
PVRTCC::Pixel pxs[kWidth * kHeight];
|
FasTC::Pixel pxs[kWidth * kHeight];
|
||||||
for(uint32 i = 0; i < kWidth; i++) {
|
for(uint32 i = 0; i < kWidth; i++) {
|
||||||
for(uint32 j = 0; j < kHeight; j++) {
|
for(uint32 j = 0; j < kHeight; j++) {
|
||||||
pxs[j*kWidth + i].R() = i*4;
|
pxs[j*kWidth + i].R() = i*4;
|
||||||
|
@ -198,7 +133,7 @@ TEST(Image, NonuniformBilinearUpscale) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PVRTCC::Image img(kHeight, kWidth, pxs);
|
PVRTCC::Image img(kWidth, kHeight, pxs);
|
||||||
img.BilinearUpscale(2, 1, PVRTCC::eWrapMode_Clamp);
|
img.BilinearUpscale(2, 1, PVRTCC::eWrapMode_Clamp);
|
||||||
EXPECT_EQ(img.GetWidth(), static_cast<uint32>(kWidth << 2));
|
EXPECT_EQ(img.GetWidth(), static_cast<uint32>(kWidth << 2));
|
||||||
EXPECT_EQ(img.GetHeight(), static_cast<uint32>(kHeight << 1));
|
EXPECT_EQ(img.GetHeight(), static_cast<uint32>(kHeight << 1));
|
||||||
|
@ -223,7 +158,7 @@ TEST(Image, NonuniformBilinearUpscale) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Image, BilinearUpscaleWrapped) {
|
TEST(Image, BilinearUpscaleWrapped) {
|
||||||
PVRTCC::Pixel pxs[16];
|
FasTC::Pixel pxs[16];
|
||||||
|
|
||||||
// Make sure that our bit depth is less than full...
|
// Make sure that our bit depth is less than full...
|
||||||
for(uint32 i = 0; i < 16; i++) {
|
for(uint32 i = 0; i < 16; i++) {
|
||||||
|
@ -245,7 +180,7 @@ TEST(Image, BilinearUpscaleWrapped) {
|
||||||
|
|
||||||
for(uint32 i = 0; i < img.GetWidth(); i++) {
|
for(uint32 i = 0; i < img.GetWidth(); i++) {
|
||||||
for(uint32 j = 0; j < img.GetHeight(); j++) {
|
for(uint32 j = 0; j < img.GetHeight(); j++) {
|
||||||
const PVRTCC::Pixel &p = img(i, j);
|
const FasTC::Pixel &p = img(i, j);
|
||||||
|
|
||||||
// First make sure that the bit depth didn't change
|
// First make sure that the bit depth didn't change
|
||||||
uint8 depth[4];
|
uint8 depth[4];
|
||||||
|
@ -284,9 +219,9 @@ TEST(Image, AverageDownscale) {
|
||||||
for(uint32 j = 0; j < img.GetHeight(); j++) {
|
for(uint32 j = 0; j < img.GetHeight(); j++) {
|
||||||
for(uint32 i = 0; i < img.GetWidth(); i++) {
|
for(uint32 i = 0; i < img.GetWidth(); i++) {
|
||||||
if((i ^ j) & 1) {
|
if((i ^ j) & 1) {
|
||||||
img(i, j) = PVRTCC::Pixel(0xFF000000);
|
img(i, j) = FasTC::Pixel(0xFF000000);
|
||||||
} else {
|
} else {
|
||||||
img(i, j) = PVRTCC::Pixel(0xFFFFFFFF);
|
img(i, j) = FasTC::Pixel(0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -297,7 +232,7 @@ TEST(Image, AverageDownscale) {
|
||||||
|
|
||||||
for(uint32 j = 0; j < img.GetHeight(); j++) {
|
for(uint32 j = 0; j < img.GetHeight(); j++) {
|
||||||
for(uint32 i = 0; i < img.GetWidth(); i++) {
|
for(uint32 i = 0; i < img.GetWidth(); i++) {
|
||||||
EXPECT_EQ(PixelPrinter(0xFF7F7F7F), PixelPrinter(img(i, j).PackRGBA()));
|
EXPECT_EQ(PixelPrinter(0xFF7F7F7F), PixelPrinter(img(i, j).Pack()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -307,9 +242,9 @@ TEST(Image, ContentAwareDownscale) {
|
||||||
for(uint32 j = 0; j < img.GetHeight(); j++) {
|
for(uint32 j = 0; j < img.GetHeight(); j++) {
|
||||||
for(uint32 i = 0; i < img.GetWidth(); i++) {
|
for(uint32 i = 0; i < img.GetWidth(); i++) {
|
||||||
if(j < 4) {
|
if(j < 4) {
|
||||||
img(i, j) = PVRTCC::Pixel( 0xFF000000 );
|
img(i, j) = FasTC::Pixel( 0xFF000000 );
|
||||||
} else {
|
} else {
|
||||||
img(i, j) = PVRTCC::Pixel( 0xFF0000FF );
|
img(i, j) = FasTC::Pixel( 0xFF0000FF );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue