Skip to content

Commit 6f97b45

Browse files
committed
Refactor: subtractive cleanup of bloated code
- Extracted `GetDefaultBitmapProps` helper to remove duplicate D2D1 properties initialization in `RenderEngine.cpp`. - Combined multiple `if (!deferZoomResizeSync)` conditions to remove AST duplication and dead code blocks in `main.cpp`. - Removed unused variables from the `IsLikelyShellIconFallback` validation method and updated its call site in `main.cpp`. - Removed redundant header includes in `ImageLoader.cpp` to optimize compilation.
1 parent 34b9aa7 commit 6f97b45

3 files changed

Lines changed: 20 additions & 35 deletions

File tree

QuickView/ImageLoader.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ using namespace QuickView;
3030
#include <immintrin.h> // SIMD
3131
#include "SIMDUtils.h"
3232
#include <thread>
33-
#include "PreviewExtractor.h"
3433
#include <shobjidl.h> // [Add] for IShellItemImageFactory
3534
#include "MappedFile.h" // [Opt]
3635
#if defined(__has_include)
@@ -581,16 +580,10 @@ HRESULT CImageLoader::LoadFromFile(LPCWSTR filePath, IWICBitmapSource** bitmap)
581580
return hr;
582581
}
583582

584-
#include <turbojpeg.h>
585583

586584
// High-Performance Library Includes
587585

588586
#include <webp/decode.h> // libwebp
589-
#include <webp/demux.h>
590-
#include <avif/avif.h> // libavif
591-
#include <jxl/decode.h> // libjxl
592-
#include <jxl/resizable_parallel_runner.h>
593-
#include <jxl/thread_parallel_runner.h>
594587
#include <libraw/libraw.h> // libraw
595588
#include <wincodec.h>
596589

@@ -600,13 +593,11 @@ HRESULT CImageLoader::LoadFromFile(LPCWSTR filePath, IWICBitmapSource** bitmap)
600593
#include <sstream>
601594
#include <iomanip>
602595
#include "exif.h"
603-
#include <immintrin.h> // [AVX2]
604596
// [v6.0] EasyExif
605597
#include "ImageEngine.h"
606598

607599
// Wuffs (Google's memory-safe decoder)
608600
// Implementation is in WuffsImpl.cpp with selective module loading
609-
#include "WuffsLoader.h"
610601

