equal
deleted
inserted
replaced
24 * THE SOFTWARE. |
24 * THE SOFTWARE. |
25 */ |
25 */ |
26 |
26 |
27 #include <stdio.h> |
27 #include <stdio.h> |
28 |
28 |
|
29 #include "config.h" |
|
30 #include "pixmap.h" |
|
31 |
29 #ifdef HAVE_PNG |
32 #ifdef HAVE_PNG |
30 # include <png.h> |
33 # include <png.h> |
31 #endif |
34 #endif |
32 |
|
33 #include "pixmap.h" |
|
34 |
35 |
35 unsigned char *Pixmap::getCharData() const |
36 unsigned char *Pixmap::getCharData() const |
36 { |
37 { |
37 unsigned char *cdata = new unsigned char[w*h*3]; |
38 unsigned char *cdata = new unsigned char[w*h*3]; |
38 Float *fd = fdata; |
39 Float *fd = fdata; |
39 |
40 |
40 #ifdef NO_SSE |
41 #if 1 //def NO_SIMD |
41 for (unsigned char *cd = cdata; cd != cdata + w*h*3; cd++, fd++) |
42 for (unsigned char *cd = cdata; cd != cdata + w*h*3; cd++, fd++) |
42 if (*fd > 1.0) |
43 if (*fd > 1.0) |
43 *cd = 255; |
44 *cd = 255; |
44 else |
45 else |
45 *cd = (unsigned char)(*fd * 255.0); |
46 *cd = (unsigned char)(*fd * 255.0); |
47 __m128 cmax = _mm_set_ps1(255.0); |
48 __m128 cmax = _mm_set_ps1(255.0); |
48 __m64 m; |
49 __m64 m; |
49 for (unsigned char *cd = cdata; cd < cdata + w*h*3; cd += 4, fd += 4) |
50 for (unsigned char *cd = cdata; cd < cdata + w*h*3; cd += 4, fd += 4) |
50 { |
51 { |
51 m = _mm_cvtps_pi16(_mm_mul_ps(cmax, |
52 m = _mm_cvtps_pi16(_mm_mul_ps(cmax, |
52 _mm_min_ps(mOne, _mm_set_ps(fd[3],fd[2],fd[1],fd[0])))); |
53 _mm_min_ps(mOne, _mm_load_ps(fd)))); |
53 for (int i = 0; i < 4; i++) |
54 for (int i = 0; i < 4; i++) |
54 cd[i] = ((unsigned char *)&m)[i<<1]; |
55 cd[i] = ((unsigned char *)&m)[i<<1]; |
55 } |
56 } |
56 #endif |
57 #endif |
57 |
58 |