• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

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

減色プログラム


Commit MetaInfo

Revision449600e25d07b57037212b666aaa9acad244bc56 (tree)
Time2011-05-21 13:28:07
Authorberupon <berupon@gmai...>
Commiterberupon

Log Message

乱数生成処理変更

Change Summary

Incremental Difference

--- a/color_quantizer.vcproj
+++ b/color_quantizer.vcproj
@@ -238,6 +238,10 @@
238238 >
239239 </File>
240240 <File
241+ RelativePath=".\dxor.h"
242+ >
243+ </File>
244+ <File
241245 RelativePath=".\quantize.h"
242246 >
243247 </File>
--- /dev/null
+++ b/dxor.h
@@ -0,0 +1,26 @@
1+#pragma once
2+
3+// from http://www001.upp.so-net.ne.jp/isaku/dxor.c.html
4+
5+static union { int i[4]; double d[2]; __m128i m; }
6+x = {{123456789,(362436069&0xFFFFF)|0x3FF00000,0,0}},
7+y = {{521288629,( 88675123&0xFFFFF)|0x3FF00000,0,0}},
8+z = {{ 5783321,( 6615241&0xFFFFF)|0x3FF00000,0,0}};
9+
10+__inline
11+void sdxor156(int s)
12+{
13+ // http://unkar.org/r/tech/1192628099#l76
14+ x.i[0] = s=1812433253UL*(s^(s>>30)) + 1;
15+ y.i[0] = s=1812433253UL*(s^(s>>30)) + 1;
16+ z.i[0] = s=1812433253UL*(s^(s>>30)) + 1;
17+}
18+
19+__inline double dxor156(void) {
20+ const union { int i[4]; __m128i m; } mask={{-1,0xFFFFF,0,0}};
21+ __m128i t=x.m, s;
22+ s=_mm_slli_epi64(t,19); t=_mm_xor_si128(t,s);
23+ t=_mm_and_si128(t,mask.m); s=_mm_srli_epi64(t,33);
24+ s=_mm_xor_si128(s,t); t=y.m; x.m=t; t=z.m; y.m=t;
25+ t=_mm_xor_si128(t,s); z.m=t; return z.d[0]-1.0;
26+}
--- a/main.cpp
+++ b/main.cpp
@@ -40,6 +40,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4040 #include "ReadImage/File.h"
4141
4242 #include "quantize.h"
43+#include "dxor.h"
4344
4445 // http://proglab.aki.gs/mediaproc/colors.html
4546
@@ -58,8 +59,7 @@ int _tmain(int argc, _TCHAR* argv[])
5859 return -1;
5960 }
6061
61- srand(time(NULL));
62-
62+ sdxor156(time(NULL));
6363 ImageInfo imageInfo;
6464 FILE* f = _tfopen(argv[1], _T("rb"));
6565 File file(f);
@@ -113,9 +113,9 @@ int _tmain(int argc, _TCHAR* argv[])
113113
114114 for (size_t i=0; i<num_colors; ++i) {
115115 palette[i] = Color(
116- ((double)rand())/RAND_MAX,
117- ((double)rand())/RAND_MAX,
118- ((double)rand())/RAND_MAX,
116+ dxor156(),
117+ dxor156(),
118+ dxor156(),
119119 0.0
120120 );
121121 }
--- a/quantize.cpp
+++ b/quantize.cpp
@@ -41,6 +41,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4141 #include <deque>
4242 #include <limits>
4343 #include <iostream>
44+#include "dxor.h"
4445
4546 using namespace std;
4647
@@ -62,7 +63,7 @@ void fill_random(Array3D<double>& a)
6263 for (size_t y=0; y<a.height_; ++y) {
6364 for (size_t x=0; x<a.width_; ++x) {
6465 for (size_t z=0; z<a.depth_; ++z) {
65- a(x,y,z) = ((double)rand())/RAND_MAX;
66+ a(x,y,z) = dxor156();
6667 }
6768 }
6869 }