diff options
author | jk7744.park <jk7744.park@samsung.com> | 2015-10-24 16:24:13 +0900 |
---|---|---|
committer | jk7744.park <jk7744.park@samsung.com> | 2015-10-24 16:24:13 +0900 |
commit | c2208a1561c762051e749869ff8fb419c21e6b07 (patch) | |
tree | 2c750b438cc2b45684c3923b64ad720d4dd5fa84 | |
parent | d3f1fc6f3c48c7e3cd156148f287cc5fb679006a (diff) | |
download | mediavision-c2208a1561c762051e749869ff8fb419c21e6b07.tar.gz mediavision-c2208a1561c762051e749869ff8fb419c21e6b07.tar.bz2 mediavision-c2208a1561c762051e749869ff8fb419c21e6b07.zip |
tizen 2.4 releasetizen_2.4_mobile_releasesubmit/tizen_2.4/20151028.063614accepted/tizen/2.4/mobile/20151029.034644accepted/tizen_2.4_mobile
55 files changed, 9053 insertions, 0 deletions
@@ -0,0 +1,8 @@ +ByungWook Jang <bw.jang at samsung dot com> +Tae-Young Chung <ty83.chung at samsung dot com> +Oleg Kopysov <o.kopysov at samsung dot com> +Ievgen Vagin <i.vagin at samsung dot com> +Anton Artyukh <a.artyukh at samsung dot com> +Yaroslav Zatsikha <y.zatsikha at samsung dot com> +Sergii Rudenko <s.rudenko at samsung dot com> +SeokHoon Lee <andy.shlee at samsung dot com> diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..07c5432 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,135 @@ + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(fw_name "capi-media-vision") + +PROJECT(${fw_name}) + +SET(CMAKE_INSTALL_PREFIX /usr) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +# Configure for porting layer: +option(MEDIA_VISION_BARCODE_DETECTOR_LICENSE_PORT + "Turn on building of licensed port of the barcode detecting module (if OFF - open port will be built)." OFF) +option(MEDIA_VISION_BARCODE_GENERATOR_LICENSE_PORT + "Turn on building of licensed port of the barcode generating module (if OFF - open port will be built)." OFF) +set(MV_COMMON_LIB_NAME "mv_common") +set(MV_BARCODE_DETECTOR_LIB_NAME "mv_barcode_detector" CACHE STRING + "Name of the library will be built for barcode detecting module (without extension).") +set(MV_BARCODE_GENERATOR_LIB_NAME "mv_barcode_generator" CACHE STRING + "Name of the library will be built for barcode generating module (without extension).") + +SET(INC_DIR "${PROJECT_SOURCE_DIR}/include") +SET(INC_COMMON "${PROJECT_SOURCE_DIR}/mv_common/include") + +if(MEDIA_VISION_BARCODE_DETECTOR_LICENSE_PORT) + add_definitions(-DMEDIA_VISION_BARCODE_DETECTOR_LICENSE_PORT) + SET(INC_BARCODE_DETECTOR "${PROJECT_SOURCE_DIR}/mv_barcode/barcode_detector_lic/include") +else() + SET(INC_BARCODE_DETECTOR "${PROJECT_SOURCE_DIR}/mv_barcode/barcode_detector/include") +endif() + +if(MEDIA_VISION_BARCODE_GENERATOR_LICENSE_PORT) + add_definitions(-DMEDIA_VISION_BARCODE_GENERATOR_LICENSE_PORT) + SET(INC_BARCODE_GENERATOR "${PROJECT_SOURCE_DIR}/mv_barcode/barcode_generator_lic/include") +else() + SET(INC_BARCODE_GENERATOR "${PROJECT_SOURCE_DIR}/mv_barcode/barcode_generator/include") +endif() + +INCLUDE_DIRECTORIES(${INC_DIR} ${INC_COMMON} ${INC_BARCODE_DETECTOR} ${INC_BARCODE_GENERATOR}) + +SET(dependents "dlog capi-media-tool capi-system-info") +SET(pc_dependents "dlog") + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_name} REQUIRED ${dependents}) +FOREACH(flag ${${fw_name}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") + SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "-I./include -I./include/headers ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -w") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +SET(CMAKE_CXX_FLAGS "-I./include -I./include/headers ${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS} -fPIC") +SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g --w") + +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DTIZEN_DEBUG") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib") + +ADD_SUBDIRECTORY(mv_common) +ADD_SUBDIRECTORY(mv_barcode) + +aux_source_directory(src SOURCES) +ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) + +TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS} + ${MV_COMMON_LIB_NAME} + ${MV_BARCODE_DETECTOR_LIB_NAME} + ${MV_BARCODE_GENERATOR_LIB_NAME}) + +SET_TARGET_PROPERTIES(${fw_name} + PROPERTIES + VERSION ${FULLVER} + SOVERSION ${MAJORVER} + CLEAN_DIRECT_OUTPUT 1 +) + +INSTALL(TARGETS ${fw_name} DESTINATION lib) +INSTALL( + DIRECTORY ${INC_DIR}/ DESTINATION include/media + FILES_MATCHING + PATTERN "*_private.h" EXCLUDE + PATTERN "*.h" + ) + +SET(PC_NAME ${fw_name}) +SET(PC_REQUIRED ${pc_dependents}) +SET(PC_LDFLAGS -l${fw_name}) +SET(PC_CFLAGS -I\${includedir}/media) + +CONFIGURE_FILE( + ${fw_name}.pc.in + ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc + @ONLY +) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig) + +ADD_SUBDIRECTORY(test) + +IF(UNIX) + +ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution) +ADD_CUSTOM_COMMAND( + DEPENDS clean + COMMENT "distribution clean" + COMMAND find + ARGS . + -not -name config.cmake -and \( + -name tester.c -or + -name Testing -or + -name CMakeFiles -or + -name cmake.depends -or + -name cmake.check_depends -or + -name CMakeCache.txt -or + -name cmake.check_cache -or + -name *.cmake -or + -name Makefile -or + -name core -or + -name core.* -or + -name gmon.out -or + -name install_manifest.txt -or + -name *.pc -or + -name *~ \) + | grep -v TC | xargs rm -rf + TARGET distclean + VERBATIM +) + +ENDIF(UNIX) + diff --git a/LICENSE.APLv2 b/LICENSE.APLv2 new file mode 100644 index 0000000..54b213e --- /dev/null +++ b/LICENSE.APLv2 @@ -0,0 +1,204 @@ +Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved. + + 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. + @@ -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. @@ -0,0 +1,196 @@ +CONTENT + +1. GENERAL DESCRIPTION OF THE MEDIA VISION PACKAGE +2. USAGE OF PORTING LAYER FOR CHANGING MEDIA VISION ENGINE MODULES +3. OPEN PORT REQUIRED PACKAGES +4. TEST SUITE + + + + +1. GENERAL DESCRIPTION OF THE MEDIA VISION PACKAGE + +Currently Media Vision package includes three modules: Common, Barcode +detector and Barcode generator. Common module provides two handles (mv_source_h +and mv_engine_config_h) and related fuctionality. It used by barcode detector +and generator modules. mv_source_h is used for wrapping raw image data buffers. +mv_engine_config_h is optional. It can be used for fine tuning of internal +libraries which are used by API. mv_engine_config_h handle usually can be used +by barcode detector and/or generator modules (these modules provide +mv_barcode_detector and mv_barcode_generator internal libraries) in the case +when Native API doesn't cover all features supported by internal libraries. +Using NULL instead of real mv_engine_h handle as functions parameter has to be +taken into account. In most cases API user prefer to ignore detailed +configuration of the modules. + +Barcode detector module API provides tools to analyze the image buffers using +mv_barcode_detect() function. This analysis strives to detect barcodes at the +image, determine the type and extract the message. Results can be processed +using mv_barcode_detected_cb callback. + +Barcode generator module API provides tools to generate image buffer (or image +file) with barcode. Barcodes generation can be configured by type, message, +size, encoding mode, ECC (error correction level), version (three last setting +are allowed only for QR Codes). One of two functions can be used: +mv_barcode_generate_source() to generate the mv_source_h handle and +mv_barcode_generate_image() to generate the file with barcode image. + + + +2. USAGE OF PORTING LAYER FOR CHANGING MEDIA VISION ENGINE MODULES + +By default open source engine libraries are used to provide modules +functionality. But it is possible to substitute them by licensed or other custom +libraries. To enable building of custom library for the Media Vision package, +follow these steps: + +a. Find CMakeLists.txt in the root of the package directory and change + MEDIA_VISION_BARCODE_DETECTOR_LICENSE_PORT (for enabling build of a custom + barcode detector library) and/or + MEDIA_VISION_BARCODE_GENERATOR_LICENSE_PORT (for enabling build of a custom + barcode generator library) options to ON. Example: + + # only barcode detector module will be customized + option(MEDIA_VISION_BARCODE_DETECTOR_LICENSE_PORT "..." ON) + # barcode generator module will be default + option(MEDIA_VISION_BARCODE_GENERATOR_LICENSE_PORT "..." OFF) + +b. Options change will cause CMake to build from different subdirectories of + mv_barcode directory. mv_barcode/barcode_detector and + mv_barcode/barcode_generator subdirectories are used by default. + mv_barcode/barcode_detector_lic and mv_barcode/mv_barcode_generator_lic + subdirectories will be used during build if the corresponding option is ON. + Last two subdirectories already include base structure of the porting layer + projects, and files will be used by main capi-media-vision library. Use this + files to call functions from custom libraries. For example, you can change + mv_barcode_detect_lic.c file in such a way: + + #include "mv_barcode_detect_lic.h" + #include "custom_library_header.h" + + int mv_barcode_detect_lic( + mv_source_h source, + mv_engine_config_h engine_cfg, + mv_rectangle_s roi, + mv_barcode_detected_cb detect_cb, + void *user_data) + { + mv_quadrangle_s *locations = NULL; + const char *messages = NULL; + mv_barcode_type_e *types = NULL; + + // Here the call of the custom barcode detection function from + // custom_library_header.h: + int barcodes_number = custom_library_function( + source, roi, &locations, &messages, &types); + + if (barcodes_number > 0) + { + detect_cb( + source, engine_cfg, locations, messages, types, barcodes_number, + user_data); + delete[] locations; + delete[] messages; + delete[] types; + } + + return MEDIA_VISION_ERROR_NONE; + } + +c. Change the packaging/capi-media-vision.spec to support any packages required + to be found into the system for success build of the custom libraries + (mv_barcode_detector and/or mv_barcode_generator). You also can remove + requirements on open packages that are required by disabled barcode + generator/detector ports. See list of the dependencies in the section 3 of + this README file. + +d. Modify mv_barcode/barcode_{detector/generator}_lic/CMakeLists.txt file for + linking required libraries and/or including additional headers. Don't modify + the project name or reset ${MV_BARCODE_DETECTOR_LIB_NAME} variable, because + porting layer use these ones during the build. If it is required to change + projects/libraries names, best solution is to change + MV_BARCODE_DETECTOR_LIB_NAME and/or MV_BARCODE_GENERATOR_LIB_NAME options in + the CMakeLists.txt file that is located in the root of the package sources. + +e. If custom libraries support mv_engine_config_h handle attributes, then + default values of these attributes has to be specified into + media-vision-config.json file. This file can be found into the root directory + of the sources. For each attribute three parameters has to be specified: + attribute name, attribute value type and attribute value. For example, + in the following example four attributes are specified: + + { + "attributes": + [ + { "name" : "custom_detect_threshold", + "type" : "double", + "value" : 0.82, + }, + { "name" : "custom_detect_cascades_num", + "type" : "integer", + "value" : 50, + }, + { "name" : "custom_detect_use_haar", + "type" : "boolean", + "value" : true, + }, + { "name" : "custom_detect_haar_file_name", + "type" : "string", + "value" : "/usr/share/capi-media-vision/custom_haar.xml", + }, + ] + } + + In above example for each newly created mv_engine_config_h handle four + attributes will be automatically added. These values can be accessed + into the custom modules using Media Vision Common library interface + functions: + mv_engine_config_get_double_attribute(), + mv_engine_config_get_int_attribute(), + mv_engine_config_get_bool_attribute(), + mv_engine_config_get_string_attribute(). + For example, following code can be used to get value of the + "custom_detect_threshold" attribute: + + mv_engine_conf_h engine_cfg = NULL; + // When configuration is creating, default attributes from + // media-vision-config.json file will be set: + int err = mv_create_engine_config(&engine_cfg); + if (MEDIA_VISION_ERROR_NONE == err) + { + double attribute_value = 0.0; + err = mv_engine_config_get_double_attribute( + engine_cfg, "custom_detect_threshold", &attribute_value); + + if (MEDIA_VISION_ERROR_NONE == err) + { + // now attribute_value = 0.82 ("value" : 0.82 in json configuration) + } + } + + + +3. OPEN PORT REQUIRED PACKAGES + +Building default barcode detector and generator libraries requires following +dependencies: + +Barcode detector: zbar +Barcode generator: zint + +You can remove BuildRequires sections for these libraries from +packaging/capi-media-vision.spec file if corresponding module/modules is/are +disabled with options mentioned in 2.a. + + + +4. TEST SUITE + +capi-media-vision package includes test suite that allows to check API +functionality. The test suite application provides console interface that allows +to select options for barcode generation and detection. +Generation feature allows to generate barcodes images configured according to +the specified settings (type, message, size, encoding mode, ECC (error +correction level), version). Detection feature detects barcodes at the input +image files, decodes messages and generates output file (in jpeg format) where +locations of detected bercodes can be checked. diff --git a/capi-media-vision.manifest b/capi-media-vision.manifest new file mode 100644 index 0000000..86dbb26 --- /dev/null +++ b/capi-media-vision.manifest @@ -0,0 +1,5 @@ +<manifest> + <request> + <domain name="_" /> + </request> +</manifest> diff --git a/capi-media-vision.pc.in b/capi-media-vision.pc.in new file mode 100644 index 0000000..1d238ec --- /dev/null +++ b/capi-media-vision.pc.in @@ -0,0 +1,14 @@ + +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=/usr +libdir=/usr/lib +includedir=/usr/include/media + +Name: @PC_NAME@ +Description: @PACKAGE_DESCRIPTION@ +Version: @VERSION@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} @PC_LDFLAGS@ +Cflags: -I${includedir} diff --git a/doc/mediavision_doc.h b/doc/mediavision_doc.h new file mode 100644 index 0000000..810376d --- /dev/null +++ b/doc/mediavision_doc.h @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __TIZEN_MEDIAVISION_DOC_H__ +#define __TIZEN_MEDIAVISION_DOC_H__ + +/** + * @ingroup CAPI_MEDIA_FRAMEWORK + * @defgroup CAPI_MEDIA_VISION_MODULE Media Vision + * @brief Media Vision library provides functionality for barcodes detection and + * generation. + * @section CAPI_MEDIA_VISION_MODULE_HEADER Required Header + * \#include <mv_barcode.h> + * + * @defgroup CAPI_MEDIA_VISION_COMMON_MODULE Media Vision Common + * @ingroup CAPI_MEDIA_VISION_MODULE + * @brief Common functions, structures and enumerations used in + * @ref CAPI_MEDIA_VISION_BARCODE_MODULE submodule. + * @section CAPI_MEDIA_VISION_COMMON_MODULE_HEADER Required Header + * \#include <mv_common.h> + * + * @section CAPI_MEDIA_VISION_COMMON_MODULE_OVERVIEW Overview + * @ref CAPI_MEDIA_VISION_COMMON_MODULE provides a set of functions that + * are used in Media Vision API to correctly prepare and use included modules. + * @ref mv_source_h is the handler that has to be created to keep information + * on image or video frame data as row buffer. It can be created based on + * the media data stored in memory or using the @ref media_packet_h handler. + * @ref mv_source_h supported by the set of getters which allow to retrieve + * such image parameters as its size or colorspace (see @ref mv_colorspace_e + * enumeration). The handler is usually used as parameter for functions + * performing computer vision tasks on the image data.\n + * @ref mv_engine_config_h is the handler which provides dictionary + * functionality. It means that it is possible to set (key, value) pairs to + * the @ref mv_engine_config_h handlers and use them to transfer these values + * to the engine part underlying Media Vision API. Information on which + * attributes can be set is provided together with particular engines. + + * @section CAPI_MEDIA_VISION_COMMON_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/vision.barcode_detection\n + * - http://tizen.org/feature/vision.barcode_generation\n + * + * It is recommended to design feature related codes in your application for + * reliability.\n + * You can check if a device supports the related features for this API by using + * @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of + * your application.\n + * To ensure your application is only running on the device with specific + * features, please define the features in your manifest file using the manifest + * editor in the SDK.\n + * More details on featuring your application can be found from + * <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"> + * <b>Feature Element</b>. + * </a> + + * @defgroup CAPI_MEDIA_VISION_BARCODE_MODULE Media Vision BarCode + * @ingroup CAPI_MEDIA_VISION_MODULE + * @brief Barcode module consists of barcode detection and barcode generation + * submodules. + * @section CAPI_MEDIA_VISION_BARCODE_MODULE_HEADER Required Header + * \#include <mv_barcode.h> + * + * @section CAPI_MEDIA_VISION_BARCODE_MODULE_OVERVIEW Overview + * + * @section CAPI_MEDIA_VISION_BARCODE_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/vision.barcode_detection\n + * - http://tizen.org/feature/vision.barcode_generation\n + * + * It is recommended to design feature related codes in your application for + * reliability.\n + * You can check if a device supports the related features for this API by using + * @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of + * your application.\n + * To ensure your application is only running on the device with specific + * features, please define the features in your manifest file using the manifest + * editor in the SDK.\n + * More details on featuring your application can be found from + * <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"> + * <b>Feature Element</b>. + * </a> + * + * @ref CAPI_MEDIA_VISION_BARCODE_MODULE contains two submodules:\n + * * Detection submodule, + * * Generation submodule.\n + * + * Detection submodule can be used for detecting barcodes on image sources, + * reading encoded messages, getting barcode types.\n + * This module contains + * @ref mv_barcode_detect() function and @ref mv_barcode_detected_cb + * callback. @ref mv_barcode_detect() function can be called for the image + * determined by @ref mv_source_h handler to detect barcodes. If barcodes + * were detected, then @ref mv_barcode_detected_cb callback is called. + * Each detected barcode type, message and location can be processed by + * this callback. @ref mv_barcode_detect() supports ROI (rectangular region of + * interest) specification to allow barcode detection only for the region on + * the image. + * + * Generation submodule can be used for generating the barcodes and QR codes. + * Different encoding types (see @ref mv_barcode_qr_mode_e), error correction + * codes (see @ref mv_barcode_qr_ecc_e) and code versions are supported for + * QRCodes.\nThis submodule contains @ref mv_barcode_generate_source() function + * to generate handler to the buffer with row image of barcode, and + * @ref mv_barcode_generate_image() function to generate image file with + * barcode. Both functions support the set of parameters which allow API user to + * configure output barcode. QR codes as well as Barcodes are supported + * (see @ref mv_barcode_type_e enumeration for full list of supported barcodes). + * For QR codes it is possible to specify error correction code and encoding + * mode (see @ref mv_barcode_qr_mode_e). Generation to file supports several + * formats (see @ref mv_barcode_image_format_e). + */ + +#endif /* __TIZEN_MEDIAVISION_DOC_H__ */ diff --git a/include/mv_barcode.h b/include/mv_barcode.h new file mode 100644 index 0000000..00ec447 --- /dev/null +++ b/include/mv_barcode.h @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __TIZEN_MEDIAVISION_BARCODE_H__ +#define __TIZEN_MEDIAVISION_BARCODE_H__ + +#include <mv_common.h> +#include <mv_barcode_detect.h> +#include <mv_barcode_generate.h> + +/** + * @file mv_barcode.h + * @brief Representative Media Vision Barcode API header file that includes + * Media Vision Barcode detection and generation functionalities. + */ + +#endif /* __TIZEN_MEDIAVISION_BARCODE_H__ */ diff --git a/include/mv_barcode_detect.h b/include/mv_barcode_detect.h new file mode 100644 index 0000000..28d4d31 --- /dev/null +++ b/include/mv_barcode_detect.h @@ -0,0 +1,126 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __TIZEN_MEDIAVISION_BARCODE_DETECT_H__ +#define __TIZEN_MEDIAVISION_BARCODE_DETECT_H__ + +#include <mv_common.h> +#include <mv_barcode_type.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file mv_barcode_detect.h + * @brief This file contains the Media Vision barcode detect API. + */ + +/** + * @addtogroup CAPI_MEDIA_VISION_BARCODE_MODULE + * @{ + */ + +/** + * @brief Define MV_BARCODE_DETECT_ATTR_TARGET to set target attribute of the engine configuration + * + * @since_tizen 2.4 + * + * @see mv_barcode_detect_attr_target_e + */ +#define MV_BARCODE_DETECT_ATTR_TARGET "MV_BARCODE_DETECT_ATTR_TARGET" /**< Target: 0-all, 1-1D, 2-2D*/ + +/** + * @brief Enumeration to target attribute + * + * @since_tizen 2.4 + */ +typedef enum { + MV_BARCODE_DETECT_ATTR_TARGET_ALL, /**< 1D and 2D */ + MV_BARCODE_DETECT_ATTR_TARGET_1D_BARCODE, /**< 1D barcode only */ + MV_BARCODE_DETECT_ATTR_TARGET_2D_BARCODE, /**< 2D barcode only */ +} mv_barcode_detect_attr_target_e; + + +/** + * @brief Called when barcode detection is completed. + * @details If no barcode is detected then the method will be called, barcodes + * and states will be equal to NULL, and @a number_of_barcodes - 0. + * + * @since_tizen 2.4 + * @param [in] source The handle to the media source + * @param [in] engine_cfg The handle to the configuration of the engine + * @param [in] barcode_locations The quadrangle locations of detected barcodes + * @param [in] messages The decoded messages of barcodes + * @param [in] types The types of detected barcodes + * @param [in] number_of_barcodes The number of detected barcodes + * @param [in] user_data The user data passed from + * the mv_barcode_detect() function + * + * @pre mv_barcode_detect() invokes this callback + * + * @see mv_barcode_detect() + */ +typedef void(*mv_barcode_detected_cb)( + mv_source_h source, + mv_engine_config_h engine_cfg, + const mv_quadrangle_s *barcode_locations, + const char *messages[], + const mv_barcode_type_e *types, + int number_of_barcodes, + void *user_data); + +/** + * @brief Detects barcode(s) on source and reads message from it. + * + * @since_tizen 2.4 + * @param [in] source The media source handle + * @param [in] engine_cfg The handle to the configuration of the engine + * @param [in] roi Region of interest - rectangular area on the + * @a source which will be used for barcode detection + * Note that @a roi should be inside area on the + * @a source. + * @param [in] detect_cb The callback for result handling + * @param [in] user_data The user data to be passed to the callback function + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT Not supported format + * @retval #MEDIA_VISION_ERROR_INTERNAL Internal error + * + * @pre Create a source handle by calling @ref mv_create_source() + * @pre Create an engine configuration handle by calling + * @ref mv_create_engine_config(), otherwise use NULL + * + * @see mv_barcode_detected_cb() + */ +int mv_barcode_detect( + mv_source_h source, + mv_engine_config_h engine_cfg, + mv_rectangle_s roi, + mv_barcode_detected_cb detect_cb, + void *user_data); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __TIZEN_MEDIAVISION_BARCODE_DETECT_H__ */ diff --git a/include/mv_barcode_generate.h b/include/mv_barcode_generate.h new file mode 100644 index 0000000..cbd4c1f --- /dev/null +++ b/include/mv_barcode_generate.h @@ -0,0 +1,177 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __TIZEN_MEDIAVISION_BARCODE_GENERATE_H__ +#define __TIZEN_MEDIAVISION_BARCODE_GENERATE_H__ + +#include <mv_common.h> +#include <mv_barcode_type.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file mv_barcode_generate.h + * @brief This file contains the Media Vision barcode generate API. + */ + +/** + * @addtogroup CAPI_MEDIA_VISION_BARCODE_MODULE + * @{ + */ + +/** + * @brief Define MV_BARCODE_GENERATE_ATTR_TEXT to set text attribute + of the engine configuration + * + * @since_tizen 2.4 + * @remarks This attribute is only available for 1D barcode generation + * + * @see mv_barcode_generate_attr_text_e + */ +#define MV_BARCODE_GENERATE_ATTR_TEXT "MV_BARCODE_GENERATE_ATTR_TEXT" /**< Text: + 0-invisible, + 1-visible */ + +/** + * @brief Enumeration to text attribute + * + * @since_tizen 2.4 + */ +typedef enum { + MV_BARCODE_GENERATE_ATTR_TEXT_INVISIBLE, /**< Invisible */ + MV_BARCODE_GENERATE_ATTR_TEXT_VISIBLE, /**< Visible */ +} mv_barcode_generate_attr_text_e; + + +/** + * @brief Generates @ref mv_source_h with barcode image. + * @details Pay attention that for EAN-8 and EAN-13 barcode types the barcode + * type may be selected automatically and this selection depends on the input + * message length. Also for QR codes the version may be selected as minimum + * required to generate QR code with the input message length. + * + * @since_tizen 2.4 + * @remarks If the text attribute of engine configuration is set to + * MV_BARCODE_GENERATE_ATTR_TEXT_VISIBLE, + * MEDIA_VISION_ERROR_INVALID_OPERATION will be return + * when @a type is MV_BARCODE_QR + * + * @param [in] engine_cfg The handle to the configuration of the engine + * @param [in] message The message to be encoded in the barcode + * @param [in] type Type of the barcode to be generated + * @param [in] qr_enc_mode Encoding mode for the message (only for QR codes; + * for 1D barcodes set this parameter to + * @a MV_BARCODE_QR_MODE_UNAVAILABLE) + * @param [in] qr_ecc Error correction level (only for QR codes; for + * 1D barcodes set this parameter to + * @a MV_BARCODE_QR_ECC_UNAVAILABLE) + * @param [in] qr_version QR code version (for 1D barcodes set this + * parameter to 0) + * @param [in, out] image The media source handle which will be used to + * fill by the buffer with generated image + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_MSG_TOO_LONG Too long or short message + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * @retval #MEDIA_VISION_ERROR_INVALID_DATA Invalid data + * @retval #MEDIA_VISION_ERROR_INTERNAL Internal error + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * + * @pre Create an engine configuration handle by calling + * @ref mv_create_engine_config(), otherwise use NULL + * + * @see mv_barcode_generate_image() + */ +int mv_barcode_generate_source( + mv_engine_config_h engine_cfg, + const char *message, + mv_barcode_type_e type, + mv_barcode_qr_mode_e qr_enc_mode, + mv_barcode_qr_ecc_e qr_ecc, + int qr_version, + mv_source_h image); + +/** + * @brief Generates image file with barcode. + * @details Pay attention that for EAN-8 and EAN-13 barcode types the barcode + * type may be selected automatically and this selection depends on the input + * message length. Also for QR codes the version may be selected as minimum + * required to generate QR code with the input message length. + * + * @since_tizen 2.4 + * @remarks If the text attribute of engine configuration is set to + * MV_BARCODE_GENERATE_ATTR_TEXT_VISIBLE, + * MEDIA_VISION_ERROR_INVALID_OPERATION will be return + * when @a type is MV_BARCODE_QR + * + * @remarks The mediastorage privilege http://tizen.org/privilege/mediastorage is needed \n + if @a image_path is relevant to media storage.\n + The externalstorage privilege http://tizen.org/privilege/externalstorage is needed \n + if @a image_path is relevant to external storage. + * @param [in] engine_cfg The handle to the configuration of the engine + * @param [in] message The message to be encoded in the barcode + * @param [in] image_width The width of the generated image + * @param [in] image_height The height of the generated image + * @param [in] type Type of the barcode to be generated + * @param [in] qr_enc_mode Encoding mode for the message (only for QR codes; + * for 1D barcodes set this parameter to + * @a MV_BARCODE_QR_MODE_UNAVAILABLE) + * @param [in] qr_ecc Error correction level (only for QR codes; for + * 1D barcodes set this parameter to + * @a MV_BARCODE_QR_ECC_UNAVAILABLE) + * @param [in] qr_version QR code version (for 1D barcodes set this + * parameter to 0) + * @param [in] image_path The path to the file that has to be generated + * @param [in] image_format The format of the output image + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_MSG_TOO_LONG Too long or short message + * @retval #MEDIA_VISION_ERROR_PERMISSION_DENIED Permission denied + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * @retval #MEDIA_VISION_ERROR_INVALID_DATA Invalid data + * @retval #MEDIA_VISION_ERROR_INTERNAL Internal error + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * + * @pre Create an engine configuration handle by calling + * @ref mv_create_engine_config(), otherwise use NULL + * + * @see mv_barcode_generate_source() + */ +int mv_barcode_generate_image( + mv_engine_config_h engine_cfg, + const char *message, + int image_width, + int image_height, + mv_barcode_type_e type, + mv_barcode_qr_mode_e qr_enc_mode, + mv_barcode_qr_ecc_e qr_ecc, + int qr_version, + const char *image_path, + mv_barcode_image_format_e image_format); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __TIZEN_MEDIAVISION_BARCODE_GENERATE_H__ */ diff --git a/include/mv_barcode_type.h b/include/mv_barcode_type.h new file mode 100644 index 0000000..4fe17a3 --- /dev/null +++ b/include/mv_barcode_type.h @@ -0,0 +1,103 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __TIZEN_MEDIAVISION_BARCODE_TYPE_H__ +#define __TIZEN_MEDIAVISION_BARCODE_TYPE_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file mv_barcode_type.h + * @brief This file contains enumerations required by barcode detect/generate API. + */ + +/** + * @addtogroup CAPI_MEDIA_VISION_BARCODE_MODULE + * @{ + */ + +/** + * @brief Enumeration for supported barcode types. + * @details QR codes (versions 1 to 40) and set of 1D barcodes are supported + * + * @since_tizen 2.4 + */ +typedef enum +{ + MV_BARCODE_QR, /**< 2D barcode - Quick Response code */ + MV_BARCODE_UPC_A, /**< 1D barcode - Universal Product Code with 12-digit */ + MV_BARCODE_UPC_E, /**< 1D barcode - Universal Product Code with 6-digit */ + MV_BARCODE_EAN_8, /**< 1D barcode - International Article Number with 8-digit */ + MV_BARCODE_EAN_13, /**< 1D barcode - International Article Number with 13-digit */ + MV_BARCODE_CODE128, /**< 1D barcode - Code 128 */ + MV_BARCODE_CODE39, /**< 1D barcode - Code 39 */ + MV_BARCODE_I2_5, /**< 1D barcode - Interleaved Two of Five */ + MV_BARCODE_UNDEFINED /**< Undefined */ +} +mv_barcode_type_e; + +/** + * @brief Enumeration for supported QR code error correction level. + * + * @since_tizen 2.4 + * @remarks This is unavailable for 1D barcodes + */ +typedef enum { + MV_BARCODE_QR_ECC_LOW, /**< Recovery up to 7% losses */ + MV_BARCODE_QR_ECC_MEDIUM, /**< Recovery up to 15% losses */ + MV_BARCODE_QR_ECC_QUARTILE, /**< Recovery up to 25% losses */ + MV_BARCODE_QR_ECC_HIGH, /**< Recovery up to 30% losses */ + MV_BARCODE_QR_ECC_UNAVAILABLE /**< Unavailable */ +} mv_barcode_qr_ecc_e; + +/** + * @brief Enumeration for supported QR code encoding mode. + * + * @since_tizen 2.4 + * @remarks This is unavailable for 1D barcodes + */ +typedef enum { + MV_BARCODE_QR_MODE_NUMERIC, /**< Numeric digits */ + MV_BARCODE_QR_MODE_ALPHANUMERIC, /**< Alphanumeric characters */ + MV_BARCODE_QR_MODE_BYTE, /**< Raw 8-bit bytes */ + MV_BARCODE_QR_MODE_UTF8, /**< UTF-8 character encoding */ + MV_BARCODE_QR_MODE_UNAVAILABLE /**< Unavailable */ +} mv_barcode_qr_mode_e; + +/** + * @brief Enumeration for supported image formats for the barcode generating. + * + * @since_tizen 2.4 + */ +typedef enum { + MV_BARCODE_IMAGE_FORMAT_UNAVAILABLE = -1, /** Unvailable image format */ + MV_BARCODE_IMAGE_FORMAT_BMP, /**< BMP image format */ + MV_BARCODE_IMAGE_FORMAT_JPG, /**< JPEG image format */ + MV_BARCODE_IMAGE_FORMAT_PNG, /**< PNG image format */ + MV_BARCODE_IMAGE_FORMAT_NUM, /**< The number of supported iamge format */ +} mv_barcode_image_format_e; + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __TIZEN_MEDIAVISION_BARCODE_TYPE_H__ */ diff --git a/include/mv_common.h b/include/mv_common.h new file mode 100644 index 0000000..98eedde --- /dev/null +++ b/include/mv_common.h @@ -0,0 +1,680 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __TIZEN_MEDIAVISION_COMMON_H__ +#define __TIZEN_MEDIAVISION_COMMON_H__ + +#include <media_packet.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file mv_common.h + * @brief This file contains the Media Vision Common API. + */ + +/** + * @addtogroup CAPI_MEDIA_VISION_COMMON_MODULE + * @{ + */ + +/** + * @brief Point in 2D space. + * + * @since_tizen 2.4 + */ +typedef struct { + int x; /**< X-axis coordinate of the point in 2D space */ + int y; /**< Y-axis coordinate of the point in 2D space */ +} mv_point_s; + +/** + * @brief Location of the object bounded by quadrangle defined by four 2D points. + * + * @since_tizen 2.4 + */ +typedef struct { + mv_point_s points[4]; /**< Four points that define object bounding + quadrangle */ +} mv_quadrangle_s; + +/** + * @brief Location of the object bounded by rectangle defined by + * coordinates of top left corner, width and height. + * + * @since_tizen 2.4 + */ +typedef struct { + mv_point_s point; /**< Top left corner of rectangle coordinates */ + int width; /**< Width of the bounding rectangle */ + int height; /**< Height of the bounding rectangle */ +} mv_rectangle_s; + +/** + * @brief Enumeration for Media Vision error. + * + * @since_tizen 2.4 + */ +typedef enum { + MEDIA_VISION_ERROR_NONE + = TIZEN_ERROR_NONE, /**< Successful */ + MEDIA_VISION_ERROR_NOT_SUPPORTED + = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */ + MEDIA_VISION_ERROR_MSG_TOO_LONG + = TIZEN_ERROR_MSG_TOO_LONG, /**< Msg too long */ + MEDIA_VISION_ERROR_NO_DATA + = TIZEN_ERROR_NO_DATA, /**< No data */ + MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE + = TIZEN_ERROR_KEY_NOT_AVAILABLE, /**< Key not available */ + MEDIA_VISION_ERROR_OUT_OF_MEMORY + = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + MEDIA_VISION_ERROR_INVALID_PARAMETER + = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + MEDIA_VISION_ERROR_INVALID_OPERATION + = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid operation */ + MEDIA_VISION_ERROR_PERMISSION_DENIED + = TIZEN_ERROR_NOT_PERMITTED, /**< Not permitted */ + MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT + = TIZEN_ERROR_MEDIA_VISION | 0x01, /**< Not supported format */ + MEDIA_VISION_ERROR_INTERNAL + = TIZEN_ERROR_MEDIA_VISION | 0x02, /**< Internal error */ + MEDIA_VISION_ERROR_INVALID_DATA + = TIZEN_ERROR_MEDIA_VISION | 0x03, /**< Invalid data */ +} mv_error_e; + +/** + * @brief Enumeration for Media Vision @ref mv_engine_config_h handle attribute + * type. + * + * @since_tizen 2.4 + */ +typedef enum { + MV_ENGINE_CONFIG_ATTR_TYPE_DOUBLE, /**< Double attribute type */ + MV_ENGINE_CONFIG_ATTR_TYPE_INTEGER, /**< Integer attribute type */ + MV_ENGINE_CONFIG_ATTR_TYPE_BOOLEAN, /**< Boolean attribute type */ + MV_ENGINE_CONFIG_ATTR_TYPE_STRING /**< String attribute type */ +} mv_config_attribute_type_e; + +/** + * @brief Enumeration for Media Vision colorspace. + * + * @since_tizen 2.4 + */ +typedef enum { + MEDIA_VISION_COLORSPACE_INVALID, /**< The colorspace type is invalid */ + MEDIA_VISION_COLORSPACE_Y800, /**< The colorspace type is Y800 */ + MEDIA_VISION_COLORSPACE_I420, /**< The colorspace type is I420 */ + MEDIA_VISION_COLORSPACE_NV12, /**< The colorspace type is NV12 */ + MEDIA_VISION_COLORSPACE_YV12, /**< The colorspace type is YV12 */ + MEDIA_VISION_COLORSPACE_NV21, /**< The colorspace type is NV21 */ + MEDIA_VISION_COLORSPACE_YUYV, /**< The colorspace type is YUYV */ + MEDIA_VISION_COLORSPACE_UYVY, /**< The colorspace type is UYVY */ + MEDIA_VISION_COLORSPACE_422P, /**< The colorspace type is 422P */ + MEDIA_VISION_COLORSPACE_RGB565, /**< The colorspace type is RGB565 */ + MEDIA_VISION_COLORSPACE_RGB888, /**< The colorspace type is RGB888 */ + MEDIA_VISION_COLORSPACE_RGBA, /**< The colorspace type is RGBA */ +} mv_colorspace_e; + +/** + * @brief The handle to the Media Vision API engine algorithms configuration. + * @details Configuration is a dictionary consists of key and value pairs to + * collect engine-specific settings and allow Media Vision module to + * access them internally. Engine configuration provides developer by + * the possibility to make computer vision algorithms work better + * in particular conditions of API usage. To create engine + * configuration handle @ref mv_create_engine_config() function has to + * be used. When configuration is not needed any more, it is required to + * destroy it and release resources by @ref mv_destroy_engine_config() + * function. + * + * @since_tizen 2.4 + * + * @see mv_create_engine_config() + * @see mv_destroy_engine_config() + */ +typedef void *mv_engine_config_h; + +/** + * @brief The handle to the source. + * + * @since_tizen 2.4 + */ +typedef void *mv_source_h; + +/** + * @brief Creates a source handle. + * + * @since_tizen 2.4 + * @remarks You must release @a source by using @ref mv_destroy_source(). + * @param [out] source A new handle to the source + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @see mv_destroy_source() + */ +int mv_create_source( + mv_source_h *source); + +/** + * @brief Destroys the source handle and releases all its resources. + * + * @since_tizen 2.4 + * @param [in] source The handle to the source to be destroyed + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @see mv_create_source() + */ +int mv_destroy_source( + mv_source_h source); + +/** + * @brief Fills the media source based on the media packet. + * + * @since_tizen 2.4 + * @param [in, out] source The handle to the source + * @param [in] media_packet The handle to the media packet from which + * will be filled the source + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT Not supported format + * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @pre Create a source handle by calling @ref mv_create_source() + * + * @see mv_create_source() + * @see mv_destroy_source() + */ +int mv_source_fill_by_media_packet( + mv_source_h source, + media_packet_h media_packet); + +/** + * @brief Fills the media source based on the buffer and metadata. + * + * @since_tizen 2.4 + * @param [in, out] source The handle to the source + * @param [in] data_buffer The buffer of image data + * @param [in] buffer_size The buffer size + * @param [in] image_width The width of image data + * @param [in] image_height The height of image data + * @param [in] image_colorspace The image colorspace + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @pre Create a source handle by calling @ref mv_create_source() + * + * @see mv_source_clear() + */ +int mv_source_fill_by_buffer( + mv_source_h source, + unsigned char *data_buffer, + unsigned int buffer_size, + unsigned int image_width, + unsigned int image_height, + mv_colorspace_e image_colorspace); + +/** + * @brief Clears the buffer of the media source. + * + * @since_tizen 2.4 + * @param [in, out] source The handle to the source + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @see mv_source_fill_by_buffer() + */ +int mv_source_clear( + mv_source_h source); + +/** + * @brief Gets buffer of the media source. + * + * @since_tizen 2.4 + * @remarks Note that the retrieved buffer will be destroyed when + * @ref mv_destroy_source() or @ref mv_source_clear() function + * is called for the @a source. + * + * @param [in] source The handle to the source + * @param [out] data_buffer The buffer of the source + * @param [out] buffer_size The size of buffer + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @see mv_source_get_width() + * @see mv_source_get_height() + * @see mv_source_get_colorspace() + */ +int mv_source_get_buffer( + mv_source_h source, + unsigned char **data_buffer, + unsigned int *buffer_size); + +/** + * @brief Gets height of the media source. + * + * @since_tizen 2.4 + * @param [in] source The handle to the source + * @param [out] image_height The height of an image in the source + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @see mv_source_get_width() + * @see mv_source_get_colorspace() + * @see mv_source_get_buffer() + */ +int mv_source_get_height( + mv_source_h source, + unsigned int *image_height); + +/** + * @brief Gets width of the media source. + * + * @since_tizen 2.4 + * @param [in] source The handle to the source + * @param [out] image_width The width of an image in the source + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @see mv_source_get_height() + * @see mv_source_get_colorspace() + * @see mv_source_get_buffer() + */ +int mv_source_get_width( + mv_source_h source, + unsigned int *image_width); + +/** + * @brief Gets colorspace of the media source. + * + * @since_tizen 2.4 + * @param [in] source The handle to the source + * @param [out] image_colorspace The colorspace of an image in the source + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @see mv_source_get_width() + * @see mv_source_get_height() + * @see mv_source_get_buffer() + */ +int mv_source_get_colorspace( + mv_source_h source, + mv_colorspace_e *image_colorspace); + +/** + * @brief Creates the handle to the configuration of engine. + * + * @since_tizen 2.4 + * @remarks Available engine configuration attributes can be get by using + * @ref mv_engine_config_foreach_supported_attribute(). + * The attributes can be changed by @ref mv_engine_config_h + * related setters. Default values are used if the attributes + * are not changed. + * @param [out] engine_cfg The handle to the engine to be created + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @see mv_engine_config_h + * @see mv_destroy_engine_config() + * @see mv_engine_config_set_double_attribute() + * @see mv_engine_config_set_int_attribute() + * @see mv_engine_config_set_bool_attribute() + * @see mv_engine_config_set_string_attribute() + * @see mv_engine_config_get_double_attribute() + * @see mv_engine_config_get_int_attribute() + * @see mv_engine_config_get_bool_attribute() + * @see mv_engine_config_get_string_attribute() + */ +int mv_create_engine_config( + mv_engine_config_h *engine_cfg); + +/** + * @brief Destroys the engine configuration handle and releases all its + * resources. + * + * @since_tizen 2.4 + * @param [in] engine_cfg The handle to the engine configuration + * to be destroyed + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @see mv_engine_config_h + * @see mv_create_engine_config() + */ +int mv_destroy_engine_config( + mv_engine_config_h engine_cfg); + +/** + * @brief Sets the double attribute to the configuration. + * + * @since_tizen 2.4 + * @param [in] engine_cfg Engine configuration for which @a value has + * to be set + * @param [in] name String key of the attribute will be used for + * storing the @a value into configuration + * dictionary + * @param [in] value The double value of the attribute + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE Attribute key isn't available + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @see mv_engine_config_get_double_attribute() + * @see mv_engine_config_set_int_attribute() + * @see mv_engine_config_set_bool_attribute() + * @see mv_engine_config_set_string_attribute() + */ +int mv_engine_config_set_double_attribute( + mv_engine_config_h engine_cfg, + const char *name, + double value); + +/** + * @brief Sets the integer attribute to the configuration. + * + * @since_tizen 2.4 + * @param [in] engine_cfg Engine configuration for which @a value has + * to be set + * @param [in] name String key of the attribute will be used for + * storing the @a value into configuration + * dictionary + * @param [in] value The integer value of the attribute + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE Attribute key isn't available + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @see mv_engine_config_get_int_attribute() + * @see mv_engine_config_set_double_attribute() + * @see mv_engine_config_set_bool_attribute() + * @see mv_engine_config_set_string_attribute() + * @see mv_barcode_detect_attr_target_e + * @see mv_barcode_generate_attr_text_e + */ +int mv_engine_config_set_int_attribute( + mv_engine_config_h engine_cfg, + const char *name, + int value); + +/** + * @brief Sets the boolean attribute to the configuration. + * + * @since_tizen 2.4 + * @param [in] engine_cfg Engine configuration for which @a value has + * to be set + * @param [in] name String key of the attribute will be used for + * storing the @a value into configuration + * dictionary + * @param [in] value The boolean value of the attribute + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE Attribute key isn't available + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @see mv_engine_config_get_bool_attribute() + * @see mv_engine_config_set_double_attribute() + * @see mv_engine_config_set_int_attribute() + * @see mv_engine_config_set_string_attribute() + */ +int mv_engine_config_set_bool_attribute( + mv_engine_config_h engine_cfg, + const char *name, + bool value); + +/** + * @brief Sets the string attribute to the configuration. + * + * @since_tizen 2.4 + * @param [in] engine_cfg Engine configuration for which @a value has + * to be set + * @param [in] name String key of the attribute will be used for + * storing the @a value into configuration + * dictionary + * @param [in] value The string value of the attribute + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE Attribute key isn't available + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @see mv_engine_config_get_string_attribute() + * @see mv_engine_config_set_double_attribute() + * @see mv_engine_config_set_int_attribute() + * @see mv_engine_config_set_bool_attribute() + */ +int mv_engine_config_set_string_attribute( + mv_engine_config_h engine_cfg, + const char *name, + const char *value); + +/** + * @brief Gets the double attribute from the configuration dictionary. + * + * @since_tizen 2.4 + * @param [in] engine_cfg Engine configuration from which @a value + * has to be gotten. If NULL, default attribute + * value will be returned + * @param [in] name String key of the attribute will be used for + * getting the @a value from the + * configuration dictionary + * @param [out] value The attribute to be filled with double value + * from dictionary + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE Attribute key isn't available + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @see mv_engine_config_set_double_attribute() + * @see mv_engine_config_get_int_attribute() + * @see mv_engine_config_get_bool_attribute() + * @see mv_engine_config_get_string_attribute() + */ +int mv_engine_config_get_double_attribute( + mv_engine_config_h engine_cfg, + const char *name, + double *value); + +/** + * @brief Gets the integer attribute from the configuration dictionary. + * + * @since_tizen 2.4 + * @param [in] engine_cfg Engine configuration from which @a value + * has to be gotten. If NULL, default attribute + * value will be returned + * @param [in] name String key of the attribute will be used for + * getting the @a value from the + * configuration dictionary + * @param [out] value The attribute to be filled with integer value + * from dictionary + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE Attribute key isn't available + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @see mv_engine_config_set_int_attribute() + * @see mv_engine_config_get_double_attribute() + * @see mv_engine_config_get_bool_attribute() + * @see mv_engine_config_get_string_attribute() + * @see mv_barcode_detect_attr_target_e + * @see mv_barcode_generate_attr_text_e + */ +int mv_engine_config_get_int_attribute( + mv_engine_config_h engine_cfg, + const char *name, + int *value); + +/** + * @brief Gets the boolean attribute from the configuration dictionary. + * + * @since_tizen 2.4 + * @param [in] engine_cfg Engine configuration from which @a value + * has to be gotten. If NULL, default attribute + * value will be returned + * @param [in] name String key of the attribute will be used for + * getting the @a value from the + * configuration dictionary + * @param [out] value The attribute to be filled with boolean value + * from dictionary + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE Attribute key isn't available + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @see mv_engine_config_set_bool_attribute() + * @see mv_engine_config_get_double_attribute() + * @see mv_engine_config_get_int_attribute() + * @see mv_engine_config_get_string_attribute() + */ +int mv_engine_config_get_bool_attribute( + mv_engine_config_h engine_cfg, + const char *name, + bool *value); + +/** + * @brief Gets the string attribute from the configuration dictionary. + * + * @since_tizen 2.4 + * @remarks Function allocates memory required for output @a value, so + * it has to be removed by the user himself. + * @param [in] engine_cfg Engine configuration from which @a value + * has to be gotten. If NULL, default attribute + * value will be returned + * @param [in] name String key of the attribute will be used for + * getting the @a value from the + * configuration dictionary + * @param [out] value The attribute to be filled with string value + * from dictionary + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE Attribute key isn't available + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @see mv_engine_config_set_string_attribute() + * @see mv_engine_config_get_double_attribute() + * @see mv_engine_config_get_int_attribute() + * @see mv_engine_config_get_bool_attribute() + */ +int mv_engine_config_get_string_attribute( + mv_engine_config_h engine_cfg, + const char *name, + char **value); + +/** + * @brief Called to get information (type and name) once for each supported + * attribute. + * + * @since_tizen 2.4 + * @param [in] attribute_type The supported attribute type + * @param [in] attribute_name The supported attribute name + * @param [in] user_data The user data passed from the + * @ref mv_engine_config_foreach_supported_attribute() + * function + * @return @c true to continue with the next iteration of the loop, \n + * otherwise @c false to break out of the loop + * + * @pre mv_engine_config_foreach_supported_attribute() will invoke this callback + * @see mv_engine_config_foreach_supported_attribute() + */ +typedef bool(*mv_supported_attribute_cb)( + mv_config_attribute_type_e attribute_type, + const char *attribute_name, + void *user_data); + +/** + * @brief Traverses the list of supported attribute names and types. + * @details Using this function names of supported attributes can be obtained. + * Names of the attributes can be used with @ref mv_engine_config_h + * related getters and setters to get/set appropriate attribute values. + * + * @since_tizen 2.4 + * @remarks If @a callback is called zero times after + * @ref mv_engine_config_foreach_supported_attribute() call, then + * engine configuration is not supported and setting of attributes will + * cause no effect. In this case for all Media Vision functions which + * require @ref mv_engine_config_h handle as in parameter this + * parameter can be set NULL. + * @remarks If @a callback is called at least once, then attribute names and + * types obtained in the @ref mv_supported_attribute_cb callback can be + * changed after mv_engine_config_h handle creation (with + * @ref mv_create_engine_config() function) by corresponding setters. + * Although, if attributes aren't changed by setters, then default + * values will be used.\n + * Changing of attribute values will affect internal functionality + * provided by concrete library underlying Media Vision API. + * @param [in] callback The iteration callback function + * @param [in] user_data The user data to be passed to the callback function + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_NO_DATA Can't determine list of supported attributes + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * + * @see mv_engine_config_set_double_attribute() + * @see mv_engine_config_set_int_attribute() + * @see mv_engine_config_set_bool_attribute() + * @see mv_engine_config_set_string_attribute() + * @see mv_engine_config_get_double_attribute() + * @see mv_engine_config_get_int_attribute() + * @see mv_engine_config_get_bool_attribute() + * @see mv_engine_config_get_string_attribute() + */ +int mv_engine_config_foreach_supported_attribute( + mv_supported_attribute_cb callback, + void *user_data); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __TIZEN_MEDIAVISION_COMMON_H__ */ diff --git a/include/mv_private.h b/include/mv_private.h new file mode 100644 index 0000000..2bd4cbc --- /dev/null +++ b/include/mv_private.h @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved +* +* 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 __TIZEN_MEDIA_VISION_PRIVATE_H__ +#define __TIZEN_MEDIA_VISION_PRIVATE_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include <stdbool.h> +#include <dlog.h> + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "TIZEN_MEDIA_VISION" + +#define MEDIA_VISION_FUNCTION_ENTER() \ + LOGI("[%s] <ENTER>", __FUNCTION__) + +#define MEDIA_VISION_FUNCTION_LEAVE() \ + LOGI("[%s] <LEAVE>", __FUNCTION__) + +#define MEDIA_VISION_CHECK_CONDITION(condition, error, msg) \ + if(condition) {} else \ + { LOGE("[%s] %s(0x%08x)", __FUNCTION__, msg, error); return error;} + +#define MEDIA_VISION_INSTANCE_CHECK(arg) \ + MEDIA_VISION_CHECK_CONDITION(arg != NULL, \ + MEDIA_VISION_ERROR_INVALID_PARAMETER, \ + "MEDIA_VISION_ERROR_INVALID_PARAMETER") + +#define MEDIA_VISION_NULL_ARG_CHECK(arg) \ + MEDIA_VISION_CHECK_CONDITION(arg != NULL, \ + MEDIA_VISION_ERROR_INVALID_PARAMETER, \ + "MEDIA_VISION_ERROR_INVALID_PARAMETER") +#define MEDIA_VISION_SUPPORT_CHECK(arg) \ + MEDIA_VISION_CHECK_CONDITION(arg != false, MEDIA_VISION_ERROR_NOT_SUPPORTED, \ + "MEDIA_VISION_ERROR_NOT_SUPPORTED") + +bool __mv_barcode_check_system_info_feature_supported(); +bool __mv_barcode_detect_check_system_info_feature_supported(); +bool __mv_barcode_generate_check_system_info_feature_supported(); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __TIZEN_MEDIA_VISION_PRIVATE_H__ */ diff --git a/media-vision-config-example.json b/media-vision-config-example.json new file mode 100644 index 0000000..2de8fed --- /dev/null +++ b/media-vision-config-example.json @@ -0,0 +1,21 @@ +{ + "attributes": + [ + { "name" : "sample_double_attribute", + "type" : "double", + "value" : 0.82, + }, + { "name" : "sample_integer_attribute", + "type" : "integer", + "value" : 50, + }, + { "name" : "sample_boolean_attribute", + "type" : "boolean", + "value" : true, + }, + { "name" : "sample_string attribute", + "type" : "string", + "value" : "test string", + }, + ] +} diff --git a/media-vision-config.json b/media-vision-config.json new file mode 100644 index 0000000..6698e7b --- /dev/null +++ b/media-vision-config.json @@ -0,0 +1,13 @@ +{ + "attributes": + [ + { "name" : "MV_BARCODE_GENERATE_ATTR_TEXT", + "type" : "integer", + "value" : 0 + }, + { "name" : "MV_BARCODE_DETECT_ATTR_TARGET", + "type" : "integer", + "value" : 0 + } + ] +} diff --git a/mv_barcode/CMakeLists.txt b/mv_barcode/CMakeLists.txt new file mode 100644 index 0000000..88da8a9 --- /dev/null +++ b/mv_barcode/CMakeLists.txt @@ -0,0 +1,14 @@ +project(mv_barcode) +cmake_minimum_required(VERSION 2.6) + +if(MEDIA_VISION_BARCODE_DETECTOR_LICENSE_PORT) + add_subdirectory(${PROJECT_SOURCE_DIR}/barcode_detector_lic) # Licensed port +else() + add_subdirectory(${PROJECT_SOURCE_DIR}/barcode_detector) # Open port +endif() + +if(MEDIA_VISION_BARCODE_GENERATOR_LICENSE_PORT) + add_subdirectory(${PROJECT_SOURCE_DIR}/barcode_generator_lic) # Licened port +else() + add_subdirectory(${PROJECT_SOURCE_DIR}/barcode_generator) # Open port +endif() diff --git a/mv_barcode/barcode_detector/CMakeLists.txt b/mv_barcode/barcode_detector/CMakeLists.txt new file mode 100644 index 0000000..793910d --- /dev/null +++ b/mv_barcode/barcode_detector/CMakeLists.txt @@ -0,0 +1,29 @@ +project(${MV_BARCODE_DETECTOR_LIB_NAME}) +cmake_minimum_required(VERSION 2.6) + +set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG _DEBUG) + +if(NOT SKIP_WARNINGS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror") +endif() + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +include_directories("${INC_DIR}") +include_directories("${PROJECT_SOURCE_DIR}/include") +include_directories("${PROJECT_SOURCE_DIR}/src") + +file(GLOB MV_BARCODE_DET_INC_LIST "${PROJECT_SOURCE_DIR}/include/*.h") +file(GLOB MV_BARCODE_DET_SRC_LIST "${PROJECT_SOURCE_DIR}/src/*.cpp") + +if(FORCED_STATIC_BUILD) + add_library(${PROJECT_NAME} STATIC ${MV_BARCODE_DET_INC_LIST} ${MV_BARCODE_DET_SRC_LIST}) +else() + add_library(${PROJECT_NAME} SHARED ${MV_BARCODE_DET_INC_LIST} ${MV_BARCODE_DET_SRC_LIST}) +endif() + +target_link_libraries(${PROJECT_NAME} ${MV_COMMON_LIB_NAME} zbar dlog) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) diff --git a/mv_barcode/barcode_detector/include/Barcode.h b/mv_barcode/barcode_detector/include/Barcode.h new file mode 100644 index 0000000..99af53d --- /dev/null +++ b/mv_barcode/barcode_detector/include/Barcode.h @@ -0,0 +1,88 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __BARCODE_H__ +#define __BARCODE_H__ + +#include "mv_barcode.h" + +#include <stddef.h> +#include <zbar.h> + +namespace MediaVision +{ +namespace Barcode +{ + +/** + * @class Barcode + * @brief Handle to barcode object. + */ +class Barcode +{ +public: + /** + * @brief Barcode constructor. + * + * @since_tizen 2.4 + * @remarks create copy of bar_obj + * @param [in] barObj zbar barcode handle + * + */ + Barcode(const zbar::Symbol &barObj); + + /** + * @brief Barcode destructor. + * + * @since_tizen 2.4 + */ + ~Barcode(); + + /** + * @brief Gets encoded message from barcode object. + * + * @since_tizen 2.4 + * @return Encoded message + */ + std::string getMessage(void) const; + + /** + * @brief Gets the type of the barcode. + * + * @since_tizen 2.4 + * @return Enumeration value corresponding to the barcode type + */ + mv_barcode_type_e getType(void) const; + + /** + * @brief Calculates location of barcode handle from zbar. + * location polygon. + * + * @since_tizen 2.4 + * @param [out] location Quadrangle that contains barcode on image + * @return @c MEDIA_VISION_ERROR_NONE on success, + * otherwise a negative error value + */ + int calculateLocation(mv_quadrangle_s &location) const; + +private: + const zbar::Symbol *m_pBarcodeObj; /*/< Pointer to zbar barcode handle */ +}; + +} /* Barcode */ +} /* MediaVision */ + +#endif /* __BARCODE_H__ */ diff --git a/mv_barcode/barcode_detector/include/BarcodeUtils.h b/mv_barcode/barcode_detector/include/BarcodeUtils.h new file mode 100644 index 0000000..e6d1af5 --- /dev/null +++ b/mv_barcode/barcode_detector/include/BarcodeUtils.h @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __TIZEN_MEDIAVISION_BARCODE_UTILS_H__ +#define __TIZEN_MEDIAVISION_BARCODE_UTILS_H__ + +#include "mv_common.h" + +namespace zbar +{ + class Image; +} + +namespace MediaVision +{ +namespace Barcode +{ + +/** + * @brief This function converts media vision image handle to zbar image handle. + * + * @since_tizen 2.4 + * @param [in] mvSource Media vision image handle + * @param [out] zbarSource Zbar image handle + * @return @c MEDIA_VISION_ERROR_NONE on success, + otherwise a negative error value + */ +int convertSourceMV2Zbar(mv_source_h mvSource, zbar::Image &zbarSource); + +} /* Barcode */ +} /* MediaVision */ + +#endif /* __TIZEN_MEDIAVISION_BARCODE_UTILS_H__ */ diff --git a/mv_barcode/barcode_detector/include/mv_barcode_detect_open.h b/mv_barcode/barcode_detector/include/mv_barcode_detect_open.h new file mode 100644 index 0000000..5402726 --- /dev/null +++ b/mv_barcode/barcode_detector/include/mv_barcode_detect_open.h @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __TIZEN_MEDIAVISION_BARCODE_DETECT_OPEN_H__ +#define __TIZEN_MEDIAVISION_BARCODE_DETECT_OPEN_H__ + +#include "mv_barcode_detect.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file mv_barcode_detect_open.h + * @brief This file contains the Media Vision barcode detect module API for the + * open module. + */ + +/** + * @brief Detects barcode(s) on source and reads message from it. + * + * @since_tizen 2.4 + * @param [in] source The media source handle + * @param [in] engine_cfg The handle to the configuration of the engine + * @param [in] roi Region of interest - rectangular area on the + * @a source which will be used for barcode detection + * Note that @a roi should be inside area on the + * @a source. + * @param [in] detect_cb The callback for result handling + * @param [in] user_data The user data to be passed to the callback function + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT Not supported format + * @retval #MEDIA_VISION_ERROR_INTERNAL Internal error + * @pre Create a source handle by calling @ref mv_create_source() + * @pre Create an engine configuration handle by calling + * @ref mv_create_engine_config() if neccessary, otherwise use NULL + * + * @see mv_barcode_detected_cb() + */ +int mv_barcode_detect_open( + mv_source_h source, + mv_engine_config_h engine_cfg, + mv_rectangle_s roi, + mv_barcode_detected_cb detect_cb, + void *user_data); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __TIZEN_MEDIAVISION_BARCODE_DETECT_OPEN_H__ */ diff --git a/mv_barcode/barcode_detector/src/Barcode.cpp b/mv_barcode/barcode_detector/src/Barcode.cpp new file mode 100644 index 0000000..a35f8bd --- /dev/null +++ b/mv_barcode/barcode_detector/src/Barcode.cpp @@ -0,0 +1,148 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 "Barcode.h" + +#include <mv_private.h> + +namespace MediaVision +{ +namespace Barcode +{ + +Barcode::Barcode(const zbar::Symbol& barObj): + m_pBarcodeObj(new zbar::Symbol(barObj)) +{ + ; /* NULL */ +} + +Barcode::~Barcode() +{ + LOGI("Delete ZBar object"); + delete m_pBarcodeObj; +} + +std::string Barcode::getMessage(void) const +{ + LOGI("Retrieve message data from ZBar object"); + return m_pBarcodeObj->get_data(); +} + +mv_barcode_type_e Barcode::getType(void) const +{ + zbar::zbar_symbol_type_t barcodeType = m_pBarcodeObj->get_type(); + + switch (barcodeType) + { + case zbar::ZBAR_QRCODE: + return MV_BARCODE_QR; + + case zbar::ZBAR_UPCA: + return MV_BARCODE_UPC_A; + + case zbar::ZBAR_UPCE: + return MV_BARCODE_UPC_E; + + case zbar::ZBAR_EAN8: + return MV_BARCODE_EAN_8; + + case zbar::ZBAR_EAN13: + return MV_BARCODE_EAN_13; + + case zbar::ZBAR_CODE128: + return MV_BARCODE_CODE128; + + case zbar::ZBAR_CODE39: + return MV_BARCODE_CODE39; + + case zbar::ZBAR_I25: + return MV_BARCODE_I2_5; + + default: + LOGE("ZBar symbol colorspace is not supported by media vision"); + return MV_BARCODE_UNDEFINED; + } +} + +int Barcode::calculateLocation(mv_quadrangle_s& location) const +{ + const int numberOfVertexes = 4; + + const int locationPolygonSize = m_pBarcodeObj->get_location_size(); + + //polygon location should contain at least 4 points + if (locationPolygonSize < numberOfVertexes) + { + LOGW("Can't compute location of the barcode by %i points (less then %i).", locationPolygonSize, numberOfVertexes); + return MEDIA_VISION_ERROR_INVALID_OPERATION; + } + + if (locationPolygonSize == numberOfVertexes) + { + for (int i = 0; i < numberOfVertexes; ++i) + { + location.points[i].x = m_pBarcodeObj->get_location_x(i); + location.points[i].y = m_pBarcodeObj->get_location_y(i); + } + + return MEDIA_VISION_ERROR_NONE; + } + + //bounding quadrangle is computing by 4 marginal points + mv_point_s first = {m_pBarcodeObj->get_location_x(0), m_pBarcodeObj->get_location_y(0)}; + + int minX = first.x; + int maxX = first.x; + int minY = first.y; + int maxY = first.y; + + for (int i = 0; i < locationPolygonSize; ++i) + { + mv_point_s current = {m_pBarcodeObj->get_location_x(i), m_pBarcodeObj->get_location_y(i)}; + if (current.x < minX) + { + minX = current.x; + } + else if (current.x > maxX) + { + maxX = current.x; + } + + if (current.y < minY) + { + minY = current.y; + } + else if (current.y > maxY) + { + maxY = current.y; + } + } + + mv_point_s bottomLeft = {minX, maxY}; + mv_point_s bottomRight = {maxX, maxY}; + mv_point_s topRight = {maxX, minY}; + mv_point_s topLeft = {minX, minY}; + + location.points[0] = topLeft; + location.points[1] = topRight; + location.points[2] = bottomRight; + location.points[3] = bottomLeft; + + return MEDIA_VISION_ERROR_NONE; +} + +} /* Barcode */ +} /* MediaVision */ diff --git a/mv_barcode/barcode_detector/src/BarcodeUtils.cpp b/mv_barcode/barcode_detector/src/BarcodeUtils.cpp new file mode 100644 index 0000000..57219eb --- /dev/null +++ b/mv_barcode/barcode_detector/src/BarcodeUtils.cpp @@ -0,0 +1,113 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 "BarcodeUtils.h" +#include "mv_common_c.h" + +#include <mv_private.h> + +#include <zbar.h> + +namespace MediaVision +{ +namespace Barcode +{ + +int convertSourceMV2Zbar(mv_source_h mvSource, zbar::Image& zbarSource) +{ + int err = MEDIA_VISION_ERROR_NONE; + unsigned char *buffer = NULL; + unsigned int height = 0; + unsigned int width = 0; + unsigned int size = 0; + mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID; + + err = mv_source_get_colorspace_c(mvSource, &colorspace); + if (err != MEDIA_VISION_ERROR_NONE) + { + LOGW("Can't determine mv_source_h colorspace to convert to ZBar colorspace. Conversion failed"); + return err; + } + + switch(colorspace) + { + case MEDIA_VISION_COLORSPACE_Y800: + zbarSource.set_format("Y800"); + break; + case MEDIA_VISION_COLORSPACE_I420: + zbarSource.set_format("I420"); + break; + case MEDIA_VISION_COLORSPACE_NV12: + zbarSource.set_format("NV12"); + break; + case MEDIA_VISION_COLORSPACE_YV12: + zbarSource.set_format("YV12"); + break; + case MEDIA_VISION_COLORSPACE_NV21: + zbarSource.set_format("NV21"); + break; + case MEDIA_VISION_COLORSPACE_YUYV: + zbarSource.set_format("YUYV"); + break; + case MEDIA_VISION_COLORSPACE_UYVY: + zbarSource.set_format("UYVY"); + break; + case MEDIA_VISION_COLORSPACE_422P: + zbarSource.set_format("422P"); + break; + case MEDIA_VISION_COLORSPACE_RGB565: + zbarSource.set_format("RGBP"); + break; + case MEDIA_VISION_COLORSPACE_RGB888: + zbarSource.set_format("RGB3"); + break; + case MEDIA_VISION_COLORSPACE_RGBA: + zbarSource.set_format("RGB4"); + break; + default: + LOGE("Media vision colorspace is not supported by ZBar symbol"); + return MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT; + } + + err = mv_source_get_buffer_c(mvSource, &buffer, &size); + if (err != MEDIA_VISION_ERROR_NONE) + { + LOGW("Can't get mv_source_h buffer to convert to ZBar image. Conversion failed"); + return err; + } + + err = mv_source_get_height_c(mvSource, &height); + if (err != MEDIA_VISION_ERROR_NONE) + { + LOGW("Can't get mv_source_h height for conversion. Conversion failed"); + return err; + } + + err = mv_source_get_width_c(mvSource, &width); + if (err != MEDIA_VISION_ERROR_NONE) + { + LOGW("Can't get mv_source_h width for conversion. Conversion failed"); + return err; + } + + zbarSource.set_size(width, height); + zbarSource.set_data(buffer, size); + + return err; +} + +} /* Barcode */ +} /* MediaVision */ diff --git a/mv_barcode/barcode_detector/src/mv_barcode_detect_open.cpp b/mv_barcode/barcode_detector/src/mv_barcode_detect_open.cpp new file mode 100644 index 0000000..baaac31 --- /dev/null +++ b/mv_barcode/barcode_detector/src/mv_barcode_detect_open.cpp @@ -0,0 +1,153 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 "mv_barcode_detect_open.h" + +#include "Barcode.h" +#include "BarcodeUtils.h" + +#include <mv_private.h> + +#include <zbar.h> + +using namespace MediaVision::Barcode; + +int mv_barcode_detect_open( + mv_source_h source, + mv_engine_config_h engine_cfg, + mv_rectangle_s roi, + mv_barcode_detected_cb detect_cb, + void *user_data) +{ + if (!source || !detect_cb) + { + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + zbar::Image image; + int err = convertSourceMV2Zbar(source, image); + if (err != MEDIA_VISION_ERROR_NONE) + { + LOGW("convertSourceMV2Zbar failed"); + return err; + } + + zbar::Image greyImage = image.convert("Y800"); + greyImage.set_crop(roi.point.x, roi.point.y, roi.width, roi.height); + zbar::ImageScanner scanner; + + int target_val = 0; + err = mv_engine_config_get_int_attribute(engine_cfg, "MV_BARCODE_DETECT_ATTR_TARGET", &target_val); + if (err != MEDIA_VISION_ERROR_NONE) + { + LOGW("mv_engine_config_get_int_attribute failed"); + return err; + } + + /** + * 0 - linear barcodes and QR codes + * 1 - only linear barcodes + * 2 - only QR codes + */ + switch (target_val) + { + case 0: + scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1); + break; + case 1: + scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 0); + scanner.set_config(zbar::ZBAR_UPCA, zbar::ZBAR_CFG_ENABLE, 1); + scanner.set_config(zbar::ZBAR_UPCE, zbar::ZBAR_CFG_ENABLE, 1); + scanner.set_config(zbar::ZBAR_EAN8, zbar::ZBAR_CFG_ENABLE, 1); + scanner.set_config(zbar::ZBAR_EAN13, zbar::ZBAR_CFG_ENABLE, 1); + scanner.set_config(zbar::ZBAR_CODE128, zbar::ZBAR_CFG_ENABLE, 1); + scanner.set_config(zbar::ZBAR_CODE39, zbar::ZBAR_CFG_ENABLE, 1); + scanner.set_config(zbar::ZBAR_I25, zbar::ZBAR_CFG_ENABLE, 1); + break; + case 2: + scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 0); + scanner.set_config(zbar::ZBAR_QRCODE, zbar::ZBAR_CFG_ENABLE, 1); + break; + default: + LOGW("Unavailabe target value %d", target_val); + } + + int numberOfBarcodes = scanner.scan(greyImage); + LOGI("ZBar scanner has found %i barcodes on the mv_source_h", numberOfBarcodes); + mv_quadrangle_s *barcodeLocations = NULL; + mv_barcode_type_e *types = NULL; + + if (numberOfBarcodes == 0) + { + LOGI("Call the detect callback for 0 detected barcodes"); + detect_cb(source, engine_cfg, barcodeLocations, NULL, types, numberOfBarcodes, user_data); + return MEDIA_VISION_ERROR_NONE; + } + else if (numberOfBarcodes < 0) + { + LOGW("Incorrect number of barcodes (%i), detection is terminated", numberOfBarcodes); + return MEDIA_VISION_ERROR_INTERNAL; + } + + const char **messagesArray = new const char*[numberOfBarcodes]; + barcodeLocations = new mv_quadrangle_s[numberOfBarcodes]; + types = new mv_barcode_type_e[numberOfBarcodes]; + + int i = 0; + //extract results and prepare them for callback passing + for (zbar::SymbolIterator symbol = greyImage.symbol_begin(); + symbol != greyImage.symbol_end(); + ++symbol, ++i) + { + Barcode curBarcode(*symbol); + + size_t messageLength = curBarcode.getMessage().size(); + char *curMessage = new char[messageLength + 1]; + curBarcode.getMessage().copy(curMessage, messageLength); + curMessage[messageLength] = '\0'; + messagesArray[i] = curMessage; + + types[i] = curBarcode.getType(); + + int err = curBarcode.calculateLocation(barcodeLocations[i]); + if (err != MEDIA_VISION_ERROR_NONE) + { + LOGW("Can't determine location for barcode, detection is terminated"); + for (int j = 0; j <= i; ++j) + { + delete[] messagesArray[j]; + } + delete[] messagesArray; + delete[] barcodeLocations; + delete[] types; + return err; + } + } + + LOGI("Call the detect callback for %i detected barcodes", numberOfBarcodes); + detect_cb(source, engine_cfg, barcodeLocations, messagesArray, types, numberOfBarcodes, user_data); + + LOGI("Clean the memory from barcodes messages, locations and types"); + for (int j = 0; j < numberOfBarcodes; ++j) + { + delete[] messagesArray[j]; + } + delete[] messagesArray; + delete[] barcodeLocations; + delete[] types; + + return MEDIA_VISION_ERROR_NONE; +} diff --git a/mv_barcode/barcode_detector_lic/CMakeLists.txt b/mv_barcode/barcode_detector_lic/CMakeLists.txt new file mode 100644 index 0000000..22fd07c --- /dev/null +++ b/mv_barcode/barcode_detector_lic/CMakeLists.txt @@ -0,0 +1,25 @@ +project(${MV_BARCODE_DETECTOR_LIB_NAME}) +cmake_minimum_required(VERSION 2.6) + +set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG _DEBUG) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +include_directories("${INC_DIR}") +include_directories("${PROJECT_SOURCE_DIR}/include") +include_directories("${PROJECT_SOURCE_DIR}/src") + +file(GLOB MV_BARCODE_DET_INC_LIST "${PROJECT_SOURCE_DIR}/include/*.h") +file(GLOB MV_BARCODE_DET_SRC_LIST "${PROJECT_SOURCE_DIR}/src/*.c") + +if(FORCED_STATIC_BUILD) + add_library(${PROJECT_NAME} STATIC ${MV_BARCODE_DET_INC_LIST} ${MV_BARCODE_DET_SRC_LIST}) +else() + add_library(${PROJECT_NAME} SHARED ${MV_BARCODE_DET_INC_LIST} ${MV_BARCODE_DET_SRC_LIST}) +endif() + +target_link_libraries(${PROJECT_NAME} ${MV_COMMON_LIB_NAME}) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) diff --git a/mv_barcode/barcode_detector_lic/include/mv_barcode_detect_lic.h b/mv_barcode/barcode_detector_lic/include/mv_barcode_detect_lic.h new file mode 100644 index 0000000..4e5e41a --- /dev/null +++ b/mv_barcode/barcode_detector_lic/include/mv_barcode_detect_lic.h @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __TIZEN_MEDIAVISION_BARCODE_DETECT_LIC_H__ +#define __TIZEN_MEDIAVISION_BARCODE_DETECT_LIC_H__ + +#include "mv_barcode_detect.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file mv_barcode_detect_lic.h + * @brief This file contains the Media Vision barcode detect module API for the + * licensed module. + */ + +/** + * @brief Detects barcode(s) on source and reads message from it. + * + * @since_tizen 2.4 + * @param [in] source The media source handle + * @param [in] engine_cfg The handle to the configuration of the engine + * @param [in] roi Region of interest - rectangular area on the + * @a source which will be used for barcode detection + * @param [in] detect_cb The callback for result handling + * @param [in] user_data The user data to be passed to the callback function + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre Create a source handle by calling @ref mv_create_source() + * @pre Create an engine configuration handle by calling + * @ref mv_create_engine_config() if neccessary, otherwise use NULL + * + * @see mv_barcode_detected_cb() + */ +int mv_barcode_detect_lic( + mv_source_h source, + mv_engine_config_h engine_cfg, + mv_rectangle_s roi, + mv_barcode_detected_cb detect_cb, + void *user_data); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __TIZEN_MEDIAVISION_BARCODE_DETECT_LIC_H__ */ diff --git a/mv_barcode/barcode_detector_lic/src/mv_barcode_detect_lic.c b/mv_barcode/barcode_detector_lic/src/mv_barcode_detect_lic.c new file mode 100644 index 0000000..ba94e29 --- /dev/null +++ b/mv_barcode/barcode_detector_lic/src/mv_barcode_detect_lic.c @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 "mv_barcode_detect_lic.h" + +int mv_barcode_detect_lic( + mv_source_h source, + mv_engine_config_h engine_cfg, + mv_rectangle_s roi, + mv_barcode_detected_cb detect_cb, + void *user_data) +{ + return MEDIA_VISION_ERROR_NOT_SUPPORTED; +} diff --git a/mv_barcode/barcode_generator/CMakeLists.txt b/mv_barcode/barcode_generator/CMakeLists.txt new file mode 100644 index 0000000..6d70344 --- /dev/null +++ b/mv_barcode/barcode_generator/CMakeLists.txt @@ -0,0 +1,32 @@ +project(${MV_BARCODE_GENERATOR_LIB_NAME}) +cmake_minimum_required(VERSION 2.6) + +set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG _DEBUG) + +if(NOT SKIP_WARNINGS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror") +endif() + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +include_directories("${INC_DIR}") +include_directories("${PROJECT_SOURCE_DIR}/include") +include_directories("${PROJECT_SOURCE_DIR}/src") + +file(GLOB MV_BARCODE_GEN_INC_LIST "${PROJECT_SOURCE_DIR}/include/*.h") +file(GLOB MV_BARCODE_GEN_SRC_LIST "${PROJECT_SOURCE_DIR}/src/*.cpp") + +find_package(OpenCV REQUIRED) +include_directories(${OpenCV_INCLUDE_DIRS}) + +if(FORCED_STATIC_BUILD) + add_library(${PROJECT_NAME} STATIC ${MV_BARCODE_GEN_INC_LIST} ${MV_BARCODE_GEN_SRC_LIST}) +else() + add_library(${PROJECT_NAME} SHARED ${MV_BARCODE_GEN_INC_LIST} ${MV_BARCODE_GEN_SRC_LIST}) +endif() + +target_link_libraries(${PROJECT_NAME} zint ${MV_COMMON_LIB_NAME} ${OpenCV_LIBS} dlog) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) diff --git a/mv_barcode/barcode_generator/include/BarcodeGenerator.h b/mv_barcode/barcode_generator/include/BarcodeGenerator.h new file mode 100644 index 0000000..145603b --- /dev/null +++ b/mv_barcode/barcode_generator/include/BarcodeGenerator.h @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __BARCODEGENERATOR_H__ +#define __BARCODEGENERATOR_H__ + +#include "BarcodeOptions.h" + +#include <string> + +/** + * @file BarcodeGenerator.h + * @brief This file contains the BarcodeGenerator class. + */ + +namespace MediaVision +{ +namespace Barcode +{ + +/** + * @brief This class implements barcode generation. + * @details 1D Barcodes and 2D QR codes are supported. + * + * @since_tizen 2.4 + */ +class BarcodeGenerator +{ +public: + + /** + * @brief This method generates Barcodes image according to options. + * + * @since_tizen 2.4 + * @param [in] imageFileName Image file name which will be generated + * @param [in] imageFormat Image file format which will be generated + * @param [in] imageWidth Image file width which will be generated + * @param [in] imageHeight Image file height which will be generated + * @param [in] message Input message to be encoded + * @param [in] type Barcode type(1D barcode or 2D QR code) + * @param [in] encodingMode Encoding mode(for QR codes only) + * @param [in] correctionLevel Error correction level(for QR codes only) + * @param [in] qrVersion QR code version(1 ~ 40, 0 for 1D barcodes) + * @param [in] showText Show text or not + * @return BARCODE_ERROR_NONE from BarcodeError whitch is 0 if success, + * BarcodeError value otherwise + */ + static int generateBarcodeToImage( + const std::string &imageFileName, + BarcodeImageFormat imageFormat, + const int imageWidth, + const int imageHeight, + const std::string &message, + BarcodeType type, + BarcodeQREncodingMode encodingMode = BARCODE_QR_MODE_UNAVAILABLE, + BarcodeQRErrorCorrectionLevel correctionLevel = BARCODE_QR_ECC_UNAVAILABLE, + int qrVersion = 0, + int showText = 0); + + /** + * @brief This method generates Barcodes image buffer according to options. + * + * @since_tizen 2.4 + * @param [out] imageBuffer Image buffer with image to be generated + * @param [out] imageWidth Image buffer width which will be generated + * @param [out] imageHeight Image buffer height which will be generated + * @param [out] imageChannels Image buffer channels number which will be generated + * @param [in] message Input message to be encoded + * @param [in] type Barcode type(1D barcode or 2D QR code) + * @param [in] encodingMode Encoding mode(for QR codes only) + * @param [in] correctionLevel Error correction level(for QR codes only) + * @param [in] qrVersion QR code version(1 ~ 40, 0 for 1D barcodes) + * @param [in] showText Show text or not + * @return BARCODE_ERROR_NONE from BarcodeError whitch is 0 if success, + * BarcodeError value otherwise + */ + static int generateBarcodeToBuffer( + unsigned char **imageBuffer, + unsigned int *imageWidth, + unsigned int *imageHeight, + unsigned int *imageChannels, + const std::string &message, + BarcodeType type, + BarcodeQREncodingMode encodingMode = BARCODE_QR_MODE_UNAVAILABLE, + BarcodeQRErrorCorrectionLevel correctionLevel = BARCODE_QR_ECC_UNAVAILABLE, + int qrVersion = 0, + int showText = 0); +}; + +} /* Barcode */ +} /* MediaVision */ + +#endif /* __BARCODEGENERATOR_H__ */ + diff --git a/mv_barcode/barcode_generator/include/BarcodeOptions.h b/mv_barcode/barcode_generator/include/BarcodeOptions.h new file mode 100644 index 0000000..023a028 --- /dev/null +++ b/mv_barcode/barcode_generator/include/BarcodeOptions.h @@ -0,0 +1,119 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __BARCODEOPTIONS_H__ +#define __BARCODEOPTIONS_H__ + +/** + * @file BarcodeOptions.h + * @brief This file contains the Barcode options. + */ + +namespace MediaVision +{ +namespace Barcode +{ + +/** + * @brief The Barcode type enumeration. + * + * @since_tizen 2.4 + */ +enum BarcodeType { + BARCODE_QR = 58, + BARCODE_UPCA = 34, + BARCODE_UPCE = 37, + BARCODE_EAN8 = 13, + BARCODE_EAN13 = BARCODE_EAN8, + BARCODE_CODE39 = 8, + BARCODE_CODE128 = 20, + BARCODE_INTERLEAVE_2_5 = 3 +}; + +/** + * @brief The Barcode error correction level enumeration. + * + * @since_tizen 2.4 + * @remarks This is unavailable for 1D barcodes. + */ +enum BarcodeQRErrorCorrectionLevel { + BARCODE_QR_ECC_UNAVAILABLE = 0, + BARCODE_QR_ECC_LOW = 1, + BARCODE_QR_ECC_MEDIUM = 2, + BARCODE_QR_ECC_QUARTILE = 3, + BARCODE_QR_ECC_HIGH = 4 +}; + + +/** + * @brief The Barcode encoding mode enumeration. + * + * @since_tizen 2.4 + * @remarks This is unavailable for 1D barcodes. + */ +enum BarcodeQREncodingMode { + /* TODO: verify using real data */ + BARCODE_QR_MODE_NUMERIC = 1, + BARCODE_QR_MODE_ALPHANUMERIC = 1, + BARCODE_QR_MODE_BYTE = 0, + BARCODE_QR_MODE_UTF8 = 1, + BARCODE_QR_MODE_KANJI = 3, + BARCODE_QR_MODE_UNAVAILABLE +}; + +/** + * @brief The Barcode image format enumeration. + * + * @since_tizen 2.4 + */ +enum BarcodeImageFormat { + BARCODE_IMAGE_JPG, + BARCODE_IMAGE_PNG, + BARCODE_IMAGE_BMP +}; + +/** + * @brief The Barcode generation text option enumeration. + * + * @since_tizen 2.4 + */ +enum BarcodeGenTextOpt { + BARCODE_GEN_TEXT_INVISIBLE, + BARCODE_GEN_TEXT_VISIBLE +}; + +/** + * @brief The Barcode error enumeration. + * + * @since_tizen 2.4 + */ +enum BarcodeError { + BARCODE_ERROR_NONE = 0, + BARCODE_WARNING_INVALID_OPTION = 2, + BARCODE_ERROR_TOO_LONG = 5, + BARCODE_ERROR_INVALID_DATA = 6, + BARCODE_ERROR_INVALID_CHECK = 7, + BARCODE_ERROR_INVALID_OPTION = 8, + BARCODE_ERROR_ENCODING_PROBLEM = 9, + BARCODE_ERROR_FILE_ACCESS = 10, + BARCODE_ERROR_MEMORY = 11 +}; + +} /* Barcode */ +} /* MediaVision */ + +#endif /* __BARCODEOPTIONS_H__ */ + diff --git a/mv_barcode/barcode_generator/include/mv_barcode_generate_open.h b/mv_barcode/barcode_generator/include/mv_barcode_generate_open.h new file mode 100644 index 0000000..0650602 --- /dev/null +++ b/mv_barcode/barcode_generator/include/mv_barcode_generate_open.h @@ -0,0 +1,108 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __TIZEN_MEDIAVISION_BARCODE_GENERATE_OPEN_H__ +#define __TIZEN_MEDIAVISION_BARCODE_GENERATE_OPEN_H__ + +#include "mv_barcode_generate.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file mv_barcode_generate_open.h + * @brief This file contains the Media Vision barcode generate module API for + * the open module. + */ + +/** + * @brief Generates @ref mv_source_h with barcode image. + * + * @since_tizen 2.4 + * @param [in] engine_cfg The handle to the configuration of the engine + * @param [in] message The message to be encoded in the barcode + * @param [in] type Type of the barcode to be generated + * @param [in] qr_enc_mode Encoding mode for the message (only for QR codes; + * for 1D barcodes set this parameter to + * @ref MV_BARCODE_QR_MODE_UNAVAILABLE) + * @param [in] qr_ecc Error correction level (only for QR codes; for + * 1D barcodes set this parameter to + * @ref MV_BARCODE_QR_ECC_UNAVAILABLE) + * @param [in] qr_version QR code version (for 1D barcodes set this + * parameter to 0) + * @param [in, out] image The media source handle which will be used to + * fill by the buffer with generated image + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_MSG_TOO_LONG Too long or short message + * @retval #MEDIA_VISION_ERROR_PERMISSION_DENIED Permission denied + * + * @see mv_barcode_generate_image_open() + */ +int mv_barcode_generate_source_open(mv_engine_config_h engine_cfg, + const char *message, + mv_barcode_type_e type, + mv_barcode_qr_mode_e qr_enc_mode, + mv_barcode_qr_ecc_e qr_ecc, + int qr_version, + mv_source_h image); + +/** + * @brief Generates image file with barcode. + * + * @since_tizen 2.4 + * @param [in] engine_cfg The handle to the configuration of the engine + * @param [in] message The message to be encoded in the barcode + * @param [in] image_width The width of the generated image + * @param [in] image_height The height of the generated image + * @param [in] type Type of the barcode to be generated + * @param [in] qr_enc_mode Encoding mode for the message (only for QR codes; + * for 1D barcodes set this parameter to + * @ref MV_BARCODE_QR_MODE_UNAVAILABLE) + * @param [in] qr_ecc Error correction level (only for QR codes; for + * 1D barcodes set this parameter to + * @ref MV_BARCODE_QR_ECC_UNAVAILABLE) + * @param [in] qr_version QR code version (for 1D barcodes set this + * parameter to 0) + * @param [in] image_path The path to the file that has to be generated + * @param [in] image_format The format of the output image + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_MSG_TOO_LONG Too long or short message + * @retval #MEDIA_VISION_ERROR_PERMISSION_DENIED Permission denied + * + * @see mv_barcode_generate_source_open() + */ +int mv_barcode_generate_image_open( + mv_engine_config_h engine_cfg, + const char *message, + int image_width, + int image_height, + mv_barcode_type_e type, + mv_barcode_qr_mode_e qr_enc_mode, + mv_barcode_qr_ecc_e qr_ecc, + int qr_version, + const char *image_path, + mv_barcode_image_format_e image_format); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __TIZEN_MEDIAVISION_BARCODE_GENERATE_OPEN_H__ */ diff --git a/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp b/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp new file mode 100644 index 0000000..432c8c4 --- /dev/null +++ b/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp @@ -0,0 +1,300 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 "BarcodeGenerator.h" + +#include <mv_private.h> + +#include <zint.h> + +#include <opencv2/core/core.hpp> +#include <opencv2/imgproc/imgproc.hpp> +#include <opencv2/highgui/highgui.hpp> + +#include <cstring> +#include <vector> + +namespace MediaVision +{ +namespace Barcode +{ + +namespace +{ + +int getFormatEncodingInfo( + BarcodeImageFormat imageFormat, + std::vector<std::string>& extensions, + std::vector<int>& compressionParams) +{ + static const int PNGCompressionLevel = 3; + + compressionParams.clear(); + extensions.clear(); + + switch (imageFormat) + { + case BARCODE_IMAGE_PNG: + compressionParams.push_back(CV_IMWRITE_PNG_COMPRESSION); + compressionParams.push_back(PNGCompressionLevel); + extensions.push_back(".png"); + break; + case BARCODE_IMAGE_JPG: + extensions.push_back(".jpg"); + extensions.push_back(".jpeg"); + extensions.push_back(".jpe"); + break; + case BARCODE_IMAGE_BMP: + extensions.push_back(".bmp"); + extensions.push_back(".dib"); + break; + default: + return BARCODE_ERROR_INVALID_OPTION; + } + return BARCODE_ERROR_NONE; +} + +int createBarcode( + const std::string& message, + BarcodeType type, + BarcodeQREncodingMode encodingMode, + BarcodeQRErrorCorrectionLevel correctionLevel, + int qrVersion, + int showText, + zint_symbol *symbol) +{ + // set input values + symbol->symbology = type; + symbol->input_mode = encodingMode; + symbol->option_1 = correctionLevel; + symbol->option_2 = qrVersion; + symbol->scale = 1; + symbol->show_hrt = showText; + + // set default values + std::strncpy(symbol->fgcolour, "000000", 10); + std::strncpy(symbol->bgcolour, "ffffff", 10); + symbol->border_width = 1; + symbol->height = 50; + + if (type == BARCODE_QR) { + symbol->whitespace_width = 0; + } else { + symbol->whitespace_width = 10; + } + + // create barcode + const int rotationAngle = 0; + int error = ZBarcode_Encode_and_Buffer( + symbol, + (unsigned char*)(message.c_str()), + message.length(), + rotationAngle); + + return error; +} + +int writeBufferToImageFile( + zint_symbol *symbol, + const std::string& imageFileName, + BarcodeImageFormat imageFormat, + const int imageWidth, + const int imageHeight) +{ + if (imageWidth <= 0 || imageHeight <= 0) + { + LOGE("Barcode image size is invalid: %i x %i. Terminate write to " + "the image operation", imageWidth, imageHeight); + return BARCODE_ERROR_INVALID_DATA; + } + + static const std::string defaultFilePath = "out"; + + // check current extension + std::vector<std::string> expectedExtensions; + std::vector<int> compressionParams; + + int error = getFormatEncodingInfo(imageFormat, + expectedExtensions, compressionParams); + + if (BARCODE_ERROR_NONE != error || expectedExtensions.empty()) + { + LOGE("Image format is incorrectly specified or not supported"); + return error; + } + + bool rightExtensionFlag = false; + + std::string resultFilePath(imageFileName); + if (resultFilePath.empty()) + { + resultFilePath = defaultFilePath; + } + else + { + for (size_t extNum = 0; extNum < expectedExtensions.size(); ++extNum) + { + if (resultFilePath.size() >= expectedExtensions[extNum].size()) + { + std::string givenExtension = resultFilePath.substr( + resultFilePath.length() - expectedExtensions[extNum].size(), + expectedExtensions[extNum].size()); + + std::transform( + givenExtension.begin(), givenExtension.end(), + givenExtension.begin(), ::tolower); + + if (givenExtension == expectedExtensions[extNum]) + { + rightExtensionFlag = true; + break; + } + } + } + } + if (!rightExtensionFlag) + { + resultFilePath += expectedExtensions[0]; + } + + cv::Mat image(symbol->bitmap_height, symbol->bitmap_width, CV_8UC3, symbol->bitmap); + cv::resize(image, image, cv::Size(imageWidth, imageHeight), 0, 0, cv::INTER_AREA); + + error = cv::imwrite(resultFilePath, image, compressionParams) ? + BARCODE_ERROR_NONE : BARCODE_ERROR_INVALID_DATA; + + if (BARCODE_ERROR_NONE != error) + { + LOGE("Write barcode image to file %s operation failed.", + resultFilePath.c_str()); + return error; + } + + return error; +} + +} /* anonymous namespace */ + +int BarcodeGenerator::generateBarcodeToImage( + const std::string& imageFileName, + BarcodeImageFormat imageFormat, + const int imageWidth, + const int imageHeight, + const std::string& message, + BarcodeType type, + BarcodeQREncodingMode encodingMode, + BarcodeQRErrorCorrectionLevel correctionLevel, + int qrVersion, + int showText) +{ + zint_symbol *symbol = ZBarcode_Create(); + + if(symbol == NULL) + { + LOGE("ZBarcode creation failed"); + + return BARCODE_ERROR_ENCODING_PROBLEM; + } + + int error = createBarcode( + message, + type, + encodingMode, + correctionLevel, + qrVersion, + showText, + symbol); + + if (error != BARCODE_ERROR_NONE) + { + LOGE("Barcode creation failed, clean memory"); + ZBarcode_Delete(symbol); + return error; + } + + error = writeBufferToImageFile( + symbol, + imageFileName, + imageFormat, + imageWidth, + imageHeight); + if (error != BARCODE_ERROR_NONE) + { + LOGE("Barcode [%s] file write fail, clean memory", imageFileName.c_str()); + } + else + { + LOGI("Barcode image [%s] is successfully generated, clean memory", imageFileName.c_str()); + } + + ZBarcode_Delete(symbol); + + return error; +} + +int BarcodeGenerator::generateBarcodeToBuffer( + unsigned char **imageBuffer, + unsigned int *imageWidth, + unsigned int *imageHeight, + unsigned int *imageChannels, + const std::string& message, + BarcodeType type, + BarcodeQREncodingMode encodingMode, + BarcodeQRErrorCorrectionLevel correctionLevel, + int qrVersion, + int showText) +{ + zint_symbol *symbol = ZBarcode_Create(); + + if(symbol == NULL) + { + LOGE("ZBarcode creation failed"); + + return BARCODE_ERROR_ENCODING_PROBLEM; + } + + int error = createBarcode( + message, + type, + encodingMode, + correctionLevel, + qrVersion, + showText, + symbol); + + if (error != BARCODE_ERROR_NONE) + { + LOGE("Barcode creation failed, clean memory"); + ZBarcode_Delete(symbol); + return error; + } + + // fill output buffer + *imageWidth = symbol->bitmap_width; + *imageHeight = symbol->bitmap_height; + *imageChannels = 3; + const unsigned int imageBufferSize = (*imageWidth) * (*imageHeight) * (*imageChannels); + *imageBuffer = new unsigned char [imageBufferSize]; + memmove(*imageBuffer, symbol->bitmap, imageBufferSize); + + LOGI("Barcode buffer has been successfully generated, clean memory"); + ZBarcode_Delete(symbol); + + return BARCODE_ERROR_NONE; +} + +} /* Barcode */ +} /* MediaVision */ diff --git a/mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp b/mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp new file mode 100644 index 0000000..a6acfe4 --- /dev/null +++ b/mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp @@ -0,0 +1,370 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 "mv_barcode_generate_open.h" + +#include "mv_common_c.h" +#include "BarcodeGenerator.h" + +#include <mv_private.h> + +#include <algorithm> +#include <cstring> + +using namespace MediaVision::Barcode; + +namespace +{ + +int alphanumToUpper(std::string& strToTransform) +{ + std::string tempString = strToTransform; + std::transform(tempString.begin(), tempString.end(), + tempString.begin(), ::toupper); + + if (std::string::npos != tempString.find_first_not_of("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:")) + { + LOGE("Barcode message can't be converted according to support " + "alphanumeric (0..9, A..Z, space, $, %, *, +, -, ., /, :) " + "mode: %s", strToTransform.c_str()); + return BARCODE_ERROR_INVALID_DATA; + } + + LOGI("Barcode message was converted according to support alphanumeric " + "mode: %s -> %s", strToTransform.c_str(), tempString.c_str()); + strToTransform = tempString; + return BARCODE_ERROR_NONE; +} + +BarcodeType convertBarcodeType(mv_barcode_type_e type) +{ + BarcodeType barcodeType = BARCODE_QR; + switch (type) + { + case MV_BARCODE_UPC_A: + barcodeType = BARCODE_UPCA; + break; + case MV_BARCODE_UPC_E: + barcodeType = BARCODE_UPCE; + break; + case MV_BARCODE_EAN_8: + barcodeType = BARCODE_EAN8; + break; + case MV_BARCODE_EAN_13: + barcodeType = BARCODE_EAN13; + break; + case MV_BARCODE_CODE128: + barcodeType = BARCODE_CODE128; + break; + case MV_BARCODE_CODE39: + barcodeType = BARCODE_CODE39; + break; + case MV_BARCODE_I2_5: + barcodeType = BARCODE_INTERLEAVE_2_5; + break; + default: + break; + } + + LOGI("Media vision barcode type has been converted to ZInt barcode type " + "(%i -> %i)", type, barcodeType); + return barcodeType; +} + +BarcodeQREncodingMode convertEncodingMode(mv_barcode_qr_mode_e mode) +{ + BarcodeQREncodingMode encodingMode = BARCODE_QR_MODE_ALPHANUMERIC; + + switch (mode) + { + case MV_BARCODE_QR_MODE_NUMERIC: + encodingMode = BARCODE_QR_MODE_NUMERIC; + break; + case MV_BARCODE_QR_MODE_BYTE: + encodingMode = BARCODE_QR_MODE_BYTE; + break; + case MV_BARCODE_QR_MODE_UTF8: + encodingMode = BARCODE_QR_MODE_UTF8; + break; + default: + break; + } + + LOGI("Media vision QRCode encoding mode has been converted to " + "ZInt encoding mode (%i -> %i)", mode, encodingMode); + return encodingMode; +} + +BarcodeQRErrorCorrectionLevel convertECC(mv_barcode_qr_ecc_e ecc) +{ + BarcodeQRErrorCorrectionLevel ecclevel = BARCODE_QR_ECC_LOW; + + switch (ecc) + { + case MV_BARCODE_QR_ECC_MEDIUM: + ecclevel = BARCODE_QR_ECC_MEDIUM; + break; + case MV_BARCODE_QR_ECC_QUARTILE: + ecclevel = BARCODE_QR_ECC_QUARTILE; + break; + case MV_BARCODE_QR_ECC_HIGH: + ecclevel = BARCODE_QR_ECC_HIGH; + break; + default: + break; + } + + LOGI("Media vision ECC level has been converted to " + "ZInt ECC level (%i -> %i)", ecc, ecclevel); + return ecclevel; +} + +int convertBarcodeError(int barcodeError) +{ + int mvError = MEDIA_VISION_ERROR_NONE; + + switch (barcodeError) + { + case BARCODE_WARNING_INVALID_OPTION: + mvError = MEDIA_VISION_ERROR_INVALID_PARAMETER; + break; + case BARCODE_ERROR_TOO_LONG: + mvError = MEDIA_VISION_ERROR_MSG_TOO_LONG; + break; + case BARCODE_ERROR_INVALID_DATA: + mvError = MEDIA_VISION_ERROR_INVALID_DATA; + break; + case BARCODE_ERROR_INVALID_CHECK: + mvError = MEDIA_VISION_ERROR_INVALID_PARAMETER; + break; + case BARCODE_ERROR_INVALID_OPTION: + mvError = MEDIA_VISION_ERROR_INVALID_PARAMETER; + break; + case BARCODE_ERROR_ENCODING_PROBLEM: + mvError = MEDIA_VISION_ERROR_INTERNAL; + break; + case BARCODE_ERROR_FILE_ACCESS: + mvError = MEDIA_VISION_ERROR_PERMISSION_DENIED; + break; + case BARCODE_ERROR_MEMORY: + mvError = MEDIA_VISION_ERROR_OUT_OF_MEMORY; + break; + default: + break; + } + + LOGI("ZInt error code has been converted to the media vision error code " + "(%i -> (0x%08x))", barcodeError, mvError); + return mvError; +} + +BarcodeImageFormat convertImageFormat(mv_barcode_image_format_e format) +{ + BarcodeImageFormat imageFormat = BARCODE_IMAGE_PNG; + + switch (format) + { + case MV_BARCODE_IMAGE_FORMAT_JPG: + imageFormat = BARCODE_IMAGE_JPG; + break; + case MV_BARCODE_IMAGE_FORMAT_BMP: + imageFormat = BARCODE_IMAGE_BMP; + break; + default: + break; + } + + LOGI("Media vision image format has been converted to " + "internal image format (%i -> %i)", format, imageFormat); + return imageFormat; +} + +} /* anonymous namespace */ + +int mv_barcode_generate_source_open( + mv_engine_config_h engine_cfg, + const char *message, + mv_barcode_type_e type, + mv_barcode_qr_mode_e qr_enc_mode, + mv_barcode_qr_ecc_e qr_ecc, + int qr_version, + mv_source_h image) +{ + std::string messageStr = std::string(message); + + if (qr_enc_mode == MV_BARCODE_QR_MODE_NUMERIC && + messageStr.find_first_not_of("0123456789") != std::string::npos) + { + LOGE("Barcode message can't be used according to support " + "numeric (0..9) mode: %s", messageStr.c_str()); + return MEDIA_VISION_ERROR_INVALID_DATA; + } + + int error = BARCODE_ERROR_NONE; + if (MV_BARCODE_QR == type && + MV_BARCODE_QR_MODE_ALPHANUMERIC == qr_enc_mode) + { + error = alphanumToUpper(messageStr); + if (BARCODE_ERROR_NONE != error) + { + return convertBarcodeError(error); + } + } + + unsigned char *imageBuffer = NULL; + unsigned int imageWidth = 0u; + unsigned int imageHeight = 0u; + unsigned int imageChannels = 0u; + + int showText = 0; + error = mv_engine_config_get_int_attribute(engine_cfg, "MV_BARCODE_GENERATE_ATTR_TEXT", &showText); + if (error != MEDIA_VISION_ERROR_NONE) + { + LOGW("mv_engine_config_get_int_attribute failed"); + return error; + } + + if (showText == BARCODE_GEN_TEXT_VISIBLE && type == MV_BARCODE_QR) + { + LOGW("QR code generation with visible text is not supported"); + return MEDIA_VISION_ERROR_INVALID_OPERATION; + } + + error = BarcodeGenerator::generateBarcodeToBuffer( + &imageBuffer, + &imageWidth, + &imageHeight, + &imageChannels, + messageStr, + convertBarcodeType(type), + convertEncodingMode(qr_enc_mode), + convertECC(qr_ecc), + qr_version, + showText); + + if (error != BARCODE_ERROR_NONE) + { + LOGE("Barcode generation to the buffer failed"); + if (NULL != imageBuffer) + { + LOGI("Delete temporal buffer"); + delete[] imageBuffer; + } + return convertBarcodeError(error); + } + + const unsigned int imageBufferSize = imageWidth * imageHeight * imageChannels; + + LOGI("Barcode has been generated to the buffer: " + "Buffer size = %ui x %ui; Channels = %ui; Message = %s", + imageWidth, imageHeight, imageChannels, messageStr.c_str()); + + error = mv_source_fill_by_buffer_c( + image, + imageBuffer, + imageBufferSize, + imageWidth, + imageHeight, + MEDIA_VISION_COLORSPACE_RGB888); + + if (error != MEDIA_VISION_ERROR_NONE) + { + LOGE("Meidiavision source fill by generated buffer failed"); + } + + if (NULL != imageBuffer) + { + LOGI("Delete temporal buffer"); + delete[] imageBuffer; + } + + return error; +} + + +int mv_barcode_generate_image_open( + mv_engine_config_h engine_cfg, + const char *message, + int image_width, + int image_height, + mv_barcode_type_e type, + mv_barcode_qr_mode_e qr_enc_mode, + mv_barcode_qr_ecc_e qr_ecc, + int qr_version, + const char *image_path, + mv_barcode_image_format_e image_format) +{ + std::string messageStr = std::string(message); + + if (qr_enc_mode == MV_BARCODE_QR_MODE_NUMERIC && + messageStr.find_first_not_of("0123456789") != std::string::npos) + { + LOGE("Barcode message can't be used according to support " + "numeric (0..9) mode: %s", messageStr.c_str()); + return MEDIA_VISION_ERROR_INVALID_DATA; + } + + int error = BARCODE_ERROR_NONE; + if (MV_BARCODE_QR == type && + MV_BARCODE_QR_MODE_ALPHANUMERIC == qr_enc_mode) + { + error = alphanumToUpper(messageStr); + if (BARCODE_ERROR_NONE != error) + { + return convertBarcodeError(error); + } + } + + int showText = 0; + error = mv_engine_config_get_int_attribute(engine_cfg, "MV_BARCODE_GENERATE_ATTR_TEXT", &showText); + if (error != MEDIA_VISION_ERROR_NONE) + { + LOGW("mv_engine_config_get_int_attribute failed"); + return error; + } + + if (showText == BARCODE_GEN_TEXT_VISIBLE && type == MV_BARCODE_QR) + { + LOGW("QR code generation with visible text is not supported"); + return MEDIA_VISION_ERROR_INVALID_OPERATION; + } + + error = BarcodeGenerator::generateBarcodeToImage( + std::string(image_path), + convertImageFormat(image_format), + image_width, + image_height, + messageStr, + convertBarcodeType(type), + convertEncodingMode(qr_enc_mode), + convertECC(qr_ecc), + qr_version, + showText); + + if (error != BARCODE_ERROR_NONE) + { + LOGE("Barcode generation to the image file failed"); + } + else + { + LOGI("Barcode has been generated to the image: " + "Image size = %ui x %ui; Message = %s", + image_width, image_height, messageStr.c_str()); + } + + return convertBarcodeError(error); +} + diff --git a/mv_barcode/barcode_generator_lic/CMakeLists.txt b/mv_barcode/barcode_generator_lic/CMakeLists.txt new file mode 100644 index 0000000..26f7d2e --- /dev/null +++ b/mv_barcode/barcode_generator_lic/CMakeLists.txt @@ -0,0 +1,25 @@ +project(${MV_BARCODE_GENERATOR_LIB_NAME}) +cmake_minimum_required(VERSION 2.6) + +set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG _DEBUG) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +include_directories("${INC_DIR}") +include_directories("${PROJECT_SOURCE_DIR}/include") +include_directories("${PROJECT_SOURCE_DIR}/src") + +file(GLOB MV_BARCODE_GEN_INCLUDE_LIST "${PROJECT_SOURCE_DIR}/include/*.h") +file(GLOB MV_BARCODE_GEN_SRC_LIST "${PROJECT_SOURCE_DIR}/src/*.c") + +if(FORCED_STATIC_BUILD) + add_library(${PROJECT_NAME} STATIC ${MV_BARCODE_GEN_INCLUDE_LIST} ${MV_BARCODE_GEN_SRC_LIST}) +else() + add_library(${PROJECT_NAME} SHARED ${MV_BARCODE_GEN_INCLUDE_LIST} ${MV_BARCODE_GEN_SRC_LIST}) +endif() + +target_link_libraries(${PROJECT_NAME} ${MV_COMMON_LIB_NAME}) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) diff --git a/mv_barcode/barcode_generator_lic/include/mv_barcode_generate_lic.h b/mv_barcode/barcode_generator_lic/include/mv_barcode_generate_lic.h new file mode 100644 index 0000000..61eca89 --- /dev/null +++ b/mv_barcode/barcode_generator_lic/include/mv_barcode_generate_lic.h @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __TIZEN_MEDIAVISION_BARCODE_GENERATE_LIC_H__ +#define __TIZEN_MEDIAVISION_BARCODE_GENERATE_LIC_H__ + +#include "mv_barcode_generate.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file mv_barcode_generate_lic.h + * @brief This file contains the Media Vision barcode generate module API for + * the licensed module. + */ + +/** + * @brief Generates @ref mv_source_h with barcode image. + * + * @since_tizen 2.4 + * @param [in] engine_cfg The handle to the configuration of the engine + * @param [in] message The message to be encoded in the barcode + * @param [in] image_width The width of the generated image + * @param [in] image_height The height of the generated image + * @param [in] type Type of the barcode to be generated + * @param [in] qr_enc_mode Encoding mode for the message(only for QR codes; + * for 1D barcodes set this parameter to + * @ref MV_BARCODE_QR_MODE_UNAVAILABLE) + * @param [in] qr_ecc Error correction level(only for QR codes; for + * 1D barcodes set this parameter to + * @ref MV_BARCODE_QR_ECC_UNAVAILABLE) + * @param [in] qr_version QR code version(for 1D barcodes set this + * parameter to 0) + * @param [in] image The media source handle which will be used to + * fill by the buffer with generated image + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see mv_barcode_generate_image_lic() + */ +int mv_barcode_generate_source_lic( + mv_engine_config_h engine_cfg, + const char *message, + mv_barcode_type_e type, + mv_barcode_qr_mode_e qr_enc_mode, + mv_barcode_qr_ecc_e qr_ecc, + int qr_version, + mv_source_h image); + +/** + * @brief Generates image file with barcode. + * + * @since_tizen 2.4 + * @param [in] engine_cfg The handle to the configuration of the engine + * @param [in] message The message to be encoded in the barcode + * @param [in] image_width The width of the generated image + * @param [in] image_height The height of the generated image + * @param [in] type Type of the barcode to be generated + * @param [in] qr_enc_mode Encoding mode for the message(only for QR codes; + * for 1D barcodes set this parameter to + * @ref MV_BARCODE_QR_MODE_UNAVAILABLE) + * @param [in] qr_ecc Error correction level(only for QR codes; for + * 1D barcodes set this parameter to + * @ref MV_BARCODE_QR_ECC_UNAVAILABLE) + * @param [in] qr_version QR code version(for 1D barcodes set this + * parameter to 0) + * @param [in] image_path The path to the file that has to be generated + * @param [in] image_format The format of the output image + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see mv_barcode_generate_source_lic() + */ +int mv_barcode_generate_image_lic( + mv_engine_config_h engine_cfg, + const char *message, + int image_width, + int image_height, + mv_barcode_type_e type, + mv_barcode_qr_mode_e qr_enc_mode, + mv_barcode_qr_ecc_e qr_ecc, + int qr_version, + const char *image_path, + mv_barcode_image_format_e image_format); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __TIZEN_MEDIAVISION_BARCODE_GENERATE_LIC_H__ */ diff --git a/mv_barcode/barcode_generator_lic/src/mv_barcode_generate_lic.c b/mv_barcode/barcode_generator_lic/src/mv_barcode_generate_lic.c new file mode 100644 index 0000000..01c2633 --- /dev/null +++ b/mv_barcode/barcode_generator_lic/src/mv_barcode_generate_lic.c @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 "mv_barcode_generate_lic.h" + +int mv_barcode_generate_source_lic( + mv_engine_config_h engine_cfg, + const char *message, + mv_barcode_type_e type, + mv_barcode_qr_mode_e qr_enc_mode, + mv_barcode_qr_ecc_e qr_ecc, + int qr_version, + mv_source_h image) +{ + return MEDIA_VISION_ERROR_NOT_SUPPORTED; +} + +int mv_barcode_generate_image_lic( + mv_engine_config_h engine_cfg, + const char *message, + int image_width, + int image_height, + mv_barcode_type_e type, + mv_barcode_qr_mode_e qr_enc_mode, + mv_barcode_qr_ecc_e qr_ecc, + int qr_version, + const char *image_path, + mv_barcode_image_format_e image_format) +{ + return MEDIA_VISION_ERROR_NOT_SUPPORTED; +} + diff --git a/mv_common/CMakeLists.txt b/mv_common/CMakeLists.txt new file mode 100644 index 0000000..ea3660b --- /dev/null +++ b/mv_common/CMakeLists.txt @@ -0,0 +1,40 @@ +project(${MV_COMMON_LIB_NAME}) +cmake_minimum_required(VERSION 2.6) + +set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG _DEBUG) + +if(NOT SKIP_WARNINGS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror") +endif() + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +include_directories("${INC_DIR}") +include_directories("${PROJECT_SOURCE_DIR}/include") + +file(GLOB MV_COMMON_INC_LIST "${PROJECT_SOURCE_DIR}/include/*.h") +file(GLOB MV_COMMON_SRC_LIST "${PROJECT_SOURCE_DIR}/src/*.cpp") + +find_package(OpenCV REQUIRED core highgui imgproc) + +if(NOT OpenCV_FOUND) + message(SEND_ERROR "Failed to find OpenCV") + return() +else() + include_directories(${OpenCV_INCLUDE_DIRS}) +endif() + +pkg_check_modules(JSONGLIB REQUIRED json-glib-1.0) +include_directories(${JSONGLIB_INCLUDE_DIRS}) + +if(FORCED_STATIC_BUILD) + add_library(${PROJECT_NAME} STATIC ${MV_COMMON_INC_LIST} ${MV_COMMON_SRC_LIST}) +else() + add_library(${PROJECT_NAME} SHARED ${MV_COMMON_INC_LIST} ${MV_COMMON_SRC_LIST}) +endif() + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} jpeg ${OpenCV_LIBS} capi-media-tool tbm json-glib-1.0) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) diff --git a/mv_common/include/EngineConfig.h b/mv_common/include/EngineConfig.h new file mode 100644 index 0000000..1f5f839 --- /dev/null +++ b/mv_common/include/EngineConfig.h @@ -0,0 +1,183 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __ENGINECONFIG_H__ +#define __ENGINECONFIG_H__ + +#include <string> +#include <map> + +#include "mv_common.h" + +/** + * @file EngineConfig.h + * @brief Engine Configuration class definition. + */ + +namespace MediaVision +{ +namespace Common +{ + +typedef std::map<std::string, double>::const_iterator DictDblConstIter; +typedef std::map<std::string, int>::const_iterator DictIntConstIter; +typedef std::map<std::string, bool>::const_iterator DictBoolConstIter; +typedef std::map<std::string, std::string>::const_iterator DictStrConstIter; + +class EngineConfig +{ +public: + /** + * @brief Engine configuration constructor. + * @details Create new engine configuration dictionary and set default + * attributes values. + * + * @since_tizen 2.4 + */ + EngineConfig(); + + /** + * @brief Engine configuration destructor. + */ + virtual ~EngineConfig(); + + /** + * @brief Sets attribute with double value. + * + * @since_tizen 2.4 + * @param [in] key The string name of the attribute + * @param [in] value The double attribute value to be set + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + */ + int setAttribute(const std::string &key, const double value); + + /** + * @brief Sets attribute with integer value. + * + * @since_tizen 2.4 + * @param [in] key The string name of the attribute + * @param [in] value The integer attribute value to be set + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + */ + int setAttribute(const std::string &key, const int value); + + /** + * @brief Sets attribute with boolean value. + * + * @since_tizen 2.4 + * @param [in] key The string name of the attribute + * @param [in] value The boolean attribute value to be set + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + */ + int setAttribute(const std::string &key, const bool value); + + /** + * @brief Sets attribute with string value. + * + * @since_tizen 2.4 + * @param [in] key The string name of the attribute + * @param [in] value The string attribute value to be set + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + */ + int setAttribute(const std::string &key, const std::string &value); + + /** + * @brief Gets double attribute value by attribute name. + * + * @since_tizen 2.4 + * @param [in] key The string name of the attribute + * @param [out] value r The double attribute value to be obtained + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE If attribute with name @a key + * doesn't exist in the engine configuration dictionary + */ + int getDoubleAttribute(const std::string &key, double *value) const; + + /** + * @brief Gets integer attribute value by attribute name. + * + * @since_tizen 2.4 + * @param [in] key The string name of the attribute + * @param [out] value The integer attribute value to be obtained + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE If attribute with name @a key + * doesn't exist in the engine configuration dictionary + */ + int getIntegerAttribute(const std::string &key, int *value) const; + + /** + * @brief Gets boolean attribute value by attribute name. + * + * @since_tizen 2.4 + * @param [in] key The string name of the attribute + * @param [out] value The boolean attribute value to be obtained + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE If attribute with name @a key + * doesn't exist in the engine configuration dictionary + */ + int getBooleanAttribute(const std::string &key, bool *value) const; + + /** + * @brief Gets string attribute value by attribute name. + * + * @since_tizen 2.4 + * @param [in] key The string name of the attribute + * @param [out] value The string attribute value to be obtained + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE If attribute with name @a key + * doesn't exist in the engine configuration dictionary + */ + int getStringAttribute(const std::string &key, std::string *value) const; + +public: + static bool setDefaultConfigFilePath(const std::string& confFilePath); + + static const std::map<std::string, double>& getDefaultDblDict(); + static const std::map<std::string, int>& getDefaultIntDict(); + static const std::map<std::string, bool>& getDefaultBoolDict(); + static const std::map<std::string, std::string>& getDefaultStrDict(); + static int cacheDictionaries( + bool isLazyCache = true, + std::string configFilePath = DefConfigFilePath); + +private: + std::map<std::string, double> m_dblDict; + std::map<std::string, int> m_intDict; + std::map<std::string, bool> m_boolDict; + std::map<std::string, std::string> m_strDict; + +private: + static std::string DefConfigFilePath; + + static std::map<std::string, double> DefDblDict; + static std::map<std::string, int> DefIntDict; + static std::map<std::string, bool> DefBoolDict; + static std::map<std::string, std::string> DefStrDict; + +}; + +} /* Common */ +} /* MediaVision */ + +#endif /* __ENGINECONFIG_H__ */ diff --git a/mv_common/include/ImageHelper.h b/mv_common/include/ImageHelper.h new file mode 100644 index 0000000..8fe27f6 --- /dev/null +++ b/mv_common/include/ImageHelper.h @@ -0,0 +1,226 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __IMAGEHELPER_H__ +#define __IMAGEHELPER_H__ + +#include "mv_common.h" + +#include <cstddef> +#include <cstdio> + +#include <jpeglib.h> + +/** + * @file ImageHelper.h + * @brief ImageHelper class definition. + */ + +namespace MediaVision +{ +namespace Common +{ + +/** + * @class ImageHelper + * @brief Helper class that provides set of useful methods for image management. + */ +class ImageHelper +{ +public: + /** + * @brief Structure to keep information about width, height and colorspace of an image. + * + * @since_tizen 2.4 + */ + struct ImageData { + unsigned int imageWidth; /**< Image width */ + unsigned int imageHeight; /**< Image height */ + mv_colorspace_e imageColorspace; /**< Image colorspace */ + }; + + /** + * @brief Loads image from file to the buffer of unsigned chars. + * + * @since_tizen 2.4 + * @param [in] filePath Path to the image file to be loaded to the + * @a pDataBuffer + * @param [out] pDataBuffer The buffer of unsigned chars where image data + * will be stored + * @param [out] pBufferSize The size of the @a pDataBuffer + * @param [out] pImageData The image data(structure that keeps + * information about image width, height, + * and colorspace) + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + * + * @see ImageHelper::saveImageFromBuffer() + */ + static int loadImageToBuffer( + const char *filePath, + unsigned char **pDataBuffer, + unsigned long *pBufferSize, + ImageData *pImageData); + + /** + * @brief Saves image stored into @a pDataBuffer to the file in jpeg format. + * + * @since_tizen 2.4 + * @param [in] filePath The path to the file where image will be saved + * @param [in] pDataBuffer Data buffer that contains image data + * @param [in] imageData The image data(structure that keeps + * information about image width, height, + * and colorspace) + * @param [in] quality Quality for the output jpeg file(0..100) + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + * + * @see ImageHelper::loadImageToBuffer() + */ + static int saveImageFromBuffer( + const char *filePath, + unsigned char *pDataBuffer, + const ImageData &imageData, + int quality = 100); + + /** + * @brief Draws the rectangle of specified size on the image data buffer. + * + * @since_tizen 2.4 + * @param [in] topLeftVertexX The rectangle top left corner + * x coordinate + * @param [in] topLeftVertexY The rectangle top left corner + * y coordinate + * @param [in] bottomRightVertexX The rectangle bottom right corner + * x coordinate + * @param [in] bottomRightVertexY The rectangle bottom right corner + * y coordinate + * @param [in] thickness The thickness of the rectangle border + * (negative value to draw filled rectangle) + * @param [in] imageData The image data(structure that keeps + * information about image width, height, + * and colorspace). Colorspace has to be + * @c MEDIA_VISION_COLORSPACE_RGB888 + * @param [out] pDataBuffer The pointer to the image data buffer + * which will be used for rectangle drawing + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + */ + static int drawRectangleOnBuffer( + int topLeftVertexX, + int topLeftVertexY, + int bottomRightVertexX, + int bottomRightVertexY, + int thickness, + const ImageData &imageData, + unsigned char *pDataBuffer); + + /** + * @brief Convers libjpeg colorspace to the Tizen 'image util' colorspace. + * + * @since_tizen 2.4 + * @param [in] inColorspace The libjpeg colorspace to be converted. + * @param [out] pOutColorspace The Tizen 'image util' colorspace that + * will be obtained after conversion + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + * + * @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Conversion is impossible. + * + * @see ImageHelper::convertMVColorspaceToJpeglibColorspace() + */ + static int convertJpeglibColorspaceToMVColorspace( + J_COLOR_SPACE inColorspace, + mv_colorspace_e *pOutColorspace); + + /** + * @brief Convers libjpeg colorspace to the Tizen image util colorspace. + * + * @since_tizen 2.4 + * @param [in] inColorspace The Tizen 'image util' colorspace to be + * converted + * @param [out] pOutColorspace The libjpeg colorspace that will be + * obtained after conversion + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + * + * @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Conversion is impossible. + * + * @see ImageHelper::convertJpeglibColorspaceToMVColorspace() + */ + static int convertMVColorspaceToJpeglibColorspace( + mv_colorspace_e inColorspace, + J_COLOR_SPACE *pOutColorspace); + + /** + * @brief Converts image data to the image data of RGB888 colorspace. + * + * @since_tizen 2.4 + * @param [in] pInBuffer Buffer with image data to be converted to + * RGB888 colorspace + * @param [in] imageData The image data(structure that keeps + * information about image width, height, + * and colorspace) for source image + * @param [out] pOutBuffer Buffer with image data to be generated as + * a result of the conversion + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + */ + static int convertBufferToRGB888( + const unsigned char *pInBuffer, + const ImageData &imageData, + unsigned char **pOutBuffer); + + /** + * @brief Determines number of channels(components) for the colorspace. + * + * @since_tizen 2.4 + * @param [in] colorspace Colorspace for which number of + * components will be determined + * @param [out] pComponentsNumber Number of components to be determined + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + */ + static int getNumberOfComponents( + mv_colorspace_e colorspace, + int *pComponentsNumber); + +private: + /** + * @brief Converts buffer with image data in Y800 colorspace format + * to the buffer with image data in RGB888 colorspace format. + * + * @since_tizen 2.4 + * @param [in] pInBuffer The buffer with data in Y800 colorspace format + * @param [in] imageData The image data(structure that keeps + * information about image width, height, and + * colorspace) for source buffer + * @param [out] pOutBuffer The buffer that will contain converted image + * data in RGB888 colorspace format + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + */ + static int convertY800ToRGB( + const unsigned char *pInBuffer, + const ImageData &imageData, + unsigned char **pOutBuffer); + +}; + +} /* namespace Common */ +} /* namespace MediaVision */ + +#endif /* __IMAGEHELPER_H__ */ diff --git a/mv_common/include/MediaSource.h b/mv_common/include/MediaSource.h new file mode 100644 index 0000000..6576e8d --- /dev/null +++ b/mv_common/include/MediaSource.h @@ -0,0 +1,148 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __MEDIASOURCE_H__ +#define __MEDIASOURCE_H__ + +/* Need for a colorspace */ +#include <mv_common.h> + +/** + * @file MediaSource.h + * @brief This file contains the MediaSource class. + */ + +namespace MediaVision +{ +namespace Common +{ + +/** + * @class MediaSource + * @brief The Media Source container + * @details It is class which contains Media Source information. This class + * will be use in the Media Vision as simple image. + */ +class MediaSource +{ +public: + + /** + * @brief Creates a MediaSource. + * @details Default parameters values of the MediaSource will be: zero for + * width, height and buffer size; NULL for buffer; + * MEDIA_VISION_COLORSPACE_INVALID for colorspace. + * + * @since_tizen 2.4 + * + * @see MediaSource::~MediaSource() + */ + MediaSource(); + + /** + * @brief Destroys the MediaSource and releases all its resources. + * + * @since_tizen 2.4 + * + * @see MediaSource::MediaSource() + */ + virtual ~MediaSource(); + + /** + * @brief Clears the MediaSource. + * @details Releases all internal resources and set parameters to default values. + * + * @since_tizen 2.4 + * + * @see MediaSource::MediaSource() + * @see MediaSource::fill() + */ + void clear(void); + + /** + * @brief Fills the MediaSource based on the buffer and metadata. + * + * @since_tizen 2.4 + * @param [in] buffer The buffer of image data + * @param [in] bufferSize The buffer size + * @param [in] width The image width + * @param [in] height The image height + * @param [in] colorspace The image colorspace + * @return true if filled process is ok. Otherwise return false. + * + * @see MediaSource::MediaSource() + * @see MediaSource::clear() + */ + bool fill(const unsigned char *buffer, unsigned int bufferSize, unsigned int + width, unsigned int height, mv_colorspace_e colorspace); + + /** + * @brief Gets data buffer of the MediaSource. + * + * @since_tizen 2.4 + * @return Pointer to the data buffer. + */ + unsigned char *getBuffer(void) const; + + /** + * @brief Gets buffer size of the MediaSource. + * + * @since_tizen 2.4 + * @return Size of data buffer. + */ + unsigned int getBufferSize(void) const; + + /** + * @brief Gets image width of the MediaSource. + * + * @since_tizen 2.4 + * @return Width of image. + */ + unsigned int getWidth(void) const; + + /** + * @brief Gets image height of the MediaSource. + * + * @since_tizen 2.4 + * @return Height of image. + */ + unsigned int getHeight(void) const; + + /** + * @brief Gets image colorspace of the MediaSource. + * + * @since_tizen 2.4 + * @return Colorspace of image. + */ + mv_colorspace_e getColorspace(void) const; + +private: + + unsigned char *m_pBuffer; /**< The data buffer */ + + unsigned int m_bufferSize; /**< The buffer size */ + + unsigned int m_width; /**< The image width */ + + unsigned int m_height; /**< The image height */ + + mv_colorspace_e m_colorspace; /**< The image colorspace */ +}; + +} /* Common */ +} /* MediaVision */ + +#endif /* __MEDIASOURCE_H__ */ diff --git a/mv_common/include/image_helper.h b/mv_common/include/image_helper.h new file mode 100644 index 0000000..7a8dace --- /dev/null +++ b/mv_common/include/image_helper.h @@ -0,0 +1,196 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __IMAGE_HELPER_H__ +#define __IMAGE_HELPER_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include "mv_common.h" + +#ifdef __cplusplus +#include <cstddef> +#include <cstdio> +#else +#include <stddef.h> +#include <stdio.h> +#endif + +#include <jpeglib.h> + +/** + * @file image_helper.h + * @brief Helper functions that provides set of useful methods for image management + * (c wrapper of ImageHelper class). + */ + +/** + * @brief Structure to keep information about width, height and colorspace of an image. + * + * @since_tizen 2.4 + */ +typedef struct { + unsigned int image_width; /**< Image width */ + unsigned int image_height; /**< Image height */ + mv_colorspace_e image_colorspace; /**< Image colorspace */ +} image_data_s; + +/** + * @brief Loads image from file to the buffer of unsigned chars. + * + * @since_tizen 2.4 + * @param [in] file_path Path to the image file to be loaded to the + * @a pDataBuffer + * @param [out] data_buffer The buffer of unsigned chars where image data + * will be stored + * @param [out] buffer_size The size of the @a pDataBuffer + * @param [out] image_data The image data(structure that keeps + * information about image width, height, + * and colorspace) + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + * + * @see save_image_from_buffer() + */ +int load_image_to_buffer( + const char *file_path, + unsigned char **data_buffer, + unsigned long *buffer_size, + image_data_s *image_data); + +/** + * @brief Saves image stored into @a pDataBuffer to the file in jpeg format. + * + * @since_tizen 2.4 + * @param [in] file_path The path to the file where image will be saved + * @param [in] data_buffer Data buffer that contains image data + * @param [in] image_data The image data(structure that keeps + * information about image width, height, + * and colorspace) + * @param [in] quality Quality for the output jpeg file(0..100) + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + * + * @see load_image_to_buffer() + */ +int save_image_from_buffer( + const char *file_path, + unsigned char *data_buffer, + const image_data_s *image_data, + int quality); + +/** + * @brief Draws the rectangle of specified size on the image data buffer. + * + * @since_tizen 2.4 + * @param [in] tl_vertex_x The rectangle top left corner x coordinate + * @param [in] tl_vertex_y The rectangle top left corner y coordinate + * @param [in] br_vertex_x The rectangle bottom right corner x coordinate + * @param [in] br_vertex_y The rectangle bottom right corner y coordinate + * @param [in] thickness The thickness of the rectangle border(negative + * value to draw filled rectangle) + * @param [in] image_data The image data(structure that keeps information + * about image width, height, and colorspace). + * Colorspace has to be @c MEDIA_VISION_COLORSPACE_RGB888 + * @param [out] data_buffer The pointer to the image data buffer which will + * be used for rectangle drawing + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + */ +int draw_rectangle_on_buffer( + int tl_vertex_x, + int tl_vertex_y, + int br_vertex_x, + int br_vertex_y, + int thickness, + const image_data_s *image_data, + unsigned char *data_buffer); + +/** + * @brief Convers libjpeg colorspace to the Tizen 'image util' colorspace. + * + * @since_tizen 2.4 + * @param [in] in_colorspace The libjpeg colorspace to be converted. + * @param [out] out_colorspace The Tizen 'image util' colorspace that + * will be obtained after conversion + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + * @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Conversion is impossible. + * + * @see convert_mv_colorspace_to_jpeglib_colorspace() + */ +int convert_jpeglib_colorspace_to_mv_colorspace( + J_COLOR_SPACE in_colorspace, + mv_colorspace_e *out_colorspace); + +/** + * @brief Convers libjpeg colorspace to the Tizen image util colorspace. + * + * @since_tizen 2.4 + * @param [in] in_colorspace The Tizen 'image util' colorspace to be + * converted + * @param [out] out_colorspace The libjpeg colorspace that will be + * obtained after conversion + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + * @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Conversion is impossible. + * + * @see convert_jpeglib_colorspace_to_mv_colorspace() + */ +int convert_mv_colorspace_to_jpeglib_colorspace( + mv_colorspace_e in_colorspace, + J_COLOR_SPACE *out_colorspace); + +/** + * @brief Converts image data to the image data of RGB888 colorspace. + * + * @since_tizen 2.4 + * @param [in] in_buffer Buffer with image data to be converted to + * RGB888 colorspace + * @param [in] image_data The image data(structure that keeps + * information about image width, height, + * and colorspace) for source image + * @param [out] out_buffer Buffer with image data to be generated as + * a result of the conversion + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + */ +int convert_buffer_to_RGB888( + const unsigned char *in_buffer, + const image_data_s *image_data, + unsigned char **out_buffer); + +/** + * @brief Determines number of channels(components) for the colorspace. + * + * @since_tizen 2.4 + * @param [in] colorspace Colorspace for which number of + * components will be determined + * @param [out] components_number Number of components to be determined + * @return @c MEDIA_VISION_ERROR_NONE on success, \n + * otherwise a negative error value + */ +int get_number_of_components( + mv_colorspace_e colorspace, + int *components_number); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __IMAGE_HELPER_H__ */ diff --git a/mv_common/include/mv_common_c.h b/mv_common/include/mv_common_c.h new file mode 100644 index 0000000..8d8f16b --- /dev/null +++ b/mv_common/include/mv_common_c.h @@ -0,0 +1,492 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __TIZEN_MEDIAVISION_COMMON_C_H__ +#define __TIZEN_MEDIAVISION_COMMON_C_H__ + +#include "mv_common.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file mv_common_c.h + * @brief This file contains the Media Vision Common module API. + */ + +/** + * @brief Creates a source handle. + * + * @since_tizen 2.4 + * @remarks You must release @a source by using @ref mv_destroy_source_c(). + * @param [out] source A new handle to the source + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory + * + * @see mv_destroy_source_c() + */ +int mv_create_source_c( + mv_source_h *source); + +/** + * @brief Destroys the source handle and releases all its resources. + * + * @since_tizen 2.4 + * @param [in] source The handle to the source to be destroyed + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see mv_create_source_c() + */ +int mv_destroy_source_c( + mv_source_h source); + +/** + * @brief Fills the media source based on the media packet. + * + * @since_tizen 2.4 + * @param [in, out] source The handle to the source + * @param [in] media_packet The handle to the media packet from which + * will be filled the source + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported media format + * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory + * + * @pre Create a source handle by calling @ref mv_create_source_c() + * + * @see mv_create_source_c() + * @see mv_destroy_source_c() + */ +int mv_source_fill_by_media_packet_c( + mv_source_h source, + media_packet_h media_packet); + +/** + * @brief Fills the media source based on the buffer and metadata. + * + * @since_tizen 2.4 + * @param [in, out] source The handle to the source + * @param [in] data_buffer The buffer of image data + * @param [in] buffer_size The buffer size + * @param [in] image_width The image width + * @param [in] image_height The image height + * @param [in] image_colorspace The image colorspace + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory + * + * @pre Create a source handle by calling @ref mv_create_source_c() + * + * @see mv_source_clear_c() + */ +int mv_source_fill_by_buffer_c( + mv_source_h source, + unsigned char *data_buffer, + unsigned int buffer_size, + unsigned int image_width, + unsigned int image_height, + mv_colorspace_e image_colorspace); + +/** + * @brief Clears the buffer of the media source. + * + * @since_tizen 2.4 + * @param [in] source The handle to the source + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see mv_source_fill_by_buffer_c() + */ +int mv_source_clear_c( + mv_source_h source); + +/** + * @brief Gets buffer of the media source. + * + * @since_tizen 2.4 + * @remarks Note that the retrieved buffer will be destroyed when + * @ref mv_destroy_source_c() or @ref mv_source_clear_c() function + * is called for the @a source. + * + * @param [in] source The handle to the source + * @param [out] data_buffer The buffer of the source + * @param [out] buffer_size The size of buffer + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see mv_source_get_width_c() + * @see mv_source_get_height_c() + * @see mv_source_get_colorspace_c() + */ +int mv_source_get_buffer_c( + mv_source_h source, + unsigned char **data_buffer, + unsigned int *buffer_size); + +/** + * @brief Gets height of the media source. + * + * @since_tizen 2.4 + * @param [in] source The handle to the source + * @param [out] image_height The height of the source + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see mv_source_get_width_c() + * @see mv_source_get_colorspace_c() + * @see mv_source_get_buffer_c() + */ +int mv_source_get_height_c( + mv_source_h source, + unsigned int *image_height); + +/** + * @brief Gets width of the media source. + * + * @since_tizen 2.4 + * @param [in] source The handle to the source + * @param [out] image_width The width of the source + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see mv_source_get_height_c() + * @see mv_source_get_colorspace_c() + * @see mv_source_get_buffer_c() + */ +int mv_source_get_width_c( + mv_source_h source, + unsigned int *image_width); + +/** + * @brief Gets colorspace of the media source. + * + * @since_tizen 2.4 + * @param [in] source The handle to the source + * @param [out] image_colorspace The colorspace of the source + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see mv_source_get_width_c() + * @see mv_source_get_height_c() + * @see mv_source_get_buffer_c() + */ +int mv_source_get_colorspace_c( + mv_source_h source, + mv_colorspace_e *image_colorspace); + +/** + * @brief Creates the handle to the configuration of engine. + * + * @since_tizen 2.4 + * @param [out] engine_cfg The handle to the engine to be created + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory + * + * @see mv_engine_config_h + * @see mv_destroy_engine_config_c() + * @see mv_engine_config_set_double_attribute_c() + * @see mv_engine_config_set_int_attribute_c() + * @see mv_engine_config_set_bool_attribute_c() + * @see mv_engine_config_set_string_attribute_c() + * @see mv_engine_config_get_double_attribute_c() + * @see mv_engine_config_get_int_attribute_c() + * @see mv_engine_config_get_bool_attribute_c() + * @see mv_engine_config_get_string_attribute_c() + */ +int mv_create_engine_config_c( + mv_engine_config_h *engine_cfg); + +/** + * @brief Destroys the engine configuration handle and releases all its + * resources. + * + * @since_tizen 2.4 + * @param [in] engine_cfg The handle to the engine configuration + * to be destroyed + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see mv_engine_config_h + * @see mv_create_engine_config_c() + */ +int mv_destroy_engine_config_c( + mv_engine_config_h engine_cfg); + +/** + * @brief Sets the double attribute to the configuration. + * + * @since_tizen 2.4 + * @param [in] engine_cfg Engine configuration for which @a value has + * to be set + * @param [in] name String key of the attribute will be used for + * storing the @a value into configuration + * dictionary + * @param [in] value The double value of the attribute + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see mv_engine_config_get_double_attribute_c() + * @see mv_engine_config_set_int_attribute_c() + * @see mv_engine_config_set_bool_attribute_c() + * @see mv_engine_config_set_string_attribute_c() + */ +int mv_engine_config_set_double_attribute_c( + mv_engine_config_h engine_cfg, + const char *name, + double value); + +/** + * @brief Sets the integer attribute to the configuration. + * + * @since_tizen 2.4 + * @param [in] engine_cfg Engine configuration for which @a value has + * to be set + * @param [in] name String key of the attribute will be used for + * storing the @a value into configuration + * dictionary + * @param [in] value The integer value of the attribute + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see mv_engine_config_get_int_attribute_c() + * @see mv_engine_config_set_double_attribute_c() + * @see mv_engine_config_set_bool_attribute_c() + * @see mv_engine_config_set_string_attribute_c() + */ +int mv_engine_config_set_int_attribute_c( + mv_engine_config_h engine_cfg, + const char *name, + int value); + +/** + * @brief Sets the boolean attribute to the configuration. + * + * @since_tizen 2.4 + * @param [in] engine_cfg Engine configuration for which @a value has + * to be set + * @param [in] name String key of the attribute will be used for + * storing the @a value into configuration + * dictionary + * @param [in] value The boolean value of the attribute + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see mv_engine_config_get_bool_attribute_c() + * @see mv_engine_config_set_double_attribute_c() + * @see mv_engine_config_set_int_attribute_c() + * @see mv_engine_config_set_string_attribute_c() + */ +int mv_engine_config_set_bool_attribute_c( + mv_engine_config_h engine_cfg, + const char *name, + bool attribute); + +/** + * @brief Sets the string attribute to the configuration. + * + * @since_tizen 2.4 + * @param [in] engine_cfg Engine configuration for which @a value has + * to be set + * @param [in] name String key of the attribute will be used for + * storing the @a value into configuration + * dictionary + * @param [in] value The string value of the attribute + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see mv_engine_config_get_string_attribute_c() + * @see mv_engine_config_set_double_attribute_c() + * @see mv_engine_config_set_int_attribute_c() + * @see mv_engine_config_set_bool_attribute_c() + */ +int mv_engine_config_set_string_attribute_c( + mv_engine_config_h engine_cfg, + const char *name, + const char *value); + +/** + * @brief Gets the double attribute from the configuration dictionary. + * + * @since_tizen 2.4 + * @param [in] engine_cfg Engine configuration from which @a value + * has to be gotten + * @param [in] name String key of the attribute will be used for + * getting the @a value from the + * configuration dictionary + * @param [out] value The attribute to be filled with double value + * from dictionary + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE Parameter key isn't available + * + * @see mv_engine_config_set_double_attribute_c() + * @see mv_engine_config_get_int_attribute_c() + * @see mv_engine_config_get_bool_attribute_c() + * @see mv_engine_config_get_string_attribute_c() + */ +int mv_engine_config_get_double_attribute_c( + mv_engine_config_h engine_cfg, + const char *name, + double *value); + +/** + * @brief Gets the integer attribute from the configuration dictionary. + * + * @since_tizen 2.4 + * @param [in] engine_cfg Engine configuration from which @a value + * has to be gotten + * @param [in] name String key of the attribute will be used for + * getting the @a value from the + * configuration dictionary + * @param [out] value The attribute to be filled with integer value + * from dictionary + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE Parameter key isn't available + * + * @see mv_engine_config_set_int_attribute_c() + * @see mv_engine_config_get_double_attribute_c() + * @see mv_engine_config_get_bool_attribute_c() + * @see mv_engine_config_get_string_attribute_c() + */ +int mv_engine_config_get_int_attribute_c( + mv_engine_config_h engine_cfg, + const char *name, + int *value); + +/** + * @brief Gets the boolean attribute from the configuration dictionary. + * + * @since_tizen 2.4 + * @param [in] engine_cfg Engine configuration from which @a value + * has to be gotten + * @param [in] name String key of the attribute will be used for + * getting the @a value from the + * configuration dictionary + * @param [out] value The attribute to be filled with boolean value + * from dictionary + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE Parameter key isn't available + * + * @see mv_engine_config_set_bool_attribute_c() + * @see mv_engine_config_get_double_attribute_c() + * @see mv_engine_config_get_int_attribute_c() + * @see mv_engine_config_get_string_attribute_c() + */ +int mv_engine_config_get_bool_attribute_c( + mv_engine_config_h engine_cfg, + const char *name, + bool *value); + +/** + * @brief Gets the string attribute from the configuration dictionary. + * + * @since_tizen 2.4 + * @remarks Function allocates memory required for output @a value, so + * it has to be removed by the user himself. + * @param [in] engine_cfg Engine configuration from which @a value + * has to be gotten + * @param [in] name String key of the attribute will be used for + * getting the @a value from the + * configuration dictionary + * @param [out] value The attribute to be filled with string value + * from dictionary + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE Parameter key isn't available + * + * @see mv_engine_config_set_string_attribute_c() + * @see mv_engine_config_get_double_attribute_c() + * @see mv_engine_config_get_int_attribute_c() + * @see mv_engine_config_get_bool_attribute_c() + */ +int mv_engine_config_get_string_attribute_c( + mv_engine_config_h engine_cfg, + const char *name, + char **value); + +/** + * @brief Traverses the list of supported attribute names and types. + * @details Using this function names of supported attributes can be obtained. + * Names of the attributes can be used with @ref mv_engine_config_h + * related getters and setters to get/set appropriate attribute values. + * + * @since_tizen 2.4 + * @remarks If @a callback is called zero times after + * @ref mv_engine_config_foreach_supported_attribute() call, then + * engine configuration is not supported and setting of attributes will + * cause no effect. In this case for all Media Vision functions which + * require @ref mv_engine_config_h handle as in parameter this + * parameter can be set NULL. + * @remarks If @a callback is called at least once, then attribute names and + * types obtained in the @ref mv_supported_attribute_cb callback can be + * changed after mv_engine_config_h handle creation (with + * @ref mv_create_engine_config_c() function) by corresponding setters. + * Although, if attributes aren't changed by setters, then default + * values will be used.\n + * Changing of attribute values will affect internal functionality + * provided by concrete library underlying Media Vision API. + * @param [in] callback The iteration callback function + * @param [in] user_data The user data to be passed to the callback function + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * (@a callback can't be NULL) + * @retval #MEDIA_VISION_ERROR_NO_DATA Can't determine list of supported attributes + * + * @see mv_engine_config_set_double_attribute_c() + * @see mv_engine_config_set_int_attribute_c() + * @see mv_engine_config_set_bool_attribute_c() + * @see mv_engine_config_set_string_attribute_c() + * @see mv_engine_config_get_double_attribute_c() + * @see mv_engine_config_get_int_attribute_c() + * @see mv_engine_config_get_bool_attribute_c() + * @see mv_engine_config_get_string_attribute_c() + */ +int mv_engine_config_foreach_supported_attribute_c( + mv_supported_attribute_cb callback, + void *user_data); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __TIZEN_MEDIAVISION_COMMON_C_H__ */ diff --git a/mv_common/src/EngineConfig.cpp b/mv_common/src/EngineConfig.cpp new file mode 100644 index 0000000..97c8f76 --- /dev/null +++ b/mv_common/src/EngineConfig.cpp @@ -0,0 +1,364 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 "EngineConfig.h" + +#include <mv_private.h> + +#include <json-glib/json-glib.h> + +/** + * @file EngineConfig.cpp + * @brief Engine Configuration class methods implementation. + */ + +namespace MediaVision +{ +namespace Common +{ + +std::string EngineConfig::DefConfigFilePath = + std::string("/usr/share/config/capi-media-vision/media-vision-config.json"); + +std::map<std::string, double> EngineConfig::DefDblDict; +std::map<std::string, int> EngineConfig::DefIntDict; +std::map<std::string, bool> EngineConfig::DefBoolDict; +std::map<std::string, std::string> EngineConfig::DefStrDict; + +EngineConfig::EngineConfig() +{ + // Force load default attributes from configuration file + cacheDictionaries(false); + + // Insert default attribute values into creating engine configuration + m_dblDict.insert(getDefaultDblDict().begin(), getDefaultDblDict().end()); + m_intDict.insert(getDefaultIntDict().begin(), getDefaultIntDict().end()); + m_boolDict.insert(getDefaultBoolDict().begin(), getDefaultBoolDict().end()); + m_strDict.insert(getDefaultStrDict().begin(), getDefaultStrDict().end()); +} + +EngineConfig::~EngineConfig() +{ + ; /* NULL */ +} + +int EngineConfig::setAttribute(const std::string& key, const double value) +{ + LOGI("Set double attribute for the engine config %p. [%s] = %f", + this, key.c_str(), value); + + if (m_dblDict.find(key) == m_dblDict.end()) + { + LOGE("Double attribute [%s] can't be set because isn't supported", key.c_str()); + return MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE; + } + + m_dblDict[key] = value; + + return MEDIA_VISION_ERROR_NONE; +} + +int EngineConfig::setAttribute(const std::string& key, const int value) +{ + LOGI("Set integer attribute for the engine config %p. [%s] = %i", + this, key.c_str(), value); + + if (m_intDict.find(key) == m_intDict.end()) + { + LOGE("Integer attribute [%s] can't be set because isn't supported", key.c_str()); + return MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE; + } + + m_intDict[key] = value; + + return MEDIA_VISION_ERROR_NONE; +} + +int EngineConfig::setAttribute(const std::string& key, const bool value) +{ + LOGI("Set boolean attribute for the engine config %p. [%s] = %s", + this, key.c_str(), value ? "TRUE" : "FALSE"); + + if (m_boolDict.find(key) == m_boolDict.end()) + { + LOGE("Boolean attribute [%s] can't be set because isn't supported", key.c_str()); + return MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE; + } + + m_boolDict[key] = value; + + return MEDIA_VISION_ERROR_NONE; +} + +int EngineConfig::setAttribute(const std::string& key, const std::string& value) +{ + LOGI("Set string attribute for the engine config %p. [%s] = %s", + this, key.c_str(), value.c_str()); + + if (m_strDict.find(key) == m_strDict.end()) + { + LOGE("String attribute [%s] can't be set because isn't supported", key.c_str()); + return MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE; + } + + m_strDict[key] = value; + + return MEDIA_VISION_ERROR_NONE; +} + +int EngineConfig::getDoubleAttribute(const std::string& key, double *value) const +{ + DictDblConstIter dictIter = m_dblDict.find(key); + if (dictIter == m_dblDict.end()) + { + LOGE("Attempt to access to the unsupported double attribute [%s] " + "of the engine config %p", key.c_str(), this); + return MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE; + } + + LOGD("Get double attribute from the engine config %p. [%s] = %f", + this, dictIter->first.c_str(), dictIter->second); + + *value = dictIter->second; + + return MEDIA_VISION_ERROR_NONE; +} + +int EngineConfig::getIntegerAttribute(const std::string& key, int *value) const +{ + DictIntConstIter dictIter = m_intDict.find(key); + if (dictIter == m_intDict.end()) + { + LOGE("Attempt to access to the unsupported integer attribute [%s] " + "of the engine config %p", key.c_str(), this); + return MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE; + } + + LOGD("Get integer attribute from the engine config %p. [%s] = %i", + this, dictIter->first.c_str(), dictIter->second); + + *value = dictIter->second; + + return MEDIA_VISION_ERROR_NONE; +} + +int EngineConfig::getBooleanAttribute(const std::string& key, bool *value) const +{ + DictBoolConstIter dictIter = m_boolDict.find(key); + if (dictIter == m_boolDict.end()) + { + LOGE("Attempt to access to the unsupported boolean attribute [%s] " + "of the engine config %p", key.c_str(), this); + return MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE; + } + + LOGD("Get boolean attribute from the engine config %p. [%s] = %s", + this, dictIter->first.c_str(), dictIter->second ? "TRUE" : "FALSE"); + + *value = dictIter->second; + + return MEDIA_VISION_ERROR_NONE; +} + +int EngineConfig::getStringAttribute(const std::string& key, std::string *value) const +{ + DictStrConstIter dictIter = m_strDict.find(key); + if (dictIter == m_strDict.end()) + { + LOGE("Attempt to access to the unsupported string attribute [%s] " + "of the engine config %p", key.c_str(), this); + return MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE; + } + + LOGD("Get string attribute from the engine config %p. [%s] = %s", + this, dictIter->first.c_str(), dictIter->second.c_str()); + + *value = dictIter->second; + + return MEDIA_VISION_ERROR_NONE; +} + +// static + +bool EngineConfig::setDefaultConfigFilePath(const std::string& confFilePath) +{ + if (0 != DefConfigFilePath.compare(confFilePath)) + { + DefConfigFilePath = confFilePath; + return true; + } + + return false; +} + +const std::map<std::string, double>& EngineConfig::getDefaultDblDict() +{ + cacheDictionaries(); + + return DefDblDict; +} + +const std::map<std::string, int>& EngineConfig::getDefaultIntDict() +{ + cacheDictionaries(); + + return DefIntDict; +} + +const std::map<std::string, bool>& EngineConfig::getDefaultBoolDict() +{ + cacheDictionaries(); + + return DefBoolDict; +} + +const std::map<std::string, std::string>& EngineConfig::getDefaultStrDict() +{ + cacheDictionaries(); + + return DefStrDict; +} + +int EngineConfig::cacheDictionaries(bool isLazyCache, std::string configFilePath) +{ + static bool isCached = false; + if (!isLazyCache || !isCached) + { + LOGI("Start to cache default attributes from engine configuration file."); + + DefDblDict.clear(); + DefIntDict.clear(); + DefBoolDict.clear(); + DefStrDict.clear(); + + const char *conf_file = configFilePath.c_str(); + JsonParser *parser; + GError *error = NULL; + + parser = json_parser_new(); + json_parser_load_from_file(parser, conf_file, &error); + if (error) + { + LOGW("Unable to parse file '%s': %s\n", conf_file, error->message); + g_error_free(error); + g_object_unref(parser); + return MEDIA_VISION_ERROR_NO_DATA; + } + + JsonNode *root = json_parser_get_root(parser); + if (JSON_NODE_OBJECT != json_node_get_node_type(root)) + { + LOGW("Can't parse tests configuration file. " + "Incorrect json markup."); + g_object_unref(parser); + return MEDIA_VISION_ERROR_NO_DATA; + } + + JsonObject *jobj = json_node_get_object(root); + + if (!json_object_has_member(jobj, "attributes")) + { + LOGW("Can't parse tests configuration file. " + "No 'attributes' section."); + g_object_unref(parser); + return MEDIA_VISION_ERROR_NO_DATA; + } + + JsonNode *attr_node = + json_object_get_member(jobj, "attributes"); + + if (JSON_NODE_ARRAY != json_node_get_node_type(attr_node)) + { + LOGW("Can't parse tests configuration file. " + "'attributes' section isn't array."); + g_object_unref(parser); + return MEDIA_VISION_ERROR_NO_DATA; + } + + JsonArray *attr_array = json_node_get_array(attr_node); + + const guint attr_num = json_array_get_length(attr_array); + + guint attrInd = 0; + for (; attrInd < attr_num; ++attrInd) + { + JsonNode *attr_node = json_array_get_element(attr_array, attrInd); + + if (JSON_NODE_OBJECT != json_node_get_node_type(attr_node)) + { + LOGW("Attribute %u wasn't parsed from json file.", attrInd); + continue; + } + + JsonObject *attr_obj = json_node_get_object(attr_node); + + if (!json_object_has_member(attr_obj, "name") || + !json_object_has_member(attr_obj, "type") || + !json_object_has_member(attr_obj, "value")) + { + LOGW("Attribute %u wasn't parsed from json file.", attrInd); + continue; + } + + const char *nameStr = + (char*)json_object_get_string_member(attr_obj, "name"); + const char *typeStr = + (char*)json_object_get_string_member(attr_obj, "type"); + + if(NULL != nameStr && NULL != typeStr) + { + if (0 == strcmp("double", typeStr)) + { + DefDblDict[std::string(nameStr)] = + (double)json_object_get_double_member(attr_obj, "value"); + } + else if (0 == strcmp("integer", typeStr)) + { + DefIntDict[std::string(nameStr)] = + (int)json_object_get_int_member(attr_obj, "value"); + } + else if (0 == strcmp("boolean", typeStr)) + { + DefBoolDict[std::string(nameStr)] = + json_object_get_boolean_member(attr_obj, "value") ? true : false; + } + else if (0 == strcmp("string", typeStr)) + { + const char *valueStr = (char*)json_object_get_string_member(attr_obj, "value"); + + if(NULL != valueStr) + { + DefStrDict[std::string(nameStr)] = valueStr; + } + } + else + { + LOGW("Attribute %i:%s wasn't parsed from json file. " + "Type isn't supported.", attrInd, nameStr); + continue; + } + } + } + + g_object_unref(parser); + isCached = true; + } + + return MEDIA_VISION_ERROR_NONE; +} + +} /* namespace Common */ +} /* namespace MediaVision */ diff --git a/mv_common/src/ImageHelper.cpp b/mv_common/src/ImageHelper.cpp new file mode 100644 index 0000000..64b149c --- /dev/null +++ b/mv_common/src/ImageHelper.cpp @@ -0,0 +1,356 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 "ImageHelper.h" + +#include <cstring> + +#include <setjmp.h> + +#include <opencv2/core/core.hpp> +#include <opencv2/highgui/highgui.hpp> +#include <opencv2/imgproc/imgproc.hpp> + +/** + * @file ImageHelper.cpp + * @brief The ImageHelper class methods implementation. + */ + +namespace MediaVision +{ +namespace Common +{ + +static const int OpenCVChannels = 3; +static const mv_colorspace_e OpenCVColor = MEDIA_VISION_COLORSPACE_RGB888; + +static std::vector<std::string> getJPGExtensions() +{ + std::vector<std::string> extensions; + extensions.push_back(".jpg"); + extensions.push_back(".jpe"); + extensions.push_back(".jpeg"); + return extensions; +} + +int ImageHelper::loadImageToBuffer( + const char *filePath, + unsigned char **pDataBuffer, + unsigned long *pBufferSize, + ImageData *pImageData) +{ + if (filePath == NULL || pDataBuffer == NULL || + pBufferSize == NULL || pImageData == NULL) + { + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + cv::Mat image; + image = cv::imread(filePath); + + if (!image.data) + { + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + cv::cvtColor(image, image, CV_BGR2RGB); + + *pBufferSize = image.total() * image.elemSize(); + (*pDataBuffer) = new unsigned char[*pBufferSize]; + std::memcpy(*pDataBuffer, image.data, *pBufferSize); + + pImageData->imageWidth = image.cols; + pImageData->imageHeight = image.rows; + pImageData->imageColorspace = OpenCVColor; + + return MEDIA_VISION_ERROR_NONE; +} + +int ImageHelper::saveImageFromBuffer( + const char *filePath, + unsigned char *pDataBuffer, + const ImageData& imageData, + int quality) +{ + if (filePath == NULL || pDataBuffer == NULL) + { + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + static const std::string defaultFilePath = "out"; + static const std::vector<std::string> jpgExtensions = getJPGExtensions(); + + bool rightExtensionFlag = false; + + std::string resultFilePath(filePath); + if (resultFilePath.empty()) + { + resultFilePath = defaultFilePath; + } + else + { + for (size_t extNum = 0; extNum < jpgExtensions.size(); ++extNum) + { + if (resultFilePath.size() >= jpgExtensions[extNum].size()) + { + std::string givenExtension = resultFilePath.substr( + resultFilePath.length() - jpgExtensions[extNum].size(), + jpgExtensions[extNum].size()); + + std::transform( + givenExtension.begin(), givenExtension.end(), + givenExtension.begin(), ::tolower); + + if (givenExtension == jpgExtensions[extNum]) + { + rightExtensionFlag = true; + break; + } + } + } + } + + if (!rightExtensionFlag) + { + resultFilePath += jpgExtensions[0]; + } + + if (quality <= 0 || quality > 100) + { + quality = 100; + } + + struct jpeg_compress_struct cinfo; + struct jpeg_error_mgr jerr; + FILE *outfile = NULL; + JSAMPROW rowPointer[1]; + int rowStride = 0; + + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_compress(&cinfo); + + if ((outfile = fopen(resultFilePath.data(), "wb")) == NULL) + { + jpeg_destroy_compress(&cinfo); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + jpeg_stdio_dest(&cinfo, outfile); + + cinfo.image_width = imageData.imageWidth; + cinfo.image_height = imageData.imageHeight; + + int numberOfComponents = 0; + if (MEDIA_VISION_ERROR_NONE != + getNumberOfComponents( + imageData.imageColorspace, + &numberOfComponents)) + { + fclose(outfile); + jpeg_destroy_compress(&cinfo); + return MEDIA_VISION_ERROR_NOT_SUPPORTED; + } + + cinfo.input_components = numberOfComponents; + + J_COLOR_SPACE colorspace = JCS_UNKNOWN; + if (MEDIA_VISION_ERROR_NONE != + convertMVColorspaceToJpeglibColorspace( + imageData.imageColorspace, + &colorspace)) + { + return MEDIA_VISION_ERROR_NOT_SUPPORTED; + } + + cinfo.in_color_space = colorspace; + + jpeg_set_defaults(&cinfo); + jpeg_set_quality(&cinfo, quality, TRUE); + jpeg_start_compress(&cinfo, TRUE); + + rowStride = imageData.imageWidth * cinfo.input_components; + + while (cinfo.next_scanline < cinfo.image_height) + { + rowPointer[0] = &pDataBuffer[cinfo.next_scanline * rowStride]; + (void) jpeg_write_scanlines(&cinfo, rowPointer, 1); + } + + jpeg_finish_compress(&cinfo); + fclose(outfile); + jpeg_destroy_compress(&cinfo); + + return MEDIA_VISION_ERROR_NONE; +} + +int ImageHelper::drawRectangleOnBuffer( + int topLeftVertexX, + int topLeftVertexY, + int bottomRightVertexX, + int bottomRightVertexY, + int thickness, + const ImageData& imageData, + unsigned char *pDataBuffer) +{ + if (NULL == pDataBuffer) + { + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + cv::Mat cvImage(imageData.imageHeight, imageData.imageWidth, CV_8UC(OpenCVChannels), pDataBuffer); + cv::rectangle( + cvImage, + cv::Point(topLeftVertexX, topLeftVertexY), + cv::Point(bottomRightVertexX, bottomRightVertexY), + cv::Scalar(255, 0, 0), + thickness); + + return MEDIA_VISION_ERROR_NONE; +} + +int ImageHelper::convertJpeglibColorspaceToMVColorspace( + J_COLOR_SPACE inColorspace, + mv_colorspace_e *pOutColorspace) +{ + if (pOutColorspace == NULL) + { + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + switch(inColorspace) + { + case JCS_GRAYSCALE: + (*pOutColorspace) = MEDIA_VISION_COLORSPACE_Y800; + return MEDIA_VISION_ERROR_NONE; + case JCS_RGB: + (*pOutColorspace) = MEDIA_VISION_COLORSPACE_RGB888; + return MEDIA_VISION_ERROR_NONE; + default: + return MEDIA_VISION_ERROR_NOT_SUPPORTED; + } + + return MEDIA_VISION_ERROR_NONE; +} + +int ImageHelper::convertMVColorspaceToJpeglibColorspace( + mv_colorspace_e inColorspace, + J_COLOR_SPACE *pOutColorspace) +{ + if (pOutColorspace == NULL) + { + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + switch (inColorspace) + { + case MEDIA_VISION_COLORSPACE_Y800: + (*pOutColorspace) = JCS_GRAYSCALE; + return MEDIA_VISION_ERROR_NONE; + case MEDIA_VISION_COLORSPACE_RGB888: + (*pOutColorspace) = JCS_RGB; + return MEDIA_VISION_ERROR_NONE; + default: + return MEDIA_VISION_ERROR_NOT_SUPPORTED; + } + + return MEDIA_VISION_ERROR_NOT_SUPPORTED; +} + +int ImageHelper::convertBufferToRGB888( + const unsigned char *pInBuffer, + const ImageData& imageData, + unsigned char **pOutBuffer) +{ + if (pInBuffer == NULL || pOutBuffer == NULL) + { + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + switch(imageData.imageColorspace) + { + case MEDIA_VISION_COLORSPACE_Y800: + return convertY800ToRGB(pInBuffer, imageData, pOutBuffer); + case MEDIA_VISION_COLORSPACE_RGB888: + { + int numberOfComponents = 0; + getNumberOfComponents( + MEDIA_VISION_COLORSPACE_RGB888, &numberOfComponents); + const int dataSize = + imageData.imageHeight * imageData.imageWidth * numberOfComponents; + (*pOutBuffer) = new unsigned char[dataSize]; + std::memcpy(*pOutBuffer, pInBuffer, dataSize); + return MEDIA_VISION_ERROR_NONE; + } + default: + return MEDIA_VISION_ERROR_NOT_SUPPORTED; + } + + return MEDIA_VISION_ERROR_NOT_SUPPORTED; +} + +int ImageHelper::getNumberOfComponents( + mv_colorspace_e colorspace, + int *pComponentsNumber) +{ + if (pComponentsNumber == NULL) + { + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + // todo: support more colorspaces: + switch (colorspace) + { + case MEDIA_VISION_COLORSPACE_Y800: + (*pComponentsNumber) = 1; + return MEDIA_VISION_ERROR_NONE; + case MEDIA_VISION_COLORSPACE_RGB888: + (*pComponentsNumber) = 3; + return MEDIA_VISION_ERROR_NONE; + default: + return MEDIA_VISION_ERROR_NOT_SUPPORTED; + } + + return MEDIA_VISION_ERROR_NOT_SUPPORTED; +} + +int ImageHelper::convertY800ToRGB( + const unsigned char *pInBuffer, + const ImageData& imageData, + unsigned char **pOutBuffer) +{ + if (pInBuffer == NULL || pOutBuffer == NULL || + imageData.imageColorspace != MEDIA_VISION_COLORSPACE_Y800) + { + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + const int inDataSize = imageData.imageHeight * imageData.imageWidth; + int numberOfComponents = 0; + getNumberOfComponents(MEDIA_VISION_COLORSPACE_RGB888, &numberOfComponents); + const int dataSize = inDataSize * numberOfComponents; + (*pOutBuffer) = new unsigned char[dataSize]; + for (int i = 0; i < inDataSize; ++i) + { + int pixelStartIndex = i*numberOfComponents; + (*pOutBuffer)[pixelStartIndex] = pInBuffer[i]; + (*pOutBuffer)[pixelStartIndex+1] = pInBuffer[i]; + (*pOutBuffer)[pixelStartIndex+2] = pInBuffer[i]; + } + return MEDIA_VISION_ERROR_NONE; +} + +} /* namespace Common */ +} /* namespace MediaVision */ diff --git a/mv_common/src/MediaSource.cpp b/mv_common/src/MediaSource.cpp new file mode 100644 index 0000000..1288625 --- /dev/null +++ b/mv_common/src/MediaSource.cpp @@ -0,0 +1,124 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 "MediaSource.h" + +#include <mv_private.h> + +#include <cstring> + +namespace MediaVision +{ +namespace Common +{ + +MediaSource::MediaSource() : m_pBuffer (NULL), m_bufferSize (0), m_width (0), + m_height (0), m_colorspace (MEDIA_VISION_COLORSPACE_INVALID) +{ +} + +MediaSource::~MediaSource() +{ + clear(); +} + +void MediaSource::clear(void) +{ + if (m_pBuffer != NULL) + { + LOGD("Delete internal buffer for media source %p", this); + delete[] m_pBuffer; + } + LOGD("Set defaults for media source %p : buffer = NULL; " + "bufferSize = 0; width = 0; height = 0; " + "colorspace = MEDIA_VISION_COLORSPACE_INVALID", this); + m_pBuffer = NULL; + m_bufferSize = 0; + m_width = 0; + m_height = 0; + m_colorspace = MEDIA_VISION_COLORSPACE_INVALID; +} + +bool MediaSource::fill(const unsigned char *buffer, unsigned int bufferSize, + unsigned int width, unsigned int height, mv_colorspace_e colorspace) +{ + if (bufferSize == 0 || buffer == NULL) + { + return false; + } + + LOGD("Call clear() first for media source %p", this); + clear(); + + try + { + LOGD("Allocate memory for buffer in media source %p", this); + m_pBuffer = new unsigned char[bufferSize]; + } + catch(...) + { + LOGE("Memory allocating for buffer in media source %p failed!", this); + m_pBuffer = NULL; + return false; + } + + LOGD("Copy data from external buffer (%p) to the internal buffer (%p) of " + "media source %p", buffer, m_pBuffer, this); + std::memcpy(m_pBuffer, buffer, bufferSize); + + LOGD("Assign new size of the internal buffer of media source %p. " + "New size is %ui.", this, bufferSize); + m_bufferSize = bufferSize; + + LOGD("Assign new size (%ui x %ui) of the internal buffer image for " + "the media source %p", width, height, this); + m_width = width; + m_height = height; + + LOGD("Assign new colorspace (%i) of the internal buffer image for " + "the media source %p", colorspace, this); + m_colorspace = colorspace; + + return true; +} + +unsigned char *MediaSource::getBuffer(void) const +{ + return m_pBuffer; +} + +unsigned int MediaSource::getBufferSize(void) const +{ + return m_bufferSize; +} + +unsigned int MediaSource::getWidth(void) const +{ + return m_width; +} + +unsigned int MediaSource::getHeight(void) const +{ + return m_height; +} + +mv_colorspace_e MediaSource::getColorspace(void) const +{ + return m_colorspace; +} + +} /* Common */ +} /* MediaVision */ diff --git a/mv_common/src/image_helper.cpp b/mv_common/src/image_helper.cpp new file mode 100644 index 0000000..bbf852c --- /dev/null +++ b/mv_common/src/image_helper.cpp @@ -0,0 +1,143 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 "image_helper.h" +#include "ImageHelper.h" + +/** + * @file image_helper.cpp + * @brief image_helper.h functions implementation. + */ + +using namespace MediaVision::Common; + +image_data_s convertToCData(const ImageHelper::ImageData& data) +{ + image_data_s ret; + ret.image_width = data.imageWidth; + ret.image_height = data.imageHeight; + ret.image_colorspace = data.imageColorspace; + return ret; +} + +ImageHelper::ImageData convertToCppData(const image_data_s& data) +{ + ImageHelper::ImageData ret; + ret.imageWidth = data.image_width; + ret.imageHeight = data.image_height; + ret.imageColorspace = data.image_colorspace; + return ret; +} + +int load_image_to_buffer( + const char *file_path, + unsigned char **data_buffer, + unsigned long *buffer_size, + image_data_s *image_data) +{ + if (image_data == NULL) + { + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + ImageHelper::ImageData imageData; + int err = ImageHelper::loadImageToBuffer(file_path, data_buffer, buffer_size, &imageData); + + if (err == MEDIA_VISION_ERROR_NONE) + { + *image_data = convertToCData(imageData); + } + + return err; +} + +int save_image_from_buffer( + const char *file_path, + unsigned char *data_buffer, + const image_data_s *image_data, + int quality) +{ + if (image_data == NULL) + { + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + ImageHelper::ImageData imageData = convertToCppData(*image_data); + return ImageHelper::saveImageFromBuffer(file_path, data_buffer, imageData, quality); +} + +int draw_rectangle_on_buffer( + int tl_vertex_x, + int tl_vertex_y, + int br_vertex_x, + int br_vertex_y, + int thickness, + const image_data_s *image_data, + unsigned char *data_buffer) +{ + if (image_data == NULL) + { + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + ImageHelper::ImageData imageData = convertToCppData(*image_data); + + return ImageHelper::drawRectangleOnBuffer( + tl_vertex_x, tl_vertex_y, + br_vertex_x, br_vertex_y, + thickness, + imageData, data_buffer); +} + +int convert_jpeglib_colorspace_to_mv_colorspace( + J_COLOR_SPACE in_colorspace, + mv_colorspace_e *out_colorspace) +{ + return ImageHelper::convertJpeglibColorspaceToMVColorspace(in_colorspace, out_colorspace); +} + +int convert_mv_colorspace_to_jpeglib_colorspace( + mv_colorspace_e in_colorspace, + J_COLOR_SPACE *out_colorspace) +{ + return ImageHelper::convertMVColorspaceToJpeglibColorspace(in_colorspace, out_colorspace); +} + +int convert_buffer_to_RGB888( + const unsigned char *in_buffer, + const image_data_s *image_data, + unsigned char **out_buffer) +{ + if (image_data == NULL) + { + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + ImageHelper::ImageData imageData = convertToCppData(*image_data); + return ImageHelper::convertBufferToRGB888(in_buffer, imageData, out_buffer); +} + +int get_number_of_components( + mv_colorspace_e colorspace, + int *components_number) +{ + if (components_number == NULL) + { + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + return ImageHelper::getNumberOfComponents(colorspace, components_number); +} diff --git a/mv_common/src/mv_common_c.cpp b/mv_common/src/mv_common_c.cpp new file mode 100644 index 0000000..feea279 --- /dev/null +++ b/mv_common/src/mv_common_c.cpp @@ -0,0 +1,767 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 "mv_common_c.h" + +#include "MediaSource.h" +#include "EngineConfig.h" + +#include <mv_private.h> + +#include <string.h> +#include <media_packet.h> + +int mv_create_source_c( + mv_source_h *source_ptr) +{ + if (source_ptr == NULL) + { + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + LOGD("Creating media vision source"); + (*source_ptr) = ((mv_source_h)new MediaVision::Common::MediaSource()); + + if (*source_ptr == NULL) + { + LOGE("Failed to create media vision source"); + + return MEDIA_VISION_ERROR_OUT_OF_MEMORY; + } + + LOGD("Media vision source [%p] has been created", *source_ptr); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_destroy_source_c( + mv_source_h source) +{ + if (!source) + { + LOGE("Media source can't be destroyed because handle is NULL"); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + LOGD("Destroying media vision source [%p]", source); + delete ((MediaVision::Common::MediaSource*)source); + LOGD("Media vision source has been destroyed"); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_source_fill_by_media_packet_c( + mv_source_h source, + media_packet_h media_packet) +{ + if (!source || !media_packet) + { + LOGE("Media source can't be filled by media_packet handle because " + "one of the source or media_packet handles is NULL. " + "source = %p; media_packet = %p", source, media_packet); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + bool is_video = false; + int image_width = 0; + int image_height = 0; + media_format_h format = NULL; + media_format_mimetype_e mimetype = MEDIA_FORMAT_I420; + unsigned char *data_buffer = NULL; + uint64_t buffer_size = 0; + mv_colorspace_e image_colorspace = MEDIA_VISION_COLORSPACE_INVALID; + + int ret = media_packet_is_video(media_packet, &is_video); + if (ret != MEDIA_PACKET_ERROR_NONE) + { + LOGE("media_packet_is_video() failed, mv_source_h fill skipped"); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + if (!is_video) + { + LOGE("Media packet isn't video, mv_source_h fill skipped"); + + return MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT; + } + + ret = media_packet_get_format(media_packet, &format); + if (ret != MEDIA_PACKET_ERROR_NONE) + { + LOGE("media_packet_get_format() failed, mv_source_h fill skipped"); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + ret = media_format_get_video_info( + format, &mimetype, &image_width, &image_height, NULL, NULL); + if (ret != MEDIA_PACKET_ERROR_NONE) + { + LOGE("media_format_get_video_info() failed, mv_source_h fill skipped"); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + if (mimetype > MEDIA_FORMAT_H261 && mimetype <= MEDIA_FORMAT_MPEG4_ASP) + { + LOGE("Media format mimetype is not the raw video, mv_source_h fill skipped"); + + return MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT; + } + + switch (mimetype) + { + case MEDIA_FORMAT_I420: + image_colorspace = MEDIA_VISION_COLORSPACE_I420; + break; + case MEDIA_FORMAT_NV12: + image_colorspace = MEDIA_VISION_COLORSPACE_NV12; + break; + case MEDIA_FORMAT_YV12: + image_colorspace = MEDIA_VISION_COLORSPACE_YV12; + break; + case MEDIA_FORMAT_NV21: + image_colorspace = MEDIA_VISION_COLORSPACE_NV21; + break; + case MEDIA_FORMAT_YUYV: + image_colorspace = MEDIA_VISION_COLORSPACE_YUYV; + break; + case MEDIA_FORMAT_UYVY: + image_colorspace = MEDIA_VISION_COLORSPACE_UYVY; + break; + case MEDIA_FORMAT_422P: + image_colorspace = MEDIA_VISION_COLORSPACE_422P; + break; + case MEDIA_FORMAT_RGB565: + image_colorspace = MEDIA_VISION_COLORSPACE_RGB565; + break; + case MEDIA_FORMAT_RGB888: + image_colorspace = MEDIA_VISION_COLORSPACE_RGB888; + break; + case MEDIA_FORMAT_RGBA: + image_colorspace = MEDIA_VISION_COLORSPACE_RGBA; + break; + default: + LOGE("Format of the media packet buffer is not supported by media " + "vision source (media_format_h mimetype=%i)", mimetype); + + return MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT; + } + + ret = media_packet_get_buffer_data_ptr(media_packet, (void**)&data_buffer); + if (ret != MEDIA_PACKET_ERROR_NONE) + { + LOGE("media_packet_get_buffer_data_ptr() failed, mv_source_h fill skipped"); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + ret = media_packet_get_buffer_size(media_packet, &buffer_size); + if (ret != MEDIA_PACKET_ERROR_NONE) + { + LOGE("media_packet_get_buffer_size() failed, mv_source_h fill skipped"); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + if (!((MediaVision::Common::MediaSource*)source)->fill(data_buffer, + buffer_size, (unsigned int)image_width, (unsigned int)image_height, image_colorspace)) + { + LOGE("mv_source_h filling from media_packet_h failed"); + + return MEDIA_VISION_ERROR_OUT_OF_MEMORY; + } + + LOGD("Media source has been filled from media packet"); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_source_fill_by_buffer_c( + mv_source_h source, + unsigned char *data_buffer, + unsigned int buffer_size, + unsigned int image_width, + unsigned int image_height, + mv_colorspace_e image_colorspace) +{ + if (!source || buffer_size == 0 || data_buffer == NULL) + { + LOGE("Media source can't be filled by buffer because " + "one of the source or data_buffer is NULL or buffer_size = 0. " + "source = %p; data_buffer = %p; buffer_size = %u", + source, data_buffer, buffer_size); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + if (!((MediaVision::Common::MediaSource*)source)->fill(data_buffer, + buffer_size, image_width, image_height, image_colorspace)) + { + LOGE("mv_source_h filling from buffer failed"); + + return MEDIA_VISION_ERROR_OUT_OF_MEMORY; + } + + LOGD("Media source has been filled from buffer"); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_source_clear_c( + mv_source_h source) +{ + if (!source) + { + LOGE("Media source can't be cleared because source handle is NULL"); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + LOGD("Clear media vision source [%p]", source); + ((MediaVision::Common::MediaSource*)source)->clear(); + LOGD("Media vision source [%p] has been cleared", source); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_source_get_buffer_c( + mv_source_h source, + unsigned char **buffer, + unsigned int *size) +{ + if (!source) + { + LOGE("Impossible to get buffer for NULL mv_source_h handle"); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + LOGD("Get media vision source [%p] buffer and buffer size to be returned", source); + *buffer = ((MediaVision::Common::MediaSource*)source)->getBuffer(); + *size = ((MediaVision::Common::MediaSource*)source)->getBufferSize(); + LOGD("Media vision source [%p] buffer (%p) and buffer size (%ui) has been returned", source, buffer, *size); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_source_get_height_c( + mv_source_h source, + unsigned int *height) +{ + if (!source) + { + LOGE("Impossible to get height for NULL mv_source_h handle"); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + LOGD("Get media vision source [%p] height to be returned", source); + *height = ((MediaVision::Common::MediaSource*)source)->getHeight(); + LOGD("Media vision source [%p] height (%ui) has been returned", source, *height); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_source_get_width_c( + mv_source_h source, + unsigned int *width) +{ + if (!source) + { + LOGE("Impossible to get width for NULL mv_source_h handle"); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + LOGD("Get media vision source [%p] width to be returned", source); + *width = ((MediaVision::Common::MediaSource*)source)->getWidth(); + LOGD("Media vision source [%p] width (%ui) has been returned", source, *width); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_source_get_colorspace_c( + mv_source_h source, + mv_colorspace_e *colorspace) +{ + if (!source) + { + LOGE("Impossible to get colorspace for NULL mv_source_h handle"); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + LOGD("Get media vision source [%p] colorspace to be returned", source); + *colorspace = ((MediaVision::Common::MediaSource*)source)->getColorspace(); + LOGD("Media vision source [%p] colorspace (%i) has been returned", source, *colorspace); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_create_engine_config_c( + mv_engine_config_h *engine_cfg) +{ + if (engine_cfg == NULL) + { + LOGE("Impossible to create mv_engine_config_h handle"); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + + LOGD("Creating media vision engine config"); + (*engine_cfg) = ((mv_engine_config_h)new MediaVision::Common::EngineConfig()); + LOGD("Media vision engine config [%p] has been created", *engine_cfg); + + if (*engine_cfg == NULL) + { + LOGE("Failed to create mv_engine_config_h handle"); + + return MEDIA_VISION_ERROR_OUT_OF_MEMORY; + } + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_destroy_engine_config_c( + mv_engine_config_h engine_cfg) +{ + if (!engine_cfg) + { + LOGE("Impossible to destroy NULL mv_engine_config_h handle"); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + LOGD("Destroying media vision engine config [%p]", engine_cfg); + delete ((MediaVision::Common::EngineConfig*)engine_cfg); + LOGD("Media vision engine config has been destroyed"); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_engine_config_set_double_attribute_c( + mv_engine_config_h engine_cfg, + const char *name, + double value) +{ + if (!engine_cfg || name == NULL) + { + LOGE("Impossible to set attribute. One of the required parameters is " + "NULL. engine_cfg = %p; name = %p;", engine_cfg, name); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + int ret = ((MediaVision::Common::EngineConfig*)engine_cfg)->setAttribute( + std::string(name), value); + + if (ret != MEDIA_VISION_ERROR_NONE) + { + LOGE("Failed to set attribute [%s] with value %f. Error code (0x%08x)", + name, value, ret); + + return ret; + } + + LOGD("Attribute [%s] (value %f) has been set", name, value); + + return ret; +} + +int mv_engine_config_set_int_attribute_c( + mv_engine_config_h engine_cfg, + const char *name, + int value) +{ + if (!engine_cfg || name == NULL) + { + LOGE("Impossible to set attribute. One of the required parameters is " + "NULL. engine_cfg = %p; name = %p;", engine_cfg, name); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + int ret = ((MediaVision::Common::EngineConfig*)engine_cfg)->setAttribute( + std::string(name), value); + + if (ret != MEDIA_VISION_ERROR_NONE) + { + LOGE("Failed to set attribute [%s] with value %i. Error code (0x%08x)", + name, value, ret); + + return ret; + } + + LOGD("Attribute [%s] (value %i) has been set", name, value); + + return ret; +} + +int mv_engine_config_set_bool_attribute_c( + mv_engine_config_h engine_cfg, + const char *name, + bool value) +{ + if (!engine_cfg || name == NULL) + { + LOGE("Impossible to set attribute. One of the required parameters is " + "NULL. engine_cfg = %p; name = %p;", engine_cfg, name); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + int ret = ((MediaVision::Common::EngineConfig*)engine_cfg)->setAttribute( + std::string(name), value); + + if (ret != MEDIA_VISION_ERROR_NONE) + { + LOGE("Failed to set attribute [%s] with value %s. Error code (0x%08x)", + name, value ? "TRUE" : "FALSE", ret); + + return ret; + } + + LOGD("Attribute [%s] (value %s) has been set", + name, value ? "TRUE" : "FALSE"); + + return ret; +} + +int mv_engine_config_set_string_attribute_c( + mv_engine_config_h engine_cfg, + const char *name, + const char *value) +{ + if (!engine_cfg || name == NULL || value == NULL) + { + LOGE("Impossible to set attribute. One of the required parameters is " + "NULL. engine_cfg = %p; name = %p; value = %p;", + engine_cfg, name, value); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + int ret = ((MediaVision::Common::EngineConfig*)engine_cfg)->setAttribute( + std::string(name), std::string(value)); + + if (ret != MEDIA_VISION_ERROR_NONE) + { + LOGE("Failed to set attribute [%s] with value %s. Error code (0x%08x)", + name, value, ret); + + return ret; + } + + LOGD("Attribute [%s] (value %s) has been set", name, value); + + return ret; +} + +int mv_engine_config_get_double_attribute_c( + mv_engine_config_h engine_cfg, + const char *name, + double *value) +{ + if (name == NULL || value == NULL) + { + LOGE("Impossible to get attribute. One of the required parameters is " + "NULL. name = %p; value = %p;", name, value); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + if (!engine_cfg) + { + const std::map<std::string, double>& defDblMap = + MediaVision::Common::EngineConfig::getDefaultDblDict(); + MediaVision::Common::DictDblConstIter dblAttributeIter = + defDblMap.find(std::string(name)); + if (dblAttributeIter != defDblMap.end()) + { + *value = dblAttributeIter->second; + + return MEDIA_VISION_ERROR_NONE; + } + else + { + LOGE("Double attribute %s isn't supported by default.", name); + + return MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE; + } + } + + int ret = ((MediaVision::Common::EngineConfig*)engine_cfg)->getDoubleAttribute( + std::string(name), value); + + if (ret != MEDIA_VISION_ERROR_NONE) + { + LOGE("Failed to get attribute [%s]. Error code (0x%08x)", name, ret); + + return ret; + } + + LOGD("Attribute [%s] (value %f) has been gotten", name, *value); + + return ret; +} + +int mv_engine_config_get_int_attribute_c( + mv_engine_config_h engine_cfg, + const char *name, + int *value) +{ + if (name == NULL || value == NULL) + { + LOGE("Impossible to get attribute. One of the required parameters is " + "NULL. name = %p; value = %p;", name, value); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + if (!engine_cfg) + { + const std::map<std::string, int>& defIntMap = + MediaVision::Common::EngineConfig::getDefaultIntDict(); + MediaVision::Common::DictIntConstIter intAttributeIter = + defIntMap.find(std::string(name)); + if (intAttributeIter != defIntMap.end()) + { + *value = intAttributeIter->second; + + return MEDIA_VISION_ERROR_NONE; + } + else + { + LOGE("Integer attribute %s isn't supported by default.", name); + + return MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE; + } + } + + int ret = ((MediaVision::Common::EngineConfig*)engine_cfg)->getIntegerAttribute( + std::string(name), value); + + if (ret != MEDIA_VISION_ERROR_NONE) + { + LOGE("Failed to get attribute [%s]. Error code (0x%08x)", name, ret); + + return ret; + } + + LOGD("Attribute [%s] (value %i) has been gotten", name, *value); + + return ret; +} + +int mv_engine_config_get_bool_attribute_c( + mv_engine_config_h engine_cfg, + const char *name, + bool *value) +{ + if (name == NULL || value == NULL) + { + LOGE("Impossible to get attribute. One of the required parameters is " + "NULL. name = %p; value = %p;", name, value); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + if (!engine_cfg) + { + const std::map<std::string, bool>& defBoolMap = + MediaVision::Common::EngineConfig::getDefaultBoolDict(); + MediaVision::Common::DictBoolConstIter boolAttributeIter = + defBoolMap.find(std::string(name)); + if (boolAttributeIter != defBoolMap.end()) + { + *value = boolAttributeIter->second; + + return MEDIA_VISION_ERROR_NONE; + } + else + { + LOGE("Boolean attribute %s isn't supported by default.", name); + + return MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE; + } + } + + int ret = ((MediaVision::Common::EngineConfig*)engine_cfg)->getBooleanAttribute( + std::string(name), value); + + if (ret != MEDIA_VISION_ERROR_NONE) + { + LOGE("Failed to get attribute [%s]. Error code (0x%08x)", name, ret); + + return ret; + } + + LOGD("Attribute [%s] (value %s) has been gotten", + name, *value ? "TRUE" : "FALSE"); + + return ret; +} + +int mv_engine_config_get_string_attribute_c( + mv_engine_config_h engine_cfg, + const char *name, + char **value) +{ + if (name == NULL || value == NULL) + { + LOGE("Impossible to get attribute. One of the required parameters is " + "NULL. name = %p; value = %p;", name, value); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + std::string attributeValue; + int ret = MEDIA_VISION_ERROR_NONE; + + if (!engine_cfg) + { + const std::map<std::string, std::string>& defStrMap = + MediaVision::Common::EngineConfig::getDefaultStrDict(); + MediaVision::Common::DictStrConstIter strAttributeIter = + defStrMap.find(std::string(name)); + if (strAttributeIter != defStrMap.end()) + { + attributeValue = strAttributeIter->second; + } + else + { + LOGE("String attribute %s isn't supported by default.", name); + + return MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE; + } + } + else + { + ret = ((MediaVision::Common::EngineConfig*)engine_cfg)->getStringAttribute( + std::string(name), &attributeValue); + + if (ret != MEDIA_VISION_ERROR_NONE) + { + LOGE("Failed to get attribute [%s]. Error code (0x%08x)", name, ret); + + return ret; + } + } + + LOGD("Convert string to char*"); + int stringSize = attributeValue.size(); + (*value) = new char[stringSize + 1]; + + if (attributeValue.copy(*value, stringSize) != attributeValue.size()) + { + LOGE("Conversion from string to char* failed"); + delete[] (*value); + (*value) = NULL; + + return MEDIA_VISION_ERROR_INVALID_OPERATION; + } + + (*value)[stringSize] = '\0'; + LOGD("Attribute [%s] (value %s) has been gotten", name, *value); + + return ret; +} + +int mv_engine_config_foreach_supported_attribute_c( + mv_supported_attribute_cb callback, + void *user_data) +{ + if (NULL == callback) + { + LOGE("Impossible to traverse supported by Media Vision engine " + "configuration attributes. Callback is NULL"); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + using namespace MediaVision::Common; + + int err = EngineConfig::cacheDictionaries(); + + if (MEDIA_VISION_ERROR_NONE != err) + { + LOGE("Failed to get attribute names/types. " + "Failed to cache attributes from file"); + + return err; + } + + DictDblConstIter dblDictIter = EngineConfig::getDefaultDblDict().begin(); + DictIntConstIter intDictIter = EngineConfig::getDefaultIntDict().begin(); + DictBoolConstIter boolDictIter = EngineConfig::getDefaultBoolDict().begin(); + DictStrConstIter strDictIter = EngineConfig::getDefaultStrDict().begin(); + + while (dblDictIter != EngineConfig::getDefaultDblDict().end()) + { + if (!callback(MV_ENGINE_CONFIG_ATTR_TYPE_DOUBLE, + dblDictIter->first.c_str(), user_data)) + { + LOGD("Attribute names/types traverse has been stopped by the user"); + + return MEDIA_VISION_ERROR_NONE; + } + ++dblDictIter; + } + + while (intDictIter != EngineConfig::getDefaultIntDict().end()) + { + if (!callback(MV_ENGINE_CONFIG_ATTR_TYPE_INTEGER, + intDictIter->first.c_str(), user_data)) + { + LOGD("Attribute names/types traverse has been stopped by the user"); + + return MEDIA_VISION_ERROR_NONE; + } + ++intDictIter; + } + + while (boolDictIter != EngineConfig::getDefaultBoolDict().end()) + { + if (!callback(MV_ENGINE_CONFIG_ATTR_TYPE_BOOLEAN, + boolDictIter->first.c_str(), user_data)) + { + LOGD("Attribute names/types traverse has been stopped by the user"); + + return MEDIA_VISION_ERROR_NONE; + } + ++boolDictIter; + } + + while (strDictIter != EngineConfig::getDefaultStrDict().end()) + { + if (!callback(MV_ENGINE_CONFIG_ATTR_TYPE_STRING, + strDictIter->first.c_str(), user_data)) + { + LOGD("Attribute names/types traverse has been stopped by the user"); + + return MEDIA_VISION_ERROR_NONE; + } + ++strDictIter; + } + + LOGD("Attribute names/types has been gotten"); + + return MEDIA_VISION_ERROR_NONE; +} diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec new file mode 100644 index 0000000..e0d83f3 --- /dev/null +++ b/packaging/capi-media-vision.spec @@ -0,0 +1,77 @@ +Name: capi-media-vision +Summary: Media Vision library for Tizen Native API +Version: 0.1.15 +Release: 0 +Group: Multimedia/Framework +License: Apache-2.0 +Source0: %{name}-%{version}.tar.gz +BuildRequires: cmake +BuildRequires: pkgconfig(capi-media-tool) +BuildRequires: pkgconfig(libtbm) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(capi-system-info) +BuildRequires: pkgconfig(opencv) +BuildRequires: pkgconfig(zbar) +# Change to the pkgconfig(zint) after zint package refactor +BuildRequires: zint +BuildRequires: zint-devel +BuildRequires: pkgconfig(json-glib-1.0) +BuildRequires: dlogutil +BuildRequires: libjpeg-turbo +BuildRequires: libjpeg-turbo-devel +BuildRequires: pkgconfig(libavcodec) +BuildRequires: pkgconfig(libavformat) +BuildRequires: pkgconfig(libswscale) + +Requires(post): /sbin/ldconfig + +%description +Media Vision library for Tizen Native API. Includes barcode detecting and generating modules. + +%package devel +Summary: Multimedia Vision Library (DEV) +Group: Multimedia/Framework +Requires: %{name} = %{version}-%{release} + +%description devel +Media Vision library for Tizen Native API (DEV). Includes barcode detecting and generating modules. + +%prep +%setup -q + +%build +%if 0%{?sec_build_binary_debug_enable} +export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE" +export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE" +export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" +%endif +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` +cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot}/usr/share/license/ +mkdir -p %{buildroot}/usr/share/config/%{name} +cp LICENSE.APLv2 %{buildroot}/usr/share/license/%{name} +cp media-vision-config.json %{buildroot}/usr/share/config/%{name}/ + +%make_install + +%post -p /sbin/ldconfig +%postun -p /sbin/ldconfig + +%files +%manifest capi-media-vision.manifest +%{_datadir}/license/%{name} +%{_datadir}/config/%{name}/media-vision-config.json +%{_libdir}/libcapi-media-vision.so.* +%{_libdir}/libmv*.so + +%files devel +%{_datadir}/config/%{name}/media-vision-config.json +%{_includedir}/media/*.h +%{_libdir}/pkgconfig/*.pc +%{_libdir}/lib%{name}.so +/opt/usr/devel/media/testsuites/* diff --git a/src/mv_barcode.c b/src/mv_barcode.c new file mode 100644 index 0000000..ab8deda --- /dev/null +++ b/src/mv_barcode.c @@ -0,0 +1,237 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 <system_info.h> + +#include "mv_private.h" +#include "mv_barcode_detect.h" +#include "mv_barcode_generate.h" + +#ifdef MEDIA_VISION_BARCODE_DETECTOR_LICENSE_PORT + +/* Include headers of licensed barcode detect module here. */ +#include "mv_barcode_detect_lic.h" + +#else + +/* Include headers of open barcode detect module here. */ +#include "mv_barcode_detect_open.h" + +#endif /* MEDIA_VISION_BARCODE_DETECTOR_LICENSE_PORT */ + +#ifdef MEDIA_VISION_BARCODE_GENERATOR_LICENSE_PORT + +/* Include headers of licensed barcode generate module here. */ +#include "mv_barcode_generate_lic.h" + +#else + +/* Include headers of open barcode generate module here. */ +#include "mv_barcode_generate_open.h" + +#endif /* MEDIA_VISION_BARCODE_GENERATOR_LICENSE_PORT */ + +/** + * @file mv_barcode.c + * @brief This file contains the porting layer for Media Vision barcode module. + */ + +int mv_barcode_detect( + mv_source_h source, + mv_engine_config_h engine_cfg, + mv_rectangle_s roi, + mv_barcode_detected_cb detect_cb, + void *user_data) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_detect_check_system_info_feature_supported()); + MEDIA_VISION_INSTANCE_CHECK(source); + MEDIA_VISION_NULL_ARG_CHECK(detect_cb); + + MEDIA_VISION_FUNCTION_ENTER(); + + int ret = MEDIA_VISION_ERROR_NONE; + unsigned int src_w = 0; + unsigned int src_h = 0; + + ret = mv_source_get_width(source, &src_w); + if (ret != MEDIA_VISION_ERROR_NONE) { + LOGE("mv_source_get_width fail"); + return ret; + } + + ret = mv_source_get_height(source, &src_h); + if (ret != MEDIA_VISION_ERROR_NONE) { + LOGE("mv_source_get_height fail"); + return ret; + } + + if (roi.point.x < 0 || roi.point.y < 0) { + LOGE("roi is out of area on source"); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + if ((roi.point.x + roi.width) > src_w || + (roi.point.y + roi.height) > src_h) { + LOGE("roi is out of area on source"); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + +#ifdef MEDIA_VISION_BARCODE_DETECTOR_LICENSE_PORT + + /* Use licensed barcode detect functionality here. */ + ret = mv_barcode_detect_lic( + source, engine_cfg, roi, detect_cb, user_data); + +#else + + /* Use open barcode detect functionality here. */ + ret = mv_barcode_detect_open( + source, engine_cfg, roi, detect_cb, user_data); + +#endif /* MEDIA_VISION_BARCODE_DETECTOR_LICENSE_PORT */ + + MEDIA_VISION_FUNCTION_LEAVE(); + return ret; +} + +int mv_barcode_generate_source( + mv_engine_config_h engine_cfg, + const char *message, + mv_barcode_type_e type, + mv_barcode_qr_mode_e qr_enc_mode, + mv_barcode_qr_ecc_e qr_ecc, + int qr_version, + mv_source_h image) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_generate_check_system_info_feature_supported()); + MEDIA_VISION_NULL_ARG_CHECK(message); + MEDIA_VISION_INSTANCE_CHECK(image); + + MEDIA_VISION_FUNCTION_ENTER(); + + if (type < MV_BARCODE_QR || + type >= MV_BARCODE_UNDEFINED) { + LOGE("Not supported barcode type [%d]", type); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + if (type == MV_BARCODE_QR) { + if (qr_enc_mode < MV_BARCODE_QR_MODE_NUMERIC || + qr_enc_mode >= MV_BARCODE_QR_MODE_UNAVAILABLE) { + LOGE("Not supported QR encoding mode[%d]", qr_enc_mode); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + if (qr_ecc < MV_BARCODE_QR_ECC_LOW || + qr_ecc >= MV_BARCODE_QR_ECC_UNAVAILABLE) { + LOGE("Not supported QR ECC level [%d]", qr_ecc); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + if (qr_version < 1 || qr_version > 40) { + LOGE("Not supported QR version [%d]", qr_version); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + } + +#ifdef MEDIA_VISION_BARCODE_GENERATOR_LICENSE_PORT + + /* Use licensed barcode generate functionality here. */ + int ret = mv_barcode_generate_source_lic( + engine_cfg, message, type, qr_enc_mode, qr_ecc, qr_version, + image); + +#else + + /* Use open barcode generate functionality here. */ + int ret = mv_barcode_generate_source_open( + engine_cfg, message, type, qr_enc_mode, qr_ecc, qr_version, + image); + +#endif /* MEDIA_VISION_BARCODE_GENERATOR_LICENSE_PORT */ + + MEDIA_VISION_FUNCTION_LEAVE(); + return ret; +} + +int mv_barcode_generate_image( + mv_engine_config_h engine_cfg, + const char *message, + int image_width, + int image_height, + mv_barcode_type_e type, + mv_barcode_qr_mode_e qr_enc_mode, + mv_barcode_qr_ecc_e qr_ecc, + int qr_version, + const char *image_path, + mv_barcode_image_format_e image_format) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_generate_check_system_info_feature_supported()); + MEDIA_VISION_NULL_ARG_CHECK(message); + MEDIA_VISION_NULL_ARG_CHECK(image_path); + + MEDIA_VISION_FUNCTION_ENTER(); + + if (type < MV_BARCODE_QR || + type >= MV_BARCODE_UNDEFINED) { + LOGE("Not supported barcode type [%d]", type); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + if (type == MV_BARCODE_QR) { + if (qr_enc_mode < MV_BARCODE_QR_MODE_NUMERIC || + qr_enc_mode >= MV_BARCODE_QR_MODE_UNAVAILABLE) { + LOGE("Not supported QR encoding mode[%d]", qr_enc_mode); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + if (qr_ecc < MV_BARCODE_QR_ECC_LOW || + qr_ecc >= MV_BARCODE_QR_ECC_UNAVAILABLE) { + LOGE("Not supported QR ECC level [%d]", qr_ecc); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + if (qr_version < 1 || qr_version > 40) { + LOGE("Not supported QR version [%d]", qr_version); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + } + + if (image_format < MV_BARCODE_IMAGE_FORMAT_BMP || + image_format >= MV_BARCODE_IMAGE_FORMAT_NUM) { + LOGE("Not supported image format [%d]", image_format); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + +#ifdef MEDIA_VISION_BARCODE_GENERATOR_LICENSE_PORT + + /* Use licensed barcode generate functionality here. */ + int ret = mv_barcode_generate_image_lic( + engine_cfg, message, image_width, image_height, type, + qr_enc_mode, qr_ecc, qr_version, image_path, image_format); + +#else + + /* Use open barcode generate functionality here. */ + int ret = mv_barcode_generate_image_open( + engine_cfg, message, image_width, image_height, type, + qr_enc_mode, qr_ecc, qr_version, image_path, image_format); + +#endif /* MEDIA_VISION_BARCODE_GENERATOR_LICENSE_PORT */ + + MEDIA_VISION_FUNCTION_LEAVE(); + return ret; +} diff --git a/src/mv_common.c b/src/mv_common.c new file mode 100644 index 0000000..69825ce --- /dev/null +++ b/src/mv_common.c @@ -0,0 +1,338 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 "mv_private.h" +#include "mv_common.h" +#include "mv_common_c.h" + +int mv_create_source( + mv_source_h *source) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_NULL_ARG_CHECK(source); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_create_source_c(source); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_destroy_source( + mv_source_h source) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_INSTANCE_CHECK(source); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_destroy_source_c(source); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_source_fill_by_media_packet( + mv_source_h source, + media_packet_h media_packet) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_INSTANCE_CHECK(source); + MEDIA_VISION_INSTANCE_CHECK(media_packet); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_source_fill_by_media_packet_c(source, media_packet); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_source_fill_by_buffer( + mv_source_h source, + unsigned char *data_buffer, + unsigned int buffer_size, + unsigned int image_width, + unsigned int image_height, + mv_colorspace_e image_colorspace) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_INSTANCE_CHECK(source); + MEDIA_VISION_NULL_ARG_CHECK(data_buffer); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_source_fill_by_buffer_c( + source, data_buffer, buffer_size, image_width, image_height, + image_colorspace); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_source_clear( + mv_source_h source) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_INSTANCE_CHECK(source); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_source_clear_c(source); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_source_get_buffer( + mv_source_h source, + unsigned char **data_buffer, + unsigned int *buffer_size) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_INSTANCE_CHECK(source); + MEDIA_VISION_NULL_ARG_CHECK(data_buffer); + MEDIA_VISION_NULL_ARG_CHECK(buffer_size); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_source_get_buffer_c(source, data_buffer, buffer_size); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_source_get_height( + mv_source_h source, + unsigned int *image_height) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_INSTANCE_CHECK(source); + MEDIA_VISION_NULL_ARG_CHECK(image_height); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_source_get_height_c(source, image_height); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_source_get_width( + mv_source_h source, + unsigned int *image_width) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_INSTANCE_CHECK(source); + MEDIA_VISION_NULL_ARG_CHECK(image_width); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_source_get_width_c(source, image_width); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_source_get_colorspace( + mv_source_h source, + mv_colorspace_e *image_colorspace) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_INSTANCE_CHECK(source); + MEDIA_VISION_NULL_ARG_CHECK(image_colorspace); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_source_get_colorspace_c(source, image_colorspace); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_create_engine_config( + mv_engine_config_h *engine_cfg) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_NULL_ARG_CHECK(engine_cfg); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_create_engine_config_c(engine_cfg); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_destroy_engine_config( + mv_engine_config_h engine_cfg) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_INSTANCE_CHECK(engine_cfg); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_destroy_engine_config_c(engine_cfg); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_engine_config_set_double_attribute( + mv_engine_config_h engine_cfg, + const char *name, + double value) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_INSTANCE_CHECK(engine_cfg); + MEDIA_VISION_NULL_ARG_CHECK(name); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_engine_config_set_double_attribute_c( + engine_cfg, name, value); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_engine_config_set_int_attribute( + mv_engine_config_h engine_cfg, + const char *name, + int value) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_INSTANCE_CHECK(engine_cfg); + MEDIA_VISION_NULL_ARG_CHECK(name); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_engine_config_set_int_attribute_c( + engine_cfg, name, value); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_engine_config_set_bool_attribute( + mv_engine_config_h engine_cfg, + const char *name, + bool value) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_INSTANCE_CHECK(engine_cfg); + MEDIA_VISION_NULL_ARG_CHECK(name); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_engine_config_set_bool_attribute_c( + engine_cfg, name, value); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_engine_config_set_string_attribute( + mv_engine_config_h engine_cfg, + const char *name, + const char *value) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_INSTANCE_CHECK(engine_cfg); + MEDIA_VISION_NULL_ARG_CHECK(name); + MEDIA_VISION_NULL_ARG_CHECK(value); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_engine_config_set_string_attribute_c( + engine_cfg, name, value); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_engine_config_get_double_attribute( + mv_engine_config_h engine_cfg, + const char *name, + double *value) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_INSTANCE_CHECK(engine_cfg); + MEDIA_VISION_NULL_ARG_CHECK(name); + MEDIA_VISION_NULL_ARG_CHECK(value); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_engine_config_get_double_attribute_c( + engine_cfg, name, value); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_engine_config_get_int_attribute( + mv_engine_config_h engine_cfg, + const char *name, + int *value) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_INSTANCE_CHECK(engine_cfg); + MEDIA_VISION_NULL_ARG_CHECK(name); + MEDIA_VISION_NULL_ARG_CHECK(value); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_engine_config_get_int_attribute_c( + engine_cfg, name, value); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_engine_config_get_bool_attribute( + mv_engine_config_h engine_cfg, + const char *name, + bool *value) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_INSTANCE_CHECK(engine_cfg); + MEDIA_VISION_NULL_ARG_CHECK(name); + MEDIA_VISION_NULL_ARG_CHECK(value); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_engine_config_get_bool_attribute_c( + engine_cfg, name, value); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_engine_config_get_string_attribute( + mv_engine_config_h engine_cfg, + const char *name, + char **value) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_INSTANCE_CHECK(engine_cfg); + MEDIA_VISION_NULL_ARG_CHECK(name); + MEDIA_VISION_NULL_ARG_CHECK(value); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = mv_engine_config_get_string_attribute_c( + engine_cfg, name, value); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_engine_config_foreach_supported_attribute( + mv_supported_attribute_cb callback, + void *user_data) +{ + MEDIA_VISION_SUPPORT_CHECK(__mv_barcode_check_system_info_feature_supported()); + MEDIA_VISION_NULL_ARG_CHECK(callback); + + MEDIA_VISION_FUNCTION_ENTER(); + int ret = + mv_engine_config_foreach_supported_attribute_c(callback, user_data); + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} diff --git a/src/mv_private.c b/src/mv_private.c new file mode 100644 index 0000000..13facce --- /dev/null +++ b/src/mv_private.c @@ -0,0 +1,96 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 <system_info.h> + +#include "mv_private.h" + +bool __mv_barcode_check_system_info_feature_supported() +{ + bool isBarcodeDetectionSupported = false; + bool isBarcodeGenerationSupported = false; + + int nRetVal = system_info_get_platform_bool( + "http://tizen.org/feature/vision.barcode_detection", + &isBarcodeDetectionSupported); + + if (nRetVal != SYSTEM_INFO_ERROR_NONE) { + LOGE("[%s] SYSTEM_INFO_ERROR", __FUNCTION__); + return false; + } + + nRetVal = system_info_get_platform_bool( + "http://tizen.org/feature/vision.barcode_generation", + &isBarcodeGenerationSupported); + + if (nRetVal != SYSTEM_INFO_ERROR_NONE) { + LOGE("[%s] SYSTEM_INFO_ERROR", __FUNCTION__); + return false; + } + + (isBarcodeDetectionSupported || isBarcodeGenerationSupported) ? + LOGI("system_info_get_platform_bool returned" + "Supported barcode features capability\n") : + LOGE("system_info_get_platform_bool returned" + "Unsupported barcode features capability\n"); + + return (isBarcodeDetectionSupported || isBarcodeGenerationSupported); +} + +bool __mv_barcode_detect_check_system_info_feature_supported() +{ + bool isBarcodeDetectionSupported = false; + + const int nRetVal = system_info_get_platform_bool( + "http://tizen.org/feature/vision.barcode_detection", + &isBarcodeDetectionSupported); + + if (nRetVal != SYSTEM_INFO_ERROR_NONE) { + LOGE("[%s] SYSTEM_INFO_ERROR", __FUNCTION__); + return false; + } + + isBarcodeDetectionSupported ? + LOGI("system_info_get_platform_bool returned " + "Supported barcode detection feature capability\n") : + LOGE("system_info_get_platform_bool returned " + "Unsupported barcode detection feature capability\n"); + + return isBarcodeDetectionSupported; +} + +bool __mv_barcode_generate_check_system_info_feature_supported() +{ + bool isBarcodeGenerationSupported = false; + + const int nRetVal = system_info_get_platform_bool( + "http://tizen.org/feature/vision.barcode_generation", + &isBarcodeGenerationSupported); + + if (nRetVal != SYSTEM_INFO_ERROR_NONE) { + LOGE("[%s] SYSTEM_INFO_ERROR", __FUNCTION__); + return false; + } + + isBarcodeGenerationSupported ? + LOGI("system_info_get_platform_bool returned " + "Supported barcode generation feature capability\n") : + LOGE("system_info_get_platform_bool returned " + "Unsupported barcode generation feature capability\n"); + + return isBarcodeGenerationSupported; +} + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..b61a2b3 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,5 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +SET(testbin_dir /opt/usr/devel/media/) + +ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/test/testsuites) diff --git a/test/testsuites/CMakeLists.txt b/test/testsuites/CMakeLists.txt new file mode 100644 index 0000000..5511f35 --- /dev/null +++ b/test/testsuites/CMakeLists.txt @@ -0,0 +1,6 @@ +project(mv_testsuites) +cmake_minimum_required(VERSION 2.6) + +set(testsuites_dir "${testbin_dir}/testsuites") + +add_subdirectory(${PROJECT_SOURCE_DIR}/barcodes) diff --git a/test/testsuites/barcodes/CMakeLists.txt b/test/testsuites/barcodes/CMakeLists.txt new file mode 100644 index 0000000..be51a6d --- /dev/null +++ b/test/testsuites/barcodes/CMakeLists.txt @@ -0,0 +1,26 @@ +project(ts_barcodes) +cmake_minimum_required(VERSION 2.6) + +set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG _DEBUG) + +if(NOT SKIP_WARNINGS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror") +endif() + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +include_directories(${PROJECT_SOURCE_DIR}) +include_directories(${MV_CAPI_MEDIA_VISION_INC_DIR}) + +file(GLOB MV_TEST_SUITE_INC_LIST "${PROJECT_SOURCE_DIR}/*.h") +file(GLOB MV_TEST_SUITE_SRC_LIST "${PROJECT_SOURCE_DIR}/*.c") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE") + +add_executable(${PROJECT_NAME} ${MV_TEST_SUITE_SRC_LIST} ${MV_TEST_SUITE_INC_LIST} ${MV_CAPI_MEDIA_VISION_INC_LIST}) + +target_link_libraries(${PROJECT_NAME} capi-media-vision dlog avcodec avformat avutil swscale) + +install(TARGETS ${PROJECT_NAME} DESTINATION ${testsuites_dir})
\ No newline at end of file diff --git a/test/testsuites/barcodes/ts_barcodes.c b/test/testsuites/barcodes/ts_barcodes.c new file mode 100644 index 0000000..6ae3459 --- /dev/null +++ b/test/testsuites/barcodes/ts_barcodes.c @@ -0,0 +1,1338 @@ +/** + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 <mv_barcode.h> + +#include <image_helper.h> +#include <mv_private.h> + +#include <ctype.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include <libswscale/swscale.h> +#include <libavcodec/avcodec.h> +#include <libavutil/pixfmt.h> + +typedef struct { + mv_barcode_type_e type; + mv_barcode_qr_ecc_e ecc; + mv_barcode_qr_mode_e mode; + int version; + size_t width; + size_t height; + mv_barcode_image_format_e out_image_format; + mv_colorspace_e colorspace; + char *message; + char *file_name; + char *out_file_name; + unsigned char *out_buffer_ptr; +} barcode_model_s; + +typedef enum { + MV_TS_GENERATE_TO_IMAGE_FCN, + MV_TS_GENERATE_TO_SOURCE_FCN +} generation_fcn_e; + +int convert_rgb_to(unsigned char *src_buffer, unsigned char **dst_buffer, + image_data_s image_data, mv_colorspace_e dst_colorspace, + unsigned long *cvt_buffer_size) +{ + int AVPicture_ret = 0; + enum PixelFormat pixel_format = PIX_FMT_NONE; + + MEDIA_VISION_FUNCTION_ENTER(); + + switch (dst_colorspace) { + case MEDIA_VISION_COLORSPACE_Y800: + pixel_format = PIX_FMT_GRAY8; + break; + case MEDIA_VISION_COLORSPACE_I420: + pixel_format = PIX_FMT_YUV420P; + break; + case MEDIA_VISION_COLORSPACE_NV12: + pixel_format = PIX_FMT_NV12; + break; + case MEDIA_VISION_COLORSPACE_YV12: + pixel_format = PIX_FMT_YUV420P; /* the same as I420 with inversed U and V */ + break; + case MEDIA_VISION_COLORSPACE_NV21: + pixel_format = PIX_FMT_NV21; + break; + case MEDIA_VISION_COLORSPACE_YUYV: + pixel_format = PIX_FMT_YUYV422; + break; + case MEDIA_VISION_COLORSPACE_UYVY: + pixel_format = PIX_FMT_UYVY422; + break; + case MEDIA_VISION_COLORSPACE_422P: + pixel_format = PIX_FMT_YUV422P; + break; + case MEDIA_VISION_COLORSPACE_RGB565: + pixel_format = PIX_FMT_RGB565BE; + break; + case MEDIA_VISION_COLORSPACE_RGBA: + pixel_format = PIX_FMT_RGBA; + break; + case MEDIA_VISION_COLORSPACE_RGB888: + *cvt_buffer_size = + image_data.image_width * image_data.image_height * 3; + (*dst_buffer) = (unsigned char *)malloc(*cvt_buffer_size); + if ((*dst_buffer) == NULL) { + MEDIA_VISION_FUNCTION_LEAVE(); + return MEDIA_VISION_ERROR_OUT_OF_MEMORY; + } + memcpy(*dst_buffer, src_buffer, *cvt_buffer_size); + + MEDIA_VISION_FUNCTION_LEAVE(); + return MEDIA_VISION_ERROR_NONE; + default: + MEDIA_VISION_FUNCTION_LEAVE(); + return MEDIA_VISION_ERROR_NOT_SUPPORTED; + } + + AVPicture src_picture; + AVPicture dst_picture; + + avpicture_fill(&src_picture, (uint8_t *)src_buffer, PIX_FMT_RGB24, + image_data.image_width, image_data.image_height); + + avpicture_alloc(&dst_picture, pixel_format, + image_data.image_width, image_data.image_height); + + struct SwsContext *context = sws_getContext( + image_data.image_width, image_data.image_height, PIX_FMT_RGB24, + image_data.image_width, image_data.image_height, pixel_format, + SWS_FAST_BILINEAR, 0, 0, 0); + + if (context == NULL) { + avpicture_free(&dst_picture); + MEDIA_VISION_FUNCTION_LEAVE(); + return MEDIA_VISION_ERROR_INTERNAL; + } + + sws_scale(context, (const uint8_t * const *)src_picture.data, + src_picture.linesize, 0, image_data.image_height, + dst_picture.data, dst_picture.linesize); + + AVPicture_ret = avpicture_get_size(pixel_format, + image_data.image_width, image_data.image_height); + + if (AVPicture_ret < 0) { + avpicture_free(&dst_picture); + MEDIA_VISION_FUNCTION_LEAVE(); + return MEDIA_VISION_ERROR_INTERNAL; + } + *cvt_buffer_size = AVPicture_ret; + + (*dst_buffer) = (unsigned char *)malloc(*cvt_buffer_size); + if ((*dst_buffer) == NULL) { + avpicture_free(&dst_picture); + MEDIA_VISION_FUNCTION_LEAVE(); + return MEDIA_VISION_ERROR_OUT_OF_MEMORY; + } + memcpy(*dst_buffer, dst_picture.data[0], *cvt_buffer_size); + + avpicture_free(&dst_picture); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return MEDIA_VISION_ERROR_NONE; +} + +int find_min_x(const mv_quadrangle_s *quadrangle, int *minX) +{ + MEDIA_VISION_FUNCTION_ENTER(); + + if (NULL == quadrangle) { + MEDIA_VISION_FUNCTION_LEAVE(); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + *minX = quadrangle->points[0].x; + *minX = quadrangle->points[1].x < *minX ? quadrangle->points[1].x : *minX; + *minX = quadrangle->points[2].x < *minX ? quadrangle->points[2].x : *minX; + *minX = quadrangle->points[3].x < *minX ? quadrangle->points[3].x : *minX; + + MEDIA_VISION_FUNCTION_LEAVE(); + + return MEDIA_VISION_ERROR_NONE; +} + +int find_min_y(const mv_quadrangle_s *quadrangle, int *minY) +{ + MEDIA_VISION_FUNCTION_ENTER(); + + if (NULL == quadrangle) { + MEDIA_VISION_FUNCTION_LEAVE(); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + *minY = quadrangle->points[0].y; + *minY = quadrangle->points[1].y < *minY ? quadrangle->points[1].y : *minY; + *minY = quadrangle->points[2].y < *minY ? quadrangle->points[2].y : *minY; + *minY = quadrangle->points[3].y < *minY ? quadrangle->points[3].y : *minY; + + MEDIA_VISION_FUNCTION_LEAVE(); + + return MEDIA_VISION_ERROR_NONE; +} + +int find_max_x(const mv_quadrangle_s *quadrangle, int *maxX) +{ + MEDIA_VISION_FUNCTION_ENTER(); + + if (NULL == quadrangle) { + MEDIA_VISION_FUNCTION_LEAVE(); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + *maxX = quadrangle->points[0].x; + *maxX = quadrangle->points[1].x > *maxX ? quadrangle->points[1].x : *maxX; + *maxX = quadrangle->points[2].x > *maxX ? quadrangle->points[2].x : *maxX; + *maxX = quadrangle->points[3].x > *maxX ? quadrangle->points[3].x : *maxX; + + MEDIA_VISION_FUNCTION_LEAVE(); + + return MEDIA_VISION_ERROR_NONE; +} + +int find_max_y(const mv_quadrangle_s *quadrangle, int *maxY) +{ + MEDIA_VISION_FUNCTION_ENTER(); + + if (NULL == quadrangle) { + MEDIA_VISION_FUNCTION_LEAVE(); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + *maxY = quadrangle->points[0].y; + *maxY = quadrangle->points[1].y > *maxY ? quadrangle->points[1].y : *maxY; + *maxY = quadrangle->points[2].y > *maxY ? quadrangle->points[2].y : *maxY; + *maxY = quadrangle->points[3].y > *maxY ? quadrangle->points[3].y : *maxY; + + MEDIA_VISION_FUNCTION_LEAVE(); + + return MEDIA_VISION_ERROR_NONE; +} + +bool _mv_engine_config_supported_attribute( + mv_config_attribute_type_e attribute_type, + const char *attribute_name, + void *user_data) +{ + printf("Callback call for engine configuration attribute\n"); + + if (user_data == NULL) { + return false; + } + + mv_engine_config_h mv_engine_config = (mv_engine_config_h *)user_data; + + int int_value = 0; + double double_value = 0.0; + bool bool_value = false; + char str_value[1024]; + switch (attribute_type) { + case MV_ENGINE_CONFIG_ATTR_TYPE_DOUBLE: + if (MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE == + mv_engine_config_get_double_attribute( + mv_engine_config, attribute_name, &double_value)) { + printf("Default double attribute %s wasn't set in engine\n", + attribute_name); + return false; + } + printf("Default double attribute %s was set to %f in engine\n", + attribute_name, double_value); + break; + case MV_ENGINE_CONFIG_ATTR_TYPE_INTEGER: + if (MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE == + mv_engine_config_get_int_attribute( + mv_engine_config, attribute_name, &int_value)) { + printf("Default integer attribute %s wasn't set in engine\n", + attribute_name); + return false; + } + printf("Default interget attribute %s was set to %d in engine\n", + attribute_name, int_value); + break; + case MV_ENGINE_CONFIG_ATTR_TYPE_BOOLEAN: + if (MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE == + mv_engine_config_get_bool_attribute( + mv_engine_config, attribute_name, &bool_value)) { + printf("Default bool attribute %s wasn't set in engine\n", + attribute_name); + return false; + } + printf("Default bool attribute %s was set to %s in engine\n", + attribute_name, bool_value ? "TRUE" : "FALSE"); + break; + case MV_ENGINE_CONFIG_ATTR_TYPE_STRING: + if (MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE == + mv_engine_config_get_string_attribute( + mv_engine_config, attribute_name, &str_value)) { + printf("Default string ttribute %s wasn't set in engine\n", + attribute_name); + return false; + } + printf("Default string attribute %s was set to %s in engine\n", + attribute_name, str_value); + break; + default: + printf("Not supported attribute type\n"); + return false; + } + + return true; +} + +void barcode_detected_cb( + mv_source_h source, + mv_engine_config_h engine_cfg, + const mv_quadrangle_s *barcodes_locations, + const char *messages[], + const mv_barcode_type_e *types, + int number_of_barcodes, + void *user_data) +{ + MEDIA_VISION_FUNCTION_ENTER(); + + printf("%i barcodes were detected on the image.\n", number_of_barcodes); + if (number_of_barcodes > 0) { + int is_source_data_loaded = 0; + + char *file_name = NULL; + unsigned char *out_buffer = NULL; + unsigned char *draw_buffer = NULL; + unsigned int buf_size = 0; + image_data_s image_data = { 0, 0, MEDIA_VISION_COLORSPACE_INVALID }; + /* Check Media Vision source: */ + if (MEDIA_VISION_ERROR_NONE != + mv_source_get_buffer(source, &out_buffer, &buf_size) || + MEDIA_VISION_ERROR_NONE != + mv_source_get_width(source, &(image_data.image_width)) || + MEDIA_VISION_ERROR_NONE != + mv_source_get_height(source, &(image_data.image_height)) || + MEDIA_VISION_ERROR_NONE != + mv_source_get_colorspace(source, + &(image_data.image_colorspace)) || + user_data == NULL) { + printf("ERROR: Creating out image is impossible.\n"); + } else { + file_name = ((barcode_model_s *)user_data)->out_file_name; + draw_buffer = ((barcode_model_s *)user_data)->out_buffer_ptr; + image_data.image_colorspace = MEDIA_VISION_COLORSPACE_RGB888; + is_source_data_loaded = 1; + } + + int i = 0; + for (i = 0; i < number_of_barcodes; ++i) { + const char *cur_message = messages[i]; + mv_barcode_type_e cur_type = types[i]; + const char *str_type = NULL; + switch (cur_type) { + case MV_BARCODE_QR: + str_type = "QR"; + break; + case MV_BARCODE_UPC_A: + str_type = "UPC-A"; + break; + case MV_BARCODE_UPC_E: + str_type = "UPC-E"; + break; + case MV_BARCODE_EAN_8: + case MV_BARCODE_EAN_13: + str_type = "EAN-8/13"; + break; + case MV_BARCODE_CODE128: + str_type = "CODE128"; + break; + case MV_BARCODE_CODE39: + str_type = "CODE39"; + break; + case MV_BARCODE_I2_5: + str_type = "I25"; + break; + default: + str_type = "Undetected"; + break; + } + printf("\tBarcode %i : type is %s\n", i, str_type); + + if (cur_message != NULL) { + printf("\t message is %s\n", cur_message); + } else { + printf("\t message wasn't detected\n"); + } + + if (is_source_data_loaded == 1) { + int minX = 0; + int minY = 0; + int maxX = 0; + int maxY = 0; + if (MEDIA_VISION_ERROR_NONE != + find_min_x(&barcodes_locations[i], &minX) || + MEDIA_VISION_ERROR_NONE != + find_min_y(&barcodes_locations[i], &minY) || + MEDIA_VISION_ERROR_NONE != + find_max_x(&barcodes_locations[i], &maxX) || + MEDIA_VISION_ERROR_NONE != + find_max_y(&barcodes_locations[i], &maxY)) { + continue; + } + + const int rectangle_thickness = 6; + if (MEDIA_VISION_ERROR_NONE != draw_rectangle_on_buffer( + minX, minY, maxX, maxY, + rectangle_thickness, &image_data, draw_buffer)) { + continue; + } + } + } + + if (file_name != NULL && + MEDIA_VISION_ERROR_NONE == + save_image_from_buffer(file_name, draw_buffer, + &image_data, 100)) { + printf("Image was generated as %s\n", file_name); + } else { + printf("ERROR: Failed to generate output file. " + "Check file name and permissions. \n"); + } + + printf("\n"); + } + + MEDIA_VISION_FUNCTION_LEAVE(); +} + +int generate_barcode_to_image(barcode_model_s model) +{ + MEDIA_VISION_FUNCTION_ENTER(); + + if (model.message == NULL || + model.file_name == NULL) { + MEDIA_VISION_FUNCTION_LEAVE(); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + LOGI("Call the mv_barcode_generate_image() function"); + + mv_engine_config_h mv_engine_config; + int err = mv_create_engine_config(&mv_engine_config); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Errors were occurred during creating the media engine " + "config: %i\n", err); + } + + mv_engine_config_set_int_attribute( + mv_engine_config, + MV_BARCODE_GENERATE_ATTR_TEXT, + MV_BARCODE_GENERATE_ATTR_TEXT_VISIBLE); + + err = mv_barcode_generate_image( + mv_engine_config, + model.message, + model.width, + model.height, + model.type, + model.mode, + model.ecc, + model.version, + model.file_name, + model.out_image_format); + + const int err2 = mv_destroy_engine_config(mv_engine_config); + if (MEDIA_VISION_ERROR_NONE != err2) { + printf("ERROR: Errors were occurred during destroying the media engine " + "config: %i\n", err2); + } + + MEDIA_VISION_FUNCTION_LEAVE(); + + return err; +} + +int generate_barcode_to_source(barcode_model_s model) +{ + MEDIA_VISION_FUNCTION_ENTER(); + + if (model.message == NULL || + model.file_name == NULL) { + MEDIA_VISION_FUNCTION_LEAVE(); + + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + LOGI("mv_source_h creation started"); + + mv_source_h source = NULL; + int err = mv_create_source(&source); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Error occurred when trying to create Media Vision " + "source. Error code: %i\n", err); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return err; + } + + LOGI("mv_source_h creation finished"); + + LOGI("Call the mv_barcode_generate_source() function"); + + mv_engine_config_h mv_engine_config; + err = mv_create_engine_config(&mv_engine_config); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Errors were occurred during creating the media engine " + "config: %i\n", err); + } + + err = mv_barcode_generate_source( + mv_engine_config, + model.message, + model.type, + model.mode, + model.ecc, + model.version, + source); + + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Error occurred during generation barcode to the " + "Media Vision source. Error code: %i\n", err); + + const int err2 = mv_destroy_source(source); + if (MEDIA_VISION_ERROR_NONE != err2) { + printf("ERROR: Error occurred when try to destroy Media Vision " + "source. Error code: %i\n", err2); + } + + const int err3 = mv_destroy_engine_config(mv_engine_config); + if (MEDIA_VISION_ERROR_NONE != err3) { + printf("ERROR: Errors were occurred during destroying the media engine " + "config: %i\n", err3); + } + + MEDIA_VISION_FUNCTION_LEAVE(); + + return err; + } + + unsigned char *data_buffer = NULL; + unsigned int buffer_size = 0; + unsigned int image_width = 0; + unsigned int image_height = 0; + mv_colorspace_e image_colorspace = MEDIA_VISION_COLORSPACE_INVALID; + + bool is_source_corrupted = false; + err = mv_source_get_buffer(source, &data_buffer, &buffer_size); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Error occurred when trying to get buffer from " + "Media Vision source. Error code: %i\n", err); + is_source_corrupted = true; + } + + err = mv_source_get_width(source, &image_width); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Error occurred when trying to get width of " + "Media Vision source. Error code: %i\n", err); + is_source_corrupted = true; + } + + err = mv_source_get_height(source, &image_height); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Error occurred when trying to get height of " + "Media Vision source. Error code: %i\n", err); + is_source_corrupted = true; + } + + err = mv_source_get_colorspace(source, &image_colorspace); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Error occurred when trying to get colorspace of " + "Media Vision source. Error code: %i\n", err); + is_source_corrupted = true; + } + + if (is_source_corrupted) { + err = mv_destroy_source(source); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Error occurred when trying to destroy Media Vision " + "source. Error code: %i\n", err); + } + + err = mv_destroy_engine_config(mv_engine_config); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Errors were occurred during destroying the media engine " + "config: %i\n", err); + } + + MEDIA_VISION_FUNCTION_LEAVE(); + + return MEDIA_VISION_ERROR_INTERNAL; + } + + const image_data_s image_data = { + image_width, image_height, image_colorspace }; + + char *jpeg_file_name = ""; + if (0 == strcmp(model.file_name + strlen(model.file_name) - 4, ".jpg") || + 0 == strcmp(model.file_name + strlen(model.file_name) - 5, ".jpeg")) { + jpeg_file_name = (char *)malloc(strlen(model.file_name) + 1); + if (jpeg_file_name == NULL) { + mv_destroy_source(source); + mv_destroy_engine_config(mv_engine_config); + MEDIA_VISION_FUNCTION_LEAVE(); + return MEDIA_VISION_ERROR_OUT_OF_MEMORY; + } + + strncpy(jpeg_file_name, model.file_name, strlen(model.file_name) + 1); + jpeg_file_name[strlen(model.file_name)] = '\0'; + } else { + jpeg_file_name = (char *)malloc(strlen(model.file_name) + 5); + if (jpeg_file_name == NULL) { + mv_destroy_source(source); + mv_destroy_engine_config(mv_engine_config); + MEDIA_VISION_FUNCTION_LEAVE(); + return MEDIA_VISION_ERROR_OUT_OF_MEMORY; + } + + strncpy(jpeg_file_name, model.file_name, strlen(model.file_name) + 5); + strncpy(jpeg_file_name + strlen(model.file_name), ".jpg", 5); + jpeg_file_name[strlen(model.file_name) + 4] = '\0'; + } + + save_image_from_buffer(jpeg_file_name, data_buffer, &image_data, 100); + + free(jpeg_file_name); + + const int err2 = mv_destroy_source(source); + if (MEDIA_VISION_ERROR_NONE != err2) { + printf("ERROR: Error occurred when try to destroy Media Vision source." + "Error code: %i\n", err2); + } + + const int err3 = mv_destroy_engine_config(mv_engine_config); + if (MEDIA_VISION_ERROR_NONE != err3) { + printf("ERROR: Errors were occurred during destroying the media engine " + "config: %i\n", err); + } + + MEDIA_VISION_FUNCTION_LEAVE(); + + return err; +} + +int detect_barcode(barcode_model_s model, mv_rectangle_s roi) +{ + MEDIA_VISION_FUNCTION_ENTER(); + + unsigned char *data_buffer = NULL; + unsigned long buffer_size = 0; + image_data_s image_data; + + int err = load_image_to_buffer( + model.file_name, &data_buffer, &buffer_size, &image_data); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Errors were occurred during opening the file!!! " + "Error code: %i\n", err); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return err; + } + + unsigned char *converted_buffer = NULL; + unsigned long converted_buffer_size = 0; + + err = convert_rgb_to( + data_buffer, + &converted_buffer, + image_data, + model.colorspace, + &converted_buffer_size); + + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Can't convert to the selected colorspace!!! code: %i\n", + err); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return err; + } + + model.out_buffer_ptr = data_buffer; + + mv_engine_config_h mv_engine_config; + err = mv_create_engine_config(&mv_engine_config); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Errors were occurred during creating the media engine " + "config: %i\n", err); + } + + mv_engine_config_foreach_supported_attribute( + _mv_engine_config_supported_attribute, mv_engine_config); + + mv_engine_config_set_int_attribute( + mv_engine_config, + MV_BARCODE_DETECT_ATTR_TARGET, + MV_BARCODE_DETECT_ATTR_TARGET_2D_BARCODE); + + mv_source_h source; + err = mv_create_source(&source); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Errors were occurred during creating the source!!! " + "Error code: %i\n", err); + + if (data_buffer != NULL) { + free(data_buffer); + } + + if (converted_buffer != NULL) { + free(converted_buffer); + } + mv_destroy_source(source); + mv_destroy_engine_config(mv_engine_config); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return err; + } + + err = mv_source_fill_by_buffer( + source, converted_buffer, + converted_buffer_size, + image_data.image_width, + image_data.image_height, + model.colorspace); + + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Errors were occurred during filling the source!!! " + "Error code: %i\n", err); + + if (data_buffer != NULL) { + free(data_buffer); + } + + if (converted_buffer != NULL) { + free(converted_buffer); + } + + mv_destroy_source(source); + mv_destroy_engine_config(mv_engine_config); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return err; + } + + if (converted_buffer != NULL) { + free(converted_buffer); + } + + err = mv_barcode_detect( + source, mv_engine_config, roi, barcode_detected_cb, &model); + + if (data_buffer != NULL) { + free(data_buffer); + } + + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Errors were occurred during barcode detection!!! " + "Error code: %i\n", err); + + mv_destroy_source(source); + mv_destroy_engine_config(mv_engine_config); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return err; + } + + err = mv_destroy_source(source); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Errors were occurred during destroying the source!!! " + "Error code: %i\n", err); + } + + err = mv_destroy_engine_config(mv_engine_config); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Error were occurred during destroying the source!!! " + "Error code: %i\n", err); + } + + MEDIA_VISION_FUNCTION_LEAVE(); + + return err; +} + +int input_string(const char *prompt, size_t max_len, char **string) +{ + MEDIA_VISION_FUNCTION_ENTER(); + + printf("\n"); + printf("%s ", prompt); + + if (scanf("\n") != 0) { + MEDIA_VISION_FUNCTION_LEAVE(); + return -1; + } + + char buffer[max_len]; + int last_char = 0; + buffer[last_char] = '\0'; + buffer[sizeof(buffer) - 1] = ~'\0'; + if (fgets(buffer, sizeof(buffer), stdin) == NULL) { + MEDIA_VISION_FUNCTION_LEAVE(); + return -1; + } + + size_t real_string_len = strlen(buffer); + buffer[real_string_len - 1] = '\0'; + *string = (char *)malloc(real_string_len * sizeof(char)); + if (*string == NULL) { + MEDIA_VISION_FUNCTION_LEAVE(); + return -1; + } + + strncpy(*string, buffer, real_string_len); + + size_t str_len = strlen(*string); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return str_len; +} + +int input_size(const char *prompt, size_t max_size, size_t *size) +{ + MEDIA_VISION_FUNCTION_ENTER(); + + printf("\n"); + printf("%s ", prompt); + + if (scanf("%20zu", size) == 0) { + if (scanf("%*[^\n]%*c") != 0) { + printf("ERROR: Reading the input line error.\n"); + MEDIA_VISION_FUNCTION_LEAVE(); + return -1; + } + printf("ERROR: Incorrect input.\n"); + MEDIA_VISION_FUNCTION_LEAVE(); + return -1; + } + + int ret = (*size > max_size ? -1 : 0); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int input_int(const char *prompt, int min_value, int max_value, int *value) +{ + MEDIA_VISION_FUNCTION_ENTER(); + + printf("\n"); + printf("%s ", prompt); + + if (scanf("%20i", value) == 0) { + if (scanf("%*[^\n]%*c") != 0) { + printf("ERROR: Reading the input line error.\n"); + MEDIA_VISION_FUNCTION_LEAVE(); + return -1; + } + printf("ERROR: Incorrect input.\n"); + MEDIA_VISION_FUNCTION_LEAVE(); + return -1; + } + + int ret = (*value < min_value || *value > max_value ? -1 : 0); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int show_menu( + const char *title, + const int *options, + const char **names, + int cnt) +{ + MEDIA_VISION_FUNCTION_ENTER(); + + printf("***************************\n"); + printf("* %23s *\n", title); + printf("*-------------------------*\n"); + int i = 0; + for (i = 0; i < cnt; ++i) { + printf("* %2i. %19s *\n", options[i], names[i]); + } + printf("***************************\n\n"); + int selection = 0; + printf("Your choise: "); + if (scanf("%20i", &selection) == 0) { + if (scanf("%*[^\n]%*c") != 0) { + printf("ERROR: Reading the input line error.\n"); + MEDIA_VISION_FUNCTION_LEAVE(); + return -1; + } + printf("ERROR: Incorrect input.\n"); + } + + MEDIA_VISION_FUNCTION_LEAVE(); + + return selection; +} + +mv_barcode_type_e select_type(void) +{ + mv_barcode_type_e selected_type = MV_BARCODE_UNDEFINED; + int sel_opt = 0; + const int options[8] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + const char *names[8] = { "qr", "upca", "upce", "ean8", + "ean13", "code39", "code128", "interleave25" }; + + MEDIA_VISION_FUNCTION_ENTER(); + + while (sel_opt == 0) { + sel_opt = show_menu("Select barcode type:", options, names, 8); + + switch (sel_opt) { + case 1: + selected_type = MV_BARCODE_QR; + break; + case 2: + selected_type = MV_BARCODE_UPC_A; + break; + case 3: + selected_type = MV_BARCODE_UPC_E; + break; + case 4: + selected_type = MV_BARCODE_EAN_8; + break; + case 5: + selected_type = MV_BARCODE_EAN_13; + break; + case 6: + selected_type = MV_BARCODE_CODE39; + break; + case 7: + selected_type = MV_BARCODE_CODE128; + break; + case 8: + selected_type = MV_BARCODE_I2_5; + break; + default: + sel_opt = 0; + break; + } + } + + MEDIA_VISION_FUNCTION_LEAVE(); + + return selected_type; +} + +mv_barcode_qr_mode_e select_mode(void) +{ + mv_barcode_qr_mode_e selected_mode = MV_BARCODE_QR_MODE_UNAVAILABLE; + int sel_opt = 0; + const int options[4] = { 1, 2, 3, 4 }; + const char *names[4] = { "numeric", "alphanumeric", "byte", "utf8" }; + + MEDIA_VISION_FUNCTION_ENTER(); + + while (sel_opt == 0) { + sel_opt = show_menu("Select encoding mode:", options, names, 4); + switch (sel_opt) { + case 1: + selected_mode = MV_BARCODE_QR_MODE_NUMERIC; + break; + case 2: + selected_mode = MV_BARCODE_QR_MODE_ALPHANUMERIC; + break; + case 3: + selected_mode = MV_BARCODE_QR_MODE_BYTE; + break; + case 4: + selected_mode = MV_BARCODE_QR_MODE_UTF8; + break; + default: + sel_opt = 0; + break; + } + } + + MEDIA_VISION_FUNCTION_LEAVE(); + + return selected_mode; +} + +mv_barcode_qr_ecc_e select_ecc(void) +{ + mv_barcode_qr_ecc_e selected_ecc = MV_BARCODE_QR_ECC_UNAVAILABLE; + int sel_opt = 0; + const int options[4] = { 1, 2, 3, 4 }; + const char *names[4] = { "low", "medium", "quartile", "high" }; + + MEDIA_VISION_FUNCTION_ENTER(); + + while (sel_opt == 0) { + sel_opt = show_menu("Select ECC level:", options, names, 4); + switch (sel_opt) { + case 1: + selected_ecc = MV_BARCODE_QR_ECC_LOW; + break; + case 2: + selected_ecc = MV_BARCODE_QR_ECC_MEDIUM; + break; + case 3: + selected_ecc = MV_BARCODE_QR_ECC_QUARTILE; + break; + case 4: + selected_ecc = MV_BARCODE_QR_ECC_HIGH; + break; + default: + sel_opt = 0; + break; + } + } + + MEDIA_VISION_FUNCTION_LEAVE(); + + return selected_ecc; +} + +int select_version(void) +{ + MEDIA_VISION_FUNCTION_ENTER(); + + int sel_opt = 0; + while (sel_opt == 0) { + const int options[2] = {1, 40}; + const char *names[2] = { "1..", "..40" }; + sel_opt = show_menu("Select QR version:", options, names, 2); + if (sel_opt < 1 || sel_opt > 40) { + sel_opt = 0; + } + } + + MEDIA_VISION_FUNCTION_LEAVE(); + + return sel_opt; +} + +generation_fcn_e select_gen_function(void) +{ + generation_fcn_e ret_fcn_type = MV_TS_GENERATE_TO_IMAGE_FCN; + int sel_opt = 0; + const int options[2] = { 1, 2 }; + const char *names[2] = { "Generate to file", "Generate to source" }; + + MEDIA_VISION_FUNCTION_ENTER(); + + while (sel_opt == 0) { + sel_opt = show_menu("Select API function:", options, names, 2); + switch (sel_opt) { + case 1: + ret_fcn_type = MV_TS_GENERATE_TO_IMAGE_FCN; + break; + case 2: + ret_fcn_type = MV_TS_GENERATE_TO_SOURCE_FCN; + break; + default: + sel_opt = 0; + break; + } + } + + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret_fcn_type; +} + +mv_barcode_image_format_e select_file_format(void) +{ + mv_barcode_image_format_e image_format = MV_BARCODE_IMAGE_FORMAT_JPG; + int sel_opt = 0; + const int options[3] = { 1, 2, 3 }; + const char *names[3] = { "BMP", "JPG", "PNG" }; + + MEDIA_VISION_FUNCTION_ENTER(); + + while (sel_opt == 0) { + sel_opt = show_menu("Select file format:", options, names, 3); + switch (sel_opt) { + case 1: + image_format = MV_BARCODE_IMAGE_FORMAT_BMP; + break; + case 2: + image_format = MV_BARCODE_IMAGE_FORMAT_JPG; + break; + case 3: + image_format = MV_BARCODE_IMAGE_FORMAT_PNG; + break; + default: + sel_opt = 0; + break; + } + } + + MEDIA_VISION_FUNCTION_LEAVE(); + + return image_format; +} + +int perform_detect() +{ + MEDIA_VISION_FUNCTION_ENTER(); + + barcode_model_s detect_model = { + MV_BARCODE_UNDEFINED, + MV_BARCODE_QR_ECC_UNAVAILABLE, + MV_BARCODE_QR_MODE_UNAVAILABLE, + 0, 0, 0, + MV_BARCODE_IMAGE_FORMAT_PNG, + MEDIA_VISION_COLORSPACE_INVALID, + NULL, NULL, NULL, NULL }; + + while (-1 == input_string( + "Input file name to be analyzed:", + 1024, + &(detect_model.file_name))) { + printf("Incorrect input! Try again.\n"); + } + LOGI("Barcode input image has been specified"); + + mv_rectangle_s roi = { {0, 0}, 0, 0 }; + + while (-1 == input_int("Input x coordinate for ROI top left vertex:", + 0, 10000, &(roi.point.x))) { + printf("Incorrect input! Try again.\n"); + } + + while (-1 == input_int("Input y coordinate for ROI top left vertex:", + 0, 10000, &(roi.point.y))) { + printf("Incorrect input! Try again.\n"); + } + + while (input_int("Input ROI width:", 0, 10000, &(roi.width)) == -1) { + printf("Incorrect input! Try again.\n"); + } + + while (input_int("Input ROI height:", 0, 10000, &(roi.height)) == -1) { + printf("Incorrect input! Try again.\n"); + } + LOGI("Region of interest (ROI) to detect barcode into has been specified"); + + while (-1 == input_string("Input file name to be generated:", + 1024, &(detect_model.out_file_name))) { + printf("Incorrect input! Try again.\n"); + } + LOGI("Barcode output image has been specified"); + + const int options[11] = { MEDIA_VISION_COLORSPACE_Y800, + MEDIA_VISION_COLORSPACE_I420, + MEDIA_VISION_COLORSPACE_NV12, + MEDIA_VISION_COLORSPACE_YV12, + MEDIA_VISION_COLORSPACE_NV21, + MEDIA_VISION_COLORSPACE_YUYV, + MEDIA_VISION_COLORSPACE_UYVY, + MEDIA_VISION_COLORSPACE_422P, + MEDIA_VISION_COLORSPACE_RGB565, + MEDIA_VISION_COLORSPACE_RGB888, + MEDIA_VISION_COLORSPACE_RGBA }; + const char *names[11] = { "Y800", "I420", "NV12", "YV12", "NV21", + "YUYV", "UYVY", "422P", "RGB565", + "RGB888", "RGBA" }; + + while (true) { + int sel_opt = show_menu("Select colorspace to test detector on:", + options, names, 11); + if (sel_opt < MEDIA_VISION_COLORSPACE_Y800 || + sel_opt > MEDIA_VISION_COLORSPACE_RGBA) { + continue; + } + detect_model.colorspace = (mv_colorspace_e)sel_opt; + LOGI("User selection is %i", sel_opt); + break; + } + + int err = detect_barcode(detect_model, roi); + + if (detect_model.file_name != NULL) { + free(detect_model.file_name); + } + + if (detect_model.out_file_name != NULL) { + free(detect_model.out_file_name); + } + + if (err != MEDIA_VISION_ERROR_NONE) { + LOGE("Barcode detection failed with error code (0x%08x)", err); + } + + MEDIA_VISION_FUNCTION_LEAVE(); + + return err; +} + +int perform_generate(void) +{ + MEDIA_VISION_FUNCTION_ENTER(); + + barcode_model_s generate_model = { + MV_BARCODE_UNDEFINED, + MV_BARCODE_QR_ECC_UNAVAILABLE, + MV_BARCODE_QR_MODE_UNAVAILABLE, + 0, 0, 0, + MV_BARCODE_IMAGE_FORMAT_PNG, + MEDIA_VISION_COLORSPACE_INVALID, + NULL, NULL, NULL, NULL }; + + generation_fcn_e gen_fcn = select_gen_function(); + generate_model.type = select_type(); + LOGI("Barcode type has been selected"); + + if (generate_model.type == MV_BARCODE_QR) { + generate_model.mode = select_mode(); + LOGI("Barcode encoding mode has been selected"); + generate_model.ecc = select_ecc(); + LOGI("Barcode ecc level has been selected"); + generate_model.version = select_version(); + LOGI("Barcode version has been selected"); + } + + if (gen_fcn == MV_TS_GENERATE_TO_IMAGE_FCN) { + generate_model.out_image_format = select_file_format(); + LOGI("Barcode output image format has been selected"); + } + + while (-1 == input_string("Input message:", 7089, &generate_model.message)) { + printf("Incorrect input! Try again.\n"); + } + LOGI("Barcode message has been specified"); + + while (-1 == input_string("Input file name:", + 1024, &generate_model.file_name)) { + printf("Incorrect input! Try again.\n"); + } + LOGI("Barcode output file name has been specified"); + + if (gen_fcn == MV_TS_GENERATE_TO_IMAGE_FCN) { + while (-1 == input_size("Input image width:", + 10000, &generate_model.width)) { + printf("Incorrect input! Try again.\n"); + } + LOGI("Barcode output file width has been specified"); + + while (-1 == input_size("Input image height:", + 10000, &generate_model.height)) { + printf("Incorrect input! Try again.\n"); + } + LOGI("Barcode output file height has been specified"); + } + + const int err = + gen_fcn == MV_TS_GENERATE_TO_IMAGE_FCN ? + generate_barcode_to_image(generate_model) : + generate_barcode_to_source(generate_model); + + if (generate_model.message != NULL) { + free(generate_model.message); + } + + if (generate_model.file_name != NULL) { + free(generate_model.file_name); + } + + if (err != MEDIA_VISION_ERROR_NONE) { + LOGE("Barcode generation failed with error code (0x%08x)", err); + printf("ERROR: Errors were occurred during barcode generation!!!\n"); + MEDIA_VISION_FUNCTION_LEAVE(); + return err; + } + + LOGI("Barcode output file has been generated"); + printf("\nBarcode image was successfully generated.\n"); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return 0; +} + +int main(void) +{ + LOGI("Media Vision Testsuite is launched."); + + int err = MEDIA_VISION_ERROR_NONE; + + int sel_opt = 0; + const int options[2] = { 1, 2 }; + const char *names[2] = { "Generate", "Detect" }; + + while (sel_opt == 0) { + sel_opt = show_menu("Select action:", options, names, 2); + switch (sel_opt) { + case 1: + LOGI("Start the barcode generation flow"); + err = perform_generate(); + break; + case 2: + LOGI("Start the barcode detection flow"); + err = perform_detect(); + break; + default: + sel_opt = 0; + continue; + } + + int do_another = 0; + + if (err != MEDIA_VISION_ERROR_NONE) { + printf("ERROR: Action is finished with error code: %i\n", err); + } + + sel_opt = 0; + const int options_last[2] = { 1, 2 }; + const char *names_last[2] = { "YES", "NO" }; + + while (sel_opt == 0) { + sel_opt = show_menu("Perform another action?", + options_last, names_last, 2); + switch (sel_opt) { + case 1: + do_another = 1; + break; + case 2: + do_another = 0; + break; + default: + sel_opt = 0; + break; + } + } + LOGI("User selection is %i", sel_opt); + + sel_opt = (do_another == 1 ? 0 : sel_opt); + } + + LOGI("Media Vision Testsuite is closed."); + + return err; +} |