Skip to content

Commit e6cbed6

Browse files
committed
minor code cleanup and comments
1 parent 5c6e1ea commit e6cbed6

File tree

5 files changed

+95
-84
lines changed

5 files changed

+95
-84
lines changed

PIFShellExtensions.sln

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
4+
VisualStudioVersion = 14.0.25123.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PIFShellExtensions", "PIFShellExtensions\PIFShellExtensions.vcxproj", "{73E69D94-C385-4703-AD0B-BB2FE6905F46}"
77
ProjectSection(ProjectDependencies) = postProject
@@ -16,9 +16,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PIFShellExtensionsTests", "
1616
{73E69D94-C385-4703-AD0B-BB2FE6905F46} = {73E69D94-C385-4703-AD0B-BB2FE6905F46}
1717
EndProjectSection
1818
EndProject
19-
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "PIFShellExtensionsSetup64", "PIFShellExtensionsInstaller\PIFShellExtensionsInstaller32.vdproj", "{666E1DAB-6CE5-4F12-ACBA-72DA2295D8A5}"
19+
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "PIFShellExtensionsSetup64", "PIFShellExtensionsInstaller32\PIFShellExtensionsInstaller32.vdproj", "{43B95D11-3CFF-4286-B075-CF222158561F}"
2020
EndProject
21-
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "PIFShellExtensionsSetup32", "PIFShellExtensionsInstaller\PIFShellExtensionsInstaller64.vdproj", "{22F6343A-EA1E-4301-A866-4D3E02BD8F57}"
21+
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "PIFShellExtensionsSetup32", "PIFShellExtensionsInstaller64\PIFShellExtensionsInstaller64.vdproj", "{AE483C99-DC19-4BED-81DF-7DC33FAD8C45}"
2222
EndProject
2323
Global
2424
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -53,22 +53,22 @@ Global
5353
{8E105821-E661-439F-BB4D-0745753A8CDA}.Release|x64.Build.0 = Release|x64
5454
{8E105821-E661-439F-BB4D-0745753A8CDA}.Release|x86.ActiveCfg = Release|Win32
5555
{8E105821-E661-439F-BB4D-0745753A8CDA}.Release|x86.Build.0 = Release|Win32
56-
{666E1DAB-6CE5-4F12-ACBA-72DA2295D8A5}.Debug|x64.ActiveCfg = Debug
57-
{666E1DAB-6CE5-4F12-ACBA-72DA2295D8A5}.Debug|x64.Build.0 = Debug
58-
{666E1DAB-6CE5-4F12-ACBA-72DA2295D8A5}.Debug|x86.ActiveCfg = Debug
59-
{666E1DAB-6CE5-4F12-ACBA-72DA2295D8A5}.Debug|x86.Build.0 = Debug
60-
{666E1DAB-6CE5-4F12-ACBA-72DA2295D8A5}.Release|x64.ActiveCfg = Release
61-
{666E1DAB-6CE5-4F12-ACBA-72DA2295D8A5}.Release|x64.Build.0 = Release
62-
{666E1DAB-6CE5-4F12-ACBA-72DA2295D8A5}.Release|x86.ActiveCfg = Release
63-
{666E1DAB-6CE5-4F12-ACBA-72DA2295D8A5}.Release|x86.Build.0 = Release
64-
{22F6343A-EA1E-4301-A866-4D3E02BD8F57}.Debug|x64.ActiveCfg = Debug
65-
{22F6343A-EA1E-4301-A866-4D3E02BD8F57}.Debug|x64.Build.0 = Debug
66-
{22F6343A-EA1E-4301-A866-4D3E02BD8F57}.Debug|x86.ActiveCfg = Debug
67-
{22F6343A-EA1E-4301-A866-4D3E02BD8F57}.Debug|x86.Build.0 = Debug
68-
{22F6343A-EA1E-4301-A866-4D3E02BD8F57}.Release|x64.ActiveCfg = Release
69-
{22F6343A-EA1E-4301-A866-4D3E02BD8F57}.Release|x64.Build.0 = Release
70-
{22F6343A-EA1E-4301-A866-4D3E02BD8F57}.Release|x86.ActiveCfg = Release
71-
{22F6343A-EA1E-4301-A866-4D3E02BD8F57}.Release|x86.Build.0 = Release
56+
{43B95D11-3CFF-4286-B075-CF222158561F}.Debug|x64.ActiveCfg = Debug
57+
{43B95D11-3CFF-4286-B075-CF222158561F}.Debug|x64.Build.0 = Debug
58+
{43B95D11-3CFF-4286-B075-CF222158561F}.Debug|x86.ActiveCfg = Debug
59+
{43B95D11-3CFF-4286-B075-CF222158561F}.Debug|x86.Build.0 = Debug
60+
{43B95D11-3CFF-4286-B075-CF222158561F}.Release|x64.ActiveCfg = Release
61+
{43B95D11-3CFF-4286-B075-CF222158561F}.Release|x64.Build.0 = Release
62+
{43B95D11-3CFF-4286-B075-CF222158561F}.Release|x86.ActiveCfg = Release
63+
{43B95D11-3CFF-4286-B075-CF222158561F}.Release|x86.Build.0 = Release
64+
{AE483C99-DC19-4BED-81DF-7DC33FAD8C45}.Debug|x64.ActiveCfg = Debug
65+
{AE483C99-DC19-4BED-81DF-7DC33FAD8C45}.Debug|x64.Build.0 = Debug
66+
{AE483C99-DC19-4BED-81DF-7DC33FAD8C45}.Debug|x86.ActiveCfg = Debug
67+
{AE483C99-DC19-4BED-81DF-7DC33FAD8C45}.Debug|x86.Build.0 = Debug
68+
{AE483C99-DC19-4BED-81DF-7DC33FAD8C45}.Release|x64.ActiveCfg = Release
69+
{AE483C99-DC19-4BED-81DF-7DC33FAD8C45}.Release|x64.Build.0 = Release
70+
{AE483C99-DC19-4BED-81DF-7DC33FAD8C45}.Release|x86.ActiveCfg = Release
71+
{AE483C99-DC19-4BED-81DF-7DC33FAD8C45}.Release|x86.Build.0 = Release
7272
EndGlobalSection
7373
GlobalSection(SolutionProperties) = preSolution
7474
HideSolutionNode = FALSE

PIFShellExtensionsInstaller/PIFShellExtensionsInstaller32.vdproj renamed to PIFShellExtensionsInstaller32/PIFShellExtensionsInstaller32.vdproj

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
"SccProvider" = "8:"
1414
"Hierarchy"
1515
{
16+
"Entry"
17+
{
18+
"MsmKey" = "8:_B768E87047984DA89660198D73DE6A8F"
19+
"OwnerKey" = "8:_UNDEFINED"
20+
"MsmSig" = "8:_UNDEFINED"
21+
}
1622
}
1723
"Configurations"
1824
{
@@ -1814,7 +1820,7 @@
18141820
{
18151821
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_62C7E43DC5C24F0AB7B178689623E7E1"
18161822
{
1817-
"SourcePath" = "8:..\\x64\\Release\\PIFShellExtensions64.dll"
1823+
"SourcePath" = "8:"
18181824
"TargetName" = "8:"
18191825
"Tag" = "8:"
18201826
"Folder" = "8:_DEF88850782F4B4D8EB738ECB05EDB69"
@@ -1840,6 +1846,34 @@
18401846
{
18411847
}
18421848
}
1849+
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_B768E87047984DA89660198D73DE6A8F"
1850+
{
1851+
"SourcePath" = "8:..\\Win32\\Release\\PIFShellExtensions32.dll"
1852+
"TargetName" = "8:"
1853+
"Tag" = "8:"
1854+
"Folder" = "8:_DEF88850782F4B4D8EB738ECB05EDB69"
1855+
"Condition" = "8:"
1856+
"Transitive" = "11:FALSE"
1857+
"Vital" = "11:TRUE"
1858+
"ReadOnly" = "11:FALSE"
1859+
"Hidden" = "11:FALSE"
1860+
"System" = "11:FALSE"
1861+
"Permanent" = "11:FALSE"
1862+
"SharedLegacy" = "11:FALSE"
1863+
"PackageAs" = "3:1"
1864+
"Register" = "3:1"
1865+
"Exclude" = "11:FALSE"
1866+
"IsDependency" = "11:FALSE"
1867+
"IsolateTo" = "8:"
1868+
"ProjectOutputGroupRegister" = "3:1"
1869+
"OutputConfiguration" = "8:Release|Win32"
1870+
"OutputGroupCanonicalName" = "8:Built"
1871+
"OutputProjectGuid" = "8:{73E69D94-C385-4703-AD0B-BB2FE6905F46}"
1872+
"ShowKeyOutput" = "11:TRUE"
1873+
"ExcludeFilters"
1874+
{
1875+
}
1876+
}
18431877
}
18441878
}
18451879
}

