Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8585273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:01:06+00:00 2026-06-11T22:01:06+00:00

According to http://developer.android.com/reference/android/graphics/ImageFormat.html#NV21 , NV21 is the default used format. There are quite a

  • 0

According to http://developer.android.com/reference/android/graphics/ImageFormat.html#NV21, NV21 is the default used format.

There are quite a number of code on web regarding YUV NV21 to RGB conversion. However, when I go through the code, I doubt on the correctness of the code.

The first component V should come first, followed by first component U

According to http://wiki.videolan.org/YUV#NV21, NV21 is like NV12, but with U and V order reversed: it starts with V. However, when I went through the code implementation

  • http://pastebin.com/T0my7zSc – It assumes U comes first
  • https://stackoverflow.com/a/8394202/72437 – It assumes U comes first too
  • https://stackoverflow.com/a/10125048/72437 – It assmes U comes first too

R should be the most significant position
According implementation of int argb in Color.java, R suppose to be at the most significant position. However, I went through the following code implementation

  • http://pastebin.com/T0my7zSc – It assumes R is in least significant position
  • https://stackoverflow.com/a/8394202/72437 – It assumes R is in least significant position

I was wondering, are they making common mistake, or I have overlooked something?

Currently, my implementation is as follow.

public static void YUV_NV21_TO_RGB(int[] argb, byte[] yuv, int width, int height) {
    final int frameSize = width * height;

    final int ii = 0;
    final int ij = 0;
    final int di = +1;
    final int dj = +1;

    int a = 0;
    for (int i = 0, ci = ii; i < height; ++i, ci += di) {
        for (int j = 0, cj = ij; j < width; ++j, cj += dj) {
            int y = (0xff & ((int) yuv[ci * width + cj]));
            int v = (0xff & ((int) yuv[frameSize + (ci >> 1) * width + (cj & ~1) + 0]));
            int u = (0xff & ((int) yuv[frameSize + (ci >> 1) * width + (cj & ~1) + 1]));
            y = y < 16 ? 16 : y;

            int r = (int) (1.164f * (y - 16) + 1.596f * (v - 128));
            int g = (int) (1.164f * (y - 16) - 0.813f * (v - 128) - 0.391f * (u - 128));
            int b = (int) (1.164f * (y - 16) + 2.018f * (u - 128));

            r = r < 0 ? 0 : (r > 255 ? 255 : r);
            g = g < 0 ? 0 : (g > 255 ? 255 : g);
            b = b < 0 ? 0 : (b > 255 ? 255 : b);

            argb[a++] = 0xff000000 | (r << 16) | (g << 8) | b;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:01:07+00:00Added an answer on June 11, 2026 at 10:01 pm

    First of all, I am not super experienced with image encoding (has some limited exposure to this about a year ago). So, take my answer with grain of salt.

    However, I believe you are right. I think in their code both
    a) V and U are flipped
    b) R and B are flipped

    I have a feeling that when both of these things are flipped, it will produce the same result as if they arent’ flipped. That’s the reason why you can find wrong code in many places (originally, somebody got it wrong and after it was copied all over the places, because the resulting code works (however, variables named incorrectly)).

    Here is another example of code (which works the same as yours):
    http://www.41post.com/3470/programming/android-retrieving-the-camera-preview-as-a-pixel-array

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to the [Canvas.drawVertices Javadoc](http://developer.android.com/reference/android/graphics/Canvas.html#drawVertices(android.graphics.Canvas.VertexMode, int, float[], int, float[], int, int[], int, short[], int,
The Activity Lifecycle is giving me headaches. The documentation at http://developer.android.com/reference/android/app/Activity.html is so darn
According to: http://developer.android.com/sdk/android-2.0-highlights.html Android 2.0 should support the HTML5 video element. I haven't been
According to http://developer.android.com/guide/practices/screens_support.html Normal screen with hdpi can have few resolutions, like 480X800 600x1024
I just set up eclipse to start android development according to this http://developer.android.com/sdk/installing.html .
http://developer.android.com/guide/practices/ui_guidelines/icon_design_tab.html According to the above link you have to place tab icons in a
I've created a WebView-based application according to http://developer.android.com/resources/tutorials/views/hello-webview.html Although I did exactly what was
I was reading this two docs about Service in the Android SDK http://developer.android.com/reference/android/app/Service.html http://developer.android.com/guide/components/services.html
According to http://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar.html - Status bar icons should be white without any color. Many
According to http://developer.android.com/guide/market/billing/billing_admin.html#billing-list-setup To create a product list for an application, follow these steps:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.