611602
// [v5.3] Global storage - kept for internal decoder use, exposed via DecodeResult.metadata
612603
std::wstring g_lastFormatDetails;
@@ -7392,7 +7383,6 @@ void CImageLoader::ComputeHistogramFromFrame(const QuickView::RawImageFrame& fra
73927383
// Phase 6: Surgical Format Optimizations
73937384
// ============================================================================
73947385

7395-
#include <webp/decode.h>
73967386

73977387

73987388

@@ -8700,7 +8690,6 @@ CImageLoader::ImageHeaderInfo CImageLoader::PeekHeader(LPCWSTR filePath) {
87008690
// It decodes images directly to RawImageFrame, bypassing WIC where possible.
87018691
// ============================================================================
87028692

8703-
#include "MemoryArena.h"
87048693

87058694
HRESULT CImageLoader::LoadToFrame(LPCWSTR filePath, QuickView::RawImageFrame* outFrame,
87068695
QuantumArena* arena,

QuickView/RenderEngine.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ HRESULT CRenderEngine::CreateDeviceResources() {
115115
return S_OK;
116116
}
117117

118+
119+
// Helper to standardize D2D1 bitmap properties creation
120+
static inline D2D1_BITMAP_PROPERTIES1 GetDefaultBitmapProps(
121+
DXGI_FORMAT format = DXGI_FORMAT_B8G8R8A8_UNORM,
122+
D2D1_ALPHA_MODE alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED)
123+
{
124+
return D2D1::BitmapProperties1(
125+
D2D1_BITMAP_OPTIONS_NONE,
126+
D2D1::PixelFormat(format, alphaMode),
127+
96.0f, 96.0f
128+
);
129+
}
130+
118131
HRESULT CRenderEngine::CreateBitmapFromWIC(IWICBitmapSource* wicBitmap, ID2D1Bitmap** d2dBitmap) {
119132
if (!wicBitmap || !d2dBitmap) return E_INVALIDARG;
120133

@@ -149,10 +162,7 @@ HRESULT CRenderEngine::CreateBitmapFromWIC(IWICBitmapSource* wicBitmap, ID2D1Bit
149162
}
150163

151164
// Use PREMULTIPLIED mode for proper transparency support
152-
D2D1_BITMAP_PROPERTIES1 props = D2D1::BitmapProperties1(
153-
D2D1_BITMAP_OPTIONS_NONE,
154-
D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED)
155-
);
165+
D2D1_BITMAP_PROPERTIES1 props = GetDefaultBitmapProps();
156166

157167
// Create D2D bitmap from WIC using Resource Context
158168
hr = m_d2dContext->CreateBitmapFromWicBitmap(
@@ -168,11 +178,7 @@ HRESULT CRenderEngine::CreateBitmapFromMemory(const void* data, UINT width, UINT
168178
if (!m_d2dContext) return E_POINTER;
169179

170180
// Assume BGRX (32bpp) as standard
171-
D2D1_BITMAP_PROPERTIES1 props = D2D1::BitmapProperties1(
172-
D2D1_BITMAP_OPTIONS_NONE,
173-
D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED),
174-
96.0f, 96.0f
175-
);
181+
D2D1_BITMAP_PROPERTIES1 props = GetDefaultBitmapProps();
176182

177183
return m_d2dContext->CreateBitmap(D2D1::SizeU(width, height), data, stride, &props, reinterpret_cast<ID2D1Bitmap1**>(ppBitmap));
178184
}
@@ -210,11 +216,7 @@ HRESULT CRenderEngine::UploadRawFrameToGPU(const QuickView::RawImageFrame& frame
210216
break;
211217
}
212218

213-
D2D1_BITMAP_PROPERTIES1 props = D2D1::BitmapProperties1(
214-
D2D1_BITMAP_OPTIONS_NONE,
215-
D2D1::PixelFormat(dxgiFormat, alphaMode),
216-
96.0f, 96.0f
217-
);
219+
D2D1_BITMAP_PROPERTIES1 props = GetDefaultBitmapProps(dxgiFormat, alphaMode);
218220

219221
// [Optimization] Use GPU Compute for non-native format conversion
220222
if (m_computeEngine && m_computeEngine->IsAvailable() &&

QuickView/main.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5837,11 +5837,8 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
58375837

58385838
if (!deferZoomResizeSync) {
58395839
g_programmaticResize = false;
5840-
}
5841-
5842-
// [DComp Fix] Update Image Layout (Fit + Zoom) logic
5843-
// [Refactor] Use Centralized SyncDCompState
5844-
if (!deferZoomResizeSync) {
5840+
// [DComp Fix] Update Image Layout (Fit + Zoom) logic
5841+
// [Refactor] Use Centralized SyncDCompState
58455842
RECT rc; GetClientRect(hwnd, &rc);
58465843
SyncDCompState(hwnd, (float)rc.right, (float)rc.bottom);
58475844
}
@@ -9075,10 +9072,7 @@ static bool TryBuildPhase1WicEmbeddedFrame(const std::wstring& path, std::shared
90759072

90769073
// With SIIGBF_THUMBNAILONLY the Shell API never returns icons.
90779074
// This is a defensive-only check for typical Windows icon dimensions.
9078-
static bool IsLikelyShellIconFallback(
9079-
const std::shared_ptr<QuickView::RawImageFrame>& frame,
9080-
UINT /*sourceW*/,
9081-
UINT /*sourceH*/) {
9075+
static bool IsLikelyShellIconFallback(const std::shared_ptr<QuickView::RawImageFrame>& frame) {
90829076
if (!frame || !frame->IsValid()) return false;
90839077
int w = frame->width;
90849078
int h = frame->height;
@@ -9190,7 +9184,7 @@ static void PrimePhase1Placeholder(HWND hwnd, const std::wstring& path, ImageID
91909184
// Shell thumbnail: multi-level cache-only extraction (no disk decode, safe for UI thread)
91919185
std::shared_ptr<QuickView::RawImageFrame> shellFrame;
91929186
if (TryBuildPhase1ShellCachedFrame(path, &shellFrame)) {
9193-
if (IsLikelyShellIconFallback(shellFrame, sourceW, sourceH)) {
9187+
if (IsLikelyShellIconFallback(shellFrame)) {
91949188
OutputDebugStringW(L"[Phase1] Shell cache returned icon-like bitmap. Treat as cache miss.\n");
91959189
} else {
91969190
if (ApplyPhase1PlaceholderFrame(hwnd, path, imageId, shellFrame, sourceW, sourceH, L"Shell Cache Thumbnail")) {

0 commit comments

Comments
 (0)