減色プログラム
修订版 | 449600e25d07b57037212b666aaa9acad244bc56 (tree) |
---|---|
时间 | 2011-05-21 13:28:07 |
作者 | berupon <berupon@gmai...> |
Commiter | berupon |
乱数生成処理変更
@@ -238,6 +238,10 @@ | ||
238 | 238 | > |
239 | 239 | </File> |
240 | 240 | <File |
241 | + RelativePath=".\dxor.h" | |
242 | + > | |
243 | + </File> | |
244 | + <File | |
241 | 245 | RelativePath=".\quantize.h" |
242 | 246 | > |
243 | 247 | </File> |
@@ -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 | +} |
@@ -40,6 +40,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
40 | 40 | #include "ReadImage/File.h" |
41 | 41 | |
42 | 42 | #include "quantize.h" |
43 | +#include "dxor.h" | |
43 | 44 | |
44 | 45 | // http://proglab.aki.gs/mediaproc/colors.html |
45 | 46 |
@@ -58,8 +59,7 @@ int _tmain(int argc, _TCHAR* argv[]) | ||
58 | 59 | return -1; |
59 | 60 | } |
60 | 61 | |
61 | - srand(time(NULL)); | |
62 | - | |
62 | + sdxor156(time(NULL)); | |
63 | 63 | ImageInfo imageInfo; |
64 | 64 | FILE* f = _tfopen(argv[1], _T("rb")); |
65 | 65 | File file(f); |
@@ -113,9 +113,9 @@ int _tmain(int argc, _TCHAR* argv[]) | ||
113 | 113 | |
114 | 114 | for (size_t i=0; i<num_colors; ++i) { |
115 | 115 | palette[i] = Color( |
116 | - ((double)rand())/RAND_MAX, | |
117 | - ((double)rand())/RAND_MAX, | |
118 | - ((double)rand())/RAND_MAX, | |
116 | + dxor156(), | |
117 | + dxor156(), | |
118 | + dxor156(), | |
119 | 119 | 0.0 |
120 | 120 | ); |
121 | 121 | } |
@@ -41,6 +41,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
41 | 41 | #include <deque> |
42 | 42 | #include <limits> |
43 | 43 | #include <iostream> |
44 | +#include "dxor.h" | |
44 | 45 | |
45 | 46 | using namespace std; |
46 | 47 |
@@ -62,7 +63,7 @@ void fill_random(Array3D<double>& a) | ||
62 | 63 | for (size_t y=0; y<a.height_; ++y) { |
63 | 64 | for (size_t x=0; x<a.width_; ++x) { |
64 | 65 | for (size_t z=0; z<a.depth_; ++z) { |
65 | - a(x,y,z) = ((double)rand())/RAND_MAX; | |
66 | + a(x,y,z) = dxor156(); | |
66 | 67 | } |
67 | 68 | } |
68 | 69 | } |