MBOOL
JpegCodec::
encode(
    ImgBufInfo const rSrcBufInfo, 
    ImgBufInfo const rDstBufInfo, 
    Rect const rROI, 
    MUINT32 const u4Rotation, 
    MUINT32 const u4Flip, 
    MUINT32 const u4Quality, 
    MUINT32 const u4IsSOI, 
    MUINT32 &u4EncSize
)
{
    MBOOL ret = MTRUE; 
    if (checkIfNeedImgTransform(rSrcBufInfo, rDstBufInfo, rROI, u4Rotation, u4Flip))
    {
        // 
        IMEM_BUF_INFO rTempMemBuf; 
        // Jpeg code width/height should align to 16x 
        MUINT32 u4AlignedWidth = (~0xf) & (0xf + rDstBufInfo.u4ImgWidth);
        MUINT32 u4AlignedHeight = (~0xf) & (0xf + rDstBufInfo.u4ImgHeight); 
        MY_LOGD("[encode] Ori (width, height) = (%d, %d), Aligned (width, height) = (%d, %d)", 
                          rDstBufInfo.u4ImgWidth, rDstBufInfo.u4ImgHeight, u4AlignedWidth, u4AlignedHeight); 
        rTempMemBuf.size = u4AlignedWidth *u4AlignedHeight* 2; 
        allocMem(rTempMemBuf); 
        // (1). Image transform 
        MUINT32 u4Stride[3] = {u4AlignedWidth, 0, 0}; 
        ImgBufInfo rTempImgBuf(ImgInfo(eImgFmt_YUY2, u4AlignedWidth, u4AlignedHeight), 
                          BufInfo(rTempMemBuf.size, rTempMemBuf.virtAddr, rTempMemBuf.phyAddr, rTempMemBuf.memID), u4Stride); 
        // 
        IImageTransform *pImgTransform = IImageTransform::createInstance(); 
        
        ret =  pImgTransform->execute(rSrcBufInfo, rTempImgBuf, rROI, u4Rotation, u4Flip, 10 * 1000);  //10s timeout
        if (mu4DumpFlag)
        {
            char fileName[256]; 
            sprintf(fileName, "/%s/trans_%dx%d.yuv", MEDIA_PATH, u4AlignedWidth, u4AlignedHeight); 
            MtkCamUtils::saveBufToFile(fileName, reinterpret_cast<MUINT8*>(rTempMemBuf.virtAddr), rTempMemBuf.size); 
        }

        pImgTransform->destroyInstance();
        // (2). Encode
        encode(rTempImgBuf, rDstBufInfo, u4Quality, u4IsSOI, u4EncSize); 
        // 
        deallocMem(rTempMemBuf); 
    }    
    else 
    {
        ret = encode(rSrcBufInfo, rDstBufInfo, u4Quality, u4IsSOI, u4EncSize); 
    }
    return ret;  
} 
MBOOL
SImager::
imgTransform(
    ImgBufInfo const rSrcBufInfo, 
    ImgBufInfo const rDstBufInfo,  
    Rect const rROI, 
    MUINT32 const u4Rotation, 
    MUINT32 const u4Flip,
    MUINT32 const u4TimeoutInMs
)
{
    FUNCTION_LOG_START;
    MBOOL ret = MTRUE; 
    //
    IImageTransform *pImgTransform = IImageTransform::createInstance(); 
    ret =  pImgTransform->execute(rSrcBufInfo, rDstBufInfo, rROI, u4Rotation, u4Flip, u4TimeoutInMs); 
    pImgTransform->destroyInstance();
    //
    FUNCTION_LOG_END;
    return ret ; 
}
Exemplo n.º 3
0
MBOOL
JpegCodec::
encode(
    IImageBuffer const *pSrcBufInfo, 
    IImageBuffer const *pDstBufInfo, 
    MRect const rROI, 
    MUINT32 const u4Transform, 
    MUINT32 const u4Quality, 
    MUINT32 const u4IsSOI, 
    MUINT32 const eCodecType,
    MUINT32 const u4TimeoutMs//,
//    MUINT32 &u4EncSize
)
{
    MBOOL ret = MTRUE; 
    if (checkIfNeedImgTransform(pSrcBufInfo, pDstBufInfo, rROI, u4Transform))
    {
        //   
        IImageBuffer *pImageBuff; 
        int format = pSrcBufInfo->getImgFormat();
        MUINT32 u4AlignedWidth = pDstBufInfo->getImgSize().w;
        MUINT32 u4AlignedHeight = pDstBufInfo->getImgSize().h; 

        if( !isSupportedFormat((NSCam::EImageFormat)format) )
        {
            MY_LOGW("use yuy2 for jpeg encode");
            // default format
            format = eImgFmt_YUY2;
        }

        {
            // Jpeg code width/height should be aligned
            MUINT32 w_align, h_align;
            getAlignment(format, &w_align, &h_align);

            u4AlignedWidth = (~(w_align-1)) & ((w_align-1) + u4AlignedWidth);
            u4AlignedHeight = (~(h_align-1)) & ((h_align-1) + u4AlignedHeight); 
            MY_LOGW("[encode] Ori (width, height) = (%d, %d), Aligned (width, height) = (%d, %d)", 
                    pSrcBufInfo->getImgSize().w, pSrcBufInfo->getImgSize().h, 
                    u4AlignedWidth, u4AlignedHeight); 
        }

        if( !allocYuvMem(&pImageBuff, 
                         MSize(u4AlignedWidth, u4AlignedHeight), format) )
        {
            return MFALSE;
        }
        
        // 
        IImageTransform *pImgTransform = IImageTransform::createInstance(); 

        ret = pImageBuff->lockBuf(LOG_TAG, eBUFFER_USAGE_HW_CAMERA_WRITE|eBUFFER_USAGE_SW_MASK);

        ret = pImageBuff->syncCache(eCACHECTRL_INVALID);

        ret = ret && pImgTransform->execute(pSrcBufInfo, pImageBuff, NULL, rROI, u4Transform, u4TimeoutMs);  //10s timeout

        if (ret && mu4DumpFlag)
        {
            char fileName[256] = {0}; 
            sprintf(fileName, "/%s/trans_%dx%d.yuv", MEDIA_PATH, u4AlignedWidth, u4AlignedHeight); 
            pImageBuff->saveToFile(fileName); 
        }

        pImgTransform->destroyInstance();
        // (2). Encode
        ret = ret && encode(pImageBuff, pDstBufInfo, 
                            u4Quality, u4IsSOI, eCodecType, u4TimeoutMs); 
        ret = ret && pImageBuff->unlockBuf(LOG_TAG);

        freeYuvMem(&pImageBuff);
        // 
    }    
    else 
    {
        ret = encode(pSrcBufInfo, pDstBufInfo, u4Quality, u4IsSOI, eCodecType, u4TimeoutMs/*, u4EncSize*/); 
    }
    return ret;  
} 
Exemplo n.º 4
0
MBOOL 
CapPass2::
transform(
        IImageBuffer* src,
        IImageBuffer* dst0,
        IImageBuffer* dst1,
        MRect const crop,
        MINT32 const transform0)
{
    MBOOL ret = MTRUE;
    IImageTransform* pImgTransform = NULL;
    //
    if( src == NULL || (dst0==NULL && dst1==NULL) )
    {
        ret = MFALSE;
        goto lbExit;
    }
    //
    pImgTransform = IImageTransform::createInstance(); 
    if( !pImgTransform )
    {
        MY_LOGE("imageTransform create failed");
        return MFALSE;
    }
    //
    ret = pImgTransform->execute(
            src,
            dst0,
            dst1,
            crop,
            transform0,
            0xFFFFFFFF);
    //
    if( pImgTransform )
    {
        pImgTransform->destroyInstance();
        pImgTransform = NULL;
    }
    //
    if( dst0 )
        dst0->setTimestamp( src->getTimestamp() );
    if( dst1 )
        dst1->setTimestamp( src->getTimestamp() );
    //
lbExit:
    if( !ret )
    {
        if( src )
        {
            MY_LOGE("src: buf 0x%x, %dx%d, fmt 0x%x",
                    src,
                    src->getImgSize().w,
                    src->getImgSize().h,
                    src->getImgFormat());
        }
        if( dst0 )
        {
            MY_LOGE("dst0: buf 0x%x, %dx%d, fmt 0x%x",
                    dst0,
                    dst0->getImgSize().w,
                    dst0->getImgSize().h,
                    dst0->getImgFormat());
        }
        if( dst1 )
        {
            MY_LOGE("dst1: buf 0x%x, %dx%d, fmt 0x%x",
                    dst1,
                    dst1->getImgSize().w,
                    dst1->getImgSize().h,
                    dst1->getImgFormat());
        }
    }
    //
    return ret;
}