X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2FFMedia_ImageImpl.cpp;h=dfb27b849a25dca6ca4ee8ee3aac5ffc786dd4b0;hb=4c90a2abac7fbf8eb3acb96e75985ee559d9d5cb;hp=4d62299e45c862de30710d1fbbf087c6a51264a9;hpb=06638ca36ef792e859a62d0dbb3348c315298cea;p=platform%2Fframework%2Fnative%2Fimage.git diff --git a/src/FMedia_ImageImpl.cpp b/src/FMedia_ImageImpl.cpp index 4d62299..dfb27b8 100644 --- a/src/FMedia_ImageImpl.cpp +++ b/src/FMedia_ImageImpl.cpp @@ -28,14 +28,19 @@ #include #include "FMedia_MediaUtil.h" #include "FMedia_ImageImpl.h" +#include "FMedia_ImageUtil.h" #include "FMedia_ImageUtilImpl.h" #include "FMedia_ImageDecoder.h" #include "FMedia_ImageEncoder.h" #include "FMedia_ImageUriDataFactory.h" +#include "FGrp_BitmapImpl.h" +#include "FUi_CoordinateSystemUtils.h" + using namespace Tizen::Graphics; using namespace Tizen::Base; using namespace Tizen::Io; +using namespace Tizen::Ui; namespace Tizen { namespace Media { @@ -85,43 +90,92 @@ _ImageImpl::Construct(void) return E_SUCCESS; } +Bitmap* +_ImageImpl::DecodeToBitmapN(const Tizen::Base::String& srcImagePath, Tizen::Graphics::BitmapPixelFormat pixelFormat) +{ + std::unique_ptr pBuf; + Bitmap* pBmp = null; + + pBuf.reset(_MediaUtil::FileToBufferN(srcImagePath)); + SysTryReturn(NID_MEDIA, pBuf.get() != null, null, GetLastResult(), + "[%s] FileToBufferN %S", GetErrorMessage(GetLastResult()), srcImagePath.GetPointer()); + + pBmp = DecodeToBitmapN(*pBuf.get(), pixelFormat); + return pBmp; +} + +Bitmap* +_ImageImpl::DecodeToBitmapN(const Tizen::Base::ByteBuffer& srcImageBuf, Tizen::Graphics::BitmapPixelFormat pixelFormat) +{ + result r = E_SUCCESS; + std::unique_ptr pBuf; + std::unique_ptr pBmp; + Dimension outDim; + + _ImageDecoder dec; + + r = dec.Construct(srcImageBuf, _ImageUtilImpl::ToMediaPixelFormat(pixelFormat)); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Decoder construct failed.", GetErrorMessage(r)); + + pBuf.reset(dec.DecodeN()); + SysTryReturn(NID_MEDIA, pBuf.get() != null, null, GetLastResult(), + "[%s] Propagated", GetErrorMessage(GetLastResult())); + r = GetLastResult(); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated. ", GetErrorMessage(r)); + + r = dec.GetDimension(outDim.width, outDim.height); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated. ", GetErrorMessage(r)); + + pBmp.reset(new (std::nothrow) Bitmap); + SysTryReturn(NID_MEDIA, pBmp != null, null, E_OUT_OF_MEMORY, + "[%s] new Bitmap", GetErrorMessage(GetLastResult())); + r = pBmp->Construct(*pBuf.get(), outDim, pixelFormat, BUFFER_SCALING_AUTO); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated. ", GetErrorMessage(r)); + + SetLastResult(E_SUCCESS); + return pBmp.release(); +} + Bitmap* -_ImageImpl::DecodeToBitmapN(const String& srcImgPath, BitmapPixelFormat pixelFormat, - const Tizen::Graphics::Dimension &dstDim, - Tizen::Graphics::BufferScaling bufferScaling, - ImageFormat imgFormat, bool keepAspectRatio) +_ImageImpl::DecodeToBitmapN(const Tizen::Base::String& srcImagePath, Tizen::Graphics::BitmapPixelFormat pixelFormat, const Tizen::Graphics::Dimension &destDim, + Tizen::Graphics::BufferScaling bufferScaling) { std::unique_ptr pBuf; Bitmap* pBmp = null; - pBuf.reset(_MediaUtil::FileToBufferN(srcImgPath)); + pBuf.reset(_MediaUtil::FileToBufferN(srcImagePath)); SysTryReturn(NID_MEDIA, pBuf.get() != null, null, GetLastResult(), - "[%s] FileToBufferN %S", GetErrorMessage(GetLastResult()), srcImgPath.GetPointer()); + "[%s] FileToBufferN %S", GetErrorMessage(GetLastResult()), srcImagePath.GetPointer()); - pBmp = DecodeToBitmapN(*pBuf.get(), pixelFormat, dstDim, bufferScaling, imgFormat, keepAspectRatio); + pBmp = DecodeToBitmapN(*pBuf.get(), pixelFormat, destDim, bufferScaling); return pBmp; } -Tizen::Graphics::Bitmap* -_ImageImpl::DecodeToBitmapN(const Tizen::Base::ByteBuffer& srcImageBuf, - Tizen::Graphics::BitmapPixelFormat pixelFormat, - const Tizen::Graphics::Dimension &dstDim, - Tizen::Graphics::BufferScaling bufferScaling, - ImageFormat imgFormat, bool keepAspectRatio) +Bitmap* +_ImageImpl::DecodeToBitmapN(const Tizen::Base::ByteBuffer& srcImageBuf, Tizen::Graphics::BitmapPixelFormat pixelFormat, const Tizen::Graphics::Dimension &destDim, + Tizen::Graphics::BufferScaling bufferScaling) { result r = E_SUCCESS; std::unique_ptr pBuf; std::unique_ptr pBmp; Dimension outDim; - //SysTryCatch(NID_MEDIA, IS_VALID_BITMAP_PIXEL(pixelFormat), , E_INVALID_ARG, - // "[E_INVALID_ARG] pixelFormat:%d", pixelFormat); - //SysTryCatch(NID_MEDIA, IS_VALID_DIMENSION(dstDim), , E_OUT_OF_RANGE, - // "[E_OUT_OF_RANGE] dest dimension:%d,%d", dstDim.width, dstDim.height); + _ImageDecoder dec; - pBuf.reset(DecodeToBufferN(srcImageBuf, outDim, dstDim, pixelFormat, imgFormat, keepAspectRatio)); + r = dec.Construct(srcImageBuf, _ImageUtilImpl::ToMediaPixelFormat(pixelFormat)); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Decoder construct failed.", GetErrorMessage(r)); + + // Reset decoder output demension + dec.SetOutputDimension(destDim.width, destDim.height, true); + + pBuf.reset(dec.DecodeN()); SysTryReturn(NID_MEDIA, pBuf.get() != null, null, GetLastResult(), "[%s] Propagated", GetErrorMessage(GetLastResult())); + r = GetLastResult(); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated. ", GetErrorMessage(r)); + + r = dec.GetDimension(outDim.width, outDim.height); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated. ", GetErrorMessage(r)); pBmp.reset(new (std::nothrow) Bitmap); SysTryReturn(NID_MEDIA, pBmp != null, null, E_OUT_OF_MEMORY, @@ -133,6 +187,64 @@ _ImageImpl::DecodeToBitmapN(const Tizen::Base::ByteBuffer& srcImageBuf, return pBmp.release(); } +Bitmap* +_ImageImpl::DecodeToBitmapN(const Tizen::Base::ByteBuffer& srcImageBuf, Tizen::Graphics::BitmapPixelFormat pixelFormat, + const Tizen::Graphics::FloatDimension &destDim) +{ + result r = E_SUCCESS; + std::unique_ptr pBuf; + std::unique_ptr pBmp; + Dimension orgDim, tmpDim; + FloatDimension outDim; + BufferInfo bufInfo; + + _ImageDecoder dec; + + r = dec.Construct(srcImageBuf, _ImageUtilImpl::ToMediaPixelFormat(pixelFormat)); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Decoder construct failed.", GetErrorMessage(r)); + + r = dec.GetDimension(orgDim.width, orgDim.height); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated. ", GetErrorMessage(r)); + + // Reset decoder output demension + dec.SetOutputDimension(_CoordinateSystemUtils::ConvertToInteger(destDim.width), + _CoordinateSystemUtils::ConvertToInteger(destDim.height), + true); + + pBuf.reset(dec.DecodeN()); + SysTryReturn(NID_MEDIA, pBuf.get() != null, null, GetLastResult(), + "[%s] Propagated", GetErrorMessage(GetLastResult())); + + r = dec.GetDimension(tmpDim.width, tmpDim.height); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated. ", GetErrorMessage(r)); + + r = _ImageUtil::GetResizedDimension(orgDim.width, orgDim.height, destDim.width, destDim.height, outDim.width, outDim.height); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated. ", GetErrorMessage(r)); + + pBmp.reset(new (std::nothrow) Bitmap); + SysTryReturn(NID_MEDIA, pBmp.get() != null, null, E_OUT_OF_MEMORY, + "[%s] new Bitmap", GetErrorMessage(GetLastResult())); + + pBmp.reset(_BitmapImpl::GetNonScaledBitmapN(*pBuf.get(), tmpDim, pixelFormat)); + SetLastResult(E_SUCCESS); + return pBmp.release(); +} + +Bitmap* +_ImageImpl::DecodeToBitmapN(const Tizen::Base::String& srcImagePath, Tizen::Graphics::BitmapPixelFormat pixelFormat, + const Tizen::Graphics::FloatDimension &destDim) +{ + std::unique_ptr pBuf; + Bitmap* pBmp = null; + + pBuf.reset(_MediaUtil::FileToBufferN(srcImagePath)); + SysTryReturn(NID_MEDIA, pBuf.get() != null, null, GetLastResult(), + "[%s] FileToBufferN %S", GetErrorMessage(GetLastResult()), srcImagePath.GetPointer()); + + pBmp = DecodeToBitmapN(*pBuf.get(), pixelFormat, destDim); + return pBmp; +} + Tizen::Base::ByteBuffer* _ImageImpl::DecodeToBufferN(const Tizen::Base::String& srcImagePath, Tizen::Graphics::Dimension &restDim,