Skip to content

Commit

Permalink
VTF 7.6
Browse files Browse the repository at this point in the history
  • Loading branch information
SCell555 committed Jul 25, 2022
1 parent 777124f commit 305d59e
Show file tree
Hide file tree
Showing 17 changed files with 401 additions and 1,858 deletions.
2 changes: 2 additions & 0 deletions ThumbnailProvider/Common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#define GDIPVER 0x0110

#include <windows.h>
#include <shlobj.h>
#include <shlwapi.h>
Expand Down
9 changes: 8 additions & 1 deletion ThumbnailProvider/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#define INITGUID
#include "Common.h"

static LONG g_cRef = 0;
#ifdef _AMD64_
#pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.Windows.GdiPlus' version='1.1.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.Windows.GdiPlus' version='1.1.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif

static volatile LONG g_cRef = 0;

struct REGKEY_DELETEKEY
{
Expand All @@ -21,6 +27,7 @@ struct REGKEY_SUBKEY_AND_VALUE
static HRESULT CreateRegistryKeys( REGKEY_SUBKEY_AND_VALUE* aKeys, ULONG cKeys );
static HRESULT DeleteRegistryKeys( REGKEY_DELETEKEY* aKeys, ULONG cKeys );

_Use_decl_annotations_
STDAPI DllCanUnloadNow()
{
return g_cRef ? S_FALSE : S_OK;
Expand Down
60 changes: 36 additions & 24 deletions ThumbnailProvider/ThumbnailProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
using namespace Gdiplus;
CThumbnailProvider::CThumbnailProvider()
{
DllAddRef();
m_cRef = 1;
m_pSite = nullptr;
DllAddRef();
m_cRef = 1;
m_pSite = nullptr;
}

CThumbnailProvider::~CThumbnailProvider()
{
if ( m_pSite )
{
m_pSite->Release();
m_pSite = nullptr;
}
DllRelease();
{
m_pSite->Release();
m_pSite = nullptr;
}
DllRelease();
}

STDMETHODIMP CThumbnailProvider::QueryInterface( REFIID riid, void** ppvObject )
Expand All @@ -28,26 +28,32 @@ STDMETHODIMP CThumbnailProvider::QueryInterface( REFIID riid, void** ppvObject )
QITABENT( CThumbnailProvider, IThumbnailProvider ),
QITABENT( CThumbnailProvider, IObjectWithSite ),
{ nullptr, 0 }
};
};
return QISearch( this, qit, riid, ppvObject );
}

STDMETHODIMP_( ULONG ) CThumbnailProvider::AddRef()
{
const LONG cRef = InterlockedIncrement( &m_cRef );
return cRef;
return cRef;
}

STDMETHODIMP_( ULONG ) CThumbnailProvider::Release()
{
const LONG cRef = InterlockedDecrement( &m_cRef );
if ( 0 == cRef )
delete this;
delete this;
return cRef;
}

