说我有一个二进制文件; 它包含正二进制数,但以小端编写为32位整数
我该如何阅读此文件?我现在有这个.
int main() {
FILE * fp;
char buffer[4];
int num = 0;
fp=fopen("file.txt","rb");
while ( fread(&buffer, 1, 4,fp) != 0) {
// I think buffer should be 32 bit integer I read,
// how can I let num equal to 32 bit little endian integer?
}
// Say I just want to get the sum of all these binary little endian integers,
// is there an another way to make read and get sum faster …Run Code Online (Sandbox Code Playgroud) 在关于将RGB转换为RGBA和ARGB转换为BGR的一些先前问题的后续内容中,我想通过SSE加速RGB到BGRA的转换.假设一台32位机器,并想使用内在函数.我很难将源缓冲区和目标缓冲区对齐以使用128位寄存器,并寻求其他精明的矢量化解决方案.
矢量化的例程如下......
void RGB8ToBGRX8(int w, const void *in, void *out)
{
int i;
int width = w;
const unsigned char *src= (const unsigned char*) in;
unsigned int *dst= (unsigned int*) out;
unsigned int invalue, outvalue;
for (i=0; i<width; i++, src+=3, dst++)
{
invalue = src[0];
outvalue = (invalue<<16);
invalue = src[1];
outvalue |= (invalue<<8);
invalue = src[2];
outvalue |= (invalue);
*dst = outvalue | 0xff000000;
}
}
Run Code Online (Sandbox Code Playgroud)
这个例程主要用于大纹理(512KB),所以如果我可以并行化一些操作,那么一次处理更多像素可能是有益的.当然,我需要介绍一下.:)
编辑:
我的编译论据......
gcc -O2 main.c
Run Code Online (Sandbox Code Playgroud)