#include <stdio.h>
#include <stdlib.h>
#pragma pack(push, 1)
typedef struct {
unsigned short bfType;
unsigned int bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
unsigned int bfOffBits;
} BITMAPFILEHEADER;
typedef struct {
unsigned int biSize;
unsigned int biWidth;
unsigned int biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned int biCompression;
unsigned int biSizeImage;
unsigned int biXPelsPerMeter;
unsigned int biYPelsPerMeter;
unsigned int biClrUsed;
unsigned int biClrImportant;
} BITMAPINFOHEADER;
#pragma pack(pop)
// C6000兼容的周期计数函数
unsigned long long get_cycle_count() {
unsigned int tsch, tscl;
asm(" mvc .s2 TSCH, %0" : "=r"(tsch));
asm(" mvc .s2 TSCL, %0" : "=r"(tscl));
return ((unsigned long long)tsch << 32) | tscl;
}
int main(void) {
const int width = 768, height = 576;
const int sizeImage = width * height * 3;
const int iterations = 1000;
const char *src1_path = "HazyDay1.bmp";
const char *src2_path = "HazyDay2.bmp";
const char *dst_path = "jieguo.bmp";
printf("Starting image processing on C6000 DSP...\n");
printf("Image size: %dx%d, Iterations: %d\n", width, height, iterations);
FILE *src1 = fopen(src1_path, "rb");
FILE *src2 = fopen(src2_path, "rb");
FILE *dst = fopen(dst_path, "wb");
if (!src1 || !src2 || !dst) {
printf("Error opening files\n");
if (src1) fclose(src1);
if (src2) fclose(src2);
if (dst) fclose(dst);
return -1;
}
BITMAPFILEHEADER fileHeader;
BITMAPINFOHEADER infoHeader;
if (fread(&fileHeader, sizeof(BITMAPFILEHEADER), 1, src1) != 1 ||
fread(&infoHeader, sizeof(BITMAPINFOHEADER), 1, src1) != 1) {
printf("Error reading BMP headers\n");
fclose(src1);
fclose(src2);
fclose(dst);
return -1;
}
unsigned char *img1 = (unsigned char *)malloc(sizeImage);
unsigned char *img2 = (unsigned char *)malloc(sizeImage);
unsigned char *result = (unsigned char *)malloc(sizeImage);
if (!img1 || !img2 || !result) {
printf("Memory allocation failed\n");
free(img1);
free(img2);
free(result);
fclose(src1);
fclose(src2);
fclose(dst);
return -1;
}
fseek(src1, fileHeader.bfOffBits, SEEK_SET);
fseek(src2, fileHeader.bfOffBits, SEEK_SET);
fread(img1, 1, sizeImage, src1);
fread(img2, 1, sizeImage, src2);
unsigned long long start_cycles, end_cycles;
double total_time_3ch = 0, total_time_1ch = 0;
int i, iter;
// ================= 三通道同时处理 =================
printf("Running 3-channel method...\n");
start_cycles = get_cycle_count();
for (iter = 0; iter < iterations; iter++) {
unsigned char *p1 = img1;
unsigned char *p2 = img2;
unsigned char *res = result;
for (i = 0; i < sizeImage; i++) {
*res++ = (*p1++ + *p2++) >> 1;
}
}
end_cycles = get_cycle_count();
total_time_3ch = (double)(end_cycles - start_cycles);
// ================= 单通道分别处理 =================
printf("Running 1-channel method...\n");
start_cycles = get_cycle_count();
for (iter = 0; iter < iterations; iter++) {
for (i = 0; i < sizeImage; i += 3) {
result[i] = (img1[i] + img2[i]) >> 1;
result[i+1] = (img1[i+1] + img2[i+1]) >> 1;
result[i+2] = (img1[i+2] + img2[i+2]) >> 1;
}
}
end_cycles = get_cycle_count();
total_time_1ch = (double)(end_cycles - start_cycles);
// 输出结果
printf("\nProcessing Time Comparison (after %d iterations):\n", iterations);
printf("3-Channel Method:\n");
printf(" Total cycles: %.0f\n", total_time_3ch);
printf(" Average cycles: %.0f\n", total_time_3ch/iterations);
printf("1-Channel Method:\n");
printf(" Total cycles: %.0f\n", total_time_1ch);
printf(" Average cycles: %.0f\n", total_time_1ch/iterations);
if (total_time_1ch > 0 && total_time_3ch > 0) {
double improvement = (total_time_1ch - total_time_3ch) / total_time_1ch * 100;
printf("Efficiency Improvement: %.2f%% (%s method is faster)\n",
fabs(improvement),
improvement > 0 ? "3-channel" : "1-channel");
}
// 写入结果
fwrite(&fileHeader, sizeof(BITMAPFILEHEADER), 1, dst);
fwrite(&infoHeader, sizeof(BITMAPINFOHEADER), 1, dst);
fseek(dst, fileHeader.bfOffBits, SEEK_SET);
fwrite(result, 1, sizeImage, dst);
// 释放资源
free(img1);
free(img2);
free(result);
fclose(src1);
fclose(src2);
fclose(dst);
return 0;
}
为什么有下面的报错
**** Build of configuration Debug for project lab_03_app ****
"G:\\ccs\\CCS5.5.0.00077_win32\\ccsv5\\utils\\bin\\gmake" -k all
'Building file: ../main.c'
'Invoking: C6000 Compiler'
"G:/ccs/CCS5.5.0.00077_win32/ccsv5/tools/compiler/c6000_7.4.4/bin/cl6x" -mv6740 --abi=coffabi -g --include_path="G:/ccs/CCS5.5.0.00077_win32/ccsv5/tools/compiler/c6000_7.4.4/include" --display_error_number --diag_warning=225 --diag_wrap=off --preproc_with_compile --preproc_dependency="main.pp" "../main.c"
"../main.c", line 31: error #18: expected a ")"
"../main.c", line 32: error #18: expected a ")"
"../main.c", line 33: warning #551-D: variable "tsch" is used before its value is set
"../main.c", line 33: warning #551-D: variable "tscl" is used before its value is set
2 errors detected in the compilation of "../main.c".
>> Compilation failure
gmake: *** [main.obj] Error 1
gmake: Target `all' not remade because of errors.
**** Build Finished ****
最新发布