Clean up Image class.
This commit is contained in:
parent
4bb87de0e6
commit
0d3674faac
30 changed files with 330 additions and 135 deletions
|
@ -2,8 +2,9 @@
|
||||||
|
|
||||||
void CyclicRedundancyChecker::createTable()
|
void CyclicRedundancyChecker::createTable()
|
||||||
{
|
{
|
||||||
|
mTable = std::vector<unsigned long>(TABLE_SIZE, 0);
|
||||||
unsigned long c{0};
|
unsigned long c{0};
|
||||||
for (int n = 0; n < 256; n++)
|
for (int n = 0; n < TABLE_SIZE; n++)
|
||||||
{
|
{
|
||||||
c = (unsigned long) n;
|
c = (unsigned long) n;
|
||||||
for (int k = 0; k < 8; k++)
|
for (int k = 0; k < 8; k++)
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include "AbstractChecksumCalculator.h"
|
#include "AbstractChecksumCalculator.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class CyclicRedundancyChecker : public AbstractChecksumCalculator
|
class CyclicRedundancyChecker : public AbstractChecksumCalculator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -16,5 +18,7 @@ private:
|
||||||
bool mTableComputed{false};
|
bool mTableComputed{false};
|
||||||
|
|
||||||
uint32_t mLastValue{0xffffffffL};
|
uint32_t mLastValue{0xffffffffL};
|
||||||
unsigned long mTable[256];
|
|
||||||
|
static const std::size_t TABLE_SIZE{ 256 };
|
||||||
|
std::vector<unsigned long> mTable;
|
||||||
};
|
};
|
||||||
|
|
|
@ -55,8 +55,7 @@ std::string GlyphRunOutlines::toPostScriptPath()
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
FontGlyph::FontGlyph(unsigned width, unsigned height, int bearingX, int bearingY,
|
FontGlyph::FontGlyph(unsigned width, unsigned height, int bearingX, int bearingY, int advanceX, std::unique_ptr<Image> image)
|
||||||
int advanceX, std::unique_ptr<Image<unsigned char> > image)
|
|
||||||
: mImage(std::move(image)),
|
: mImage(std::move(image)),
|
||||||
mWidth(width),
|
mWidth(width),
|
||||||
mHeight(height),
|
mHeight(height),
|
||||||
|
@ -67,7 +66,7 @@ FontGlyph::FontGlyph(unsigned width, unsigned height, int bearingX, int bearingY
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Image<unsigned char>* FontGlyph::getImage() const
|
Image* FontGlyph::getImage() const
|
||||||
{
|
{
|
||||||
return mImage.get();
|
return mImage.get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,12 +38,10 @@ private:
|
||||||
|
|
||||||
class FontGlyph
|
class FontGlyph
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FontGlyph(unsigned width, unsigned height, int bearingX, int bearingY,
|
FontGlyph(unsigned width, unsigned height, int bearingX, int bearingY, int advanceX, std::unique_ptr<Image> image);
|
||||||
int advanceX, std::unique_ptr<Image<unsigned char> > image);
|
|
||||||
|
|
||||||
Image<unsigned char>* getImage() const;
|
Image* getImage() const;
|
||||||
|
|
||||||
unsigned getWidth() const;
|
unsigned getWidth() const;
|
||||||
unsigned getHeight() const;
|
unsigned getHeight() const;
|
||||||
|
@ -57,5 +55,5 @@ private:
|
||||||
int mBearingX{0};
|
int mBearingX{0};
|
||||||
int mBearingY{0};
|
int mBearingY{0};
|
||||||
int mAdvanceX{0};
|
int mAdvanceX{0};
|
||||||
std::unique_ptr<Image<unsigned char> > mImage;
|
std::unique_ptr<Image> mImage;
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,12 +40,11 @@ Scene* DrawingSurface::getScene()
|
||||||
return mScene.get();
|
return mScene.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
Image<unsigned char>* DrawingSurface::getImage()
|
Image* DrawingSurface::getImage()
|
||||||
{
|
{
|
||||||
if (!mBackingImage)
|
if (!mBackingImage)
|
||||||
{
|
{
|
||||||
mBackingImage = std::make_unique<Image<unsigned char> >(mWidth, mHeight);
|
mBackingImage = std::make_unique<Image>(mWidth, mHeight);
|
||||||
mBackingImage->initialize();
|
|
||||||
}
|
}
|
||||||
return mBackingImage.get();
|
return mBackingImage.get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
class Scene;
|
class Scene;
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class Image;
|
class Image;
|
||||||
|
|
||||||
class DrawingSurface
|
class DrawingSurface
|
||||||
|
@ -21,7 +19,7 @@ public:
|
||||||
|
|
||||||
unsigned getHeight() const;
|
unsigned getHeight() const;
|
||||||
|
|
||||||
Image<unsigned char>* getImage();
|
Image* getImage();
|
||||||
|
|
||||||
Scene* getScene();
|
Scene* getScene();
|
||||||
|
|
||||||
|
@ -29,5 +27,5 @@ protected:
|
||||||
unsigned mWidth = 0;
|
unsigned mWidth = 0;
|
||||||
unsigned mHeight = 0;
|
unsigned mHeight = 0;
|
||||||
std::unique_ptr<Scene> mScene;
|
std::unique_ptr<Scene> mScene;
|
||||||
std::unique_ptr<Image<unsigned char> > mBackingImage;
|
std::unique_ptr<Image> mBackingImage;
|
||||||
};
|
};
|
||||||
|
|
|
@ -94,6 +94,9 @@ void DirectXInterface::initialize()
|
||||||
|
|
||||||
void DirectXInterface::initializeD2dStandalone()
|
void DirectXInterface::initializeD2dStandalone()
|
||||||
{
|
{
|
||||||
|
D2D1_FACTORY_OPTIONS d2dFactoryOptions = {};
|
||||||
|
D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory3), &d2dFactoryOptions, &mD2dFactory);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,29 +1,51 @@
|
||||||
|
set(MODULE_NAME image)
|
||||||
|
|
||||||
|
set(platform_LIB_INCLUDES)
|
||||||
|
|
||||||
list(APPEND image_HEADERS
|
list(APPEND image_HEADERS
|
||||||
Image.h
|
Image.h
|
||||||
|
ImageData.h
|
||||||
|
PlatformImage.h
|
||||||
|
PlatformImageWriter.h
|
||||||
png/PngWriter.h
|
png/PngWriter.h
|
||||||
|
png/PngReader.h
|
||||||
)
|
)
|
||||||
|
|
||||||
list(APPEND image_LIB_INCLUDES
|
list(APPEND image_LIB_INCLUDES
|
||||||
Image.cpp
|
Image.cpp
|
||||||
|
ImageBitStream.cpp
|
||||||
|
PlatformImage.cpp
|
||||||
png/PngWriter.cpp
|
png/PngWriter.cpp
|
||||||
png/PngReader.cpp
|
png/PngReader.cpp
|
||||||
png/PngHeader.cpp
|
png/PngHeader.cpp
|
||||||
png/PngInfo.cpp
|
png/PngInfo.cpp
|
||||||
ImageBitStream.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
list(APPEND platform_LIB_INCLUDES
|
||||||
|
win32/Win32WicImage.h
|
||||||
|
win32/Win32WicImage.cpp
|
||||||
|
win32/Win32WicImageWriter.h
|
||||||
|
win32/Win32WicImageWriter.cpp
|
||||||
|
win32/Win32WicInterface.h
|
||||||
|
win32/Win32WicInterface.cpp
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
list(APPEND image_LIBS core compression)
|
list(APPEND image_LIBS core compression)
|
||||||
list(APPEND image_DEFINES "")
|
list(APPEND image_DEFINES "")
|
||||||
|
|
||||||
|
add_library(image SHARED ${image_LIB_INCLUDES} ${platform_LIB_INCLUDES} ${image_HEADERS})
|
||||||
|
|
||||||
add_library(image SHARED ${image_LIB_INCLUDES} ${image_HEADERS})
|
target_include_directories(${MODULE_NAME} PUBLIC
|
||||||
#target_compile_definitions(image PRIVATE ${image_DEFINES})
|
|
||||||
|
|
||||||
target_include_directories(image PUBLIC
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/png)
|
${CMAKE_CURRENT_SOURCE_DIR}/png
|
||||||
set_target_properties( image PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
|
${CMAKE_CURRENT_SOURCE_DIR}/win32
|
||||||
|
)
|
||||||
|
|
||||||
target_link_libraries( image PUBLIC ${image_LIBS})
|
|
||||||
|
|
||||||
set_property(TARGET image PROPERTY FOLDER src)
|
set_target_properties( ${MODULE_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
|
||||||
|
|
||||||
|
target_link_libraries( ${MODULE_NAME} PUBLIC ${image_LIBS})
|
||||||
|
|
||||||
|
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER src)
|
||||||
|
|
|
@ -2,121 +2,111 @@
|
||||||
|
|
||||||
#include "Color.h"
|
#include "Color.h"
|
||||||
|
|
||||||
template<typename T>
|
Image::Image(unsigned width, unsigned height, ImageData::Type dataType)
|
||||||
Image<T>::Image(unsigned width, unsigned height)
|
|
||||||
: mWidth(width),
|
: mWidth(width),
|
||||||
mHeight(height)
|
mHeight(height),
|
||||||
|
mDataType(mDataType)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
Image::~Image()
|
||||||
Image<T>::~Image()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
std::unique_ptr<Image> Image::Create(unsigned width, unsigned height, ImageData::Type dataType)
|
||||||
void Image<T>::initialize()
|
|
||||||
{
|
{
|
||||||
mData = std::vector<T>(getBytesPerRow()*mHeight, 10);
|
return std::make_unique<Image>(width, height, dataType);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
void Image::initialize()
|
||||||
void Image<T>::setDataItem(std::size_t index, T item)
|
|
||||||
{
|
{
|
||||||
if(index >= mData.size())
|
if (mDataType == ImageData::Type::UCHAR || mDataType == ImageData::Type::UNKNOWN)
|
||||||
{
|
{
|
||||||
return;
|
auto data = std::unique_ptr<ImageDataT<unsigned char> >();
|
||||||
|
data->initialize(getBytesPerRow() * mHeight, 0);
|
||||||
|
mData = std::move(data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto data = std::unique_ptr<ImageDataT<uint8_t> >();
|
||||||
|
data->initialize(getBytesPerRow() * mHeight, 0);
|
||||||
|
mData = std::move(data);
|
||||||
}
|
}
|
||||||
mData[index] = item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
void Image::setPixelValue(unsigned idx, unsigned jdx, const Color& color)
|
||||||
void Image<T>::setPixelValue(unsigned idx, unsigned jdx, const Color& color)
|
|
||||||
{
|
{
|
||||||
if (mData.empty())
|
if (!mData)
|
||||||
{
|
{
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
mData[jdx*getBytesPerRow() + idx*3] = static_cast<T>(color.getR());
|
const auto offset = jdx * getBytesPerRow() + idx * 3;
|
||||||
mData[jdx*getBytesPerRow() + idx*3 + 1] = static_cast<T>(color.getG());
|
mData->setDataItem(offset, color.getR());
|
||||||
mData[jdx*getBytesPerRow() + idx*3 + 2] = static_cast<T>(color.getB());
|
mData->setDataItem(offset + 1, color.getG());
|
||||||
|
mData->setDataItem(offset + 2, color.getB());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
unsigned Image::getBytesPerRow() const
|
||||||
std::unique_ptr<Image<T> > Image<T>::Create(unsigned width, unsigned height)
|
|
||||||
{
|
|
||||||
return std::make_unique<Image<T> >(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
unsigned Image<T>::getBytesPerRow() const
|
|
||||||
{
|
{
|
||||||
const auto bitsPerEntry = mBitDepth <= 8 ? 1 : 2;
|
const auto bitsPerEntry = mBitDepth <= 8 ? 1 : 2;
|
||||||
return mWidth * mNumChannels * bitsPerEntry;
|
return mWidth * mNumChannels * bitsPerEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
unsigned Image::getWidth() const
|
||||||
unsigned Image<T>::getWidth() const
|
|
||||||
{
|
{
|
||||||
return mWidth;
|
return mWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
unsigned Image::getHeight() const
|
||||||
unsigned Image<T>::getHeight() const
|
|
||||||
{
|
{
|
||||||
return mHeight;
|
return mHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
unsigned Image::getBitDepth() const
|
||||||
unsigned Image<T>::getBitDepth() const
|
|
||||||
{
|
{
|
||||||
return mBitDepth;
|
return mBitDepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
PlatformImage* Image::getPlatformImage() const
|
||||||
T Image<T>::getByte(unsigned idx, unsigned jdx) const
|
|
||||||
{
|
{
|
||||||
return mData[jdx*getBytesPerRow() + idx];
|
return mPlatformImage.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
ImageData* Image::getData()
|
||||||
unsigned Image<T>::getNumChannels() const
|
{
|
||||||
|
return mData.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char Image::getAsUnsignedChar(unsigned idx, unsigned jdx) const
|
||||||
|
{
|
||||||
|
return mData->getAsUnsignedChar(jdx * getBytesPerRow() + idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned Image::getNumChannels() const
|
||||||
{
|
{
|
||||||
return mNumChannels;
|
return mNumChannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
void Image::setWidth(unsigned width)
|
||||||
void Image<T>::setData(const std::vector<T>& data)
|
|
||||||
{
|
|
||||||
mData = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void Image<T>::setWidth(unsigned width)
|
|
||||||
{
|
{
|
||||||
mWidth = width;
|
mWidth = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
void Image::setHeight(unsigned height)
|
||||||
void Image<T>::setHeight(unsigned height)
|
|
||||||
{
|
{
|
||||||
mHeight = height;
|
mHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
void Image::setBitDepth(unsigned bitDepth)
|
||||||
void Image<T>::setBitDepth(unsigned bitDepth)
|
|
||||||
{
|
{
|
||||||
mBitDepth = bitDepth;
|
mBitDepth = bitDepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
void Image::setNumChannels(unsigned numChannels)
|
||||||
void Image<T>::setNumChannels(unsigned numChannels)
|
|
||||||
{
|
{
|
||||||
mNumChannels = numChannels;
|
mNumChannels = numChannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
template class Image<unsigned char>;
|
|
||||||
//template class Image<uint8_t>;
|
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "PlatformImage.h"
|
||||||
|
#include "ImageData.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class Color;
|
class Color;
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class Image
|
class Image
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Image(unsigned width, unsigned height);
|
Image(unsigned width, unsigned height, ImageData::Type dataType = ImageData::Type::UCHAR);
|
||||||
~Image();
|
~Image();
|
||||||
static std::unique_ptr<Image<T> > Create(unsigned width, unsigned height);
|
static std::unique_ptr<Image> Create(unsigned width, unsigned height, ImageData::Type dataType = ImageData::Type::UCHAR);
|
||||||
|
|
||||||
unsigned getBytesPerRow() const;
|
unsigned getBytesPerRow() const;
|
||||||
unsigned getWidth() const;
|
unsigned getWidth() const;
|
||||||
|
@ -19,40 +21,25 @@ public:
|
||||||
unsigned getBitDepth() const;
|
unsigned getBitDepth() const;
|
||||||
unsigned getNumChannels() const;
|
unsigned getNumChannels() const;
|
||||||
|
|
||||||
|
ImageData* getData();
|
||||||
|
unsigned char getAsUnsignedChar(unsigned idx, unsigned jdx) const;
|
||||||
|
PlatformImage* getPlatformImage() const;
|
||||||
|
|
||||||
void setPixelValue(unsigned idx, unsigned jdx, const Color& color);
|
void setPixelValue(unsigned idx, unsigned jdx, const Color& color);
|
||||||
|
|
||||||
T getByte(unsigned idx, unsigned jdx) const;
|
|
||||||
|
|
||||||
void setData(const std::vector<T>& data);
|
|
||||||
|
|
||||||
void setDataItem(std::size_t index, T);
|
|
||||||
void setWidth(unsigned width);
|
void setWidth(unsigned width);
|
||||||
void setHeight(unsigned height);
|
void setHeight(unsigned height);
|
||||||
void setBitDepth(unsigned bitDepth);
|
void setBitDepth(unsigned bitDepth);
|
||||||
void setNumChannels(unsigned numChannels);
|
void setNumChannels(unsigned numChannels);
|
||||||
|
|
||||||
void initialize();
|
|
||||||
|
|
||||||
const T* getDataPtr() const
|
|
||||||
{
|
|
||||||
return mData.data();
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<T>& getDataRef() const
|
|
||||||
{
|
|
||||||
return mData;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<T> getData() const
|
|
||||||
{
|
|
||||||
return mData;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void initialize();
|
||||||
|
|
||||||
unsigned mWidth{1};
|
unsigned mWidth{1};
|
||||||
unsigned mHeight{1};
|
unsigned mHeight{1};
|
||||||
unsigned mBitDepth{8};
|
unsigned mBitDepth{8};
|
||||||
unsigned mNumChannels{4};
|
unsigned mNumChannels{4};
|
||||||
std::vector<T> mData;
|
|
||||||
|
ImageData::Type mDataType;
|
||||||
|
std::unique_ptr<ImageData> mData;
|
||||||
|
std::unique_ptr<PlatformImage> mPlatformImage;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "ImageBitStream.h"
|
#include "ImageBitStream.h"
|
||||||
|
|
||||||
ImageBitStream::ImageBitStream(Image<unsigned char>* image)
|
ImageBitStream::ImageBitStream(Image* image)
|
||||||
: BitStream(),
|
: BitStream(),
|
||||||
mImage(image)
|
mImage(image)
|
||||||
{
|
{
|
||||||
|
@ -9,7 +9,7 @@ ImageBitStream::ImageBitStream(Image<unsigned char>* image)
|
||||||
|
|
||||||
bool ImageBitStream::isFinished() const
|
bool ImageBitStream::isFinished() const
|
||||||
{
|
{
|
||||||
return mByteOffset == mImage->getDataRef().size();
|
return mByteOffset == mImage->getData()->getLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<unsigned char> ImageBitStream::peekNextNBytes(unsigned n) const
|
std::vector<unsigned char> ImageBitStream::peekNextNBytes(unsigned n) const
|
||||||
|
@ -25,7 +25,7 @@ std::optional<unsigned char> ImageBitStream::readNextByte()
|
||||||
{
|
{
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
const auto val = mImage->getDataRef()[mByteOffset];
|
const auto val = mImage->getData()->getAsUnsignedChar(mByteOffset);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,6 @@ void ImageBitStream::writeByte(unsigned char data, bool checkOverflow )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mImage->setDataItem(mByteOffset, data);
|
mImage->getData()->setDataItem(mByteOffset, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
class ImageBitStream : public BitStream
|
class ImageBitStream : public BitStream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ImageBitStream(Image<unsigned char>* image);
|
ImageBitStream(Image* image);
|
||||||
|
|
||||||
bool isFinished() const override;
|
bool isFinished() const override;
|
||||||
|
|
||||||
|
@ -28,5 +28,5 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Image<unsigned char>* mImage{nullptr};
|
Image* mImage{nullptr};
|
||||||
};
|
};
|
||||||
|
|
110
src/image/ImageData.h
Normal file
110
src/image/ImageData.h
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
class ImageData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum class Type
|
||||||
|
{
|
||||||
|
UCHAR,
|
||||||
|
UINT8,
|
||||||
|
UNKNOWN
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual Type getType() const = 0;
|
||||||
|
|
||||||
|
virtual void setDataItem(std::size_t index, unsigned char item) = 0;
|
||||||
|
|
||||||
|
virtual unsigned char getAsUnsignedChar(std::size_t index) const = 0;
|
||||||
|
|
||||||
|
virtual std::size_t getLength() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class ImageDataT : public ImageData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual Type getType() const override
|
||||||
|
{
|
||||||
|
if (std::is_same<T, unsigned char>::value)
|
||||||
|
{
|
||||||
|
return Type::UCHAR;
|
||||||
|
}
|
||||||
|
else if (std::is_same<T, uint8_t>::value)
|
||||||
|
{
|
||||||
|
return Type::UINT8;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Type::UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
const T* getDataPtr() const
|
||||||
|
{
|
||||||
|
return mData.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
const std::vector<T>& getData() const
|
||||||
|
{
|
||||||
|
return mData;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void setData(const std::vector<T>& data)
|
||||||
|
{
|
||||||
|
mData = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDataItem(std::size_t index, unsigned char item) override
|
||||||
|
{
|
||||||
|
if (index < mData.size())
|
||||||
|
{
|
||||||
|
mData[index] = static_cast<T>(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void setDataItem(std::size_t index, T item)
|
||||||
|
{
|
||||||
|
if (index < mData.size())
|
||||||
|
{
|
||||||
|
mData[index] = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void initialize(std::size_t size, T value)
|
||||||
|
{
|
||||||
|
mData.resize(size);
|
||||||
|
for (std::size_t idx = 0; idx < size; idx++)
|
||||||
|
{
|
||||||
|
mData[idx] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char getAsUnsignedChar(std::size_t index) const override
|
||||||
|
{
|
||||||
|
if (index < mData.size())
|
||||||
|
{
|
||||||
|
return static_cast<unsigned char>(mData[index]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t getLength() const override
|
||||||
|
{
|
||||||
|
return mData.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<T> mData;
|
||||||
|
};
|
||||||
|
|
13
src/image/PlatformImage.cpp
Normal file
13
src/image/PlatformImage.cpp
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class Image;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class PlatformImage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PlatformImage(Image<T>* image);
|
||||||
|
private:
|
||||||
|
Image<T>* mImage{ nullptr };
|
||||||
|
};
|
15
src/image/PlatformImage.h
Normal file
15
src/image/PlatformImage.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
class Image;
|
||||||
|
|
||||||
|
class PlatformImage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PlatformImage(Image* image)
|
||||||
|
: mImage(image)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
Image* mImage{ nullptr };
|
||||||
|
};
|
6
src/image/PlatformImageWriter.h
Normal file
6
src/image/PlatformImageWriter.h
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
class PlatformImageWriter
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
|
@ -162,9 +162,9 @@ bool PngReader::readIDATChunk(unsigned length)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Image<unsigned char> > PngReader::read()
|
std::unique_ptr<Image> PngReader::read()
|
||||||
{
|
{
|
||||||
auto image = std::make_unique<Image<unsigned char> >(5, 5);
|
auto image = std::make_unique<Image>(5, 5);
|
||||||
|
|
||||||
mFile = std::make_unique<File>(mPath);
|
mFile = std::make_unique<File>(mPath);
|
||||||
mFile->open(File::AccessMode::Read);
|
mFile->open(File::AccessMode::Read);
|
||||||
|
@ -188,7 +188,6 @@ std::unique_ptr<Image<unsigned char> > PngReader::read()
|
||||||
image->setHeight(mHeader.getHeight());
|
image->setHeight(mHeader.getHeight());
|
||||||
image->setBitDepth(mHeader.getBitDepth());
|
image->setBitDepth(mHeader.getBitDepth());
|
||||||
image->setNumChannels(mHeader.getPngInfo().getNumChannels());
|
image->setNumChannels(mHeader.getPngInfo().getNumChannels());
|
||||||
image->initialize();
|
|
||||||
|
|
||||||
auto image_bit_stream = std::make_unique<ImageBitStream>(image.get());
|
auto image_bit_stream = std::make_unique<ImageBitStream>(image.get());
|
||||||
PngFilter filter(mOutputStream.get(), image_bit_stream.get());
|
PngFilter filter(mOutputStream.get(), image_bit_stream.get());
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
~PngReader();
|
~PngReader();
|
||||||
void setPath(const Path& path);
|
void setPath(const Path& path);
|
||||||
|
|
||||||
std::unique_ptr<Image<unsigned char> > read();
|
std::unique_ptr<Image> read();
|
||||||
private:
|
private:
|
||||||
bool readChunk();
|
bool readChunk();
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ private:
|
||||||
|
|
||||||
PngHeader mHeader;
|
PngHeader mHeader;
|
||||||
|
|
||||||
std::unique_ptr<Image<unsigned char> > mWorkingImage;
|
std::unique_ptr<Image> mWorkingImage;
|
||||||
std::unique_ptr<File> mFile;
|
std::unique_ptr<File> mFile;
|
||||||
Path mPath;
|
Path mPath;
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,7 @@ void PngWriter::writeDataChunks(const BufferBitStream& buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PngWriter::write(Image<unsigned char>* image)
|
void PngWriter::write(Image* image)
|
||||||
{
|
{
|
||||||
if (!mPath.empty())
|
if (!mPath.empty())
|
||||||
{
|
{
|
||||||
|
@ -222,7 +222,7 @@ void PngWriter::write(Image<unsigned char>* image)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PngWriter::write(const std::unique_ptr<Image<unsigned char> >& image)
|
void PngWriter::write(const std::unique_ptr<Image>& image)
|
||||||
{
|
{
|
||||||
write(image.get());
|
write(image.get());
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "PngHeader.h"
|
#include "PngHeader.h"
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
#include "DeflateElements.h"
|
#include "DeflateElements.h"
|
||||||
|
#include "PlatformImageWriter.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -28,8 +29,8 @@ public:
|
||||||
|
|
||||||
void setPngInfo(const PngInfo& info);
|
void setPngInfo(const PngInfo& info);
|
||||||
|
|
||||||
void write(const std::unique_ptr<Image<unsigned char> >& image);
|
void write(const std::unique_ptr<Image>& image);
|
||||||
void write(Image<unsigned char>* image);
|
void write(Image* image);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void writeSignature();
|
void writeSignature();
|
||||||
|
@ -42,7 +43,7 @@ private:
|
||||||
//void writeIDatChunk();
|
//void writeIDatChunk();
|
||||||
|
|
||||||
Path mPath;
|
Path mPath;
|
||||||
Image<unsigned char>* mWorkingImage{nullptr};
|
Image* mWorkingImage{nullptr};
|
||||||
std::unique_ptr<BitStream> mInStream;
|
std::unique_ptr<BitStream> mInStream;
|
||||||
std::unique_ptr<BitStream> mOutStream;
|
std::unique_ptr<BitStream> mOutStream;
|
||||||
std::unique_ptr<File> mWorkingFile;
|
std::unique_ptr<File> mWorkingFile;
|
||||||
|
@ -52,6 +53,8 @@ private:
|
||||||
PngHeader mPngHeader;
|
PngHeader mPngHeader;
|
||||||
|
|
||||||
Deflate::CompressionMethod mCompressionMethod{Deflate::CompressionMethod::DYNAMIC_HUFFMAN};
|
Deflate::CompressionMethod mCompressionMethod{Deflate::CompressionMethod::DYNAMIC_HUFFMAN};
|
||||||
|
|
||||||
|
std::unique_ptr<PlatformImageWriter> mPlatformWriter;
|
||||||
};
|
};
|
||||||
|
|
||||||
using PngWriterPtr = std::unique_ptr<PngWriter>;
|
using PngWriterPtr = std::unique_ptr<PngWriter>;
|
||||||
|
|
1
src/image/win32/Win32WicImage.cpp
Normal file
1
src/image/win32/Win32WicImage.cpp
Normal file
|
@ -0,0 +1 @@
|
||||||
|
#include "Win32WicImage.h"
|
8
src/image/win32/Win32WicImage.h
Normal file
8
src/image/win32/Win32WicImage.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "PlatformImage.h"
|
||||||
|
|
||||||
|
class Win32WicImage : public PlatformImage
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
2
src/image/win32/Win32WicImageWriter.cpp
Normal file
2
src/image/win32/Win32WicImageWriter.cpp
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#include "Win32WicImageWriter.h"
|
||||||
|
|
8
src/image/win32/Win32WicImageWriter.h
Normal file
8
src/image/win32/Win32WicImageWriter.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "PlatformImageWriter.h"
|
||||||
|
|
||||||
|
class Win32WicImageWriter
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
13
src/image/win32/Win32WicInterface.cpp
Normal file
13
src/image/win32/Win32WicInterface.cpp
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#include "Win32WicInterface.h"
|
||||||
|
|
||||||
|
#include <wincodec.h>
|
||||||
|
|
||||||
|
Win32WicInterface::Win32WicInterface()
|
||||||
|
{
|
||||||
|
mIsValid = SUCCEEDED(::CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&mImagingFactory)));
|
||||||
|
}
|
||||||
|
|
||||||
|
IWICImagingFactory* Win32WicInterface::getFactory() const
|
||||||
|
{
|
||||||
|
return mImagingFactory.Get();
|
||||||
|
}
|
16
src/image/win32/Win32WicInterface.h
Normal file
16
src/image/win32/Win32WicInterface.h
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <wrl.h>
|
||||||
|
|
||||||
|
struct IWICImagingFactory;
|
||||||
|
|
||||||
|
class Win32WicInterface
|
||||||
|
{
|
||||||
|
Win32WicInterface();
|
||||||
|
|
||||||
|
IWICImagingFactory* getFactory() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool mIsValid{ false };
|
||||||
|
Microsoft::WRL::ComPtr<IWICImagingFactory> mImagingFactory;
|
||||||
|
};
|
|
@ -22,7 +22,7 @@ void AbstractVisualNode::update(SceneInfo* sceneInfo)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Image<unsigned char>* AbstractVisualNode::getImage() const
|
Image* AbstractVisualNode::getImage() const
|
||||||
{
|
{
|
||||||
return mImage.get();
|
return mImage.get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public:
|
||||||
|
|
||||||
const std::string& getName() const;
|
const std::string& getName() const;
|
||||||
|
|
||||||
Image<unsigned char>* getImage() const;
|
Image* getImage() const;
|
||||||
|
|
||||||
bool getIsVisible() const;
|
bool getIsVisible() const;
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
Point mLocation;
|
Point mLocation;
|
||||||
std::vector<std::unique_ptr<SceneItem> > mSceneItems;
|
std::vector<std::unique_ptr<SceneItem> > mSceneItems;
|
||||||
std::unique_ptr<Image<unsigned char> > mImage;
|
std::unique_ptr<Image> mImage;
|
||||||
|
|
||||||
std::vector<AbstractVisualNode*> mChildren;
|
std::vector<AbstractVisualNode*> mChildren;
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,6 @@ TEST_CASE(TestDirectXRendering, "graphics")
|
||||||
auto text_node = std::make_unique<TextNode>("Test", DiscretePoint(100, 100));
|
auto text_node = std::make_unique<TextNode>("Test", DiscretePoint(100, 100));
|
||||||
scene->addNode(text_node.get());
|
scene->addNode(text_node.get());
|
||||||
|
|
||||||
scene->update(nullptr);
|
scene->update();
|
||||||
gui_app->run();
|
gui_app->run();
|
||||||
};
|
};
|
|
@ -15,7 +15,7 @@ TEST_CASE(TestCompressedPng, "image")
|
||||||
unsigned width = 20;
|
unsigned width = 20;
|
||||||
unsigned height = 20;
|
unsigned height = 20;
|
||||||
unsigned numChannels = 1;
|
unsigned numChannels = 1;
|
||||||
auto image = Image<unsigned char>::Create(width, height);
|
auto image = Image::Create(width, height);
|
||||||
image->setNumChannels(numChannels);
|
image->setNumChannels(numChannels);
|
||||||
image->setBitDepth(8);
|
image->setBitDepth(8);
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ TEST_CASE(TestCompressedPng, "image")
|
||||||
data[idx] = val;
|
data[idx] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
image->setData(data);
|
dynamic_cast<ImageDataT<unsigned char>*>(image->getData())->setData(data);
|
||||||
|
|
||||||
PngWriter writer;
|
PngWriter writer;
|
||||||
writer.setPath(TestUtils::getTestOutputDir() / "test_compressed.png");
|
writer.setPath(TestUtils::getTestOutputDir() / "test_compressed.png");
|
||||||
|
@ -48,7 +48,7 @@ TEST_CASE(TestFixedPng, "image")
|
||||||
unsigned width = 10;
|
unsigned width = 10;
|
||||||
unsigned height = 10;
|
unsigned height = 10;
|
||||||
unsigned numChannels = 1;
|
unsigned numChannels = 1;
|
||||||
auto image = Image<unsigned char>::Create(width, height);
|
auto image = Image::Create(width, height);
|
||||||
image->setNumChannels(numChannels);
|
image->setNumChannels(numChannels);
|
||||||
image->setBitDepth(8);
|
image->setBitDepth(8);
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ TEST_CASE(TestFixedPng, "image")
|
||||||
data[idx] = val;
|
data[idx] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
image->setData(data);
|
dynamic_cast<ImageDataT<unsigned char>*>(image->getData())->setData(data);
|
||||||
|
|
||||||
PngWriter writer;
|
PngWriter writer;
|
||||||
writer.setPath(TestUtils::getTestOutputDir() / "test_fixed.png");
|
writer.setPath(TestUtils::getTestOutputDir() / "test_fixed.png");
|
||||||
|
@ -78,7 +78,7 @@ TEST_CASE(TestDynamicCompressedPng, "image")
|
||||||
unsigned width = 10;
|
unsigned width = 10;
|
||||||
unsigned height = 10;
|
unsigned height = 10;
|
||||||
unsigned numChannels = 1;
|
unsigned numChannels = 1;
|
||||||
auto image = Image<unsigned char>::Create(width, height);
|
auto image = Image::Create(width, height);
|
||||||
image->setNumChannels(numChannels);
|
image->setNumChannels(numChannels);
|
||||||
image->setBitDepth(8);
|
image->setBitDepth(8);
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ TEST_CASE(TestDynamicCompressedPng, "image")
|
||||||
data[idx] = val;
|
data[idx] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
image->setData(data);
|
dynamic_cast<ImageDataT<unsigned char>*>(image->getData())->setData(data);
|
||||||
|
|
||||||
PngWriter writer;
|
PngWriter writer;
|
||||||
writer.setPath(TestUtils::getTestOutputDir() / "test_dynamic.png");
|
writer.setPath(TestUtils::getTestOutputDir() / "test_dynamic.png");
|
||||||
|
|
Loading…
Reference in a new issue