1

I want to convert (try to set red channel to 0) gstreamer buffer using cuda. There is a snippet of code:

__global__ void transform( guint8 *data, int width ){
  uint x = (blockIdx.x * blockDim.x) + threadIdx.x;
  uint y = (blockIdx.y * blockDim.y) + threadIdx.y;
  uint pixPos = (y * width + x) * 4;
  data[pixPos + 2] = 0; // BGRA format
}

void simple_transform( guint8 *data, int width, int height ){
  guint8 *d_data;
  guint8 size = width * height * 4;

  checkCudaErrors( cudaMalloc( (void**)&d_data, size ) );
  // copy original buffer into device
  checkCudaErrors( cudaMemcpy( d_data, data, size, cudaMemcpyHostToDevice ) );

  dim3 threads = dim3(8, 8);
  dim3 blocks = dim3(width / threads.x, height / threads.y);

  // execute kernel
  transform<<< blocks, threads >>>( d_data, width );

  // move back converted data to original buffer
  checkCudaErrors( cudaMemcpy( data, d_data, size, cudaMemcpyDeviceToHost ) );

  cudaFree( d_data );
}

The problem is that video shows without any changes. I want to see blue-green picture, but can't. Where is my mistake?

4

1 回答 1

3

You are assigning the total size of the image to a variable of type guint8

guint8 size = width * height * 4;

This is able to accommodate values up to 255 only. Size must be assigned to a variable of larger data type (say size_t).

size_t size = width * height * 4;
于 2013-07-15T17:41:14.870 回答