Drawing Images in Native Window in NDK

1,803 views
Skip to first unread message

vijayasarathy m

unread,
Mar 21, 2013, 6:54:14 AM3/21/13
to andro...@googlegroups.com

Dear all,

I need a help in Drawing Images in ANativeWindow in NDK.

I am trying to draw a 320 * 240 image in ANativeWindow in NDK using below code.

ANativeWindow_setBuffersGeometry(player.nativeWindow, 320, 240, WINDOW_FORMAT_RGB_565) ;  // Called only once

The above code is called only once in the init function.
The Window is passed from application as a surface. The Surface is OpenGLSurface in Application

In a thread, below code is used to draw on Native Window

ANativeWindow_acquire(nativeWindow);
if(ANativeWindow_lock(nativeWindow,&outBuffer,NULL) < 0)
{
LOGE("Native Window Lock Failed....");
return -1;
}
memcpy(outBuffer.bits,frame->data,320*240*2);
if(ANativeWindow_unlockAndPost(is->nativeWindow) < 0)
{
    LOGE("Native Window unlock and post failed");
}
return;

But the image that is being drawn on the device is not full.It looks like a zoomed Image.It is drawing only a part of the image.
Whereas when I dump the frame that is being copied to Native Window Outbuffer, the image is perfect as 320*240 image


The App is Run in Landscape Mode. The Display size is 800 * 480. The Open GL Surface Dimension is 320 * 240.

Please let me know, whether I am missing something or Its a bug in ANativeWindow.

Thanks & Regards
Vijayasarathy.M


Ken Turkowski

unread,
Mar 23, 2013, 9:40:19 PM3/23/13
to andro...@googlegroups.com
There are a couple of things that could be happening:
(1) Just because you ask for a window with format RGB565 doesn't mean that you will get it. With GL, at least, you will get something that is compatible with it.
(2) The Y stride is probably not 640 bytes; with the display being 800 pixels wide, the stride could well be 1600 bytes.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-ndk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

vijayasarathy m

unread,
Mar 24, 2013, 11:51:46 PM3/24/13
to andro...@googlegroups.com
Dear Turk,

I am printing the parameters of outbuffer after doing ANativeWindow_lock which gives me below log

outbuffer, width=320, height=240, stride=320,format=4 bits=0x5d7d9000

As Per this stride is 320 and format is 4 which is WINDOW_FORMAT_RGB_565 as per native_window.h.

Thanks & Regards,
Vijayasarathy.M
Reply all
Reply to author
Forward
0 new messages