From 06638ca36ef792e859a62d0dbb3348c315298cea Mon Sep 17 00:00:00 2001 From: Jinkun Jang Date: Wed, 13 Mar 2013 01:50:38 +0900 Subject: [PATCH] Tizen 2.1 base --- CMakeLists.txt | 100 +++ LICENSE.APLv2.0 | 202 +++++++ NOTICE | 3 + inc/FMediaGifDecoder.h | 213 +++++++ inc/FMediaIImageEventListener.h | 100 +++ inc/FMediaImage.h | 665 ++++++++++++++++++++ inc/FMediaImageBuffer.h | 479 +++++++++++++++ inc/FMediaImageUtil.h | 250 ++++++++ inc/FMediaTypes.h | 196 ++++++ osp-image.manifest | 5 + osp-image.pc.in | 13 + packaging/osp-image.spec | 107 ++++ src/FMediaGifDecoder.cpp | 128 ++++ src/FMediaImage.cpp | 433 +++++++++++++ src/FMediaImageBuffer.cpp | 387 ++++++++++++ src/FMediaImageUtil.cpp | 68 +++ src/FMedia_ExifUtil.cpp | 279 +++++++++ src/FMedia_GifDecoderImpl.cpp | 173 ++++++ src/FMedia_GifDecoderImpl.h | 142 +++++ src/FMedia_ImageBufferImpl.cpp | 1108 ++++++++++++++++++++++++++++++++++ src/FMedia_ImageDownloadListener.cpp | 378 ++++++++++++ src/FMedia_ImageDownloadListener.h | 94 +++ src/FMedia_ImageImpl.cpp | 523 ++++++++++++++++ src/FMedia_ImageUriData.cpp | 321 ++++++++++ src/FMedia_ImageUriData.h | 97 +++ src/FMedia_ImageUriDataEvent.cpp | 159 +++++ src/FMedia_ImageUriDataEvent.h | 57 ++ src/FMedia_ImageUriDataEventArg.cpp | 203 +++++++ src/FMedia_ImageUriDataEventArg.h | 176 ++++++ src/FMedia_ImageUriDataFactory.cpp | 326 ++++++++++ src/FMedia_ImageUriDataFactory.h | 79 +++ src/FMedia_ImageUriDataHolder.cpp | 127 ++++ src/FMedia_ImageUriDataHolder.h | 68 +++ src/FMedia_ImageUtilImpl.cpp | 186 ++++++ src/inc/FMedia_ExifUtil.h | 72 +++ src/inc/FMedia_ImageBufferImpl.h | 215 +++++++ src/inc/FMedia_ImageImpl.h | 233 +++++++ src/inc/FMedia_ImageUtilImpl.h | 85 +++ 38 files changed, 8450 insertions(+) create mode 100755 CMakeLists.txt create mode 100755 LICENSE.APLv2.0 create mode 100755 NOTICE create mode 100644 inc/FMediaGifDecoder.h create mode 100644 inc/FMediaIImageEventListener.h create mode 100644 inc/FMediaImage.h create mode 100644 inc/FMediaImageBuffer.h create mode 100644 inc/FMediaImageUtil.h create mode 100644 inc/FMediaTypes.h create mode 100755 osp-image.manifest create mode 100755 osp-image.pc.in create mode 100755 packaging/osp-image.spec create mode 100644 src/FMediaGifDecoder.cpp create mode 100644 src/FMediaImage.cpp create mode 100644 src/FMediaImageBuffer.cpp create mode 100644 src/FMediaImageUtil.cpp create mode 100644 src/FMedia_ExifUtil.cpp create mode 100644 src/FMedia_GifDecoderImpl.cpp create mode 100644 src/FMedia_GifDecoderImpl.h create mode 100644 src/FMedia_ImageBufferImpl.cpp create mode 100644 src/FMedia_ImageDownloadListener.cpp create mode 100644 src/FMedia_ImageDownloadListener.h create mode 100644 src/FMedia_ImageImpl.cpp create mode 100644 src/FMedia_ImageUriData.cpp create mode 100644 src/FMedia_ImageUriData.h create mode 100644 src/FMedia_ImageUriDataEvent.cpp create mode 100644 src/FMedia_ImageUriDataEvent.h create mode 100644 src/FMedia_ImageUriDataEventArg.cpp create mode 100644 src/FMedia_ImageUriDataEventArg.h create mode 100644 src/FMedia_ImageUriDataFactory.cpp create mode 100644 src/FMedia_ImageUriDataFactory.h create mode 100644 src/FMedia_ImageUriDataHolder.cpp create mode 100644 src/FMedia_ImageUriDataHolder.h create mode 100644 src/FMedia_ImageUtilImpl.cpp create mode 100644 src/inc/FMedia_ExifUtil.h create mode 100644 src/inc/FMedia_ImageBufferImpl.h create mode 100644 src/inc/FMedia_ImageImpl.h create mode 100644 src/inc/FMedia_ImageUtilImpl.h diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..336ab4e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,100 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +SET (this_target osp-image) + +SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/cmake_build_tmp/output) + +INCLUDE_DIRECTORIES( + inc + src + src/inc + /usr/include + /usr/include/curl + /usr/include/libxml2 + /usr/include/glib-2.0 + /usr/lib/glib-2.0/include + /usr/include/osp + /usr/include/osp/app + /usr/include/osp/base + /usr/include/osp/io + /usr/include/osp/graphics + /usr/include/osp/media + /usr/include/osp/net + /usr/include/osp/security + /usr/include/osp/system + /usr/include/osp/ui + ) + +SET (${this_target}_SOURCE_FILES + src/FMediaImage.cpp + src/FMedia_ImageImpl.cpp + src/FMediaImageBuffer.cpp + src/FMedia_ImageBufferImpl.cpp + src/FMediaImageUtil.cpp + src/FMedia_ImageUtilImpl.cpp + src/FMediaGifDecoder.cpp + src/FMedia_GifDecoderImpl.cpp + src/FMedia_ImageDownloadListener.cpp + src/FMedia_ImageUriData.cpp + src/FMedia_ImageUriDataEvent.cpp + src/FMedia_ImageUriDataEventArg.cpp + src/FMedia_ImageUriDataFactory.cpp + src/FMedia_ImageUriDataHolder.cpp + src/FMedia_ExifUtil.cpp +) + +## Definitions +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall" ) + +## SET C COMPILER FLAGS +SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}") + +## SET CPP COMPILER FLAGS +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") +SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}") + +## Create Library +ADD_LIBRARY (${this_target} SHARED ${${this_target}_SOURCE_FILES}) + +## SET LINKER FLAGS +SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined -Wl,--as-needed") + +TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp -losp-appfw" ) +TARGET_LINK_LIBRARIES(${this_target} "-losp-image-core" ) +TARGET_LINK_LIBRARIES(${this_target} "-losp-uifw" ) +TARGET_LINK_LIBRARIES(${this_target} "-losp-net" ) +TARGET_LINK_LIBRARIES(${this_target} "-lexif" ) +TARGET_LINK_LIBRARIES(${this_target} "-lpthread" ) + +SET_TARGET_PROPERTIES(${this_target} + PROPERTIES + VERSION ${FULLVER} + SOVERSION ${MAJORVER} + CLEAN_DIRECT_OUTPUT 1 + ) + +ADD_CUSTOM_COMMAND(TARGET ${this_target} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX} ${LIBRARY_OUTPUT_PATH}/debug/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${FULLVER} + COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${FULLVER} ${LIBRARY_OUTPUT_PATH}/debug/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${MAJORVER} + COMMAND ${CMAKE_STRIP} --strip-unneeded ${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX} + COMMENT "strip ${this_target}" + ) + +INSTALL(DIRECTORY ${LIBRARY_OUTPUT_PATH}/ DESTINATION lib/osp + FILES_MATCHING PATTERN "*.so*" + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ + GROUP_EXECUTE GROUP_READ + WORLD_EXECUTE WORLD_READ) +INSTALL(DIRECTORY ${LIBRARY_OUTPUT_PATH}/debug/ DESTINATION lib/osp/debug + FILES_MATCHING PATTERN "*" + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ + GROUP_EXECUTE GROUP_READ + WORLD_EXECUTE WORLD_READ) + +INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/inc/ DESTINATION include/osp FILES_MATCHING PATTERN "*.h") +INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/src/inc/ DESTINATION include/osp/media FILES_MATCHING PATTERN "*.h") + +# pkgconfig file +CONFIGURE_FILE(${this_target}.pc.in ${CMAKE_SOURCE_DIR}/${this_target}.pc @ONLY) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/${this_target}.pc DESTINATION lib/pkgconfig) diff --git a/LICENSE.APLv2.0 b/LICENSE.APLv2.0 new file mode 100755 index 0000000..d645695 --- /dev/null +++ b/LICENSE.APLv2.0 @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/NOTICE b/NOTICE new file mode 100755 index 0000000..ccdad52 --- /dev/null +++ b/NOTICE @@ -0,0 +1,3 @@ +Copyright (c) Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Apache License, Version 2. +Please, see the LICENSE file for Apache License terms and conditions. diff --git a/inc/FMediaGifDecoder.h b/inc/FMediaGifDecoder.h new file mode 100644 index 0000000..c4a5336 --- /dev/null +++ b/inc/FMediaGifDecoder.h @@ -0,0 +1,213 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMediaGifDecoder.h + * @brief This is the header file for the %GifDecoder class. + * + * This header file contains the declarations of the %GifDecoder class. + */ + +#ifndef _FMEDIA_GIF_DECODER_H_ +#define _FMEDIA_GIF_DECODER_H_ + +#include +#include +#include + +#include + +namespace Tizen { namespace Media +{ + +class _GifDecoderImpl; + +/** + * @class GifDecoder + * @brief This class supports GIF image decoding. + * + * @since 2.0 + * + * The %GifDecoder class provides APIs for GIF image decoding. @n + * This class also supports animated GIF decoding. + * + * The following example demonstrates how to use the %GifDecoder class. + * + * @code + * #include + * #include + * #include + * #include + * + * using namespace Tizen::Base; + * using namespace Tizen::Graphics; + * using namespace Tizen::Media; + * + * result + * GifDecoderSample(void) + * { + * result r; + * GifDecoder dec; + * long duration; + * Bitmap *pBmp = null; + * String filePath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/test.gif"; + * + * r = dec.Construct(filePath, MEDIA_PIXEL_FORMAT_BGRA8888); + * if (IsFailed(r)) + * { + * return r; + * } + * + * while ((pBmp = dec.GetNextBitmapN(duration)) != null) + * { + * AppLog("dimension:%dx%d duration=%d", pBmp->GetWidth(), pBmp->GetHeight(), duration); + * + * delete pBmp; + * } + * + * return E_SUCCESS; + * } + * @endcode + */ +class _OSP_EXPORT_ GifDecoder + : public Tizen::Base::Object +{ +public: + /** + * This is the default constructor for this class. + * + * @since 2.0 + * + * @see Construct() + */ + GifDecoder(void); + + /** + * This is the destructor for this class. + * + * @since 2.0 + * + * @see Construct() + */ + virtual ~GifDecoder(void); + + /** + * Initializes this instance of %GifDecoder with the specified file path and pixel format. + * + * @if OSPCOMPAT + * @brief [Compatibility] + * @endif + * @since 2.0 + * @if OSPCOMPAT + * @compatibility This method has compatibility issues with OSP compatible applications. @n + * For more information, see @ref CompIoPathPage "here". + * @endif + * + * @return An error code + * @param[in] filePath The file path of the source image + * @param[in] pixelFormat The output pixel format of the decoded image + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_DATA The input data is invalid. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @exception E_INVALID_ARG The specified pixel format is not supported. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @remarks Supported pixel formats are @c MEDIA_PIXEL_FORMAT_RGB565LE, and @c MEDIA_PIXEL_FORMAT_BGRA8888. + */ + result Construct(const Tizen::Base::String& filePath, MediaPixelFormat pixelFormat); + + /** + * Initializes this instance of %GifDecoder with the specified buffer data and pixel format. + * + * @since 2.0 + * + * @return An error code + * @param[in] srcBuf The source buffer where the image data is stored + * @param[in] pixelFormat The output pixel format of the decoded image + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_DATA The input data is invalid. + * @exception E_INVALID_ARG The specified pixel format is not supported. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @remarks Supported pixel formats are @c MEDIA_PIXEL_FORMAT_RGB565LE, and @c MEDIA_PIXEL_FORMAT_BGRA8888. + */ + result Construct(const Tizen::Base::ByteBuffer& srcBuf, MediaPixelFormat pixelFormat); + + /** + * Gets the width of the image. + * + * @since 2.0 + * + * @return The width of the image, @n + * else @c 0 if an error occurs + */ + int GetWidth(void) const; + + /** + * Gets the height of the image. + * + * @since 2.0 + * + * @return The height of the image, @n + * else @c 0 if an error occurs + */ + int GetHeight(void) const; + + /** + * Decodes and gets the next frame in raw RGB format. + * + * @since 2.0 + * + * @return The next decoded frame, @n + * else @c null if no frame is left or an error occurs + * @param[out] duration The duration of returned frame in milliseconds + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_DATA The data of the next frame is invalid. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Base::ByteBuffer* GetNextFrameN(long& duration); + + /** + * Decodes and gets the next frame in bitmap format. + * + * @since 2.0 + * + * @return The next decoded frame, @n + * else @c null if no frame is left or an error occurs + * @param[out] duration The duration of returned frame in milliseconds + * @param[in] bufferScaling The buffer scaling type of Bitmap + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_DATA The data of the next frame is invalid. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Graphics::Bitmap* GetNextBitmapN(long& duration, Tizen::Graphics::BufferScaling bufferScaling = Tizen::Graphics::BUFFER_SCALING_AUTO); + +private: + GifDecoder(const GifDecoder& rhs); + GifDecoder& operator =(const GifDecoder& rhs); + + friend class _GifDecoderImpl; + class _GifDecoderImpl *__pDecImpl; +}; // class GifDecoder + +}} // Tizen::Media + +#endif // FMEDIA_GIFDECODER_H_ diff --git a/inc/FMediaIImageEventListener.h b/inc/FMediaIImageEventListener.h new file mode 100644 index 0000000..089b400 --- /dev/null +++ b/inc/FMediaIImageEventListener.h @@ -0,0 +1,100 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMediaIImageEventListener.h + * @brief This is the header file for the %IImageDecodeUrlEventListener interface. + * + * This header file contains the declarations of the %IImageDecodeUrlEventListener interface. + */ + +#ifndef _FMEDIA_IIMAGE_EVENT_LISTENER_H_ +#define _FMEDIA_IIMAGE_EVENT_LISTENER_H_ + +#include +#include +#include + +namespace Tizen { namespace Media +{ + +/** + * @interface IImageDecodeUrlEventListener + * @brief This interface provides a listener that receives events associated with the Image::DecodeUrl() method. + * + * @since 2.0 + * + * The %IImageDecodeUrlEventListener interface provides a listener that receives events associated with the Image::DecodeUrl() method, including specifying the methods used to get the decoded bitmap data from the remote URL. + * The %Image::DecodeUrl() method works asynchronously. Therefore, it is important to implement this listener to ensure that the decoding flows correctly. + * When an operation of each method is completed, an event is generated and a method of this interface is called. + * + * For more information on the class features, see Viewing and Processing Still Images. + */ +class _OSP_EXPORT_ IImageDecodeUrlEventListener + : virtual public Tizen::Base::Runtime::IEventListener +{ + +public: + /** + * This is the destructor for this class. + * + * @since 2.0 + */ + virtual ~IImageDecodeUrlEventListener(void) {} + + /** + * Called when a Image::DecodeUrl() operation is completed. + * + * @since 2.0 + * + * @param[in] reqId The requested ID + * @param[in] pBitmap The downloaded bitmap data + * @param[in] r The result of the upload + * @param[in] errorCode The error code + * @param[in] errorMessage The error message + * @remarks The Image object must not be deleted in this event listener. @n@n + * This method passes auto-scaled bitmap, @n + * so the dimension can be different to the requested dimension when the passed bitmap is locked. + * @see Image::DecodeUrl() + */ + virtual void OnImageDecodeUrlReceived(RequestId reqId, Tizen::Graphics::Bitmap* pBitmap, result r, const Tizen::Base::String errorCode, const Tizen::Base::String errorMessage) = 0; + +protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void IImageDecodeUrlEventListener_Reserved1(void){} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void IImageDecodeUrlEventListener_Reserved2(void){} + +}; // class IImageDecodeUrlEventListener + +}; +}; // Tizen::Media + +#endif diff --git a/inc/FMediaImage.h b/inc/FMediaImage.h new file mode 100644 index 0000000..1d2806d --- /dev/null +++ b/inc/FMediaImage.h @@ -0,0 +1,665 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** +* @file FMediaImage.h +* @brief This is the header file for the %Image class. +* +* This header file contains the declarations of the %Tizen::Media::Image class. +*/ + +#ifndef _FMEDIA_IMAGE_H_ +#define _FMEDIA_IMAGE_H_ + +// include +#include +#include +#include +#include + +namespace Tizen { namespace Media +{ + +/** + * @class Image + * @brief This class is used for handling images. + * + * @since 2.0 + * + * The %Image class is used for handling images, including image decoding, encoding, conversion, and JPEG compression. @n + * @remarks The minimum dimension is 16x16 for JPEG encoding and 8x8 for PNG encoding. + * + * For more information on the class features, see Viewing and Processing Still Images. @n + * The following example demonstrates how to use the %Image class for image decoding and encoding. + * + * @code +#include +#include +#include +#include +#include +#include + +using namespace Tizen::Base; +using namespace Tizen::Io; +using namespace Tizen::Graphics; +using namespace Tizen::Ui::Controls; +using namespace Tizen::Media; + +class ImageSample + : public Tizen::Ui::Controls::Form +{ +public: + result TestDecoding(void); + result TestEncoding(void); +}; + +result +ImageSample::TestDecoding(void) +{ + result r = E_SUCCESS; + Image img; + Bitmap* pBitmap = null; + Canvas *pCanvas = null; + String filePath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/test.jpg"; + + img.Construct(); + + // Decodes the image + pBitmap = img.DecodeN(filePath, BITMAP_PIXEL_FORMAT_RGB565); + if (pBitmap == null) + { + goto CATCH; + } + + // Gets a Canvas instance + pCanvas = GetCanvasN(); + if (pCanvas == null) + { + goto CATCH; + } + + pCanvas->DrawBitmap(Point(0,0), *pBitmap); + pCanvas->Show(); + + return r; + +CATCH: + if (pCanvas) + { + delete pCanvas; + } + if (pBitmap) + { + delete pBitmap; + } + + return r; +} + +result +ImageSample::TestEncoding(void) +{ + result r = E_SUCCESS; + Image img; + Bitmap* pBitmap = null; + String filePath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/test.jpg"; + String dstPath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/test_out.jpg"; + + img.Construct(); + + pBitmap = img.DecodeN(filePath, BITMAP_PIXEL_FORMAT_RGB565); + if (pBitmap == null) + { + goto CATCH; + } + + r = img.EncodeToFile(*pBitmap, IMG_FORMAT_JPG, dstPath, true); + if (IsFailed(r)) + { + goto CATCH; + } + + return r; + +CATCH: + if (pBitmap) + { + delete pBitmap; + } + + return r; +} + + * @endcode + */ + +class _OSP_EXPORT_ Image + : public Tizen::Base::Object +{ +public: + + /** + * This is the default constructor for this class. @n + * The object is not fully constructed after this constructor is called. + * For full construction, the Construct() method must be called right after + * calling this constructor. + * + * @since 2.0 + * + * @see Construct() + */ + Image(void); + + /** + * This is the destructor for this class. @n + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.0 + * + * @see Construct() + */ + virtual ~Image(void); + +public: + /** + * Initializes this instance of %Image. + * + * @since 2.0 + * + * @return An error code + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + */ + result Construct(void); + + /** + * Decodes an image file into the decoded bitmap container. @n + * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP. + * + * @if OSPCOMPAT + * @brief [Compatibility] + * @endif + * @since 2.0 + * @if OSPCOMPAT + * @compatibility This method has compatibility issues with OSP compatible applications. @n + * For more information, see @ref CompIoPathPage "here". + * @endif + * + * @return A decoded bitmap that is not resized + * @param[in] srcImagePath The local file path of the image file to open + * @param[in] pixelFormat The output pixel format defined by Tizen::Graphics::BitmapPixelFormat + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified pixel format is not supported. + * @exception E_INVALID_DATA The specified input instance has invalid data. + * @exception E_OVERFLOW The specified input instance has overflowed. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @remarks This method retains the aspect ratio of the original image. @n + * @c E_OUT_OF_MEMORY can be returned if there is no available memory when decoding a large image. @n + * The specific error code can be accessed using the GetLastResult() method. @n + * This method returns auto-scaled bitmap, @n + * so the dimension can be different from the dimension of source image when the returned bitmap is locked. + */ + Tizen::Graphics::Bitmap* DecodeN(const Tizen::Base::String& srcImagePath, Tizen::Graphics::BitmapPixelFormat pixelFormat) const; + + /** + * Decodes an image file into the decoded bitmap container after resizing it as per the specified width and height. @n + * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP. + * + * @if OSPCOMPAT + * @brief [Compatibility] + * @endif + * @since 2.0 + * @if OSPCOMPAT + * @compatibility This method has compatibility issues with OSP compatible applications. @n + * For more information, see @ref CompIoPathPage "here". + * @endif + * + * @return A decoded bitmap data with the specified destination width and height + * @param[in] srcImagePath The local file path of the image file to open + * @param[in] pixelFormat The output pixel format defined by Tizen::Graphics::BitmapPixelFormat + * @param[in] destWidth The intended width of the image @n + * An exception is returned if the value is less than @c 0. + * @param[in] destHeight The intended height of the image @n + * An exception is returned if the value is less than @c 0. + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified pixel format is not supported. + * @exception E_INVALID_DATA The specified input instance has invalid data. + * @exception E_OVERFLOW The specified input instance has overflowed. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @exception E_OUT_OF_RANGE The specified size is out of range. + * @remarks This method retains the aspect ratio of the original image. @n + * It supports only the downscaling of an image. @n + * The specific error code can be accessed using the GetLastResult() method. @n + * This method returns auto-scaled bitmap, @n + * so the dimension can be different from the requested dimension when the returned bitmap is locked. + */ + Tizen::Graphics::Bitmap* DecodeN(const Tizen::Base::String& srcImagePath, Tizen::Graphics::BitmapPixelFormat pixelFormat, int destWidth, int destHeight) const; + + /** + * Decodes an image data into the decoded bitmap as per the specified width and height. @n + * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP. + * + * @since 2.0 + * + * @return An error code + * @param[in] srcImageUrl The URL of the remote image to decode + * @param[in] pixelFormat The output pixel format defined by Tizen::Graphics::BitmapPixelFormat + * @param[in] destWidth The intended width of the image @n + * An exception is returned if the value is less than @c 0. + * @param[in] destHeight The intended height of the image @n + * An exception is returned if the value is less than @c 0. + * @param[out] reqId The request ID + * @param[in] listener An instance of IImageDecodeUrlEventListener + * @param[in] timeout The timeout period in milliseconds @n + * Set to @c TIMEOUT_INFINITE to make the @c timeout period infinite. + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_DATA The specified input instance has invalid data. + * @exception E_INVALID_ARG The specified pixel format is not supported. + * @exception E_OUT_OF_RANGE The specified size is out of range. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_NETWORK_FAILED The network is unavailable. + * @exception E_MAX_EXCEEDED The number of concurrent accesses to the URLs has reached the maximum limit. + * @remarks This method retains the aspect ratio of the original image. @n + * It supports only the downscaling of an image. @n + * The maximum limit for downscaling is 3. @n + * The supported protocol is HTTP. + */ + result DecodeUrl(const Tizen::Base::Utility::Uri& srcImageUrl, Tizen::Graphics::BitmapPixelFormat pixelFormat, int destWidth, int destHeight, RequestId& reqId, const IImageDecodeUrlEventListener& listener, long timeout) const; + + /** + * Decodes an image data into the decoded bitmap container without resizing. @n + * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP. The %DecodeN() method retains the + * aspect ratio of the original image. + * + * @since 2.0 + * + * @return A decoded bitmap data that has not been resized + * @param[in] srcImageBuf The data to decode + * @param[in] srcImageFormat The image format of the input file + * @param[in] pixelFormat The output pixel format defined by Tizen::Graphics::BitmapPixelFormat + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_DATA The specified input instance has invalid data. + * @exception E_INVALID_ARG The specified pixel format is not supported. + * @exception E_OVERFLOW The specified input instance has overflowed. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OBJ_NOT_FOUND The specified image buffer cannot be found. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks This method retains the aspect ratio of the original image. @n + * @c E_OUT_OF_MEMORY is returned if the memory is not available when decoding a large image. @n + * The specific error code can be accessed using the GetLastResult() method. @n + * This method returns auto-scaled bitmap, @n + * so the dimension can be different from the dimension of source image when the returned bitmap is locked. + */ + Tizen::Graphics::Bitmap* DecodeN(const Tizen::Base::ByteBuffer& srcImageBuf, ImageFormat srcImageFormat, Tizen::Graphics::BitmapPixelFormat pixelFormat) const; + + /** + * Decodes an image data into the decoded bitmap container after resizing it as per the specified width and height. @n + * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP. + * + * @since 2.0 + * + * @return A decoded bitmap data with the specified destination width and height + * @param[in] srcImageBuf The data to decode + * @param[in] srcImageFormat The image format of the input file + * @param[in] pixelFormat The output pixel format defined by Tizen::Graphics::BitmapPixelFormat + * @param[in] destWidth The intended width of the image @n + * An exception is returned if the value is less than @c 0. + * @param[in] destHeight The intended height of the image @n + * An exception is returned if the value is less than @c 0. + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified pixel format is not supported. + * @exception E_INVALID_DATA The specified input instance has invalid data. + * @exception E_OVERFLOW The specified input instance has overflowed. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_OBJ_NOT_FOUND The specified image buffer cannot be found. + * @exception E_OUT_OF_RANGE The specified size is out of range. + * @remarks This method retains the aspect ratio of the original image. @n + * It supports only the downscaling of an image. @n + * The specific error code can be accessed using the GetLastResult() method. @n + * This method returns auto-scaled bitmap, @n + * so the dimension can be different from the requested dimension when the returned bitmap is locked. + */ + Tizen::Graphics::Bitmap* DecodeN(const Tizen::Base::ByteBuffer& srcImageBuf, ImageFormat srcImageFormat, Tizen::Graphics::BitmapPixelFormat pixelFormat, int destWidth, int destHeight) const; + + /** + * Encodes the specified bitmap data into a byte buffer. @n + * The currently supported encoding formats are JPEG, BMP, and PNG. + * + * @since 2.0 + * + * @return A byte buffer containing encoded image data + * @param[in] srcBitmap The bitmap data to encode + * @param[in] destImageFormat The intended image format + * @exception E_SUCCESS The method is successful. + * @exception E_OVERFLOW The specified input instance has overflowed. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_OBJ_NOT_FOUND The specified bitmap data cannot be found. + * @remarks The specific error code can be accessed using the GetLastResult() method. @n + * This method uses raw RGB data from locked bitmap, @n + * so the dimension of encoded data can be different from the dimension of source bitmap if the bitmap is auto-scaled. + */ + Tizen::Base::ByteBuffer* EncodeToBufferN(const Tizen::Graphics::Bitmap& srcBitmap, ImageFormat destImageFormat) const; + + /** + * Encodes the specified bitmap data into a file. @n + * The currently supported encoding formats are JPEG, BMP, and PNG. + * + * @if OSPCOMPAT + * @brief [Compatibility] + * @endif + * @since 2.0 + * @if OSPCOMPAT + * @compatibility This method has compatibility issues with OSP compatible applications. @n + * For more information, see @ref CompIoPathPage "here". + * @endif + * + * @return An error code + * @param[in] srcBitmap The bitmap data to encode + * @param[in] destImageFormat The intended image format + * @param[in] destImagePath The intended name of encoded image file @n + * The available paths start with prefixes retrieved from the functions such as: @n + * Tizen::App::App::GetInstance()->GetAppRootPath() @n + * Tizen::System::Environment::GetMediaPath() @n + * Tizen::System::Environment::GetExternalStoragePath() + * @param[in] overwrite Set to @c true to overwrite the file, @n + * else @c false + * @exception E_SUCCESS The method is successful. + * @exception E_OVERFLOW The specified input instance has overflowed. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @exception E_OBJ_NOT_FOUND The specified bitmap data cannot be found. + * @exception E_FILE_ALREADY_EXIST The specified file already exists. + * @exception E_SYSTEM A system error has occurred. + * @exception E_STORAGE_FULL The storage is full. + * @remarks The specific error code can be accessed using the GetLastResult() method. @n + * The application should use Tizen::Content::ContentManager::CreateContent() to register the created file into the Contents database. @n + * This method uses raw RGB data from locked bitmap, @n + * so the dimension of encoded data can be different from the dimension of source bitmap if the bitmap is auto-scaled. + */ + result EncodeToFile(const Tizen::Graphics::Bitmap& srcBitmap, ImageFormat destImageFormat, const Tizen::Base::String& destImagePath, bool overwrite) const; + + /** + * Converts the image file to the specified image format. @n + * This is a synchronous method. The converting formats currently supported are JPEG, BMP, and PNG. + * + * @if OSPCOMPAT + * @brief [Compatibility] + * @endif + * @since 2.0 + * @if OSPCOMPAT + * @compatibility This method has compatibility issues with OSP compatible applications. @n + * For more information, see @ref CompIoPathPage "here". + * @endif + * + * @return The byte buffer containing image data + * @param[in] srcImagePath The local file path of the image file to open + * @param[in] destImageFormat The intended image format + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_DATA The specified input instance has invalid data. + * @exception E_OVERFLOW The specified input instance has overflowed. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Base::ByteBuffer* ConvertN(const Tizen::Base::String& srcImagePath, ImageFormat destImageFormat) const; + + /** + * @if OSPDEPREC + * @{ + * Compresses an encoded image file to reduce its size as per the specified limit. @n + * The only supported compression format is JPEG. + * + * @if OSPCOMPAT + * @brief [Deprecated] [Compatibility] + * @endif + * @deprecated This method is deprecated. + * @since 2.0 + * @if OSPCOMPAT + * @compatibility This method has compatibility issues with OSP compatible applications. @n + * For more information, see @ref CompIoPathPage "here". + * @endif + * + * @return An error code + * @param[in] srcImagePath The local file path of the image file to open + * @param[in] destImagePath The destination file path @n + * If the file already exists, it is overwritten. @n + * The available paths start with prefix such as: @n + * Tizen::App::App::GetInstance()->GetAppRootPath() @n + * Tizen::System::Environment::GetMediaPath() @n + * Tizen::System::Environment::GetExternalStoragePath() + * @param[in] limitSize The maximum compressed data size in bytes @n + * If the data size is too small, the width and height of the original + * image can be reduced. @n The size must be less than the original size + * and greater than @c 1024 byte. + * @exception E_SUCCESS The method is successful. + * @exception E_OVERFLOW The specified input instance has overflowed. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_SYSTEM A system error has occurred. + * @exception E_STORAGE_FULL The file cannot be created because the file has reached its size limit. + * @exception E_OUT_OF_RANGE The specified size is out of range. + * @} + * @endif + */ + result CompressJpeg(const Tizen::Base::String& srcImagePath, const Tizen::Base::String& destImagePath, int limitSize) const; + + /** + * @if OSPDEPREC + * Compresses an encoded image data to the byte buffer to reduce its data size as per the specified limit. @n + * The only supported compression format is JPEG. + * + * @brief [Deprecated] + * @deprecated This method is deprecated. + * @since 2.0 + * + * @return A byte buffer containing the compressed image data as per the specified size + * @param[in] srcImageBuf The encoded image source in the byte buffer + * @param[in] limitSize The limit size to compress in bytes @n + * The size must be less than the original size and greater than @c 1024 bytes. + * @exception E_SUCCESS The method is successful. + * @exception E_OVERFLOW The specified input instance has overflowed. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OBJ_NOT_FOUND The specified image buffer cannot be found. + * @exception E_SYSTEM A system error has occurred. + * @exception E_OUT_OF_RANGE The specified size is out of range. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @endif + */ + Tizen::Base::ByteBuffer* CompressJpegN(const Tizen::Base::ByteBuffer& srcImageBuf, int limitSize) const; + + /** + * Decodes an image data into the decoded byte buffer container without resizing. @n + * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP. + * + * @since 2.0 + * + * @return A decoded byte data that is not resized, @n + * else @c null if an exception occurs + * @param[in] srcImageBuf The data to decode + * @param[in] srcImageFormat The image format of the input data + * @param[in] pixelFormat The output pixel format defined by Tizen::Graphics::BitmapPixelFormat + * @param[out] imageWidth The original width of the image @n + * An exception is returned if the value is less than @c 0. + * @param[out] imageHeight The original height of the image @n + * An exception is returned if the value is less than @c 0. + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified color format is not supported. + * @exception E_INVALID_DATA The specified input instance has invalid data. + * @exception E_OVERFLOW The specified input instance has overflowed. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_OBJ_NOT_FOUND The specified media buffer cannot be found. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Base::ByteBuffer* DecodeToBufferN(const Tizen::Base::ByteBuffer& srcImageBuf, ImageFormat srcImageFormat, Tizen::Graphics::BitmapPixelFormat pixelFormat, int& imageWidth, int& imageHeight) const; + + /** + * Decodes an image file into the decoded byte buffer container without resizing. @n + * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP. + * + * @if OSPCOMPAT + * @brief [Compatibility] + * @endif + * @since 2.0 + * @if OSPCOMPAT + * @compatibility This method has compatibility issues with OSP compatible applications. @n + * For more information, see @ref CompIoPathPage "here". + * @endif + * + * @return A decoded byte data that is not resized, @n + * else @c null if an exception occurs + * @param[in] srcImagePath The local file path of the image file to decode + * @param[in] pixelFormat The output pixel format defined by Tizen::Graphics::BitmapPixelFormat + * @param[out] imageWidth The original width of the image @n + * An exception is returned if the value is less than @c 0. + * @param[out] imageHeight The original height of the image @n + * An exception is returned if the value is less than @c 0. + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified color format is not supported. + * @exception E_INVALID_DATA The specified input instance has invalid data. + * @exception E_OVERFLOW The specified input instance has overflowed. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Base::ByteBuffer* DecodeToBufferN(const Tizen::Base::String& srcImagePath, Tizen::Graphics::BitmapPixelFormat pixelFormat, int& imageWidth, int& imageHeight) const; + + /** + * Sets the timeout interval to infinity. + * + * @since 2.0 + */ + static const int TIMEOUT_INFINITE = 0; + + + /** + * Gets the format of the image in the specified file. + * + * @if OSPCOMPAT + * @brief [Compatibility] + * @endif + * @since 2.0 + * @if OSPCOMPAT + * @compatibility This method has compatibility issues with OSP compatible applications. @n + * For more information, see @ref CompIoPathPage "here". + * @endif + * + * @return The format of the image + * @param[in] srcImagePath The local path of the image file + * @exception E_SUCCESS The method is successful. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_SYSTEM A system error has occurred. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Media::ImageFormat GetImageFormat(const Tizen::Base::String& srcImagePath) const; + + /** + * Gets the image format from an image buffer. + * + * @since 2.0 + * + * @return The format of the image + * @param[in] srcImageBuf The Tizen::Base::ByteBuffer containing the image data + * @exception E_SUCCESS The method is successful. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OBJ_NOT_FOUND The specified image buffer cannot be found. + * @exception E_SYSTEM A system error has occurred. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Media::ImageFormat GetImageFormat(const Tizen::Base::ByteBuffer& srcImageBuf) const; + + /** + * Checks whether the specified image file has alpha channels. @n + * Currently, only 32-bit PNG images are supported. + * + * @if OSPCOMPAT + * @brief [Compatibility] + * @endif + * @since 2.0 + * @if OSPCOMPAT + * @compatibility This method has compatibility issues with OSP compatible applications. @n + * For more information, see @ref CompIoPathPage "here". + * @endif + * + * @return @c true if the image has alpha channels, @n + * else @c false + * @param[in] srcImagePath The local file path of the image file + * @exception E_SUCCESS The method is successful. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_FILE_NOT_FOUND The specified image file cannot be found. + * @exception E_SYSTEM A system error has occurred. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + bool HasAlphaChannels(const Tizen::Base::String& srcImagePath) const; + + /** + * Checks whether the specified image buffer has alpha channels. @n + * Currently only 32-bit PNG images are supported. + * + * @since 2.0 + * + * @return @c true if the image has alpha channels, @n + * else @c false + * @param[in] srcImageBuf The Tizen::Base::ByteBuffer containing the image data + * @exception E_SUCCESS The method is successful. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OBJ_NOT_FOUND The specified image buffer cannot be found. + * @exception E_SYSTEM A system error has occurred. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + bool HasAlphaChannels(const Tizen::Base::ByteBuffer& srcImageBuf) const; + +private: + + /** + * The implementation of this copy constructor is intentionally blank + * and declared as private to prohibit copying of objects. + */ + Image(const Image& image); + + /** + * The implementation of this copy assignment operator is intentionally blank + * and declared as private to prohibit copying of objects. + */ + Image& operator =(const Image& image); + +private: + class _ImageImpl* __pImageImpl; + friend class _ImageImpl; + +}; // class Image + +}; +}; // Tizen::Media + +#endif diff --git a/inc/FMediaImageBuffer.h b/inc/FMediaImageBuffer.h new file mode 100644 index 0000000..055c598 --- /dev/null +++ b/inc/FMediaImageBuffer.h @@ -0,0 +1,479 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMediaImageBuffer.h + * @brief This is the header file for the %ImageBuffer class. + * + * This header file contains the declarations of the %ImageBuffer class. + */ + +#ifndef _FMEDIA_IMAGEBUFFER_H_ +#define _FMEDIA_IMAGEBUFFER_H_ + +#include +#include + +namespace Tizen { namespace Media +{ +/** + * @class ImageBuffer + * @brief This class is used for handling decoded image data. + * + * @since 2.0 + * + * The %ImageBuffer class is used for handling decoded image data, including image decoding and encoding. + * @remarks The minimum dimension is 16x16 for JPEG encoding and 8x8 for PNG encoding. + * + * The following example demonstrates how to use the %ImageBuffer class to decode and encode image. + * + * @code +#include +#include + +using namespace Tizen::Base; +using namespace Tizen::Media; + +result +TestImageBuffer(void) +{ + result r = E_SUCCESS; + ImageBuffer img; + + // Constructs an image buffer instance with an image file + r = img.Construct(Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/test.bmp"); + if (IsFailed(r)) + { + return r; + } + // Encodes the image buffer into compressed data + r = img.EncodeToFile(Tizen::App::App::GetInstance()->GetAppRootPath()+L"data/test.jpg", IMG_FORMAT_JPG, true, 70); + + return r; +} + * @endcode + */ + +class _OSP_EXPORT_ ImageBuffer + : public Tizen::Base::Object +{ +public: + /** + * This is the default constructor for this class. @n + * The object is not fully constructed after this constructor is called. + * For full construction, the Construct() method must be called right after + * calling this constructor. + * + * @since 2.0 + * + * @see Construct() + */ + ImageBuffer(void); + + /** + * This is the destructor for this class. @n + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.0 + * + * @see Construct() + */ + virtual ~ImageBuffer(void); + + /** + * Initializes this instance of %ImageBuffer with the specified parameters. + * + * @since 2.0 + * + * @return An error code + * @param[in] width The width of image + * @param[in] height The height of image + * @param[in] pixelFormat The pixel format of image should be one of values returned from GetSupportedPixelFormatListN() + * @param[in] data The raw pixel data of image @n If @c data is not @c null then it will be copied into internal buffer of this instance. + * If @c null then default color data will be filled. + * @param[in] length The size of data + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG A specified input parameter is invalid. + * @exception E_UNSUPPORTED_FORMAT The specified @c pixelFormat is not supported. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @see GetSupportedPixelFormatListN() + * @remarks It’s a high probability that the out-of-memory exception occurs. Check the exception as possible if it is E_OUT_OF_MEMORY. + * Refer to Exception Check and handle the out-of-memory. + */ + result Construct(int width, int height, MediaPixelFormat pixelFormat, const byte* pData = null, int length = 0); + + /** + * Initializes this instance of %ImageBuffer with the decoded data of the given image path. + * + * @since 2.0 + * + * @return An error code + * @param[in] srcImagePath The source image path + * @param[in] pDecodingRegion The region that will be decoded @n If this is @c null, then the whole image will be decoded. + * @param[in] autoRotate If @c true then the image will be rotated automatically based on EXIF orientation tag + * If @c false then the image will be decoded without rotation. + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG A specified input parameter is invalid. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OVERFLOW The specified input instance exceeds the supported maximum file size or dimension. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @remarks It’s a high probability that the out-of-memory exception occurs. Check the exception as possible if it is E_OUT_OF_MEMORY. + * Refer to Exception Check and handle the out-of-memory. + */ + result Construct(const Tizen::Base::String &srcImagePath, const Tizen::Graphics::Rectangle *pDecodingRegion = null, bool autoRotate = true); + + /** + * Initializes this instance of %ImageBuffer with the decoded data of the given image buffer. + * + * @since 2.0 + * + * @return An error code + * @param[in] srcImageBuf The buffer that contains compressed image data + * @param[in] pDecodingRegion The region that will be decoded @n If this is @c null, then the whole image will be decoded. + * @param[in] autoRotate If @c true then the image will be rotated automatically based on EXIF orientation tag + * If @c false then the image will be decoded without rotation. + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG A specified input parameter is invalid. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OVERFLOW The specified input instance exceeds the supported maximum file size or dimension. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks It’s a high probability that the out-of-memory exception occurs. Check the exception as possible if it is E_OUT_OF_MEMORY. + * Refer to Exception Check and handle the out-of-memory. + */ + result Construct(const Tizen::Base::ByteBuffer &srcImageBuf, const Tizen::Graphics::Rectangle *pDecodingRegion = null, bool autoRotate = true); + + /** + * Initializes this instance of %ImageBuffer with the given bitmap data. @n + * The %Construct() method copies the raw RGB data from the @c srcBitmap, + * so the dimension of this instance can be different from that of @c srcBitmap if the @c srcBitmap is an auto-scaled bitmap. + * + * @since 2.0 + * + * @return An error code + * @param[in] srcBitmap The source bitmap data + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified input parameter is invalid. + * @exception E_OVERFLOW The specified input instance exceeds the supported maximum file size or dimension. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + */ + result Construct(const Tizen::Graphics::Bitmap &srcBitmap); + + /** + * Converts an instance of the Tizen::Base::Object class to an instance of %ImageBuffer and then + * compares it with the calling %ImageBuffer instance. + * + * @since 2.0 + * + * @return @c true if the value of @c rhs matches the value of the calling %ImageBuffer instance, @n + * else @c false + * @param[in] rhs A reference to the Tizen::Base::Object instance that is to compare with the calling %ImageBuffer instance + * @see Tizen::Base::Object::Equals() + */ + virtual bool Equals(const Object& rhs) const; + + /** + * Gets the hash value of the current instance by overriding the GetHashCode() method in the Tizen::Base::Object class. + * + * @since 2.0 + * + * @return The hash value of the current instance + */ + virtual int GetHashCode(void) const; + + /** + * Gets the height of the image buffer. + * + * @since 2.0 + * + * @return The height of the image buffer + */ + int GetHeight(void) const; + + /** + * Gets the width of the image buffer. + * + * @since 2.0 + * + * @return The width of the image buffer + */ + int GetWidth(void) const; + + /** + * Gets the current pixel format. + * + * @since 2.0 + * + * @return The pixel format of the media + */ + MediaPixelFormat GetPixelFormat(void) const; + + /** + * Encodes the data of this instance into a byte buffer. @n + * The supported encoding formats are JPEG, BMP, and PNG. + * + * @since 2.0 + * + * @return A pointer to the Tizen::Base::ByteBuffer instance containing the encoded image data + * @param[in] destImageFormat The intended image format + * @param[in] quality The encoding quality @n + * Valid range of this parameter is @c 1 to @c 100. + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_RANGE A specified input parameter is out of range. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Base::ByteBuffer* EncodeToBufferN(ImageFormat destImageFormat, int quality = 90) const; + + /** + * Encodes the data of this instance to a file. @n + * The supported encoding formats are JPEG, BMP, and PNG. + * + * @since 2.0 + * + * @return An error code + * @param[in] destImagePath The intended name of encoded image file + * @param[in] destImageFormat The intended image format + * @param[in] overwrite Set to @c true to overwrite the file, @n + * else @c false + * @param[in] quality The encoding quality @n + * Valid range of this parameter is @c 1 to @c 100. + * @exception E_SUCCESS The method is successful. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_ILLEGAL_ACCESS The specified file cannot be found or accessed. + * @exception E_FILE_ALREADY_EXIST The specified file already exists and the value of @c overwrite is @c false. + * @exception E_OUT_OF_RANGE A specified input parameter is out of range. + * @remarks The application should use Tizen::Content::ContentManager::CreateContent() to + * register the created file into the Contents database. + */ + result EncodeToFile(const Tizen::Base::String &destImagePath, ImageFormat destImageFormat, bool overwrite, int quality = 90) const; + + /** + * Gets an instance of Tizen::Graphics::Bitmap with the data of this instance. + * + * @since 2.0 + * + * @return A pointer to the Tizen::Graphics::Bitmap instance + * @param[in] pixelFormat The bitmap pixel format + * @param[in] bufferScaling The buffer scaling type + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG A specified input parameter is invalid. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Graphics::Bitmap* GetBitmapN(Tizen::Graphics::BitmapPixelFormat pixelFormat, Tizen::Graphics::BufferScaling bufferScaling) const; + + /** + * Gets an instance of Tizen::Base::ByteBuffer with the data of this instance. + * + * @since 2.0 + * + * @return A pointer to the Tizen::Base::ByteBuffer instance + * @param[in] pixelFormat The pixel format + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified input parameter is invalid. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @see GetSupportedPixelFormatListN() + */ + Tizen::Base::ByteBuffer* GetByteBufferN(MediaPixelFormat pixelFormat) const; + + /** + * Creates and returns a copy of this instance. + * + * @since 2.0 + * + * @return A copy of this instance + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + virtual ImageBuffer* CloneN(void) const; + + /** + * Gets a new %ImageBuffer with the converted pixel format of the current image data. + * + * @since 2.0 + * + * @return A pointer to the %ImageBuffer instance containing the converted %ImageBuffer by specified MediaPixelFormat + * @param[in] pixelFormat The pixel format for returned %ImageBuffer + * @exception E_SUCCESS The method is successful. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_INVALID_DATA The current data is invalid for this operation. @n + * This will happen when the width or height is not even value, + * and the requested pixel format is sub-sampled pixel format like MEDIA_PIXEL_FORMAT_YUV420P. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @remarks It’s a high probability that the out-of-memory exception occurs. Check the exception as possible if it is E_OUT_OF_MEMORY. + * Refer to Exception Check and handle the out-of-memory. + */ + ImageBuffer* ConvertPixelFormatN(MediaPixelFormat pixelFormat) const; + + /** + * Gets a resized %ImageBuffer with the current image data. @n + * The aspect ratio of the data will not be preserved. + * + * @since 2.0 + * + * @return A pointer to the %ImageBuffer instance containing the resized image data + * @param[in] width The width of the destination image + * @param[in] height The height of the destination image + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_RANGE A specified input parameter is out of range. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_INVALID_DATA The current data is invalid for this operation. @n + * This will happen when the current pixel format is sub-sampled pixel format like @c MEDIA_PIXEL_FORMAT_YUV420P + * and the requested @c width or @c height is not even value. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @remarks It’s a high probability that the out-of-memory exception occurs. Check the exception as possible if it is E_OUT_OF_MEMORY. + * Refer to Exception Check and handle the out-of-memory. + */ + ImageBuffer* ResizeN(int width, int height) const; + + /** + * Gets a horizontally or vertically flipped image from current instance. + * + * @since 2.0 + * + * @return A pointer to the %ImageBuffer instance containing the flipped image data + * @param[in] flipType The flip type + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified input parameter is invalid. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @remarks It’s a high probability that the out-of-memory exception occurs. Check the exception as possible if it is E_OUT_OF_MEMORY. + * Refer to Exception Check and handle the out-of-memory. + */ + ImageBuffer* FlipN(ImageFlipType flipType) const; + + /** + * Gets a rotated image in clockwise direction from current image. + * + * @since 2.0 + * + * @return A pointer to the %ImageBuffer instance containing the rotated image data + * @param[in] rotateType The rotation type + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified input parameter is invalid. + * @exception E_INVALID_DATA The current data is invalid for this operation. @n + * This will happen when the current pixel format is sub-sampled pixel format like @c MEDIA_PIXEL_FORMAT_YUYV422 + * and the height is odd value and the requested rotation type is @c IMAGE_ROTATION_90 or @c IMAGE_ROTATION_270. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @remarks It’s a high probability that the out-of-memory exception occurs. Check the exception as possible if it is E_OUT_OF_MEMORY. + * Refer to Exception Check and handle the out-of-memory. + */ + ImageBuffer* RotateN(ImageRotationType rotateType) const; + + /** + * Crops the region of the current %ImageBuffer. + * + * @since 2.0 + * + * @return A pointer to the %ImageBuffer instance containing the cropped image data + * @param[in] x The x position + * @param[in] y The y position + * @param[in] width The width of the destination image + * @param[in] height The height of the destination image + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_RANGE A specified input parameter is out of range. + * @exception E_INVALID_DATA The current data is invalid for this operation. @n + * This will happen when the current pixel format is sub-sampled pixel format like MEDIA_PIXEL_FORMAT_YUV420P + * and the requested x, y, width, or height is not even value. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @remarks It’s a high probability that the out-of-memory exception occurs. Check the exception as possible if it is E_OUT_OF_MEMORY. + Refer to Exception Check and handle the out-of-memory. + */ + ImageBuffer* CropN(int x, int y, int width, int height) const; + + /** + * Gets the image information. + * + * @since 2.0 + * + * @return An error code + * @param[in] srcImagePath The source image path + * @param[out] imageFormat The format of image + * @param[out] width The width of image + * @param[out] height The height of image + * @exception E_SUCCESS The method is successful. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @exception E_SYSTEM A system error has occurred. + */ + static result GetImageInfo(const Tizen::Base::String& srcImagePath, ImageFormat &imageFormat, int &width, int &height); + + /** + * Gets the image information. + * + * @since 2.0 + * + * @return An error code + * @param[in] srcImageBuf The buffer that contains compressed image data + * @param[out] imageFormat The format of image + * @param[out] width The width of image + * @param[out] height The height of image + * @exception E_SUCCESS The method is successful. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + */ + static result GetImageInfo(const Tizen::Base::ByteBuffer& srcImageBuf, ImageFormat &imageFormat, int &width, int &height); + + /** + * Gets a list of the supported pixel formats. + * + * @since 2.0 + * + * @return A list of the pixel formats supported by the %ImageBuffer class, @n + * else @c null if an exception occurs + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @see Construct() + * @see GetByteBufferN() + */ + static Tizen::Base::Collection::IListT* GetSupportedPixelFormatListN(void); + +private: + + /** + * The implementation of this copy constructor is intentionally blank + * and declared as private to prohibit copying of objects. + */ + ImageBuffer(const ImageBuffer& rhs); + + /** + * The implementation of this copy assignment operator is intentionally blank + * and declared as private to prohibit copying of objects. + * Use CloneN() to get an exact copy of this instance. + * Use Equals() to compare contents of one instance with the other. + */ + ImageBuffer& operator =(const ImageBuffer& rhs); + + friend class _ImageBufferImpl; + class _ImageBufferImpl* __pImpl; + +}; + +}} // Tizen::Media +#endif // _FMEDIA_IMAGEBUFFER_H_ diff --git a/inc/FMediaImageUtil.h b/inc/FMediaImageUtil.h new file mode 100644 index 0000000..69dcff5 --- /dev/null +++ b/inc/FMediaImageUtil.h @@ -0,0 +1,250 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMediaImageUtil.h + * @brief This is the header file for the %ImageUtil class. + * + * This header file contains the declarations of the %ImageUtil class. + */ + +#ifndef _FMEDIA_IMAGE_UTIL_H_ +#define _FMEDIA_IMAGE_UTIL_H_ + +#include +#include + +#include +#include + +namespace Tizen { namespace Media +{ + +class _ImageUtilImpl; + +/** + * @class ImageUtil + * @brief This class provides methods for converting the color space of the image, flipping, rotating, or resizing. + * + * @since 2.0 + * + * The %ImageUtil class provides methods for %Image pixel format conversion and %Image scaling, such as resizing, rotating, and flipping. + * + * For more information on the class features, see Viewing and Processing Still Images. + * + * The following example demonstrates how to use the %ImageUtil class. + * + * @code + +#include +#include +#include +#include +#include + +using namespace Tizen::Base; +using namespace Tizen::Graphics; +using namespace Tizen::Media; + +result +ImageUtilSample(void) +{ + ByteBuffer yuvBuf, rgbBuf; + Bitmap bitmap; + Image image; + int width = 320, height = 240; + int yuvBufSize = width * height * 3 / 2; + int rgbBufSize = width * height * 4; + byte *pBuf = null; + Dimension dim(width, height); + String filePath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/test.jpg"; + + pBuf = new byte[yuvBufSize]; + + // Fills source buffer with a 2x2 checkboard + for (int j = 0; j < height; j++) + { + for (int i = 0; i < width; i++) + { + pBuf[j * width + i] = (((i >= width / 2) + (j >= height / 2)) & 1) ? 255 : 0; // Y + } + } + memset(pBuf + width * height, 128, width * height / 4); // Cb + memset(pBuf + width * height * 5 / 4, 128, width * height / 4); // Cr + + // Creates yuv and rgb buffers + yuvBuf.Construct(pBuf, 0, yuvBufSize, yuvBufSize); + yuvBuf.SetPosition(0); + yuvBuf.SetLimit(yuvBufSize); + + rgbBuf.Construct(rgbBufSize); + rgbBuf.SetPosition(0); + rgbBuf.SetLimit(rgbBufSize); + + image.Construct(); + + // Converts pixel format + ImageUtil::ConvertPixelFormat(yuvBuf, rgbBuf, MEDIA_PIXEL_FORMAT_YUV420P, MEDIA_PIXEL_FORMAT_BGRA8888, dim); + + // Makes a Bitmap with converted rgb data + bitmap.Construct(rgbBuf, dim, BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE); + image.EncodeToFile(bitmap, IMG_FORMAT_JPG, filePath, true); + + delete pBuf; + return E_SUCCESS; +} + + * @endcode + * + */ + +class _OSP_EXPORT_ ImageUtil +{ + +public: + /** + * Converts the pixel format of the image. + * + * @since 2.0 + * + * @return An error code + * @param[in] srcBuf The source buffer + * @param[out] destBuf The destination buffer + * @param[in] srcPixelFormat The source pixel format + * @param[in] destPixelFormat The destination pixel format + * @param[in] dim The width and height of the source and destination images @n + * The value of the width and height must be greater than or equal to @c 1. + * @exception E_SUCCESS The method is successful. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_INVALID_ARG The specified width and height are invalid, or the size of @c srcBuf or @c destBuf is insufficient. + * @exception E_INVALID_DATA A source image data in the buffer is invalid. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @remarks The supported pixel formats are @c MEDIA_PIXEL_FORMAT_RGB565LE, @c MEDIA_PIXEL_FORMAT_BGRA8888, and @c MEDIA_PIXEL_FORMAT_YUV420P. @n + * The conversion is possible between: @n + * - @c MEDIA_PIXEL_FORMAT_YUV420P and @c MEDIA_PIXEL_FORMAT_RGB565LE. @n + * - @c MEDIA_PIXEL_FORMAT_YUV420P and @c MEDIA_PIXEL_FORMAT_BGRA8888. @n + * The position and limit of @c destBuf are set along with the size of the converted data. + */ + static result ConvertPixelFormat(const Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& destBuf, MediaPixelFormat srcPixelFormat, MediaPixelFormat destPixelFormat, const Tizen::Graphics::Dimension& dim); + + /** + * Resizes the image. + * + * @since 2.0 + * + * @return An error code + * @param[in] srcBuf The source buffer + * @param[out] destBuf The destination buffer + * @param[in] srcDim The width and height of the source image @n + * The value of the width and height must be greater than or equal to @c 1. + * @param[in] destDim The width and height of the destination image @n + * The value of the width and height must be greater than or equal to @c 1. + * @param[in] pixelFormat The source and destination pixel format + * @exception E_SUCCESS The method is successful. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_INVALID_ARG The specified width and height are invalid, or the size of @c srcBuf or @c destBuf is insufficient. + * @exception E_INVALID_DATA A source image data in the buffer is invalid. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @remarks The supported pixel formats are @c MEDIA_PIXEL_FORMAT_RGB565LE, @c MEDIA_PIXEL_FORMAT_BGRA8888, and @c MEDIA_PIXEL_FORMAT_YUV420P. @n + * The position and limit of @c destBuf are set along with the size of the resized data. @n + * The minimum resolution is 16x16. + */ + static result Resize(const Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& destBuf, const Tizen::Graphics::Dimension& srcDim, const Tizen::Graphics::Dimension& destDim, MediaPixelFormat pixelFormat); + + /** + * Rotates the image. + * + * @since 2.0 + * + * @return An error code + * @param[in] srcBuf The source buffer + * @param[out] destBuf The destination buffer + * @param[in] dim The width and height of the source image @n + * The value of the width and height must be equal to or greater than @c 1. + * @param[in] rotate The rotation type + * @param[in] pixelFormat The source and destination pixel formats + * @exception E_SUCCESS The method is successful. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_INVALID_ARG The specified width and height are invalid, or the size of @c srcBuf or @c destBuf is insufficient. + * @exception E_INVALID_DATA A source image data in the buffer is invalid. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @remarks The supported pixel formats are @c MEDIA_PIXEL_FORMAT_RGB565LE, @c MEDIA_PIXEL_FORMAT_BGRA8888, and @c MEDIA_PIXEL_FORMAT_YUV420P. @n + * The position and limit of @c destBuf are set along with the size of the rotated data. @n + * The dimension of the destination buffer must be calculated by an application. + * @see ImageRotationType + */ + static result Rotate(const Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& destBuf, const Tizen::Graphics::Dimension& dim, ImageRotationType rotate, MediaPixelFormat pixelFormat); + + /** + * Flips the image. + * + * @since 2.0 + * + * @return An error code + * @param[in] srcBuf The source buffer + * @param[out] destBuf The destination buffer + * @param[in] dim The width and height of the source and destination images @n + * The value of the width and height must be equal to or greater than @c 1. + * @param[in] flip The flip type + * @param[in] pixelFormat The source and destination pixel formats + * @exception E_SUCCESS The method is successful. + * @exception E_UNSUPPORTED_FORMAT The specified format is not supported. + * @exception E_INVALID_ARG The specified width and height are invalid, or the size of @c srcBuf or @c destBuf is insufficient. + * @exception E_INVALID_DATA A source image data in the buffer is invalid. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @remarks The supported pixel formats are @c MEDIA_PIXEL_FORMAT_RGB565LE, @c MEDIA_PIXEL_FORMAT_BGRA8888, and @c MEDIA_PIXEL_FORMAT_YUV420P. @n + * The position and limit of @c destBuf are set along with the size of the flipped data. + * @see ImageFlipType + */ + static result Flip(const Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& destBuf, const Tizen::Graphics::Dimension& dim, ImageFlipType flip, MediaPixelFormat pixelFormat); + +private: + + /** + * This default constructor is intentionally declared as private because + * this class cannot be constructed. + */ + ImageUtil(void); + + /** + * This destructor is intentionally declared as private because this class + * cannot be constructed. + */ + virtual ~ImageUtil(void); + + /** + * The implementation of this copy constructor is intentionally blank + * and declared as private to prohibit copying of objects. + */ + ImageUtil(const ImageUtil& image); + + /** + * The implementation of this copy assignment operator is intentionally blank + * and declared as private to prohibit copying of objects. + */ + ImageUtil& operator =(const ImageUtil& image); + +}; // class ImageUtil + +}} // Tizen::Media + +#endif // _FMEDIA_IMAGEUTIL_H_ + diff --git a/inc/FMediaTypes.h b/inc/FMediaTypes.h new file mode 100644 index 0000000..39d13f0 --- /dev/null +++ b/inc/FMediaTypes.h @@ -0,0 +1,196 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** +* @file FMediaTypes.h +* @brief This is the header file for the media types. +* +* This header file contains the declarations of the media types. +*/ +#ifndef _FMEDIA_MEDIA_TYPES_H_ +#define _FMEDIA_MEDIA_TYPES_H_ + +#include + +namespace Tizen { namespace Media +{ + +/** + * Defines a macro that is added to declare the four-character code. + * + * @since 2.0 + * + * @param[in] ch1 The first character + * @param[in] ch2 The second character + * @param[in] ch3 The third character + * @param[in] ch4 The fourth character +*/ +#define FourCharCode(ch1, ch2, ch3, ch4) ((unsigned int) (unsigned char) (ch1)) | \ + ((unsigned int) (unsigned char) (ch2) << 8) | \ + ((unsigned int) (unsigned char) (ch3) << 16) | \ + ((unsigned int) (unsigned char) (ch4) << 24) + +/** + * @enum CodecType + * + * Defines the types of codec. + * + * @since 2.0 + * + * @see FourCharCode(ch1, ch2, ch3, ch4) + */ +enum CodecType +{ + CODEC_NONE = 0x00000000, /**< No codec */ + // Audio codecs + CODEC_LPCM = FourCharCode('L', 'P', 'C', 'M'), /**< The Linear PCM codec */ + CODEC_ALAW = FourCharCode('A', 'L', 'A', 'W'), /**< The G.711 A-Law codec */ + CODEC_ULAW = FourCharCode('u', 'L', 'A', 'W'), /**< The G.711 u-Law codec */ + CODEC_IMA_ADPCM = FourCharCode('I', 'M', 'A', 'D'), /**< The IMA ADPCM codec */ + CODEC_MS_ADPCM = FourCharCode('M', 'S', 'A', 'D'), /**< The MS ADPCM codec */ + CODEC_AMR_NB = FourCharCode('A', 'M', 'R', ' '), /**< The AMR-NB codec */ + CODEC_FLAC = FourCharCode('F', 'L', 'A', 'C'), /**< The FLAC codec */ + CODEC_MP3 = FourCharCode('M', 'P', '3', ' '), /**< The MP3 codec */ + CODEC_AAC = FourCharCode('A', 'A', 'C', ' '), /**< The AAC codec */ + CODEC_HEAAC = FourCharCode('A', 'A', 'C', 'H'), /**< The Enhanced AAC codec */ + CODEC_HEAAC_V2 = FourCharCode('A', 'A', 'C', 'P'), /**< The Enhanced AAC V2 codec */ + CODEC_AC3 = FourCharCode('A', 'C', '-', '3'), /**< The AC-3 codec */ + CODEC_VORBIS = FourCharCode('V', 'O', 'R', 'B'), /**< The VORBIS codec */ + CODEC_WMA = FourCharCode('W', 'M', 'A', ' '), /**< The WMA codec */ + CODEC_MIDI = FourCharCode('M', 'I', 'D', 'I'), /**< The MIDI codec */ + // Video codecs + CODEC_H263 = FourCharCode('H', '2', '6', '3'), /**< The H.263 codec */ + CODEC_MPEG4 = FourCharCode('M', 'P', 'G', '4'), /**< The MPEG4 codec */ + CODEC_H264 = FourCharCode('H', '2', '6', '4'), /**< The H.264 codec */ + CODEC_THEORA = FourCharCode('T', 'H', 'R', 'A'), /**< The THEORA codec */ + CODEC_WMV = FourCharCode('W', 'M', 'V', ' '), /**< The WMV codec */ + // Image codecs + CODEC_JPEG = FourCharCode('J', 'P', 'E', 'G'), /**< The JPEG codec */ + CODEC_PNG = FourCharCode('P', 'N', 'G', ' '), /**< The PNG codec */ + CODEC_GIF = FourCharCode('G', 'I', 'F', ' '), /**< The GIF codec */ + + CODEC_UNKNOWN = 0xFFFFFFFE, /**< The unknown codec */ + CODEC_MAX = 0xFFFFFFFF // Max +}; + +/** + * @enum MediaContainerType + * + * Defines the various container types of the media. + * + * @since 2.0 + * + * @see FourCharCode(ch1, ch2, ch3, ch4) + */ +enum MediaContainerType +{ + MEDIA_CONTAINER_NONE = 0x00000000, /**< No container */ + MEDIA_CONTAINER_WAV = FourCharCode('W', 'A', 'V', ' '), /**< The WAVE container */ + MEDIA_CONTAINER_AMR = FourCharCode('A', 'M', 'R', ' '), /**< The AMR container */ + MEDIA_CONTAINER_AAC = FourCharCode('A', 'A', 'C', ' '), /**< The AAC container */ + MEDIA_CONTAINER_MP3 = FourCharCode('M', 'P', '3', ' '), /**< The MP3 container */ + MEDIA_CONTAINER_FLAC = FourCharCode('F', 'L', 'A', 'C'), /**< The FLAC container */ + MEDIA_CONTAINER_3GP = FourCharCode('3', 'G', 'P', ' '), /**< The 3GP container */ + MEDIA_CONTAINER_MP4 = FourCharCode('M', 'P', '4', ' '), /**< The MP4 container */ + MEDIA_CONTAINER_AVI = FourCharCode('A', 'V', 'I', ' '), /**< The AVI container */ + MEDIA_CONTAINER_ASF = FourCharCode('A', 'S', 'F', ' '), /**< The ASF container */ + MEDIA_CONTAINER_MKV = FourCharCode('M', 'K', 'V', ' '), /**< The MKV container */ + MEDIA_CONTAINER_MOV = FourCharCode('M', 'O', 'V', ' '), /**< The MOV container */ + MEDIA_CONTAINER_OGG = FourCharCode('O', 'G', 'G', ' '), /**< The OGG container */ + MEDIA_CONTAINER_UNKNOWN = 0xFFFFFFFE, /**< The unknown container */ + MEDIA_CONTAINER_MAX = 0xFFFFFFFF // Max +}; + +/** + * @enum MediaPropertyType + * + * Defines the various property types of the media. + * + * @since 2.0 + */ +enum MediaPropertyType +{ + MEDIA_PROPERTY_VIDEO_WIDTH = 0x0001, /**< The video width (int) */ + MEDIA_PROPERTY_VIDEO_HEIGHT, /**< The video height (int) */ + MEDIA_PROPERTY_VIDEO_FRAME_RATE, /**< The video frame rate (float or int) */ + MEDIA_PROPERTY_VIDEO_PIXEL_FORMAT, /**< The video pixel format (::MediaPixelFormat) */ + MEDIA_PROPERTY_VIDEO_BIT_RATE, /**< The video bit rate (int) */ + + MEDIA_PROPERTY_VIDEO_QUANTIZATION_PARAMETER = 0x0100, /**< The video quantization level (int) */ + MEDIA_PROPERTY_VIDEO_QUANTIZATION_MIN, /**< The minimum quantization level (int) */ + MEDIA_PROPERTY_VIDEO_QUANTIZATION_MAX, /**< The maximum quantization level (int) */ + MEDIA_PROPERTY_VIDEO_GOP_SIZE, /**< The video Group of Picture (GOP) size (int) */ + MEDIA_PROPERTY_VIDEO_PROFILE, /**< The video profile (int) */ + MEDIA_PROPERTY_VIDEO_GOB_SIZE, /**< The video Group of Block (GOB) size (int) */ + MEDIA_PROPERTY_VIDEO_PACKET_SIZE, /**< The video packet size in byte (int) */ + MEDIA_PROPERTY_VIDEO_SLICE_SIZE_MODE, /**< The slice mode (::VideoSliceMode) */ + MEDIA_PROPERTY_VIDEO_SLICE_SIZE_IN_BYTE, /**< The size of a video slice in bytes (int) */ + MEDIA_PROPERTY_VIDEO_SLICE_SIZE_IN_MACROBLOCK, /**< The number of macroblocks in a slice (int) */ + MEDIA_PROPERTY_VIDEO_REFERENCE_PICTURE_COUNT, /**< The count of reference picture (int) */ + + MEDIA_PROPERTY_VIDEO_USE_FRAME_SKIP = 0x0200, /**< The media property type that uses the frame skip algorithm (int) */ + MEDIA_PROPERTY_VIDEO_USE_DEBLOCKING_FILTER, /**< The media property type that uses the deblocking filter (int) @n + It enables or disables the deblocking filter. */ + MEDIA_PROPERTY_VIDEO_USE_AC_PREDICTION, /**< The media property type that uses the AC prediction mode (int) */ + MEDIA_PROPERTY_VIDEO_USE_HEADER_EXTENSION_CODE, /**< The media property type that uses the header extension code mode (int) */ + + MEDIA_PROPERTY_VIDEO_FORCE_SKIP_FRAME = 0x0300, /**< The media property type that skips the encoding or decoding of the current frame (int) by force */ + MEDIA_PROPERTY_VIDEO_FORCE_INTRA_CODING, /**< The media property type that uses the intra coding for the current frame (int) by force */ + + MEDIA_PROPERTY_VIDEO_H264_USE_ANNEX_B = 0x0400, /**< The media property type that uses H.264 Annex B for output bitstream format (int) */ + + + MEDIA_PROPERTY_AUDIO_SAMPLE_RATE = 0x1000, /**< The audio sample rate (int) */ + MEDIA_PROPERTY_AUDIO_BIT_RATE, /**< The audio bit rate (int) */ + MEDIA_PROPERTY_AUDIO_CHANNEL_TYPE, /**< The audio channel type (::AudioChannelType) */ + MEDIA_PROPERTY_AUDIO_SAMPLE_TYPE, /**< The audio sample type (::AudioSampleType) */ + +}; + +/** + * @enum VideoSliceMode + * + * Defines the slice mode of the video data. + * + * @since 2.0 + */ +enum VideoSliceMode +{ + VIDEO_SLICE_MODE_NONE = 0x00, /**< The no slicing mode */ + VIDEO_SLICE_MODE_FIXED_MACROBLOCK, /**< The slicing of a video by a fixed number of macroblocks */ + VIDEO_SLICE_MODE_FIXED_BYTE, /**< The slicing of a video by a fixed number of bytes */ +}; + +/** + * @enum H263ProfileType + * + * Defines the profile types of the H.263 video codec. + * + * @since 2.0 + */ +enum H263ProfileType +{ + H263_PROFILE_BASELINE = 0x00, /**< The baseline profile */ + H263_PROFILE_VERSION_2 = 0x03, /**< The version 2 interactive and streaming wireless profile */ +}; + + +}; +}; // Tizen::Media + + +#endif diff --git a/osp-image.manifest b/osp-image.manifest new file mode 100755 index 0000000..ae3e6f7 --- /dev/null +++ b/osp-image.manifest @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/osp-image.pc.in b/osp-image.pc.in new file mode 100755 index 0000000..c064287 --- /dev/null +++ b/osp-image.pc.in @@ -0,0 +1,13 @@ +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=/usr +libdir=/usr/lib/osp +includedir=/usr/include/osp + +Name: @PC_NAME@ +Description: @PACKAGE_DESCRIPTION@ +Version: @VERSION@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} @PC_LDFLAGS@ +Cflags: -I${includedir} \ No newline at end of file diff --git a/packaging/osp-image.spec b/packaging/osp-image.spec new file mode 100755 index 0000000..83fb7fc --- /dev/null +++ b/packaging/osp-image.spec @@ -0,0 +1,107 @@ +%define debug_package %{nil} +%define __strip /bin/true + +Name: osp-image +Summary: The Media Image library of OSP +Version: 1.2.0.0 +Release: 1 +Group: TO_BE/FILLED_IN +License: TO BE FILLED IN +Source0: %{name}-%{version}.tar.gz +BuildRequires: cmake +BuildRequires: pkgconfig(libcurl) +BuildRequires: pkgconfig(osp-appfw) +BuildRequires: osp-appfw-internal-devel +BuildRequires: pkgconfig(osp-image-core) +BuildRequires: osp-image-core-internal-devel +BuildRequires: pkgconfig(osp-uifw) +BuildRequires: osp-uifw-internal-devel +BuildRequires: pkgconfig(osp-net) +BuildRequires: osp-net-internal-devel +BuildRequires: libexif-devel +BuildRequires: pkgconfig(openssl) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(libavcodec) +BuildRequires: pkgconfig(libavformat) +BuildRequires: pkgconfig(libavutil) +BuildRequires: pkgconfig(libswscale) +BuildRequires: pkgconfig(libwbxml2) + +# runtime requires +Requires: osp-appfw +Requires: osp-image-core +Requires: osp-uifw +Requires: osp-net + +Provides: libosp-image.so.1 + +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description +The Media Image library of OSP + +%package devel +Summary: The Media Image library of OSP (Development) +Group: TO_BE/FILLED_IN +Requires: %{name} = %{version}-%{release} + +%description devel +The Media Image library of OSP (DEV) + +%package internal-devel +Summary: osp media image internel (Internal) +Group: TO_BE/FILLED_IN +Requires: %{name} = %{version}-%{release} + +%description internal-devel +The Media Image library of OSP (Internal-DEV) + +%package debug +Summary: The Media Image library of OSP (Development) +Group: TO_BE/FILLED_IN +Requires: %{name} = %{version}-%{release} + +%description debug +The Media Image library of OSP (DEV) + +%prep +%setup -q + +%build +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` +%ifarch %{ix86} +CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_OSP_X86_ -D_OSP_EMUL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DOBS=1 -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DARCH=x86 +%else +CXXFLAGS="-O2 -g -pipe -Wall -fno-exceptions -Wformat -Wformat-security -Wl,--as-needed -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=neon -mfloat-abi=softfp -D__SOFTFP__ -mthumb -Wa,-mimplicit-it=thumb -funwind-tables -D_OSP_DEBUG_ -D_OSP_ARMEL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DOBS=1 -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DARCH=arm +%endif + +# Call make instruction with smp support +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot}/usr/share/license +cp %{_builddir}/%{name}-%{version}/LICENSE.APLv2.0 %{buildroot}/usr/share/license/%{name} + +%make_install + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + +%files +%manifest osp-image.manifest +/usr/share/license/%{name} +%{_libdir}/osp/libosp-image.so* + +%files devel +%{_includedir}/osp/*.h +%{_libdir}/pkgconfig/osp-image.pc + +%files internal-devel +%{_includedir}/osp/media/*.h + +%files debug +%{_libdir}/osp/debug/*.so* + diff --git a/src/FMediaGifDecoder.cpp b/src/FMediaGifDecoder.cpp new file mode 100644 index 0000000..270b89a --- /dev/null +++ b/src/FMediaGifDecoder.cpp @@ -0,0 +1,128 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMediaGifDecoder.cpp + * @brief This file contains the implementation of GifDecoder. + */ + +#include +#include +#include "FMediaGifDecoder.h" +#include "FMedia_GifDecoderImpl.h" + +namespace Tizen { namespace Media +{ + +GifDecoder::GifDecoder(void) +{ + __pDecImpl = null; +} + +GifDecoder::~GifDecoder(void) +{ + if (__pDecImpl) + { + delete __pDecImpl; + } +} + +result +GifDecoder::Construct(const Tizen::Base::String& filePath, MediaPixelFormat pixelFormat) +{ + result r = E_SUCCESS; + ClearLastResult(); + // Check pre-construct + SysAssertf(__pDecImpl == null, + "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); + // Create _GifDecoderImpl_ instance + _GifDecoderImpl* pGifDecoderImpl = new (std::nothrow) _GifDecoderImpl(); + SysTryCatch(NID_MEDIA, pGifDecoderImpl, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed Propagated."); + r = pGifDecoderImpl->Construct(filePath,pixelFormat); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagated", GetErrorMessage(r)); + __pDecImpl = pGifDecoderImpl; + return r; +CATCH: + if (pGifDecoderImpl) + { + delete pGifDecoderImpl; + pGifDecoderImpl = null; + } + return r; +} + +result +GifDecoder::Construct(const Tizen::Base::ByteBuffer& srcBuf, MediaPixelFormat pixelFormat) +{ + result r = E_SUCCESS; + ClearLastResult(); + // Check pre-construct + SysAssertf(__pDecImpl == null, + "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); + // Create _GifDecoderImpl_ instance + _GifDecoderImpl* pGifDecoderImpl = new (std::nothrow) _GifDecoderImpl(); + SysTryCatch(NID_MEDIA, pGifDecoderImpl, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed Propagated."); + r = pGifDecoderImpl->Construct(srcBuf,pixelFormat); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagated", GetErrorMessage(r)); + __pDecImpl = pGifDecoderImpl; + return r; +CATCH: + if (pGifDecoderImpl) + { + delete pGifDecoderImpl; + pGifDecoderImpl = null; + } + return r; +} + + +int +GifDecoder::GetWidth(void) const +{ + ClearLastResult(); + SysAssertf(__pDecImpl != null, "Not yet constructed. Construct() should be called before use."); + return __pDecImpl->GetWidth(); + +} + +int +GifDecoder::GetHeight(void) const +{ + ClearLastResult(); + SysAssertf(__pDecImpl != null, "Not yet constructed. Construct() should be called before use."); + return __pDecImpl->GetHeight(); +} + +Tizen::Base::ByteBuffer* +GifDecoder::GetNextFrameN(long& duration) +{ + ClearLastResult(); + SysAssertf(__pDecImpl != null, "Not yet constructed. Construct() should be called before use."); + + return __pDecImpl->GetNextFrameN(duration); +} + +Tizen::Graphics::Bitmap* +GifDecoder::GetNextBitmapN(long& duration, Tizen::Graphics::BufferScaling bufferScaling) +{ + ClearLastResult(); + SysAssertf(__pDecImpl != null, "Not yet constructed. Construct() should be called before use."); + + return __pDecImpl->GetNextBitmapN(duration, bufferScaling); +} + +}} //Tizen::Media diff --git a/src/FMediaImage.cpp b/src/FMediaImage.cpp new file mode 100644 index 0000000..2731462 --- /dev/null +++ b/src/FMediaImage.cpp @@ -0,0 +1,433 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMediaImage.cpp + * @brief This file contains the implementation of subsystem's Image. + */ + +#include +#include +#include +#include +#include +#include +#include "FMedia_ImageImpl.h" +#include "FMedia_ImageUtilImpl.h" + +using namespace Tizen::Graphics; +using namespace Tizen::Base; +using namespace Tizen::Io; +using namespace Tizen::App; + +namespace Tizen { namespace Media +{ + +static const int MIN_LIMIT_SIZE = 1024; + +Image::Image(void) +{ + __pImageImpl = null; +} + +Image::~Image(void) +{ + if (__pImageImpl != null) + { + delete __pImageImpl; + __pImageImpl = null; + } +} + +result +Image::Construct(void) +{ + result r = E_SUCCESS; + + SysAssertf(__pImageImpl == null, + "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); + _ImageImpl* pImageImpl = new (std::nothrow) _ImageImpl(); + SysTryCatch(NID_MEDIA, pImageImpl != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Construct Failed "); + + r = pImageImpl->Construct(); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Create instance failed.", GetErrorMessage(r)); + + __pImageImpl = pImageImpl; + return E_SUCCESS; + +CATCH: + if (pImageImpl) + { + delete pImageImpl; + pImageImpl = null; + } + return r; +} + +Bitmap* +Image::DecodeN(const String& srcImagePath, BitmapPixelFormat pixelFormat) const +{ + result r = E_SUCCESS; + + SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use."); + SysTryCatch(NID_MEDIA, !srcImagePath.IsEmpty(), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] srcImagePath is empty"); + SysTryCatch(NID_MEDIA, File::IsFileExist(srcImagePath), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, + "[E_FILE_NOT_FOUND] srcImagePath:%ls", srcImagePath.GetPointer()); + SysTryCatch(NID_MEDIA, ((pixelFormat==BITMAP_PIXEL_FORMAT_RGB565) || (pixelFormat==BITMAP_PIXEL_FORMAT_ARGB8888) || (pixelFormat==BITMAP_PIXEL_FORMAT_R8G8B8A8)), + r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] pixelFormat:%d", pixelFormat); + return _ImageImpl::DecodeToBitmapN(srcImagePath, pixelFormat); + +CATCH: + return null; +} + + +Bitmap* +Image::DecodeN(const String& srcImagePath, BitmapPixelFormat pixelFormat, int destWidth, int destHeight) const +{ + result r = E_SUCCESS; + + SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use."); + SysTryCatch(NID_MEDIA, !srcImagePath.IsEmpty(), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] srcImagePath is empty"); + SysTryCatch(NID_MEDIA, File::IsFileExist(srcImagePath), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, + "[E_FILE_NOT_FOUND] srcImagePath:%ls", srcImagePath.GetPointer()); + SysTryCatch(NID_MEDIA, ((pixelFormat==BITMAP_PIXEL_FORMAT_RGB565) || (pixelFormat==BITMAP_PIXEL_FORMAT_ARGB8888) || (pixelFormat==BITMAP_PIXEL_FORMAT_R8G8B8A8)), + r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] pixelFormat:%d", pixelFormat); + SysTryCatch(NID_MEDIA, destWidth > 0, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] destWidth:%d", destWidth); + SysTryCatch(NID_MEDIA, destHeight > 0, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] destHeight:%d", destHeight); + + return _ImageImpl::DecodeToBitmapN(srcImagePath, pixelFormat, Dimension(destWidth, destHeight)); + +CATCH: + return null; +} + +Bitmap* +Image::DecodeN(const ByteBuffer& srcImageBuf, ImageFormat srcImageFormat, + BitmapPixelFormat pixelFormat) const +{ + result r = E_SUCCESS; + + SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use."); + SysTryCatch(NID_MEDIA, &srcImageBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] srcImageBuf is null"); + SysTryCatch(NID_MEDIA, ((srcImageFormat>IMG_FORMAT_NONE) && (srcImageFormat<=IMG_FORMAT_WBMP)), r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT, + "[E_UNSUPPORTED_FORMAT] srcImageFormat:%d", srcImageFormat); + SysTryCatch(NID_MEDIA, ((pixelFormat==BITMAP_PIXEL_FORMAT_RGB565) || (pixelFormat==BITMAP_PIXEL_FORMAT_ARGB8888) || (pixelFormat==BITMAP_PIXEL_FORMAT_R8G8B8A8)), + r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] %s=%d", "pixelFormat", pixelFormat); + + return _ImageImpl::DecodeToBitmapN(srcImageBuf, pixelFormat); + +CATCH: + return null; +} + + +Bitmap* +Image::DecodeN(const ByteBuffer& srcImageBuf, ImageFormat imgFormat, BitmapPixelFormat pixelFormat, + int destWidth, int destHeight) const +{ + result r = E_SUCCESS; + + SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use."); + SysTryCatch(NID_MEDIA, &srcImageBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] srcImageBuf is null"); + SysTryCatch(NID_MEDIA, ((imgFormat>IMG_FORMAT_NONE) && (imgFormat<=IMG_FORMAT_WBMP)), r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT, + "[E_UNSUPPORTED_FORMAT] imgFormat:%d", imgFormat); + SysTryCatch(NID_MEDIA, ((pixelFormat==BITMAP_PIXEL_FORMAT_RGB565) || (pixelFormat==BITMAP_PIXEL_FORMAT_ARGB8888) || (pixelFormat==BITMAP_PIXEL_FORMAT_R8G8B8A8)), + r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] pixelFormat:%d", pixelFormat); + SysTryCatch(NID_MEDIA, destWidth > 0, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] destWidth:%d", destWidth); + SysTryCatch(NID_MEDIA, destHeight > 0, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] destHeight:%d", destHeight); + + return _ImageImpl::DecodeToBitmapN(srcImageBuf, pixelFormat, Dimension(destWidth, destHeight), + BUFFER_SCALING_AUTO, imgFormat); + +CATCH: + return null; +} + + +ByteBuffer* +Image::EncodeToBufferN(const Bitmap& srcImageBuf, ImageFormat destImageFormat) const +{ + result r = E_SUCCESS; + + SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use."); + SysTryCatch(NID_MEDIA, &srcImageBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] srcImageBuf is null"); + SysTryCatch(NID_MEDIA, ((destImageFormat==IMG_FORMAT_BMP) || (destImageFormat==IMG_FORMAT_JPG) || (destImageFormat==IMG_FORMAT_PNG)), + r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT, "[E_UNSUPPORTED_FORMAT] destImageFormat:%d", destImageFormat); + SysTryCatch(NID_MEDIA, srcImageBuf.GetWidth() > 0 && srcImageBuf.GetHeight() > 0, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, + "[E_OBJ_NOT_FOUND] bmp.width=%d,height=%d", srcImageBuf.GetWidth(), srcImageBuf.GetHeight()); + + + return _ImageImpl::EncodeToBufferN(srcImageBuf, destImageFormat); + +CATCH: + return null; +} + +result +Image::EncodeToFile(const Bitmap& srcImageBuf, ImageFormat destImageFormat, + const String& destImagePath, bool overwrite) const +{ + result r = E_SUCCESS; + + SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use."); + SysTryCatch(NID_MEDIA, &srcImageBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] srcImageBuf is null"); + SysTryCatch(NID_MEDIA, ((destImageFormat==IMG_FORMAT_BMP) || (destImageFormat==IMG_FORMAT_JPG) || (destImageFormat==IMG_FORMAT_PNG)), + r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT, "[E_UNSUPPORTED_FORMAT] destImageFormat:%d", destImageFormat); + SysTryCatch(NID_MEDIA, srcImageBuf.GetWidth() > 0 && srcImageBuf.GetHeight() > 0, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, + "[E_OBJ_NOT_FOUND] bmp.width=%d,height=%d", srcImageBuf.GetWidth(), srcImageBuf.GetHeight()); + + return _ImageImpl::EncodeToFile(srcImageBuf, destImageFormat, destImagePath, overwrite); + +CATCH: + return r; +} + +ByteBuffer* +Image::ConvertN(const String& srcImagePath, ImageFormat destImageFormat) const +{ + result r = E_SUCCESS; + + SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use."); + SysTryCatch(NID_MEDIA, !srcImagePath.IsEmpty(), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] path is empty"); + SysTryCatch(NID_MEDIA, File::IsFileExist(srcImagePath), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, + "[E_FILE_NOT_FOUND] srcImagePath:%ls", srcImagePath.GetPointer()); + SysTryCatch(NID_MEDIA, ((destImageFormat>IMG_FORMAT_NONE) && (destImageFormat<=IMG_FORMAT_WBMP)), r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT, + "[E_UNSUPPORTED_FORMAT] destImageFormat:%d", destImageFormat); + + return _ImageImpl::ConvertToBufferN(srcImagePath, destImageFormat); + +CATCH: + return null; +} + + +result +Image::CompressJpeg(const Tizen::Base::String& srcImagePath, const Tizen::Base::String& destImagePath, int limitSize) const +{ + result r = E_SUCCESS; + ImageFormat imgFormat; + + SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use."); + SysTryCatch(NID_MEDIA, !srcImagePath.IsEmpty(), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] srcImagePath is empty"); + SysTryCatch(NID_MEDIA, File::IsFileExist(srcImagePath), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, + "[E_FILE_NOT_FOUND] srcImagePath:%ls", srcImagePath.GetPointer()); + + // CompressJpeg should accept only jpeg encoded images. + imgFormat = _ImageUtilImpl::GetImageFormat(srcImagePath); + SysTryCatch(NID_MEDIA, imgFormat == IMG_FORMAT_JPG, r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT, + "[E_UNSUPPORTED_FORMAT] image format(%d) != JPG", imgFormat); + + SysTryCatch(NID_MEDIA, limitSize > MIN_LIMIT_SIZE, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, + "[E_OUT_OF_RANGE] limitSize:%d < %d", limitSize, MIN_LIMIT_SIZE); + + return _ImageImpl::CompressJpeg(srcImagePath, destImagePath, limitSize); + +CATCH: + return r; +} + +Tizen::Base::ByteBuffer* +Image::CompressJpegN(const Tizen::Base::ByteBuffer& srcImageBuf, int limitSize) const +{ + result r = E_SUCCESS; + ImageFormat imgFormat; + + SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use."); + SysTryCatch(NID_MEDIA, &srcImageBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] srcImageBuf is null"); + + SysTryCatch(NID_MEDIA, limitSize > MIN_LIMIT_SIZE, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, + "[E_OUT_OF_RANGE] limitSize:%d < %d", limitSize, MIN_LIMIT_SIZE); + SysTryCatch(NID_MEDIA, srcImageBuf.GetCapacity() > limitSize, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, + "[E_OUT_OF_RANGE] srcSize(%d) <= limitSize(%d)", srcImageBuf.GetCapacity(), limitSize); + + imgFormat = _ImageUtilImpl::GetImageFormat(srcImageBuf); + SysTryCatch(NID_MEDIA, imgFormat == IMG_FORMAT_JPG, r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT, + "[E_UNSUPPORTED_FORMAT] image format(%d) != JPG", imgFormat); + + return _ImageImpl::CompressJpegN(srcImageBuf, limitSize); + +CATCH: + return null; +} + + +Tizen::Base::ByteBuffer* +Image::DecodeToBufferN(const Tizen::Base::ByteBuffer& srcImageBuf, ImageFormat srcImageFormat, + Tizen::Graphics::BitmapPixelFormat pixelFormat, + int& imageWidth, int& imageHeight) const +{ + Dimension dim; + ByteBuffer* pBuf = null; + result r = E_SUCCESS; + + SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use."); + SysTryCatch(NID_MEDIA, &srcImageBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] srcImageBuf is null"); + SysTryCatch(NID_MEDIA, ((srcImageFormat>IMG_FORMAT_NONE) && (srcImageFormat<=IMG_FORMAT_WBMP)), r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT, + "[E_UNSUPPORTED_FORMAT] srcImageFormat:%d", srcImageFormat); + SysTryCatch(NID_MEDIA, ((pixelFormat==BITMAP_PIXEL_FORMAT_RGB565) || (pixelFormat==BITMAP_PIXEL_FORMAT_ARGB8888) || (pixelFormat==BITMAP_PIXEL_FORMAT_R8G8B8A8)), + r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] pixelFormat:%d", pixelFormat); + + pBuf = _ImageImpl::DecodeToBufferN(srcImageBuf, dim, Dimension(0,0), pixelFormat, srcImageFormat); + SysTryCatch(NID_MEDIA, pBuf != null, r = GetLastResult(), GetLastResult(), + "[%s] Propagated.", GetErrorMessage(GetLastResult())); + imageWidth = dim.width; + imageHeight = dim.height; + + return pBuf; + +CATCH: + + return null; +} + +Tizen::Base::ByteBuffer* +Image::DecodeToBufferN(const Tizen::Base::String& srcImagePath, + Tizen::Graphics::BitmapPixelFormat pixelFormat, + int& imageWidth, int& imageHeight) const +{ + Dimension dim; + ByteBuffer* pBuf = null; + result r = E_SUCCESS; + + SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use."); + SysTryCatch(NID_MEDIA, !srcImagePath.IsEmpty(), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] srcImagePath is empty"); + SysTryCatch(NID_MEDIA, File::IsFileExist(srcImagePath), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, + "[E_FILE_NOT_FOUND] srcImagePath:%ls", srcImagePath.GetPointer()); + SysTryCatch(NID_MEDIA, ((pixelFormat==BITMAP_PIXEL_FORMAT_RGB565) || (pixelFormat==BITMAP_PIXEL_FORMAT_ARGB8888) || (pixelFormat==BITMAP_PIXEL_FORMAT_R8G8B8A8)), + r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] pixelFormat:%d", pixelFormat); + + pBuf = _ImageImpl::DecodeToBufferN(srcImagePath, dim, Dimension(0,0), pixelFormat); + SysTryCatch(NID_MEDIA, pBuf != null, r = GetLastResult(), GetLastResult(), + "[%s] Propagated.", GetErrorMessage(GetLastResult())); + imageWidth = dim.width; + imageHeight = dim.height; + + return pBuf; + +CATCH: + + return null; +} + +ImageFormat +Image::GetImageFormat(const Tizen::Base::String& srcImagePath) const +{ + ImageFormat fmt; + result r = E_SUCCESS; + + SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use."); + SysTryCatch(NID_MEDIA, !srcImagePath.IsEmpty(), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] srcImagePath is empty"); + SysTryCatch(NID_MEDIA, File::IsFileExist(srcImagePath), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, + "[E_FILE_NOT_FOUND] srcImagePath:%ls", srcImagePath.GetPointer()); + fmt = _ImageUtilImpl::GetImageFormat(srcImagePath); + r = GetLastResult(); + + if (r == E_INVALID_DATA || r == E_INVALID_ARG) + { + SetLastResult(E_UNSUPPORTED_FORMAT); + } + + return fmt; + +CATCH: + return IMG_FORMAT_NONE; +} + + +ImageFormat +Image::GetImageFormat(const Tizen::Base::ByteBuffer& srcImageBuf) const +{ + ImageFormat fmt; + result r = E_SUCCESS; + + SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use."); + SysTryCatch(NID_MEDIA, &srcImageBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] srcImagePath is null"); + + fmt = _ImageUtilImpl::GetImageFormat(srcImageBuf); + r = GetLastResult(); + + if (r == E_INVALID_DATA || r == E_INVALID_ARG) + { + SetLastResult(E_UNSUPPORTED_FORMAT); + } + + return fmt; + +CATCH: + return IMG_FORMAT_NONE; +} + +bool +Image::HasAlphaChannels(const Tizen::Base::String& srcImagePath) const +{ + result r = E_SUCCESS; + + SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use."); + SysTryCatch(NID_MEDIA, !srcImagePath.IsEmpty(), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] srcImagePath is empty"); + SysTryCatch(NID_MEDIA, File::IsFileExist(srcImagePath), r = E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, + "[E_FILE_NOT_FOUND] srcImagePath:%ls", srcImagePath.GetPointer()); + + return _ImageUtilImpl::HasAlphaChannel(srcImagePath); + +CATCH: + return false; +} + + +bool +Image::HasAlphaChannels(const Tizen::Base::ByteBuffer& srcImageBuf) const +{ + result r = E_SUCCESS; + + SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use."); + SysTryCatch(NID_MEDIA, &srcImageBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] srcImageBuf is null"); + + return _ImageUtilImpl::HasAlphaChannel(srcImageBuf); + +CATCH: + return false; +} + +result +Image::DecodeUrl(const Tizen::Base::Utility::Uri& srcImageUrl, + Tizen::Graphics::BitmapPixelFormat pixelFormat, int destWidth, + int destHeight, RequestId& reqId, const IImageDecodeUrlEventListener& listener, + long timeout) const +{ + result r = E_SUCCESS; + + SysAssertf(__pImageImpl != null, "Not yet constructed. Construct() should be called before use."); + SysTryCatch(NID_MEDIA, ((pixelFormat==BITMAP_PIXEL_FORMAT_RGB565) || (pixelFormat==BITMAP_PIXEL_FORMAT_ARGB8888) || (pixelFormat==BITMAP_PIXEL_FORMAT_R8G8B8A8)), + r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] pixelFormat:%d", pixelFormat); + SysTryCatch(NID_MEDIA, destWidth > 0, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] destWidth:%d", destWidth); + SysTryCatch(NID_MEDIA, destHeight > 0, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] destHeight:%d", destHeight); + + SysTryCatch(NID_MEDIA, timeout == TIMEOUT_INFINITE || timeout > 0, r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, + "[E_OUT_OF_RANGE] timeout:%d", timeout); + + r = __pImageImpl->DecodeUrl(srcImageUrl, pixelFormat, destWidth,destHeight, reqId, listener, timeout); +SysTryCatch(NID_MEDIA, r == E_SUCCESS , , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + return r; +} + +}} // Tizen::Media diff --git a/src/FMediaImageBuffer.cpp b/src/FMediaImageBuffer.cpp new file mode 100644 index 0000000..41e2ad1 --- /dev/null +++ b/src/FMediaImageBuffer.cpp @@ -0,0 +1,387 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMediaImageBuffer.cpp + * @brief This file contains the implementation of subsystem's ImageBuffer. + */ + +#include +#include +#include +#include +#include +#include +#include "FMedia_ImageBufferImpl.h" +#include "FMedia_ImageUtilImpl.h" + +using namespace Tizen::Graphics; +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; +using namespace Tizen::App; + +namespace Tizen { namespace Media +{ + +ImageBuffer::ImageBuffer(void) +{ + __pImpl = null; +} + +ImageBuffer::~ImageBuffer(void) +{ + if (__pImpl != null) + { + delete __pImpl; + __pImpl = null; + } +} + +result +ImageBuffer::Construct(int width, int height, MediaPixelFormat pixelFormat, + const byte* pData, int length) +{ + result r = E_SUCCESS; + + SysAssertf(__pImpl == null, + "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); + + _ImageBufferImpl* pImageBufferImpl = new (std::nothrow) _ImageBufferImpl(); + SysTryReturnResult(NID_MEDIA, pImageBufferImpl != null, E_OUT_OF_MEMORY, "Create instance failed."); + + r = pImageBufferImpl->Construct(width, height, pixelFormat, pData, length); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , GetLastResult(), + "[%s] Construct instance failed.", GetErrorMessage(GetLastResult())); + + __pImpl = pImageBufferImpl; + return r; + +CATCH: + if (pImageBufferImpl != null) + { + delete pImageBufferImpl; + pImageBufferImpl = null; + } + return r; + +} + +result +ImageBuffer::Construct(const Tizen::Base::String &srcImagePath, + const Tizen::Graphics::Rectangle *pDecodingRegion, bool autoRotate) +{ + result r = E_SUCCESS; + + SysAssertf(__pImpl == null, + "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); + SysTryReturnResult(NID_MEDIA, !srcImagePath.IsEmpty(), E_INVALID_ARG,"path is empty."); + + SysTryReturnResult(NID_MEDIA, File::IsFileExist(srcImagePath), E_FILE_NOT_FOUND, + "file not found: %ls", srcImagePath.GetPointer()); + + _ImageBufferImpl* pImageBufferImpl = new (std::nothrow) _ImageBufferImpl(); + SysTryReturnResult(NID_MEDIA, pImageBufferImpl != null, E_OUT_OF_MEMORY, "Create instance failed."); + + r = pImageBufferImpl->Construct(srcImagePath, pDecodingRegion, autoRotate); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , GetLastResult(), + "[%s] Construct instance failed.", GetErrorMessage(GetLastResult())); + + __pImpl = pImageBufferImpl; + return r; + +CATCH: + if (pImageBufferImpl != null) + { + delete pImageBufferImpl; + pImageBufferImpl = null; + } + return r; +} + +result +ImageBuffer::Construct(const Tizen::Base::ByteBuffer &srcImageBuf, + const Tizen::Graphics::Rectangle *pDecodingRegion, bool autoRotate) +{ + result r = E_SUCCESS; + + SysAssertf(__pImpl == null, + "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); + SysTryReturnResult(NID_MEDIA, &srcImageBuf != null, E_INVALID_ARG, + "src buffer is null"); + + _ImageBufferImpl* pImageBufferImpl = new (std::nothrow) _ImageBufferImpl(); + SysTryReturnResult(NID_MEDIA, pImageBufferImpl != null, E_OUT_OF_MEMORY, "Create instance failed."); + + r = pImageBufferImpl->Construct(srcImageBuf, pDecodingRegion, autoRotate); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, + "[%s] Construct instance failed.", GetErrorMessage(r)); + + __pImpl = pImageBufferImpl; + return r; + +CATCH: + if (pImageBufferImpl != null) + { + delete pImageBufferImpl; + pImageBufferImpl = null; + } + return r; +} + +result +ImageBuffer::Construct(const Tizen::Graphics::Bitmap &srcBitmap) +{ + result r = E_SUCCESS; + + SysAssertf(__pImpl == null, + "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); + SysTryReturnResult(NID_MEDIA, (srcBitmap.GetWidth() > 0) && (srcBitmap.GetHeight() > 0) + && (srcBitmap.GetBitsPerPixel() > 0), E_INVALID_ARG, + "Source bitmap is invalid: (%d x %d), bpp = %d.", + srcBitmap.GetWidth(), srcBitmap.GetHeight(), srcBitmap.GetBitsPerPixel()); + + _ImageBufferImpl* pImageBufferImpl = new (std::nothrow) _ImageBufferImpl(); + SysTryReturnResult(NID_MEDIA, pImageBufferImpl != null, E_OUT_OF_MEMORY, "Create instance failed."); + + r = pImageBufferImpl->Construct(srcBitmap); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, + "[%s] Construct instance failed.", GetErrorMessage(r)); + + __pImpl = pImageBufferImpl; + return r; + +CATCH: + if (pImageBufferImpl != null) + { + delete pImageBufferImpl; + pImageBufferImpl = null; + } + return r; +} + +bool +ImageBuffer::Equals(const Object& rhs) const +{ + SysAssertf(__pImpl != null, + "Not yet constructed. Construct() should be called before use."); + + ImageBuffer* pOther = (const_cast(dynamic_cast (&rhs))); + SysTryReturn(NID_MEDIA, pOther != null, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, + "[E_OBJ_NOT_FOUND] RHS ImageBuffer is not found."); + + return __pImpl->Equals(pOther); +} + +int +ImageBuffer::GetHashCode() const +{ + int hashCode = 0; + + SysAssertf(__pImpl != null, + "Not yet constructed. Construct() should be called before use."); + + hashCode = __pImpl->GetHashCode(); + return hashCode; +} + +int +ImageBuffer::GetHeight() const +{ + SysAssertf(__pImpl != null, + "Not yet constructed. Construct() should be called before use."); + + return __pImpl->GetHeight(); +} + +int +ImageBuffer::GetWidth() const +{ + SysAssertf(__pImpl != null, + "Not yet constructed. Construct() should be called before use."); + + return __pImpl->GetWidth(); +} + +MediaPixelFormat +ImageBuffer::GetPixelFormat() const +{ + SysAssertf(__pImpl != null, + "Not yet constructed. Construct() should be called before use."); + + return __pImpl->GetPixelFormat(); +} + +ByteBuffer* +ImageBuffer::EncodeToBufferN(ImageFormat destImageFormat, int quality) const +{ + SysAssertf(__pImpl != null, + "Not yet constructed. Construct() should be called before use."); + SysTryReturn(NID_MEDIA, ((destImageFormat == IMG_FORMAT_BMP) || + (destImageFormat == IMG_FORMAT_JPG) || (destImageFormat == IMG_FORMAT_PNG)), + null, E_UNSUPPORTED_FORMAT, "[E_UNSUPPORTED_FORMAT] %s = %d", + "destImageFormat", destImageFormat); + + return __pImpl->EncodeToBufferN(destImageFormat, quality); +} + +result +ImageBuffer::EncodeToFile(const String &destImagePath, ImageFormat destImageFormat, + bool overwrite, int quality) const +{ + SysAssertf(__pImpl != null, + "Not yet constructed. Construct() should be called before use."); + + return __pImpl->EncodeToFile(destImagePath, destImageFormat, overwrite, quality); +} + +Bitmap* +ImageBuffer::GetBitmapN(BitmapPixelFormat pixelFormat, BufferScaling bufferScaling) const +{ + SysAssertf(__pImpl != null, + "Not yet constructed. Construct() should be called before use."); + + return __pImpl->GetBitmapN(pixelFormat, bufferScaling); +} + +ByteBuffer* +ImageBuffer::GetByteBufferN(MediaPixelFormat pixelFormat) const +{ + SysAssertf(__pImpl != null, + "Not yet constructed. Construct() should be called before use."); + + return __pImpl->GetByteBufferN(pixelFormat); +} + +ImageBuffer* +ImageBuffer::CloneN() const +{ + ImageBuffer* pImgBuffer = null; + + SysAssertf(__pImpl != null, + "Not yet constructed. Construct() should be called before use."); + + pImgBuffer = __pImpl->CloneN(); + + return pImgBuffer; +} + +ImageBuffer* +ImageBuffer::ConvertPixelFormatN(MediaPixelFormat pixelFormat) const +{ + ImageBuffer* pImgBuffer = null; + + SysAssertf(__pImpl != null, + "Not yet constructed. Construct() should be called before use."); + + pImgBuffer = __pImpl->ConvertPixelFormatN(pixelFormat); + + return pImgBuffer; +} + +ImageBuffer* +ImageBuffer::ResizeN(int width, int height) const +{ + ImageBuffer* pImgBuffer = null; + + SysAssertf(__pImpl != null, + "Not yet constructed. Construct() should be called before use."); + + pImgBuffer = __pImpl->ResizeN(width, height); + + return pImgBuffer; +} + +ImageBuffer* +ImageBuffer::FlipN(ImageFlipType flipType) const +{ + ImageBuffer* pImgBuffer = null; + + SysAssertf(__pImpl != null, + "Not yet constructed. Construct() should be called before use."); + + pImgBuffer = __pImpl->FlipN(flipType); + + return pImgBuffer; +} + +ImageBuffer* +ImageBuffer::RotateN(ImageRotationType rotateType) const +{ + ImageBuffer* pImgBuffer = null; + + SysAssertf(__pImpl != null, + "Not yet constructed. Construct() should be called before use."); + + pImgBuffer = __pImpl->RotateN(rotateType); + + return pImgBuffer; +} + +ImageBuffer* +ImageBuffer::CropN(int x, int y, int width, int height) const +{ + ImageBuffer* pImgBuffer = null; + + SysAssertf(__pImpl != null, + "Not yet constructed. Construct() should be called before use."); + + pImgBuffer = __pImpl->CropN(x, y, width, height); + + return pImgBuffer; +} + +result +ImageBuffer::GetImageInfo(const String& srcImagePath, ImageFormat& imageFormat, + int &width, int &height) +{ + result r = E_SUCCESS; + + SysTryReturn(NID_MEDIA, !srcImagePath.IsEmpty(), E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, + "[E_FILE_NOT_FOUND] path is empty"); + + SysTryReturn(NID_MEDIA, File::IsFileExist(srcImagePath), E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, + "[E_FILE_NOT_FOUND] file not found: %ls", srcImagePath.GetPointer()); + + r = _ImageBufferImpl::GetImageInfo(srcImagePath, imageFormat, width, height); + return r; +} + +result +ImageBuffer::GetImageInfo(const ByteBuffer& srcImageBuf, ImageFormat& imageFormat, + int &width, int &height) +{ + SysTryReturn(NID_MEDIA, &srcImageBuf != null, E_INVALID_ARG, E_INVALID_ARG, + "[E_INVALID_ARG] srcImageBuf is null"); + + return _ImageBufferImpl::GetImageInfo(srcImageBuf, imageFormat, width, height); +} + +IListT* +ImageBuffer::GetSupportedPixelFormatListN() +{ + IListT *pList = null; + + pList = _ImageBufferImpl::GetSupportedPixelFormatListN(); + + return pList; +} + + + + +}} // Tizen::Media diff --git a/src/FMediaImageUtil.cpp b/src/FMediaImageUtil.cpp new file mode 100644 index 0000000..88cf7f2 --- /dev/null +++ b/src/FMediaImageUtil.cpp @@ -0,0 +1,68 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMediaImageUtil.cpp + * @brief This file contains the implementation of ImageUtil class. + */ + +#include +#include +#include +#include "FMedia_ImageUtilImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Graphics; + +namespace Tizen { namespace Media +{ + +result +ImageUtil::ConvertPixelFormat(const ByteBuffer& srcBuf, ByteBuffer& destBuf, + MediaPixelFormat srcPixelFormat, MediaPixelFormat destPixelFormat, + const Dimension& dim) +{ + return _ImageUtilImpl::ConvertPixelFormat(srcBuf, destBuf, srcPixelFormat, destPixelFormat, dim); +} + + +result +ImageUtil::Resize(const ByteBuffer& srcBuf, ByteBuffer& destBuf, const Dimension& srcDim, + const Dimension& destDim, MediaPixelFormat pixelFormat) +{ + return _ImageUtilImpl::Resize(srcBuf, destBuf, srcDim, destDim, pixelFormat); +} + + +result +ImageUtil::Rotate(const ByteBuffer& srcBuf, ByteBuffer& destBuf, const Dimension& dim, + ImageRotationType rotate, MediaPixelFormat pixelFormat) +{ + return _ImageUtilImpl::Rotate(srcBuf, destBuf, dim, rotate, pixelFormat); +} + + +result +ImageUtil::Flip(const ByteBuffer& srcBuf, ByteBuffer& destBuf, const Dimension& dim, + ImageFlipType flip, MediaPixelFormat pixelFormat) +{ + return _ImageUtilImpl::Flip(srcBuf, destBuf, dim, flip, pixelFormat); +} + + +}; +}; diff --git a/src/FMedia_ExifUtil.cpp b/src/FMedia_ExifUtil.cpp new file mode 100644 index 0000000..29478a3 --- /dev/null +++ b/src/FMedia_ExifUtil.cpp @@ -0,0 +1,279 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMedia_ExifUtil.h" + +namespace Tizen { namespace Media +{ + +const wchar_t* const EXIF_TAG_IMAGE_ORIENTATION = L"Exif.Orientation"; +const wchar_t* const EXIF_TAG_IMAGE_GPS_ALTITUDE = L"Exif.Gps.Altitude"; +const wchar_t* const EXIF_TAG_IMAGE_GPS_LONGITUDE = L"Exif.Gps.Longitude"; +const wchar_t* const EXIF_TAG_IMAGE_GPS_LATITUDE = L"Exif.Gps.Latitude"; + +_ExifUtil::_ExifUtil() +: __pExifData(null) +, __pExifLog(null) +, __orientation(-1) +, __gpsLongitude(0.0) +, __gpsLatitude(0.0) +, __gpsAltitude(0.0) +, __gpsLongitudeExist(false) +, __gpsAltitudeExist(false) +, __gpsLatitudeExist(false) +, __orientationExist(false) +{ +} + +_ExifUtil::~_ExifUtil() +{ + if (__pExifData) + { + exif_data_free(__pExifData); + } + if (__pExifLog) + { + exif_log_free(__pExifLog); + } +} + +result _ExifUtil::Construct(const byte* pBuf, int length) +{ + result r = E_SUCCESS; + + SysTryCatch(NID_MEDIA, pBuf != null, r = E_INVALID_DATA, E_INVALID_DATA, "[E_INVALID_DATA] Buffer is null. length: %d", length); + + __pExifData = exif_data_new_from_data(pBuf, length); + SysTryCatch(NID_MEDIA, __pExifData != null, r = E_INVALID_DATA, E_INVALID_DATA, "[E_INVALID_DATA] exi data is null. length: %d", length); + + __pExifLog = exif_log_new(); + SysTryCatch(NID_MEDIA, __pExifLog != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] exif_log_new fail"); + +#if defined _EXIF_UTIL_LOG_ + //exif_log_set_func(__pExifLog, _ExifUtil::ExifLogFuncStatic, this); + //exif_data_log(__pExifData, __pExifLog); +#endif + exif_data_foreach_content(__pExifData, _ExifUtil::ForEachContentStatic, this); + return r; + +CATCH: + if (__pExifLog) + { + exif_log_free(__pExifLog); + } + return r; +} + +#if defined _EXIF_UTIL_LOG_ +//void _ExifUtil::ExifLogFuncStatic(ExifLog *log, ExifLogCode code, const char *domain, const char *format, va_list args, void *data) +//{ +// ((_ExifUtil*)data)->ExifLogFunc(log, code, domain, format, args); +//} + +//void _ExifUtil::ExifLogFunc(ExifLog *log, ExifLogCode code, const char *domain, const char *format, va_list args) +//{ +// char msg[1024]; +// vsprintf(msg, format, args); +// TLog("ExifLog : %s", msg); +//} +#endif + +void _ExifUtil::ForEachContentStatic(struct _ExifContent *pContent, void *pUserData) +{ + SysTryReturnVoidResult(NID_MEDIA, pContent != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] ExifContent instance is not available."); + + _ExifUtil* pUtil = static_cast<_ExifUtil*>(pUserData); + SysTryReturnVoidResult(NID_MEDIA, pUtil != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _ExifUtil instance is not available."); + + pUtil->ForEachContent(pContent); +} + +void _ExifUtil::ForEachContent(struct _ExifContent *pContent) +{ + SysTryReturnVoidResult(NID_MEDIA, pContent != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] ExifContent instance is not available."); + + exif_content_log(pContent, __pExifLog); + exif_content_dump(pContent, 0); + + exif_content_foreach_entry(pContent, _ExifUtil::ForEachEntryStatic, this); +} + +void _ExifUtil::ForEachEntryStatic(struct _ExifEntry *pEntry, void *pUserData) +{ + SysTryReturnVoidResult(NID_MEDIA, pEntry != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] ExifEntry instance is not available."); + + _ExifUtil* pUtil = static_cast<_ExifUtil*>(pUserData); + SysTryReturnVoidResult(NID_MEDIA, pUtil != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _ExifUtil instance is not available."); + + pUtil->ForEachEntry(pEntry); +} + +void _ExifUtil::ForEachEntry(struct _ExifEntry *pEntry) +{ + SysTryReturnVoidResult(NID_MEDIA, pEntry != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] ExifEntry instance is not available."); + SysTryReturnVoidResult(NID_MEDIA, pEntry->parent != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Entry's parent instance is not available."); + + const ExifByteOrder o = exif_data_get_byte_order (pEntry->parent->parent); + ExifRational exifRational; + +#if defined (_EXIF_UTIL_LOG_) + char value[1024]; +#endif + + switch ((int)pEntry->tag) + { + case EXIF_TAG_ORIENTATION: + if (pEntry->format == EXIF_FORMAT_SHORT && pEntry->size == 2) + { + __orientation = *(short*)(pEntry->data); + __orientationExist = true; + } + break; + + case EXIF_TAG_GPS_LATITUDE: + if (pEntry->format == EXIF_FORMAT_RATIONAL) + { + /* + exifRational = exif_get_rational (pEntry->data, o); + + if (exifRational.denominator && exifRational.denominator != 1) { + __gpsLatitude = (double)exifRational.numerator / (double)exifRational.denominator; + } + else + { + __gpsLatitude = (double)exifRational.numerator; + } + */ + __gpsLatitude = 0.0; + for (int i = 0; i < (int)pEntry->components; i++) + { + exifRational = exif_get_rational (pEntry->data + 8 * i, o); + if (exifRational.denominator) + { + __gpsLatitude += ((double)exifRational.numerator / (double)exifRational.denominator) / pow((float)60.0, i); + } + else + { + __gpsLatitude += (double)exifRational.numerator / pow((float)60.0, i); + } + } + __gpsLatitudeExist = true; + } + break; + + case EXIF_TAG_GPS_LONGITUDE: + if (pEntry->format == EXIF_FORMAT_RATIONAL) + { + /* + exifRational = exif_get_rational (pEntry->data, o); + + if (exifRational.denominator && exifRational.denominator != 1) { + __gpsLatitude = (double)exifRational.numerator / (double)exifRational.denominator; + } else { + __gpsLatitude = (double)exifRational.numerator; + } + */ + __gpsLongitude = 0.0; + + for (int i = 0; i < (int)pEntry->components; i++) + { + exifRational = exif_get_rational (pEntry->data + 8 * i, o); + if (exifRational.denominator && exifRational.denominator != 1) + { + __gpsLongitude += ((double)exifRational.numerator / (double)exifRational.denominator) / pow((float)60.0, i); + } + else + { + __gpsLongitude += (double)exifRational.numerator / pow((float)60.0, i); + } + } + __gpsLongitudeExist = true; + } + break; + + case EXIF_TAG_GPS_ALTITUDE: + if (pEntry->format == EXIF_FORMAT_RATIONAL) + { + exifRational = exif_get_rational (pEntry->data, o); + + if (exifRational.denominator && exifRational.denominator != 1) + { + __gpsAltitude = (double)exifRational.numerator / (double)exifRational.denominator; + } + else + { + __gpsAltitude = (double)exifRational.numerator; + } + __gpsAltitudeExist = true; + } + break; + + default: + break; + } +} + +result _ExifUtil::GetValue(const Tizen::Base::String& key, int &value) +{ + if (key.Equals(EXIF_TAG_IMAGE_ORIENTATION, true)) + { + SysTryReturn(NID_MEDIA, __orientationExist, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] bool instance is not available. Orientation value was not found."); + value = __orientation; + } + else + { + SysLogException(NID_MEDIA, E_INVALID_ARG, "[E_INVALID_ARG] Key:%S was wrong.", key.GetPointer()); + return E_INVALID_ARG; + } + + return E_SUCCESS; +} + +result _ExifUtil::GetValue(const Tizen::Base::String& key, double &value) +{ + if (key.Equals(EXIF_TAG_IMAGE_GPS_ALTITUDE, true)) + { + SysTryReturn(NID_MEDIA, __gpsAltitudeExist, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] bool instance is not available. Altitude value was not found."); + value = __gpsAltitude; + } + else if (key.Equals(EXIF_TAG_IMAGE_GPS_LONGITUDE, true)) + { + SysTryReturn(NID_MEDIA, __gpsLongitude, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] bool instance is not available. Longitude value was not found."); + value = __gpsLongitude; + } else if (key.Equals(EXIF_TAG_IMAGE_GPS_LATITUDE, true)) + { + SysTryReturn(NID_MEDIA, __gpsLatitude, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] bool instance is not available. Latitude value was not found."); + value = __gpsLatitude; + } else + { + SysLogException(NID_MEDIA, E_INVALID_ARG, "[E_INVALID_ARG] Key:%S was wrong.", key.GetPointer()); + return E_INVALID_ARG; + } + + return E_SUCCESS; +} + +}} + diff --git a/src/FMedia_GifDecoderImpl.cpp b/src/FMedia_GifDecoderImpl.cpp new file mode 100644 index 0000000..1edb0b7 --- /dev/null +++ b/src/FMedia_GifDecoderImpl.cpp @@ -0,0 +1,173 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// +// @file FMedia_GifDecoder.cpp +// @brief This file has implementatoin details of GifDecoder class . +// +#include +#include +#include +#include +#include +#include +#include "FMedia_MediaUtil.h" +#include "FMedia_GifDecoder.h" +#include "FMedia_GifDecoderImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Graphics; + +namespace Tizen { namespace Media +{ + + +_GifDecoderImpl::_GifDecoderImpl() +{ +} + +_GifDecoderImpl::~_GifDecoderImpl() +{ +} + +result +_GifDecoderImpl::Construct(const Tizen::Base::String& filePath, MediaPixelFormat pixelFormat) +{ + result r = E_SUCCESS; + std::unique_ptr pByteBuffer; + + SysTryReturnResult(NID_MEDIA, __pGifDecoder.get() == null, E_INVALID_STATE, "Already constructed"); + __pGifDecoder.reset(new (std::nothrow) _GifDecoder); + SysTryReturnResult(NID_MEDIA, __pGifDecoder.get(), E_OUT_OF_MEMORY, "could not create _GifDecoder"); + + SysTryReturnResult(NID_MEDIA, (pixelFormat == MEDIA_PIXEL_FORMAT_BGRA8888 || pixelFormat == MEDIA_PIXEL_FORMAT_RGB565LE), + E_INVALID_ARG, "Invalid Pixel Format"); + + pByteBuffer.reset(_MediaUtil::FileToBufferN(filePath, 0)); + r = GetLastResult(); + SysTryReturn(NID_MEDIA, pByteBuffer.get() != null, r, r, "FiltToeBufferN:%S", filePath.GetPointer()); + r = __pGifDecoder->Construct(pByteBuffer->GetPointer(), pByteBuffer->GetLimit(), pixelFormat); + if (r != E_SUCCESS) + { + SysLogException(NID_MEDIA, r, "_GifDecoder::Construct failed"); + } + return r; +} + +result +_GifDecoderImpl::Construct(const Tizen::Base::ByteBuffer& srcBuf, MediaPixelFormat pixelFormat) +{ + result r = E_SUCCESS; + SysTryReturnResult(NID_MEDIA, __pGifDecoder.get() == null, E_INVALID_STATE, "Already constructed"); + __pGifDecoder.reset(new (std::nothrow) _GifDecoder); + SysTryReturnResult(NID_MEDIA, __pGifDecoder, E_OUT_OF_MEMORY, "could not create _GifDecoder"); + + SysTryReturnResult(NID_MEDIA, (pixelFormat == MEDIA_PIXEL_FORMAT_BGRA8888 || pixelFormat == MEDIA_PIXEL_FORMAT_RGB565LE), + E_INVALID_ARG, "Invalid Pixel Format"); + r = __pGifDecoder->Construct(srcBuf.GetPointer(), srcBuf.GetLimit(), pixelFormat); + if (r != E_SUCCESS) + { + SysLogException(NID_MEDIA, r, "_GifDecoder::Construct failed"); + } + return r; +} + +int +_GifDecoderImpl::GetWidth()const +{ + Dimension dim; + result r = E_SUCCESS; + SysTryReturnResult(NID_MEDIA, __pGifDecoder.get(), E_INVALID_STATE, "not constructed"); + r = __pGifDecoder->GetDimension(dim.width, dim.height); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, 0, r, "[%s] propagated", GetErrorMessage(r)); + return dim.width; +} + +int +_GifDecoderImpl::GetHeight()const +{ + Dimension dim; + result r = E_SUCCESS; + SysTryReturnResult(NID_MEDIA, __pGifDecoder.get(), E_INVALID_STATE, "not constructed"); + r = __pGifDecoder->GetDimension(dim.width, dim.height); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, 0, r, "[%s] propagated", GetErrorMessage(r)); + return dim.height; +} + +Tizen::Base::ByteBuffer* +_GifDecoderImpl::GetNextFrameN(long& duration) +{ + result r = E_SUCCESS; + std::unique_ptr pBuf; + std::unique_ptr pOutBuf; + int outLength = 0; + Long longValue; + + SysTryReturn(NID_MEDIA, __pGifDecoder.get(), null, E_INVALID_STATE, "not constructed"); + pOutBuf.reset(__pGifDecoder->DecodeN(outLength)); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated.", GetErrorMessage(r)); + if (!pOutBuf.get()) + { + SetLastResult(E_SUCCESS); + return null; + } + pBuf.reset(new (std::nothrow) ByteBuffer()); + SysTryReturn(NID_MEDIA, pBuf.get(), null, GetLastResult(), + "new ByteBuffer:%s", GetErrorMessage(GetLastResult())); + r = pBuf.get()->Construct(outLength); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, + "[%s] buf.Construct. %d", GetErrorMessage(r), outLength); + r = pBuf.get()->SetArray(pOutBuf.get(), 0, outLength); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated. ", GetErrorMessage(r)); + pBuf.get()->Flip(); + + r = __pGifDecoder->GetValue(String("duration"), longValue); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, + "[%s] dec.GetValue(duration)", GetErrorMessage(r)); + duration = longValue.ToLong(); + SetLastResult(E_SUCCESS); + return pBuf.release(); +} + +Tizen::Graphics::Bitmap* +_GifDecoderImpl::GetNextBitmapN(long& duration, Tizen::Graphics::BufferScaling bufferScaling) +{ + std::unique_ptr pBitmap; + std::unique_ptr pByteBuffer; + BitmapPixelFormat pixelFormat = BITMAP_PIXEL_FORMAT_MIN; + Dimension dim; + result r = E_SUCCESS; + + SysTryReturn(NID_MEDIA, __pGifDecoder.get(), null, E_INVALID_STATE, "not constructed"); + pByteBuffer.reset(GetNextFrameN(duration)); + SysTryReturn(NID_MEDIA, GetLastResult() == E_SUCCESS, null, GetLastResult(), "GetNextFameN failed "); + + if (pByteBuffer.get()) + { + pBitmap.reset(new (std::nothrow) Bitmap); + SysTryReturn(NID_MEDIA, pBitmap.get(), pBitmap.get(), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] could not allocate memory to bitmap"); + __pGifDecoder->GetDimension(dim.width, dim.height); + pixelFormat = (__pGifDecoder->GetPixelFormat() == MEDIA_PIXEL_FORMAT_RGB565LE) + ? BITMAP_PIXEL_FORMAT_RGB565 : BITMAP_PIXEL_FORMAT_ARGB8888; + r = pBitmap->Construct(*pByteBuffer.get(), dim, pixelFormat, bufferScaling); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null,r, "pBmp->Construct:%s", GetErrorMessage(r)); + } + SetLastResult(E_SUCCESS); + return pBitmap.release(); +} + +}} // Tizen::Media diff --git a/src/FMedia_GifDecoderImpl.h b/src/FMedia_GifDecoderImpl.h new file mode 100644 index 0000000..387c5df --- /dev/null +++ b/src/FMedia_GifDecoderImpl.h @@ -0,0 +1,142 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef _FMEDIA_INTERNAL_GIF_DECODER_IMPL_H_ +#define _FMEDIA_INTERNAL_GIF_DECODER_IMPL_H_ + +#include +namespace Tizen { namespace Media +{ + +class _GifDecoder; + +class _GifDecoderImpl + : public Tizen::Base::Object +{ +public: + /** + * The constructor. + */ + _GifDecoderImpl(void); + + /** + * The destructor. + */ + virtual ~_GifDecoderImpl(void); + + /** + * Initializes a new instance of this class + * + * @return An error code + * + * @param[in] filePath The file path of image. + * @param[in] pixelFormat The output pixel format of the decoded image. + * + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_STATE Current state is invalid. + * @exception E_INVALID_DATA The input data is invalid. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @exception E_INVALID_ARG A specified pixel format is not supported. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error occurred. + * @remarks Supported pixelFormats are MEDIA_PIXEL_FORMAT_RGB565LE, and MEDIA_PIXEL_FORMAT_BGRA8888. + */ + result Construct(const Tizen::Base::String& filePath, MediaPixelFormat pixelFormat); + + /** + * Initializes a new instance of this class + * + * @return An error code + * + * @param[in] srcBuf The source buffer that the image data is stored. + * @param[in] pixelFormat The output pixel format of the decoded image. + * + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_STATE Current state is invalid. + * @exception E_INVALID_DATA The input data is invalid. + * @exception E_INVALID_ARG A specified pixel format is not supported. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error occurred. + * @remarks Supported pixelFormats are MEDIA_PIXEL_FORMAT_RGB565LE, and MEDIA_PIXEL_FORMAT_BGRA8888. + */ + result Construct(const Tizen::Base::ByteBuffer& srcBuf, MediaPixelFormat pixelFormat); + + /** + * Gets the width of the image. + * + * @return The width of image, @n + * else @c 0 when an error occurred. + * + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_STATE Current state is invalid. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + int GetWidth(void) const; + + /** + * Gets the height of the image. + * + * @return The height of the image, @n + * else @c 0 when an error occurred. + * + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_STATE Current state is invalid. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + int GetHeight(void) const; + + /** + * Decodes and gets the next frame in RAW RGB format. + * + * @return The next decoded frame. @n + * else @c null when no frame is left or an error occurred. + * @param[out] duration The duration of returned frame in miliseconds. + * + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_STATE Current state is invalid. + * @exception E_INVALID_DATA The data of the next frame is invalid. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception ImplE_SYSTEM A system error occurred. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Base::ByteBuffer* GetNextFrameN(long& duration); + + /** + * Decodes and gets the next frame in Bitmap format. + * + * @return The next decoded frame. @n + * else @c null when no frame is left or an error occurred. + * @param[out] duration The duration of returned frame in miliseconds. + * @param[in] bufferScaling The buffer scaling type. + * + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_STATE Current state is invalid. + * @exception E_INVALID_DATA The data of the next frame is invalid. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error occurred. + * @remarks When autoScale parameter is true auto scaled Bitmap will be returned. @n + * The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Graphics::Bitmap* GetNextBitmapN(long& duration, Tizen::Graphics::BufferScaling bufferScaling = Tizen::Graphics::BUFFER_SCALING_AUTO); +private: + _GifDecoderImpl(const _GifDecoderImpl& rhs); + _GifDecoderImpl& operator =(const _GifDecoderImpl& rhs); + std::unique_ptr<_GifDecoder> __pGifDecoder; +}; + +}}; +#endif diff --git a/src/FMedia_ImageBufferImpl.cpp b/src/FMedia_ImageBufferImpl.cpp new file mode 100644 index 0000000..00e8831 --- /dev/null +++ b/src/FMedia_ImageBufferImpl.cpp @@ -0,0 +1,1108 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMedia_ImageBufferImpl.cpp + * @brief This file contains the implementation of ImageBuffer's impl layer. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMedia_ImageBufferImpl.h" +#include "FMedia_ImageUtil.h" +#include "FMedia_ImageUtilImpl.h" +#include "FMedia_ImageDecoder.h" +#include "FMedia_ImageEncoder.h" +#include "FMedia_ColorConverter.h" +#include "FMedia_ExifUtil.h" + +using namespace Tizen::Graphics; +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; +using namespace Tizen::App; + +namespace Tizen { namespace Media +{ + +#define ISSUPPORTED(x) \ + ((x == MEDIA_PIXEL_FORMAT_YUV420P) || (x == MEDIA_PIXEL_FORMAT_BGRA8888) || \ + (x == MEDIA_PIXEL_FORMAT_RGB565LE) || (x == MEDIA_PIXEL_FORMAT_GRAY)) + +enum _ExifOrientation +{ + EXIF_ORIENTATION_TOP_LEFT = 0x01, /**< The row #0 is top, column #0 is left */ + EXIF_ORIENTATION_TOP_RIGHT, /**< The row #0 is top, column #0 is right */ + EXIF_ORIENTATION_BOTTOM_RIGHT, /**< The row #0 is bottom, column #0 is right */ + EXIF_ORIENTATION_BOTTOM_LEFT, /**< The row #0 is bottom, column #0 is left */ + EXIF_ORIENTATION_LEFT_TOP, /**< The row #0 is left, column #0 is top */ + EXIF_ORIENTATION_RIGHT_TOP, /**< The row #0 is right, column #0 is top */ + EXIF_ORIENTATION_RIGHT_BOTTOM, /**< The row #0 is right, column #0 is bottom */ + EXIF_ORIENTATION_LEFT_BOTTOM, /**< The row #0 is left, column #0 is bottom */ +}; + +typedef struct { + ImageRotationType rotateType; + ImageFlipType flipType; + bool dimensionSwitch; +} _ImageExifInfo; + +static const _ImageExifInfo _IMAGE_ROTATE_FLIP_MAP[] = { + { IMAGE_ROTATION_0, IMAGE_FLIP_NONE, false }, /* NONE */ + { IMAGE_ROTATION_0, IMAGE_FLIP_NONE, false }, /* TOP_LEFT */ + { IMAGE_ROTATION_0, IMAGE_FLIP_VERTICAL, false }, /* TOP_RIGHT */ + { IMAGE_ROTATION_180, IMAGE_FLIP_NONE, false }, /* BOTTOM_RIGHT */ + { IMAGE_ROTATION_0, IMAGE_FLIP_HORIZONTAL, false }, /* BOTTOM_LEFT */ + { IMAGE_ROTATION_90, IMAGE_FLIP_VERTICAL, true }, /* LEFT_TOP */ + { IMAGE_ROTATION_90, IMAGE_FLIP_NONE, true }, /* RIGHT_TOP */ + { IMAGE_ROTATION_90, IMAGE_FLIP_HORIZONTAL, true }, /* RIGHT_BOTTOM */ + { IMAGE_ROTATION_270, IMAGE_FLIP_NONE, true } /* LEFT_BOTTOM */ +}; + +static const MediaPixelFormat _IMAGE_BUFFER_PIXEL_FORMATS[] = +{ + MEDIA_PIXEL_FORMAT_RGB565LE, + MEDIA_PIXEL_FORMAT_BGRA8888, + MEDIA_PIXEL_FORMAT_YUV420P +}; + +_ImageBufferImpl::_ImageBufferImpl(void) + : __pBuffer(null) + , __width(0) + , __height(0) + , __pixelFormat(MEDIA_PIXEL_FORMAT_NONE) + , __isLocked(false) +{ +} + +_ImageBufferImpl::~_ImageBufferImpl(void) +{ +} + +result +_ImageBufferImpl::Construct(int width, int height, MediaPixelFormat pixelFormat) +{ + result r = E_SUCCESS; + int length = 0; + + __width = width; + __height = height; + __pixelFormat = pixelFormat; + + SysTryReturn(NID_MEDIA, IsSupportedPixelFormat(pixelFormat) == true , null, E_UNSUPPORTED_FORMAT, + "[E_UNSUPPORTED_FORMAT] The specified pixelFormat is not supported.") + + length = _ImageUtil::GetBufferSize(__pixelFormat, __width, __height); + SysTryReturn(NID_MEDIA, length > 0, E_INVALID_ARG, E_INVALID_ARG, + "[E_INVALID_ARG] Check inputs: (%d x %d), pixel format (%d).", + __width, __height, __pixelFormat); + + __pBuffer.reset(new (std::nothrow) ByteBuffer); + SysTryReturn(NID_MEDIA, __pBuffer.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Construct instance failed."); + + r = __pBuffer->Construct(length); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, + "[%s] Construct instance failed.", GetErrorMessage(r)); + + return r; +} + +result +_ImageBufferImpl::Construct(int width, int height, MediaPixelFormat pixelFormat, + const byte* pData, int length) +{ + result r = E_SUCCESS; + int reqBufferSize = 0; + + SysTryReturn(NID_MEDIA, IsSupportedPixelFormat(pixelFormat) == true , E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT, + "[E_UNSUPPORTED_FORMAT] The specified pixelFormat is not supported.") + + SysTryReturn(NID_MEDIA, (width > 0) && (height > 0), E_INVALID_ARG, E_INVALID_ARG, + "[E_INVALID_ARG] Dimensions should be greater than zero : (%d x %d).", width, height); + + SysTryReturn(NID_MEDIA, ISSUPPORTED(pixelFormat) == true, E_INVALID_ARG, E_INVALID_ARG, + "[E_INVALID_ARG] Pixelformat is not supported : %d.", pixelFormat); + + reqBufferSize = _ImageUtil::GetBufferSize(pixelFormat, width, height); + + if (pData != null) + { + SysTryReturn(NID_MEDIA, reqBufferSize <= length, E_INVALID_ARG, E_INVALID_ARG, + "[E_INVALID_ARG] Check length. Required for (%d x %d) in %d format is %d : arg = %d.", + width, height, pixelFormat, length); + } + + __width = width; + __height = height; + __pixelFormat = pixelFormat; + + __pBuffer.reset(new (std::nothrow) ByteBuffer); + SysTryReturn(NID_MEDIA, __pBuffer.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Construct instance failed."); + + r = __pBuffer->Construct(reqBufferSize); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, + "[%s] Construct instance failed.", GetErrorMessage(r)); + + if (pData != null) + { + r = __pBuffer->SetArray(pData, 0, reqBufferSize); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, + "[%s] SetArray for buffer %x of length %d failed.", GetErrorMessage(r), + pData, reqBufferSize); + } + __pBuffer->Flip(); + return r; +} + +result +_ImageBufferImpl::Construct(const Tizen::Base::String &srcImagePath, const Rectangle *pDecodingRegion, bool autoRotate) +{ + result r = E_SUCCESS; + + std::unique_ptr pBuf; + pBuf.reset(_MediaUtil::FileToBufferN(srcImagePath)); + SysTryReturn(NID_MEDIA, pBuf.get() != null, GetLastResult(), GetLastResult(), + "[%s] FileToBufferN %S", GetErrorMessage(GetLastResult()), srcImagePath.GetPointer()); + r = Construct(*pBuf.get(), pDecodingRegion, autoRotate); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] ImageBuffer construct failed.", GetErrorMessage(r)); + return r; +} + +result +_ImageBufferImpl::Construct(const Tizen::Base::ByteBuffer &srcImageBuf, const Tizen::Graphics::Rectangle *pDecodingRegion, bool autoRotate) +{ + + result r = E_SUCCESS; + + _ImageDecoder dec; + std::unique_ptr pDstBuf; + Tizen::Graphics::Rectangle transformRegion; + int orientationInfo = 0; + + r = dec.Construct(srcImageBuf); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Decoder construct failed.", GetErrorMessage(r)); + + __pixelFormat = dec.GetPixelFormat(); + r = GetLastResult(); + SysTryReturn(NID_MEDIA, __pixelFormat != MEDIA_PIXEL_FORMAT_NONE, r, r, + "[%s] GetPixelFormat failed.", GetErrorMessage(r)); + + if(autoRotate == true) + { + _ExifUtil imgExif; + imgExif.Construct(srcImageBuf.GetPointer(), srcImageBuf.GetCapacity()); + imgExif.GetValue(EXIF_TAG_IMAGE_ORIENTATION, orientationInfo); + // imgExif.GetValue() will return "r = E_OBJ_NOT_FOUND" if it could not be found exif infomation. + // However, the result should be decided by result of construct in this function. + SetLastResult(E_SUCCESS); + } + + if (pDecodingRegion != null) + { + int imgWidth = 0; + int imgHeight = 0; + ImageRotationType rotateType = _IMAGE_ROTATE_FLIP_MAP[orientationInfo].rotateType; + ImageFlipType flipType = _IMAGE_ROTATE_FLIP_MAP[orientationInfo].flipType; + + r = dec.GetDimension(imgWidth, imgHeight); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] dec.GetDimension", GetErrorMessage(r)); + + if (rotateType == IMAGE_ROTATION_90 || rotateType == IMAGE_ROTATION_270) + { + SysTryReturn(NID_MEDIA, imgHeight >= (pDecodingRegion->x + pDecodingRegion->width) + && imgWidth >= (pDecodingRegion->y + pDecodingRegion->height), + E_INVALID_ARG, E_INVALID_ARG, + "[E_INVALID_ARG] imageWidth = %d, imageHeight = %d, x = %d, y = %d, width = %d, height = %d", + imgHeight, imgWidth, pDecodingRegion->x, pDecodingRegion->y, + pDecodingRegion->width, pDecodingRegion->height); + } + else + { + SysTryReturn(NID_MEDIA, imgWidth >= (pDecodingRegion->x + pDecodingRegion->width) + && imgHeight >= (pDecodingRegion->y + pDecodingRegion->height), + E_INVALID_ARG, E_INVALID_ARG, + "[E_INVALID_ARG] imageWidth = %d, imageHeight = %d, x = %d, y = %d, width = %d, height = %d", + imgWidth, imgHeight, pDecodingRegion->x, pDecodingRegion->y, + pDecodingRegion->width, pDecodingRegion->height); + } + + if(autoRotate == true) + { + if (rotateType == IMAGE_ROTATION_90) + { + transformRegion.x = pDecodingRegion->y; + transformRegion.y = imgHeight-(pDecodingRegion->width+pDecodingRegion->x); + transformRegion.width = pDecodingRegion->height; + transformRegion.height = pDecodingRegion->width; + } + else if (rotateType == IMAGE_ROTATION_180) + { + transformRegion.x = imgWidth-(pDecodingRegion->width+pDecodingRegion->x); + transformRegion.y = imgHeight-(pDecodingRegion->height+pDecodingRegion->y); + transformRegion.width = pDecodingRegion->width; + transformRegion.height = pDecodingRegion->height; + } + else if (rotateType == IMAGE_ROTATION_270) + { + transformRegion.x = imgWidth-(pDecodingRegion->height+pDecodingRegion->y); + transformRegion.y = pDecodingRegion->x; + transformRegion.width = pDecodingRegion->height; + transformRegion.height = pDecodingRegion->width; + } + else + { + transformRegion.x = pDecodingRegion->x; + transformRegion.y = pDecodingRegion->y; + transformRegion.width = pDecodingRegion->width; + transformRegion.height = pDecodingRegion->height; + } + + if (flipType == IMAGE_FLIP_VERTICAL) + { + transformRegion.x = imgWidth-(transformRegion.width+transformRegion.x); + } + else if (flipType == IMAGE_FLIP_HORIZONTAL) + { + transformRegion.y = imgHeight-(transformRegion.height+transformRegion.y); + } + } + else + { + transformRegion.x = pDecodingRegion->x; + transformRegion.y = pDecodingRegion->y; + transformRegion.width = pDecodingRegion->width; + transformRegion.height = pDecodingRegion->height; + } + + r = dec.SetDecodingRegion(transformRegion.x, transformRegion.y, + transformRegion.width, transformRegion.height); + + SysTryReturn(NID_MEDIA, r == E_SUCCESS || r == E_UNSUPPORTED_OPERATION, r, r, + "[%s] dec.SetDecodingRegion:%d %d %d %d", GetErrorMessage(r), + pDecodingRegion->x, pDecodingRegion->y, pDecodingRegion->width, pDecodingRegion->height); + + __width = transformRegion.width; + __height = transformRegion.height; + + if (r == E_SUCCESS) + { + __pBuffer.reset(dec.DecodeN()); + r = GetLastResult(); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] DecodeN failed.", + GetErrorMessage(r)); + SysTryReturn(NID_MEDIA, __pBuffer.get() != null, r, r, + "[%s] DecodeN returned empty buffer.", GetErrorMessage(r)); + } + else if (r == E_UNSUPPORTED_OPERATION) + { + // crop image + ByteBuffer *pTmpBuf = null; + + __pBuffer.reset(dec.DecodeN()); + r = GetLastResult(); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagated. ", GetErrorMessage(r)); + + pTmpBuf = _ImageUtil::CropN(*__pBuffer.get(), __pixelFormat, imgWidth, imgHeight, + transformRegion.x, transformRegion.y, transformRegion.width, transformRegion.height); + SysTryReturn(NID_MEDIA, pTmpBuf != null, GetLastResult(), GetLastResult(), + "[%s] Crop:%x %d %d %d %d %d %d %d", GetErrorMessage(GetLastResult()), __pBuffer->GetPointer(), + __pixelFormat, imgWidth, imgHeight, pDecodingRegion->x, pDecodingRegion->y, + pDecodingRegion->width, pDecodingRegion->height); + + __pBuffer.reset(pTmpBuf); + } + } + else + { + r = dec.GetDimension(__width, __height); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] GetDimension failed.", + GetErrorMessage(r)); + + __pBuffer.reset(dec.DecodeN()); + r = GetLastResult(); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] DecodeN failed.", + GetErrorMessage(r)); + SysTryReturn(NID_MEDIA, __pBuffer.get() != null, r, r, + "[%s] DecodeN returned empty buffer.", GetErrorMessage(r)); + } + + if (autoRotate == true) + { + ByteBuffer *pTmpBuf = null; + int tempWidth = 0; + int length = 0; + + if (orientationInfo == EXIF_ORIENTATION_TOP_LEFT || orientationInfo == 0) + { + return E_SUCCESS; + } + + if (orientationInfo > EXIF_ORIENTATION_LEFT_BOTTOM || orientationInfo < EXIF_ORIENTATION_TOP_LEFT) + { + return E_SUCCESS; + } + + pDstBuf.reset(new (std::nothrow) ByteBuffer()); + SysTryReturn(NID_MEDIA, pDstBuf.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]"); + + length = _ImageUtil::GetBufferSize(__pixelFormat, __width, __height); + + pDstBuf->Construct(length); + pDstBuf->SetLimit(length); + pDstBuf->SetPosition(0); + + ImageRotationType rotateType = _IMAGE_ROTATE_FLIP_MAP[orientationInfo].rotateType; + ImageFlipType flipType = _IMAGE_ROTATE_FLIP_MAP[orientationInfo].flipType; + + r = _ImageUtil::Rotate(*__pBuffer.get(), __pixelFormat, __width, __height, *pDstBuf.get(), rotateType); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] _ImageUtil:Resize", GetErrorMessage(r)); + if(_IMAGE_ROTATE_FLIP_MAP[orientationInfo].dimensionSwitch == true) + { + tempWidth = __width; + __width = __height; + __height = tempWidth; + } + + __pBuffer.swap(pDstBuf); + + if (flipType != IMAGE_FLIP_NONE) + { + r = _ImageUtil::Flip(*__pBuffer.get(), __pixelFormat, __width, __height, *pDstBuf, flipType); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] _ImageUtil:Flip", GetErrorMessage(r)); + __pBuffer.swap(pDstBuf); + } + } + return r; +} + +result +_ImageBufferImpl::Construct(const Bitmap &srcBitmap) +{ + BufferInfo info; + Bitmap *pTmpBmp = null; + int bpp = 0; + int length = 0; + result r = E_SUCCESS; + + pTmpBmp = (const_cast(&srcBitmap)); + SysTryReturn(NID_MEDIA, pTmpBmp != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Construct instance failed."); + + r = pTmpBmp->Lock(info); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Bitmap.Lock failed.", + GetErrorMessage(r)); + + __width = info.width; + __height = info.height; + bpp = info.bitsPerPixel / 8; + length = __width * __height * bpp; + + __pixelFormat = _ImageUtilImpl::ToMediaPixelFormat(srcBitmap.GetPixelColorFormat()); + + __pBuffer.reset(new (std::nothrow) ByteBuffer); + SysTryCatch(NID_MEDIA, __pBuffer.get(), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Construct instance failed."); + + r = __pBuffer->Construct(length); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, + "[%s] Construct instance failed.", GetErrorMessage(r)); + r = __pBuffer->SetArray((byte*)info.pPixels, 0, length); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagated.", GetErrorMessage(r)); + + r = pTmpBmp->Unlock(); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Bitmap.Unlock failed.", GetErrorMessage(r)); + + __pBuffer->Flip(); + + return r; + +CATCH: + pTmpBmp->Unlock(); + + return r; +} + +bool +_ImageBufferImpl::Equals(ImageBuffer* pRhs) const +{ + _ImageBufferImpl* pRhsImpl = null; + byte* pRawOther = null; + int lengthOther = 0; + MediaPixelFormat pixFmtOther = MEDIA_PIXEL_FORMAT_NONE; + + byte* pRawThis = null; + int lengthThis = 0; + MediaPixelFormat pixFmtThis = MEDIA_PIXEL_FORMAT_NONE; + + bool out = false; + result r = E_SUCCESS; + + if (pRhs == null) + { + out = false; + } + else + { + pRhsImpl = GetInstance(*pRhs); + if (pRhsImpl == null) + { + out = false; + } + else if (pRhsImpl == this) + { + out = true; + } + else + { + // Compare dimensions. + if ((__height != pRhsImpl->GetHeight()) || (__width != pRhsImpl->GetWidth())) + { + out = false; + } + else + { + r = const_cast<_ImageBufferImpl*>(pRhsImpl)->Lock(pRawOther, lengthOther, pixFmtOther); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, false, r, + "[%s] Could not lock RHS ImageBuffer contents.", GetErrorMessage(r)); + + r = const_cast<_ImageBufferImpl *>(this)->Lock(pRawThis, lengthThis, pixFmtThis); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, false, r, + "[%s] Could not lock this ImageBuffer contents.", GetErrorMessage(r)); + + // Check if contents are equal. + if ((__pixelFormat != pixFmtOther) || (__pBuffer->GetCapacity() != lengthOther)) + { + out = false; + } + else + { + if (memcmp(pRawOther, pRawThis, lengthOther) == 0) + { + out = true; + } + else + { + out = false; + } + } + } + } + } + + return out; +} + +int +_ImageBufferImpl::GetHashCode() const +{ + int hashCode = 0; + + hashCode = __pBuffer->GetHashCode(); + + hashCode = (hashCode ^ (__width * __height)) | (hashCode & __pixelFormat); + + return hashCode; +} + +int +_ImageBufferImpl::GetHeight() const +{ + return __height; +} + +int +_ImageBufferImpl::GetWidth() const +{ + return __width; +} + +MediaPixelFormat +_ImageBufferImpl::GetPixelFormat() const +{ + return __pixelFormat; +} + +result +_ImageBufferImpl::Lock(byte* &data, int &length, MediaPixelFormat &pixelFormat) +{ + result r = E_SUCCESS; + + SysTryReturn(NID_MEDIA, __isLocked != true, E_INVALID_STATE, E_INVALID_STATE, + "[E_INVALID_STATE] Instance is locked. Unlock to use."); + + data = const_cast(__pBuffer->GetPointer()); + length = _ImageUtil::GetBufferSize(__pixelFormat, __width, __height); + pixelFormat = __pixelFormat; + + __isLocked = true; + + return r; +} + +result +_ImageBufferImpl::Unlock() +{ + result r = E_SUCCESS; + + SysTryReturn(NID_MEDIA, __isLocked, E_INVALID_STATE, E_INVALID_STATE, + "[E_INVALID_STATE] Instance is not locked."); + + __isLocked = false; + + return r; +} + +ByteBuffer* +_ImageBufferImpl::EncodeToBufferN(ImageFormat destImageFormat, int quality) const +{ + result r = E_SUCCESS; + int inLength = 0; + ByteBuffer* pBuf = null; + + SysTryReturn(NID_MEDIA, !__isLocked, null, E_INVALID_STATE, + "[E_INVALID_STATE] Instance is locked. Unlock to use."); + + inLength = _ImageUtil::GetBufferSize(__pixelFormat, __width, __height); + pBuf = _ImageEncoder::EncodeN(destImageFormat, (const byte*)__pBuffer->GetPointer(), inLength, __width, __height, + __pixelFormat, quality); + SysTryReturn(NID_MEDIA, pBuf != null, null, GetLastResult(), "[%s] Propagated. ", GetErrorMessage(GetLastResult())); + + SetLastResult(r); + return pBuf; +} + +result +_ImageBufferImpl::EncodeToFile(const String &destImagePath, ImageFormat destImageFormat, + bool overwrite, int quality) const +{ + result r = E_SUCCESS; + std::unique_ptr pBuf; + + SysTryReturn(NID_MEDIA, !__isLocked, E_INVALID_STATE, E_INVALID_STATE, + "[E_INVALID_STATE] Instance is locked. Unlock to use."); + + pBuf.reset(this->EncodeToBufferN(destImageFormat, quality)); + SysTryReturn(NID_MEDIA, pBuf.get() != null, GetLastResult(), GetLastResult(), + "[%s] Propagated. ", GetErrorMessage(GetLastResult())); + + r = _MediaUtil::BufferToFile(*pBuf.get(), destImagePath, overwrite); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagated. ", GetErrorMessage(r)); + + return r; +} + +Bitmap* +_ImageBufferImpl::GetBitmapN(BitmapPixelFormat pixelFormat, BufferScaling bufferScaling) const +{ + result r = E_SUCCESS; + std::unique_ptr pOutBitmap; + std::unique_ptr pConverted; + MediaPixelFormat inPixelFormat = MEDIA_PIXEL_FORMAT_NONE; + + SysTryReturn(NID_MEDIA, !__isLocked, null, E_INVALID_STATE, + "[E_INVALID_STATE] Instance is locked. Unlock to use."); + + inPixelFormat = _ImageUtilImpl::ToMediaPixelFormat(pixelFormat); + SysTryReturn(NID_MEDIA, inPixelFormat != MEDIA_PIXEL_FORMAT_NONE, null, E_INVALID_ARG, + "[E_INVALID_ARG] Pixel format is %d, invalid or not supported.", pixelFormat); + + if (inPixelFormat != __pixelFormat) + { + // Convert raw data to the required pixel format. + pConverted.reset(GetByteBufferN(inPixelFormat)); + r = GetLastResult(); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated.", GetErrorMessage(r)); + } + + pOutBitmap.reset(new (std::nothrow) Bitmap); + SysTryReturn(NID_MEDIA, pOutBitmap.get() != null, null, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Propagated."); + + if (inPixelFormat != __pixelFormat) + { + r = pOutBitmap->Construct(*pConverted.get(), Dimension(__width, __height), pixelFormat, bufferScaling); + } + else + { + r = pOutBitmap->Construct(*__pBuffer, Dimension(__width, __height), pixelFormat, bufferScaling); + } + + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated.", + GetErrorMessage(r)); + return pOutBitmap.release(); +} + +ByteBuffer* +_ImageBufferImpl::GetByteBufferN(MediaPixelFormat inPixelFormat) const +{ + result r = E_SUCCESS; + std::unique_ptr pOutBuf; + + SysTryReturn(NID_MEDIA, !__isLocked, null, E_INVALID_STATE, + "[E_INVALID_STATE] Instance is locked. Unlock to use."); + + SysTryReturn(NID_MEDIA, (inPixelFormat > MEDIA_PIXEL_FORMAT_NONE) && (inPixelFormat <= MEDIA_PIXEL_FORMAT_YUYV422), + null, E_INVALID_ARG, "[E_INVALID_ARG] Pixel format is invalid.", inPixelFormat); + + SysTryReturn(NID_MEDIA, IsSupportedPixelFormat(inPixelFormat) == true , null, E_UNSUPPORTED_FORMAT, + "[E_UNSUPPORTED_FORMAT] The specified pixelFormat is not supported.") + + if (inPixelFormat != __pixelFormat) + { + // Convert raw data to the required pixel format. + _ColorConverter cvt; + + r = cvt.Construct(__pixelFormat, __width, __height, + inPixelFormat, __width, __height); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated.", GetErrorMessage(r)); + + pOutBuf.reset(cvt.ConvertN(*__pBuffer)); + r = GetLastResult(); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated.", GetErrorMessage(r)); + } + else + { + pOutBuf.reset(new (std::nothrow) ByteBuffer); + SysTryReturn(NID_MEDIA, pOutBuf.get() != null, null, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Propagated."); + + r = pOutBuf->Construct(*__pBuffer); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, + "[%s] Propagated.", GetErrorMessage(r)); + } + + SetLastResult(r); + return pOutBuf.release(); +} + +ImageBuffer* +_ImageBufferImpl::CloneN() const +{ + std::unique_ptr pImgBuffer; + _ImageBufferImpl* pImgBufferImpl = null; + result r = E_SUCCESS; + byte* pData = null; + int length = 0; + MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE; + + r = const_cast<_ImageBufferImpl *>(this)->Lock(pData, length, pixFmt); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, pImgBuffer.get(), r, "[%s] Propagated.", GetErrorMessage(r)); + + pImgBuffer.reset(new (std::nothrow) ImageBuffer); + SysTryReturn(NID_MEDIA, pImgBuffer.get() != null, null, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Could not create new instance.") + + r = pImgBuffer->Construct(__width, __height, pixFmt, pData, length); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, + "[%s] Failed to construct the cloned ImageBuffer.", GetErrorMessage(r)); + + const_cast<_ImageBufferImpl *>(this)->Unlock(); + + SetLastResult(r); + return pImgBuffer.release(); +} + +ImageBuffer* +_ImageBufferImpl::ConvertPixelFormatN(MediaPixelFormat pixelFormat) const +{ + std::unique_ptr pImgBuffer; + _ImageBufferImpl* pImgBufferImpl = null; + result r = E_SUCCESS; + byte* pData = null; + std::unique_ptr pDataConvert; + int length = 0; + int dstLength = 0; + MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE; + + SysTryReturn(NID_MEDIA, ISSUPPORTED(pixelFormat) == true, pImgBuffer.get(), E_INVALID_ARG, + "[E_INVALID_ARG] Pixel format %d is not supported.", pixelFormat); + + if (pixelFormat != __pixelFormat) + { + _ColorConverter cvt; + + r = cvt.Construct(__pixelFormat, __width, __height, + pixelFormat, __width, __height); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagated.", GetErrorMessage(r)); + + r = const_cast<_ImageBufferImpl *>(this)->Lock(pData, length, pixFmt); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, + "[%s] Lock failed. Propagated.", GetErrorMessage(r)); + + pDataConvert.reset(cvt.ConvertN(pData, length, dstLength)); + r = GetLastResult(); + SysTryCatch(NID_MEDIA, (r == E_SUCCESS) && (pDataConvert.get() != null), , r, + "[%s] Failed to convert data to required pixelformat.", GetErrorMessage(r)); + + const_cast<_ImageBufferImpl *>(this)->Unlock(); + + pImgBuffer.reset(new (std::nothrow) ImageBuffer); + SysTryCatch(NID_MEDIA, pImgBuffer.get() != null, , E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Could not create new instance.") + + r = pImgBuffer->Construct(__width, __height, pixelFormat, pDataConvert.get(), dstLength); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, + "[%s] Failed to construct the converted ImageBuffer.", GetErrorMessage(r)); + } + else + { + pImgBuffer.reset(CloneN()); + } + + SetLastResult(r); + return pImgBuffer.release(); + +CATCH: + const_cast<_ImageBufferImpl *>(this)->Unlock(); + SetLastResult(r); + return null; +} + +ImageBuffer* +_ImageBufferImpl::ResizeN(int width, int height) const +{ + std::unique_ptr pImgBuffer; + _ImageBufferImpl* pImgBufferImpl = null; + result r = E_SUCCESS; + byte* pData = null; + std::unique_ptr pDataResized; + int length = 0; + int dstLength = 0; + MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE; + + SysTryReturn(NID_MEDIA, (width > 0) && (height > 0), pImgBuffer.get(), E_INVALID_ARG, + "[E_INVALID_ARG] Dimensions should be greater than zero: (%d x %d)", width, height); + + if ((width != __width) && (height != __height)) + { + dstLength = _ImageUtil::GetBufferSize(__pixelFormat, width, height); + SysTryReturn(NID_MEDIA, dstLength > 0, pImgBuffer.get(), GetLastResult(), + "[%s] Failed to get valid buffer length for (%d x %d), pixel format %d.", + GetErrorMessage(GetLastResult()), width, height, __pixelFormat); + + pDataResized.reset(new (std::nothrow) byte[dstLength]); + SysTryReturn(NID_MEDIA, pDataResized.get() != null, pImgBuffer.get(), E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Failed to allocate %d bytes.", dstLength); + + r = const_cast<_ImageBufferImpl *>(this)->Lock(pData, length, pixFmt); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, + "[%s] Lock failed. Propagated.", GetErrorMessage(r)); + + r = _ImageUtil::ResizeBuffer(pData, __pixelFormat, __width, __height, + pDataResized.get(), width, height); + SysTryCatch(NID_MEDIA, (r == E_SUCCESS) && (pDataResized.get() != null), , r, + "[%s] Could not resize buffer.", GetErrorMessage(r)); + + const_cast<_ImageBufferImpl *>(this)->Unlock(); + + pImgBuffer.reset(new (std::nothrow) ImageBuffer); + SysTryCatch(NID_MEDIA, pImgBuffer.get() != null, , E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Could not create new instance.") + + r = pImgBuffer->Construct(width, height, __pixelFormat, pDataResized.get(), dstLength); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, + "[%s] Failed to construct the resized ImageBuffer.", GetErrorMessage(r)); + } + else + { + pImgBuffer.reset(CloneN()); + } + + SetLastResult(r); + return pImgBuffer.release(); + +CATCH: + + const_cast<_ImageBufferImpl *>(this)->Unlock(); + SetLastResult(r); + return null; +} + +ImageBuffer* +_ImageBufferImpl::FlipN(ImageFlipType flipType) const +{ + std::unique_ptr pImgBuffer; + _ImageBufferImpl* pImgBufferImpl = null; + result r = E_SUCCESS; + byte* pData = null; + std::unique_ptr pDataFlip; + int length = 0; + MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE; + + SysTryReturn(NID_MEDIA, (flipType >= IMAGE_FLIP_NONE) && (flipType <= IMAGE_FLIP_VERTICAL), + pImgBuffer.get(), E_INVALID_ARG, "[E_INVALID_ARG] Flip type is not valid: %d.", flipType); + + if (flipType != IMAGE_FLIP_NONE) + { + r = const_cast<_ImageBufferImpl *>(this)->Lock(pData, length, pixFmt); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, pImgBuffer.get(), r, + "[%s] Lock failed. Propagated.", GetErrorMessage(r)); + + pDataFlip.reset(new (std::nothrow) byte[length]); + SysTryCatch(NID_MEDIA, pDataFlip.get() != null, , E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Could not allocate %d bytes for flipped output.", length); + + r = _ImageUtil::FlipBuffer(pData, __pixelFormat, __width, __height, pDataFlip.get(), flipType); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, + "[%s] Could not flip the data.", GetErrorMessage(r)); + + const_cast<_ImageBufferImpl *>(this)->Unlock(); + + pImgBuffer.reset(new (std::nothrow) ImageBuffer); + SysTryCatch(NID_MEDIA, pImgBuffer.get() != null, , E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Could not create new instance.") + + r = pImgBuffer->Construct(__width, __height, __pixelFormat, pDataFlip.get(), length); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, + "[%s] Failed to construct the fliped ImageBuffer.", GetErrorMessage(r)); + } + else + { + pImgBuffer.reset(CloneN()); + } + + SetLastResult(r); + return pImgBuffer.release(); + +CATCH: + + const_cast<_ImageBufferImpl *>(this)->Unlock(); + + SetLastResult(r); + return null; +} + +ImageBuffer* +_ImageBufferImpl::RotateN(ImageRotationType rotationType) const +{ + std::unique_ptr pImgBuffer; + _ImageBufferImpl* pImgBufferImpl = null; + result r = E_SUCCESS; + byte* pData = null; + std::unique_ptr pDataRotate; + int length = 0; + int rotatedWidth= 0; + int rotatedHeight = 0; + MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE; + + SysTryReturn(NID_MEDIA, (rotationType >= IMAGE_ROTATION_0) && (rotationType <= IMAGE_ROTATION_270), + pImgBuffer.get(), E_INVALID_ARG, "[E_INVALID_ARG] Rotation type is not valid: %d.", rotationType); + + if (rotationType != IMAGE_ROTATION_0) + { + r = const_cast<_ImageBufferImpl *>(this)->Lock(pData, length, pixFmt); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, pImgBuffer.get(), r, + "[%s] Lock failed. Propagated.", GetErrorMessage(r)); + + pDataRotate.reset(new (std::nothrow) byte[length]); + SysTryCatch(NID_MEDIA, pDataRotate.get() != null, , E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Could not allocate %d bytes for rotated output.", length); + + r = _ImageUtil::RotateBuffer(pData, __pixelFormat, __width, __height, pDataRotate.get(), + rotatedWidth, rotatedHeight, rotationType); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, + "[%s] Could not rotate the data.", GetErrorMessage(r)); + + const_cast<_ImageBufferImpl *>(this)->Unlock(); + + pImgBuffer.reset(new (std::nothrow) ImageBuffer); + SysTryCatch(NID_MEDIA, pImgBuffer.get() != null, , E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Could not create new instance.") + + r = pImgBuffer->Construct(rotatedWidth, rotatedHeight, __pixelFormat, pDataRotate.get(), length); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, + "[%s] Failed to construct the rotated ImageBuffer.", GetErrorMessage(r)); + } + else + { + pImgBuffer.reset(CloneN()); + } + + SetLastResult(r); + return pImgBuffer.release(); + +CATCH: + + const_cast<_ImageBufferImpl *>(this)->Unlock(); + + SetLastResult(r); + return null; +} + +ImageBuffer* +_ImageBufferImpl::CropN(int x, int y, int width, int height) const +{ + std::unique_ptr pImgBuffer; + _ImageBufferImpl* pImgBufferImpl = null; + result r = E_SUCCESS; + byte* pData = null; + std::unique_ptr pDataCropped; + int length = 0; + int dstLength = 0; + MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE; + + SysTryReturn(NID_MEDIA, (x >= 0) && (y >= 0) && (x <= __width) && (y <= __height), + pImgBuffer.get(), E_INVALID_ARG, + "[E_INVALID_ARG] Origin should lie within image: (%d, %d) is outside (0, 0) - (%d, %d).", + x, y, __width, __height); + + SysTryReturn(NID_MEDIA, (width > 0) && (height > 0), + pImgBuffer.get(), E_INVALID_ARG, + "[E_INVALID_ARG] Dimensions of cropped region should greater than zero: (%d, %d).", + width, height); + + SysTryReturn(NID_MEDIA, (x + width <= __width) && (y + height <= __height), + pImgBuffer.get(), E_INVALID_ARG, + "[E_INVALID_ARG] End of cropped region should lie within image: (%d, %d) is outside (0, 0) - (%d, %d).", + x + width, y + height, __width, __height); + + SysTryReturn(NID_MEDIA, _ImageUtil::IsValidDimension(__pixelFormat, width, height) == true, + pImgBuffer.get(), E_INVALID_ARG, + "[E_INVALID_ARG] Current pixel format does not support odd dimensions (%d, %d).", + width, height); + + if ((x != 0) || (y != 0) || (width != __width) || (height != __height)) + { + r = const_cast<_ImageBufferImpl *>(this)->Lock(pData, length, pixFmt); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, pImgBuffer.get(), r, + "[%s] Lock failed. Propagated.", GetErrorMessage(r)); + + dstLength = _ImageUtil::GetBufferSize(__pixelFormat, width, height); + SysTryCatch(NID_MEDIA, dstLength > 0, , GetLastResult(), + "[%s] Could not get output buffer size.", GetErrorMessage(GetLastResult())); + + pDataCropped.reset(new (std::nothrow) byte[dstLength]); + SysTryCatch(NID_MEDIA, pDataCropped.get() != null, , E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Could not allocate %d bytes for cropped output.", dstLength); + + r = _ImageUtil::CropBuffer(pData, __pixelFormat, __width, __height, + pDataCropped.get(), x, y, width, height); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, + "[%s] Could not Crop the data.", GetErrorMessage(r)); + + const_cast<_ImageBufferImpl *>(this)->Unlock(); + + pImgBuffer.reset(new (std::nothrow) ImageBuffer); + SysTryCatch(NID_MEDIA, pImgBuffer.get() != null, , E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Could not create new instance.") + + r = pImgBuffer->Construct(width, height, __pixelFormat, pDataCropped.get(), dstLength); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, + "[%s] Failed to construct the croped ImageBuffer.", GetErrorMessage(r)); + } + else + { + pImgBuffer.reset(CloneN()); + } + + SetLastResult(r); + return pImgBuffer.release(); + +CATCH: + + const_cast<_ImageBufferImpl *>(this)->Unlock(); + + SetLastResult(r); + return null; +} + +result +_ImageBufferImpl::GetImageInfo(const String& srcImagePath, ImageFormat& imageFormat, + int &width, int &height) +{ + result r = E_SUCCESS; + + std::unique_ptr pSrcBuf(_MediaUtil::FileToBufferN(srcImagePath, 0)); + SysTryReturn(NID_MEDIA, pSrcBuf.get() != null, GetLastResult(), GetLastResult(), + "[%s] Propagated.", GetErrorMessage(GetLastResult())); + + r = GetImageInfo(*pSrcBuf.get(), imageFormat, width, height); + + return r; +} + +result +_ImageBufferImpl::GetImageInfo(const ByteBuffer& srcImageBuf, ImageFormat& imageFormat, + int &width, int &height) +{ + result r = E_SUCCESS; + _ImageDecoder dec; + + r = dec.Construct(srcImageBuf, MEDIA_PIXEL_FORMAT_RGB565LE); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] dec.Construct", GetErrorMessage(r)); + imageFormat = dec.GetImageFormat(); + r = dec.GetDimension(width, height); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] dec.GetDimension", GetErrorMessage(r)); + + return r; +} + +bool +_ImageBufferImpl::IsSupportedPixelFormat(MediaPixelFormat pixelFormat) +{ + for (int i = 0; i < sizeof(_IMAGE_BUFFER_PIXEL_FORMATS)/sizeof(_IMAGE_BUFFER_PIXEL_FORMATS[0]) ; i++) + { + if(pixelFormat == _IMAGE_BUFFER_PIXEL_FORMATS[i]) + { + return true; + } + } + return false; +} + +IListT* +_ImageBufferImpl::GetSupportedPixelFormatListN() +{ + result r = E_SUCCESS; + std::unique_ptr > pList(new (std::nothrow) ArrayListT()); + SysTryReturn(NID_MEDIA, pList.get() != null, null, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Could not allocate memory for output."); + + // TODO update list later for supported color formats in color converter?. + for (int i=0; iAdd(_IMAGE_BUFFER_PIXEL_FORMATS[i]); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, + "[%s] Adding elements to list failed. List is not complete.", GetErrorMessage(r)); + } + + SetLastResult(r); + return pList.release(); +} + +_ImageBufferImpl* +_ImageBufferImpl::GetInstance(ImageBuffer& a) +{ + return a.__pImpl; +} + +const _ImageBufferImpl* +_ImageBufferImpl::GetInstance(const ImageBuffer& a) +{ + return a.__pImpl; +} + +}} // Tizen::Media + diff --git a/src/FMedia_ImageDownloadListener.cpp b/src/FMedia_ImageDownloadListener.cpp new file mode 100644 index 0000000..aeaf9af --- /dev/null +++ b/src/FMedia_ImageDownloadListener.cpp @@ -0,0 +1,378 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMedia_ImageDownloadListener.cpp + * @brief This file contains the implementation of Image download listener class, + * required internally by Image::DecodeUrl. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "FMedia_ImageUriData.h" +#include "FMedia_ImageUriDataEvent.h" +#include "FMedia_ImageUriDataEventArg.h" +#include "FMedia_ImageDownloadListener.h" + +using namespace Tizen::Base; +using namespace Tizen::Io; +using namespace Tizen::Graphics; +using namespace Tizen::Net::Http; + +namespace Tizen{ namespace Media{ + +_ImageDownloadListener::_ImageDownloadListener() + : __requestID(0), + __pImageUriEvent(null), + __pImageUriData(null), + __pDownloadedData(null), + __colorFormat(BITMAP_PIXEL_FORMAT_RGB565), + __destWidth(0), + __destHeight(0) +{ +} + +_ImageDownloadListener::~_ImageDownloadListener() +{ + + __pImageUriEvent = null; + + __pImageUriData = null; + + __requestID = 0; + +} + +void +_ImageDownloadListener::OnTransactionReadyToRead(Tizen::Net::Http::HttpSession& httpSession, + Tizen::Net::Http::HttpTransaction& httpTransaction, int availableBodyLen) +{ + result r = E_SUCCESS; + std::unique_ptr pBody; + HttpResponse* pHttpResponse = null; + _ImageUriDataDestroyArg* pUriDestroyArg = null; + _ImageUriDataErrorArg* pImageUriErrorArg = null; + + pHttpResponse = httpTransaction.GetResponse(); + r = GetLastResult(); + SysTryCatch(NID_MEDIA, pHttpResponse != null, , r, "[%s] Get response is failed.", GetErrorMessage(r)); + + if (pHttpResponse->GetHttpStatusCode() != HTTP_STATUS_OK) + { + SysLogException(NID_MEDIA, E_INVALID_STATE, "[E_INVALID_STATE] OnTransactionReadyToRead failed."); + goto CATCH; + } + + pBody.reset(pHttpResponse->ReadBodyN()); + SysTryCatch(NID_MEDIA, pBody.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] OnTransactionReadyToRead failed."); + + if (__pDownloadedData == null) + { + __pDownloadedData = new (std::nothrow) ByteBuffer; + SysTryCatch(NID_MEDIA, __pDownloadedData != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] OnTransactionReadyToRead failed."); + r = __pDownloadedData->Construct(pBody->GetLimit()); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, + "ByteBuffer construct failed."); + + r = __pDownloadedData->CopyFrom(*pBody.get()); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, + "ByteBuffer::CopyFrom failed."); + } + else + { + r = __pDownloadedData->ExpandCapacity(__pDownloadedData->GetLimit() + pBody->GetLimit()); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, + "ByteBuffer::ExpandCapacity failed."); + + r = __pDownloadedData->CopyFrom(*pBody.get()); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, + "ByteBuffer::CopyFrom failed."); + } + return; + +CATCH: + + // Send error event. + pImageUriErrorArg = new (std::nothrow) _ImageUriDataErrorArg; + if (pImageUriErrorArg == null) + { + SysLogException(NID_MEDIA, E_OUT_OF_MEMORY, "Could not create pImageUriErrorArg! Exiting."); + return; + } + pImageUriErrorArg->SetEventType(IMAGE_URI_DATA_EVENT_ERROR); + pImageUriErrorArg->SetError(r); + pImageUriErrorArg->SetErrorCode(GetErrorMessage(r)); + pImageUriErrorArg->SetErrorMessage(GetErrorMessage(r)); + pImageUriErrorArg->SetRequestId(__requestID); + r = __pImageUriEvent->FireAsync(*pImageUriErrorArg); + if (r != E_SUCCESS) + { + SysLogException(NID_MEDIA, r, "Failed to Fire ImageUriEvent!"); + SysLogException(NID_MEDIA, r, "[%s] Propagated.", GetErrorMessage(r)); + } + + // Send destroy event to destroy ImageUriData's resources. - start + if (pUriDestroyArg == null) + { + pUriDestroyArg = new (std::nothrow) _ImageUriDataDestroyArg; + if ( pUriDestroyArg == null ) + { + return; + } + } + + pUriDestroyArg->SetEventType(IMAGE_URI_DATA_EVENT_DESTROY); + pUriDestroyArg->SetRequestId(__requestID); + r = __pImageUriEvent->FireAsync(*pUriDestroyArg); + // Send destroy event to destroy ImageUriData's resources. - end + + return; +} + +void +_ImageDownloadListener::OnTransactionAborted(Tizen::Net::Http::HttpSession& httpSession, + Tizen::Net::Http::HttpTransaction& httpTransaction, result res) +{ + _ImageUriDataDestroyArg* pUriDestroyArg = null; + _ImageUriDataErrorArg* pImageUriErrorArg = null; + result r = E_SUCCESS; + + // Send error event. + pImageUriErrorArg = new (std::nothrow) _ImageUriDataErrorArg; + if (pImageUriErrorArg == null) + { + SysLogException(NID_MEDIA, E_OUT_OF_MEMORY, "Could not create pImageUriErrorArg! Exiting."); + return; + } + pImageUriErrorArg->SetEventType(IMAGE_URI_DATA_EVENT_ERROR); + pImageUriErrorArg->SetError(res); + pImageUriErrorArg->SetErrorCode(GetErrorMessage(res)); + pImageUriErrorArg->SetErrorMessage(GetErrorMessage(res)); + pImageUriErrorArg->SetRequestId(__requestID); + r = __pImageUriEvent->FireAsync(*pImageUriErrorArg); + if (r != E_SUCCESS) + { + SysLogException(NID_MEDIA, r, "Failed to Fire ImageUriEvent!"); + SysLogException(NID_MEDIA, r, "[%s] Propagated.", GetErrorMessage(r)); + } + + // Send destroy event to destroy ImageUriData's resources. - start + pUriDestroyArg = new (std::nothrow) _ImageUriDataDestroyArg; + if (pUriDestroyArg == null) + { + return; + } + + pUriDestroyArg->SetEventType(IMAGE_URI_DATA_EVENT_DESTROY); + pUriDestroyArg->SetRequestId(__requestID); + r = __pImageUriEvent->FireAsync(*pUriDestroyArg); + // Send destroy event to destroy ImageUriData's resources. - end + + return; +} + +void +_ImageDownloadListener::OnTransactionCompleted(Tizen::Net::Http::HttpSession& httpSession, + Tizen::Net::Http::HttpTransaction& httpTransaction) +{ + result r = E_SUCCESS; + std::unique_ptr<_ImageUriDataEventArg> pUriEventArg; + _ImageUriDataDestroyArg* pUriDestroyArg = null; + _ImageUriDataErrorArg* pImageUriErrorArg = null; + + // Send event. + pUriEventArg.reset(new (std::nothrow) _ImageUriDataEventArg); + SysTryCatch(NID_MEDIA, pUriEventArg.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] new _ImageUriDataEventArg"); + + pUriEventArg->SetEventType(IMAGE_URI_DATA_EVENT_SUCCESS); + pUriEventArg->SetImageFormat(IMG_FORMAT_NONE); + pUriEventArg->SetData(__pDownloadedData); + pUriEventArg->SetRequestId(__requestID); + pUriEventArg->SetResult(E_SUCCESS); + pUriEventArg->SetColorFormat(__colorFormat); + pUriEventArg->SetDestDimension(Dimension(__destWidth, __destHeight)); + + r = __pImageUriEvent->FireAsync(*pUriEventArg.release()); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Failed to Fire _ImageUriDataEventArg", GetErrorMessage(r)); + + pUriDestroyArg = new (std::nothrow) _ImageUriDataDestroyArg; + SysTryCatch(NID_MEDIA, pUriDestroyArg != null, r = E_OUT_OF_MEMORY, + E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] while creating destroy arg." ); + + pUriDestroyArg->SetEventType(IMAGE_URI_DATA_EVENT_DESTROY); + + pUriDestroyArg->SetRequestId(__requestID); + + r = __pImageUriEvent->FireAsync(*pUriDestroyArg); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagated.", + GetErrorMessage(r)); + + // Send destroy event to destroy ImageUriData's resources. - end + return; +CATCH: + + // Send error event. + pImageUriErrorArg = new (std::nothrow) _ImageUriDataErrorArg; + if (pImageUriErrorArg == null) + { + SysLogException(NID_MEDIA, E_OUT_OF_MEMORY, "Could not create pImageUriErrorArg! Exiting."); + return; + } + pImageUriErrorArg->SetEventType(IMAGE_URI_DATA_EVENT_ERROR); + pImageUriErrorArg->SetError(r); + pImageUriErrorArg->SetErrorCode(GetErrorMessage(r)); + pImageUriErrorArg->SetErrorMessage(GetErrorMessage(r)); + pImageUriErrorArg->SetRequestId(__requestID); + r = __pImageUriEvent->FireAsync(*pImageUriErrorArg); + if (r != E_SUCCESS) + { + SysLogException(NID_MEDIA, r, "Failed to Fire ImageUriEvent!"); + SysLogException(NID_MEDIA, r, "[%s] Propagated.", GetErrorMessage(r)); + } + + // Send destroy event to destroy ImageUriData's resources. - start + if (pUriDestroyArg == null) + { + pUriDestroyArg = new (std::nothrow) _ImageUriDataDestroyArg; + if ( pUriDestroyArg == null ) + { + return; + } + } + + pUriDestroyArg->SetEventType(IMAGE_URI_DATA_EVENT_DESTROY); + pUriDestroyArg->SetRequestId(__requestID); + r = __pImageUriEvent->FireAsync(*pUriDestroyArg); + // Send destroy event to destroy ImageUriData's resources. - end + return; +} + +void +_ImageDownloadListener::OnTransactionCertVerificationRequiredN(Tizen::Net::Http::HttpSession& httpSession, + Tizen::Net::Http::HttpTransaction& httpTransaction, String* pCert) +{ + // Not used. +} + +void +_ImageDownloadListener::OnTransactionHeaderCompleted(Tizen::Net::Http::HttpSession& httpSession, + Tizen::Net::Http::HttpTransaction& httpTransaction, int headerLen, bool bAuthRequired) +{ + // Not used. +} + +void +_ImageDownloadListener::OnTransactionReadyToWrite(Tizen::Net::Http::HttpSession& httpSession, + Tizen::Net::Http::HttpTransaction& httpTransaction, int recommendedChunkSize) +{ + // Not used. +} + +void +_ImageDownloadListener::OnDownloadCanceled(result res) +{ + std::unique_ptr<_ImageUriDataEventArg> pUriEventArg; + _ImageUriDataDestroyArg* pUriDestroyArg = null; + result r = E_SUCCESS; + + // Send event. + pUriEventArg.reset(new (std::nothrow) _ImageUriDataEventArg); + if (pUriEventArg.get() == null) + { + SysLogException(NID_MEDIA, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Failed to allocate memory _ImageUriDataEventArg"); + return; + } + + pUriEventArg->SetEventType(IMAGE_URI_DATA_EVENT_CANCEL); + pUriEventArg->SetImageFormat(IMG_FORMAT_NONE); + pUriEventArg->SetData(null); + pUriEventArg->SetRequestId(__requestID); + pUriEventArg->SetResult(res); + + r = __pImageUriEvent->FireAsync(*pUriEventArg.release()); + if (r != E_SUCCESS) + { + SysLogException(NID_MEDIA, r, "[%s] Failed to Fire _ImageUriDataEventArg", GetErrorMessage(r)); + } + + pUriDestroyArg = new (std::nothrow) _ImageUriDataDestroyArg; + if (pUriDestroyArg == null) + { + SysLogException(NID_MEDIA, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] while creating destroy arg." ); + return; + } + + pUriDestroyArg->SetEventType(IMAGE_URI_DATA_EVENT_DESTROY); + + pUriDestroyArg->SetRequestId(__requestID); + + r = __pImageUriEvent->FireAsync(*pUriDestroyArg); + if (r != E_SUCCESS) + { + SysLogException(NID_MEDIA, r, "[%s] Propagated.", + GetErrorMessage(r)); + return; + } + + // Send destroy event to destroy ImageUriData's resources. - end + +} + +void +_ImageDownloadListener::SetImageUrlEvent(_ImageUriDataEvent* pImageUriEvent) +{ + __pImageUriEvent = pImageUriEvent; +} + +void +_ImageDownloadListener::SetImageUrlData(_ImageUriData* pImageUriData) +{ + __pImageUriData = pImageUriData; +} + +void +_ImageDownloadListener::SetImagePixelFormat(BitmapPixelFormat colorFormat ) +{ + __colorFormat = colorFormat; +} + +void +_ImageDownloadListener::SetImageDestDimension(int destWidth, int destHeight ) +{ + __destWidth = destWidth; + __destHeight = destHeight; +} + +void +_ImageDownloadListener::SetRequestId(RequestId reqId) +{ + __requestID = reqId; +} + + +}} // Tizen::Media diff --git a/src/FMedia_ImageDownloadListener.h b/src/FMedia_ImageDownloadListener.h new file mode 100644 index 0000000..27f6eb9 --- /dev/null +++ b/src/FMedia_ImageDownloadListener.h @@ -0,0 +1,94 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMedia_ImageDownloadListener.h + * @brief This file contains the declaration of Image download listener class, + * required internally by Image::DecodeUrl. + */ + +#ifndef FMEDIA_INTERNAL_IMAGEDOWNLOADLISTENER_H_ +#define FMEDIA_INTERNAL_IMAGEDOWNLOADLISTENER_H_ + +#define _EXCEPT_DEPENDENCY_ +#include + +namespace Tizen{ namespace Media{ + +class _ImageUriDataEvent; +class _ImageUriData; + +class _ImageDownloadListener + : virtual public Tizen::Net::Http::IHttpTransactionEventListener + , virtual public Tizen::Base::Object + , virtual public Tizen::Base::Runtime::IEventListener +{ + +public: + _ImageDownloadListener(void); + virtual ~_ImageDownloadListener(void); + +public: + virtual void OnTransactionReadyToRead(Tizen::Net::Http::HttpSession& httpSession, + Tizen::Net::Http::HttpTransaction& httpTransaction, int availableBodyLen); + + virtual void OnTransactionAborted(Tizen::Net::Http::HttpSession& httpSession, + Tizen::Net::Http::HttpTransaction& httpTransaction, result r); + + virtual void OnTransactionCompleted(Tizen::Net::Http::HttpSession& httpSession, + Tizen::Net::Http::HttpTransaction& httpTransaction); + + virtual void OnTransactionCertVerificationRequiredN(Tizen::Net::Http::HttpSession& httpSession, + Tizen::Net::Http::HttpTransaction& httpTransaction, Tizen::Base::String* pCert); + + virtual void OnTransactionHeaderCompleted(Tizen::Net::Http::HttpSession& httpSession, + Tizen::Net::Http::HttpTransaction& httpTransaction, int headerLen, bool bAuthRequired); + + virtual void OnTransactionReadyToWrite(Tizen::Net::Http::HttpSession& httpSession, + Tizen::Net::Http::HttpTransaction& httpTransaction, int recommendedChunkSize); + + void OnDownloadCanceled(result res); + + void setDownloadPath(Tizen::Base::String NewDownloadPath); + void SetImageUrlEvent(_ImageUriDataEvent* pImageUriEvent); + void SetImageUrlData(_ImageUriData* pImageUriData); + void SetImagePixelFormat(Tizen::Graphics::BitmapPixelFormat colorFormat); + void SetImageDestDimension(int destWidth, int destHeight); + void SetRequestId(RequestId reqId); + +private: + /** + * This is the copy constructor for this class. + */ + _ImageDownloadListener(const _ImageDownloadListener& rhs); + /** + * This is the assignment operator. + */ + _ImageDownloadListener& operator =(const _ImageDownloadListener& rhs); + + RequestId __requestID; + _ImageUriDataEvent* __pImageUriEvent; + _ImageUriData* __pImageUriData; + Tizen::Base::ByteBuffer* __pDownloadedData; + Tizen::Graphics::BitmapPixelFormat __colorFormat; + int __destWidth; + int __destHeight; +}; + +}} // Tizen::Media + +#endif // FMEDIA_INTERNAL_IMAGEDOWNLOADLISTENER_H_ diff --git a/src/FMedia_ImageImpl.cpp b/src/FMedia_ImageImpl.cpp new file mode 100644 index 0000000..4d62299 --- /dev/null +++ b/src/FMedia_ImageImpl.cpp @@ -0,0 +1,523 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMedia_ImageImpl.cpp + * @brief This file contains the implementation of subsystem's Image. + */ + +#include +#include +#include +#include +#include +#include +#include "FMedia_MediaUtil.h" +#include "FMedia_ImageImpl.h" +#include "FMedia_ImageUtilImpl.h" +#include "FMedia_ImageDecoder.h" +#include "FMedia_ImageEncoder.h" +#include "FMedia_ImageUriDataFactory.h" + +using namespace Tizen::Graphics; +using namespace Tizen::Base; +using namespace Tizen::Io; + +namespace Tizen { namespace Media +{ + +static const float _SCALE_DOWN_RATIO = 0.5; +static const int _RGB565_PIXEL_DEPTH = 2; +static const int _MIN_ENCODE_QUALITY = 20; // Changed from 50 to 20 to allow greater compression. +static const int _MAX_ENCODE_QUALITY = 99; +static const int _DEFAULT_ENCODE_QUALITY = 50; +static const int _MAX_ENCODE_LOOP = 2; +static const int _MAX_ENCODE_RESIZE_LOOP = 2; +//static const int MAX_IMGFILE_SIZE = 4096000; + +_ImageImpl::_ImageImpl(void) +{ +} + +_ImageImpl::~_ImageImpl(void) +{ +} + +_ImageImpl* +_ImageImpl::GetInstance(Image* pImage) +{ + if (pImage != null) + { + return pImage->__pImageImpl; + } + + return null; +} + +const _ImageImpl* +_ImageImpl::GetInstance(const Image* pImage) +{ + if (pImage != null) + { + return pImage->__pImageImpl; + } + + return null; +} + +result +_ImageImpl::Construct(void) +{ + return E_SUCCESS; +} + +Bitmap* +_ImageImpl::DecodeToBitmapN(const String& srcImgPath, BitmapPixelFormat pixelFormat, + const Tizen::Graphics::Dimension &dstDim, + Tizen::Graphics::BufferScaling bufferScaling, + ImageFormat imgFormat, bool keepAspectRatio) +{ + std::unique_ptr pBuf; + Bitmap* pBmp = null; + + pBuf.reset(_MediaUtil::FileToBufferN(srcImgPath)); + SysTryReturn(NID_MEDIA, pBuf.get() != null, null, GetLastResult(), + "[%s] FileToBufferN %S", GetErrorMessage(GetLastResult()), srcImgPath.GetPointer()); + + pBmp = DecodeToBitmapN(*pBuf.get(), pixelFormat, dstDim, bufferScaling, imgFormat, keepAspectRatio); + 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) +{ + 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); + + pBuf.reset(DecodeToBufferN(srcImageBuf, outDim, dstDim, pixelFormat, imgFormat, keepAspectRatio)); + SysTryReturn(NID_MEDIA, pBuf.get() != null, null, GetLastResult(), + "[%s] Propagated", GetErrorMessage(GetLastResult())); + + 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, bufferScaling); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated. ", GetErrorMessage(r)); + + SetLastResult(E_SUCCESS); + return pBmp.release(); +} + +Tizen::Base::ByteBuffer* +_ImageImpl::DecodeToBufferN(const Tizen::Base::String& srcImagePath, + Tizen::Graphics::Dimension &restDim, + const Tizen::Graphics::Dimension &dstDim, + Tizen::Graphics::BitmapPixelFormat pixelFormat, + ImageFormat imgFormat, bool keepAspectRatio) +{ + std::unique_ptr pBuf; + ByteBuffer* pRetBuf = null; + + //SysTryCatch(NID_MEDIA, IS_VALID_DIMENSION(dstDim), , E_OUT_OF_RANGE, + //"[E_OUT_OF_RANGE] dest dimension:%d,%d", dstDim.width, dstDim.height); + + pBuf.reset(_MediaUtil::FileToBufferN(srcImagePath)); + SysTryReturn(NID_MEDIA, pBuf.get() != null, null, GetLastResult(), + "[%s] FileToBufferN %S", GetErrorMessage(GetLastResult()), srcImagePath.GetPointer()); + + pRetBuf = DecodeToBufferN(*pBuf.get(), restDim, dstDim, pixelFormat, imgFormat, keepAspectRatio); + return pRetBuf; +} + +Tizen::Base::ByteBuffer* +_ImageImpl::DecodeToBufferN(const Tizen::Base::ByteBuffer &srcImageBuf, + Tizen::Graphics::Dimension &retDim, + const Tizen::Graphics::Dimension &dstDim, + Tizen::Graphics::BitmapPixelFormat pixelFormat, + ImageFormat imgFormat, bool keepAspectRatio) +{ + result r = E_SUCCESS; + std::unique_ptr pBuf; + _ImageDecoder dec; + + //SysTryCatch(NID_MEDIA, IS_VALID_BITMAP_PIXEL(pixelFormat), , E_INVALID_ARG, + //"[E_INVALID_ARG] pixelFormat:%d", pixelFormat); + + r = dec.Construct(srcImageBuf, _ImageUtilImpl::ToMediaPixelFormat(pixelFormat), imgFormat); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Decoder construct failed.", GetErrorMessage(r)); + + // Reset decoder output demension + dec.SetOutputDimension(dstDim.width, dstDim.height, keepAspectRatio); + + pBuf.reset(dec.DecodeN()); + r = GetLastResult(); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated. ", GetErrorMessage(r)); + + r = dec.GetDimension(retDim.width, retDim.height); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated. ", GetErrorMessage(r)); + + SetLastResult(E_SUCCESS); + return pBuf.release(); +} + +Tizen::Base::ByteBuffer* +_ImageImpl::DecodeToBufferN(const Tizen::Base::String& srcImagePath, + Tizen::Graphics::BitmapPixelFormat pixelFormat, + int& imageWidth, int& imageHeight, bool keepAspectRatio) +{ + ByteBuffer *pBuf = null; + Dimension dim; + + pBuf = DecodeToBufferN(srcImagePath, dim, Dimension(0, 0), pixelFormat, IMG_FORMAT_NONE, keepAspectRatio); + imageWidth = dim.width; + imageHeight = dim.height; + return pBuf; +} + + +Tizen::Base::ByteBuffer* +_ImageImpl::DecodeN(const Tizen::Base::String& srcImagePath, + Tizen::Graphics::BitmapPixelFormat pixelFormat, + int destWidth, int destHeight, bool keepAspectRatio) +{ + Dimension dim; + + return DecodeToBufferN(srcImagePath, dim, Dimension(destWidth, destHeight), pixelFormat, IMG_FORMAT_NONE, keepAspectRatio); +} + +result +_ImageImpl::DecodeUrl(const Tizen::Base::Utility::Uri& srcImageUrl, + Tizen::Graphics::BitmapPixelFormat colorFormat, + int destWidth, int destHeight, RequestId& reqId, + const IImageDecodeUrlEventListener& listener, long timeout) +{ + result r = E_SUCCESS; + + _ImageUriDataFactory *pFactory = null; + + SysTryCatch(NID_MEDIA, (colorFormat > Tizen::Graphics::BITMAP_PIXEL_FORMAT_MIN) + && colorFormat < Tizen::Graphics::BITMAP_PIXEL_FORMAT_MAX, , E_INVALID_ARG, + "[E_INVALID_ARG] Wrong color format."); + + SysTryCatch(NID_MEDIA, destWidth > 0 && destHeight > 0, , E_OUT_OF_RANGE, + "[E_OUT_OF_RANGE] The designated width and height SHOUL be greater than 0."); + + SysTryCatch(NID_MEDIA, timeout == _TIMEOUT_INFINITE || timeout > 0 , + r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, + "[E_OUT_OF_RANGE] The designated timeout SHOUL be greater than 0"); + + pFactory = _ImageUriDataFactory::GetInstance(); + SysTryCatch(NID_MEDIA, pFactory != null, r = GetLastResult(), r, + "[%s] Failed to GetInstance().", GetErrorMessage(r)); + + r = pFactory->DecodeUrl(srcImageUrl, colorFormat, destWidth,destHeight, reqId, listener, timeout); + SysTryCatch(NID_MEDIA, r == E_SUCCESS , , r,"[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + return r; +} + +ByteBuffer* +_ImageImpl::EncodeToBufferN(const Bitmap& srcBmp, ImageFormat dstFormat) +{ + std::unique_ptr pBuf; + BufferInfo bmpInfo; + Dimension dim; + + // ClearLastResult(); + + Tizen::Graphics::Bitmap& tmpBmp = const_cast(srcBmp); + + // Create src buf + tmpBmp.Lock(bmpInfo); + + dim.SetSize(bmpInfo.width, bmpInfo.height); + + // TODO: handle case that pitch != width * bpp/8 + SysTryReturn(NID_MEDIA, bmpInfo.pitch == bmpInfo.width*bmpInfo.bitsPerPixel/8, null, E_SYSTEM, + "[E_SYSTEM] pitch=%d bpp=%d", bmpInfo.pitch, bmpInfo.bitsPerPixel); + + pBuf.reset(_ImageEncoder::EncodeN(dstFormat, (const byte*)bmpInfo.pPixels, bmpInfo.pitch * bmpInfo.height, + dim.width, dim.height, + _ImageUtilImpl::ToMediaPixelFormat(srcBmp.GetPixelColorFormat()), + _DEFAULT_ENCODE_QUALITY)); + SysTryReturn(NID_MEDIA, pBuf.get() != null, null, GetLastResult(), "[%s] Propagated. ", GetErrorMessage(GetLastResult())); + + return pBuf.release(); +} + +result +_ImageImpl::EncodeToFile(const Bitmap& srcBmp, ImageFormat dstFormat, + const String& dstPath, bool overwrite) +{ + result r = E_SUCCESS; + std::unique_ptr pBuf; + + pBuf.reset(EncodeToBufferN(srcBmp, dstFormat)); + SysTryReturn(NID_MEDIA, pBuf.get() != null, GetLastResult(), GetLastResult(), + "[%s] Propagated.", GetErrorMessage(GetLastResult())); + + r = _MediaUtil::BufferToFile(*pBuf.get(), dstPath, overwrite); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagated. ", GetErrorMessage(r)); + + SetLastResult(r); + return r; +} + +Tizen::Base::ByteBuffer* +_ImageImpl::CompressJpegN(const Tizen::Base::ByteBuffer& srcImageBuf, int limitSize) +{ + result r = E_SUCCESS; + std::unique_ptr pDecBuf; + std::unique_ptr pEncBuf; + Dimension srcDim; + _ImageDecoder dec; + volatile int limit = limitSize; + MediaPixelFormat pixelFormat = MEDIA_PIXEL_FORMAT_BGRA8888; + + // TODO : use yuv pixel format + + r = dec.Construct(srcImageBuf, pixelFormat); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Decoder construct failed.", GetErrorMessage(r)); + + pDecBuf.reset(dec.DecodeN()); + r = GetLastResult(); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated. ", GetErrorMessage(r)); + SysTryReturn(NID_MEDIA, pDecBuf.get() != null, null, E_SYSTEM, "[E_SYSTEM] Propagated."); + + r = dec.GetDimension(srcDim.width, srcDim.height); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated. ", GetErrorMessage(r)); + + for (int i = 0; i < _MAX_ENCODE_RESIZE_LOOP; i++) + { + Dimension dstDim; + ByteBuffer *pTmpBuf = null; + + pEncBuf.reset(EncodeToBufferLimitN(*pDecBuf.get(), srcDim, pixelFormat, IMG_FORMAT_JPG, limit)); + + if (pEncBuf.get() != null) + { + break; + } + + // halve and make even number + dstDim.width = srcDim.width >> 2; + dstDim.height = srcDim.height >> 2; + + dstDim.width = dstDim.width << 1; + dstDim.height = dstDim.height << 1; + + SysTryReturn(NID_MEDIA, srcDim != dstDim && dstDim.width > 0 && dstDim.height > 0, null, E_SYSTEM, + "[E_SYSTEM] Resize failed:src:%dx%d dst:%dx%d, %d %d, %d", + srcDim.width, srcDim.height, dstDim.width, dstDim.height, i, _SCALE_DOWN_RATIO, + limit); + + pTmpBuf = _ImageUtilImpl::ResizeN(*pDecBuf.get(), srcDim, pixelFormat, dstDim); + SysTryReturn(NID_MEDIA, pTmpBuf != null, null, GetLastResult(), + "[%s] ResizeN: %dx%d->%dx%d", GetErrorMessage(GetLastResult()), + srcDim.width, srcDim.height, dstDim.width, dstDim.height); + + srcDim = dstDim; + pDecBuf.reset(pTmpBuf); + } + SysTryReturn(NID_MEDIA, pEncBuf.get() != null, null, E_SYSTEM, "[E_SYSTEM] Compress failed"); + SetLastResult(E_SUCCESS); + return pEncBuf.release(); +} + +result +_ImageImpl::CompressJpeg(const Tizen::Base::String& srcImagePath, + const Tizen::Base::String& dstImagePath, int limitSize) +{ + File file; + result r = E_SUCCESS; + std::unique_ptr pSrcBuf; + std::unique_ptr pEncBuf; + + pSrcBuf.reset(_MediaUtil::FileToBufferN(srcImagePath)); + SysTryReturn(NID_MEDIA, pSrcBuf.get() != null, GetLastResult(), GetLastResult(), + "[%s] Propagated. ", GetErrorMessage(GetLastResult())); + +// SysTryCatch(NID_MEDIA, pSrcBuf->GetCapacity() < MAX_IMGFILE_SIZE, r = E_OVERFLOW, E_OVERFLOW, +// "[E_OUT_OF_RANGE] Input file size is smaller than limitSize."); + + SysTryReturn(NID_MEDIA, pSrcBuf.get()->GetCapacity() > limitSize, E_OUT_OF_RANGE, E_OUT_OF_RANGE, + "[E_OUT_OF_RANGE] Input file size is smaller than limitSize."); + + pEncBuf.reset(CompressJpegN(*pSrcBuf, limitSize)); + SysTryReturn(NID_MEDIA, pEncBuf != null, GetLastResult(), GetLastResult(), + "[%s] Propagated. ", GetErrorMessage(GetLastResult())); + + if (File::IsFileExist(dstImagePath)) + { + File::Remove(dstImagePath); + } + + r = file.Construct(dstImagePath, "wb", true); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagated. ", GetErrorMessage(r)); + r = file.Write(*pEncBuf); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagated. ", GetErrorMessage(r)); + + return r; +} + +Tizen::Base::ByteBuffer* +_ImageImpl::ConvertToBufferN(const Tizen::Base::String& srcImagePath, ImageFormat destImageFormat) +{ + std::unique_ptr pBmp; + ByteBuffer* pBuf = null; + + pBmp.reset(DecodeToBitmapN(srcImagePath, BITMAP_PIXEL_FORMAT_ARGB8888, Dimension(0, 0), + BUFFER_SCALING_NONE)); + SysTryReturn(NID_MEDIA, pBmp.get(), null, GetLastResult(), + "[%s] Propagated. ", GetErrorMessage(GetLastResult())); + + pBuf = EncodeToBufferN(*pBmp.get(), destImageFormat); + SysTryReturn(NID_MEDIA, pBuf != null, null, GetLastResult(), + "[%s] Propagated.", GetErrorMessage(GetLastResult())); + + SetLastResult(E_SUCCESS); + return pBuf; +} + +Tizen::Base::ByteBuffer* +_ImageImpl::EncodeToBufferLimitN(const Tizen::Base::ByteBuffer &srcBuf, + const Tizen::Graphics::Dimension& dim, + MediaPixelFormat pixelFormat, ImageFormat imgFormat, int limit) +{ + int minQuality = _MIN_ENCODE_QUALITY; + int maxQuality = _MAX_ENCODE_QUALITY; + int curQuality = 0; + int minDiff = 0; + int maxDiff = 0; + + std::unique_ptr pMaxBuf; + std::unique_ptr pMinBuf; + + pMaxBuf.reset(EncodeToBufferQualityN(srcBuf, dim, pixelFormat, imgFormat, maxQuality)); + SysTryReturn(NID_MEDIA, pMaxBuf.get() != null, pMinBuf.get(), E_SYSTEM, "[E_SYSTEM] maxBuf is null"); + maxDiff = pMaxBuf->GetLimit() - limit; + SysLog(NID_MEDIA, "maxDiff:%d buf:%d limit:%d q:%d", + maxDiff, pMaxBuf->GetLimit(), limit, maxQuality); + if (maxDiff <= 0) + { + SetLastResult(E_SUCCESS); + return pMaxBuf.release(); + } + pMinBuf.reset(EncodeToBufferQualityN(srcBuf, dim, pixelFormat, imgFormat, minQuality)); + SysTryReturn(NID_MEDIA, pMinBuf.get() != null, pMinBuf.release(), E_SYSTEM, "[E_SYSTEM] minBuf is null"); + minDiff = pMinBuf->GetLimit() - limit; + SysLog(NID_MEDIA, "minDiff:%d buf:%d limit:%d q:%d", + minDiff, pMinBuf->GetLimit(), limit, minQuality); + if (minDiff > 0) + { + SetLastResult(E_OVERFLOW); + return null; + } + if (minDiff == 0) + { + SetLastResult(E_SUCCESS); + return pMinBuf.release(); + } + + for (int i = 0; i < _MAX_ENCODE_LOOP; i++) + { + int prevQuality = curQuality; + int curDiff = 0; + ByteBuffer *pCurBuf = null; + + curQuality = (minQuality + maxQuality) / 2; + if (prevQuality == curQuality) + { + break; + } + pCurBuf = EncodeToBufferQualityN(srcBuf, dim, pixelFormat, imgFormat, curQuality); + if (pCurBuf == null && pMinBuf.get() != null) + { + break; + } + SysTryReturn(NID_MEDIA, pCurBuf != null, pMinBuf.release(), E_SYSTEM, + "[E_SYSTEM] curBuf is null : %d %d %d", dim.width, dim.height, curQuality); + curDiff = pCurBuf->GetLimit() - limit; + SysLog(NID_MEDIA, "curDiff:%d buf:%d limit:%d q:%d", + curDiff, pCurBuf->GetLimit(), limit, curQuality); + if (curDiff == 0) + { + SetLastResult(E_SUCCESS); + return pCurBuf; + } + else if (curDiff > 0) + { + maxDiff = curDiff; + maxQuality = curQuality; + pMaxBuf.reset(pCurBuf); + } + else if (curDiff < 0) + { + pMinBuf.reset(pCurBuf); + minDiff = curDiff; + minQuality = curQuality; + } + } + if (pMinBuf.get()) + { + SetLastResult(E_SUCCESS); + } + else + { + // should not come here. + SetLastResult(E_SYSTEM); + } + return pMinBuf.release(); +} + +Tizen::Base::ByteBuffer* +_ImageImpl::EncodeToBufferQualityN(const Tizen::Base::ByteBuffer &srcBuf, + const Tizen::Graphics::Dimension& dim, + MediaPixelFormat pixelFormat, ImageFormat imgFormat, int quality) +{ + ByteBuffer* pBuf = null; + + pBuf = _ImageEncoder::EncodeN(imgFormat, srcBuf.GetPointer(), srcBuf.GetLimit(), + dim.width, dim.height, pixelFormat, quality); + SysTryReturn(NID_MEDIA, pBuf != null, pBuf, GetLastResult(), + "[%s] enc.EncodeN. ", GetErrorMessage(GetLastResult())); + + return pBuf; +} + +result +_ImageImpl::GetImageInfo(const Tizen::Base::String& path, ImageFormat &imgFormat, + Tizen::Graphics::Dimension &dim) +{ + return _ImageDecoder::GetImageInfo(path, imgFormat, dim.width, dim.height); +} + +}} // Tizen::Media diff --git a/src/FMedia_ImageUriData.cpp b/src/FMedia_ImageUriData.cpp new file mode 100644 index 0000000..ed3fbf5 --- /dev/null +++ b/src/FMedia_ImageUriData.cpp @@ -0,0 +1,321 @@ + +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMedia_ImageUriData.cpp + * @brief This file contains the implementation of _ImageUriData class, + * required internally by Image::DecodeUrl. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "FMedia_ImageDownloadListener.h" +#include "FMedia_ImageUriData.h" +#include "FMedia_ImageUriDataFactory.h" +#include "FMedia_ImageUriDataEvent.h" +#include "FMedia_ImageUriDataEventArg.h" + +using namespace Tizen::Graphics; +using namespace Tizen::Base; +using namespace Tizen::Base::Runtime; +using namespace Tizen::System; +using namespace Tizen::Io; +using namespace Tizen::Net::Http; + + +namespace Tizen{ namespace Media{ + +_ImageUriData::_ImageUriData(void): + __destWidth(0), + __destHeight(0), + __pSessionImpl(null), + __pTransactionImpl(null), + __pRequest(null), + __pRequestImpl(null), + __pDataEvent(null), + __colorFormat(BITMAP_PIXEL_FORMAT_RGB565), + __requestId(INVALID_REQUEST_ID), + __refCount(1), + __isTimerStarted(false) +{ +} + +_ImageUriData::~_ImageUriData(void) +{ + if (__isTimerStarted) + { + SysLog(NID_MEDIA, "Timeout Timer canceled, ReqeustId : %d", __requestId); + __requestTimeout.Cancel(); + } + + if (__pSession.get() != null) + { + __pSessionImpl = null; + } + + if (__pTransaction.get() != null) + { + __pTransactionImpl = null; + } + +} + +result +_ImageUriData::Construct(IEventListener& listener) +{ + result r = E_SUCCESS; + + __pDataEvent.reset(new (std::nothrow) _ImageUriDataEvent); + SysTryReturn(NID_MEDIA, __pDataEvent.get() != null, E_OUT_OF_MEMORY, + E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]."); + + r = __pDataEvent->Construct(); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagated.", GetErrorMessage(r)); + + r = __pDataEvent->AddListener (listener); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagated.", GetErrorMessage(r)); + + r = __requestTimeout.Construct(*this); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; +} + +result +_ImageUriData::RequestDecode(const Utility::Uri &uri, BitmapPixelFormat colorFormat, + const Dimension& destDim, RequestId& reqId, long msec) +{ + result r = E_SUCCESS; + + __srcUri = uri; + __destWidth = destDim.width; + __destHeight = destDim.height; + __colorFormat = colorFormat; + __requestId = reqId; + + if (__pListener.get() == null) + { + __pListener.reset(new (std::nothrow) _ImageDownloadListener); + SysTryReturnResult(NID_MEDIA, __pListener.get() != null, E_OUT_OF_MEMORY, + "Could not allocate _ImageDownloadListener."); + } + + __pListener->SetImageUrlData(this); + __pListener->SetRequestId(reqId); + __pListener->SetImageUrlEvent(__pDataEvent.get()); + __pListener->SetImagePixelFormat(__colorFormat); + __pListener->SetImageDestDimension(__destWidth, __destHeight); + + r = RequestDownload(uri, reqId, msec); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagated..", GetErrorMessage(r)); + + // Start timer + if (msec != _TIMEOUT_INFINITE) + { + r = __requestTimeout.Start(msec); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagated..", GetErrorMessage(r)); + SysLog(NID_MEDIA, "Timeout Timer started ReqeustId : %d, [%d msec]", __requestId, msec); + __isTimerStarted = true; + } + + return r; +} + +result +_ImageUriData::Cancel(RequestId reqId, result res) +{ + result r = E_SUCCESS; + + SysTryCatch(NID_MEDIA, __pSessionImpl != null, r = E_OBJ_NOT_FOUND, r, + "[E_OBJ_NOT_FOUND] Session is null."); + SysTryCatch(NID_MEDIA, __pTransaction.get() != null, r = E_OBJ_NOT_FOUND, r, + "[E_OBJ_NOT_FOUND] Transaction is null."); + + r = __pSessionImpl->CancelTransaction(*__pTransaction.get()); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Cancel failed.", + GetErrorMessage(r)); + + __pListener->OnDownloadCanceled(res); + __pTransactionImpl = null; + + __pSessionImpl = null; + + SetLastResult(r); + return r; + +CATCH: + + if (__pTransaction.get()) + { + __pTransactionImpl = null; + } + if (__pSession.get()) + { + __pSessionImpl = null; + } + + return r; +} + +RequestId +_ImageUriData::GetRequestId(void) const +{ + return __requestId; +} + +result +_ImageUriData::RequestDownload(const Utility::Uri &downloadUri, + RequestId& reqId, long msec) +{ + result r = E_SUCCESS; + int sec = (msec == 0) ? 0 : (msec + 999) / 1000; + + String srcPath; + String destPath; + String hostAddr(L""); + String proxyAddr(L""); + + hostAddr = downloadUri.GetHost(); + + // Create HTTP session + if (__pSession.get() == null) + { + __pSession.reset(new (std::nothrow) HttpSession); + } + SysTryCatch(NID_MEDIA, __pSession.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Failed to create the HTTP session."); + + r = __pSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, null, hostAddr, null); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, + "[E_SYSTEM] Failed to construct HTTP session."); + + __pSessionImpl = _HttpSessionImpl::GetInstance(*__pSession.get()); + SysTryCatch(NID_MEDIA, __pSessionImpl != null, r = GetLastResult(), GetLastResult(), + "[%s] Failed to get the managed httpsession.", GetErrorMessage(GetLastResult())); + + __pTransaction.reset(__pSessionImpl->OpenTransactionN()); + SysTryCatch(NID_MEDIA, __pTransaction.get() != null, r = E_SYSTEM, E_SYSTEM, + "[E_SYSTEM] Failed to create the HTTP transaction."); + + __pTransactionImpl = _HttpTransactionImpl::GetInstance(*__pTransaction.get()); + SysTryCatch(NID_MEDIA, __pTransactionImpl != null, r = GetLastResult(), GetLastResult(), + "[%s] Failed to get the managed httptransaction.", GetErrorMessage(GetLastResult())); + + r = __pTransactionImpl->SetTimeout(sec); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Failed to set timeout.", GetErrorMessage(r)); + + r = __pTransactionImpl->AddHttpTransactionListener(*(this->__pListener.release())); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Failed to add listener into the HTTP transaction.", GetErrorMessage(r)); + + __pRequest = __pTransactionImpl->GetRequest(); + SysTryCatch(NID_MEDIA, __pRequest != null, r = GetLastResult(), GetLastResult(), "[%s] Failed to get response from the HTTP transaction.", GetErrorMessage(GetLastResult())); + + __pRequestImpl = _HttpRequestImpl::GetInstance(*__pRequest); + SysTryCatch(NID_MEDIA, __pRequestImpl != null, r = GetLastResult(), GetLastResult(), + "[%s] Failed to get the managed httprequest.", GetErrorMessage(GetLastResult())); + + SysLog(NID_MEDIA, "Uri = %S", downloadUri.ToString().GetPointer()); + + r = __pRequestImpl->SetUri(downloadUri.ToString()); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Failed to set uri into the HTTP request.", GetErrorMessage(r)); + + r = __pRequestImpl->SetMethod(NET_HTTP_METHOD_GET); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Failed to set method into the HTTP request.", GetErrorMessage(r)); + + r = __pTransactionImpl->Submit(); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Failed to submit the HTTP request.", GetErrorMessage(r)); + + return r; + +CATCH: + + if (__pTransaction.get()) + { + __pTransactionImpl = null; + } + if (__pSession.get()) + { + __pSessionImpl = null; + } + return r; + +} + +void +_ImageUriData::OnTimerExpired(Timer& timer) +{ + result r = E_SUCCESS; + _ImageUriDataErrorArg* pUriErrorArg = null; + _ImageUriDataDestroyArg* pUriDestroyArg = null; + RequestId reqId = GetRequestId(); + + SysLog(NID_MEDIA, "RequestId : %d", reqId); + __isTimerStarted = false; + + r = Cancel(reqId, E_TIMEOUT); + if (r != E_SUCCESS) + { + pUriErrorArg = new (std::nothrow) _ImageUriDataErrorArg; + SysTryCatch(NID_MEDIA, pUriErrorArg != null, r = E_OUT_OF_MEMORY, + E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]"); + + pUriErrorArg->SetError(E_TIMEOUT); + pUriErrorArg->SetErrorCode(L"E_TIMEOUT"); + pUriErrorArg->SetErrorMessage(L"E_TIMEOUT"); + pUriErrorArg->SetRequestId(reqId); + pUriErrorArg->SetEventType(IMAGE_URI_DATA_EVENT_ERROR); + + r = __pDataEvent->FireAsync(*pUriErrorArg); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagated.", GetErrorMessage(r)); + + SysLog(NID_MEDIA, "Send destroy event : %d", reqId); + + pUriDestroyArg = new (std::nothrow) _ImageUriDataDestroyArg; + SysTryCatch(NID_MEDIA, pUriDestroyArg != null, r = E_OUT_OF_MEMORY, + E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]"); + + pUriDestroyArg->SetRequestId(this->GetRequestId()); + pUriDestroyArg->SetEventType(IMAGE_URI_DATA_EVENT_DESTROY); + + r = __pDataEvent->FireAsync(*pUriDestroyArg); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagated.", + GetErrorMessage(r)); + + } + + SetLastResult(E_SUCCESS); + return; + +CATCH: + SetLastResult(r); + return; +} + +}} // Tizen::Media diff --git a/src/FMedia_ImageUriData.h b/src/FMedia_ImageUriData.h new file mode 100644 index 0000000..d62708f --- /dev/null +++ b/src/FMedia_ImageUriData.h @@ -0,0 +1,97 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMedia_ImageUriData.h + * @brief This file contains the declaration of _ImageUriData class, + * required internally by Image::DecodeUrl. + */ + +#ifndef FMEDIA_INTERNAL_IMAGEURIDATA_H_ +#define FMEDIA_INTERNAL_IMAGEURIDATA_H_ + +#include + +namespace Tizen { namespace Net { namespace Http +{ +class HttpTransaction; +class HttpSession; +class HttpRequest; + +class _HttpTransactionImpl; +class _HttpSessionImpl; +class _HttpRequestImpl; +}}} +namespace Tizen{ namespace Media{ + +class _ImageUriDataEvent; +class _ImageDownloadListener; +class IImageDecodeUrlEventListener; + +/** + * @brief This class provides the _ImageUriData + * + * @see Image + */ +class _ImageUriData + : virtual public Tizen::Base::Object + , virtual public Tizen::Base::Runtime::ITimerEventListener + , virtual public Tizen::Base::Runtime::IEventListener +{ +public: + _ImageUriData(void); + virtual ~_ImageUriData(void); + + result Construct(Tizen::Base::Runtime::IEventListener& listener); + result RequestDecode(const Tizen::Base::Utility::Uri &uri, + Tizen::Graphics::BitmapPixelFormat colorFormat, + const Tizen::Graphics::Dimension& destDim, RequestId& reqId, long msec); + result Cancel(RequestId reqId, result res); + RequestId GetRequestId(void) const; + + Tizen::Base::Utility::Uri GetDownloadableUri(void) const; + +private: + _ImageUriData(const _ImageUriData& rhs); + _ImageUriData& operator =(const _ImageUriData& rhs); + + result RequestDownload(const Tizen::Base::Utility::Uri &downloadUri, RequestId& reqId, long msec ); + + void OnTimerExpired (Tizen::Base::Runtime::Timer &timer); + + Tizen::Base::Utility::Uri __srcUri; + Tizen::Base::Utility::Uri __downloadableUri; + int __destWidth; + int __destHeight; + std::unique_ptr __pSession; + Tizen::Net::Http::_HttpSessionImpl* __pSessionImpl; + std::unique_ptr __pTransaction; + Tizen::Net::Http::_HttpTransactionImpl* __pTransactionImpl; + Tizen::Net::Http::HttpRequest* __pRequest; + Tizen::Net::Http::_HttpRequestImpl* __pRequestImpl; + std::unique_ptr<_ImageDownloadListener> __pListener; + std::unique_ptr<_ImageUriDataEvent> __pDataEvent; + Tizen::Base::Runtime::Timer __requestTimeout; + Tizen::Graphics::BitmapPixelFormat __colorFormat; + RequestId __requestId; + int __refCount; + bool __isTimerStarted; +}; + +}} // Tizen::Media + +#endif // FMEDIA_INTERNAL_IMAGEURIDATA_H_ diff --git a/src/FMedia_ImageUriDataEvent.cpp b/src/FMedia_ImageUriDataEvent.cpp new file mode 100644 index 0000000..83052d7 --- /dev/null +++ b/src/FMedia_ImageUriDataEvent.cpp @@ -0,0 +1,159 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMedia_ImageUriDataEvent.cpp + * @brief This file contains the implementation of _ImageUriDataEvent class, + * required internally by Image::DecodeUrl. + */ + +#include +#include +#include + +#include +#include + +#include "FMedia_ImageUriDataFactory.h" +#include "FMedia_ImageUriDataEvent.h" +#include "FMedia_ImageUriDataEventArg.h" + + +using namespace Tizen::Base; +using namespace Tizen::Graphics; + +namespace Tizen{ namespace Media{ + + +_ImageUriDataEvent::_ImageUriDataEvent(void):__cntListener(0) +{ + +} + +_ImageUriDataEvent::~_ImageUriDataEvent(void) +{ + +} + +result +_ImageUriDataEvent::Construct(void) +{ + result r = E_SUCCESS; + r = _Event::Initialize(); + return r; +} + +void +_ImageUriDataEvent::FireImpl(Runtime::IEventListener& listener, const Runtime::IEventArg& arg) +{ + RequestId reqId = -1; + + Runtime::IEventArg* pTempArg = const_cast (&arg); + SysTryReturn(NID_MEDIA, pTempArg != null, ,E_INVALID_ARG, + "[E_INVALID_ARG] Received invalid EventArg."); + _ImageUriDataEventTypeArg* pEventTypeArg = dynamic_cast<_ImageUriDataEventTypeArg*>(pTempArg); + SysTryReturn(NID_MEDIA, pEventTypeArg != null, ,E_INVALID_ARG, + "[E_INVALID_ARG] Received invalid EventArg."); + + SysLog(NID_MEDIA, "Event Type(): %d", pEventTypeArg->GetEventType()); + reqId = pEventTypeArg->GetRequestId(); + + switch (pEventTypeArg->GetEventType()) + { + case IMAGE_URI_DATA_EVENT_ERROR: + { + _ImageUriDataErrorArg* pArg = dynamic_cast<_ImageUriDataErrorArg*>(pEventTypeArg); + SysTryReturn(NID_MEDIA, pArg != null, ,E_INVALID_ARG, + "[E_INVALID_ARG] Received invalid EventTypeArg."); + IImageDecodeUrlEventListener* pEventListener = dynamic_cast(&listener); + SysTryReturn(NID_MEDIA, pEventListener != null, ,E_INVALID_ARG, + "[E_INVALID_ARG] Received invalid ImageDecodeUrlEventListener."); + + pEventListener->OnImageDecodeUrlReceived(reqId, null, + pArg->GetError(), pArg->GetErrorCode(), pArg->GetErrorMessage()); + } + break; + + case IMAGE_URI_DATA_EVENT_SUCCESS: + { + _ImageUriDataEventArg* pArg = dynamic_cast<_ImageUriDataEventArg*>(pEventTypeArg); + SysTryReturn(NID_MEDIA, pArg != null, ,E_INVALID_ARG, + "[E_INVALID_ARG] Received invalid EventTypeArg."); + IImageDecodeUrlEventListener* pEventListener = dynamic_cast(&listener); + SysTryReturn(NID_MEDIA, pEventListener != null, ,E_INVALID_ARG, + "[E_INVALID_ARG] Received invalid ImageDecodeUrlEventListener."); + + if (pArg->GetData() != null) // if the network sends only file data. + { + // decode data to bitmap & call the listener. + std::unique_ptr pBitmap(_ImageImpl::DecodeToBitmapN(*((pArg)->GetData()), + pArg->GetColorFormat(), + pArg->GetDestDimension(), + BUFFER_SCALING_AUTO, + pArg->GetImageFormat())); + + if (pBitmap.get() != null) + { + pEventListener->OnImageDecodeUrlReceived( + reqId, pBitmap.get(), E_SUCCESS, L"E_SUCCESS", L"E_SUCCESS"); + } + else // decode fail + { + pEventListener->OnImageDecodeUrlReceived( + reqId, null, E_DECODING_FAILED, L"E_DECODING_FAILED", L"E_DECODING_FAILED"); + } + } + else // if E_SUCCESS but the data is null + { + pEventListener->OnImageDecodeUrlReceived( + reqId, null, E_SYSTEM, L"E_SYSTEM", L"E_SYSTEM"); + } + } + break; + + case IMAGE_URI_DATA_EVENT_CANCEL: + { + IImageDecodeUrlEventListener* pEventListener = dynamic_cast(&listener); + SysTryReturn(NID_MEDIA, pEventListener != null, ,E_INVALID_ARG, + "[E_INVALID_ARG] Received invalid ImageDecodeUrlEventListener."); + _ImageUriDataEventArg* pArg = dynamic_cast<_ImageUriDataEventArg*>(pEventTypeArg); + SysTryReturn(NID_MEDIA, pArg != null, ,E_INVALID_ARG, + "[E_INVALID_ARG] Received invalid EventTypeArg."); + pEventListener->OnImageDecodeUrlReceived(reqId, null, pArg->GetResult(), + GetErrorMessage(pArg->GetResult()), GetErrorMessage(pArg->GetResult())); + } + break; + + case IMAGE_URI_DATA_EVENT_DESTROY: + { + _ImageUriDataFactory* pFactory = _ImageUriDataFactory::GetInstance(); + + if (pFactory != null) + { + pFactory->OnMediaSessionEnded(reqId); + } + + } + break; + + default: + break; +} + +} + +}} // Tizen::Media diff --git a/src/FMedia_ImageUriDataEvent.h b/src/FMedia_ImageUriDataEvent.h new file mode 100644 index 0000000..88b73f4 --- /dev/null +++ b/src/FMedia_ImageUriDataEvent.h @@ -0,0 +1,57 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMedia_ImageUriDataEvent.h + * @brief This file contains the declaration of _ImageUriDataEvent class, + * required internally by Image::DecodeUrl. + */ + +#ifndef FMEDIA_INTERNAL_IMAGEURIDATAEVENT_H_ +#define FMEDIA_INTERNAL_IMAGEURIDATAEVENT_H_ + +#include + +namespace Tizen{ namespace Media{ + +class _ImageUriDataEvent + : public Tizen::Base::Runtime::_Event +{ + +public: + _ImageUriDataEvent(void); + + virtual ~_ImageUriDataEvent(void); + + result Construct(void); + +protected: + virtual void FireImpl(Tizen::Base::Runtime::IEventListener& Listener, + const Tizen::Base::Runtime::IEventArg& arg); + +private: + _ImageUriDataEvent(const _ImageUriDataEvent& value); + _ImageUriDataEvent& operator =(const _ImageUriDataEvent& value); + + int __cntListener; + +}; + +}} // Tizen::Media + +#endif // FMEDIA_INTERNAL_IMAGEURIDATAEVENT_H_ + diff --git a/src/FMedia_ImageUriDataEventArg.cpp b/src/FMedia_ImageUriDataEventArg.cpp new file mode 100644 index 0000000..b1ee650 --- /dev/null +++ b/src/FMedia_ImageUriDataEventArg.cpp @@ -0,0 +1,203 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMedia_ImageUriDataEventArg.cpp + * @brief This file contains the implementation of _ImageUriDataEvent class, + * required internally by Image::DecodeUrl. + */ + + +//include +#include +#include "FMedia_ImageUriDataEventArg.h" + +using namespace Tizen::Base; +using namespace Tizen::Graphics; + +namespace Tizen{ namespace Media{ + +_ImageUriDataEventTypeArg::_ImageUriDataEventTypeArg(void) + : __ImageUriDataEventType(IMAGE_URI_DATA_EVENT_NONE) + , __reqId(0) +{ + +} + +_ImageUriDataEventTypeArg::~_ImageUriDataEventTypeArg(void) +{ + // nothing to do. +} + +void +_ImageUriDataEventTypeArg::SetEventType(_ImageUriDataEventType eType) +{ + __ImageUriDataEventType = eType; +} + +_ImageUriDataEventType +_ImageUriDataEventTypeArg::GetEventType(void) const +{ + return __ImageUriDataEventType; +} + +RequestId +_ImageUriDataEventTypeArg::GetRequestId(void) const +{ + return __reqId; +} + +void +_ImageUriDataEventTypeArg::SetRequestId(RequestId reqId) +{ + __reqId = reqId; +} + +_ImageUriDataEventArg::_ImageUriDataEventArg(void) + : __imageFormat(IMG_FORMAT_NONE) + , __colorFormat(BITMAP_PIXEL_FORMAT_RGB565) + , __res(E_SUCCESS) +{ + +} + +_ImageUriDataEventArg::~_ImageUriDataEventArg(void) +{ +} + +void +_ImageUriDataEventArg::SetData( ByteBuffer* data) +{ + __pImageData.reset(data); +} + +ByteBuffer* +_ImageUriDataEventArg::GetData(void) const +{ + return __pImageData.get(); +} + +void +_ImageUriDataEventArg::SetDestDimension( Dimension dimension) +{ + __dimension = dimension; +} + +Dimension +_ImageUriDataEventArg::GetDestDimension(void) const +{ + return __dimension; +} + +void +_ImageUriDataEventArg::SetImageFormat( ImageFormat imageFormat ) +{ + __imageFormat = imageFormat; +} + +ImageFormat +_ImageUriDataEventArg::GetImageFormat(void) const +{ + return __imageFormat; +} + +void +_ImageUriDataEventArg::SetColorFormat( BitmapPixelFormat colorFormat) +{ + __colorFormat = colorFormat; +} + +BitmapPixelFormat +_ImageUriDataEventArg::GetColorFormat(void) const +{ + return __colorFormat; +} + +void +_ImageUriDataEventArg::SetResult(result r) +{ + __res = r; +} + +result +_ImageUriDataEventArg::GetResult(void) const +{ + return __res; +} + +_ImageUriDataErrorArg::_ImageUriDataErrorArg(void) + : __error(E_UNKNOWN) +{ + __errorCode = String(L""); + __errorMessage = String(L""); +} + +_ImageUriDataErrorArg::~_ImageUriDataErrorArg(void) +{ + // nothing to do. +} + +result +_ImageUriDataErrorArg::GetError(void) const +{ + return __error; +} + +void +_ImageUriDataErrorArg::SetError(result r) +{ + __error = r; +} + +String +_ImageUriDataErrorArg::GetErrorCode(void) const +{ + return __errorCode; +} + +void +_ImageUriDataErrorArg::SetErrorCode( const String errorCode) +{ + __errorCode = errorCode; +} + +String +_ImageUriDataErrorArg::GetErrorMessage(void) const +{ + return __errorMessage; +} + +void +_ImageUriDataErrorArg::SetErrorMessage( const String errorMessage) +{ + __errorMessage = errorMessage; +} + + +_ImageUriDataDestroyArg::_ImageUriDataDestroyArg(void) +{ + // nothing to do. +} + +_ImageUriDataDestroyArg::~_ImageUriDataDestroyArg(void) +{ + // nothing to do. +} + +}} // Tizen::Media + + diff --git a/src/FMedia_ImageUriDataEventArg.h b/src/FMedia_ImageUriDataEventArg.h new file mode 100644 index 0000000..3aaecb4 --- /dev/null +++ b/src/FMedia_ImageUriDataEventArg.h @@ -0,0 +1,176 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMedia_ImageUriDataEventArg.h + * @brief This file contains the declaration of _ImageUriDataEventArg class, + * required internally by Image::DecodeUrl. + */ + +#ifndef FMEDIA_INTERNAL_IMAGEURIDATAEVENTARG_H_ +#define FMEDIA_INTERNAL_IMAGEURIDATAEVENTARG_H_ + +//Include +#include +#include +#include +#include +#include + +namespace Tizen{ namespace Media{ +// +// @enum _ImageUriDataEventType +// @brief This represents ImageUriData event type. +// +enum _ImageUriDataEventType +{ + IMAGE_URI_DATA_EVENT_NONE, // Event_None + IMAGE_URI_DATA_EVENT_SUCCESS, // Success Event + IMAGE_URI_DATA_EVENT_CANCEL, // Cancel Event + IMAGE_URI_DATA_EVENT_ERROR, // Error event + IMAGE_URI_DATA_EVENT_DESTROY, // Destroy event +}; + + +/** + * @class _ImageUriDataEventTypeArg + * @brief This class contains the base information about the ImageUriData event. + * + */ +class _ImageUriDataEventTypeArg + : public Tizen::Base::Runtime::IEventArg + , public Tizen::Base::Object +{ +public: + + _ImageUriDataEventTypeArg(void); + + virtual ~_ImageUriDataEventTypeArg(void); + + _ImageUriDataEventType GetEventType(void) const; + + void SetEventType(_ImageUriDataEventType eType); + + RequestId GetRequestId(void) const; + + void SetRequestId(RequestId reqId); + +private: + _ImageUriDataEventTypeArg(const _ImageUriDataEventTypeArg& rhs); + _ImageUriDataEventTypeArg& operator =(const _ImageUriDataEventTypeArg& rhs); + + _ImageUriDataEventType __ImageUriDataEventType; + RequestId __reqId; +}; + +/** + * @class _ImageUriDataEventArg + * @brief This class contains the information about the ImageUriData event. + * + * @see ImageUriData + * + */ +class _ImageUriDataEventArg + : public _ImageUriDataEventTypeArg +{ + +public: + _ImageUriDataEventArg(void); + + virtual ~_ImageUriDataEventArg(void); + + Tizen::Base::ByteBuffer* GetData(void) const; + + Tizen::Graphics::Dimension GetDestDimension(void) const; + + ImageFormat GetImageFormat(void) const; + + Tizen::Graphics::BitmapPixelFormat GetColorFormat(void) const; + + result GetResult(void) const; + + void SetData(Tizen::Base::ByteBuffer* data); + + void SetDestDimension(Tizen::Graphics::Dimension dimension); + + void SetImageFormat(ImageFormat imageFormat); + + void SetColorFormat(Tizen::Graphics::BitmapPixelFormat colorFormat); + + void SetResult(result r); + +private: + std::unique_ptr __pImageData; + Tizen::Graphics::Dimension __dimension; + ImageFormat __imageFormat; + Tizen::Graphics::BitmapPixelFormat __colorFormat; + result __res; +}; + +/** + * @class _ImageUriDataErrorArg + * @brief This class contains the error about the ImageUriData. + * + * @see ImageUriData + * + */ +class _ImageUriDataErrorArg + : public _ImageUriDataEventTypeArg +{ +public: + _ImageUriDataErrorArg(void); + + virtual ~_ImageUriDataErrorArg(void); + + result GetError(void) const; + + Tizen::Base::String GetErrorCode(void) const; + + Tizen::Base::String GetErrorMessage(void) const; + + void SetError(result r); + + void SetErrorCode(const Tizen::Base::String errorCode); + + void SetErrorMessage(const Tizen::Base::String errorMessage); + +private: + result __error; + Tizen::Base::String __errorCode; + Tizen::Base::String __errorMessage; +}; + + +/** + * @class _ImageUriDataDestroyArg + * @brief This class if for life-cycle of ImageUriData. + * + * @see ImageUriData + * + */ +class _ImageUriDataDestroyArg + : public _ImageUriDataEventTypeArg +{ +public: + _ImageUriDataDestroyArg(void); + + virtual ~_ImageUriDataDestroyArg(void); +}; + +}} // Tizen::Media + +#endif // FMEDIA_INTERNAL_IMAGEURIDATAEVENTARG_H_ diff --git a/src/FMedia_ImageUriDataFactory.cpp b/src/FMedia_ImageUriDataFactory.cpp new file mode 100644 index 0000000..730415f --- /dev/null +++ b/src/FMedia_ImageUriDataFactory.cpp @@ -0,0 +1,326 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMedia_ImageUriDataFactory.cpp + * @brief This file contains the implementation of _ImageUriDataFactory class, + * required internally by Image::DecodeUrl. + */ + +//include +#include +#include +#include +#include +#include +#include + +#include "FMedia_ImageUriData.h" +#include "FMedia_ImageUriDataHolder.h" +#include "FMedia_ImageUriDataFactory.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Utility; +using namespace Tizen::Graphics; + +namespace Tizen{ namespace Media{ + +// 3 requests in worker queue. As in 2.0. +static const int _MAX_IMAGE_URI_DATA_WORK = 3; +// 3 requests in pending queue. As in 2.0. +static const int _MAX_IMAGE_URI_DATA_QUEUE_COUNT = 3; + +_ImageUriDataFactory* _ImageUriDataFactory::__pTheInstance = null; + +void +_ImageUriDataFactory::InitSingleton(void) +{ + std::unique_ptr<_ImageUriDataFactory> pInst(new (std::nothrow) _ImageUriDataFactory()); + + SysTryReturnVoidResult(NID_MEDIA, pInst, E_OUT_OF_MEMORY, + "[%s] Memory allocation failed.", + GetErrorMessage(E_OUT_OF_MEMORY)); + + result r = pInst->Construct(); + SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, + "[%s] Propagating.", GetErrorMessage(r)); + + __pTheInstance = pInst.release(); + std::atexit(DestroySingleton); +} + +void +_ImageUriDataFactory::DestroySingleton(void) +{ + delete __pTheInstance; +} + +_ImageUriDataFactory* +_ImageUriDataFactory::GetInstance(void) +{ + static pthread_once_t onceBlock = PTHREAD_ONCE_INIT; + + if (__pTheInstance == null) + { + ClearLastResult(); + pthread_once(&onceBlock, InitSingleton); + result r = GetLastResult(); + if (IsFailed(r)) + { + onceBlock = PTHREAD_ONCE_INIT; + } + } + return __pTheInstance; +} + +_ImageUriDataFactory::_ImageUriDataFactory(void) +{ + __requestId = 0; +} + +_ImageUriDataFactory::~_ImageUriDataFactory(void) +{ + if (__pImageUriDataHolderQueue.get() != null) + { + if (__pImageUriDataHolderQueue->GetCount() > 0) + { + __pImageUriDataHolderQueue->RemoveAll(true); + } + } + + if (__pImageUriDataWorkingList.get() != null) + { + if (__pImageUriDataWorkingList->GetCount() > 0) + { + __pImageUriDataWorkingList->RemoveAll(true); + } + } + + __requestId = 0; + +} + +result +_ImageUriDataFactory::Construct(void) +{ + result r = E_SUCCESS; + + __pImageUriDataHolderQueue.reset(new (std::nothrow) Collection::Queue()); + SysTryReturn(NID_MEDIA, __pImageUriDataHolderQueue.get() != null, + E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] while creating Queue"); + + r = __pImageUriDataHolderQueue->Construct(_MAX_IMAGE_URI_DATA_QUEUE_COUNT); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagated.", GetErrorMessage(r)); + + __pImageUriDataWorkingList.reset(new (std::nothrow) Collection::LinkedList()); + SysTryReturn(NID_MEDIA, __pImageUriDataWorkingList.get() != null , + E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] while creating List"); + + return r; +} + +result +_ImageUriDataFactory::DecodeUrl(const Uri& srcImageUrl, + BitmapPixelFormat colorFormat, int destWidth, int destHeight, + RequestId &reqId, const Runtime::IEventListener& listener, long timeout) +{ + result r = E_SUCCESS; + int index = 0; + reqId = -1; // if fail it returns -1; + + if (__pImageUriDataHolderQueue.get() == null) + { + r = Construct(); + SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Construct failed.", + GetErrorMessage(r)); + } + + SysTryReturn(NID_MEDIA, GetWorkerCount() < _MAX_IMAGE_URI_DATA_WORK, + E_MAX_EXCEEDED, E_MAX_EXCEEDED, + "[E_MAX_EXCEEDED] The concurrent working limitation is exceeded."); + + reqId = ++__requestId; + + index = AddImageUriData(srcImageUrl, colorFormat, destWidth, destHeight, reqId, listener, timeout); + SysTryReturn(NID_MEDIA, index > 0, GetLastResult(), GetLastResult(), + "[%s] Propagated.", GetErrorMessage(GetLastResult())); + + // 0, 1, 2.. //max 3 instances + SysTryReturn(NID_MEDIA, GetWorkerCount() < _MAX_IMAGE_URI_DATA_WORK, E_SUCCESS, + E_SUCCESS, "[E_SUCCESS] But this operation is now pending ."); + + r = StartDecode(); + return r; +} + +int +_ImageUriDataFactory::AddImageUriData(const Uri& srcImageUrl, + BitmapPixelFormat colorFormat, int destWidth, int destHeight, + RequestId &reqId, const Runtime::IEventListener& listener, long timeout) +{ + result r = E_SUCCESS; + ClearLastResult(); + + _ImageUriDataHolder* pImageUriDataHolder = new (std::nothrow) _ImageUriDataHolder(); + SysTryCatch(NID_MEDIA, pImageUriDataHolder != null , + r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] while creating Image holder"); + + pImageUriDataHolder->SetUri(srcImageUrl); + pImageUriDataHolder->SetColorFormat(colorFormat); + pImageUriDataHolder->SetDestDim(Dimension(destWidth, destHeight)); + pImageUriDataHolder->SetRequestId(reqId); + pImageUriDataHolder->SetListener(const_cast(&listener)); + pImageUriDataHolder->SetTimeout(timeout); + + r = __pImageUriDataHolderQueue->Enqueue(*pImageUriDataHolder); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagated.", GetErrorMessage(r)); + + SetLastResult(r); + return GetHolderCount(); + +CATCH: + reqId = -1; + if (pImageUriDataHolder) + { + delete pImageUriDataHolder; + pImageUriDataHolder = null; + } + return -1; +} + +result +_ImageUriDataFactory::StartDecode(void) +{ + result r = E_SUCCESS; + Object* pObj = null; + _ImageUriDataHolder* pImageUriDataHolder = null; + IImageDecodeUrlEventListener* pImageListener = null; + Runtime::IEventListener* pListener = null; + std::unique_ptr<_ImageUriData> pImageUriData; + RequestId reqId = -1; + + SysTryCatch(NID_MEDIA, __pImageUriDataHolderQueue.get() != null, + r = E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE]"); + + pObj = __pImageUriDataHolderQueue->Dequeue(); + SysTryCatch(NID_MEDIA, pObj != null, r = E_UNDERFLOW, E_UNDERFLOW, "[E_UNDERFLOW]"); + + pImageUriDataHolder = dynamic_cast<_ImageUriDataHolder*>(pObj); + SysTryCatch(NID_MEDIA, pImageUriDataHolder != null, r = E_INVALID_ARG, + E_INVALID_ARG, "[E_INVALID_ARG] : RequestId = %d", + pImageUriDataHolder->GetRequestId()); + + pListener = pImageUriDataHolder->GetListener(); + pImageListener = dynamic_cast(pListener); + SysTryCatch(NID_MEDIA, pImageListener != null, r = E_INVALID_ARG, + E_INVALID_ARG, "[E_INVALID_ARG] GetListener() : RequestId = %d", + pImageUriDataHolder->GetRequestId()); + + pImageUriData.reset(new (std::nothrow) _ImageUriData()); + SysTryCatch(NID_MEDIA, pImageUriData.get() != null, r = E_OUT_OF_MEMORY, + E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] : RequestId = %d", + pImageUriDataHolder->GetRequestId()); + + r = pImageUriData->Construct(*pImageListener); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagated : RequestId = %d.", + GetErrorMessage(r), pImageUriDataHolder->GetRequestId()); + + reqId = pImageUriDataHolder->GetRequestId(); + + r = pImageUriData->RequestDecode(pImageUriDataHolder->GetUri(), + pImageUriDataHolder->GetColorFormat(), pImageUriDataHolder->GetDestDim(), + reqId, pImageUriDataHolder->GetTimeout()); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagated : RequestId = %d.", + GetErrorMessage(r), pImageUriDataHolder->GetRequestId()); + + r = __pImageUriDataWorkingList->Add(*pImageUriData.release()); + SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagated : RequestId = %d.", + GetErrorMessage(r), pImageUriDataHolder->GetRequestId()); + + delete pImageUriDataHolder; + + return r; + +CATCH: + + if (pImageUriDataHolder) + { + delete pImageUriDataHolder; + } + return r; +} + +void +_ImageUriDataFactory::Watchout(void) +{ + result r = E_SUCCESS; + int heldCount = GetHolderCount(); + + while (0 < heldCount) + { + r = StartDecode(); + if (r == E_SUCCESS) + { + break; + } + heldCount = GetHolderCount(); + } +} + +void +_ImageUriDataFactory::OnMediaSessionEnded(RequestId requestId) +{ + int num = 0; + Object* pObj = null; + + // free the memory + num = __pImageUriDataWorkingList->GetCount(); + for (int i = 0; i < num; i++) + { + pObj = __pImageUriDataWorkingList->GetAt(i); + if (pObj != null) + { + _ImageUriData* pImageUriData = dynamic_cast<_ImageUriData*>(pObj); + if (pImageUriData != null) + { + if (requestId == pImageUriData->GetRequestId()) + { + __pImageUriDataWorkingList->RemoveAt(i, true); + break; + } + } + } + } + + Watchout(); +} + +int +_ImageUriDataFactory::GetHolderCount(void) +{ + int count = __pImageUriDataHolderQueue->GetCount(); + return count; +} + +int +_ImageUriDataFactory::GetWorkerCount(void) +{ + int count = __pImageUriDataWorkingList->GetCount(); + return count; +} + +}} // Tizen::Media diff --git a/src/FMedia_ImageUriDataFactory.h b/src/FMedia_ImageUriDataFactory.h new file mode 100644 index 0000000..cd7df71 --- /dev/null +++ b/src/FMedia_ImageUriDataFactory.h @@ -0,0 +1,79 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMedia_ImageUriDataFactory.h + * @brief This file contains the declaration of _ImageUriDataFactory class, + * required internally by Image::DecodeUrl. + */ + +#ifndef FMEDIA_INTERNAL_IMAGEURIDATAFACTORY_H_ +#define FMEDIA_INTERNAL_IMAGEURIDATAFACTORY_H_ + +#include + +namespace Tizen{ namespace Media{ + +static const int _TIMEOUT_INFINITE = 0; + +class _ImageUriDataFactory + : public Tizen::Base::Object + , Tizen::Base::Runtime::IEventListener +{ +public: + static _ImageUriDataFactory* GetInstance(void); + + result Construct(void); + + result + DecodeUrl(const Tizen::Base::Utility::Uri& srcImageUrl, + Tizen::Graphics::BitmapPixelFormat colorFormat, + int destWidth, int destHeight, RequestId &reqId, + const Tizen::Base::Runtime::IEventListener& listener, long timeout); + + int GetHolderCount(void); + int GetWorkerCount(void); + + void OnMediaSessionEnded(RequestId requestId); + +private: + _ImageUriDataFactory(void); + virtual ~_ImageUriDataFactory(void); + _ImageUriDataFactory(const _ImageUriDataFactory& value); + _ImageUriDataFactory& operator =(const _ImageUriDataFactory& value); + + int AddImageUriData(const Tizen::Base::Utility::Uri& srcImageUrl, + Tizen::Graphics::BitmapPixelFormat colorFormat, + int destWidth, int destHeight, RequestId &reqId, + const Tizen::Base::Runtime::IEventListener& listener, long timeout); + result StartDecode(void); + void Watchout(void); + + static void InitSingleton(void); + static void DestroySingleton(void); + + RequestId __requestId; + static _ImageUriDataFactory* __pTheInstance; + friend struct std::default_delete<_ImageUriDataFactory>; + std::unique_ptr __pImageUriDataHolderQueue; + std::unique_ptr __pImageUriDataWorkingList; +}; + + +}} // Tizen::Media + +#endif // FMEDIA_INTERNAL_IMAGEURIDATAFACTORY_H_ diff --git a/src/FMedia_ImageUriDataHolder.cpp b/src/FMedia_ImageUriDataHolder.cpp new file mode 100644 index 0000000..80b6d50 --- /dev/null +++ b/src/FMedia_ImageUriDataHolder.cpp @@ -0,0 +1,127 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMedia_ImageUriDataHolder.cpp + * @brief This file contains the implementation of _ImageUriDataHolder class, + * required internally by Image::DecodeUrl. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include "FMedia_ImageUriData.h" +#include "FMedia_ImageUriDataHolder.h" + +using namespace Tizen::Base; +using namespace Tizen::Graphics; +using namespace Tizen::Base::Runtime; +using namespace Tizen::Base::Utility; + +namespace Tizen{ namespace Media{ + +_ImageUriDataHolder::_ImageUriDataHolder(void) +{ + __timeout = 0; + __colorFormat = BITMAP_PIXEL_FORMAT_RGB565; + __pListener = null; + __requestId = -1; +} + +_ImageUriDataHolder::~_ImageUriDataHolder(void) +{ + +} + +Dimension +_ImageUriDataHolder::GetDestDim(void) const +{ + return __destDim; +} + +long +_ImageUriDataHolder::GetTimeout(void) const +{ + return __timeout; +} + +Uri +_ImageUriDataHolder::GetUri(void) const +{ + return __uri; +} + +void +_ImageUriDataHolder::SetDestDim(const Dimension destDim) +{ + __destDim = destDim; +} + +void +_ImageUriDataHolder::SetTimeout(long timeout) +{ + __timeout = timeout; +} + +void +_ImageUriDataHolder::SetUri(const Uri& uri) +{ + __uri = uri; +} + +BitmapPixelFormat +_ImageUriDataHolder::GetColorFormat(void) const +{ + return __colorFormat; +} + +void +_ImageUriDataHolder::SetColorFormat(BitmapPixelFormat colorFormat) +{ + __colorFormat = colorFormat; +} + +IEventListener* +_ImageUriDataHolder::GetListener(void) const +{ + return __pListener; +} + +void +_ImageUriDataHolder::SetListener(IEventListener* pListener) +{ + __pListener = pListener; +} + +RequestId +_ImageUriDataHolder::GetRequestId(void) const +{ + return __requestId; +} + +void +_ImageUriDataHolder::SetRequestId(RequestId reqId) +{ + __requestId = reqId; +} + +}} // Tizen::Media diff --git a/src/FMedia_ImageUriDataHolder.h b/src/FMedia_ImageUriDataHolder.h new file mode 100644 index 0000000..5b021c0 --- /dev/null +++ b/src/FMedia_ImageUriDataHolder.h @@ -0,0 +1,68 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMedia_ImageUriDataHolder.h + * @brief This file contains the declaration of _ImageUriDataHolder class, + * required internally by Image::DecodeUrl. + */ + +#ifndef FMEDIA_INTERNAL_IMAGEURIDATAHOLDER_H_ +#define FMEDIA_INTERNAL_IMAGEURIDATAHOLDER_H_ + + +namespace Tizen{ namespace Media{ + +/** + * @brief This class provides the _ImageUriDataHolder + * + * @see Image + */ +class _ImageUriDataHolder + : public Tizen::Base::Object +{ + public: + _ImageUriDataHolder(void); + virtual ~_ImageUriDataHolder(void); + + Tizen::Graphics::Dimension GetDestDim(void) const; + long GetTimeout(void) const; + Tizen::Base::Utility::Uri GetUri(void) const; + RequestId GetRequestId(void) const; + + void SetDestDim(const Tizen::Graphics::Dimension destDim); + void SetTimeout(long timeout); + void SetUri(const Tizen::Base::Utility::Uri& uri); + Tizen::Graphics::BitmapPixelFormat GetColorFormat(void) const; + void SetColorFormat(Tizen::Graphics::BitmapPixelFormat colorFormat); + Tizen::Base::Runtime::IEventListener *GetListener(void) const; + void SetListener(Tizen::Base::Runtime::IEventListener *pListener); + void SetRequestId(RequestId reqId); + +private: + Tizen::Base::Utility::Uri __uri; + Tizen::Graphics::Dimension __destDim; + long __timeout; + Tizen::Graphics::BitmapPixelFormat __colorFormat; + Tizen::Base::Runtime::IEventListener* __pListener; + RequestId __requestId; +}; + + +}} // Tizen::Media + +#endif // FMEDIA_INTERNAL_IMAGEURIDATAHOLDER_H_ diff --git a/src/FMedia_ImageUtilImpl.cpp b/src/FMedia_ImageUtilImpl.cpp new file mode 100644 index 0000000..9a8390b --- /dev/null +++ b/src/FMedia_ImageUtilImpl.cpp @@ -0,0 +1,186 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMedia_ImageUtilImpl.cpp + * @brief This file contains the implementation of _ImageUtilImpl class. + */ + +#include +#include +#include +#include +#include +#include +#include "FMedia_MediaUtil.h" +#include "FMedia_ImageUtil.h" +#include "FMedia_ImageUtilImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Graphics; +using namespace Tizen::Io; + +namespace Tizen { namespace Media +{ + +result +_ImageUtilImpl::ConvertPixelFormat(const ByteBuffer& srcBuf, ByteBuffer& dstBuf, + MediaPixelFormat srcFormat, MediaPixelFormat dstFormat, + const Dimension& dim) +{ + return _ImageUtil::ConvertPixelFormat(srcBuf, srcFormat, dim.width, dim.height, + dstBuf, dstFormat); +} + + +result +_ImageUtilImpl::Resize(const ByteBuffer& srcBuf, ByteBuffer& dstBuf, + const Dimension& srcDim, const Dimension& dstDim, + MediaPixelFormat pixelFormat) +{ + return _ImageUtil::Resize(srcBuf, pixelFormat, srcDim.width, srcDim.height, + dstBuf, dstDim.width, dstDim.height); +} + + +result +_ImageUtilImpl::Rotate(const ByteBuffer& srcBuf, ByteBuffer& dstBuf, + const Dimension& dim, ImageRotationType rotate, + MediaPixelFormat pixelFormat) +{ + return _ImageUtil::Rotate(srcBuf, pixelFormat, dim.width, dim.height, + dstBuf, rotate); +} + + +result +_ImageUtilImpl::Flip(const ByteBuffer& srcBuf, ByteBuffer& dstBuf, const Dimension& dim, + ImageFlipType flip, MediaPixelFormat pixelFormat) +{ + return _ImageUtil::Flip(srcBuf, pixelFormat, dim.width, dim.height, + dstBuf, flip); +} + +Tizen::Media::ImageFormat +_ImageUtilImpl::GetImageFormat(const Tizen::Base::String& srcImageFile) +{ + return _ImageUtil::GetImageFormat(srcImageFile); +} + + +bool +_ImageUtilImpl::HasAlphaChannel(const Tizen::Base::String& srcImageFile) +{ + return _ImageUtil::HasAlphaChannel(srcImageFile); +} + +int +_ImageUtilImpl::MinImageFormatLength(void) +{ + return _ImageUtil::MinImageFormatLength(); +} + +ImageFormat +_ImageUtilImpl::GetImageFormat(const Tizen::Base::ByteBuffer& srcBuf) +{ + return _ImageUtil::GetImageFormat(srcBuf); +} + +bool +_ImageUtilImpl::HasAlphaChannel(const Tizen::Base::ByteBuffer& srcBuf) +{ + return _ImageUtil::HasAlphaChannel(srcBuf); +} + +Tizen::Base::ByteBuffer* +_ImageUtilImpl::ResizeN(const Tizen::Base::ByteBuffer &srcBuf, + const Tizen::Graphics::Dimension& srcDim, + MediaPixelFormat pixelFormat, + const Tizen::Graphics::Dimension& dstDim) +{ + return _ImageUtil::ResizeN(srcBuf, pixelFormat, srcDim.height, srcDim.width, dstDim.height, dstDim.width); +} + + +MediaPixelFormat +_ImageUtilImpl::ToMediaPixelFormat(BitmapPixelFormat bitmapFormat) +{ + static struct + { + BitmapPixelFormat key; + MediaPixelFormat value; + } map[] = { + { BITMAP_PIXEL_FORMAT_RGB565, MEDIA_PIXEL_FORMAT_RGB565LE }, + { BITMAP_PIXEL_FORMAT_ARGB8888, MEDIA_PIXEL_FORMAT_BGRA8888 }, + { BITMAP_PIXEL_FORMAT_R8G8B8A8, MEDIA_PIXEL_FORMAT_RGBA8888 }, + }; + MediaPixelFormat ret = MEDIA_PIXEL_FORMAT_NONE; + + for (unsigned int i = 0; i < sizeof(map)/sizeof(map[0]); i++) + { + if (map[i].key == bitmapFormat) + { + return map[i].value; + } + } + + return ret; +} + +int +_ImageUtilImpl::GetBufferSize(const Tizen::Graphics::Dimension& dim, MediaPixelFormat pixelFormat) +{ + return _ImageUtil::GetBufferSize(pixelFormat, dim.width, dim.height); +} + +bool +_ImageUtilImpl::IsValidDimension(MediaPixelFormat pixelFormat, const Tizen::Graphics::Dimension& dim) +{ + return _ImageUtil::IsValidDimension(pixelFormat, dim.width, dim.height); +} + +Tizen::Base::String +_ImageUtilImpl::ToString(ImageFormat imgFormat) +{ + static struct + { + ImageFormat key; + const char *value; + } map[] = { + { IMG_FORMAT_NONE, "None"}, + { IMG_FORMAT_JPG, "JPG"}, + { IMG_FORMAT_PNG, "PNG"}, + { IMG_FORMAT_GIF, "GIF"}, + { IMG_FORMAT_TIFF, "TIFF"}, + { IMG_FORMAT_BMP, "BMP"}, + { IMG_FORMAT_WBMP, "WBMP"}, + }; + const char* pStr = "None"; + + for (unsigned int i = 0; i < sizeof(map)/sizeof(map[0]); i++) + { + if (map[i].key == imgFormat) + { + pStr = map[i].value; + break; + } + } + + return String(pStr); +} + +}} // Tizen::Media diff --git a/src/inc/FMedia_ExifUtil.h b/src/inc/FMedia_ExifUtil.h new file mode 100644 index 0000000..4074714 --- /dev/null +++ b/src/inc/FMedia_ExifUtil.h @@ -0,0 +1,72 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#ifndef __FMEDIA_INTERNAL_EXIF_UTIL_H__ +#define __FMEDIA_INTERNAL_EXIF_UTIL_H__ + +#include + +#define _EXIF_UTIL_LOG_ 1 + +namespace Tizen { namespace Media +{ + +_OSP_EXPORT_ extern const wchar_t* const EXIF_TAG_IMAGE_ORIENTATION; +_OSP_EXPORT_ extern const wchar_t* const EXIF_TAG_IMAGE_GPS_ALTITUDE; +_OSP_EXPORT_ extern const wchar_t* const EXIF_TAG_IMAGE_GPS_LONGITUDE; +_OSP_EXPORT_ extern const wchar_t* const EXIF_TAG_IMAGE_GPS_LATITUDE; + +class _OSP_EXPORT_ _ExifUtil + : public Tizen::Base::Object +{ +public: + _ExifUtil(); + ~_ExifUtil(); + + result Construct(const byte *buf, int length); + result GetValue(const Tizen::Base::String& key, int &value); + result GetValue(const Tizen::Base::String& key, double &value); + +protected: + void ForEachEntry(struct _ExifEntry *pEntry); + static void ForEachEntryStatic(struct _ExifEntry *pEntry, void *pUserData); + + void ForEachContent(struct _ExifContent *pContent); + static void ForEachContentStatic(struct _ExifContent *pContent, void *pUserData); + +#if defined _EXIF_UTIL_LOG_ +// static void ExifLogFuncStatic(ExifLog *log, ExifLogCode code, const char *domain, const char *format, va_list args, void *data); +// void ExifLogFunc(ExifLog *log, ExifLogCode code, const char *domain, const char *format, va_list args); +#endif + +private: + struct _ExifData*__pExifData; + struct _ExifLog*__pExifLog; + + short __orientation; + double __gpsLongitude; + double __gpsLatitude; + float __gpsAltitude; + + bool __gpsLongitudeExist; + bool __gpsAltitudeExist; + bool __gpsLatitudeExist; + bool __orientationExist; +}; + +}} + +#endif diff --git a/src/inc/FMedia_ImageBufferImpl.h b/src/inc/FMedia_ImageBufferImpl.h new file mode 100644 index 0000000..ca6b61b --- /dev/null +++ b/src/inc/FMedia_ImageBufferImpl.h @@ -0,0 +1,215 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + + +/** + * @file FMedia_ImageBufferImpl.h + * @brief This is the header file for the _ImageBufferImpl class. + * + * This header file contains the declarations of the Tizen::Media::_ImageBufferImpl class. + */ +#ifndef _FMEDIA_INTERNAL_IMAGE_BUFFER_IMPL_H_ +#define _FMEDIA_INTERNAL_IMAGE_BUFFER_IMPL_H_ + +#include + +namespace Tizen { namespace Media +{ + +class ImageBuffer; + +class _OSP_EXPORT_ _ImageBufferImpl + : public Tizen::Base::Object +{ +public: + + /** + * This is the default constructor for this class. + * The object is not fully constructed after this constructor is called. + * For full construction, the Construct() method must be called right after + * calling this constructor. + * + * @see Construct() + */ + _ImageBufferImpl(void); + + /** + * This is the destructor for this class. + * This destructor overrides Tizen::Base::Object::~Object() + * + * @see Construct() + */ + virtual ~_ImageBufferImpl(void); + + /** + * @see ImageBuffer::Construct() + */ + result Construct(int width, int height, MediaPixelFormat pixelFormat); + + /** + * @see ImageBuffer::Construct() + */ + result Construct(const Tizen::Base::String &srcImagePath, + const Tizen::Graphics::Rectangle *pDecodingRegion = null, + bool autoRotate = true); + + /** + * @see ImageBuffer::Construct() + */ + result Construct(const Tizen::Base::ByteBuffer &srcImageBuf, + const Tizen::Graphics::Rectangle *pDecodingRegion = null, + bool autoRotate = true); + + /** + * @see ImageBuffer::Construct() + */ + result Construct(int width, int height, MediaPixelFormat pixelFormat, + const byte* pData = null, int length = 0); + + /** + * @see ImageBuffer::Construct() + */ + result Construct(const Tizen::Graphics::Bitmap &srcBitmap); + + /** + * @see ImageBuffer::Equals() + */ + virtual bool Equals(ImageBuffer* pRhs) const; + + /** + * @see ImageBuffer::GetHashCode() + */ + virtual int GetHashCode(void) const; + + /** + * @see ImageBuffer::GetHeight() + */ + int GetHeight(void) const; + + /** + * @see ImageBuffer::GetWidth() + */ + int GetWidth(void) const; + + /** + * @see ImageBuffer::GetPixelFormat() + */ + MediaPixelFormat GetPixelFormat(void) const; + + /** + * @see ImageBuffer::Lock() + */ + result Lock(byte* &data, int &length, MediaPixelFormat &pixelFormat); + + /** + * @see ImageBuffer::Unlock() + */ + result Unlock(void); + + /** + * @see ImageBuffer::EncodeToBufferN() + */ + Tizen::Base::ByteBuffer* EncodeToBufferN(ImageFormat destImageFormat, int quality = 90) const; + + /** + * @see ImageBuffer::EncodeToFile() + */ + result EncodeToFile(const Tizen::Base::String &destImagePath, ImageFormat destImageFormat, bool overwrite, int quality = 90) const; + + /** + * @see ImageBuffer::GetBitmapN() + */ + Tizen::Graphics::Bitmap* GetBitmapN(Tizen::Graphics::BitmapPixelFormat pixelFormat, Tizen::Graphics::BufferScaling bufferScaling) const; + + /** + * @see ImageBuffer::GetByteBufferN() + */ + Tizen::Base::ByteBuffer* GetByteBufferN(MediaPixelFormat pixelFormat) const; + + /** + * @see ImageBuffer::CloneN() + */ + virtual ImageBuffer* CloneN(void) const; + + /** + * @see ImageBuffer::ConvertPixelFormatN() + */ + ImageBuffer* ConvertPixelFormatN(MediaPixelFormat pixelFormat) const; + + /** + * @see ImageBuffer::ResizeN() + */ + ImageBuffer* ResizeN(int width, int height) const; + + /** + * @see ImageBuffer::FlipN() + */ + ImageBuffer* FlipN(ImageFlipType flipType) const; + + /** + * @see ImageBuffer::RotateN() + */ + ImageBuffer* RotateN(ImageRotationType rotateType) const; + + /** + * @see ImageBuffer::CropN() + */ + ImageBuffer* CropN(int x, int y, int width, int height) const; + + /** + * @see ImageBuffer::GetImageInfo() + */ + static result GetImageInfo(const Tizen::Base::String& srcImagePath, ImageFormat &imageFormat, int &width, int &height); + + /** + * @see ImageBuffer::GetImageInfo() + */ + static result GetImageInfo(const Tizen::Base::ByteBuffer& srcImageBuf, ImageFormat &imageFormat, int &width, int &height); + + static bool IsSupportedPixelFormat(MediaPixelFormat pixelFormat); + /** + * @see ImageBuffer::GetSupportedPixelFormatListN() + */ + static Tizen::Base::Collection::IListT* GetSupportedPixelFormatListN(void); + + static _ImageBufferImpl* GetInstance(ImageBuffer& a); + + static const _ImageBufferImpl* GetInstance(const ImageBuffer& a); +private: + + /** + * The implementation of this copy constructor is intentionally blank + * and declared as private to prohibit copying of objects. + */ + _ImageBufferImpl(const _ImageBufferImpl& rhs); + + /** + * The implementation of this copy assignment operator is intentionally blank + * and declared as private to prohibit copying of objects. + */ + _ImageBufferImpl& operator =(const _ImageBufferImpl& rhs); + + std::unique_ptr __pBuffer; + int __width; + int __height; + MediaPixelFormat __pixelFormat; + bool __isLocked; +}; + +}} // Tizen::Media + +#endif // _FMEDIA_INTERNAL_IMAGE_BUFFER_IMPL_H_ diff --git a/src/inc/FMedia_ImageImpl.h b/src/inc/FMedia_ImageImpl.h new file mode 100644 index 0000000..455bb95 --- /dev/null +++ b/src/inc/FMedia_ImageImpl.h @@ -0,0 +1,233 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMedia_ImageImpl.h + * @brief This is the header file for the _ImageImpl. + */ +#ifndef _FMEDIA_INTERNAL_IMAGE_IMPL_H_ +#define _FMEDIA_INTERNAL_IMAGE_IMPL_H_ + +#include +#include + +#include +#include + + +namespace Tizen { namespace Media +{ + +class Image; +class _ImageEncoder; +class IImageDecodeUrlEventListener; + +class _OSP_EXPORT_ _ImageImpl + : public Tizen::Base::Object +{ +public: + _ImageImpl(void); + + virtual ~_ImageImpl(void); + +public: + result Construct(void); + + /** + * Decodes an image file into the decoded bitmap container. @n + * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP. + * + * @see Image::DecodeToBitmapN() + */ + static Tizen::Graphics::Bitmap* + DecodeToBitmapN(const Tizen::Base::String& srcImagePath, + Tizen::Graphics::BitmapPixelFormat pixelFormat = Tizen::Graphics::BITMAP_PIXEL_FORMAT_ARGB8888, + const Tizen::Graphics::Dimension &desDim = Tizen::Graphics::Dimension(0, 0), + Tizen::Graphics::BufferScaling bufferScaling = Tizen::Graphics::BUFFER_SCALING_AUTO, + ImageFormat imgFormat = IMG_FORMAT_NONE, bool keepAspectRatio = true); + /** + * Decodes an image data into the decoded bitmap container with resizing. @n + * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP. + * This method retains the aspect ratio of the original image. + * + * @see Image::DecodeToBitmapN() + */ + static Tizen::Graphics::Bitmap* + DecodeToBitmapN(const Tizen::Base::ByteBuffer& srcImageBuf, + Tizen::Graphics::BitmapPixelFormat pixelFormat = Tizen::Graphics::BITMAP_PIXEL_FORMAT_ARGB8888, + const Tizen::Graphics::Dimension &dim = Tizen::Graphics::Dimension(0, 0), + Tizen::Graphics::BufferScaling bufferScaling = Tizen::Graphics::BUFFER_SCALING_AUTO, + ImageFormat imgFormat = IMG_FORMAT_NONE, bool keepAspectRatio = true); + + /** + * Decodes an image data into the decoded byte buffer container without resizing. @n + * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP. + * + * @see Image::DecodeToBufferN() + */ + static Tizen::Base::ByteBuffer* + DecodeToBufferN(const Tizen::Base::ByteBuffer& srcImageBuf, + Tizen::Graphics::Dimension &restDim, + const Tizen::Graphics::Dimension &destDim = Tizen::Graphics::Dimension(0,0), + Tizen::Graphics::BitmapPixelFormat pixelFormat = Tizen::Graphics::BITMAP_PIXEL_FORMAT_ARGB8888, + ImageFormat imgFormat = IMG_FORMAT_NONE, bool keepAspectRatio = true); + + /** + * Decodes an image file into the decoded byte buffer container without resizing. @n + * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP. + * + * @see Image::DecodeToBufferN() + */ + static Tizen::Base::ByteBuffer* + DecodeToBufferN(const Tizen::Base::String& srcImagePath, + Tizen::Graphics::Dimension &restDim, + const Tizen::Graphics::Dimension &destDim = Tizen::Graphics::Dimension(0,0), + Tizen::Graphics::BitmapPixelFormat pixelFormat = Tizen::Graphics::BITMAP_PIXEL_FORMAT_ARGB8888, + ImageFormat imgFormat = IMG_FORMAT_NONE, bool keepAspectRatio = true); + + /** + * @deprecated + * Decodes an image file into the decoded byte buffer container without resizing. @n + * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP. + * + * @see Image::DecodeToBufferN() + */ + static Tizen::Base::ByteBuffer* + DecodeToBufferN(const Tizen::Base::String& srcImagePath, + Tizen::Graphics::BitmapPixelFormat pixelFormat, + int& imageWidth, int& imageHeight, bool keepAspectRatio = true); + + /** + * Converts the image file to the specified image format. @n + * This is a synchronous method. The converting formats currently supported are JPEG, BMP, and PNG. + * + * @see Image::ConvertToBufferN() + */ + static Tizen::Base::ByteBuffer* + ConvertToBufferN(const Tizen::Base::String& srcImagePath, ImageFormat destImageFormat); + + /** + * Encodes the specified bitmap data into a byte buffer. @n + * The currently supported encoding formats are JPEG, BMP, and PNG. + * + * @see Image::EncodeToBufferN() + */ + static Tizen::Base::ByteBuffer* + EncodeToBufferN(const Tizen::Graphics::Bitmap& srcBitmap, ImageFormat destImageFormat); + + + /** + * Encodes the specified bitmap data into a file. @n + * The currently supported encoding formats are JPEG, BMP, and PNG. + * + * @see Image::EncodeToFile() + */ + static result EncodeToFile(const Tizen::Graphics::Bitmap& srcBitmap, + ImageFormat destImageFormat, const Tizen::Base::String& destImagePath, + bool overwrite); + + /** + * Recompresses an encoded image file to reduce its size as per the specified limit. @n + * The only supported compression format is JPEG. + * + * @see Image::CompressJpeg() + */ + static result CompressJpeg(const Tizen::Base::String& srcImagePath, + const Tizen::Base::String& destImagePath, int limitSize); + + /** + * Recompresses an encoded image data to the byte buffer to reduce its data size as per the specified limit. @n + * The only supported compression format is JPEG. + * + * @see Image::CompressJpegN() + */ + static Tizen::Base::ByteBuffer* CompressJpegN(const Tizen::Base::ByteBuffer& srcImageBuf, + int limitSize); + + /** + * Get image informations + * + * @see Image::GetImageInfo() + */ + static result GetImageInfo(const Tizen::Base::String& imagePath, ImageFormat &imgFormat, + Tizen::Graphics::Dimension &dim); + +public: + + /** + * @deprecated Use DecodeToBufferN + */ + static Tizen::Base::ByteBuffer* + DecodeN(const Tizen::Base::String& srcImagePath, Tizen::Graphics::BitmapPixelFormat pixelFormat, + int destWidth, int destHeight, bool keepAspectRatio=false); + + + result DecodeUrl(const Tizen::Base::Utility::Uri& srcImageUrl, + Tizen::Graphics::BitmapPixelFormat pixelFormat, + int destWidth, int destHeight, RequestId& reqId, + const IImageDecodeUrlEventListener& listener, long timeout); + +protected: +// +// static Tizen::Base::ByteBuffer* DecodeN(const Tizen::Base::ByteBuffer& srcImageBuf, +// ImageFormat srcImageFormat, +// Tizen::Graphics::BitmapPixelFormat pixelFormat, +// Tizen::Graphics::Dimension& destDim); +// +// static Tizen::Base::ByteBuffer* DecodeN(const Tizen::Base::ByteBuffer& srcImageBuf, +// ImageFormat srcImageFormat, +// Tizen::Graphics::BitmapPixelFormat pixelFormat, +// int destWidth, int destHeight); +// +// static result DecodeN(const Tizen::Base::ByteBuffer& srcImageBuf, +// ImageFormat imgFormat, Tizen::Graphics::BitmapPixelFormat pixelFormat, +// byte*&outBuf, int &outLength, Tizen::Graphics::Dimension &dim); +// + + static Tizen::Base::ByteBuffer* + EncodeToBufferLimitN(const Tizen::Base::ByteBuffer &srcBuf, const Tizen::Graphics::Dimension& dim, + MediaPixelFormat pixelFormat, ImageFormat imgFormat, int limit); + + static Tizen::Base::ByteBuffer* + EncodeToBufferQualityN(const Tizen::Base::ByteBuffer &srcBuf, + const Tizen::Graphics::Dimension& dim, + MediaPixelFormat pixelFormat, ImageFormat imgFormat, int quality); + +public: + static _ImageImpl* GetInstance(Image* pImage); + static const _ImageImpl* GetInstance(const Image* pImage); + +private: +// +// static Tizen::Base::ByteBuffer* DecodeToBufferN(const Tizen::Base::String& srcImagePath, +// Tizen::Graphics::BitmapPixelFormat pixelFormat, +// Tizen::Graphics::Dimension& destDim); +// +// +// static int GetFilesizeWithLowestQuality(_ImageEncoder &enc, Tizen::Base::ByteBuffer& pOutBuf, +// Tizen::Graphics::Dimension& destDim); +// + + _ImageImpl(const _ImageImpl& impl); + _ImageImpl& operator =(const _ImageImpl& impl); + +}; // class _ImageImpl + +}; +}; + +#endif diff --git a/src/inc/FMedia_ImageUtilImpl.h b/src/inc/FMedia_ImageUtilImpl.h new file mode 100644 index 0000000..b6135b0 --- /dev/null +++ b/src/inc/FMedia_ImageUtilImpl.h @@ -0,0 +1,85 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMediaImageUtilImpl.h + * @brief This is the header file for the _ImageUtilImpl. + */ + +#ifndef _FMEDIA_INTERNAL_IMAGEUTIL_IMPL_H_ +#define _FMEDIA_INTERNAL_IMAGEUTIL_IMPL_H_ + +namespace Tizen { namespace Media +{ + +class _OSP_EXPORT_ _ImageUtilImpl + : public Tizen::Base::Object +{ +public: + static result ConvertPixelFormat(const Tizen::Base::ByteBuffer& srcBuf, + Tizen::Base::ByteBuffer& destBuf, + MediaPixelFormat srcPixelFormat, MediaPixelFormat destPixelFormat, + const Tizen::Graphics::Dimension& dim); + + static result Resize(const Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& destBuf, + const Tizen::Graphics::Dimension& srcDim, + const Tizen::Graphics::Dimension& destDim, + MediaPixelFormat pixelFormat); + + static result Rotate(const Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& destBuf, + const Tizen::Graphics::Dimension& dim, ImageRotationType rotate, + MediaPixelFormat pixelFormat); + + static result Flip(const Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& destBuf, + const Tizen::Graphics::Dimension& dim, ImageFlipType flip, + MediaPixelFormat pixelFormat); + +public: + static Tizen::Media::ImageFormat GetImageFormat(const Tizen::Base::String& srcImageFile); + + static Tizen::Media::ImageFormat GetImageFormat(const Tizen::Base::ByteBuffer& srcImageBuf); + + static bool HasAlphaChannel(const Tizen::Base::String& srcImageFile); + + static bool HasAlphaChannel(const Tizen::Base::ByteBuffer& srcImageBuf); + + + static int MinImageFormatLength(void); + + static Tizen::Base::ByteBuffer* ResizeN(const Tizen::Base::ByteBuffer &srcBuf, + const Tizen::Graphics::Dimension& srcDim, + MediaPixelFormat pixelFormat, + const Tizen::Graphics::Dimension& dstDim); + + static MediaPixelFormat ToMediaPixelFormat(Tizen::Graphics::BitmapPixelFormat bitmapFormat); + + static int GetBufferSize(const Tizen::Graphics::Dimension& dim, MediaPixelFormat pixelFormat); + + static bool IsValidDimension(MediaPixelFormat pixelFormat, const Tizen::Graphics::Dimension& dim); + + static Tizen::Base::String ToString(ImageFormat imgFormat); + +protected: + +private: + +}; + +}; +}; + +#endif -- 2.7.4