Browse Source

DKCompressor test

Hongtae Kim 7 years ago
parent
commit
bde66181f3
4 changed files with 116 additions and 72 deletions
  1. 1
    1
      .gitignore
  2. 96
    54
      TestApp1/TestApp1.cpp
  3. 17
    1
      TestApp1/TestApp1.vcxproj
  4. 2
    16
      TestApp1/TestApp1.xcodeproj/project.pbxproj

+ 1
- 1
.gitignore View File

@@ -59,7 +59,7 @@ __pycache__/
59 59
 docs/_build/
60 60
 
61 61
 # project settings
62
-Build/**
62
+Build/
63 63
 
64 64
 # Visual Studio 2015 and later
65 65
 *.VC.db

+ 96
- 54
TestApp1/TestApp1.cpp View File

@@ -10,79 +10,121 @@
10 10
 
11 11
 class TestApp1 : public DKApplication
12 12
 {
13
-	DKObject<DKWindow> window;
14
-	DKObject<DKThread> renderThread;
15
-
16
-	DKAtomicNumber32 runningRenderThread;
17 13
 public:
18
-	void RenderThread(void)
14
+
15
+	void OnInitialize(void) override
19 16
 	{
20
-		DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
21
-		DKObject<DKCommandQueue> queue = device->CreateCommandQueue();
22
-		DKObject<DKSwapChain> swapChain = queue->CreateSwapChain(window);
17
+		DKLogD("%s", DKGL_FUNCTION_NAME);
23 18
 
24 19
 		DKTimer timer;
25
-		timer.Reset();
26
-
27
-		DKLog("Render thread begin");
28
-		while (!runningRenderThread.CompareAndSet(0, 0))
20
+		for (auto format : { DKCompressor::Deflate, DKCompressor::LZ4, DKCompressor::LZ4HC })
29 21
 		{
30
-			DKRenderPassDescriptor rpd = swapChain->CurrentRenderPassDescriptor();
31
-			double t = timer.Elapsed();
32
-			t = (cos(t) + 1.0) * 0.5;
33
-			rpd.colorAttachments.Value(0).clearColor = DKColor(t, 0.0, 0.0, 0.0);
34
-
35
-			DKObject<DKCommandBuffer> buffer = queue->CreateCommandBuffer();
36
-			DKObject<DKRenderCommandEncoder> encoder = buffer->CreateRenderCommandEncoder(rpd);
37
-			if (encoder)
22
+			const char* fmt = [](DKCompressor::Method m) {
23
+				switch (m)
24
+				{
25
+				case DKCompressor::Deflate:	return "DEFLATE";
26
+				case DKCompressor::LZ4: return "LZ4";
27
+				case DKCompressor::LZ4HC:	return "LZ4HC";
28
+				}
29
+				return "Unknown";
30
+			}(format);
31
+
32
+			auto GetFileSizeStr = [](const DKFile* file)
38 33
 			{
39
-				// draw scene!
40
-
41
-				encoder->EndEncoding();
42
-				buffer->Commit();
43
-				//buffer->WaitUntilCompleted();
44
-				swapChain->Present();
34
+				size_t s = file->TotalLength();
35
+				if (s > size_t(1) << 40)
36
+				{
37
+					size_t d = size_t(1) << 40;
38
+					double n = static_cast<double>(s / d);
39
+					double f = static_cast<double>(s % d) / static_cast<double>(d);
40
+					return DKString::Format("%.3fTB", n + f);
41
+				}
42
+				if (s > size_t(1) << 30)
43
+				{
44
+					size_t d = size_t(1) << 30;
45
+					double n = static_cast<double>(s / d);
46
+					double f = static_cast<double>(s % d) / static_cast<double>(d);
47
+					return DKString::Format("%.3fGB", n + f);
48
+				}
49
+				if (s > size_t(1) << 20)
50
+				{
51
+					size_t d = size_t(1) << 20;
52
+					double n = static_cast<double>(s / d);
53
+					double f = static_cast<double>(s % d) / static_cast<double>(d);
54
+					return DKString::Format("%.3fMB", n + f);
55
+				}
56
+				if (s > size_t(1) << 10)
57
+				{
58
+					size_t d = size_t(1) << 10;
59
+					double n = static_cast<double>(s / d);
60
+					double f = static_cast<double>(s % d) / static_cast<double>(d);
61
+					return DKString::Format("%.3fKB", n + f);
62
+				}
63
+				return DKString::Format("%dB", s);
64
+			};
65
+
66
+			DKString filename1 = "C:\\Users\\hong\\desktop\\test\\1";
67
+			DKString filename2 = filename1 + "." + fmt;
68
+			DKString filename3 = filename2 + ".dec";
69
+			DKObject<DKFile> f1 = DKFile::Create(filename1, DKFile::ModeOpenExisting, DKFile::ModeShareRead);
70
+			DKObject<DKFile> f2 = DKFile::Create(filename2, DKFile::ModeOpenNew, DKFile::ModeShareExclusive);
71
+			DKObject<DKFile> f3 = DKFile::Create(filename3, DKFile::ModeOpenNew, DKFile::ModeShareExclusive);
72
+
73
+			DKLog("--> Compressing %s", fmt);
74
+			DKCompressor comp(format);
75
+
76
+			bool result;
77
+			timer.Reset();
78
+			// compress
79
+			result = comp.Compress(f1, f2);
80
+			double elapsed = timer.Elapsed();
81
+
82
+			if (result)
83
+				DKLog("File Compressed (%s): %ls -> %ls (%fsec)", fmt,
84
+				(const wchar_t*)GetFileSizeStr(f1), (const wchar_t*)GetFileSizeStr(f2), elapsed);
85
+			else
86
+			{
87
+				DKLog("File Compression failed");
88
+				continue;
45 89
 			}
90
+
91
+			f2->SetCurrentPosition(0);
92
+			timer.Reset();
93
+			// decompress
94
+			result = DKCompressor::Decompress(f2, f3);
95
+			elapsed = timer.Elapsed();
96
+
97
+			if (result)
98
+				DKLog("File Decompressed (%s): %ls -> %ls (%fsec)", fmt,
99
+				(const wchar_t*)GetFileSizeStr(f2), (const wchar_t*)GetFileSizeStr(f3), elapsed);
46 100
 			else
47 101
 			{
102
+				DKLog("File Decompression failed");
103
+				continue;
48 104
 			}
49 105
 
50
-			DKThread::Sleep(0.01);
51
-		}
52
-		DKLog("RenderThread terminating...");
53
-	}
106
+			// generate hash
107
+			for (DKFile* f : { f1.Ptr(), f2.Ptr(), f3.Ptr() })
108
+			{
109
+				DKString path = f->Path();
110
+				f->SetCurrentPosition(0);
111
+				DKHashResultSHA1 sha1;
112
+				if (DKHashSHA1(f, sha1))
113
+				{
114
+					DKLog("SHA1(%ls): %ls", (const wchar_t*)path, (const wchar_t*)sha1.String());
115
+				}
116
+				else
117
+					DKLog("SHA1(%ls) failed!", (const wchar_t*)path);
118
+			}
54 119
 
55
-	void OnInitialize(void) override
56
-	{
57
-		DKLogD("%s", DKGL_FUNCTION_NAME);
58
-		try {
59
-			window = DKWindow::Create("DefaultWindow");
60
-		}
61
-		catch (DKError& e)
62
-		{
63
-			DKLogE("error? :%ls", (const wchar_t*)e.Description());
64 120
 		}
65
-		window->Activate();
66 121
 
67
-		window->AddEventHandler(this,
68
-			DKFunction([this](const DKWindow::WindowEvent& e) {
69
-			if (e.type == DKWindow::WindowEvent::WindowClosed)
70
-				DKApplication::Instance()->Terminate(0);
71
-		}),
72
-		NULL, NULL);
73
-
74
-		runningRenderThread = 1;
75
-		renderThread = DKThread::Create(DKFunction(this, &TestApp1::RenderThread)->Invocation());
122
+		Terminate(0);
76 123
 	}
77 124
 	void OnTerminate(void) override
78 125
 	{
79 126
 		DKLogD("%s", DKGL_FUNCTION_NAME);
80 127
 
81
-		runningRenderThread = 0;
82
-		renderThread->WaitTerminate();
83
-		renderThread = NULL;
84
-		window = NULL;
85
-
86 128
 		DKLogI("Memory Pool Statistics");
87 129
 		size_t numBuckets = DKMemoryPoolNumberOfBuckets();
88 130
 		DKMemoryPoolBucketStatus* buckets = new DKMemoryPoolBucketStatus[numBuckets];

+ 17
- 1
TestApp1/TestApp1.vcxproj View File

@@ -22,7 +22,7 @@
22 22
     <ProjectGuid>{AE0AF61D-F069-4AFA-AE24-A75C6A233B37}</ProjectGuid>
23 23
     <Keyword>Win32Proj</Keyword>
24 24
     <RootNamespace>TestApp1</RootNamespace>
25
-    <WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
25
+    <WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
26 26
   </PropertyGroup>
27 27
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
28 28
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@@ -104,6 +104,10 @@
104 104
     <Manifest>
105 105
       <EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
106 106
     </Manifest>
107
+    <PostBuildEvent>
108
+      <Command>
109
+      </Command>
110
+    </PostBuildEvent>
107 111
   </ItemDefinitionGroup>
108 112
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
109 113
     <ClCompile>
@@ -120,6 +124,10 @@
120 124
     <Manifest>
121 125
       <EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
122 126
     </Manifest>
127
+    <PostBuildEvent>
128
+      <Command>
129
+      </Command>
130
+    </PostBuildEvent>
123 131
   </ItemDefinitionGroup>
124 132
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
125 133
     <ClCompile>
@@ -140,6 +148,10 @@
140 148
     <Manifest>
141 149
       <EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
142 150
     </Manifest>
151
+    <PostBuildEvent>
152
+      <Command>
153
+      </Command>
154
+    </PostBuildEvent>
143 155
   </ItemDefinitionGroup>
144 156
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
145 157
     <ClCompile>
@@ -160,6 +172,10 @@
160 172
     <Manifest>
161 173
       <EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
162 174
     </Manifest>
175
+    <PostBuildEvent>
176
+      <Command>
177
+      </Command>
178
+    </PostBuildEvent>
163 179
   </ItemDefinitionGroup>
164 180
   <ItemGroup>
165 181
     <ClInclude Include="Win32\Resource.h" />

+ 2
- 16
TestApp1/TestApp1.xcodeproj/project.pbxproj View File

@@ -9,7 +9,6 @@
9 9
 /* Begin PBXBuildFile section */
