Created
August 20, 2018 04:34
-
-
Save lgyjg/4913dcf90e0ec46192d448fc9b5c0d1d to your computer and use it in GitHub Desktop.
YUV2RGB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static inline uint32_t YUV2RGB(int nY, int nU, int nV) { | |
nY -= 16; | |
nU -= 128; | |
nV -= 128; | |
if (nY < 0) nY = 0; | |
// This is the floating point equivalent. We do the conversion in integer | |
// because some Android devices do not have floating point in hardware. | |
// nR = (int)(1.164 * nY + 1.596 * nV); | |
// nG = (int)(1.164 * nY - 0.813 * nV - 0.391 * nU); | |
// nB = (int)(1.164 * nY + 2.018 * nU); | |
int nR = (int)(1192 * nY + 1634 * nV); | |
int nG = (int)(1192 * nY - 833 * nV - 400 * nU); | |
int nB = (int)(1192 * nY + 2066 * nU); | |
nR = MIN(kMaxChannelValue, MAX(0, nR)); | |
nG = MIN(kMaxChannelValue, MAX(0, nG)); | |
nB = MIN(kMaxChannelValue, MAX(0, nB)); | |
nR = (nR >> 10) & 0xff; | |
nG = (nG >> 10) & 0xff; | |
nB = (nB >> 10) & 0xff; | |
return 0xff000000 | (nR << 16) | (nG << 8) | nB; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment