• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

減色プログラム


コミットメタ情報

リビジョン9259c64445832fc2f3412b0a37b5be396376d1e6 (tree)
日時2011-05-22 02:25:58
作者berupon <berupon@gmai...>
コミッターberupon

ログメッセージ

optimized
added AMD64 platform

変更サマリ

差分

--- a/Color4d.h
+++ b/Color4d.h
@@ -101,22 +101,12 @@ struct Color4d
101101 }
102102
103103 double& operator[] (int idx) {
104- switch (idx) {
105- case 0: return v[0].m128d_f64[0];
106- case 1: return v[0].m128d_f64[1];
107- case 2: return v[1].m128d_f64[0];
108- case 3: return v[1].m128d_f64[1];
109- }
104+ return ((double*)&v)[idx];
110105 }
111106 const double& operator[] (int idx) const {
112- switch (idx) {
113- case 0: return v[0].m128d_f64[0];
114- case 1: return v[0].m128d_f64[1];
115- case 2: return v[1].m128d_f64[0];
116- case 3: return v[1].m128d_f64[1];
117- }
107+ return ((double*)&v)[idx];
118108 }
119-
109+
120110 double norm_squared() {
121111 double result = 0;
122112 for (int i=0; i<3; i++) {
--- a/color_quantizer.sln
+++ b/color_quantizer.sln
@@ -6,20 +6,26 @@ EndProject
66 Global
77 GlobalSection(SolutionConfigurationPlatforms) = preSolution
88 Debug|Win32 = Debug|Win32
9+ Debug|x64 = Debug|x64
910 Release|Win32 = Release|Win32
11+ Release|x64 = Release|x64
1012 EndGlobalSection
1113 GlobalSection(ProjectConfigurationPlatforms) = postSolution
1214 {21F9C24D-7A00-425D-B59C-E1CD45C445A6}.Debug|Win32.ActiveCfg = Debug|Win32
1315 {21F9C24D-7A00-425D-B59C-E1CD45C445A6}.Debug|Win32.Build.0 = Debug|Win32
16+ {21F9C24D-7A00-425D-B59C-E1CD45C445A6}.Debug|x64.ActiveCfg = Debug|x64
17+ {21F9C24D-7A00-425D-B59C-E1CD45C445A6}.Debug|x64.Build.0 = Debug|x64
1418 {21F9C24D-7A00-425D-B59C-E1CD45C445A6}.Release|Win32.ActiveCfg = Release|Win32
1519 {21F9C24D-7A00-425D-B59C-E1CD45C445A6}.Release|Win32.Build.0 = Release|Win32
20+ {21F9C24D-7A00-425D-B59C-E1CD45C445A6}.Release|x64.ActiveCfg = Release|x64
21+ {21F9C24D-7A00-425D-B59C-E1CD45C445A6}.Release|x64.Build.0 = Release|x64
1622 EndGlobalSection
1723 GlobalSection(SolutionProperties) = preSolution
1824 HideSolutionNode = FALSE
1925 EndGlobalSection
2026 GlobalSection(ExtensibilityGlobals) = postSolution
21- AMDCaPersistentConfig = Release|Win32
22- AMDCaPersistentStartup = color_quantizer
2327 AMDCaProjectFile = C:\projects\color_quantizer\CodeAnalyst\color_quantizer.caw
28+ AMDCaPersistentStartup = color_quantizer
29+ AMDCaPersistentConfig = Release|Win32
2430 EndGlobalSection
2531 EndGlobal
--- a/color_quantizer.vcproj
+++ b/color_quantizer.vcproj
@@ -12,6 +12,9 @@
1212 <Platform
1313 Name="Win32"
1414 />
15+ <Platform
16+ Name="x64"
17+ />
1518 </Platforms>
1619 <ToolFiles>
1720 </ToolFiles>
@@ -170,6 +173,162 @@
170173 Name="VCPostBuildEventTool"
171174 />
172175 </Configuration>
176+ <Configuration
177+ Name="Debug|x64"
178+ OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
179+ IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
180+ ConfigurationType="1"
181+ CharacterSet="1"
182+ >
183+ <Tool
184+ Name="VCPreBuildEventTool"
185+ />
186+ <Tool
187+ Name="VCCustomBuildTool"
188+ />
189+ <Tool
190+ Name="VCXMLDataGeneratorTool"
191+ />
192+ <Tool
193+ Name="VCWebServiceProxyGeneratorTool"
194+ />
195+ <Tool
196+ Name="VCMIDLTool"
197+ TargetEnvironment="3"
198+ />
199+ <Tool
200+ Name="VCCLCompilerTool"
201+ Optimization="0"
202+ AdditionalIncludeDirectories="./"
203+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
204+ MinimalRebuild="true"
205+ BasicRuntimeChecks="3"
206+ RuntimeLibrary="3"
207+ UsePrecompiledHeader="2"
208+ WarningLevel="3"
209+ DebugInformationFormat="3"
210+ ForcedIncludeFiles="common.h"
211+ />
212+ <Tool
213+ Name="VCManagedResourceCompilerTool"
214+ />
215+ <Tool
216+ Name="VCResourceCompilerTool"
217+ />
218+ <Tool
219+ Name="VCPreLinkEventTool"
220+ />
221+ <Tool
222+ Name="VCLinkerTool"
223+ LinkIncremental="2"
224+ GenerateDebugInformation="true"
225+ SubSystem="1"
226+ TargetMachine="17"
227+ />
228+ <Tool
229+ Name="VCALinkTool"
230+ />
231+ <Tool
232+ Name="VCManifestTool"
233+ />
234+ <Tool
235+ Name="VCXDCMakeTool"
236+ />
237+ <Tool
238+ Name="VCBscMakeTool"
239+ />
240+ <Tool
241+ Name="VCFxCopTool"
242+ />
243+ <Tool
244+ Name="VCAppVerifierTool"
245+ />
246+ <Tool
247+ Name="VCPostBuildEventTool"
248+ />
249+ </Configuration>
250+ <Configuration
251+ Name="Release|x64"
252+ OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
253+ IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
254+ ConfigurationType="1"
255+ CharacterSet="1"
256+ WholeProgramOptimization="1"
257+ >
258+ <Tool
259+ Name="VCPreBuildEventTool"
260+ />
261+ <Tool
262+ Name="VCCustomBuildTool"
263+ />
264+ <Tool
265+ Name="VCXMLDataGeneratorTool"
266+ />
267+ <Tool
268+ Name="VCWebServiceProxyGeneratorTool"
269+ />
270+ <Tool
271+ Name="VCMIDLTool"
272+ TargetEnvironment="3"
273+ />
274+ <Tool
275+ Name="VCCLCompilerTool"
276+ Optimization="2"
277+ EnableIntrinsicFunctions="true"
278+ FavorSizeOrSpeed="1"
279+ AdditionalIncludeDirectories="./"
280+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
281+ RuntimeLibrary="0"
282+ BufferSecurityCheck="false"
283+ EnableFunctionLevelLinking="true"
284+ FloatingPointModel="2"
285+ UsePrecompiledHeader="2"
286+ BrowseInformation="1"
287+ WarningLevel="3"
288+ DebugInformationFormat="3"
289+ ForcedIncludeFiles="common.h"
290+ />
291+ <Tool
292+ Name="VCManagedResourceCompilerTool"
293+ />
294+ <Tool
295+ Name="VCResourceCompilerTool"
296+ />
297+ <Tool
298+ Name="VCPreLinkEventTool"
299+ />
300+ <Tool
301+ Name="VCLinkerTool"
302+ LinkIncremental="1"
303+ GenerateDebugInformation="true"
304+ SubSystem="1"
305+ OptimizeReferences="2"
306+ EnableCOMDATFolding="2"
307+ RandomizedBaseAddress="1"
308+ TargetMachine="17"
309+ />
310+ <Tool
311+ Name="VCALinkTool"
312+ />
313+ <Tool
314+ Name="VCManifestTool"
315+ />
316+ <Tool
317+ Name="VCXDCMakeTool"
318+ />
319+ <Tool
320+ Name="VCBscMakeTool"
321+ />
322+ <Tool
323+ Name="VCFxCopTool"
324+ />
325+ <Tool
326+ Name="VCAppVerifierTool"
327+ />
328+ <Tool
329+ Name="VCPostBuildEventTool"
330+ />
331+ </Configuration>
173332 </Configurations>
174333 <References>
175334 </References>
@@ -214,6 +373,22 @@
214373 UsePrecompiledHeader="1"
215374 />
216375 </FileConfiguration>
376+ <FileConfiguration
377+ Name="Debug|x64"
378+ >
379+ <Tool
380+ Name="VCCLCompilerTool"
381+ UsePrecompiledHeader="1"
382+ />
383+ </FileConfiguration>
384+ <FileConfiguration
385+ Name="Release|x64"
386+ >
387+ <Tool
388+ Name="VCCLCompilerTool"
389+ UsePrecompiledHeader="1"
390+ />
391+ </FileConfiguration>
217392 </File>
218393 </Filter>
219394 <Filter
@@ -280,6 +455,22 @@
280455 UsePrecompiledHeader="0"
281456 />
282457 </FileConfiguration>
458+ <FileConfiguration
459+ Name="Debug|x64"
460+ >
461+ <Tool
462+ Name="VCCLCompilerTool"
463+ UsePrecompiledHeader="0"
464+ />
465+ </FileConfiguration>
466+ <FileConfiguration
467+ Name="Release|x64"
468+ >
469+ <Tool
470+ Name="VCCLCompilerTool"
471+ UsePrecompiledHeader="0"
472+ />
473+ </FileConfiguration>
283474 </File>
284475 <File
285476 RelativePath=".\ReadImage\File.h"
@@ -308,6 +499,22 @@
308499 UsePrecompiledHeader="0"
309500 />
310501 </FileConfiguration>
502+ <FileConfiguration
503+ Name="Debug|x64"
504+ >
505+ <Tool
506+ Name="VCCLCompilerTool"
507+ UsePrecompiledHeader="0"
508+ />
509+ </FileConfiguration>
510+ <FileConfiguration
511+ Name="Release|x64"
512+ >
513+ <Tool
514+ Name="VCCLCompilerTool"
515+ UsePrecompiledHeader="0"
516+ />
517+ </FileConfiguration>
311518 </File>
312519 <File
313520 RelativePath=".\ReadImage\ReadImage.h"
--- a/main.cpp
+++ b/main.cpp
@@ -144,15 +144,13 @@ int _tmain(int argc, _TCHAR* argv[])
144144 for (int j=0; j<3; j++) {
145145 double w = exp(-sqrt((double)((i-1)*(i-1) + (j-1)*(j-1)))/(stddev*stddev));
146146 filter3_weights[i][j] = Color(w,w,w,0);
147- sum += 3 * w;
147+ sum += w;
148148 }
149149 }
150- sum /= 3;
150+ double invSum = 1.0 / sum;
151151 for (int i=0; i<3; i++) {
152152 for (int j=0; j<3; j++) {
153- for (int k=0; k<3; k++) {
154- filter3_weights[i][j][k] /= sum;
155- }
153+ filter3_weights[i][j] *= invSum;
156154 }
157155 }
158156 sum = 0.0;
@@ -160,15 +158,13 @@ int _tmain(int argc, _TCHAR* argv[])
160158 for (int j=0; j<5; j++) {
161159 double w = exp(-sqrt((double)((i-2)*(i-2) + (j-2)*(j-2)))/(stddev*stddev));
162160 filter5_weights[i][j] = Color(w,w,w,0);
163- sum += 3 * w;
161+ sum += w;
164162 }
165163 }
166- sum /= 3;
164+ invSum = 1.0 / sum;
167165 for (int i=0; i<5; i++) {
168166 for (int j=0; j<5; j++) {
169- for (int k=0; k<3; k++) {
170- filter5_weights[i][j][k] /= sum;
171- }
167+ filter5_weights[i][j] *= invSum;
172168 }
173169 }
174170
@@ -199,9 +195,10 @@ int _tmain(int argc, _TCHAR* argv[])
199195 for (int x=0; x<width; x++) {
200196 const uint8_t idx = quantized_image[y][x];
201197 Color col = palette[idx];
202- c[2] = (unsigned char)(255*col[0]);
203- c[1] = (unsigned char)(255*col[1]);
204- c[0] = (unsigned char)(255*col[2]);
198+ col *= 255.0;
199+ c[2] = (unsigned char)(col[0]);
200+ c[1] = (unsigned char)(col[1]);
201+ c[0] = (unsigned char)(col[2]);
205202 fwrite(c, 3, 1, out);
206203 }
207204 }
--- a/quantize.cpp
+++ b/quantize.cpp
@@ -74,9 +74,9 @@ void random_permutation(
7474 vector<int>& result
7575 )
7676 {
77- result.clear();
77+ result.resize(count);
7878 for (size_t i=0; i<count; ++i) {
79- result.push_back(i);
79+ result[i] = i;
8080 }
8181 random_shuffle(result.begin(), result.end());
8282 }
@@ -89,10 +89,11 @@ void random_permutation_2d(
8989 {
9090 vector<int> perm1d;
9191 random_permutation(width*height, perm1d);
92- while (!perm1d.empty()) {
93- int idx = perm1d.back();
94- perm1d.pop_back();
95- result.push_back(pair<int,int>(idx % width, idx / width));
92+ const size_t sz = perm1d.size();
93+ result.resize(sz);
94+ for (size_t i=0; i<sz; ++i) {
95+ int idx = perm1d[sz-1-i];
96+ result[i] = pair<int,int>(idx % width, idx / width);
9697 }
9798 }
9899
@@ -291,17 +292,11 @@ void compute_initial_s(
291292 const Image& b
292293 )
293294 {
294- init_image(s);
295295 size_t palette_size = s.width_;
296296 int coarse_width = coarse_variables.width_;
297297 int coarse_height = coarse_variables.height_;
298298 int center_x = (b.width_-1)/2, center_y = (b.height_-1)/2;
299-
300- printf(
301- "%s started %d %d %d\n",
302- __FUNCTION__, palette_size, coarse_width, coarse_height
303- );
304-
299+
305300 Color center_b = b_value(b,0,0,0,0);
306301 Color zero_vector;
307302 zero_vector.zero();
@@ -519,10 +514,12 @@ void spatial_color_quant(
519514 size_t iters_at_current_level = 0;
520515 bool skip_palette_maintenance = false;
521516 Image s(num_colors, num_colors);
517+ init_image(s);
522518 compute_initial_s(s, coarse_variables, *b_vec[coarse_level]);
523519 Image* j_palette_sum =
524520 new Image(coarse_variables.width_, coarse_variables.height_);
525521 compute_initial_j_palette_sum(*j_palette_sum, coarse_variables, palette, num_colors);
522+ vector<double> meanfield_logs(num_colors), meanfields(num_colors);
526523 while (coarse_level >= 0 || temperature > final_temperature) {
527524 // Need to reseat this reference in case we changed p_coarse_variables
528525 Array3D<double>& coarse_variables = *p_coarse_variables;
@@ -545,7 +542,6 @@ void spatial_color_quant(
545542 while (!visit_queue.empty()) {
546543 // If we get to 10% above initial size, just revisit them all
547544 if (visit_queue.size() > coarse_variables.width_*coarse_variables.height_*11.0/10) {
548- visit_queue.clear();
549545 random_permutation_2d(coarse_variables.width_, coarse_variables.height_, visit_queue);
550546 }
551547
@@ -557,11 +553,12 @@ void spatial_color_quant(
557553 Color p_i;
558554 p_i.zero();
559555 for (int y=0; y<b.height_; ++y) {
556+ int j_y = y - center_y + i_y;
557+ if (j_y < 0 || j_y >= coarse_variables.height_) continue;
560558 for (int x=0; x<b.width_; ++x) {
561559 int j_x = x - center_x + i_x;
562- int j_y = y - center_y + i_y;
563560 if (i_x == j_x && i_y == j_y) continue;
564- if (j_x < 0 || j_y < 0 || j_x >= coarse_variables.width_ || j_y >= coarse_variables.height_) continue;
561+ if (j_x < 0 || j_x >= coarse_variables.width_) continue;
565562 Color b_ij = b_value(b, i_x, i_y, j_x, j_y);
566563 Color j_pal = (*j_palette_sum)[j_y][j_x];
567564 p_i += b_ij * j_pal;
@@ -570,7 +567,6 @@ void spatial_color_quant(
570567 p_i *= 2.0;
571568 p_i += a[i_y][i_x];
572569
573- vector<double> meanfield_logs, meanfields;
574570 double max_meanfield_log = -numeric_limits<double>::infinity();
575571 double meanfield_sum = 0.0;
576572 for (size_t v=0; v<num_colors; ++v) {
@@ -580,14 +576,15 @@ void spatial_color_quant(
580576 // will choose a value that makes the maximum e^100.
581577 Color p_i2; p_i2 = p_i;
582578 double m = -(palette[v].dot_product(p_i2 + middle_b.direct_product(palette[v]))) / temperature;
583- meanfield_logs.push_back(m);
579+ meanfield_logs[v] = m;
584580 if (m > max_meanfield_log) {
585581 max_meanfield_log = m;
586582 }
587583 }
588584 for (size_t v=0; v<num_colors; ++v) {
589- meanfields.push_back(exp(meanfield_logs[v]-max_meanfield_log+100));
590- meanfield_sum += meanfields.back();
585+ double d = exp(meanfield_logs[v]-max_meanfield_log+100);
586+ meanfields[v] = d;
587+ meanfield_sum += d;
591588 }
592589 if (meanfield_sum == 0) {
593590 cout << "Fatal error: Meanfield sum underflowed. Please contact developer." << endl;
--- a/stdafx.h
+++ b/stdafx.h
@@ -10,6 +10,7 @@
1010 #include <stdio.h>
1111 #include <tchar.h>
1212
13+#define _SECURE_SCL 0
1314
1415
1516 // TODO: プログラムに必要な追加ヘッダーをここで参照してください。