Skip to content

Commit dc77ee8

Browse files
committed
Migrate WIC image I/O to use msw::ComPtr and add dynamic codec enumeration
- Replace raw COM pointers with msw::ComPtr for automatic lifetime management - Use releaseAndGetAddressOf() for COM output parameters - Remove overly restrictive static_assert from ComPtr that prevented compilation with forward-declared types - Implement dynamic WIC decoder/encoder enumeration to automatically register supported extensions - WIC now queries installed codecs at registration time instead of using hardcoded extension list
1 parent d4dae9a commit dc77ee8

File tree

5 files changed

+426
-88
lines changed

5 files changed

+426
-88
lines changed

include/cinder/ImageSourceFileWic.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@
2525
#include "cinder/Cinder.h"
2626
#include "cinder/ImageIO.h"
2727
#include "cinder/Exception.h"
28+
#include "cinder/msw/CinderMsw.h"
2829

2930
#include <guiddef.h>
3031

3132
// WIC forward declarations
3233
struct IWICImagingFactory;
3334
struct IWICBitmapFrameDecode;
3435
struct IWICStream;
36+
struct IWICComponentEnumerator;
37+
struct IWICBitmapCodecInfo;
3538

3639
namespace cinder {
3740

@@ -52,12 +55,12 @@ class ImageSourceFileWic : public ImageSource {
5255

5356
bool processFormat( const ::GUID &guid, ::GUID *convertGUID );
5457

55-
std::shared_ptr<IWICBitmapFrameDecode> mFrame;
56-
std::shared_ptr<IWICStream> mStream;
57-
ci::BufferRef mBuffer;
58-
bool mRequiresConversion;
59-
int32_t mRowBytes;
60-
::GUID mPixelFormat, mConvertPixelFormat;
58+
msw::ComPtr<IWICBitmapFrameDecode> mFrame;
59+
msw::ComPtr<IWICStream> mStream;
60+
ci::BufferRef mBuffer;
61+
bool mRequiresConversion;
62+
int32_t mRowBytes;
63+
::GUID mPixelFormat, mConvertPixelFormat;
6164
};
6265

6366
class ImageSourceFileWicExceptionUnsupportedData : public ImageIoException {

include/cinder/ImageTargetFileWic.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424

2525
#include "cinder/Cinder.h"
2626
#include "cinder/ImageIo.h"
27+
#include "cinder/msw/CinderMsw.h"
2728

2829
#ifndef GUID
2930
typedef struct _GUID GUID;
3031
#endif
3132
struct IWICBitmapEncoder;
3233
struct IWICBitmapFrameEncode;
34+
struct IWICComponentEnumerator;
35+
struct IWICBitmapCodecInfo;
3336

3437
namespace cinder {
3538

@@ -38,24 +41,24 @@ typedef std::shared_ptr<class ImageTargetFileWic> ImageTargetFileWicRef;
3841
class ImageTargetFileWic : public ImageTarget {
3942
public:
4043
static ImageTargetRef create( DataTargetRef dataTarget, ImageSourceRef imageSource, ImageTarget::Options options, const std::string &extensionData );
41-
44+
4245
void* getRowPointer( int32_t row ) override;
4346
void finalize() override;
44-
47+
4548
static void registerSelf();
46-
49+
4750
protected:
4851
ImageTargetFileWic( DataTargetRef dataTarget, ImageSourceRef imageSource, ImageTarget::Options options, const std::string &extensionData );
4952

5053
void setupPixelFormat( const GUID &guid );
5154

52-
std::shared_ptr<uint8_t> mData;
53-
int32_t mRowBytes;
54-
DataTargetRef mDataTarget;
55-
const GUID *mCodecGUID;
56-
57-
std::shared_ptr<IWICBitmapEncoder> mEncoder;
58-
std::shared_ptr<IWICBitmapFrameEncode> mBitmapFrame;
55+
std::shared_ptr<uint8_t> mData;
56+
int32_t mRowBytes;
57+
DataTargetRef mDataTarget;
58+
const GUID *mCodecGUID;
59+
60+
msw::ComPtr<IWICBitmapEncoder> mEncoder;
61+
msw::ComPtr<IWICBitmapFrameEncode> mBitmapFrame;
5962
};
6063

6164
} // namespace cinder

include/cinder/msw/CinderMsw.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,14 @@ CI_API inline vec2 toVec2( const ::POINTFX& p )
5656
CI_API void ComDelete( void* p );
5757

5858
//! Functor version that calls Release() on a com-managed object
59-
struct CI_API ComDeleter{ template<typename T> void operator()( T* p ){ if( p ) p->Release();
60-
}}; // namespace cinder::msw
59+
struct CI_API ComDeleter {
60+
template<typename T>
61+
void operator()( T* p )
62+
{
63+
if( p )
64+
p->Release();
65+
}
66+
};
6167

6268
template<typename T>
6369
using ManagedComRef = std::shared_ptr<T>;
@@ -86,8 +92,6 @@ ManagedComPtr<T> makeComUnique( T* p )
8692
- Move operations transfer ownership without ref-counting */
8793
template<typename T>
8894
class CI_API ComPtr {
89-
static_assert( std::is_base_of<IUnknown, T>::value, "ComPtr<T>: T must derive from IUnknown" );
90-
9195
public:
9296
ComPtr() noexcept
9397
: ptr( nullptr )

0 commit comments

Comments
 (0)