#include <stdio.h>
#include <windows.h>
const int image_Size = 256*256;
const unsigned char mask1 = 0xFF;
const unsigned short mask2 = 0xFFFF;
const unsigned int mask4 = 0xFFFFFFFF;
LARGE_INTEGER diff_ticks;
LARGE_INTEGER freq, proc_start, proc_end;
void invertImageC1byte(unsigned char *src, unsigned char *dst);
void invertImageC2byte(unsigned short *src, unsigned short *dst);
void invertImageC4byte(unsigned int *src, unsigned int *dst);
int main()
{
char input[]="gLenna_256_256.raw";
char output[]="result.raw";
unsigned char *src, *dst;
unsigned char *p1;
unsigned short *p2;
unsigned int *p4;
double *p8;
FILE *fin=0, *fout=0;
fin = fopen(input, "rb");
if( !fin )
{
printf("file open error\n");
return 0;
}
src = (unsigned char*)calloc(sizeof(unsigned char)*image_Size, 1);
dst = (unsigned char*)calloc(sizeof(unsigned char)*image_Size, 1);
p1 = src;
p2 = src;
p4 = src;
p8 = src;
fread(src, sizeof(unsigned char), image_Size, fin);
fclose(fin);
QueryPerformanceCounter(&proc_start);
//////////////////
invertImageC1byte(p1, dst);
// invertImageC2byte(p2, dst);
// invertImageC4byte(p4, dst);
// invertImageC8byte(p8, dst);
//////////////////
QueryPerformanceCounter(&proc_end);
QueryPerformanceFrequency(&freq);
diff_ticks.QuadPart = (proc_end.QuadPart - proc_start.QuadPart);
fprintf(stdout, "Elapsed CPU time : %.12f sec \n\n", ((double)diff_ticks.QuadPart/(double)freq.QuadPart));
fout = fopen(output, "wb");
fwrite(dst, sizeof(unsigned char), image_Size, fout);
fclose(fout);
return 0;
}
void invertImageC1byte(unsigned char *p1, unsigned char *dst)
{
int i;
printf("1byte \n");
for(i=0; i<image_Size; i++)
dst[i] = p1[i] ^ mask1;
}
void invertImageC2byte(unsigned short *p2, unsigned short *dst)
{
int i;
int end = image_Size >>1;
printf("2byte \n");
for(i=0; i<end; i++)
dst[i] = p2[i] ^ mask2;
}
void invertImageC4byte(unsigned int *p4, unsigned int *dst)
{
int i;
int end = image_Size >>2;
printf("4byte \n");
for(i=0; i<end; i++)
dst[i] = p4[i] ^ mask4;
}
void invertImageAsm1byte(unsigned char *src, unsigned char *dst)
{
printf("1byte Asm\n");
__asm
{
mov esi, src
mov edi, dst
mov ecx, image_Size
L1:
mov al, [esi]
xor al, mask1
mov [edi], al
add esi, 1
add edi, 1
loop L1
}
}
void invertImageAsm2byte(unsigned short *src, unsigned short *dst)
{
printf("2byte Asm\n");
__asm
{
mov esi, src
mov edi, dst
mov ecx, image_Size
L1:
mov ax, [esi]
xor ax, mask2
mov [edi], ax
add esi, 1
add edi, 1
loop L1
}
}
void invertImageAsm4byte(unsigned int *src, unsigned int *dst)
{
printf("4byte Asm\n");
__asm
{
mov esi, src
mov edi, dst
mov ecx, image_Size
shr ecx, 2
L1:
mov eax, [esi]
xor eax, mask4
mov [edi], eax
add esi, 4
add edi, 4
loop L1
}
}
댓글 없음:
댓글 쓰기