DirectDraw 怎么显示RGB24啊yv12如何转rgb32
答案:2 悬赏:20 手机版
解决时间 2021-01-29 12:43
- 提问者网友:献世佛
- 2021-01-29 03:40
DirectDraw 怎么显示RGB24啊yv12如何转rgb32
最佳答案
- 五星知识达人网友:山有枢
- 2021-01-29 04:32
提供简单例子如下
static void CopyDataFromYV12ToYUV420P(uint8_t* pDst, const uint8_t* pSrc, int nWidth, int nHeight)
{
int nYSize = nWidth * nHeight;
int nVSize = nYSize / 4;
int nUSize = nYSize / 4;
int nSrcUOffset = nYSize;
int nSrcVOffset = nSrcUOffset + nUSize;
int nDstVOffset = nYSize;
int nDstUOffset = nDstVOffset + nVSize;
memcpy(pDst, pSrc, nYSize);
memcpy((void*)((int)pDst + nDstVOffset), (void*)((int)pSrc + nSrcVOffset), nVSize);
memcpy((void*)((int)pDst + nDstUOffset), (void*)((int)pSrc + nSrcUOffset), nUSize);
}
void GetRGB888FromYV12(const char* pYV12, const int nWidthIn, const int nHeightIn, \
char** pBufferOut, const int nWidthOut, const int nHeightOut)
{
SwsContext* pConvert_ctx = NULL;
AVFrame* pFrameIn = NULL;
AVFrame* pFrameOut = NULL;
uint8_t* pFrameBufferOut = NULL;
int nFrameOutBufferSize = 0;
uint8_t* pBufferIn = NULL;
int nFrameInBufferSize = 0;
pFrameIn = avcodec_alloc_frame();
nFrameInBufferSize = avpicture_get_size(AV_PIX_FMT_YUV420P, nWidthIn, nHeightIn);
pBufferIn = (uint8_t*)av_malloc(nFrameInBufferSize * sizeof(uint8_t));
CopyDataFromYV12ToYUV420P(pBufferIn, (const uint8_t*)pYV12, nWidthIn, nHeightIn);
avpicture_fill((AVPicture*)pFrameIn, (uint8_t*)pBufferIn, AV_PIX_FMT_YUV420P, nWidthIn, nHeightIn);
pFrameOut = avcodec_alloc_frame();
nFrameOutBufferSize = avpicture_get_size(PIX_FMT_RGB24, nWidthOut, nHeightOut);
pFrameBufferOut = (uint8_t*)av_malloc(nFrameOutBufferSize * sizeof(uint8_t));
avpicture_fill((AVPicture*)pFrameOut, pFrameBufferOut, PIX_FMT_RGB24, nWidthOut, nHeightOut);
pConvert_ctx = sws_getContext(nWidthIn, nHeightIn, AV_PIX_FMT_YUV420P, \
nWidthOut, nHeightOut, PIX_FMT_RGB24, \
SWS_BICUBIC, NULL, NULL, NULL);
sws_scale(pConvert_ctx, (const uint8_t* const*)pFrameIn->data, pFrameIn->linesize, 0,\
nHeightIn, pFrameOut->data, pFrameOut->linesize);
*pBufferOut = (char*)pFrameBufferOut;
av_free(pBufferIn);
av_free(pFrameOut);
sws_freeContext(pConvert_ctx);
}
static void CopyDataFromYV12ToYUV420P(uint8_t* pDst, const uint8_t* pSrc, int nWidth, int nHeight)
{
int nYSize = nWidth * nHeight;
int nVSize = nYSize / 4;
int nUSize = nYSize / 4;
int nSrcUOffset = nYSize;
int nSrcVOffset = nSrcUOffset + nUSize;
int nDstVOffset = nYSize;
int nDstUOffset = nDstVOffset + nVSize;
memcpy(pDst, pSrc, nYSize);
memcpy((void*)((int)pDst + nDstVOffset), (void*)((int)pSrc + nSrcVOffset), nVSize);
memcpy((void*)((int)pDst + nDstUOffset), (void*)((int)pSrc + nSrcUOffset), nUSize);
}
void GetRGB888FromYV12(const char* pYV12, const int nWidthIn, const int nHeightIn, \
char** pBufferOut, const int nWidthOut, const int nHeightOut)
{
SwsContext* pConvert_ctx = NULL;
AVFrame* pFrameIn = NULL;
AVFrame* pFrameOut = NULL;
uint8_t* pFrameBufferOut = NULL;
int nFrameOutBufferSize = 0;
uint8_t* pBufferIn = NULL;
int nFrameInBufferSize = 0;
pFrameIn = avcodec_alloc_frame();
nFrameInBufferSize = avpicture_get_size(AV_PIX_FMT_YUV420P, nWidthIn, nHeightIn);
pBufferIn = (uint8_t*)av_malloc(nFrameInBufferSize * sizeof(uint8_t));
CopyDataFromYV12ToYUV420P(pBufferIn, (const uint8_t*)pYV12, nWidthIn, nHeightIn);
avpicture_fill((AVPicture*)pFrameIn, (uint8_t*)pBufferIn, AV_PIX_FMT_YUV420P, nWidthIn, nHeightIn);
pFrameOut = avcodec_alloc_frame();
nFrameOutBufferSize = avpicture_get_size(PIX_FMT_RGB24, nWidthOut, nHeightOut);
pFrameBufferOut = (uint8_t*)av_malloc(nFrameOutBufferSize * sizeof(uint8_t));
avpicture_fill((AVPicture*)pFrameOut, pFrameBufferOut, PIX_FMT_RGB24, nWidthOut, nHeightOut);
pConvert_ctx = sws_getContext(nWidthIn, nHeightIn, AV_PIX_FMT_YUV420P, \
nWidthOut, nHeightOut, PIX_FMT_RGB24, \
SWS_BICUBIC, NULL, NULL, NULL);
sws_scale(pConvert_ctx, (const uint8_t* const*)pFrameIn->data, pFrameIn->linesize, 0,\
nHeightIn, pFrameOut->data, pFrameOut->linesize);
*pBufferOut = (char*)pFrameBufferOut;
av_free(pBufferIn);
av_free(pFrameOut);
sws_freeContext(pConvert_ctx);
}
全部回答
- 1楼网友:大漠
- 2021-01-29 04:57
搜一下:DirectDraw 怎么显示RGB24啊yv12如何转rgb32
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