Hi,
Here is a patch for applying alpha blending to NvBuffer:
diff --git a/multimedia_api/ll_samples/samples/12_camera_v4l2_cuda/camera_v4l2_cuda.cpp b/multimedia_api/ll_samples/samples/12_camera_v4l2_cuda/camera_v4l2_cuda.cpp
index 6aed080..b79912c 100644
--- a/multimedia_api/ll_samples/samples/12_camera_v4l2_cuda/camera_v4l2_cuda.cpp
+++ b/multimedia_api/ll_samples/samples/12_camera_v4l2_cuda/camera_v4l2_cuda.cpp
@@ -45,6 +45,7 @@
#include "camera_v4l2_cuda.h"
static bool quit = false;
+static int inter_fd = 0;
using namespace std;
@@ -374,12 +375,14 @@ prepare_buffers(context_t * ctx)
}
- input_params.colorFormat = get_nvbuff_color_fmt(V4L2_PIX_FMT_YUV420M);
+ input_params.colorFormat = NvBufferColorFormat_ABGR32;
input_params.nvbuf_tag = NvBufferTag_NONE;
// Create Render buffer
if (-1 == NvBufferCreateEx(&ctx->render_dmabuf_fd, &input_params))
ERROR_RETURN("Failed to create NvBuffer");
+ NvBufferCreateEx(&inter_fd, &input_params);
+
if (!request_camera_buff(ctx))
ERROR_RETURN("Failed to set up camera buff");
@@ -485,7 +488,10 @@ start_capture(context_t * ctx)
cuda_postprocess(ctx, ctx->render_dmabuf_fd);
- ctx->renderer->render(ctx->render_dmabuf_fd);
+ NvBufferTransform(ctx->render_dmabuf_fd, inter_fd,
+ &transParams);
+
+ ctx->renderer->render(inter_fd);
// Enqueue camera buff
if (ioctl(ctx->cam_fd, VIDIOC_QBUF, &v4l2_buf))
diff --git a/multimedia_api/ll_samples/samples/common/algorithm/cuda/NvAnalysis.cu b/multimedia_api/ll_samples/samples/common/algorithm/cuda/NvAnalysis.cu
index e96be22..d37d231 100644
--- a/multimedia_api/ll_samples/samples/common/algorithm/cuda/NvAnalysis.cu
+++ b/multimedia_api/ll_samples/samples/common/algorithm/cuda/NvAnalysis.cu
@@ -31,16 +31,23 @@
#define BOX_W 32
#define BOX_H 32
+#define DEMO_H 256
__global__ void
addLabelsKernel(int *pDevPtr, int pitch)
{
- int row = blockIdx.y * blockDim.y + threadIdx.y + BOX_H;
- int col = blockIdx.x * blockDim.x + threadIdx.x + BOX_W;
- char *pElement = (char *)pDevPtr + row * pitch + col;
-
- pElement[0] = 0;
-
+ int row = blockIdx.y*blockDim.y + threadIdx.y;
+ int col = blockIdx.x*blockDim.x + threadIdx.x;
+ if (col <= (pitch/2) && row <= (DEMO_H/2) && (col % 4) == 3) {
+ char * pElement = (char*)pDevPtr + row * pitch + col;
+ pElement[0] = (char)223;
+ } else if (col <= pitch && row <= (DEMO_H/2) && (col % 4) == 3) {
+ char * pElement = (char*)pDevPtr + row * pitch + col;
+ pElement[0] = (char)63;
+ } else if (col <= pitch && row <= DEMO_H && (col % 4) == 3) {
+ char * pElement = (char*)pDevPtr + row * pitch + col;
+ pElement[0] = (char)191;
+ }
return;
}
@@ -48,7 +55,7 @@ int
addLabels(CUdeviceptr pDevPtr, int pitch)
{
dim3 threadsPerBlock(BOX_W, BOX_H);
- dim3 blocks(1,1);
+ dim3 blocks(pitch/BOX_W+1,DEMO_H/BOX_H+1);
addLabelsKernel<<<blocks,threadsPerBlock>>>((int *)pDevPtr, pitch);
You should see the effect by running the command:
12_camera_v4l2_cuda$ ./camera_v4l2_cuda -d /dev/video0 -s 640x480 -f UYVY -c
Please check if you can follow this method to modify alpha channel through CUDA.