How to convert Camera Preview Data (NV12) to RGB in Tizen Native Application?

Original Created Dec 07, 2016 | Regeneration Apr 22, 2026

I'm currently developing a Tizen native application and facing an issue with camera preview data conversion.

I need to programmatically convert the camera preview data from NV12 format to RGB format. Could you please provide guidance on how to achieve this conversion?

Problem Understanding

The user needs to convert camera preview data from NV12 format (commonly used in Tizen camera APIs) to RGB format for further processing or display in their native application.

Solution Methods

  1. Using Tizen Camera API:

    • The Tizen Camera API provides access to preview frames in NV12 format
    • You'll need to implement the conversion from YUV (NV12) to RGB
  2. Color Space Conversion:

    • Implement a color space conversion algorithm
    • NV12 is a YUV format, so you'll need to convert YUV to RGB

Code Examples

Here's a basic example of NV12 to RGB conversion in C:

void NV12_to_RGB(unsigned char *rgb, unsigned char *yuv, int width, int height) {
    int size = width * height;
    int offset = size;
    
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            int Y = yuv[y * width + x];
            int U = yuv[offset + (y/2) * (width/2) + (x/2)];
            int V = yuv[offset + (width * height)/4 + (y/2) * (width/2) + (x/2)];
            
            // YUV to RGB conversion formula
            int R = Y + 1.402 * (V - 128);
            int G = Y - 0.344 * (U - 128) - 0.714 * (V - 128);
            int B = Y + 1.772 * (U - 128);
            
            // Clamp values to 0-255 range
            R = (R < 0) ? 0 : (R > 255) ? 255 : R;
            G = (G < 0) ? 0 : (G > 255) ? 255 : G;
            B = (B < 0) ? 0 : (B > 255) ? 255 : B;
            
            rgb[(y * width + x) * 3 + 0] = R;
            rgb[(y * width + x) * 3 + 1] = G;
            rgb[(y * width + x) * 3 + 2] = B;
        }
    }
}

Additional Tips

  • For better performance, consider using optimized libraries or hardware acceleration
  • The conversion formula might need adjustments based on your specific requirements
  • Test the conversion with different lighting conditions to ensure color accuracy

Customize your cookie preferences

You can enable or disable non-essential cookies. Essential cookies are always on to ensure the site works properly and to keep you signed in.

Necessary

These cookies are necessary for the website to function properly and cannot be switched off. They help with things like logging in and setting your privacy preferences.

Always on

Analytics

These cookies help us improve the site by tracking which pages are most popular and how visitors move around the site.

Enable analytics cookies
Public Forum Public Forum
Employees only. Please sign in with your company account.