Initial WIC image writing.
This commit is contained in:
parent
53a9f7bd15
commit
8c814ce89f
6 changed files with 72 additions and 3 deletions
|
@ -1,6 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
using Path = std::filesystem::path;
|
||||
|
||||
class Image;
|
||||
|
||||
class PlatformImageWriter
|
||||
{
|
||||
public:
|
||||
enum class ImgFormat
|
||||
{
|
||||
PNG
|
||||
};
|
||||
|
||||
virtual void write(const Path& path, Image* image, ImgFormat format = ImgFormat::PNG) = 0;
|
||||
};
|
|
@ -15,6 +15,10 @@
|
|||
|
||||
#include "ByteUtils.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Win32WicImageWriter.h"
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
PngWriter::PngWriter()
|
||||
|
@ -157,8 +161,20 @@ void PngWriter::writeDataChunks(const BufferBitStream& buffer)
|
|||
}
|
||||
}
|
||||
|
||||
void PngWriter::writePlatform(Image* image)
|
||||
{
|
||||
mPlatformWriter = std::make_unique<Win32WicImageWriter>();
|
||||
mPlatformWriter->write(mPath, image, PlatformImageWriter::ImgFormat::PNG);
|
||||
}
|
||||
|
||||
void PngWriter::write(Image* image)
|
||||
{
|
||||
if (image->getPlatformImage())
|
||||
{
|
||||
writePlatform(image);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mPath.empty())
|
||||
{
|
||||
mWorkingFile = std::make_unique<File>(mPath);
|
||||
|
|
|
@ -33,6 +33,8 @@ public:
|
|||
void write(Image* image);
|
||||
|
||||
private:
|
||||
void writePlatform(Image* image);
|
||||
|
||||
void writeSignature();
|
||||
void writeHeader();
|
||||
|
||||
|
|
|
@ -1,2 +1,40 @@
|
|||
#include "Win32WicImageWriter.h"
|
||||
|
||||
#include "Image.h"
|
||||
#include "Win32WicInterface.h"
|
||||
#include "Win32WicImage.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
#include <wincodec.h>
|
||||
#include <wrl.h>
|
||||
|
||||
void Win32WicImageWriter::write(const Path& path, Image* image, ImgFormat format )
|
||||
{
|
||||
Win32WicInterface wic_interface;
|
||||
|
||||
Microsoft::WRL::ComPtr<IWICStream> pStream;
|
||||
auto hr = wic_interface.getFactory()->CreateStream(&pStream);
|
||||
|
||||
hr = pStream->InitializeFromFilename(path.wstring().c_str(), GENERIC_WRITE);
|
||||
|
||||
Microsoft::WRL::ComPtr<IWICBitmapEncoder> pEncoder;
|
||||
hr = wic_interface.getFactory()->CreateEncoder(GUID_ContainerFormatPng, NULL, &pEncoder);
|
||||
|
||||
hr = pEncoder->Initialize(pStream.Get(), WICBitmapEncoderNoCache);
|
||||
|
||||
Microsoft::WRL::ComPtr<IWICBitmapFrameEncode> pFrameEncode;
|
||||
hr = pEncoder->CreateNewFrame(&pFrameEncode, NULL);
|
||||
|
||||
hr = pFrameEncode->Initialize(NULL);
|
||||
|
||||
hr = pFrameEncode->SetSize(image->getWidth(), image->getHeight());
|
||||
|
||||
WICPixelFormatGUID out_format = GUID_WICPixelFormatDontCare;
|
||||
hr = pFrameEncode->SetPixelFormat(&out_format);
|
||||
|
||||
hr = pFrameEncode->WriteSource(dynamic_cast<Win32WicImage*>(image->getPlatformImage())->getBitmap(), NULL);
|
||||
|
||||
hr = pFrameEncode->Commit();
|
||||
|
||||
hr = pEncoder->Commit();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
#include "PlatformImageWriter.h"
|
||||
|
||||
class Win32WicImageWriter
|
||||
class Win32WicImageWriter : public PlatformImageWriter
|
||||
{
|
||||
|
||||
public:
|
||||
void write(const Path& path, Image* image, ImgFormat format = ImgFormat::PNG) override;
|
||||
};
|
|
@ -33,5 +33,5 @@ TEST_CASE(TestD2dOffScreenRendering, "graphics")
|
|||
|
||||
PngWriter writer;
|
||||
writer.setPath(TestUtils::getTestOutputDir(__FILE__) / "out.png");
|
||||
//writer.write(image);
|
||||
writer.write(image);
|
||||
};
|
Loading…
Reference in a new issue