STDMETHODIMP CThumbnailProvider::Initialize( IStream* pstm, DWORD grfMode )
{
if ( m_texture.IsLoaded() )
return HRESULT_FROM_WIN32( ERROR_ALREADY_INITIALIZED );

if ( grfMode & STGM_READWRITE )
return STG_E_ACCESSDENIED;

STATSTG stat;
if ( pstm->Stat( &stat, STATFLAG_NONAME ) != S_OK )
return S_FALSE;
Expand All @@ -72,11 +78,16 @@ STDMETHODIMP CThumbnailProvider::GetThumbnail( UINT cx, HBITMAP* phbmp, WTS_ALPH
*pdwAlpha = WTSAT_UNKNOWN;
ULONG_PTR token;
GdiplusStartupInput input;
if ( Ok == GdiplusStartup( &token, &input, nullptr ) )
if ( GdiplusStartup( &token, &input, nullptr ) == Ok )
{
vlUInt32 compressedSize = 0;
if ( vlUInt size; auto res = static_cast<byte*>( m_texture.GetResourceData( VTF_RSRC_AUX_COMPRESSION_INFO, size ) ) )
{
compressedSize = size > sizeof( AuxCompressionInfoHeader_t ) && reinterpret_cast<AuxCompressionInfoHeader_t*>( res )->m_CompressionLevel != 0 ? reinterpret_cast<AuxCompressionInfoEntry_t*>( res + m_texture.GetAuxInfoOffset( 0, 0, 0 ) )->m_CompressedSize : 0;
}
const vlUInt w = m_texture.GetWidth(), h = m_texture.GetHeight();
byte* pConverted = new byte[CVTFFile::ComputeImageSize( w, h, 1, IMAGE_FORMAT_BGRA8888 )];
CVTFFile::Convert( m_texture.GetData(), pConverted, w, h, m_texture.GetFormat(), IMAGE_FORMAT_BGRA8888 );
CVTFFile::Convert( m_texture.GetData(), pConverted, w, h, m_texture.GetFormat(), IMAGE_FORMAT_BGRA8888, compressedSize );
Bitmap* pBitmap = new Bitmap( w, h, w * 4, PixelFormat32bppARGB, pConverted ); // delete?
if ( pBitmap )
{
Expand All @@ -85,10 +96,11 @@ STDMETHODIMP CThumbnailProvider::GetThumbnail( UINT cx, HBITMAP* phbmp, WTS_ALPH
pBitmap->GetHBITMAP( color, phbmp );
*pdwAlpha = WTSAT_ARGB;
}
delete pBitmap;
delete[] pConverted;
}
GdiplusShutdown(token);
if( *phbmp != nullptr )
GdiplusShutdown( token );
if ( *phbmp != nullptr )
return NOERROR;
return E_NOTIMPL;

Expand All @@ -104,26 +116,26 @@ STDMETHODIMP CThumbnailProvider::GetSite( REFIID riid, void** ppvSite )
STDMETHODIMP CThumbnailProvider::SetSite( IUnknown* pUnkSite )
{
if ( m_pSite )
{
m_pSite->Release();
m_pSite = nullptr;
}
{
m_pSite->Release();
m_pSite = nullptr;
}

m_pSite = pUnkSite;
m_pSite = pUnkSite;
if ( m_pSite )
m_pSite->AddRef();
return S_OK;
}

STDAPI CThumbnailProvider_CreateInstance( REFIID riid, void** ppvObject )
{
*ppvObject = nullptr;
*ppvObject = nullptr;

CThumbnailProvider* ptp = new CThumbnailProvider();
CThumbnailProvider* ptp = new CThumbnailProvider();
if ( !ptp )
return E_OUTOFMEMORY;

const HRESULT hr = ptp->QueryInterface( riid, ppvObject );
ptp->Release();
return hr;
ptp->Release();
return hr;
}
23 changes: 12 additions & 11 deletions ThumbnailProvider/ThumbnailProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@

class CThumbnailProvider : public IThumbnailProvider, IObjectWithSite, IInitializeWithStream
{
private:
LONG m_cRef;
IUnknown* m_pSite;
CVTFFile m_texture;

~CThumbnailProvider();
~CThumbnailProvider();

public:
CThumbnailProvider();
CThumbnailProvider();

// IUnknown methods
// IUnknown methods
STDMETHOD( QueryInterface )( REFIID, void** ) override;
STDMETHOD_( ULONG, AddRef )() override;
STDMETHOD_( ULONG, Release )() override;

// IInitializeWithSteam methods
// IInitializeWithSteam methods
STDMETHOD( Initialize )( IStream*, DWORD ) override;

// IThumbnailProvider methods
// IThumbnailProvider methods
STDMETHOD( GetThumbnail )( UINT, HBITMAP*, WTS_ALPHATYPE* ) override;

// IObjectWithSite methods
// IObjectWithSite methods
STDMETHOD( GetSite )( REFIID, void** ) override;
STDMETHOD( SetSite )( IUnknown* ) override;

private:
volatile LONG m_cRef;

IUnknown* m_pSite;
CVTFFile m_texture;
};
24 changes: 18 additions & 6 deletions ThumbnailProvider/ThumbnailProvider.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
Expand Down Expand Up @@ -90,6 +90,18 @@
<LinkIncremental>false</LinkIncremental>
<TargetName>VTFThumbnailProvider64</TargetName>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<VcpkgUseStatic>true</VcpkgUseStatic>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<VcpkgUseStatic>true</VcpkgUseStatic>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<VcpkgUseStatic>true</VcpkgUseStatic>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<VcpkgUseStatic>true</VcpkgUseStatic>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
Expand Down Expand Up @@ -142,7 +154,7 @@
<Optimization>Full</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;THUMBNAILPROVIDER_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
Expand All @@ -169,7 +181,7 @@
<Optimization>Full</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN64;NDEBUG;_WINDOWS;_USRDLL;THUMBNAILPROVIDER_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
Expand Down
Loading

0 comments on commit 305d59e

Please sign in to comment.