This line gives you a pointer to the pixel buffer in the Bitmap:
    if ((ret = AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) {

Then you pass it into your drawing method:
    fill_plasma(&info, pixels );

void fill_plasma( AndroidBitmapInfo*  info, unsigned char*  pxl )

Then you allocate, at the C level, a completely different buffer:
    unsigned char* buf = (unsigned char* )malloc(pvideoBuff->framesizeIn);

Then you compress your capture buffer into jpeg data (a compressed image 
format, not a bitmap buffer) into that temporary buffer:
compress_yuyv_to_jpeg(pvideoBuff, buf, pvideoBuff->framesizeIn, 80, pvideoBuff->formatIn); //method to convert raw data into jpeg format- Quiet popular code on the

Then you overwrite the temporary parameter variable pxl with the address of the 
resulting buffer.

You never got around to changing the bytes in the Bitmap buffer that you locked and unlocked. And even if you had, you were working with Jpeg compressed data that would have been garbage as a Bitmap. Bitmaps are simple arrays of bytes representing uncompressed pixels. Additionally, malloc() allocated data is not something you pass back to Java to manage. You should copy into Java-allocated buffers.

If the capture buffer is the same size as the bitmap, you simply need to map each pixel using yuv->RGB formulas. If they are different sizes, you need to resize the image too. There are fast built-in methods to do this well, but basically you create a pixel from a weighted average in color space of the pixels that the resulting pixel overlaps.

sdw

On 12/17/11 10:59 AM, s.rawat wrote:
HI,
I have been trying hard from past four nights to get this thing work but so far not able to do that.I have taken and modified few of the code from the ndk-sample(in the samples directory in the ndk r7) for plasma -sample for passing and mapping the bitmap from the JNI.
Following is my code snippet :


*Android : *

#this code is running in a thread

       Bitmap   mBitmap = Bitmap.createBitmap(320,240, Bitmap.Config.RGB_565);
       renderPlasma(mBitmap);

#this code is running in a thread

*Native : *

Java_<my_package_name>_DrawCanvas_renderPlasma(JNIEnv * env, jobject  obj, 
jobject bitmap)
{
    AndroidBitmapInfo  info;
    unsigned char**    pixels;
    int                ret =10;


    if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) {

        return;
    }

    if (info.format != ANDROID_BITMAP_FORMAT_RGB_565) {

        return;
    }

    if ((ret = AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) {
        return;

    }


    /* Now fill the values with a nice little plasma */
    fill_plasma(&info, pixels );

AndroidBitmap_unlockPixels(env, bitmap);//i am hoping that the bitmap has been mapped to the contents of "pixel" at this point.

}

struct vdIn *pvideoBuff = 0;//v4l2 structure which contains the raw YUV data
void fill_plasma( AndroidBitmapInfo*  info, unsigned char*  pxl )
{
    unsigned char* buf = (unsigned char* )malloc(pvideoBuff->framesizeIn);
    uvc_startCapture(pvideoBuff);//v4l2 function which returns the raw yuc data 
form the uvc compliant webcamera
compress_yuyv_to_jpeg(pvideoBuff, buf, pvideoBuff->framesizeIn, 80, pvideoBuff->formatIn); //method to convert raw data into jpeg format- Quiet popular code on the web
    pxl = &buf;//i am thinking the pxl will have now all the contents of the 
jpeg converted buffer

}

//the bitmap being returned from the native code has to be drawn on the bitmap 
continuously.
canvas.drawBitmap(mBitmap, 0,0, null);

I suspect that pixel being a 2D array , I have to assisgn each array elements from the buf.Plz correct me or slap a rockstar reply to this problem.
Best Rgds and Thanks in advance
Softy


"..pain is temporary.....quitting lasts forever......"

--
You received this message because you are subscribed to the Google Groups 
"android-ndk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/android-ndk?hl=en.

--
You received this message because you are subscribed to the Google Groups "Android 
Discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/android-discuss?hl=en.

<<image/gif>>

Reply via email to