10 10
 		66DA89941DD3117F00338015 /* TestApp1.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 844A9A801DD0C080007DCC89 /* TestApp1.cpp */; };
11 11
 		66DA89971DD3118000338015 /* TestApp1.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 844A9A801DD0C080007DCC89 /* TestApp1.cpp */; };
12
-		66DA899B1DD3164E00338015 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 66DA899A1DD3164E00338015 /* AppKit.framework */; };
13 12
 		840D5D3B1DDA07B2009DA369 /* DK.xcodeproj in Resources */ = {isa = PBXBuildFile; fileRef = 840D5D3A1DDA07B2009DA369 /* DK.xcodeproj */; };
14 13
 		840D5D921DDA08C2009DA369 /* libDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 840D5D891DDA0890009DA369 /* libDK.a */; };
15 14
 		840D5D931DDA08CA009DA369 /* libDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 840D5D871DDA0890009DA369 /* libDK.a */; };
@@ -21,9 +20,6 @@
21 20
 		844A9A891DD0C080007DCC89 /* TestApp1.rc in Resources */ = {isa = PBXBuildFile; fileRef = 844A9A7F1DD0C080007DCC89 /* TestApp1.rc */; };
22 21
 		844A9A8B1DD0C08F007DCC89 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 844A9A741DD0C080007DCC89 /* Assets.xcassets */; };
