8 #include "Convolution.h"
10 const float Convolution::kernel[9][9] =
11 {{0.0828, 0.1987, 0.3705, 0.5366, 0.6063, 0.5366, 0.3705, 0.1987, 0.0828},
12 {0.1987, 0.4746, 0.8646, 1.1794, 1.2765, 1.1794, 0.8646, 0.4746, 0.1987},
13 {0.3705, 0.8646, 1.3475, 1.0033, 0.4061, 1.0033, 1.3475, 0.8646, 0.3705},
14 {0.5366, 1.1794, 1.0033, -2.8306, -6.4829, -2.8306, 1.0033, 1.1794, 0.5366},
15 {0.6063, 1.2765, 0.4061, -6.4829, -12.7462, -6.4829, 0.4061, 1.2765, 0.6063},
16 {0.5366, 1.1794, 1.0033, -2.8306, -6.4829, -2.8306, 1.0033, 1.1794, 0.5366},
17 {0.3705, 0.8646, 1.3475, 1.0033, 0.4061, 1.0033, 1.3475, 0.8646, 0.3705},
18 {0.1987, 0.4746, 0.8646, 1.1794, 1.2765, 1.1794, 0.8646, 0.4746, 0.1987},
19 {0.0828, 0.1987, 0.3705, 0.5366, 0.6063, 0.5366, 0.3705, 0.1987, 0.0828}};
21 Convolution::Convolution(int w, int h) :
27 Device::assertDim(dg, db);
29 // Allocation de la mémoire sur le GPU dédié à l'image source et bind avec la textue.
30 HANDLE_ERROR(cudaMalloc(&this->ptrDevImageSource, this->w * this->h * sizeof(uchar4)));
31 bindSouceAsTexture(this->ptrDevImageSource, this->w, this->h);
33 // Copie du kernel en constant memory.
34 ConstantMemoryLink cmKernelLink = constantMemoryKernelLink();
35 float* ptrDevKernel = (float*)cmKernelLink.ptrDevTab;
36 size_t sizeALL = cmKernelLink.sizeAll;
37 HANDLE_ERROR(cudaMemcpy(ptrDevKernel, kernel, sizeALL, cudaMemcpyHostToDevice));
40 Convolution::~Convolution()
42 unbindSouceAsTexture();
43 HANDLE_ERROR(cudaFree(this->ptrDevImageSource));
46 void Convolution::runGPU(uchar4* ptrDevPixels)
48 // Copie l'image donnée dans l'image source. La convolution sera effectuée de 'ptrImageSource' vers 'ptrDevPixels'.
49 HANDLE_ERROR(cudaMemcpy(this->ptrDevImageSource, ptrDevPixels, this->w * this->h * sizeof(uchar4), cudaMemcpyDeviceToDevice));
51 toGrayscale<<<dg,db>>>(this->ptrDevImageSource, this->w, this->h);
53 cudaDeviceSynchronize(); // Attend que toute l'image source ait été passée en niveau de gris.
54 convolution<<<dg,db>>>(ptrDevPixels, this->w, this->h);
56 //HANDLE_ERROR(cudaDeviceSynchronize()); // Pour flusher les 'printf' (pour le DEBUG).
59 void Convolution::animationStep()
61 this->t += 0.1; // TODO.
64 int Convolution::getW()
69 int Convolution::getH()
74 float Convolution::getT()
79 string Convolution::getTitle()