         fprintf(stderr, "Failed to load %s.\n", img_name);
         return -3;
     }
+    w = img_surface->w;
+    h = img_surface->h;
 
     clk = clock();
 
-    size = img_surface->w * img_surface->h * sizeof(uint32_t);
+    size = w * h * sizeof(uint32_t);
     cudaMalloc((void**)&dev_buf, size);
-    host_buf = (uint32_t*)malloc(size);
 
     cudaMemcpy(dev_buf, img_surface->pixels, size, cudaMemcpyHostToDevice);
 
-    block_per_grid.x = img_surface->w / thrd_per_block.x;
-    block_per_grid.y = img_surface->h / thrd_per_block.y;
-    monochrome<<<block_per_grid, thrd_per_block, 0>>>(dev_buf, img_surface->w, img_surface->h);
+    block_per_grid.x = w / thrd_per_block.x;
+    block_per_grid.y = h / thrd_per_block.y;
+    monochrome<<<block_per_grid, thrd_per_block, 0>>>(dev_buf, w, h);
     cudaDeviceSynchronize();
 
     cudaMemcpy(img_surface->pixels, dev_buf, size, cudaMemcpyDeviceToHost);


    printf("*** Time: %f\n", (float)(clock() - clk) / CLOCKS_PER_SEC);

    texture = SDL_CreateTextureFromSurface(renderer, img_surface);
    if (!texture)
    {
        fprintf(stderr, "Couldn't create texture from surface!\n");
        return -1;
    }
    SDL_QueryTexture(texture, NULL, NULL, &w, &h);

    SDL_SetWindowTitle(window, img_name);
    SDL_SetWindowSize(window, w, h);

            }
        }
        draw_background(renderer, w, h);
        SDL_RenderCopy(renderer, img_texture, NULL, NULL);
        SDL_RenderPresent(renderer);

        SDL_Delay(100);
    }

    SDL_FreeSurface(img_surface);
    SDL_DestroyTexture(img_texture);
    SDL_DestroyWindow(window);
    SDL_DestroyRenderer(renderer);
    SDL_Quit();
