2 #include "ScopeMultiImageEncoder.h"
3 #include "ScopeImage.h"
5 #include "parameters/Scope.h"
12 , compresstiff(_compresstiff)
15 , streams(_channels, nullptr)
16 , encoders(_channels, nullptr)
17 , frameencoders(_channels, nullptr) {
19 hr(__FUNCTION__) = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
20 hr(__FUNCTION__) = CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*)&
factory);
26 for (
size_t c = 0 ; c <
channels ; c++ ) {
42 assert(_filenames.size() ==
channels);
43 for (
size_t c = 0 ; c <
channels ; c++ ) {
45 hr(
factory->CreateEncoder(GUID_ContainerFormatTiff, NULL, &
encoders[c]), __FUNCTION__);
48 hr(
streams[c]->InitializeFromFilename(_filenames[c].c_str(), GENERIC_WRITE), __FUNCTION__);
57 for (
size_t c = 0 ; c <
channels ; c++ ) {
59 IPropertyBag2 *pPropertybag = NULL;
65 PROPBAG2 option = { 0 };
66 option.pstrName = L
"TiffCompressionMethod";
68 VariantInit(&varValue);
71 varValue.bVal = WICTiffCompressionZIP;
73 varValue.bVal = WICTiffCompressionNone;
74 hr(pPropertybag->Write(1, &option, &varValue));
114 assert(
channels == _multiimage->Channels());
115 for (
size_t c = 0 ; c <
channels ; c++ ) {
117 WICPixelFormatGUID formatGUID = GUID_WICPixelFormat16bppGray;
119 hr((IsEqualGUID(formatGUID, GUID_WICPixelFormat16bppGray) ? S_OK : E_FAIL), __FUNCTION__);
152 hr(
frameencoders[c]->SetSize(_multiimage->Linewidth(), _multiimage->Lines()), __FUNCTION__);
154 const UINT cbStride = (_multiimage->Linewidth() * 2 + 3) & ~3;
155 const UINT cbBufferSize = _multiimage->Lines() * cbStride;
160 hr(
frameencoders[c]->WritePixels(_multiimage->Lines(), cbStride, cbBufferSize,
reinterpret_cast<BYTE*
>(imagedata.GetPointer())), __FUNCTION__);
172 assert(channels < _multiimage->Channels());
173 for (
size_t c = 0 ; c <
channels ; c++ ) {
174 hr(
frameencoders[c]->SetSize(_multiimage->Linewidth(), _multiimage->Lines()), __FUNCTION__);
176 WICPixelFormatGUID formatGUID = GUID_WICPixelFormat16bppGray;
178 hr((IsEqualGUID(formatGUID, GUID_WICPixelFormat16bppGray) ? S_OK : E_FAIL), __FUNCTION__);
180 UINT cbStride = (_multiimage->Linewidth() * 2 + 3) & ~3;
182 UINT cbBufferSize =
static_cast<UINT
>((part.second - part.first)/_multiimage->Linewidth() * cbStride);
185 hr(
frameencoders[c]->WritePixels(_multiimage->Lines(), cbStride, cbBufferSize,
reinterpret_cast<BYTE*
>(imagedata.GetPointer())), __FUNCTION__);
void NewFrame()
Creates a new frame, initializes its frameencoder, and writes metadata.
IWICImagingFactory * factory
our Windows Imaging Component factory
void Initialize(const std::vector< std::wstring > &_filenames)
Creates and initializes encoders and streams for disk writing.
std::vector< IWICBitmapFrameEncode * > frameencoders
a frameencoder for each channel (remade for each frame)
void SafeRelease(Interface **ppInterfaceToRelease)
A safe release for COM objects.
std::vector< IWICStream * > streams
a stream for each channel
const bool compresstiff
do TIFF compressiong?
Gives RAII safe access (read&write) to the pixeldata of a ScopeImage.
This is the include file for standard system include files, or project specific include files that ar...
ScopeMultiImageEncoder(const ScopeMultiImageEncoder &)
disable copy and assignment
const bool dosave
do we actually save (true) or only count the frames (false)
~ScopeMultiImageEncoder()
Releases resources and uninitializes COM.
void WriteFrameNewPart(ScopeMultiImagePtr const _multiimage)
Writes the new part of a multiimage into the current frames.
void WriteMetadata()
Writes metadata via the current frameencoder into a frame Is not functional, due to limitations in WI...
uint32_t framecount
keeping track of how many frames we encoded
Various helper functions and classes for Scope.
void WriteFrame(ScopeMultiImagePtr const _multiimage)
Writes a complete multi image into the current frames.
std::vector< IWICBitmapEncoder * > encoders
an encoder for each channel
std::pair< typename std::vector< T >::iterator, typename std::vector< T >::iterator > datapart_t
pair of two iterators over the data vector
const uint32_t channels
how many channels to encode