YUV和RGB详解
https://juejin.im/post/5b4f2dab6fb9a04fc67bf265
https://www.jianshu.com/p/d9631596e9c7
https://zhuanlan.zhihu.com/p/24762605
https://www.jianshu.com/p/36ffaa905a43
https://developer.apple.com/documentation/accelerate/1533095-vimageconvert_420yp8_cbcr8toargb?language=objc
https://developer.apple.com/documentation/accelerate/vimage_ypcbcrpixelrange
https://stackoverflow.com/questions/29490145/ios-using-vimage-accelerate-to-convert-qcar-yuv-to-rgb
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); CVPixelBufferLockBaseAddress(imageBuffer,0); size_t width = CVPixelBufferGetWidth(imageBuffer); size_t height = CVPixelBufferGetHeight(imageBuffer); uint8_t *yBuffer = CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 0); size_t yPitch = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer, 0); uint8_t *cbCrBuffer = CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 1); size_t cbCrPitch = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer, 1); void *srcYpData = malloc(height *yPitch); memcpy(srcYpData, yBuffer, height *yPitch); void *srcCbCrData = malloc(height *cbCrPitch); memcpy(srcCbCrData, cbCrBuffer, height *cbCrPitch); size_t aRgbPitch = width * 4; uint8_t *aRgbBuffer = malloc(height *aRgbPitch); memset(aRgbBuffer, 0, height *aRgbPitch); vImage_Buffer srcYp = {srcYpData,height,width,yPitch}; vImage_Buffer srcCbCr = {srcCbCrData,height,width,cbCrPitch}; vImage_Buffer dest = {aRgbBuffer,height,width,aRgbPitch}; vImage_YpCbCrPixelRange pixelRange = {16,128,235,240,235,16,240,16}; vImage_YpCbCrToARGB infoYpCbCrToARGB = {}; vImage_Error error = vImageConvert_YpCbCrToARGB_GenerateConversion(kvImage_YpCbCrToARGBMatrix_ITU_R_601_4, &pixelRange, &infoYpCbCrToARGB, kvImage420Yp8_CbCr8, kvImageARGB8888, kvImageNoFlags); uint8_t permuteMap[4] = {0, 1, 2, 3}; error = vImageConvert_420Yp8_CbCr8ToARGB8888(&srcYp, &srcCbCr, &dest, &infoYpCbCrToARGB, permuteMap, 255, kvImageNoFlags); //处理dest中的ARGB数据
/*
code...
*/ free(srcYpData); free(srcCbCrData); free(aRgbBuffer);