vpx_img_alloc alignment from Java BufferedImage (Using JNI/C)

128 views
Skip to first unread message

Alex Barry

unread,
Aug 8, 2012, 4:26:52 PM8/8/12
to webm-d...@webmproject.org
Hello again community :)

I'm trying to figure out image alignment, as mentioned in the subject.  I am allocating a buffer before starting image encoding, which looks something like this:

stream[id]->buffer = vpx_img_alloc( NULL, VPX_IMG_FMT_RGB32, w, h, stream[streamid]->config.g_w * sizeof( jint ) );

I noticed that all the example code that some of the vpx_img buffers set the alignment parameter to 1, but they all grab frames from specific file formats.

And, on top of this, I'm not sure how to actually put in the image data into this buffer.  I noticed that the examples put data directly into the image structure from image->planes[0] which seems sort of specific to the file format's way of storing image data.  I was looking at doing something like this:

img = vpx_img_wrap( NULL, VPX_IMG_FMT_ARGB, stream[streamid]->config.g_w, stream[streamid]->config.g_h, stream[streamid]->config.g_w * sizeof( jint ), (unsigned char *)pixel_data );

 This is fine, but it means I have to keep allocating the image every time.  Is it safe to just dump the pixel_data directly into stream[id]->buffer.img_data ?

John Koleszar

unread,
Aug 8, 2012, 4:56:55 PM8/8/12
to webm-d...@webmproject.org
A few things going on here:

VPX_IMG_FMT_ARGB is not supported. You'll have to convert to YV12/I420.

You don't have to allocate anything every time with vpx_img_wrap().
Use a non-NULL first parameter and it will update that structure with
a descriptor that describes the buffer you've given it.

Generally, if you have the data in a buffer already, you want to use
vpx_img_wrap() to avoid a copy. If you need to copy the data anyway,
then use vpx_img_alloc(), unless you really want to allocate the
buffer yourself.

For copying the data into the buffer, you can do it in one memcpy()
iff you know that the planes have the same offset, same strides, etc.
Otherwise, do a per-row memcpy, honoring the src and dst strides of
each plane.
> --
> You received this message because you are subscribed to the Google Groups
> "WebM Discussion" group.
> To view this discussion on the web visit
> https://groups.google.com/a/webmproject.org/d/msg/webm-discuss/-/Im0i_Y_4V50J.
> To post to this group, send email to webm-d...@webmproject.org.
> To unsubscribe from this group, send email to
> webm-discuss...@webmproject.org.
> For more options, visit this group at
> http://groups.google.com/a/webmproject.org/group/webm-discuss/?hl=en.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages