This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TDA2E: TDA2E: Loss of image brightnes,in OPENGL api from YUV to RGB.

Part Number: TDA2E


Hi,

in Vision SDK version : 2.8, 

The input format is YUV420, the pixels are full range (0~255), we need to use GPU OpenGL API System_eglSetupYuvTexSurface,  the expected output is RGB format pixels with full range (0~255). 

that means :  range was cutted when yuv witch to rgb.

we check it by this way: 

After the function wraps YUV image into an external texture in the GL_TEXTURE_EXTERNAL_OES format,
The color sampled by the texture sampler is abnormal.
 
Channels with input values greater than 235 are sampled to 255 after sampling, and values less than 15 are clipped to 0.

function shows below:

static GLuint System_eglSetupYuvTexSurface(System_EglObj *pObj, System_EglTexProperty *pProp, void *bufAddr, int texIndex)
{
    EGLint attr[32];
    int attrIdx;
    PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
    PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
    attrIdx = 0;
    attr[attrIdx++] = EGL_GL_VIDEO_FOURCC_TI;
    attr[attrIdx++] = FOURCC_STR("NV12");
    attr[attrIdx++] = EGL_GL_VIDEO_WIDTH_TI;
    attr[attrIdx++] = pProp->width;
    attr[attrIdx++] = EGL_GL_VIDEO_HEIGHT_TI;
    attr[attrIdx++] = pProp->height;
    attr[attrIdx++] = EGL_GL_VIDEO_BYTE_STRIDE_TI;
    attr[attrIdx++] = pProp->pitch[0];
    attr[attrIdx++] = EGL_GL_VIDEO_BYTE_SIZE_TI;
    if(pProp->dataFormat==SYSTEM_DF_YUV420SP_UV)
    {
        attr[attrIdx++] = (pProp->pitch[0] * pProp->height * 3)/2;
    }
    else
    {
        INFO(" EGL: ERROR: Unsupported data format (%d) !!!\n", pProp->dataFormat);
        assert(0);
    }
    attr[attrIdx++] = EGL_GL_VIDEO_YUV_FLAGS_TI;
    attr[attrIdx++] = EGLIMAGE_FLAGS_YUV_CONFORMANT_RANGE | EGLIMAGE_FLAGS_YUV_BT601;
    attr[attrIdx++] = EGL_NONE;

    eglCreateImageKHR =
        (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR");
    glEGLImageTargetTexture2DOES =
        (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
    pObj->texImg[texIndex] = eglCreateImageKHR(
                                pObj->display,
                                EGL_NO_CONTEXT,
                                EGL_RAW_VIDEO_TI,
                                bufAddr,
                                attr
                              );
   System_eglCheckEglError("eglCreateImageKHR", EGL_TRUE);
   if (pObj->texImg[texIndex] == EGL_NO_IMAGE_KHR) {
       INFO(" EGL: ERROR: eglCreateImageKHR failed !!!\n");
       return -1;
   }
   glGenTextures(1, &pObj->texYuv[texIndex]);
   System_eglCheckGlError("eglCreateImageKHR");
   glBindTexture(GL_TEXTURE_EXTERNAL_OES, pObj->texYuv[texIndex]);
   System_eglCheckGlError("glBindTexture");
   glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   System_eglCheckGlError("glTexParameteri");
   glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, (GLeglImageOES)pObj->texImg[texIndex]);
   System_eglCheckGlError("glEGLImageTargetTexture2DOES");
   pObj->bufAddr[texIndex] = bufAddr;
   return 0;
}
we will have a test  changing  EGLIMAGE_FLAGS_YUV_CONFORMANT_RANGE to EGLIMAGE_FLAGS_YUV_FULL_RANGE,  it is on going..
can it solve this probelm?  have some other code need to be edit??

Thanks