Merge from master branch
authorJungYumin <y_m.jung@samsung.com>
Sat, 16 Mar 2013 05:00:34 +0000 (14:00 +0900)
committerJungYumin <y_m.jung@samsung.com>
Sat, 16 Mar 2013 05:00:34 +0000 (14:00 +0900)
Change-Id: I34c86ee1a866a0aab576d35d413a0aae15911c74
Signed-off-by: JungYumin <y_m.jung@samsung.com>
src/FMedia_BmpDecoder.cpp

index b40cea0..8ea0aaa 100755 (executable)
@@ -174,8 +174,13 @@ _BmpDecoder::DecodeN(int& outLength)
 {
        int resFfmpeg = 0;
 
+       std::unique_ptr<byte[]> pDstBuf;
        std::unique_ptr<byte[]> pOutBuf;
 
+       SwsContext* pCvtCtxt;
+       AVFrame srcFrame;
+       AVFrame dstFrame;
+
        SysTryReturn(NID_MEDIA, __pCodecCtx, null, E_INVALID_STATE,
                           "[E_INVALID_STATE] Not Constructed");
 
@@ -200,6 +205,37 @@ _BmpDecoder::DecodeN(int& outLength)
        SysTryReturn(NID_MEDIA, resFfmpeg >= 0, null, E_SYSTEM,
                           "[E_SYSTEM] Could not copy image data to buffer!!");
 
+       if (__pixelFormat == MEDIA_PIXEL_FORMAT_NONE)
+       {
+               pCvtCtxt = sws_getContext(__pCodecCtx->width, __pCodecCtx->height, __pCodecCtx->pix_fmt,
+                                                                 __pCodecCtx->width, __pCodecCtx->height, PIX_FMT_BGRA,
+                                                                 SWS_BICUBIC, NULL, NULL, NULL);
+
+               memset(&srcFrame, 0, sizeof(srcFrame));
+               memset(&dstFrame, 0, sizeof(dstFrame));
+
+               outLength = avpicture_get_size(PIX_FMT_BGRA, __pCodecCtx->width, __pCodecCtx->height);
+               SysTryReturn(NID_MEDIA, outLength >= 0, null, E_INVALID_ARG,
+                                       "[E_FAILURE] Not able find size of dest frame for pix (%d), size (%d x %d)",
+                                       PIX_FMT_BGRA, __pCodecCtx->width, __pCodecCtx->height);
+
+               pDstBuf.reset(new (std::nothrow) byte[outLength]);
+               SysTryReturn(NID_MEDIA, pOutBuf.get() != null, null, E_OUT_OF_MEMORY,
+                          "[E_OUT_OF_MEMORY] Memory allocation of %d bytes for output buffer failed!", outLength);
+
+               // Fill source frame
+               avpicture_fill((AVPicture*)&srcFrame, (byte*)pOutBuf.get(), __pCodecCtx->pix_fmt, __pCodecCtx->width, __pCodecCtx->height);
+
+               // Fill dest frame
+               avpicture_fill((AVPicture*)&dstFrame, (byte*)pDstBuf.get(), PIX_FMT_BGRA, __pCodecCtx->width, __pCodecCtx->height);
+
+               // Scaling
+               sws_scale(pCvtCtxt, srcFrame.data, srcFrame.linesize, 0, __pCodecCtx->height, dstFrame.data, dstFrame.linesize);
+
+               __pixelFormat = MEDIA_PIXEL_FORMAT_BGRA8888;
+               pOutBuf.swap(pDstBuf);
+       }
+
        SetLastResult(E_SUCCESS);
        return pOutBuf.release();
 }