Skip to content
Snippets Groups Projects
Commit 3f84511c authored by dansa828's avatar dansa828
Browse files

update

parent 2e6d1189
Branches
No related tags found
No related merge requests found
......@@ -35,7 +35,7 @@
__global__ void filter(unsigned char *image, unsigned char *out, const unsigned int imagesizex, const unsigned int imagesizey, const int kernelsizex, const int kernelsizey)
{
{
// map from blockIdx to pixel position
int x = blockIdx.x * blockDim.x + threadIdx.x;
int y = blockIdx.y * blockDim.y + threadIdx.y;
......@@ -44,18 +44,18 @@ __global__ void filter(unsigned char *image, unsigned char *out, const unsigned
unsigned int sumx, sumy, sumz;
int divby = (2*kernelsizex+1)*(2*kernelsizey+1); // Works for box filters only!
if (x < imagesizex && y < imagesizey) // If inside image
{
// Filter kernel (simple box filter)
sumx=0;sumy=0;sumz=0;
for(dy=-kernelsizey;dy<=kernelsizey;dy++)
for(dx=-kernelsizex;dx<=kernelsizex;dx++)
for(dx=-kernelsizex;dx<=kernelsizex;dx++)
{
// Use max and min to avoid branching!
int yy = min(max(y+dy, 0), imagesizey-1);
int xx = min(max(x+dx, 0), imagesizex-1);
sumx += image[((yy)*imagesizex+(xx))*3+0];
sumy += image[((yy)*imagesizex+(xx))*3+1];
sumz += image[((yy)*imagesizex+(xx))*3+2];
......@@ -101,7 +101,7 @@ void computeImages(int kernelsizex, int kernelsizey)
// Display images
void Draw()
{
// Dump the whole picture onto the screen.
// Dump the whole picture onto the screen.
glClearColor( 0.0, 0.0, 0.0, 1.0 );
glClear( GL_COLOR_BUFFER_BIT );
......@@ -123,7 +123,7 @@ void Draw()
}
// Main program, inits
int main( int argc, char** argv)
int main( int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_SINGLE | GLUT_RGBA );
......@@ -143,7 +143,7 @@ int main( int argc, char** argv)
ResetMilli();
computeImages(2, 2);
printf("%s%f\n","Measured time (ms): ", (float)GetMicroseconds()*0.001);
// You can save the result to a file like this:
// writeppm("out.ppm", imagesizey, imagesizex, pixels);
......
......@@ -172,8 +172,8 @@ int main( int argc, char** argv)
ResetMilli();
computeImages(2, 2);
computeImages(3, 3);
printf("%s%f\n","Measured time (ms): ", (float)GetMicroseconds()*0.001);
// You can save the result to a file like this:
// writeppm("out.ppm", imagesizey, imagesizex, pixels);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment