Author: post
Date: 2009-09-08 20:30:51 +0200 (Tue, 08 Sep 2009)
New Revision: 147
Modified:
RawSpeed/RawImage.cpp
RawSpeed/RawImage.h
Log:
- Added SSE2 intrinsics on Win32.
Modified: RawSpeed/RawImage.cpp
===================================================================
--- RawSpeed/RawImage.cpp 2009-09-07 11:40:48 UTC (rev 146)
+++ RawSpeed/RawImage.cpp 2009-09-08 18:30:51 UTC (rev 147)
@@ -135,8 +135,51 @@
whitePoint = m;
printf("Estimated black:%d, Estimated white: %d\n", blackLevel,
whitePoint);
}
- gw = dim.x*cpp;
float f = 65535.0f / (float)(whitePoint-blackLevel);
+ scaleValues(f);
+}
+
+#if _MSC_VER > 1399
+
+void RawImageData::scaleValues(float f) {
+ int info[4];
+ __cpuid(info,1);
+
+ // Check SSE2
+ if (f >= 0.0f && info[3]&(1<<26)) {
+
+ __m128i ssescale;
+ guint gw = pitch / 16;
+ guint i = (int)(65536.0f*f); // 16 bit fraction
+ i |= i<<16;
+ ssescale = _mm_set_epi32(i,i,i,i);
+
+ for (int y = 0; y < dim.y; y++) {
+ __m128i* pixel = (__m128i*)&data[(mOffset.y+y)*pitch];
+ for (guint x = 0 ; x < gw; x++) {
+ __m128i pix = _mm_load_si128(pixel);
+ pix = _mm_mulhi_epu16(pix, ssescale);
+ _mm_store_si128(pixel, pix);
+ pixel++;
+ }
+ }
+ } else {
+ // Not SSE2
+ gint gw = dim.x*cpp;
+ int scale = (int)(16384.0f*f); // 14 bit fraction
+ for (int y = 0; y < dim.y; y++) {
+ gushort *pixel = (gushort*)getData(0,y);
+ for (int x = 0 ; x < gw; x++) {
+ pixel[x] = clampbits(((pixel[x]-blackLevel)*scale+8192)>>14,16);
+ }
+ }
+ }
+}
+
+#else
+
+void RawImageData::scaleValues(float f) {
+ gint gw = dim.x*cpp;
int scale = (int)(16384.0f*f); // 14 bit fraction
for (int y = 0; y < dim.y; y++) {
gushort *pixel = (gushort*)getData(0,y);
@@ -146,7 +189,9 @@
}
}
+#endif
+
RawImage::RawImage( RawImageData* p ) : p_(p)
{
pthread_mutex_lock(&p_->mymutex);
Modified: RawSpeed/RawImage.h
===================================================================
--- RawSpeed/RawImage.h 2009-09-07 11:40:48 UTC (rev 146)
+++ RawSpeed/RawImage.h 2009-09-08 18:30:51 UTC (rev 147)
@@ -49,6 +49,7 @@
vector<BlackArea> blackAreas;
iPoint2D subsampling;
gboolean isAllocated() {return !!data;}
+ void scaleValues(float scale);
protected:
RawImageData(void);
RawImageData(iPoint2D dim, guint bpp, guint cpp=1);
_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit