264 lines
6.2 KiB
C++
264 lines
6.2 KiB
C++
|
|
// Intrinsic.cpp : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̨Ӧ<CCA8>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ㡣
|
|||
|
|
//
|
|||
|
|
|
|||
|
|
#include "stdafx.h"
|
|||
|
|
|
|||
|
|
#include <intrin.h>
|
|||
|
|
#include <iostream>
|
|||
|
|
|
|||
|
|
#include <chrono>
|
|||
|
|
using namespace std;
|
|||
|
|
|
|||
|
|
#include "ImageMapping.h"
|
|||
|
|
using namespace ImageMapping;
|
|||
|
|
|
|||
|
|
void Map16BitTo8Bit_u1(unsigned short *psh16BitData, long lDataLen, unsigned char* pby8BitData, int nBrightness, int nContrast);
|
|||
|
|
|
|||
|
|
int main()
|
|||
|
|
{
|
|||
|
|
unsigned short* pSrc = new unsigned short[64 * 1280 * 1024];
|
|||
|
|
unsigned char* pDest = new unsigned char[64 * 1280 * 1024];
|
|||
|
|
|
|||
|
|
/*
|
|||
|
|
_asm {
|
|||
|
|
push eax
|
|||
|
|
push ebx
|
|||
|
|
push ecx
|
|||
|
|
mov eax, 0x0F
|
|||
|
|
mov ebx, 0x10
|
|||
|
|
add eax, ebx
|
|||
|
|
mov ecx, pSrc
|
|||
|
|
mov[ecx], eax
|
|||
|
|
pop ecx
|
|||
|
|
pop ebx
|
|||
|
|
pop eax
|
|||
|
|
}
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
for (int i = 0; i < 64 * 1280 * 1024; i++)
|
|||
|
|
{
|
|||
|
|
pSrc[i] = i % 65536;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int nHist[65536] = { 0 };
|
|||
|
|
memset(nHist, 0, sizeof(nHist));
|
|||
|
|
|
|||
|
|
float fK = 0, fC = 0;
|
|||
|
|
LinarMapping::CalculateKC_u(fK, fC, pSrc, 1280 * 1024, 100, 100);
|
|||
|
|
|
|||
|
|
for(int j = 0; j < 100; j++)
|
|||
|
|
{
|
|||
|
|
chrono::system_clock::time_point tm1 = chrono::system_clock::now();
|
|||
|
|
__int64 t1 = tm1.time_since_epoch().count();
|
|||
|
|
|
|||
|
|
LinarMapping::Map16BitTo8Bit_u(pSrc, 1280*1024, pDest, fK, fC);
|
|||
|
|
|
|||
|
|
//Map16BitTo8Bit_u1(pSrc, 1280 * 1024, pDest, 100, 100);
|
|||
|
|
|
|||
|
|
chrono::system_clock::time_point tm2 = chrono::system_clock::now();
|
|||
|
|
__int64 t2 = tm2.time_since_epoch().count();
|
|||
|
|
|
|||
|
|
int nTmSpan = (tm2 - tm1).count();
|
|||
|
|
|
|||
|
|
int nTmSpan2 = t2 - t1;
|
|||
|
|
|
|||
|
|
cout << "Index " << j << ": [Span] " << nTmSpan << " / " << nTmSpan2 << endl;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
delete[] pSrc;
|
|||
|
|
pSrc = nullptr;
|
|||
|
|
|
|||
|
|
delete[] pDest;
|
|||
|
|
pDest = nullptr;
|
|||
|
|
|
|||
|
|
//getchar();
|
|||
|
|
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void Map16BitTo8Bit_u1(unsigned short *psh16BitData, long lDataLen, unsigned char* pby8BitData, int nBrightness, int nContrast)
|
|||
|
|
{
|
|||
|
|
if (psh16BitData == NULL || pby8BitData == NULL || lDataLen <= 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//ָ<><D6B8>ֱ<EFBFBD><D6B1>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
|||
|
|
int pHist[65536] = { 0 };
|
|||
|
|
memset(pHist, 0, 65536 * sizeof(int));
|
|||
|
|
|
|||
|
|
int i = 0;
|
|||
|
|
for (i = 0; i < lDataLen; i++)
|
|||
|
|
{
|
|||
|
|
pHist[psh16BitData[i]]++;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>СΪ: AreaSigma*ͼ<><CDBC><EFBFBD><EFBFBD>С/100
|
|||
|
|
int nSigma = 3 * 768;
|
|||
|
|
int nSum = 0;
|
|||
|
|
int nMin = 0;
|
|||
|
|
int nMax = 0;
|
|||
|
|
|
|||
|
|
//<2F><>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сֵ
|
|||
|
|
for (i = 0; i < 65536; i++)
|
|||
|
|
{
|
|||
|
|
nSum += pHist[i];
|
|||
|
|
if (nSum >= nSigma)
|
|||
|
|
{
|
|||
|
|
nMin = i;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
nSum = 0;
|
|||
|
|
for (i = 65535; i >= 0; i--)
|
|||
|
|
{
|
|||
|
|
nSum += pHist[i];
|
|||
|
|
if (nSum >= nSigma)
|
|||
|
|
{
|
|||
|
|
nMax = i;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
nBrightness = (nBrightness > 100) ? 100 : nBrightness;
|
|||
|
|
nBrightness = (nBrightness < 0) ? 0 : nBrightness;
|
|||
|
|
|
|||
|
|
nContrast = (nContrast > 100) ? 100 : nContrast;
|
|||
|
|
nContrast = (nContrast < 0) ? 0 : nContrast;
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>Աȶ<D4B1><C8B6><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
float K = (float)(256.0 / (nMax - nMin + 1)) * float(nBrightness / 100.0);
|
|||
|
|
float C = (float)(-K * nMin) * float(nContrast / 100.0);
|
|||
|
|
|
|||
|
|
//ͼ<><CDBC>ӳ<EFBFBD><D3B3>
|
|||
|
|
for (i = 0; i < lDataLen; i++)
|
|||
|
|
{
|
|||
|
|
int nValue = (int)(K * psh16BitData[i] + C);
|
|||
|
|
if (nValue < 0)
|
|||
|
|
{
|
|||
|
|
pby8BitData[i] = 0;
|
|||
|
|
}
|
|||
|
|
else if (nValue > 255)
|
|||
|
|
{
|
|||
|
|
pby8BitData[i] = 255;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
pby8BitData[i] = nValue;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/*
|
|||
|
|
int main()
|
|||
|
|
{
|
|||
|
|
__m128i varMi_0x00 = _mm_set_epi32(0x00, 0x00, 0x00, 0x00);
|
|||
|
|
__m128i varMi_0xFF = _mm_set_epi32(0xFF, 0xFF, 0xFF, 0xFF);
|
|||
|
|
|
|||
|
|
__m128i varMi_Value = _mm_set_epi32(-5, 160, 128, 257);
|
|||
|
|
|
|||
|
|
__m128i varMi_Mask_LT_0xFF = _mm_cmplt_epi32(varMi_Value, varMi_0xFF);
|
|||
|
|
__m128i varMi_Mask_GT_0x00 = _mm_cmpgt_epi32(varMi_Value, varMi_0x00);
|
|||
|
|
__m128i varMi_Mask_Normal = _mm_and_si128(varMi_Mask_LT_0xFF, varMi_Mask_GT_0x00);
|
|||
|
|
__m128i varMi_Value_Normal = _mm_and_si128(varMi_Value, varMi_Mask_Normal);
|
|||
|
|
|
|||
|
|
__m128i varMi_Mask_0xFF = _mm_cmpgt_epi32(varMi_Value, varMi_0xFF);
|
|||
|
|
__m128i varMi_0xFF_Valid = _mm_and_si128(varMi_0xFF, varMi_Mask_0xFF);
|
|||
|
|
|
|||
|
|
varMi_Value = _mm_or_si128(varMi_Mask_Normal, varMi_0xFF_Valid);
|
|||
|
|
|
|||
|
|
const int c_nMaxDataSize = 32 * 1024 * 1024;
|
|||
|
|
|
|||
|
|
short* fArr_A = new short[c_nMaxDataSize];
|
|||
|
|
short* fArr_B = new short[c_nMaxDataSize];
|
|||
|
|
short* fArr_C = new short[c_nMaxDataSize];
|
|||
|
|
|
|||
|
|
for (unsigned int i = 0; i < c_nMaxDataSize; i++)
|
|||
|
|
{
|
|||
|
|
fArr_A[i] = (i + 1) % 65536;
|
|||
|
|
fArr_B[i] = (i + 2) % 65536;
|
|||
|
|
fArr_C[i] = 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
__m128 varM_a, varM_b, varM_c;
|
|||
|
|
__m128i varMi_a, varMi_b, varMi_c;
|
|||
|
|
|
|||
|
|
bool bIntrinsic = true;
|
|||
|
|
|
|||
|
|
short nArr[64] = { 0 };
|
|||
|
|
|
|||
|
|
int nFlag = 1;
|
|||
|
|
|
|||
|
|
for (int j = 0; j < 100; j++)
|
|||
|
|
{
|
|||
|
|
chrono::system_clock::time_point tm1 = chrono::system_clock::now();
|
|||
|
|
|
|||
|
|
for (unsigned int i = 0; i < c_nMaxDataSize / 4; i++)
|
|||
|
|
{
|
|||
|
|
if (bIntrinsic)
|
|||
|
|
{
|
|||
|
|
varMi_a = _mm_set_epi32(fArr_A[i + 0], fArr_A[i + 1], fArr_A[i + 2], fArr_A[i + 3]);
|
|||
|
|
varM_a = _mm_cvtepi32_ps(varMi_a);
|
|||
|
|
|
|||
|
|
varMi_b = _mm_set_epi32(fArr_B[i + 0], fArr_B[i + 1], fArr_B[i + 2], fArr_B[i + 3]);
|
|||
|
|
varM_b = _mm_cvtepi32_ps(varMi_b);
|
|||
|
|
|
|||
|
|
varM_c = _mm_mul_ps(varM_a, varM_b);
|
|||
|
|
varM_c = _mm_mul_ps(varM_a, varM_b);
|
|||
|
|
varM_c = _mm_mul_ps(varM_a, varM_b);
|
|||
|
|
varM_c = _mm_mul_ps(varM_a, varM_b);
|
|||
|
|
|
|||
|
|
__m128i varM_d = _mm_cvtps_epi32(varM_c);
|
|||
|
|
|
|||
|
|
int* pAddr_Int = (int*)&varM_d;
|
|||
|
|
|
|||
|
|
nArr[0] = pAddr_Int[0];//varM_d.m128i_i32[0];
|
|||
|
|
nArr[1] = pAddr_Int[1]; //varM_d.m128i_i32[1];
|
|||
|
|
nArr[2] = pAddr_Int[2]; //varM_d.m128i_i32[2];
|
|||
|
|
nArr[3] = pAddr_Int[3]; //varM_d.m128i_i32[3];
|
|||
|
|
|
|||
|
|
//memcpy(nArr, pAddr_Int, 16);
|
|||
|
|
if(nFlag > 0)
|
|||
|
|
{
|
|||
|
|
memcpy(nArr, pAddr_Int, 16);
|
|||
|
|
nFlag = 1;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
fArr_C[4 * i + 0] = fArr_A[4 * i + 0] * fArr_B[4 * i + 0];
|
|||
|
|
fArr_C[4 * i + 1] = fArr_A[4 * i + 1] * fArr_B[4 * i + 1];
|
|||
|
|
fArr_C[4 * i + 2] = fArr_A[4 * i + 2] * fArr_B[4 * i + 2];
|
|||
|
|
fArr_C[4 * i + 3] = fArr_A[4 * i + 3] * fArr_B[4 * i + 3];
|
|||
|
|
|
|||
|
|
fArr_C[4 * i + 0] = fArr_A[4 * i + 0] * fArr_B[4 * i + 0];
|
|||
|
|
fArr_C[4 * i + 1] = fArr_A[4 * i + 1] * fArr_B[4 * i + 1];
|
|||
|
|
fArr_C[4 * i + 2] = fArr_A[4 * i + 2] * fArr_B[4 * i + 2];
|
|||
|
|
fArr_C[4 * i + 3] = fArr_A[4 * i + 3] * fArr_B[4 * i + 3];
|
|||
|
|
|
|||
|
|
fArr_C[4 * i + 0] = fArr_A[4 * i + 0] * fArr_B[4 * i + 0];
|
|||
|
|
fArr_C[4 * i + 1] = fArr_A[4 * i + 1] * fArr_B[4 * i + 1];
|
|||
|
|
fArr_C[4 * i + 2] = fArr_A[4 * i + 2] * fArr_B[4 * i + 2];
|
|||
|
|
fArr_C[4 * i + 3] = fArr_A[4 * i + 3] * fArr_B[4 * i + 3];
|
|||
|
|
|
|||
|
|
fArr_C[4 * i + 0] = fArr_A[4 * i + 0] * fArr_B[4 * i + 0];
|
|||
|
|
fArr_C[4 * i + 1] = fArr_A[4 * i + 1] * fArr_B[4 * i + 1];
|
|||
|
|
fArr_C[4 * i + 2] = fArr_A[4 * i + 2] * fArr_B[4 * i + 2];
|
|||
|
|
fArr_C[4 * i + 3] = fArr_A[4 * i + 3] * fArr_B[4 * i + 3];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
chrono::system_clock::time_point tm2 = chrono::system_clock::now();
|
|||
|
|
|
|||
|
|
int nTmSpan = (tm2 - tm1).count();
|
|||
|
|
|
|||
|
|
cout << "TmSpan " << j << ": " << nTmSpan << endl;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int jj = nArr[0];
|
|||
|
|
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
*/
|