#include "sth_util.h"
#include <qtcore>
#include <qtgui>
#include <QFile>
#include <QString>
#define _TIME_ qPrintable (QTime::currentTime().toString( "hh:mm:ss:zzz"))
int KTable[256]; //KTable 表示从后往前第一次出现处的游标
//{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //默认初始化为0
int shiftTable[256];
void BuildTable( const unsigned char* head, int length )
{
static bool k = true; //保证此函数之执行一次
if(k)
{
for ( int i = 0; i < 256; i ++ ) //总体初始化为-1
KTable[i] = -1;
for ( int i = 0; i < length; i ++ ) //保存帧头字节的游标
KTable[ head[i] ] = i;
k = false;
}
}
bool Str_To_Int(const QString& str , int& num)
{
bool ok = false;
int val = str.toInt(&ok );
if(ok) num = val;
return ok;
}
typedef unsigned char UCHAR;
void five2eight(void* pI,void* pO,unsigned int size)
{
UCHAR* pS =(UCHAR*)pI;
UCHAR* pD =(UCHAR*)pO;
for (int i=0,j=0;i<size;i+=5,j+=8)
{
pD[j] = pS[i]>>6;
pD[j+1] = (pS[i] <<2) + (pS[i+1]>>6);
pD[j+2] = ((pS[i+1] & 0x30) >>4); //+ (pS[i+2]>>4);
pD[j+3] = (pS[i+1]<<4) + (pS[i+2] >>4);
pD[j+4] = ( (pS[i+2] & 0x0c)>>2) ;//pS[i+3];
pD[j+5] = (pS[i+2]<<6) + (pS[i+3]>>2);
pD[j+6] = pS[i+3]& 0x03;
pD[j+7] = pS[i+4];
}
//颠倒字节顺序
unsigned char temp;
for (unsigned int i = 0; i<size/5*8; i +=2)
{
temp = pD[i+1];
pD[i+1] = pD[i];
pD[i] = temp;
}
}
void three2four(void* pI,void* pO,unsigned int size)
{
UCHAR* pS =(UCHAR*)pI;
UCHAR* pD =(UCHAR*)pO;
for (int i=0,j=0;i<size;i+=3,j+=4)
{
pD[j] = pS[i] >> 4;
pD[j+1] = pS[i] << 4 + pS[i+1] >> 4;
pD[j+2] = pS[i+1] & 0x0F;
pD[j+3] = pS[i+2];
}
//颠倒字节顺序
unsigned char temp;
for (unsigned int i = 0; i<size/3*4; i +=2)
{
temp = pD[i+1];
pD[i+1] = pD[i];
pD[i] = temp;
}
}
void ScanCameToRaw( QString &inFileName , QString &outFileName )
{
int i,j;
QFile scanCamFile,scanRawFile;
int block = 4070;
unsigned char *buff1 = new unsigned char[block];
memset( buff1, 0, block );
unsigned char *buff11 = new unsigned char[block/5*8];
memset( buff11, 0, block/5*8 );
int pos = 0;
scanCamFile.setFileName( inFileName );
scanCamFile.open( QIODevice::ReadOnly );
scanRawFile.setFileName( outFileName );
scanRawFile.open(QIODevice::WriteOnly );
pos += 400;
for ( j = 0; j < 11635; ++j )
{
pos += 40;
scanCamFile.seek(pos);
scanCamFile.read( (char*)buff1, block );
five2eight( buff1, buff11, block);
scanRawFile.write( (char*)buff11, block/5*8 );
pos += (block + 10);
}
delete []buff1;
delete []buff11;
}
void GazeCamToRaw( QString &inFileName, QString &outFileName )
{
QFile gazeCamFile, gazeRawFile;
int block =512 *2 /8*5;
unsigned char *buff1 = new unsigned char[block];
memset( buff1, 0, block );
unsigned char *buff11 = new unsigned char[block/5*8];
memset( buff11, 0, block/5*8 );
int i,j;
int pos = 0;
gazeCamFile.setFileName( inFileName );
gazeCamFile.open( QIODevice::ReadOnly );
gazeRawFile.setFileName( outFileName );
gazeRawFile.open(QIODevice::WriteOnly );
pos += 80;
gazeCamFile.seek(pos);
for ( j = 0; j < 512; ++j )
{
gazeCamFile.read( (char*)buff1, block );
five2eight( buff1, buff11, block);
gazeRawFile.write( (char*)buff11, block/5*8 );
}
delete []buff1;
delete []buff11;
}
int SearchHead2R(unsigned char* pData,int size,const unsigned char* fileHead,int headLength)
{
int i = 0;//初始化游标
int j = 0;
int m = i + headLength;
// int k = headLength -1;
//计时
LARGE_INTEGER tempTime;
double fre;
__int64 startTime,stoptime,totalTime; //开始结束时间
QueryPerformanceFrequency(&tempTime);
fre = tempTime.QuadPart;
QueryPerformanceCounter(&tempTime);
startTime = tempTime.QuadPart;
while( i < size && j < headLength )
{
if( pData[i] == fileHead[j] ) //开始逐个比较
{
++i;
++j;
}
else
{
//以下是新的匹配错误时查找正确匹配时的位置
// while( k >= 0 && pData[m] != fileHead[k] )
// --k;
//用查找表做
//k = KTable[ pData[m] ] - 1; //KTable中的是以1开头的位置,而k代表的是以0开始的游标
j = 0;
i = m - KTable[ pData[m] ];
m = i + headLength;
}
}
QueryPerformanceCounter(&tempTime);
stoptime = tempTime.QuadPart;
totalTime = (stoptime - startTime) * 1000000 / fre;
//qDebug() << QString("searchHead2R coast time : %1").arg(totalTime);
if( i < size )
return i - headLength;
return -1;
}
bool SaveTextToFile(const QString& fileName , const QString& textContent)
{
if(fileName.isEmpty())
{
MsgBox( QObject::tr("文件名为空!") );
return false;
}
if(textContent.isEmpty())
{
MsgBox(QObject::tr("内容为空!"));
return false;
}
QFile file(fileName);
if( !file.open(QFile::WriteOnly | QIODevice::Text ) ){
QMessageBox::about(0,"Tips" , "save failured!!!");
return false;
}
QTextStream ots(&file);
ots << textContent;
return true;
}
QString GetTextFromFile(const QString& filePath)
{
QFile file(filePath);
file.open(QFile::ReadOnly| QIODevice::Text );
return file.readAll();
}
//
//void QStringtoCharBuf(const QString& src , char* buf)
//{
// //static QTextCodec *coder = QTextCodec::codecForName("gb18030");
// //strcpy(buf, (const char*) coder->fromUnicode(src).data() );
//
// strcpy(buf, QFile::encodeName(src).constData() );
//}
bool SaveBinDataToFile(const QString& fileName , void* data , int dataLen)
{
if(fileName.isEmpty())
{
MsgBox( QObject::tr("文件名为空!") );
return false;
}
if( data == 0 || dataLen == 0)
{
MsgBox(QObject::tr("内容为空!"));
return false;
}
QFile file(fileName);
if( !file.open(QFile::WriteOnly) ){
QMessageBox::about(0,"Tips" , "save failured!!!");
return false;
}
QDataStream ots(&file);
ots.writeRawData( (const char*)data , dataLen);
return true;
}
bool SaveBoardParameterToFile(QFile* file, void* data, int dataLen)
{
if( data == 0 || dataLen == 0)
{
MsgBox(QObject::tr("内容为空!"));
return false;
}
QDataStream ots(file);
ots.writeRawData( (const char*)data , dataLen);
return true;
}
QByteArray GetBinDataFromFile(const QString& fileName)
{
QFile file(fileName);
if( file.open(QFile::ReadOnly) )
return file.readAll();
else
return QByteArray();
}
void qstring_to_charbuf(const QString& src , char* buf)
{
//static QTextCodec *coder = QTextCodec::codecForName("gb18030");
//strcpy(buf, (const char*) coder->fromUnicode(src).data() );
strcpy(buf, QFile::encodeName(src).constData() );
}
QString GetFileNameFromDialog(const QString& strFilter /*= ""*/)
{
static QString dirName;
QString str = QFileDialog::getOpenFileName( 0 , QObject::tr("get file name") , dirName , strFilter);
if(!str.isEmpty()) dirName = str;
return str;
}
#include <qfileinfo>
QStringList GetFileListFromDialog()
{
QStringList retList;
//QString ret;
QFileDialog* fileDialog = new QFileDialog;
fileDialog->setFileMode(QFileDialog::ExistingFiles);
if(fileDialog->exec() == QFileDialog::Accepted)
retList = fileDialog->selectedFiles();
//ret = retList[0];
return retList;
}
QStringList GetFileNamesFromDialog(const QString& strFilter /*= ""*/)
{
static QString dirName ;
QStringList str = QFileDialog::getOpenFileNames( 0 , QObject::tr("get file names") , dirName , strFilter );
if(str.size() > 0 )
{
dirName = QFileInfo(str[0]).absolutePath();
//MsgBox(dirName);
}
return str;
}
QString GetDirectoryFromDialog()
{
static QString dirName;
QString str = QFileDialog::getExistingDirectory( 0 , QObject::tr("get directory name") , dirName );
if(!str.isEmpty()) dirName = str;
return str;
}
QString GetSaveNameFromDialog(const QString& nameFilter /*= ""*/)
{
static QString dirName;
QString str = QFileDialog::getSaveFileName( 0 , QObject::tr("get save name") , dirName ,
nameFilter );
if(!str.isEmpty()) dirName = str;
return str;
}
//验证路径是否合法
bool PathIsValid(QString path)
{
if(path.isEmpty() || path == "点击设置"||path == "选择网络分发日志存储目录")
return false;
return true;
}
//验证是否压缩码流
bool IsCompressData(QString dataType)
{
if (dataType == "Scan-Medium-CompressData" || dataType == "Scan-Short-CompressData" || dataType == "Gaze-CompressData")
return true;
return false;
}
//验证是否直传数据
bool IsZCData(QString dataType)
{
if (dataType == "Scan-Medium-ImageLeft" || dataType == "Scan-Medium-ImageRight" || dataType == "Scan-Short-ImageLeft" || dataType == "Scan-Short-ImageRight" || dataType == "Gaze-ImageLeft" || dataType == "Gaze-ImageRight")
{
return true;
}
else
return false;
}
//验证是否直通数据
bool IsThroughData(QString dataType)
{
if ("Scan-Medium-ThroughData" == dataType || "Scan-Short-ThroughData" == dataType || "Gaze-ThroughData" == dataType)
{
return true;
}
else
return false;
}
void MsgBox(const QString& str)
{
QMessageBox::about (0 , QObject::tr("Tips") , str );
}
class MainWidgetMoveHelper : public QObject
{
private:
bool eventFilter(QObject *obj, QEvent *event)
{
switch(event->type())
{
case QEvent::MouseButtonPress :
{
QMouseEvent *ev = static_cast<QMouseEvent*>(event);
if (ev->button() == Qt::LeftButton)
{
QWidget* widget = qobject_cast<QWidget*>(obj);
m_dragPos = ev->globalPos() - widget->frameGeometry().topLeft();
//event->accept();
}
}
case QEvent::MouseMove :
{
QMouseEvent *ev = static_cast<QMouseEvent*>(event);
if (ev->buttons() & Qt::LeftButton)
{
QWidget* widget = qobject_cast<QWidget*>(obj);
//if ( (m_dragPos.y() < 50 && m_dragPos.x() < widget->size().width())
// /*||(m_dragPos.y() > 50 && m_dragPos.x() < widget->size().width()-200)*/ )
if ( m_dragPos.y() < 50 || (m_dragPos.y() > widget->size().height()-100) )
{
QWidget* widget = qobject_cast<QWidget*>(obj);
widget->move(ev->globalPos() - m_dragPos);
}
}
}
default:
return QObject::eventFilter(obj ,event);
}
}
QPoint m_dragPos;
};
//帮助定义窗口移动
void InstallMainWidgetMoveHelper(QWidget* w)
{
w->installEventFilter(new MainWidgetMoveHelper);
}
//从QString获取数字
bool GetNumberFromQString(const QString& str , int& num , int base /*= 10*/)
{
bool ok;
int res = str.toInt(&ok,base);
if(ok){num = res;}
return ok;
}
#include <sstream>
#include <iomanip>
#include <bitset>
std::string DataHex2string(void* data , int ByteLength , int showOffset /*= 10*/)
{
using namespace std;
std::stringstream ss;
unsigned char* pData = (unsigned char*) data;
for(int i = 0 ; i< ByteLength ; ++i)
{
//if( (i+1)%showOffset == 0 )
//{
// ss << setw(3) << i<< ":";
//}
ss << setw(2) << setfill('0') << hex << (int)pData[i] << " " <<( (i+1)%showOffset == 0 ?"\n" : "") ;
}
return ss.str();
}
std::string int2string(int data)
{
using namespace std;
std::stringstream ss;
ss << data ;
return ss.str();
}
#include <utility>
#include <algorithm>
void swap_short(unsigned short &data) //交换高字节、低字节顺序
{
std::swap( *(unsigned char*)&data , *( (unsigned char*)&data+1) );
}
void swap_short(short &data) //交换高字节、低字节顺序
{
std::swap( *(unsigned char*)&data , *( (unsigned char*)&data+1) );
}
void swap_int( int& intVar )
{
char* pVar = (char*)&intVar;
std::reverse( pVar , pVar+4 );
}
void swap_int(unsigned int& intVar )
{
char* pVar = (char*)&intVar;
std::reverse( pVar , pVar+4 );
}
// void swap_short(unsigned short& shortVar)
// {
// char* pVar = (char*)&shortVar;
// std::reverse(pVar,pVar+1);
// }
void swap_int_low2(unsigned int& intVar)//仅仅交换最后两个字节顺序
{
char* pVar = (char*)&intVar;
std::swap( pVar[0] , pVar[1] );
}
#include <QImage>
void GetImageFromData(QImage& img ,unsigned char* data , int width , int height)//获取图片
{
static bool isInitialied = false ;
QVector<QRgb> colorTable ;
//初始化一个 调色板,保证只初始化一次
if(isInitialied == false)
{
colorTable.reserve(256);
for(int i = 0 ; i< 256 ; ++i )
{
colorTable.push_back(qRgb (i,i,i));
}
isInitialied = true;
}
QImage image(data ,width , height ,QImage::Format_Indexed8);
image.setColorTable (colorTable);
img = image.convertToFormat(QImage::Format_RGB32,Qt::AutoColor);
// int b= 0,g= 0,r=0;
// QImage image(width , height ,QImage::Format_RGB32);
// for ( int i = 0;i< height; i++)
// {
// for ( int j = 0;j< width; j++)
// {
// b = (int) *(data + i*width + j);
// g = b;
// r = g;
// image.setPixel(j,i,qRgb(r,g,b));
//
// }
// }
// img = image.copy(0,0,width,height);
}
//获取输入压缩数据类型
QString GetInputCompressDataType()
{
QString res;
QStringList items;
/*items << QObject::tr("Scan-Medium-CompressData") << QObject::tr("Scan-Short-CompressData") << QObject::tr("Gaze-CompressData")
<<QObject::tr("Scan-Medium-ImageLeft") << QObject::tr("Scan-Medium-ImageRight")
<< QObject::tr("Scan-Short-ImageLeft") << QObject::tr("Scan-Short-ImageRight")
<< QObject::tr("Gaze-ImageLeft") << QObject::tr("Gaze-ImageRight");*/
items << QObject::tr("压缩中波扫描数据") << QObject::tr("压缩短波扫描数据") << QObject::tr("压缩凝视相机数据")
<<QObject::tr("扫描前半场中波红外数据") << QObject::tr("扫描后半场中波红外数据")
<< QObject::tr("扫描前半场短波红外数据") << QObject::tr("扫描后半场短波红外数据")
<< QObject::tr("凝视相机短波红外数据")<< QObject::tr("凝视相机中波红外及可见光数据")
<< QObject::tr("压缩直通中波扫描数据")<< QObject::tr("压缩直通短波扫描数据")
<< QObject::tr("压缩直通凝视相机数据");
bool ok;
QString item = QInputDialog::getItem( 0, QObject::tr("获取压缩数据类型"),
QObject::tr("输入压缩数据类型:"), items, 0, false, &ok);
if (ok && !item.isEmpty())
res = item;
return res;
}
//由中文数据类型,转化为英文数据类型 2015-0707
QString GetDataTypeName(QString dataType)
{
QString res;
if ("压缩中波扫描数据" == dataType)
{
res = "Scan-Medium-CompressData";
}
else if ("压缩短波扫描数据" == dataType)
{
res = "Scan-Short-CompressData";
}
else if ("压缩凝视相机数据" == dataType)
{
res = "Gaze-CompressData";
}
else if ("扫描前半场中波红外数据" == dataType)
{
res = "Scan-Medium-ImageLeft";
}
else if ("扫描后半场中波红外数据" == dataType)
{
res = "Scan-Medium-ImageRight";
}
else if ("扫描前半场短波红外数据" == dataType)
{
res = "Scan-Short-ImageLeft";
}
else if ("扫描后半场短波红外数据" == dataType)
{
res = "Scan-Short-ImageRight";
}
else if ("凝视相机短波红外数据" == dataType)
{
res = "Gaze-ImageLeft";
}
else if ("凝视相机中波红外及可见光数据" == dataType)
{
res = "Gaze-ImageRight";
}
else if ("压缩直通中波扫描数据" == dataType)
{
res = "Scan-Medium-ThroughData";
}
else if ("压缩直通短波扫描数据" == dataType)
{
res = "Scan-Short-ThroughData";
}
else if ("压缩直通凝视相机数据" == dataType)
{
res = "Gaze-ThroughData";
}
else
res = "";
return res;
}
QString GetDataTypeCName(QString dataType)
{
QString res;
if ("Scan-Medium-CompressData" == dataType)
{
res = "压缩中波扫描数据";
}
else if ("Scan-Short-CompressData" == dataType)
{
res = "压缩短波扫描数据";
}
else if ("Gaze-CompressData" == dataType)
{
res = "压缩凝视相机数据";
}
else if ("Scan-Medium-ImageLeft" == dataType)
{
res = "扫描前半场中波红外数据";
}
else if ("Scan-Medium-ImageRight" == dataType)
{
res = "扫描后半场中波红外数据";
}
else if ("Scan-Short-ImageLeft" == dataType)
{
res = "扫描前半场短波红外数据";
}
else if ("Scan-Short-ImageRight" == dataType)
{
res = "扫描后半场短波红外数据";
}
else if ("Gaze-ImageLeft" == dataType)
{
res = "凝视相机短波红外数据";
}
else if ("Gaze-ImageRight" == dataType)
{
res = "凝视相机中波红外及可见光数据";
}
else if ("Scan-Medium-ThroughData" == dataType)
{
res = "压缩直通中波扫描数据";
}
else if ("Scan-Short-ThroughData" == dataType)
{
res = "压缩直通短波扫描数据";
}
else if ("Gaze-ThroughtData" == dataType)
{
res = "压缩直通凝视相机数据";
}
else
res = "";
return res;
}
QString GetInputIs12Bit()
{
QString res;
QStringList items;
items << QObject::tr("12bit") << QObject::tr("10bit");
bool ok;
QString item = QInputDialog::getItem(0,QObject::tr("获取图像位数"),
QObject::tr("输入图像位数"),items,0,false,&ok);
if (ok && !item.isEmpty())
res = item;
return res;
}
QString GetInputIsMissRate()
{
QString res;
QStringList items;
items << QObject::tr("不进行误码率对比") << QObject::tr("与直传数据误码率对比") << QObject::tr("与标准源数据误码率对比");
bool ok;
QString item = QInputDialog::getItem(0,QObject::tr("误码率对比"),
QObject::tr("选择是否误码率对比"),items,0,false,&ok);
if (ok&& !item.isEmpty())
{
res = item;
}
return res;
}
//获取离线和回放模式下网络分发速率
QString getNetworkSpeed()
{
QString res;
QStringList items;
items << QObject::tr("600") << QObject::tr("100")<< QObject::tr("20") << QObject::tr("2");
bool ok;
QString item = QInputDialog::getItem(0,QObject::tr("获取分发速率"),
QObject::tr("输入分发速率"),items,0,false,&ok);
if (ok && !item.isEmpty())
res = item;
return res;
}
//获取输出压缩数据类型
QString GetOutputDecompressLeftDataType()
{
QString res;
QStringList items;
items << QObject::tr("Scan-Medium-Left")
<< QObject::tr("Scan-Short-CompressData-Left")
<< QObject::tr("Gaze-CompressData-Short");
bool ok;
QString item = QInputDialog::getItem( 0, QObject::tr("获取输出数据类型"),
QObject::tr("输入输出数据类型:"), items, 0, false, &ok);
if (ok && !item.isEmpty())
res = item;
return res;
}
QString GetOutputDecompressRightDataType()
{
QString res;
QStringList items;
items << QObject::tr("Scan-Medium-Right")
<< QObject::tr("Scan-Short-CompressData-Right")
<< QObject::tr("Gaze-CompressData-Visual-Medium");
bool ok;
QString item = QInputDialog::getItem( 0, QObject::tr("获取输出数据类型"),
QObject::tr("输入输出数据类型:"), items, 0, false, &ok);
if (ok && !item.isEmpty())
res = item;
return res;
}
void MakeRawPic4Test(const QString& fileName , int width , int height )
{
int size = width*height;
unsigned short * pData = new unsigned short[size];
for(int i = 0 ;i<size;++i)
pData[i] = qrand()%256;
SaveBinDataToFile(fileName , pData , size*sizeof(unsigned short));
delete [] pData;
}
#include <algorithm>
//int method_cvt ;
//
//0 高八位
//1 低八位
//2 最大最小值量化
//3 固定值量化
//void LoadRawPic4Test(const QString& fileName , int width , int height ,QImage& img , int method_cvt /*= 0*/)
void LoadRawPic4Test(unsigned char* data, unsigned char* CharData, int width, int height, QImage& img, bool is12bit, QString dataType,int method_cvt /*=0*/ ) //新改写一下函数,第一个参数为内存
{
// QByteArray rawData = GetBinDataFromFile(fileName);
// unsigned short* pData = (unsigned short*)rawData.constData();
unsigned short* pData = (unsigned short*)data;
unsigned char* pCharData = CharData; // 从参数传进来的指针,比在函数里面用New申请堆空间要好。不然容易造成很多碎片
int shortsize = sizeof(short);
int temp;
unsigned int SamplingRate =1;
switch(method_cvt)
{
case 1:
{
for(int h = 0 ; h< height ; ++h)
for(int w = 0; w<width ; ++w)
pCharData[h*width+w] = pData[h*width+w]&255;
}
break;
case 2:
{
unsigned shortMin = 50 , shortMax = 1000;
shortMin = *(std::min_element(pData , pData+width*height ));
shortMax = *(std::max_element(pData , pData+width*height ));
for(int h = 0 ; h< height ; ++h)
for(int w = 0; w<width ; ++w)
pCharData[h*width+w] =
float(pData[h*width+w] - shortMin)*255/(shortMax-shortMin);
}
break;
case 3:
{
for(int h = 0 ; h< height ; ++h)
for(int w = 0; w<width ; ++w)
pCharData[h*width+w] = float(pData[h*width+w])*255/1024;
}
break;
default:
if(dataType == "Gaze-CompressData" )
{
SamplingRate = 1;
}
else
{
SamplingRate = 2;
}
//当图像类型为扫描图像时,由于图像过大,在这里进行采样。
for(int h = 0 ; h < height /SamplingRate; h++)
for(int w = 0; w < width/SamplingRate; w++)
if (is12bit)
{
pCharData[h*width/SamplingRate+w] = (pData[h*SamplingRate*width+w*SamplingRate]&4080)>>4;
}
else
{
pCharData[h*width/SamplingRate+w] = (pData[h*SamplingRate*width+w*SamplingRate]&1020)>>2;
}
width = width/SamplingRate;
height = height/SamplingRate;
break;
}
GetImageFromData(img , pCharData , width , height);
// delete [] pCharData;
}
QStringList GetUnderDirFiles(const QString& dirName , const QString& strFilter /*= "*.*"*/)
{
QStringList finalstrlis;
finalstrlis += GetDirFiles(dirName ,strFilter);
QDir dir(dirName);
QStringList dirList = dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot );
for(int i = 0 ; i< dirList.size(); ++i)
{
finalstrlis += GetDirFiles( dir.absoluteFilePath(dirList[i]) , strFilter);
}
return finalstrlis;
}
QStringList GetDirFiles(const QString& dirName , const QString& strFilter /*= "*.*"*/)
{
QStringList strlis;
QDir dir(dirName);
strlis = dir.entryList( QStringList() << strFilter , QDir::Files|QDir::NoSymLinks );
for(int i = 0 ; i< strlis.size(); ++i)
strlis[i] = dir.absoluteFilePath(strlis[i]);
//qDebug() << __FUNCTION__ ;
//qDebug()<< strlis;
return strlis;
}
void startShiftImpl(unsigned char*outBuf,unsigned char* dataBuf,const int& dataLength )
{
unsigned char low4bit;
unsigned char high4bit;
for (int i=0;i< dataLength -1;++i)
{
high4bit = ( dataBuf[i]& 0x0f) << 4;
low4bit = ( dataBuf[i+1]& 0xf0) >> 4;
outBuf[i]=low4bit|high4bit;
}
}
void startShiftImpl(unsigned char*outBuf,unsigned char* dataBuf,int& dataLength,int& index )
{
unsigned char low4bit;
unsigned char high4bit;
for (int i=0;i< dataLength -index;++i)
{
high4bit = ( dataBuf[index-1+i]& 0x0f) << 4;
low4bit = ( dataBuf[index+i]& 0xf0) >> 4;
outBuf[i]=low4bit|high4bit;
}
}
quint64 getDiskFreeSpace(QString driver)
{
LPCTSTR lpcwstrDriver = (LPCWSTR)driver.utf16();
ULARGE_INTEGER liFreeBytesAvailable,liTotalBytes,liTotalFreeBytes;
if (!GetDiskFreeSpaceEx(lpcwstrDriver,&liFreeBytesAvailable,&liTotalBytes,&liTotalFreeBytes))
{
qDebug()<<"ERROR:Call to GetDiskFreeSpaceEx() failed.";
return 0;
}
return (quint64) liTotalFreeBytes.QuadPart/1024/1024/1024;
}
quint64 getDiskSpace(QString driver)
{
LPCTSTR lpcwstrDriver = (LPCWSTR)driver.utf16();
ULARGE_INTEGER liFreeBytesAvailable,liTotalBytes,liTotalFreeBytes;
if (!GetDiskFreeSpaceEx(lpcwstrDriver,&liFreeBytesAvailable,&liTotalBytes,&liTotalFreeBytes))
{
qDebug()<<"ERROR:Call to GetDiskFreeSpaceEx() failed.";
return 0;
}
return (quint64) liTotalBytes.QuadPart/1024/1024/1024;
}
void ComplementDataToFixedSize(QByteArray & data, int size)
{
if (data.size() < size)
{
QByteArray temp;
temp.fill(0x00,size - data.size());
data.append(temp);
}
}