23 22
 		844A9A8D1DD0C08F007DCC89 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 844A9A761DD0C080007DCC89 /* LaunchScreen.storyboard */; };
24
-		84D883561E3A6A9200478725 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D883551E3A6A9200478725 /* OpenAL.framework */; };
25
-		84D883601E3A6B0000478725 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D8835F1E3A6B0000478725 /* OpenAL.framework */; };
26
-		84F6F3401E142A110096F558 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84F6F33F1E142A110096F558 /* UIKit.framework */; };
27 23
 /* End PBXBuildFile section */
28 24
 
29 25
 /* Begin PBXContainerItemProxy section */
@@ -72,7 +68,6 @@
72 68
 /* End PBXContainerItemProxy section */
73 69
 
74 70
 /* Begin PBXFileReference section */
75
-		66DA899A1DD3164E00338015 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
76 71
 		840D5D3A1DDA07B2009DA369 /* DK.xcodeproj */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "wrapper.pb-project"; name = DK.xcodeproj; path = ../DK/DK.xcodeproj; sourceTree = "<group>"; };
77 72
 		841948E81DDCBE5000E039F0 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
78 73
 		841948E91DDCBE5000E039F0 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
@@ -91,9 +86,6 @@
91 86
 		844A9A7E1DD0C080007DCC89 /* TestApp1.ico */ = {isa = PBXFileReference; lastKnownFileType = image.ico; path = TestApp1.ico; sourceTree = "<group>"; };
92 87
 		844A9A7F1DD0C080007DCC89 /* TestApp1.rc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TestApp1.rc; sourceTree = "<group>"; };
93 88
 		844A9A801DD0C080007DCC89 /* TestApp1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestApp1.cpp; sourceTree = "<group>"; };
94
-		84D883551E3A6A9200478725 /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = System/Library/Frameworks/OpenAL.framework; sourceTree = SDKROOT; };
95
-		84D8835F1E3A6B0000478725 /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.2.sdk/System/Library/Frameworks/OpenAL.framework; sourceTree = DEVELOPER_DIR; };
96
-		84F6F33F1E142A110096F558 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.2.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; };
97 89
 /* End PBXFileReference section */
98 90
 
99 91
 /* Begin PBXFrameworksBuildPhase section */
@@ -101,8 +93,6 @@
101 93
 			isa = PBXFrameworksBuildPhase;
102 94
 			buildActionMask = 2147483647;
103 95
 			files = (
104
-				84D883561E3A6A9200478725 /* OpenAL.framework in Frameworks */,
105
-				66DA899B1DD3164E00338015 /* AppKit.framework in Frameworks */,
106 96
 				840D5D931DDA08CA009DA369 /* libDK.a in Frameworks */,
107 97
 			);
108 98
 			runOnlyForDeploymentPostprocessing = 0;
@@ -111,8 +101,6 @@
111 101
 			isa = PBXFrameworksBuildPhase;
112 102
 			buildActionMask = 2147483647;
113 103
 			files = (
114
-				84D883601E3A6B0000478725 /* OpenAL.framework in Frameworks */,
115
-				84F6F3401E142A110096F558 /* UIKit.framework in Frameworks */,
116 104
 				840D5D921DDA08C2009DA369 /* libDK.a in Frameworks */,
117 105
 			);
118 106
 			runOnlyForDeploymentPostprocessing = 0;
@@ -123,10 +111,6 @@
123 111
 		66DA89141DD1887A00338015 /* Frameworks */ = {
124 112
 			isa = PBXGroup;
125 113
 			children = (
126
-				84D8835F1E3A6B0000478725 /* OpenAL.framework */,
127
-				84D883551E3A6A9200478725 /* OpenAL.framework */,
128
-				84F6F33F1E142A110096F558 /* UIKit.framework */,
129
-				66DA899A1DD3164E00338015 /* AppKit.framework */,
130 114
 			);
131 115
 			name = Frameworks;
132 116
 			sourceTree = "<group>";
@@ -512,6 +496,7 @@
512 496
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
513 497
 				PRODUCT_BUNDLE_IDENTIFIER = "com.icondb.TestApp1-iOS";
514 498
 				PRODUCT_NAME = "$(TARGET_NAME)";
499
+				PROVISIONING_PROFILE_SPECIFIER = "";
515 500
 				SDKROOT = iphoneos;
516 501
 				TARGETED_DEVICE_FAMILY = "1,2";
517 502
 			};
@@ -529,6 +514,7 @@
529 514
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
530 515
 				PRODUCT_BUNDLE_IDENTIFIER = "com.icondb.TestApp1-iOS";
531 516
 				PRODUCT_NAME = "$(TARGET_NAME)";
517
+				PROVISIONING_PROFILE_SPECIFIER = "";
532 518
 				SDKROOT = iphoneos;
533 519
 				TARGETED_DEVICE_FAMILY = "1,2";
534 520
 				VALIDATE_PRODUCT = YES;