Clean image types

This commit is contained in:
James Grogan 2022-11-11 16:32:55 +00:00
parent e7683cd94e
commit c6d03f16d0
18 changed files with 169 additions and 107 deletions

View file

@ -1,91 +1,112 @@
#include "Image.h"
Image::Image(unsigned width, unsigned height)
#include "Color.h"
template<typename T>
Image<T>::Image(unsigned width, unsigned height)
: mWidth(width),
mHeight(height)
{
}
Image::~Image()
template<typename T>
Image<T>::~Image()
{
}
void Image::Initialize()
template<typename T>
void Image<T>::initialize()
{
mData = std::vector<unsigned char>(GetBytesPerRow()*mHeight, 0);
mData = std::vector<T>(getBytesPerRow()*mHeight, 0);
}
void Image::SetPixelValue(unsigned idx, unsigned jdx, const Color& color)
template<typename T>
void Image<T>::setPixelValue(unsigned idx, unsigned jdx, const Color& color)
{
if (mData.empty())
{
Initialize();
initialize();
}
mData[jdx*GetBytesPerRow() + idx*3] = static_cast<unsigned char>(color.GetR());
mData[jdx*GetBytesPerRow() + idx*3 + 1] = static_cast<unsigned char>(color.GetG());
mData[jdx*GetBytesPerRow() + idx*3 + 2] = static_cast<unsigned char>(color.GetB());
mData[jdx*getBytesPerRow() + idx*3] = static_cast<T>(color.GetR());
mData[jdx*getBytesPerRow() + idx*3 + 1] = static_cast<T>(color.GetG());
mData[jdx*getBytesPerRow() + idx*3 + 2] = static_cast<T>(color.GetB());
}
std::unique_ptr<Image> Image::Create(unsigned width, unsigned height)
template<typename T>
std::unique_ptr<Image<T> > Image<T>::Create(unsigned width, unsigned height)
{
return std::make_unique<Image>(width, height);
return std::make_unique<Image<T> >(width, height);
}
unsigned Image::GetBytesPerRow() const
template<typename T>
unsigned Image<T>::getBytesPerRow() const
{
const auto bitsPerEntry = mBitDepth <= 8 ? 1 : 2;
return mWidth * mNumChannels *bitsPerEntry;
}
unsigned Image::GetWidth() const
template<typename T>
unsigned Image<T>::getWidth() const
{
return mWidth;
}
unsigned Image::GetHeight() const
template<typename T>
unsigned Image<T>::getHeight() const
{
return mHeight;
}
unsigned Image::GetBitDepth() const
template<typename T>
unsigned Image<T>::getBitDepth() const
{
return mBitDepth;
}
unsigned char Image::GetByte(unsigned idx, unsigned jdx) const
template<typename T>
T Image<T>::getByte(unsigned idx, unsigned jdx) const
{
return mData[jdx*GetBytesPerRow() + idx];
return mData[jdx*getBytesPerRow() + idx];
}
unsigned Image::GetNumChannels() const
template<typename T>
unsigned Image<T>::getNumChannels() const
{
return mNumChannels;
}
void Image::SetData(const std::vector<unsigned char>& data)
template<typename T>
void Image<T>::setData(const std::vector<T>& data)
{
mData = data;
}
void Image::SetWidth(unsigned width)
template<typename T>
void Image<T>::setWidth(unsigned width)
{
mWidth = width;
}
void Image::SetHeight(unsigned height)
template<typename T>
void Image<T>::setHeight(unsigned height)
{
mHeight = height;
}
void Image::SetBitDepth(unsigned bitDepth)
template<typename T>
void Image<T>::setBitDepth(unsigned bitDepth)
{
mBitDepth = bitDepth;
}
void Image::SetNumChannels(unsigned numChannels)
template<typename T>
void Image<T>::setNumChannels(unsigned numChannels)
{
mNumChannels = numChannels;
}
template class Image<unsigned char>;
//template class Image<uint8_t>;