MBOOL JpegCodec:: allocYuvMem(IImageBuffer **pBuf, MSize const & imgSize, int const format) { MUINT32 bufStridesInBytes[3] = {0}; using namespace NSCam::Utils::Format; for (int i = 0; i < (int)queryPlaneCount(format); i++) { bufStridesInBytes[i] = (queryPlaneWidthInPixels(format,i, imgSize.w) * queryPlaneBitsPerPixel(format,i)) >> 3; } MINT32 bufBoundaryInBytes[3] = {0, 0, 0}; // IImageBufferAllocator* allocator = IImageBufferAllocator::getInstance(); IImageBufferAllocator::ImgParam imgParam( format, imgSize, bufStridesInBytes, bufBoundaryInBytes, Utils::Format::queryPlaneCount(format) ); *pBuf = allocator->alloc_ion("allocYuvBuf", imgParam); if ( *pBuf == 0 ) { CAM_LOGE("NULL YUV Buffer\n"); return MFALSE; } // MY_LOGD("<YUV> ImgBitsPerPixel:%d BufSizeInBytes:%d", (*pBuf)->getImgBitsPerPixel(), (*pBuf)->getBufSizeInBytes(0)); return MTRUE; }
static MVOID allocImageBuffer(sp<IImageBuffer> * pImageBuffer, MUINT32 w, MUINT32 h, MUINT32 fmt) { printf("alloc ImageBuffer %dx%d, fmt 0x%x\n", w, h, fmt); IImageBufferAllocator* allocator = IImageBufferAllocator::getInstance(); sp<IImageBuffer> pBuf; //allocate buffer MUINT32 bufStridesInBytes[3] = {0}; MUINT32 plane = queryPlaneCount(fmt); for (MUINT32 i = 0; i < plane; i++) { bufStridesInBytes[i] = (queryPlaneWidthInPixels(fmt,i, w) * queryPlaneBitsPerPixel(fmt,i)) >> 3; } MINT32 bufBoundaryInBytes[3] = {0, 0, 0}; // IImageBufferAllocator::ImgParam imgParam( fmt, MSize(w,h), bufStridesInBytes, bufBoundaryInBytes, plane ); *pImageBuffer = allocator->alloc_ion(LOG_TAG, imgParam); if ( pImageBuffer->get() == 0 ) { MY_LOGE("NULL Buffer\n"); } if ( !pImageBuffer->get()->lockBuf( LOG_TAG, eBUFFER_USAGE_SW_MASK | eBUFFER_USAGE_HW_MASK ) ) { MY_LOGE("lock Buffer failed\n"); } }
MBOOL CapPass2:: allocMemory(IImageBuffer* srcbuf, MINT32 const fmt, sp<IImageBuffer>& targetBuf) { MBOOL ret = MTRUE; // allocate internal memory IImageBufferAllocator* allocator = IImageBufferAllocator::getInstance(); if( allocator == NULL ) { MY_LOGE("cannot get allocator"); return MFALSE; } MSize const size = srcbuf->getImgSize(); MUINT const planecount = queryPlaneCount(fmt); MINT32 bufBoundaryInBytes[3] = {0, 0, 0}; MUINT32 bufStridesInBytes[3]; if( fmt == eImgFmt_BAYER8 || fmt == eImgFmt_BAYER10 || fmt == eImgFmt_BAYER12 || fmt == eImgFmt_BAYER14 ) { for (MUINT i = 0; i < planecount; i++) { bufStridesInBytes[i] = srcbuf->getBufStridesInBytes(i); } } else { for (MUINT i = 0; i < planecount; i++) { bufStridesInBytes[i] = (queryPlaneWidthInPixels(fmt,i, size.w)*queryPlaneBitsPerPixel(fmt,i))>>3; } } MY_LOGD("alloc %d x %d, fmt 0x%x", size.w, size.h, fmt); IImageBufferAllocator::ImgParam imgParam( fmt, size, bufStridesInBytes, bufBoundaryInBytes, planecount ); targetBuf = allocator->alloc_ion(LOG_TAG, imgParam); if( targetBuf.get() == NULL ) { MY_LOGE("failed to allocate memory"); goto lbExit; } if ( !targetBuf->lockBuf( LOG_TAG, eBUFFER_USAGE_SW_MASK | eBUFFER_USAGE_HW_MASK ) ) { MY_LOGE("lock Buffer failed\n"); goto lbExit; } if ( !targetBuf->syncCache( eCACHECTRL_INVALID ) ) { MY_LOGE("syncCache failed"); goto lbExit; } ret = MTRUE; lbExit: return ret; }