PIFShellExtensionsInstaller/PIFShellExtensionsInstaller64.vdproj renamed to PIFShellExtensionsInstaller64/PIFShellExtensionsInstaller64.vdproj

File renamed without changes.

PIFShellExtensionsLib/PIFParser.cpp

Lines changed: 37 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@ using namespace Gdiplus;
66

77
const LARGE_INTEGER c_liZero = { 0, 0 };
88

9+
//
10+
// CBaseImageParser
11+
//
12+
CBaseImageParser::CBaseImageParser() :
13+
m_uWidth(0),
14+
m_uHeight(0),
15+
m_uMaxValue(0),
16+
m_uDataLen(0),
17+
m_spStream(nullptr),
18+
m_rgData(nullptr),
19+
m_imageType(PortableImageFormatType_Invalid)
20+
{
21+
GdiplusStartupInput gdiPlusStatupInput;
22+
GdiplusStartup(&_gdiPlusToken, &gdiPlusStatupInput, nullptr);
23+
}
24+
25+
CBaseImageParser::~CBaseImageParser()
26+
{
27+
delete [] m_rgData;
28+
GdiplusShutdown(_gdiPlusToken);
29+
}
30+
931
HRESULT CBaseImageParser::CreateParserFromStream(_In_ IStream* pStream, _Outptr_ CBaseImageParser** ppImageParser)
1032
{
1133
*ppImageParser = nullptr;
@@ -43,25 +65,6 @@ HRESULT CBaseImageParser::CreateParserFromStream(_In_ IStream* pStream, _Outptr_
4365
return hr;
4466
}
4567

46-
CBaseImageParser::CBaseImageParser() :
47-
m_uWidth(0),
48-
m_uHeight(0),
49-
m_uMaxValue(0),
50-
m_uDataLen(0),
51-
m_spStream(nullptr),
52-
m_rgData(nullptr),
53-
m_imageType(PortableImageFormatType_Invalid)
54-
{
55-
GdiplusStartupInput gdiPlusStatupInput;
56-
GdiplusStartup(&_gdiPlusToken, &gdiPlusStatupInput, nullptr);
57-
}
58-
59-
CBaseImageParser::~CBaseImageParser()
60-
{
61-
delete [] m_rgData;
62-
GdiplusShutdown(_gdiPlusToken);
63-
}
64-
6568
HRESULT CBaseImageParser::GetBitmap(
6669
_Out_ HBITMAP* phBitmap)
6770
{
@@ -91,7 +94,7 @@ HRESULT CBaseImageParser::GetBitmap(
9194
return hr;
9295
}
9396

94-
HRESULT CBaseImageParser::ReadImageType(_In_ IStream *pStream, _Out_ PortableImageFormatType* pImageType)
97+
HRESULT CBaseImageParser::ReadImageType(_In_ IStream* pStream, _Out_ PortableImageFormatType* pImageType)
9598
{
9699
*pImageType = PortableImageFormatType_Invalid;
97100
HRESULT hr = pStream ? S_OK : E_INVALIDARG;
@@ -122,21 +125,7 @@ HRESULT CBaseImageParser::ReadImageHeaders()
122125
if (SUCCEEDED(hr))
123126
{
124127
// First get the portable image type
125-
while (SUCCEEDED(hr) && m_imageType == PortableImageFormatType_Invalid)
126-
{
127-
// Verify type
128-
UINT type = 0;
129-
hr = ParseImageLineForNum(m_spStream, "P%u", &type);
130-
if (SUCCEEDED(hr))
131-
{
132-
hr = (type > PortableImageFormatType_Invalid && type < PortableImageFormatType_Count) ? S_OK : E_FAIL;
133-
if (SUCCEEDED(hr))
134-
{
135-
m_imageType = static_cast<PortableImageFormatType>(type);
136-
}
137-
}
138-
}
139-
128+
hr = ReadImageType(m_spStream, &m_imageType);
140129
if (SUCCEEDED(hr))
141130
{
142131
// Parse width, height and max. PBMA and PBMB don't have max values.
@@ -472,7 +461,7 @@ HRESULT CBaseImageParser::ResizeBitmap(
472461
{
473462
*phbmpResized = nullptr;
474463

475-
Bitmap *pBitmap = new Bitmap(hbmpOriginal, nullptr);
464+
Bitmap* pBitmap = new Bitmap(hbmpOriginal, nullptr);
476465
HRESULT hr = pBitmap ? S_OK : E_OUTOFMEMORY;
477466
if (SUCCEEDED(hr))
478467
{
@@ -503,13 +492,13 @@ HRESULT CBaseImageParser::ResizeBitmap(
503492
}
504493
}
505494

506-
Bitmap *pResizeBitmap = new Bitmap(desiredWidth, desiredHeight, PixelFormat24bppRGB);
495+
Bitmap* pResizeBitmap = new Bitmap(desiredWidth, desiredHeight, PixelFormat24bppRGB);
507496
hr = pResizeBitmap ? S_OK : E_OUTOFMEMORY;
508497
if (SUCCEEDED(hr))
509498
{
510499
pResizeBitmap->SetResolution(pBitmap->GetHorizontalResolution(), pBitmap->GetVerticalResolution());
511500

512-
Graphics *pgrResize = new Graphics(pResizeBitmap);
501+
Graphics* pgrResize = new Graphics(pResizeBitmap);
513502
hr = pgrResize ? S_OK : E_OUTOFMEMORY;
514503
if (SUCCEEDED(hr))
515504
{
@@ -539,8 +528,9 @@ HRESULT CBaseImageParser::ResizeBitmap(
539528
return hr;
540529
}
541530

531+
//
542532
// CPPMImageParser
543-
533+
//
544534
size_t CPPMImageParser::GetAllocationSize()
545535
{
546536
return m_uWidth * m_uHeight * 3;
@@ -579,7 +569,7 @@ HRESULT CPPMImageParser::PopulateBitmap(_In_ Bitmap* pBitmap)
579569
HRESULT hr = (m_uWidth * m_uHeight * 3 == m_uDataLen) ? S_OK : E_INVALIDARG;
580570
if (SUCCEEDED(hr))
581571
{
582-
BYTE *pCurr = m_rgData;
572+
BYTE* pCurr = m_rgData;
583573
for (UINT row = 0; row < m_uHeight; row++)
584574
{
585575
for (UINT col = 0; col < m_uWidth; col++)
@@ -594,8 +584,9 @@ HRESULT CPPMImageParser::PopulateBitmap(_In_ Bitmap* pBitmap)
594584
return hr;
595585
}
596586

587+
//
597588
// CPGMImageParser
598-
589+
//
599590
size_t CPGMImageParser::GetAllocationSize()
600591
{
601592
return m_uWidth * m_uHeight;
@@ -633,7 +624,7 @@ HRESULT CPGMImageParser::PopulateBitmap(_In_ Bitmap* pBitmap)
633624
HRESULT hr = (m_uWidth * m_uHeight == m_uDataLen) ? S_OK : E_INVALIDARG;
634625
if (SUCCEEDED(hr))
635626
{
636-
BYTE *pCurr = m_rgData;
627+
BYTE* pCurr = m_rgData;
637628
for (UINT row = 0; row < m_uHeight; row++)
638629
{
639630
for (UINT col = 0; col < m_uWidth; col++)
@@ -648,9 +639,9 @@ HRESULT CPGMImageParser::PopulateBitmap(_In_ Bitmap* pBitmap)
648639
return hr;
649640
}
650641

651-
642+
//
652643
// CPBMImageParser
653-
644+
//
654645
size_t CPBMImageParser::GetAllocationSize()
655646
{
656647
return m_uWidth * m_uHeight;
@@ -663,21 +654,7 @@ HRESULT CPBMImageParser::ReadImageHeaders()
663654
if (SUCCEEDED(hr))
664655
{
665656
// First get the portable image type
666-
while (SUCCEEDED(hr) && m_imageType == PortableImageFormatType_Invalid)
667-
{
668-
// Verify type
669-
UINT type = 0;
670-
hr = ParseImageLineForNum(m_spStream, "P%u", &type);
671-
if (SUCCEEDED(hr))
672-
{
673-
hr = (type > PortableImageFormatType_Invalid && type < PortableImageFormatType_Count) ? S_OK : E_FAIL;
674-
if (SUCCEEDED(hr))
675-
{
676-
m_imageType = static_cast<PortableImageFormatType>(type);
677-
}
678-
}
679-
}
680-
657+
hr = ReadImageType(m_spStream, &m_imageType);
681658
if (SUCCEEDED(hr))
682659
{
683660
// Parse width and height. PBM images don't have a max value field
@@ -810,7 +787,7 @@ HRESULT CPBMImageParser::PopulateBitmap(_In_ Bitmap* pBitmap)
810787
HRESULT hr = (m_uWidth * m_uHeight == m_uDataLen) ? S_OK : E_INVALIDARG;
811788
if (SUCCEEDED(hr))
812789
{
813-
BYTE *pCurr = m_rgData;
790+
BYTE* pCurr = m_rgData;
814791
for (UINT row = 0; row < m_uHeight; row++)
815792
{
816793
for (UINT col = 0; col < m_uWidth; col++)

PIFShellExtensionsLib/PIFParser.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class CBaseImageParser
2020
virtual ~CBaseImageParser();
2121

2222
HRESULT InitializeFromStream(_In_ IStream* pStream);
23-
HRESULT GetBitmap(_Out_ HBITMAP *phBitmap);
23+
HRESULT GetBitmap(_Out_ HBITMAP* phBitmap);
2424
PortableImageFormatType GetImageType() { return m_imageType; }
2525
UINT GetWidth() { return m_uWidth; }
2626
UINT GetHeight() { return m_uHeight; }
@@ -37,12 +37,12 @@ class CBaseImageParser
3737
virtual size_t GetAllocationSize() = 0;
3838
virtual HRESULT ReadImageHeaders();
3939
virtual HRESULT ReadImageData() = 0;
40-
static HRESULT ReadImageType(_In_ IStream *pStream, _Out_ PortableImageFormatType* pImageType);
40+
static HRESULT ReadImageType(_In_ IStream* pStream, _Out_ PortableImageFormatType* pImageType);
4141
virtual HRESULT ReadBinaryImageData();
4242
virtual HRESULT ReadAsciiImageData();
4343
virtual bool IsDataSizeValid() = 0;
44-
static HRESULT ReadLineFromStream(_In_ IStream *pStream, _Outptr_ char** ppBuffer);
45-
static HRESULT ParseImageLineForNum(_In_ IStream *pStream, _In_ PCSTR pszFormat, _Out_ UINT* value);
44+
static HRESULT ReadLineFromStream(_In_ IStream* pStream, _Outptr_ char** ppBuffer);
45+
static HRESULT ParseImageLineForNum(_In_ IStream* pStream, _In_ PCSTR pszFormat, _Out_ UINT* value);
4646
virtual HRESULT PopulateBitmap(_In_ Gdiplus::Bitmap* pBitmap) = 0;
4747
static bool IsWhitespace(_In_ char ch);
4848

0 commit comments

Comments
 (0)