chundoong-lab-ta/APWS23/image-rotation-skeleton/main.cpp

63 lines
1.9 KiB
C++

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "image_rotation.h"
#include "util.h"
int main(int argc, char *argv[]) {
if (argc < 3) {
printf("Usage: %s <src file> <rotation degree>\n", argv[0]);
exit(EXIT_FAILURE);
}
char cpu_ofname[64], gpu_ofname[64];
char ifname[64], ifname_trimmed[64];
strcpy(ifname, argv[1]);
strcpy(ifname_trimmed, ifname);
ifname_trimmed[strlen(ifname_trimmed) - 4] = 0;
int deg = atoi(argv[2]);
float theta = (float) deg / 180.0 * M_PI;
float sin_theta = sinf(theta);
float cos_theta = cosf(theta);
int image_width, image_height;
double cpu_st, cpu_en, gpu_st, gpu_en;
float *input_image = readImage(argv[1], &image_width, &image_height);
float *output_image_cpu =
(float *) malloc(sizeof(float) * image_width * image_height);
float *output_image_gpu =
(float *) malloc(sizeof(float) * image_width * image_height);
printf("Image size: %d x %d\n", image_width, image_height);
cpu_st = get_current_time();
rotate_image_cpu(input_image, output_image_cpu, image_width, image_height,
sin_theta, cos_theta);
cpu_en = get_current_time();
rotate_image_gpu_initialize(image_width, image_height);
gpu_st = get_current_time();
rotate_image_gpu(input_image, output_image_gpu, image_width, image_height,
sin_theta, cos_theta);
gpu_en = get_current_time();
rotate_image_gpu_finalize();
printf("Image rotation done!\n");
sprintf(cpu_ofname, "%s_%d_cpu.bmp", ifname_trimmed, deg);
sprintf(gpu_ofname, "%s_%d_gpu.bmp", ifname_trimmed, deg);
printf("CPU elapsed time: %.5f sec\n", cpu_en - cpu_st);
printf("GPU elapsed time: %.5f sec\n", gpu_en - gpu_st);
storeImage(output_image_cpu, cpu_ofname, image_height, image_width, argv[1]);
storeImage(output_image_gpu, gpu_ofname, image_height, image_width, argv[1]);
return 0;
}