Need help in bicubic filter RGBA bicubic filter based on NVIDIA CUDA SDK Sample

Hello!

Can anybody help to newbie?

Trying create video mixer.

I receive few raw images (for example from few web cameras) in format RGBARGBA…RGBA

I need to create internal resulting buffer and place RESIZED AND FILTERED by bicubic method received images in it.

After that need get RESIZED AND FILTERED internal buffer in format RGBARGBA…RGBA too.

I tried to append NVIDIA CUDA SDK bicubic texture sample to work with RGBA images:

[codebox]T cubicFilter(float x, T c0, T c1, T c2, T c3)

{

float4 ret;

ret.x=c0.x*w0(x);

ret.x+=c1.x*w1(x);

ret.x+=c2.x*w2(x);

ret.x+=c3.x*w3(x);

ret.y=c0.y*w0(x);

ret.y+=c1.y*w1(x);

ret.y+=c2.y*w2(x);

ret.y+=c3.y*w3(x);

ret.z=c0.z*w0(x);

ret.z+=c1.z*w1(x);

ret.z+=c2.z*w2(x);

ret.z+=c3.z*w3(x);

// T r;

// r = c0 * w0(x);

// r += c1 * w1(x);

// r += c2 * w2(x);

// r += c3 * w3(x);

return ret;

}[/codebox]

My texture in format

texture<uchar4, 2, cudaReadModeNormalizedFloat> tex;

Then i make resizing and bicubic filtration:

[codebox]template<class T, class R> // return type, texture type

device

R tex2DBicubic(const texture<T, 2, cudaReadModeNormalizedFloat> texref, float x, float y)

{

x -= 0.5f;

y -= 0.5f;

float px = floor(x);

float py = floor(y);

float fx = x - px;

float fy = y - py;

return cubicFilter(fy,

                      cubicFilter<R>(fx, tex2D(texref, px-1, py-1), tex2D(texref, px, py-1), tex2D(texref, px+1, py-1), tex2D(texref, px+2,py-1)),

                      cubicFilter<R>(fx, tex2D(texref, px-1, py),   tex2D(texref, px, py),   tex2D(texref, px+1, py),   tex2D(texref, px+2, py)),

                      cubicFilter<R>(fx, tex2D(texref, px-1, py+1), tex2D(texref, px, py+1), tex2D(texref, px+1, py+1), tex2D(texref, px+2, py+1)),

                      cubicFilter<R>(fx, tex2D(texref, px-1, py+2), tex2D(texref, px, py+2), tex2D(texref, px+1, py+2), tex2D(texref, px+2, py+2))

                      );

}[/codebox]

… And copying to resulted image:

[codebox]extern “C”

void SetIncomingFrame(uchar4 *InputData, int SourceWidth, int SourceHeight, int TargetWidth, int TargetHeight, int X, int Y, cudaArray *ConferenceArray)

{

cudaArray *SourceImageArray = 0;

uchar4 *InternalBuffer = 0;



cutilSafeCall(cudaMalloc((void**)&InternalBuffer,TargetWidth*TargetHeight*4)); //ForTest

cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(8, 8, 8, 8, cudaChannelFormatKindUnsigned);

cutilSafeCall(cudaMallocArray(&SourceImageArray,&channelDesc,SourceWidth,SourceHeight));

cutilSafeCall(cudaMemcpyToArray(SourceImageArray,0,0,InputDa

ta,SourceWidthSourceHeightsizeof(uchar4),cudaMemcpyHostToDe

vice));

cutilSafeCall(cudaBindTextureToArray(tex,SourceImageArray,ch

annelDesc));

RenderInputFrame(InternalBuffer,0,SourceWidth,SourceHeight,T

argetWidth,TargetHeight);

cutilSafeCall(cudaThreadSynchronize());

cutilSafeCall(cudaMemcpy2DToArray(ConferenceArray,X,Y,Intern

alBuffer,TargetWidth*sizeof(uchar4),TargetWidth,TargetHeight,

cudaMemcpyDeviceToDevice));

cutilSafeCall(cudaFree(InternalBuffer));

//cutilSafeCall(cudaFree(SourceImageArray));

//cutilSafeCall(cudaMemcpy(InputData,InternalBuffer,352*288*4,

cudaMemcpyDeviceToHost));

}[/codebox]

(RenderInputFrame is a kernel calling function like d_render in SDK)

Result: Black screen.

What i doing incorrect? Please help to understand! :"> :wacko:

Your code looks correct as far as I can tell. Did you change the display code to handle rgba data also? This could cause a black screen.

Thanks for reply, Simon! External Media

Shure. But i already solve my plroblem. There was a problem in converting float4 to uchar4 after resizing an image. Now I translating float[4] to uint and its works.

Now I Have another problem. I need to insert resized image into resulting image. Strange, but it seems to me MemCpy2D cannot help me. It seems to me that two parameters in offset not using to place picture

in position in resulting picture thet I need.

Anybody have idea? :unsure: