From 0d3674faaca29bac658e4b0953cf6be2d7e5c473 Mon Sep 17 00:00:00 2001 From: jmsgrogan Date: Wed, 11 Jan 2023 14:31:29 +0000 Subject: [PATCH] Clean up Image class. --- src/compression/CyclicRedundancyChecker.cpp | 3 +- src/compression/CyclicRedundancyChecker.h | 6 +- src/fonts/FontGlyph.cpp | 5 +- src/fonts/FontGlyph.h | 8 +- src/graphics/DrawingSurface.cpp | 5 +- src/graphics/DrawingSurface.h | 6 +- src/graphics/directx/DirectXInterface.cpp | 3 + src/image/CMakeLists.txt | 40 +++++-- src/image/Image.cpp | 102 ++++++++-------- src/image/Image.h | 41 +++---- src/image/ImageBitStream.cpp | 8 +- src/image/ImageBitStream.h | 4 +- src/image/ImageData.h | 110 ++++++++++++++++++ src/image/PlatformImage.cpp | 13 +++ src/image/PlatformImage.h | 15 +++ src/image/PlatformImageWriter.h | 6 + src/image/png/PngReader.cpp | 5 +- src/image/png/PngReader.h | 4 +- src/image/png/PngWriter.cpp | 4 +- src/image/png/PngWriter.h | 9 +- src/image/win32/Win32WicImage.cpp | 1 + src/image/win32/Win32WicImage.h | 8 ++ src/image/win32/Win32WicImageWriter.cpp | 2 + src/image/win32/Win32WicImageWriter.h | 8 ++ src/image/win32/Win32WicInterface.cpp | 13 +++ src/image/win32/Win32WicInterface.h | 16 +++ .../nodes/AbstractVisualNode.cpp | 2 +- .../nodes/AbstractVisualNode.h | 4 +- test/graphics/TestDirectXRendering.cpp | 2 +- test/image/TestPngWriter.cpp | 12 +- 30 files changed, 330 insertions(+), 135 deletions(-) create mode 100644 src/image/ImageData.h create mode 100644 src/image/PlatformImage.cpp create mode 100644 src/image/PlatformImage.h create mode 100644 src/image/PlatformImageWriter.h create mode 100644 src/image/win32/Win32WicImage.cpp create mode 100644 src/image/win32/Win32WicImage.h create mode 100644 src/image/win32/Win32WicImageWriter.cpp create mode 100644 src/image/win32/Win32WicImageWriter.h create mode 100644 src/image/win32/Win32WicInterface.cpp create mode 100644 src/image/win32/Win32WicInterface.h diff --git a/src/compression/CyclicRedundancyChecker.cpp b/src/compression/CyclicRedundancyChecker.cpp index 977ed97..5f7c1fd 100644 --- a/src/compression/CyclicRedundancyChecker.cpp +++ b/src/compression/CyclicRedundancyChecker.cpp @@ -2,8 +2,9 @@ void CyclicRedundancyChecker::createTable() { + mTable = std::vector(TABLE_SIZE, 0); unsigned long c{0}; - for (int n = 0; n < 256; n++) + for (int n = 0; n < TABLE_SIZE; n++) { c = (unsigned long) n; for (int k = 0; k < 8; k++) diff --git a/src/compression/CyclicRedundancyChecker.h b/src/compression/CyclicRedundancyChecker.h index fa6cd0e..a20a1cf 100644 --- a/src/compression/CyclicRedundancyChecker.h +++ b/src/compression/CyclicRedundancyChecker.h @@ -2,6 +2,8 @@ #include "AbstractChecksumCalculator.h" +#include + class CyclicRedundancyChecker : public AbstractChecksumCalculator { public: @@ -16,5 +18,7 @@ private: bool mTableComputed{false}; uint32_t mLastValue{0xffffffffL}; - unsigned long mTable[256]; + + static const std::size_t TABLE_SIZE{ 256 }; + std::vector mTable; }; diff --git a/src/fonts/FontGlyph.cpp b/src/fonts/FontGlyph.cpp index a51414d..a99f340 100644 --- a/src/fonts/FontGlyph.cpp +++ b/src/fonts/FontGlyph.cpp @@ -55,8 +55,7 @@ std::string GlyphRunOutlines::toPostScriptPath() return path; } -FontGlyph::FontGlyph(unsigned width, unsigned height, int bearingX, int bearingY, - int advanceX, std::unique_ptr > image) +FontGlyph::FontGlyph(unsigned width, unsigned height, int bearingX, int bearingY, int advanceX, std::unique_ptr image) : mImage(std::move(image)), mWidth(width), mHeight(height), @@ -67,7 +66,7 @@ FontGlyph::FontGlyph(unsigned width, unsigned height, int bearingX, int bearingY } -Image* FontGlyph::getImage() const +Image* FontGlyph::getImage() const { return mImage.get(); } diff --git a/src/fonts/FontGlyph.h b/src/fonts/FontGlyph.h index 124800f..1b2ddf9 100644 --- a/src/fonts/FontGlyph.h +++ b/src/fonts/FontGlyph.h @@ -38,12 +38,10 @@ private: class FontGlyph { - public: - FontGlyph(unsigned width, unsigned height, int bearingX, int bearingY, - int advanceX, std::unique_ptr > image); + FontGlyph(unsigned width, unsigned height, int bearingX, int bearingY, int advanceX, std::unique_ptr image); - Image* getImage() const; + Image* getImage() const; unsigned getWidth() const; unsigned getHeight() const; @@ -57,5 +55,5 @@ private: int mBearingX{0}; int mBearingY{0}; int mAdvanceX{0}; - std::unique_ptr > mImage; + std::unique_ptr mImage; }; diff --git a/src/graphics/DrawingSurface.cpp b/src/graphics/DrawingSurface.cpp index b1f00e6..85393cf 100644 --- a/src/graphics/DrawingSurface.cpp +++ b/src/graphics/DrawingSurface.cpp @@ -40,12 +40,11 @@ Scene* DrawingSurface::getScene() return mScene.get(); } -Image* DrawingSurface::getImage() +Image* DrawingSurface::getImage() { if (!mBackingImage) { - mBackingImage = std::make_unique >(mWidth, mHeight); - mBackingImage->initialize(); + mBackingImage = std::make_unique(mWidth, mHeight); } return mBackingImage.get(); } diff --git a/src/graphics/DrawingSurface.h b/src/graphics/DrawingSurface.h index c4babf4..af94ab4 100644 --- a/src/graphics/DrawingSurface.h +++ b/src/graphics/DrawingSurface.h @@ -3,8 +3,6 @@ #include class Scene; - -template class Image; class DrawingSurface @@ -21,7 +19,7 @@ public: unsigned getHeight() const; - Image* getImage(); + Image* getImage(); Scene* getScene(); @@ -29,5 +27,5 @@ protected: unsigned mWidth = 0; unsigned mHeight = 0; std::unique_ptr mScene; - std::unique_ptr > mBackingImage; + std::unique_ptr mBackingImage; }; diff --git a/src/graphics/directx/DirectXInterface.cpp b/src/graphics/directx/DirectXInterface.cpp index 59b454b..b77360d 100644 --- a/src/graphics/directx/DirectXInterface.cpp +++ b/src/graphics/directx/DirectXInterface.cpp @@ -94,6 +94,9 @@ void DirectXInterface::initialize() void DirectXInterface::initializeD2dStandalone() { + D2D1_FACTORY_OPTIONS d2dFactoryOptions = {}; + D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory3), &d2dFactoryOptions, &mD2dFactory); + } diff --git a/src/image/CMakeLists.txt b/src/image/CMakeLists.txt index 247e6f0..81f01b3 100644 --- a/src/image/CMakeLists.txt +++ b/src/image/CMakeLists.txt @@ -1,29 +1,51 @@ +set(MODULE_NAME image) + +set(platform_LIB_INCLUDES) + list(APPEND image_HEADERS Image.h + ImageData.h + PlatformImage.h + PlatformImageWriter.h png/PngWriter.h + png/PngReader.h ) list(APPEND image_LIB_INCLUDES Image.cpp + ImageBitStream.cpp + PlatformImage.cpp png/PngWriter.cpp png/PngReader.cpp png/PngHeader.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_DEFINES "") +add_library(image SHARED ${image_LIB_INCLUDES} ${platform_LIB_INCLUDES} ${image_HEADERS}) -add_library(image SHARED ${image_LIB_INCLUDES} ${image_HEADERS}) -#target_compile_definitions(image PRIVATE ${image_DEFINES}) - -target_include_directories(image PUBLIC +target_include_directories(${MODULE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/png) -set_target_properties( image PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON ) + ${CMAKE_CURRENT_SOURCE_DIR}/png + ${CMAKE_CURRENT_SOURCE_DIR}/win32 + ) + + +set_target_properties( ${MODULE_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON ) -target_link_libraries( image PUBLIC ${image_LIBS}) +target_link_libraries( ${MODULE_NAME} PUBLIC ${image_LIBS}) -set_property(TARGET image PROPERTY FOLDER src) +set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER src) diff --git a/src/image/Image.cpp b/src/image/Image.cpp index b20ba6e..2d0b6f6 100644 --- a/src/image/Image.cpp +++ b/src/image/Image.cpp @@ -2,121 +2,111 @@ #include "Color.h" -template -Image::Image(unsigned width, unsigned height) - : mWidth(width), - mHeight(height) +Image::Image(unsigned width, unsigned height, ImageData::Type dataType) + : mWidth(width), + mHeight(height), + mDataType(mDataType) { } -template -Image::~Image() +Image::~Image() { } -template -void Image::initialize() +std::unique_ptr Image::Create(unsigned width, unsigned height, ImageData::Type dataType) { - mData = std::vector(getBytesPerRow()*mHeight, 10); + return std::make_unique(width, height, dataType); } -template -void Image::setDataItem(std::size_t index, T item) +void Image::initialize() { - if(index >= mData.size()) + if (mDataType == ImageData::Type::UCHAR || mDataType == ImageData::Type::UNKNOWN) { - return; + auto data = std::unique_ptr >(); + data->initialize(getBytesPerRow() * mHeight, 0); + mData = std::move(data); + } + else + { + auto data = std::unique_ptr >(); + data->initialize(getBytesPerRow() * mHeight, 0); + mData = std::move(data); } - mData[index] = item; } -template -void Image::setPixelValue(unsigned idx, unsigned jdx, const Color& color) +void Image::setPixelValue(unsigned idx, unsigned jdx, const Color& color) { - if (mData.empty()) + if (!mData) { initialize(); } - mData[jdx*getBytesPerRow() + idx*3] = static_cast(color.getR()); - mData[jdx*getBytesPerRow() + idx*3 + 1] = static_cast(color.getG()); - mData[jdx*getBytesPerRow() + idx*3 + 2] = static_cast(color.getB()); + const auto offset = jdx * getBytesPerRow() + idx * 3; + mData->setDataItem(offset, color.getR()); + mData->setDataItem(offset + 1, color.getG()); + mData->setDataItem(offset + 2, color.getB()); } -template -std::unique_ptr > Image::Create(unsigned width, unsigned height) -{ - return std::make_unique >(width, height); -} - -template -unsigned Image::getBytesPerRow() const +unsigned Image::getBytesPerRow() const { const auto bitsPerEntry = mBitDepth <= 8 ? 1 : 2; - return mWidth * mNumChannels *bitsPerEntry; + return mWidth * mNumChannels * bitsPerEntry; } -template -unsigned Image::getWidth() const +unsigned Image::getWidth() const { return mWidth; } -template -unsigned Image::getHeight() const +unsigned Image::getHeight() const { return mHeight; } -template -unsigned Image::getBitDepth() const +unsigned Image::getBitDepth() const { return mBitDepth; } -template -T Image::getByte(unsigned idx, unsigned jdx) const +PlatformImage* Image::getPlatformImage() const { - return mData[jdx*getBytesPerRow() + idx]; + return mPlatformImage.get(); } -template -unsigned Image::getNumChannels() const +ImageData* Image::getData() +{ + return mData.get(); +} + +unsigned char Image::getAsUnsignedChar(unsigned idx, unsigned jdx) const +{ + return mData->getAsUnsignedChar(jdx * getBytesPerRow() + idx); +} + +unsigned Image::getNumChannels() const { return mNumChannels; } -template -void Image::setData(const std::vector& data) -{ - mData = data; -} - -template -void Image::setWidth(unsigned width) +void Image::setWidth(unsigned width) { mWidth = width; } -template -void Image::setHeight(unsigned height) +void Image::setHeight(unsigned height) { mHeight = height; } -template -void Image::setBitDepth(unsigned bitDepth) +void Image::setBitDepth(unsigned bitDepth) { mBitDepth = bitDepth; } -template -void Image::setNumChannels(unsigned numChannels) +void Image::setNumChannels(unsigned numChannels) { mNumChannels = numChannels; } -template class Image; -//template class Image; diff --git a/src/image/Image.h b/src/image/Image.h index be354a6..c0f3707 100644 --- a/src/image/Image.h +++ b/src/image/Image.h @@ -1,17 +1,19 @@ #pragma once +#include "PlatformImage.h" +#include "ImageData.h" + #include #include class Color; -template class Image { public: - Image(unsigned width, unsigned height); + Image(unsigned width, unsigned height, ImageData::Type dataType = ImageData::Type::UCHAR); ~Image(); - static std::unique_ptr > Create(unsigned width, unsigned height); + static std::unique_ptr Create(unsigned width, unsigned height, ImageData::Type dataType = ImageData::Type::UCHAR); unsigned getBytesPerRow() const; unsigned getWidth() const; @@ -19,40 +21,25 @@ public: unsigned getBitDepth() 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); - - T getByte(unsigned idx, unsigned jdx) const; - - void setData(const std::vector& data); - - void setDataItem(std::size_t index, T); void setWidth(unsigned width); void setHeight(unsigned height); void setBitDepth(unsigned bitDepth); void setNumChannels(unsigned numChannels); - void initialize(); - - const T* getDataPtr() const - { - return mData.data(); - } - - const std::vector& getDataRef() const - { - return mData; - } - - std::vector getData() const - { - return mData; - } - private: + void initialize(); unsigned mWidth{1}; unsigned mHeight{1}; unsigned mBitDepth{8}; unsigned mNumChannels{4}; - std::vector mData; + + ImageData::Type mDataType; + std::unique_ptr mData; + std::unique_ptr mPlatformImage; }; diff --git a/src/image/ImageBitStream.cpp b/src/image/ImageBitStream.cpp index 4f7db7e..b57f5d7 100644 --- a/src/image/ImageBitStream.cpp +++ b/src/image/ImageBitStream.cpp @@ -1,6 +1,6 @@ #include "ImageBitStream.h" -ImageBitStream::ImageBitStream(Image* image) +ImageBitStream::ImageBitStream(Image* image) : BitStream(), mImage(image) { @@ -9,7 +9,7 @@ ImageBitStream::ImageBitStream(Image* image) bool ImageBitStream::isFinished() const { - return mByteOffset == mImage->getDataRef().size(); + return mByteOffset == mImage->getData()->getLength(); } std::vector ImageBitStream::peekNextNBytes(unsigned n) const @@ -25,7 +25,7 @@ std::optional ImageBitStream::readNextByte() { return std::nullopt; } - const auto val = mImage->getDataRef()[mByteOffset]; + const auto val = mImage->getData()->getAsUnsignedChar(mByteOffset); return val; } @@ -37,6 +37,6 @@ void ImageBitStream::writeByte(unsigned char data, bool checkOverflow ) { return; } - mImage->setDataItem(mByteOffset, data); + mImage->getData()->setDataItem(mByteOffset, data); } diff --git a/src/image/ImageBitStream.h b/src/image/ImageBitStream.h index f7bd6d2..1cd90ad 100644 --- a/src/image/ImageBitStream.h +++ b/src/image/ImageBitStream.h @@ -7,7 +7,7 @@ class ImageBitStream : public BitStream { public: - ImageBitStream(Image* image); + ImageBitStream(Image* image); bool isFinished() const override; @@ -28,5 +28,5 @@ public: } private: - Image* mImage{nullptr}; + Image* mImage{nullptr}; }; diff --git a/src/image/ImageData.h b/src/image/ImageData.h new file mode 100644 index 0000000..487523f --- /dev/null +++ b/src/image/ImageData.h @@ -0,0 +1,110 @@ +#pragma once + +#include +#include + +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 +class ImageDataT : public ImageData +{ +public: + virtual Type getType() const override + { + if (std::is_same::value) + { + return Type::UCHAR; + } + else if (std::is_same::value) + { + return Type::UINT8; + } + else + { + return Type::UNKNOWN; + } + } + + template + const T* getDataPtr() const + { + return mData.data(); + } + + template + const std::vector& getData() const + { + return mData; + } + + template + void setData(const std::vector& data) + { + mData = data; + } + + void setDataItem(std::size_t index, unsigned char item) override + { + if (index < mData.size()) + { + mData[index] = static_cast(item); + } + } + + template + void setDataItem(std::size_t index, T item) + { + if (index < mData.size()) + { + mData[index] = item; + } + } + + template + 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(mData[index]); + } + else + { + return 0; + } + } + + std::size_t getLength() const override + { + return mData.size(); + } + +private: + std::vector mData; +}; + diff --git a/src/image/PlatformImage.cpp b/src/image/PlatformImage.cpp new file mode 100644 index 0000000..a2cacb4 --- /dev/null +++ b/src/image/PlatformImage.cpp @@ -0,0 +1,13 @@ +#pragma once + +template +class Image; + +template +class PlatformImage +{ +public: + PlatformImage(Image* image); +private: + Image* mImage{ nullptr }; +}; \ No newline at end of file diff --git a/src/image/PlatformImage.h b/src/image/PlatformImage.h new file mode 100644 index 0000000..637e55d --- /dev/null +++ b/src/image/PlatformImage.h @@ -0,0 +1,15 @@ +#pragma once + +class Image; + +class PlatformImage +{ +public: + PlatformImage(Image* image) + : mImage(image) + { + + } +private: + Image* mImage{ nullptr }; +}; \ No newline at end of file diff --git a/src/image/PlatformImageWriter.h b/src/image/PlatformImageWriter.h new file mode 100644 index 0000000..71a5bcb --- /dev/null +++ b/src/image/PlatformImageWriter.h @@ -0,0 +1,6 @@ +#pragma once + +class PlatformImageWriter +{ + +}; \ No newline at end of file diff --git a/src/image/png/PngReader.cpp b/src/image/png/PngReader.cpp index 42aa29c..0e824a4 100644 --- a/src/image/png/PngReader.cpp +++ b/src/image/png/PngReader.cpp @@ -162,9 +162,9 @@ bool PngReader::readIDATChunk(unsigned length) } } -std::unique_ptr > PngReader::read() +std::unique_ptr PngReader::read() { - auto image = std::make_unique >(5, 5); + auto image = std::make_unique(5, 5); mFile = std::make_unique(mPath); mFile->open(File::AccessMode::Read); @@ -188,7 +188,6 @@ std::unique_ptr > PngReader::read() image->setHeight(mHeader.getHeight()); image->setBitDepth(mHeader.getBitDepth()); image->setNumChannels(mHeader.getPngInfo().getNumChannels()); - image->initialize(); auto image_bit_stream = std::make_unique(image.get()); PngFilter filter(mOutputStream.get(), image_bit_stream.get()); diff --git a/src/image/png/PngReader.h b/src/image/png/PngReader.h index 0dad321..32b5e78 100644 --- a/src/image/png/PngReader.h +++ b/src/image/png/PngReader.h @@ -20,7 +20,7 @@ public: ~PngReader(); void setPath(const Path& path); - std::unique_ptr > read(); + std::unique_ptr read(); private: bool readChunk(); @@ -34,7 +34,7 @@ private: PngHeader mHeader; - std::unique_ptr > mWorkingImage; + std::unique_ptr mWorkingImage; std::unique_ptr mFile; Path mPath; diff --git a/src/image/png/PngWriter.cpp b/src/image/png/PngWriter.cpp index c6d2a02..6ae31c1 100644 --- a/src/image/png/PngWriter.cpp +++ b/src/image/png/PngWriter.cpp @@ -157,7 +157,7 @@ void PngWriter::writeDataChunks(const BufferBitStream& buffer) } } -void PngWriter::write(Image* image) +void PngWriter::write(Image* image) { if (!mPath.empty()) { @@ -222,7 +222,7 @@ void PngWriter::write(Image* image) } } -void PngWriter::write(const std::unique_ptr >& image) +void PngWriter::write(const std::unique_ptr& image) { write(image.get()); } diff --git a/src/image/png/PngWriter.h b/src/image/png/PngWriter.h index 52971cf..1532896 100644 --- a/src/image/png/PngWriter.h +++ b/src/image/png/PngWriter.h @@ -3,6 +3,7 @@ #include "PngHeader.h" #include "Image.h" #include "DeflateElements.h" +#include "PlatformImageWriter.h" #include #include @@ -28,8 +29,8 @@ public: void setPngInfo(const PngInfo& info); - void write(const std::unique_ptr >& image); - void write(Image* image); + void write(const std::unique_ptr& image); + void write(Image* image); private: void writeSignature(); @@ -42,7 +43,7 @@ private: //void writeIDatChunk(); Path mPath; - Image* mWorkingImage{nullptr}; + Image* mWorkingImage{nullptr}; std::unique_ptr mInStream; std::unique_ptr mOutStream; std::unique_ptr mWorkingFile; @@ -52,6 +53,8 @@ private: PngHeader mPngHeader; Deflate::CompressionMethod mCompressionMethod{Deflate::CompressionMethod::DYNAMIC_HUFFMAN}; + + std::unique_ptr mPlatformWriter; }; using PngWriterPtr = std::unique_ptr; diff --git a/src/image/win32/Win32WicImage.cpp b/src/image/win32/Win32WicImage.cpp new file mode 100644 index 0000000..bf80630 --- /dev/null +++ b/src/image/win32/Win32WicImage.cpp @@ -0,0 +1 @@ +#include "Win32WicImage.h" \ No newline at end of file diff --git a/src/image/win32/Win32WicImage.h b/src/image/win32/Win32WicImage.h new file mode 100644 index 0000000..7b258bb --- /dev/null +++ b/src/image/win32/Win32WicImage.h @@ -0,0 +1,8 @@ +#pragma once + +#include "PlatformImage.h" + +class Win32WicImage : public PlatformImage +{ + +}; \ No newline at end of file diff --git a/src/image/win32/Win32WicImageWriter.cpp b/src/image/win32/Win32WicImageWriter.cpp new file mode 100644 index 0000000..720986d --- /dev/null +++ b/src/image/win32/Win32WicImageWriter.cpp @@ -0,0 +1,2 @@ +#include "Win32WicImageWriter.h" + diff --git a/src/image/win32/Win32WicImageWriter.h b/src/image/win32/Win32WicImageWriter.h new file mode 100644 index 0000000..6d775f9 --- /dev/null +++ b/src/image/win32/Win32WicImageWriter.h @@ -0,0 +1,8 @@ +#pragma once + +#include "PlatformImageWriter.h" + +class Win32WicImageWriter +{ + +}; \ No newline at end of file diff --git a/src/image/win32/Win32WicInterface.cpp b/src/image/win32/Win32WicInterface.cpp new file mode 100644 index 0000000..dda9315 --- /dev/null +++ b/src/image/win32/Win32WicInterface.cpp @@ -0,0 +1,13 @@ +#include "Win32WicInterface.h" + +#include + +Win32WicInterface::Win32WicInterface() +{ + mIsValid = SUCCEEDED(::CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&mImagingFactory))); +} + +IWICImagingFactory* Win32WicInterface::getFactory() const +{ + return mImagingFactory.Get(); +} \ No newline at end of file diff --git a/src/image/win32/Win32WicInterface.h b/src/image/win32/Win32WicInterface.h new file mode 100644 index 0000000..bddc692 --- /dev/null +++ b/src/image/win32/Win32WicInterface.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +struct IWICImagingFactory; + +class Win32WicInterface +{ + Win32WicInterface(); + + IWICImagingFactory* getFactory() const; + +private: + bool mIsValid{ false }; + Microsoft::WRL::ComPtr mImagingFactory; +}; \ No newline at end of file diff --git a/src/visual_elements/nodes/AbstractVisualNode.cpp b/src/visual_elements/nodes/AbstractVisualNode.cpp index db3c183..ad254aa 100644 --- a/src/visual_elements/nodes/AbstractVisualNode.cpp +++ b/src/visual_elements/nodes/AbstractVisualNode.cpp @@ -22,7 +22,7 @@ void AbstractVisualNode::update(SceneInfo* sceneInfo) } -Image* AbstractVisualNode::getImage() const +Image* AbstractVisualNode::getImage() const { return mImage.get(); } diff --git a/src/visual_elements/nodes/AbstractVisualNode.h b/src/visual_elements/nodes/AbstractVisualNode.h index a8c2593..2256385 100644 --- a/src/visual_elements/nodes/AbstractVisualNode.h +++ b/src/visual_elements/nodes/AbstractVisualNode.h @@ -31,7 +31,7 @@ public: const std::string& getName() const; - Image* getImage() const; + Image* getImage() const; bool getIsVisible() const; @@ -48,7 +48,7 @@ public: protected: Point mLocation; std::vector > mSceneItems; - std::unique_ptr > mImage; + std::unique_ptr mImage; std::vector mChildren; diff --git a/test/graphics/TestDirectXRendering.cpp b/test/graphics/TestDirectXRendering.cpp index b5c6cfa..b11dfa7 100644 --- a/test/graphics/TestDirectXRendering.cpp +++ b/test/graphics/TestDirectXRendering.cpp @@ -32,6 +32,6 @@ TEST_CASE(TestDirectXRendering, "graphics") auto text_node = std::make_unique("Test", DiscretePoint(100, 100)); scene->addNode(text_node.get()); - scene->update(nullptr); + scene->update(); gui_app->run(); }; \ No newline at end of file diff --git a/test/image/TestPngWriter.cpp b/test/image/TestPngWriter.cpp index bdcaf1e..fbc30c5 100644 --- a/test/image/TestPngWriter.cpp +++ b/test/image/TestPngWriter.cpp @@ -15,7 +15,7 @@ TEST_CASE(TestCompressedPng, "image") unsigned width = 20; unsigned height = 20; unsigned numChannels = 1; - auto image = Image::Create(width, height); + auto image = Image::Create(width, height); image->setNumChannels(numChannels); image->setBitDepth(8); @@ -26,7 +26,7 @@ TEST_CASE(TestCompressedPng, "image") data[idx] = val; } - image->setData(data); + dynamic_cast*>(image->getData())->setData(data); PngWriter writer; writer.setPath(TestUtils::getTestOutputDir() / "test_compressed.png"); @@ -48,7 +48,7 @@ TEST_CASE(TestFixedPng, "image") unsigned width = 10; unsigned height = 10; unsigned numChannels = 1; - auto image = Image::Create(width, height); + auto image = Image::Create(width, height); image->setNumChannels(numChannels); image->setBitDepth(8); @@ -60,7 +60,7 @@ TEST_CASE(TestFixedPng, "image") data[idx] = val; } - image->setData(data); + dynamic_cast*>(image->getData())->setData(data); PngWriter writer; writer.setPath(TestUtils::getTestOutputDir() / "test_fixed.png"); @@ -78,7 +78,7 @@ TEST_CASE(TestDynamicCompressedPng, "image") unsigned width = 10; unsigned height = 10; unsigned numChannels = 1; - auto image = Image::Create(width, height); + auto image = Image::Create(width, height); image->setNumChannels(numChannels); image->setBitDepth(8); @@ -90,7 +90,7 @@ TEST_CASE(TestDynamicCompressedPng, "image") data[idx] = val; } - image->setData(data); + dynamic_cast*>(image->getData())->setData(data); PngWriter writer; writer.setPath(TestUtils::getTestOutputDir() / "test_dynamic.png");