From b8ccdef0306cf19cde9511ec244fd43b4ae1d863 Mon Sep 17 00:00:00 2001 From: Jinkun Jang Date: Wed, 13 Mar 2013 01:49:53 +0900 Subject: Tizen 2.1 base --- AUTHORS | 2 + CMakeLists.txt | 105 + LICENSE | 708 ++++++ LICENSE.APLv2.0 | 202 ++ LICENSE.LGPLv2.1 | 504 ++++ NOTICE | 9 + include/media-thumb-error.h | 63 + include/media-thumb-types.h | 37 + include/media-thumbnail-private.h | 77 + include/media-thumbnail.h | 234 ++ libmedia-thumbnail.manifest | 6 + md5/md5.c | 253 ++ md5/md5.h | 39 + md5/media-thumb-hash.c | 132 + media-thumbnail-server.manifest | 12 + media-thumbnail.pc.in | 13 + packaging/libmedia-thumbnail.spec | 82 + server/include/thumb-server-internal.h | 55 + server/thumb-server-internal.c | 412 ++++ server/thumb-server.c | 122 + src/codec/IfegDecodeAGIF.c | 4169 ++++++++++++++++++++++++++++++++ src/codec/img-codec-osal.c | 166 ++ src/codec/img-codec-parser.c | 887 +++++++ src/codec/img-codec.c | 266 ++ src/include/codec/AGifFrameInfo.h | 65 + src/include/codec/IfegDecodeAGIF.h | 57 + src/include/codec/img-codec-agif.h | 28 + src/include/codec/img-codec-common.h | 304 +++ src/include/codec/img-codec-config.h | 26 + src/include/codec/img-codec-osal.h | 129 + src/include/codec/img-codec-parser.h | 48 + src/include/codec/img-codec.h | 49 + src/include/ipc/media-thumb-ipc.h | 125 + src/include/media-thumb-internal.h | 81 + src/include/util/media-thumb-db.h | 79 + src/include/util/media-thumb-debug.h | 81 + src/include/util/media-thumb-util.h | 146 ++ src/ipc/media-thumb-ipc.c | 634 +++++ src/media-thumb-internal.c | 1302 ++++++++++ src/media-thumbnail.c | 288 +++ src/util/media-thumb-db.c | 609 +++++ src/util/media-thumb-debug.c | 112 + src/util/media-thumb-util.c | 374 +++ test/test-thumb.c | 246 ++ thumbsvr | 4 + 45 files changed, 13342 insertions(+) create mode 100644 AUTHORS create mode 100644 CMakeLists.txt create mode 100644 LICENSE create mode 100644 LICENSE.APLv2.0 create mode 100644 LICENSE.LGPLv2.1 create mode 100644 NOTICE create mode 100755 include/media-thumb-error.h create mode 100755 include/media-thumb-types.h create mode 100755 include/media-thumbnail-private.h create mode 100755 include/media-thumbnail.h create mode 100644 libmedia-thumbnail.manifest create mode 100644 md5/md5.c create mode 100644 md5/md5.h create mode 100644 md5/media-thumb-hash.c create mode 100644 media-thumbnail-server.manifest create mode 100755 media-thumbnail.pc.in create mode 100644 packaging/libmedia-thumbnail.spec create mode 100755 server/include/thumb-server-internal.h create mode 100755 server/thumb-server-internal.c create mode 100755 server/thumb-server.c create mode 100644 src/codec/IfegDecodeAGIF.c create mode 100644 src/codec/img-codec-osal.c create mode 100644 src/codec/img-codec-parser.c create mode 100644 src/codec/img-codec.c create mode 100644 src/include/codec/AGifFrameInfo.h create mode 100644 src/include/codec/IfegDecodeAGIF.h create mode 100644 src/include/codec/img-codec-agif.h create mode 100644 src/include/codec/img-codec-common.h create mode 100644 src/include/codec/img-codec-config.h create mode 100644 src/include/codec/img-codec-osal.h create mode 100644 src/include/codec/img-codec-parser.h create mode 100644 src/include/codec/img-codec.h create mode 100755 src/include/ipc/media-thumb-ipc.h create mode 100755 src/include/media-thumb-internal.h create mode 100755 src/include/util/media-thumb-db.h create mode 100755 src/include/util/media-thumb-debug.h create mode 100755 src/include/util/media-thumb-util.h create mode 100755 src/ipc/media-thumb-ipc.c create mode 100755 src/media-thumb-internal.c create mode 100755 src/media-thumbnail.c create mode 100755 src/util/media-thumb-db.c create mode 100755 src/util/media-thumb-debug.c create mode 100755 src/util/media-thumb-util.c create mode 100755 test/test-thumb.c create mode 100644 thumbsvr diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..6a7e17d --- /dev/null +++ b/AUTHORS @@ -0,0 +1,2 @@ +Hyunjun Ko + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a4883f7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,105 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(media-thumbnail C) +SET(VERSION_MAJOR 1) +SET(VERSION "${VERSION_MAJOR}.0.0") + +SET(MEDIATHUMB-LIB "media-thumbnail") +SET(MEDIAHASH-LIB "media-hash") +SET(SRCS + src/media-thumbnail.c + src/media-thumb-internal.c + src/util/media-thumb-debug.c + src/util/media-thumb-util.c + src/util/media-thumb-db.c + src/codec/IfegDecodeAGIF.c + src/codec/img-codec.c + src/codec/img-codec-osal.c + src/codec/img-codec-parser.c + src/ipc/media-thumb-ipc.c + ) +SET(HASH_SRCS + md5/md5.c + md5/media-thumb-hash.c + ) + +SET(THUMB-SERVER server/thumb-server.c server/thumb-server-internal.c) +SET(TEST-THUMB test/test-thumb.c) + +SET(VENDOR "samsung") +SET(PACKAGE ${PROJECT_NAME}) +SET(PKGNAME "com.${VENDOR}.${PACKAGE}") +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(BINDIR "${PREFIX}/bin") +SET(LOCALBINDIR "${PREFIX}/local/bin") +SET(DATADIR "${PREFIX}/share") +SET(EXEC_PREFIX "\${prefix}") +SET(LIBDIR "\${prefix}/lib") +SET(INCLUDEDIR "\${prefix}/include") + +IF("${CMAKE_BUILD_TYPE}" STREQUAL "") + SET(CMAKE_BUILD_TYPE "Release") +ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") +MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src/include ${CMAKE_SOURCE_DIR}/src/include/util ${CMAKE_SOURCE_DIR}/src/include/codec ${CMAKE_SOURCE_DIR}/src/include/util ${CMAKE_SOURCE_DIR}/src/include/ipc ${CMAKE_SOURCE_DIR}/server/include ${CMAKE_SOURCE_DIR}/md5) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED +glib-2.0 gthread-2.0 dlog mm-fileinfo drm-client aul +libexif ecore-evas evas mmutil-imgp mmutil-jpeg heynoti libmedia-utils) + + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2 -fPIC") + +FIND_PROGRAM(UNAME NAMES uname) +EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") + MESSAGE("add -DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +ADD_DEFINITIONS("-DVENDOR=\"${VENDOR}\"") +ADD_DEFINITIONS("-DPACKAGE=\"${PACKAGE}\"") +ADD_DEFINITIONS("-DPACKAGE_NAME=\"${PKGNAME}\"") +ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"") +#ADD_DEFINITIONS("-D_PERFORMANCE_CHECK_") +ADD_DEFINITIONS("-D_USE_NEW_MEDIA_DB_") +ADD_DEFINITIONS("-D_USE_MEDIA_UTIL_") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--hash-style=both") +CONFIGURE_FILE(media-thumbnail.pc.in media-thumbnail.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/media-thumbnail.pc DESTINATION lib/pkgconfig) + +LINK_DIRECTORIES(lib) + +ADD_LIBRARY(${MEDIAHASH-LIB} SHARED ${HASH_SRCS}) +SET_TARGET_PROPERTIES(${MEDIAHASH-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR}) +SET_TARGET_PROPERTIES(${MEDIAHASH-LIB} PROPERTIES VERSION ${VERSION}) +ADD_LIBRARY(${MEDIATHUMB-LIB} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${MEDIATHUMB-LIB} ${pkgs_LDFLAGS} ${MEDIAHASH-LIB}) +SET_TARGET_PROPERTIES(${MEDIATHUMB-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR}) +SET_TARGET_PROPERTIES(${MEDIATHUMB-LIB} PROPERTIES VERSION ${VERSION}) + +INSTALL(TARGETS ${MEDIATHUMB-LIB} LIBRARY DESTINATION lib) +INSTALL(TARGETS ${MEDIAHASH-LIB} LIBRARY DESTINATION lib) + +ADD_EXECUTABLE(media-thumbnail-server ${THUMB-SERVER}) +TARGET_LINK_LIBRARIES(media-thumbnail-server ${pkgs_LDFLAGS} ${MEDIATHUMB-LIB} ) +INSTALL(TARGETS media-thumbnail-server DESTINATION ${BINDIR}) + +ADD_EXECUTABLE(test-thumb ${TEST-THUMB}) +TARGET_LINK_LIBRARIES(test-thumb ${pkgs_LDFLAGS} ${MEDIATHUMB-LIB} ) +INSTALL(TARGETS test-thumb DESTINATION ${LOCALBINDIR}) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/media-thumbnail.h DESTINATION include/${MEDIATHUMB-LIB}) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/media-thumbnail-private.h DESTINATION include/${MEDIATHUMB-LIB}) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/media-thumb-error.h DESTINATION include/${MEDIATHUMB-LIB}) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/media-thumb-types.h DESTINATION include/${MEDIATHUMB-LIB}) +#INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/thumbsvr DESTINATION /etc/init.d) + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..608d4f8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,708 @@ + 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. + + + + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/LICENSE.APLv2.0 b/LICENSE.APLv2.0 new file mode 100644 index 0000000..57bc88a --- /dev/null +++ b/LICENSE.APLv2.0 @@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/LICENSE.LGPLv2.1 b/LICENSE.LGPLv2.1 new file mode 100644 index 0000000..8add30a --- /dev/null +++ b/LICENSE.LGPLv2.1 @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..8c57009 --- /dev/null +++ b/NOTICE @@ -0,0 +1,9 @@ +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. + +Some parts of libmedia-thumbnail are licensed under the GNU Lesser General Public License version 2.1 +See the LICENSE file for LGPL License terms and conditions. +Specifically, the LGPL parts of libmedia-thumbnail are + - md5/media-svc-hash.c + diff --git a/include/media-thumb-error.h b/include/media-thumb-error.h new file mode 100755 index 0000000..3ec6cbe --- /dev/null +++ b/include/media-thumb-error.h @@ -0,0 +1,63 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 _MEDIA_THUMB_ERROR_H_ +#define _MEDIA_THUMB_ERROR_H_ + +/** + @addtogroup THUMB_GENERATE + @{ + * @file media-thumb-error.h + * @brief This file defines error codes for thumbnail generation. + + */ + +/** + @defgroup THUMB_GENERAE_ERROR error code + @{ + + @par + error code + */ + + +#define MEDIA_THUMB_ERROR_NONE 0 /* No Error */ +#define MEDIA_THUMB_ERROR_INVALID_PARAMETER -1 /* invalid parameter(s) */ +#define MEDIA_THUMB_ERROR_TOO_BIG -2 /* Original is too big to make thumb */ +#define MEDIA_THUMB_ERROR_MM_UTIL -3 /* Error in mm-util lib */ +#define MEDIA_THUMB_ERROR_UNSUPPORTED -4 /* Unsupported type */ +#define MEDIA_THUMB_ERROR_NETWORK -5 /* Error in socket */ +#define MEDIA_THUMB_ERROR_DB -6 /* Timeout */ +#define MEDIA_THUMB_ERROR_TIMEOUT -7 /* Timeout */ +#define MEDIA_THUMB_ERROR_HASHCODE -8 /* Failed to generate hash code */ +#define MEDIA_THUMB_ERROR_DUPLICATED_REQUEST -9 /* Duplicated request of same path */ + +/** + @} +*/ + +/** + @} +*/ + +#endif /*_MEDIA_THUMB_ERROR_H_*/ diff --git a/include/media-thumb-types.h b/include/media-thumb-types.h new file mode 100755 index 0000000..3387a6c --- /dev/null +++ b/include/media-thumb-types.h @@ -0,0 +1,37 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 _MEDIA_THUMB_TYPES_H_ +#define _MEDIA_THUMB_TYPES_H_ + +typedef enum { + MEDIA_THUMB_LARGE, + MEDIA_THUMB_SMALL, +} media_thumb_type; + +typedef enum { + MEDIA_THUMB_BGRA, /* BGRA, especially provided for evas users */ + MEDIA_THUMB_RGB888, /* RGB888 */ +} media_thumb_format; + +#endif /*_MEDIA_THUMB_TYPES_H_*/ diff --git a/include/media-thumbnail-private.h b/include/media-thumbnail-private.h new file mode 100755 index 0000000..e606141 --- /dev/null +++ b/include/media-thumbnail-private.h @@ -0,0 +1,77 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 _MEDIA_THUMBNAIL_PRIVATE_H_ +#define _MEDIA_THUMBNAIL_PRIVATE_H_ + +#include "media-thumb-error.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * thumbnail_generate_hash_code : + * This function generates a hash code using its original path by md5 algorithm. + * If done, the code will be returned. + * + * @return This function returns zero(MEDIA_THUMB_ERROR_NONE) on success, or negative value with error code. + * Please refer 'media-thumb-error.h' to know the exact meaning of the error. + * @param[in] origin_path The path of the original media + * @param[out] hash_code The hash code generated by md5 algorithm. + * @param[in] max_length The max length of the returned hash code. + * @see None. + * @pre None. + * @post None. + * @remark None. + * @par example + * @code + +#include + +void gen_thumb_hash_code() +{ + int ret = MEDIA_THUMB_ERROR_NONE; + const char *origin_path = "/opt/usr/media/test.jpg"; + char hashcode[255]; + + ret = thumbnail_generate_hash_code(origin_path, hashcode, 255); + + if (ret < 0) { + printf( "thumbnail_generate_hash_code fails. error code->%d", ret); + } + + return; +} + + * @endcode + */ +int thumbnail_generate_hash_code(const char *origin_path, char *hash_code, int max_length); + + +#ifdef __cplusplus +} +#endif + +#endif /*_MEDIA_THUMBNAIL_PRIVATE_H_*/ + diff --git a/include/media-thumbnail.h b/include/media-thumbnail.h new file mode 100755 index 0000000..5b38585 --- /dev/null +++ b/include/media-thumbnail.h @@ -0,0 +1,234 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 _MEDIA_THUMBNAIL_H_ +#define _MEDIA_THUMBNAIL_H_ + +#include "media-thumb-types.h" +#include "media-thumb-error.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + @defgroup THUMB_GENERATE Thumbnail generator + @{ + * @file media-thumbnail.h + * @brief This file defines API's for thumbnail generator. + * @version 1.0 + */ + +/** + @defgroup THUMB_API Thumbnail generator API + @{ + + @par + generates thumbnail data and return the path of the generated thumbnail file. + */ + + +/** + * Callback function, which is used to call thumbnail_request_from_db_async + */ + +typedef int (*ThumbFunc) (int error_code, char* path, void* data); + + +/** + * thumbnail_request_from_db: + * This function connects to the media database and find thumbnail path of the passed original image. + * If found, the thumbnail path will be returned, or starts to generate thumbnail + * + * @return This function returns zero(MEDIA_THUMB_ERROR_NONE) on success, or negative value with error code. + * Please refer 'media-thumb-error.h' to know the exact meaning of the error. + * @param[in] origin_path The path of the original image + * @param[out] thumb_path The path of generated thumbnail image. + * @param[in] max_length The max length of the returned thumbnail path. + * @see None. + * @pre None. + * @post None. + * @remark The database name is "/opt/usr/dbspace/.media.db". + * @par example + * @code + +#include + +void gen_thumbs() +{ + int ret = MEDIA_THUMB_ERROR_NONE; + const char *origin_path = "/opt/usr/media/test.jpg"; + char thumb_path[255]; + + ret = thumbnail_request_from_db(origin_path, thumb_path, 255); + + if (ret < 0) + { + printf( "thumbnail_request_from_db fails. error code->%d", ret); + } + + return; +} + + * @endcode + */ +int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max_length); + +/** + * thumbnail_request_from_db_async: + * This function connects to the media database and find thumbnail path of the passed original image. + * If found, the thumbnail path will be returned through callback, which is registered by user. + * + * @return This function returns zero(MEDIA_THUMB_ERROR_NONE) on success, or negative value with error code. + * Please refer 'media-thumb-error.h' to know the exact meaning of the error. + * @param[in] origin_path The path of the original image + * @param[in] func The callback, which is registered by user + * @param[in] user_data User data, which is used by user in callback + * @see None. + * @pre None. + * @post None. + * @remark The database name is "/opt/usr/dbspace/.media.db". + * @par example + * @code + +#include + +int _thumb_cb(int error_code, char *path, void *user_data) +{ + printf("Error code : %d\n", error_code); + printf("Thumb path : %s\n", path); +} + +void gen_thumbs() +{ + int ret = MEDIA_THUMB_ERROR_NONE; + const char *origin_path = "/opt/usr/media/test.jpg"; + char thumb_path[255]; + + ret = thumbnail_request_from_db_async(origin_path, _thumb_cb, NULL); + + if (ret < 0) + { + printf( "thumbnail_request_from_db_async fails. error code->%d", ret); + } + + return; +} + + * @endcode + */ +int thumbnail_request_from_db_async(const char *origin_path, ThumbFunc func, void *user_data); + +/** + * thumbnail_request_save_to_file: + * This function generates thumbnail of the original path and save it to the file system as jpeg format with the passed thumbnail path. + * This function doesn't care about media DB. + * + * @return This function returns zero(MEDIA_THUMB_ERROR_NONE) on success, or negative value with error code. + * Please refer 'media-thumb-error.h' to know the exact meaning of the error. + * @param[in] origin_path The path of the original image + * @param[in] thumb_type The type of the returned thumbnail data. + * @param[in] thumb_path The path of generated thumbnail image. + * @see None. + * @pre None. + * @post None. + * @par example + * @code + +#include + +void save_thumbs() +{ + int ret = MEDIA_THUMB_ERROR_NONE; + const char *origin_path = "/opt/usr/media/test.jpg"; + const char *thumb_path = "/my_dir/thumb.jpg"; + + ret = thumbnail_request_save_to_file(origin_path, thumb_path); + + if (ret < 0) { + printf( "thumbnail_request_save_to_file fails. error code->%d", ret); + } + + return; +} + + * @endcode + */ +int thumbnail_request_save_to_file(const char *origin_path, + media_thumb_type thumb_type, + const char *thumb_path); + + +/** + * thumbnail_request_extract_all_thumbs: + * This function generates thumbnail of all media, which don't have thumbnail yet and save it to the file system as jpeg format. + * Once thumbnail generated, the thumbnail path and original image's width and height will be updated to media database. + * + * @return This function returns zero(MEDIA_THUMB_ERROR_NONE) on success, or negative value with error code. + * Please refer 'media-thumb-error.h' to know the exact meaning of the error. + * @see None. + * @pre None. + * @post None. + * @par example + * @code + +#include + +void extract_all_thumbs() +{ + int ret = MEDIA_THUMB_ERROR_NONE; + + ret = thumbnail_request_extract_all_thumbs(); + + if (ret < 0) { + printf( "thumbnail_request_extract_all_thumbs fails. error code->%d", ret); + } + + return; +} + + * @endcode + */ + +int thumbnail_request_extract_all_thumbs(void); + +int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_path, int max_length, int *origin_width, int *origin_height); + +/* Cancel APIs that a request to extract thumbnail */ +int thumbnail_request_cancel_media(const char *origin_path); + +/* Cancel APIs that all requests to extract thumbnail of a process */ +int thumbnail_request_cancel_all(); + +/** @} */ + +/** + @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /*_MEDIA_THUMBNAIL_H_*/ + diff --git a/libmedia-thumbnail.manifest b/libmedia-thumbnail.manifest new file mode 100644 index 0000000..ca37499 --- /dev/null +++ b/libmedia-thumbnail.manifest @@ -0,0 +1,6 @@ + + + + + + diff --git a/md5/md5.c b/md5/md5.c new file mode 100644 index 0000000..59b47ba --- /dev/null +++ b/md5/md5.c @@ -0,0 +1,253 @@ +/* + * This code implements the MD5 message-digest algorithm. + * The algorithm is due to Ron Rivest. This code was + * written by Colin Plumb in 1993, no copyright is claimed. + * This code is in the public domain; do with it what you wish. + * + * Equivalent code is available from RSA Data Security, Inc. + * This code has been tested against that, and is equivalent, + * except that you don't need to include two pages of legalese + * with every copy. + * + * To compute the message digest of a chunk of bytes, declare an + * MD5Context structure, pass it to MD5Init, call MD5Update as + * needed on buffers full of bytes, and then call MD5Final, which + * will fill a supplied 16-byte array with the digest. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include /* for memcpy() */ +#include "md5.h" + +#if (__BYTE_ORDER == 1234) +#define byteReverse(buf, len) /* Nothing */ +#else +void byteReverse(unsigned char *buf, unsigned longs); + +/* + * Note: this code is harmless on little-endian machines. + */ +void byteReverse(unsigned char *buf, unsigned longs) +{ + uint32_t t; + do { + t = (uint32_t) ((unsigned)buf[3] << 8 | buf[2]) << 16 | + ((unsigned)buf[1] << 8 | buf[0]); + *(uint32_t *) buf = t; + buf += 4; + } while (--longs); +} +#endif + +/* + * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious + * initialization constants. + */ +void MD5Init(MD5_CTX *ctx) +{ + ctx->buf[0] = 0x67452301; + ctx->buf[1] = 0xefcdab89; + ctx->buf[2] = 0x98badcfe; + ctx->buf[3] = 0x10325476; + + ctx->bits[0] = 0; + ctx->bits[1] = 0; +} + +/* + * Update context to reflect the concatenation of another buffer full + * of bytes. + */ +void MD5Update(MD5_CTX *ctx, unsigned char const *buf, unsigned len) +{ + uint32_t t; + + /* Update bitcount */ + + t = ctx->bits[0]; + if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t) { + ctx->bits[1]++; /* Carry from low to high */ + } + + ctx->bits[1] += len >> 29; + + t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ + + /* Handle any leading odd-sized chunks */ + + if (t) { + unsigned char *p = (unsigned char *)ctx->in + t; + + t = 64 - t; + if (len < t) { + memcpy(p, buf, len); + return; + } + memcpy(p, buf, t); + byteReverse(ctx->in, 16); + MD5Transform(ctx->buf, (uint32_t *) ctx->in); + buf += t; + len -= t; + } + /* Process data in 64-byte chunks */ + + while (len >= 64) { + memcpy(ctx->in, buf, 64); + byteReverse(ctx->in, 16); + MD5Transform(ctx->buf, (uint32_t *) ctx->in); + buf += 64; + len -= 64; + } + + /* Handle any remaining bytes of data. */ + + memcpy(ctx->in, buf, len); +} + +/* + * Final wrapup - pad to 64-byte boundary with the bit pattern + * 1 0* (64-bit count of bits processed, MSB-first) + */ +void MD5Final(unsigned char digest[16], MD5_CTX *ctx) +{ + unsigned count; + unsigned char *p; + + /* Compute number of bytes mod 64 */ + count = (ctx->bits[0] >> 3) & 0x3F; + + /* Set the first char of padding to 0x80. This is safe since there is + always at least one byte free */ + p = ctx->in + count; + *p++ = 0x80; + + /* Bytes of padding needed to make 64 bytes */ + count = 64 - 1 - count; + + /* Pad out to 56 mod 64 */ + if (count < 8) { + /* Two lots of padding: Pad the first block to 64 bytes */ + memset(p, 0, count); + byteReverse(ctx->in, 16); + MD5Transform(ctx->buf, (uint32_t *) ctx->in); + + /* Now fill the next block with 56 bytes */ + memset(ctx->in, 0, 56); + } else { + /* Pad block to 56 bytes */ + memset(p, 0, count - 8); + } + byteReverse(ctx->in, 14); + + /* Append length in bits and transform */ + ((uint32_t *) ctx->in)[14] = ctx->bits[0]; + ((uint32_t *) ctx->in)[15] = ctx->bits[1]; + + MD5Transform(ctx->buf, (uint32_t *) ctx->in); + byteReverse((unsigned char *)ctx->buf, 4); + memcpy(digest, ctx->buf, 16); + memset((char *)ctx, 0, sizeof(ctx)); /* In case it's sensitive */ +} + +/* The four core functions - F1 is optimized somewhat */ + +/* #define F1(x, y, z) (x & y | ~x & z) */ +#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) +#define F2(x, y, z) (F1((z), (x), (y))) +#define F3(x, y, z) ((x) ^ (y) ^ (z)) +#define F4(x, y, z) ((y) ^ ((x) | ~(z))) + +/* This is the central step in the MD5 algorithm. */ +#define MD5STEP(f, w, x, y, z, data, s) \ +(w += f(x, y, z) + data, w = w<>(32-s), w += x) + +/* + * The core of the MD5 algorithm, this alters an existing MD5 hash to + * reflect the addition of 16 longwords of new data. MD5Update blocks + * the data and converts bytes into longwords for this routine. + */ +void MD5Transform(uint32_t buf[4], uint32_t const in[16]) +{ + register uint32_t a, b, c, d; + + a = buf[0]; + b = buf[1]; + c = buf[2]; + d = buf[3]; + + MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); + MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); + MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); + MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); + MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); + MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); + MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); + MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); + MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); + MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); + MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); + MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); + MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); + MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); + MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); + MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); + + MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); + MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); + MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); + MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); + MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); + MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); + MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); + MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); + MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); + MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); + MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); + MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); + MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); + MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); + MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); + MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); + + MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); + MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); + MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); + MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); + MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); + MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); + MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); + MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); + MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); + MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); + MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); + MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); + MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); + MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); + MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); + MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); + + MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); + MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); + MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); + MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); + MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); + MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); + MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); + MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); + MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); + MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); + MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); + MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); + MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); + MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); + MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); + MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); + + buf[0] += a; + buf[1] += b; + buf[2] += c; + buf[3] += d; +} diff --git a/md5/md5.h b/md5/md5.h new file mode 100644 index 0000000..dac53fb --- /dev/null +++ b/md5/md5.h @@ -0,0 +1,39 @@ +/* + * This code implements the MD5 message-digest algorithm. + * The algorithm is due to Ron Rivest. This code was + * written by Colin Plumb in 1993, no copyright is claimed. + * This code is in the public domain; do with it what you wish. + * + * Equivalent code is available from RSA Data Security, Inc. + * This code has been tested against that, and is equivalent, + * except that you don't need to include two pages of legalese + * with every copy. + * + * To compute the message digest of a chunk of bytes, declare an + * MD5Context structure, pass it to MD5Init, call MD5Update as + * needed on buffers full of bytes, and then call MD5Final, which + * will fill a supplied 16-byte array with the digest. + */ + + +#ifndef _MD5_H_ +#define _MD5_H_ + +#include +#include + +#define MD5_HASHBYTES 16 + +typedef struct MD5Context { + uint32_t buf[4]; + uint32_t bits[2]; + unsigned char in[64]; +} MD5_CTX; + +extern void MD5Init(MD5_CTX *context); +extern void MD5Update(MD5_CTX *context,unsigned char const *buf,unsigned len); +extern void MD5Final(unsigned char digest[MD5_HASHBYTES], MD5_CTX *context); + +extern void MD5Transform(uint32_t buf[4], uint32_t const in[16]); + +#endif diff --git a/md5/media-thumb-hash.c b/md5/media-thumb-hash.c new file mode 100644 index 0000000..bd8df13 --- /dev/null +++ b/md5/media-thumb-hash.c @@ -0,0 +1,132 @@ +/* GLIB - Library of useful routines for C programming + * + * gconvert.c: Convert between character sets using iconv + * Copyright Red Hat Inc., 2000 + * Authors: Havoc Pennington , Owen Taylor +#include + + +static const char ACCEPTABLE_URI_CHARS[96] = { + /* ! " # $ % & ' ( ) * + , - . / */ + 0x00, 0x3F, 0x20, 0x20, 0x28, 0x00, 0x2C, 0x3F, 0x3F, 0x3F, 0x3F, 0x2A, + 0x28, 0x3F, 0x3F, 0x1C, + /* 0 1 2 3 4 5 6 7 8 9 : ; < = > ? */ + 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x38, 0x20, + 0x20, 0x2C, 0x20, 0x20, + /* @ A B C D E F G H I J K L M N O */ + 0x38, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, + 0x3F, 0x3F, 0x3F, 0x3F, + /* P Q R S T U V W X Y Z [ \ ] ^ _ */ + 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x20, + 0x20, 0x20, 0x20, 0x3F, + /* ` a b c d e f g h i j k l m n o */ + 0x20, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, + 0x3F, 0x3F, 0x3F, 0x3F, + /* p q r s t u v w x y z { | } ~ DEL */ + 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x20, + 0x20, 0x20, 0x3F, 0x20 +}; + +char *_media_thumb_generate_hash_name(const char *file) +{ + int n; + MD5_CTX ctx; + static char md5out[(2 * MD5_HASHBYTES) + 1]; + unsigned char hash[MD5_HASHBYTES]; + static const char hex[] = "0123456789abcdef"; + + char *uri; + char *t; + const unsigned char *c; + int length; + + if (!file) { + return NULL; + } + + length = 3 * strlen(file) + 9; + + memset(md5out, 0, sizeof(md5out)); + +#define _check_uri_char(c) \ +((c) >= 32 && (c) < 128 && (ACCEPTABLE_URI_CHARS[(c) - 32] & 0x08)) + + uri = alloca(length); + if (uri == NULL) { + return NULL; + } + + strncpy(uri, "file://", length); + uri[length - 1] = '\0'; + t = uri + sizeof("file://") - 1; + + for (c = (const unsigned char *)file; *c != '\0'; c++) { + if (!_check_uri_char(*c)) { + *t++ = '%'; + *t++ = hex[*c >> 4]; + *t++ = hex[*c & 15]; + } else { + *t++ = *c; + } + } + *t = '\0'; +#undef _check_uri_char + + MD5Init(&ctx); + MD5Update(&ctx, (unsigned char const *)uri, (unsigned)strlen(uri)); + MD5Final(hash, &ctx); + + for (n = 0; n < MD5_HASHBYTES; n++) { + md5out[2 * n] = hex[hash[n] >> 4]; + md5out[2 * n + 1] = hex[hash[n] & 0x0f]; + } + md5out[2 * n] = '\0'; + + return md5out; +} + +int thumbnail_generate_hash_code(const char *origin_path, char *hash_code, int max_length) +{ + char *hash = NULL; + + if (max_length < ((2 * MD5_HASHBYTES) + 1)) { + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + hash = _media_thumb_generate_hash_name(origin_path); + + if (hash == NULL) { + return MEDIA_THUMB_ERROR_HASHCODE; + } + + strncpy(hash_code, hash, max_length); + hash_code[strlen(hash_code)] ='\0'; + + return MEDIA_THUMB_ERROR_NONE; +} + diff --git a/media-thumbnail-server.manifest b/media-thumbnail-server.manifest new file mode 100644 index 0000000..2ad22fe --- /dev/null +++ b/media-thumbnail-server.manifest @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/media-thumbnail.pc.in b/media-thumbnail.pc.in new file mode 100755 index 0000000..b743f00 --- /dev/null +++ b/media-thumbnail.pc.in @@ -0,0 +1,13 @@ +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=@EXEC_PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: @PROJECT_NAME@ +Description: Samsung Linux platform @PROJECT_NAME@ library +Version: @VERSION@ +Requires: dlog +Libs: -L${libdir} -lmedia-thumbnail -lmedia-hash +Cflags: -I${includedir}/media-thumbnail diff --git a/packaging/libmedia-thumbnail.spec b/packaging/libmedia-thumbnail.spec new file mode 100644 index 0000000..ab20e17 --- /dev/null +++ b/packaging/libmedia-thumbnail.spec @@ -0,0 +1,82 @@ +Name: libmedia-thumbnail +Summary: Media thumbnail service library for multimedia applications. +Version: 0.1.65 +Release: 1 +Group: utils +License: Apache +Source0: %{name}-%{version}.tar.gz +BuildRequires: cmake +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(mm-fileinfo) +BuildRequires: pkgconfig(mmutil-imgp) +BuildRequires: pkgconfig(mmutil-jpeg) +BuildRequires: pkgconfig(drm-client) +BuildRequires: pkgconfig(libexif) +BuildRequires: pkgconfig(heynoti) +BuildRequires: pkgconfig(evas) +BuildRequires: pkgconfig(ecore) +BuildRequires: pkgconfig(aul) +BuildRequires: pkgconfig(libmedia-utils) + + +%description +Description: Media thumbnail service library for multimedia applications. + + +%package devel +License: Apache +Summary: Media thumbnail service library for multimedia applications. (development) +Requires: %{name} = %{version}-%{release} +Group: Development/Libraries + +%description devel +Description: Media thumbnail service library for multimedia applications. (development) + +%package -n media-thumbnail-server +License: Apache +Summary: Thumbnail generator. +Requires: %{name} = %{version}-%{release} +Group: Development/Libraries + +%description -n media-thumbnail-server +Description: Media Thumbnail Server. + + +%prep +%setup -q + + +%build +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + +#License +mkdir -p %{buildroot}/%{_datadir}/license +cp -rf %{_builddir}/%{name}-%{version}/LICENSE %{buildroot}/%{_datadir}/license/%{name} + +%files +%manifest libmedia-thumbnail.manifest +%defattr(-,root,root,-) +%{_libdir}/libmedia-thumbnail.so +%{_libdir}/libmedia-thumbnail.so.* +%{_libdir}/libmedia-hash.so +%{_libdir}/libmedia-hash.so.1 +%{_libdir}/libmedia-hash.so.1.0.0 +#License +%{_datadir}/license/%{name} + +%files devel +%defattr(-,root,root,-) +%{_libdir}/pkgconfig/media-thumbnail.pc +%{_includedir}/media-thumbnail/*.h + +%files -n media-thumbnail-server +%manifest media-thumbnail-server.manifest +%defattr(-,root,root,-) +%{_bindir}/media-thumbnail-server +/usr/local/bin/test-thumb + diff --git a/server/include/thumb-server-internal.h b/server/include/thumb-server-internal.h new file mode 100755 index 0000000..cbf8644 --- /dev/null +++ b/server/include/thumb-server-internal.h @@ -0,0 +1,55 @@ +/* + * media-thumbnail-server + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include "media-thumb-ipc.h" +#include "media-thumb-db.h" + +#ifndef _THUMB_DAEMON_INTERNAL_H_ +#define _THUMB_DAEMON_INTERNAL_H_ + +#define SAFE_FREE(src) { if(src) {free(src); src = NULL;}} + +typedef enum { + MEDIA_SERVER_PID = 1, + OTHERS_PID = 0, + GETPID_FAIL = -1 +} _pid_e; + +typedef enum { + BLOCK_MODE = 0, + TIMEOUT_MODE = 1 +} _server_mode_e; + +#if 0 +int _thumb_daemon_get_sockfd(); +gboolean _thumb_daemon_udp_thread(void *data); +#endif + +gboolean _thumb_daemon_start_jobs(gpointer data); +void _thumb_daemon_finish_jobs(); +gboolean _thumb_server_prepare_socket(int *sock_fd); +gboolean _thumb_server_read_socket(GIOChannel *src, + GIOCondition condition, + gpointer data); + +#endif /*_THUMB_DAEMON_INTERNAL_H_*/ + diff --git a/server/thumb-server-internal.c b/server/thumb-server-internal.c new file mode 100755 index 0000000..3844fcb --- /dev/null +++ b/server/thumb-server-internal.c @@ -0,0 +1,412 @@ +/* + * media-thumbnail-server + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 "thumb-server-internal.h" + +#include +#include +#include +#include +#include + + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "MEDIA_THUMBNAIL_SERVER" + +static __thread char **arr_path; +static __thread int g_idx = 0; +static __thread int g_cur_idx = 0; + +GMainLoop *g_thumb_server_mainloop; // defined in thumb-server.c as extern + +#ifdef _USE_MEDIA_UTIL_ +gboolean _thumb_server_send_msg_to_agent(int msg_type); +#endif + +gboolean _thumb_daemon_start_jobs(gpointer data) +{ + thumb_dbg(""); + /* Initialize ecore-evas to use evas library */ + ecore_evas_init(); + +#ifdef _USE_MEDIA_UTIL_ + _thumb_server_send_msg_to_agent(MS_MSG_THUMB_SERVER_READY); +#endif + return FALSE; +} + +void _thumb_daemon_finish_jobs() +{ + sqlite3 *sqlite_db_handle = _media_thumb_db_get_handle(); + + if (sqlite_db_handle != NULL) { + _media_thumb_db_disconnect(); + thumb_dbg("sqlite3 handle is alive. So disconnect to sqlite3"); + } + + /* Shutdown ecore-evas */ + ecore_evas_shutdown(); + + return; +} + +int _thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg) +{ + int err = -1; + + err = _media_thumb_process(req_msg, res_msg); + if (err < 0) { + if (req_msg->msg_type == THUMB_REQUEST_SAVE_FILE) { + thumb_err("_media_thumb_process is failed: %d", err); + res_msg->status = THUMB_FAIL; + } else { + thumb_warn("_media_thumb_process is failed: %d, So use default thumb", err); + res_msg->status = THUMB_SUCCESS; + } + } else { + res_msg->status = THUMB_SUCCESS; + } + + return err; +} + +int _thumb_daemon_all_extract() +{ + int err = -1; + int count = 0; + char query_string[MAX_PATH_SIZE + 1] = { 0, }; + char path[MAX_PATH_SIZE + 1] = { 0, }; + sqlite3 *sqlite_db_handle = NULL; + sqlite3_stmt *sqlite_stmt = NULL; + + err = _media_thumb_db_connect(); + if (err < 0) { + thumb_err("_media_thumb_db_connect failed: %d", err); + return MEDIA_THUMB_ERROR_DB; + } + + sqlite_db_handle = _media_thumb_db_get_handle(); + if (sqlite_db_handle == NULL) { + thumb_err("sqlite handle is NULL"); + return MEDIA_THUMB_ERROR_DB; + } + + snprintf(query_string, sizeof(query_string), SELECT_PATH_FROM_UNEXTRACTED_THUMB_MEDIA); + thumb_dbg("Query: %s", query_string); + + err = sqlite3_prepare_v2(sqlite_db_handle, query_string, strlen(query_string), &sqlite_stmt, NULL); + if (SQLITE_OK != err) { + thumb_err("prepare error [%s]\n", sqlite3_errmsg(sqlite_db_handle)); + _media_thumb_db_disconnect(); + return MEDIA_THUMB_ERROR_DB; + } + + while(1) { + err = sqlite3_step(sqlite_stmt); + if (err != SQLITE_ROW) { + thumb_dbg("end of row [%s]\n", sqlite3_errmsg(sqlite_db_handle)); + break; + } + + strncpy(path, (const char *)sqlite3_column_text(sqlite_stmt, 0), MAX_PATH_SIZE + 1); + count = sqlite3_column_int(sqlite_stmt, 1); + + thumb_dbg("Path : %s", path); + + if (g_idx == 0) { + arr_path = (char**)malloc(sizeof(char*)); + } else { + arr_path = (char**)realloc(arr_path, (g_idx + 1) * sizeof(char*)); + } + + arr_path[g_idx++] = strdup(path); + } + + sqlite3_finalize(sqlite_stmt); + _media_thumb_db_disconnect(); + + return MEDIA_THUMB_ERROR_NONE; +} + +int _thumb_daemon_process_queue_jobs(gpointer data) +{ + int err = -1; + char *path = NULL; + + if (g_cur_idx < g_idx) { + thumb_dbg("There are %d jobs in the queue", g_idx - g_cur_idx); + thumb_dbg("Current idx : [%d]", g_cur_idx); + path = arr_path[g_cur_idx++]; + + thumbMsg recv_msg, res_msg; + memset(&recv_msg, 0x00, sizeof(thumbMsg)); + memset(&res_msg, 0x00, sizeof(thumbMsg)); + + recv_msg.msg_type = THUMB_REQUEST_DB_INSERT; + recv_msg.thumb_type = MEDIA_THUMB_LARGE; + strncpy(recv_msg.org_path, path, sizeof(recv_msg.org_path)); + recv_msg.org_path[sizeof(recv_msg.org_path) - 1] = '\0'; + + _thumb_daemon_process_job(&recv_msg, &res_msg); + + if (res_msg.status == THUMB_SUCCESS) { + + err = _media_thumb_db_connect(); + if (err < 0) { + thumb_err("_media_thumb_mb_svc_connect failed: %d", err); + return TRUE; + } + + /* Need to update DB once generating thumb is done */ + err = _media_thumb_update_db(recv_msg.org_path, + res_msg.dst_path, + res_msg.origin_width, + res_msg.origin_height); + if (err < 0) { + thumb_err("_media_thumb_update_db failed : %d", err); + } + + _media_thumb_db_disconnect(); + } + + SAFE_FREE(path); + } else { + g_cur_idx = 0; + g_idx = 0; + thumb_warn("Deleting array"); + SAFE_FREE(arr_path); + //_media_thumb_db_disconnect(); + + _thumb_server_send_msg_to_agent(MS_MSG_THUMB_EXTRACT_ALL_DONE); // MS_MSG_THUMB_EXTRACT_ALL_DONE + + return FALSE; + } + + return TRUE; +} + +gboolean _thumb_server_read_socket(GIOChannel *src, + GIOCondition condition, + gpointer data) +{ + struct sockaddr_in client_addr; + unsigned int client_addr_len; +#ifndef _USE_MEDIA_UTIL_ + int client_sock; +#endif + + thumbMsg recv_msg; + thumbMsg res_msg; + + int sock = -1; + int header_size = 0; + + memset((void *)&recv_msg, 0, sizeof(recv_msg)); + memset((void *)&res_msg, 0, sizeof(res_msg)); + + sock = g_io_channel_unix_get_fd(src); + if (sock < 0) { + thumb_err("sock fd is invalid!"); + return TRUE; + } + + header_size = sizeof(thumbMsg) - MAX_PATH_SIZE*2; + +#ifndef _USE_MEDIA_UTIL_ + if ((client_sock = accept(sock, (struct sockaddr*)&client_addr, &client_addr_len)) < 0) { + thumb_err("accept failed : %s", strerror(errno)); + return TRUE; + } + + thumb_dbg("Client[%d] is accepted", client_sock); + + + if (_media_thumb_recv_msg(client_sock, header_size, &recv_msg) < 0) { + thumb_err("_media_thumb_recv_msg failed "); + close(client_sock); + return TRUE; + } +#else + + if (_media_thumb_recv_udp_msg(sock, header_size, &recv_msg, &client_addr, &client_addr_len) < 0) { + thumb_err("_media_thumb_recv_udp_msg failed"); + return FALSE; + } +#endif + + thumb_dbg("Received [%d] %s(%d) from PID(%d) \n", recv_msg.msg_type, recv_msg.org_path, strlen(recv_msg.org_path), recv_msg.pid); + + if (recv_msg.msg_type == THUMB_REQUEST_ALL_MEDIA) { + thumb_dbg("All thumbnails are being extracted now"); + _thumb_daemon_all_extract(); + g_idle_add(_thumb_daemon_process_queue_jobs, NULL); + } else if(recv_msg.msg_type == THUMB_REQUEST_KILL_SERVER) { + thumb_dbg("received KILL msg from thumbnail agent."); + } else { + long start = thumb_get_debug_time(); + + _thumb_daemon_process_job(&recv_msg, &res_msg); + + long end = thumb_get_debug_time(); + thumb_dbg("Time : %f (%s)", ((double)(end - start) / (double)CLOCKS_PER_SEC), recv_msg.org_path); + } + + res_msg.msg_type = recv_msg.msg_type; + strncpy(res_msg.org_path, recv_msg.org_path, recv_msg.origin_path_size); + res_msg.origin_path_size = recv_msg.origin_path_size; + res_msg.dest_path_size = strlen(res_msg.dst_path) + 1; + + int buf_size = 0; + unsigned char *buf = NULL; + _media_thumb_set_buffer(&res_msg, &buf, &buf_size); + + //thumb_dbg("buffer size : %d", buf_size); + +#ifndef _USE_MEDIA_UTIL_ + if (send(client_sock, buf, buf_size, 0) != buf_size) { + thumb_err("sendto failed : %s", strerror(errno)); + } else { + thumb_dbg("Sent %s(%d) \n", res_msg.dst_path, strlen(res_msg.dst_path)); + } + + close(client_sock); +#else + if (sendto(sock, buf, buf_size, 0, (struct sockaddr *)&client_addr, sizeof(client_addr)) != buf_size) { + thumb_err("sendto failed: %s\n", strerror(errno)); + SAFE_FREE(buf); + return FALSE; + } +#endif + + thumb_dbg("Sent %s(%d)", res_msg.dst_path, strlen(res_msg.dst_path)); + + SAFE_FREE(buf); + + if(recv_msg.msg_type == THUMB_REQUEST_KILL_SERVER) { + thumb_dbg("Shutting down..."); + g_main_loop_quit(g_thumb_server_mainloop); + } + + return TRUE; +} + +#ifdef _USE_MEDIA_UTIL_ +gboolean _thumb_server_send_msg_to_agent(int msg_type) +{ + int sock; + const char *serv_ip = "127.0.0.1"; + struct sockaddr_in serv_addr; + ms_thumb_server_msg send_msg; +#if 0 + /* Creaete a UDP socket */ + if (_media_thumb_create_udp_socket(&sock) < 0) { + thumb_err("_media_thumb_create_udp_socket failed"); + return FALSE; + } +#endif + if (ms_ipc_create_client_socket(MS_PROTOCOL_UDP, MS_TIMEOUT_SEC_10, &sock) < 0) { + thumb_err("ms_ipc_create_server_socket failed"); + return FALSE; + } + + memset(&serv_addr, 0, sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + serv_addr.sin_addr.s_addr = inet_addr(serv_ip); + serv_addr.sin_port = htons(MS_THUMB_COMM_PORT); + + send_msg.msg_type = msg_type; + + if (sendto(sock, &send_msg, sizeof(ms_thumb_server_msg), 0, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) != sizeof(ms_thumb_server_msg)) { + thumb_err("sendto failed: %s\n", strerror(errno)); + return FALSE; + } + + thumb_dbg("Sending msg to thumbnail agent[%d] is successful", send_msg.msg_type); + + return TRUE; +} +#endif + +gboolean _thumb_server_prepare_socket(int *sock_fd) +{ + int sock; + unsigned short serv_port; + + thumbMsg recv_msg; + thumbMsg res_msg; + + memset((void *)&recv_msg, 0, sizeof(recv_msg)); + memset((void *)&res_msg, 0, sizeof(res_msg)); +#ifdef _USE_MEDIA_UTIL_ + serv_port = MS_THUMB_DAEMON_PORT; + + if (ms_ipc_create_server_socket(MS_PROTOCOL_UDP, serv_port, &sock) < 0) { + thumb_err("ms_ipc_create_server_socket failed"); + return FALSE; + } +#if 0 + /* Creaete a UDP socket */ + if (_media_thumb_create_udp_socket(&sock) < 0) { + thumb_err("_media_thumb_create_udp_socket failed"); + return FALSE; + } +#endif +#else + char thumb_path[MAX_PATH_SIZE + 1]; + struct sockaddr_in serv_addr; + serv_port = THUMB_DAEMON_PORT; + + /* Creaete a TCP socket */ + if (_media_thumb_create_socket(SERVER_SOCKET, &sock) < 0) { + thumb_err("_media_thumb_create_socket failed"); + return FALSE; + } + + memset(thumb_path, 0, sizeof(thumb_path)); + memset(&serv_addr, 0, sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); + serv_addr.sin_port = htons(serv_port); + + /* Bind to the local address */ + if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { + thumb_err("bind failed : %s", strerror(errno)); + return FALSE; + } + + thumb_dbg("bind success"); + + /* Listening */ + if (listen(sock, SOMAXCONN) < 0) { + thumb_err("listen failed : %s", strerror(errno)); + } + + thumb_dbg("Listening..."); +#endif + + *sock_fd = sock; + + return TRUE; +} + diff --git a/server/thumb-server.c b/server/thumb-server.c new file mode 100755 index 0000000..3b79684 --- /dev/null +++ b/server/thumb-server.c @@ -0,0 +1,122 @@ +/* + * media-thumbnail-server + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 "media-thumbnail.h" +#include "media-thumb-debug.h" +#include "media-thumb-ipc.h" +#include "media-thumb-util.h" +#include "thumb-server-internal.h" + +#include +#include +//#include +//#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "MEDIA_THUMBNAIL_SERVER" +#define POWEROFF_NOTI_NAME "power_off_start" /*poeroff noti from system-server*/ + + +extern GMainLoop *g_thumb_server_mainloop; + +static void _media_thumb_signal_handler(void *user_data) +{ + thumb_dbg("Singal Hander for HEYNOTI \"power_off_start\""); + + if (g_thumb_server_mainloop) + g_main_loop_quit(g_thumb_server_mainloop); + else + exit(1); + + return; +} + + +int main() +{ + int sockfd = -1; + + GSource *source = NULL; + GIOChannel *channel = NULL; + GMainContext *context = NULL; + + /*heynoti for power off*/ + int err = 0; + int heynoti_id = heynoti_init(); + + if (heynoti_id < 0) { + thumb_err("heynoti_init failed"); + } else { + err = heynoti_subscribe(heynoti_id, POWEROFF_NOTI_NAME, _media_thumb_signal_handler, NULL); + if (err < 0) { + thumb_err("heynoti_attach_handler failed: %d", err); + } else { + err = heynoti_attach_handler(heynoti_id); + if (err < 0) + thumb_err("heynoti_attach_handler failed: %d", err); + } + } + + /* Create and bind new UDP socket */ + if (!_thumb_server_prepare_socket(&sockfd)) { + thumb_err("Failed to create socket\n"); + return -1; + } + + g_thumb_server_mainloop = g_main_loop_new(context, FALSE); + context = g_main_loop_get_context(g_thumb_server_mainloop); + + /* Create new channel to watch udp socket */ + channel = g_io_channel_unix_new(sockfd); + source = g_io_create_watch(channel, G_IO_IN); + + /* Set callback to be called when socket is readable */ + g_source_set_callback(source, (GSourceFunc)_thumb_server_read_socket, NULL, NULL); + g_source_attach(source, context); + + GSource *source_evas_init = NULL; + source_evas_init = g_idle_source_new (); + g_source_set_callback (source_evas_init, _thumb_daemon_start_jobs, NULL, NULL); + g_source_attach (source_evas_init, context); + +/* Would be used when glib 2.32 is installed + GSource *sig_handler_src = NULL; + sig_handler_src = g_unix_signal_source_new (SIGTERM); + g_source_set_callback(sig_handler_src, (GSourceFunc)_media_thumb_signal_handler, NULL, NULL); + g_source_attach(sig_handler_src, context); +*/ + thumb_dbg("************************************"); + thumb_dbg("*** Thumbnail server is running ***"); + thumb_dbg("************************************"); + + g_main_loop_run(g_thumb_server_mainloop); + + thumb_dbg("Thumbnail server is shutting down..."); + g_io_channel_shutdown(channel, FALSE, NULL); + g_io_channel_unref(channel); + _thumb_daemon_finish_jobs(); + g_main_loop_unref(g_thumb_server_mainloop); + + return 0; +} diff --git a/src/codec/IfegDecodeAGIF.c b/src/codec/IfegDecodeAGIF.c new file mode 100644 index 0000000..dad124b --- /dev/null +++ b/src/codec/IfegDecodeAGIF.c @@ -0,0 +1,4169 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 "media-thumb-debug.h" +#include "img-codec-common.h" +#include "IfegDecodeAGIF.h" + + + +#define MAX_CODES 4096 + +int __FastImgGetNextFrameAGIF_NoBuffer (AGifFrameInfo *pFrameData, BOOL bCenterAlign); +int __FastImgGetNextFrameAGIF_UseBuffer (AGifFrameInfo *pFrameData, BOOL bCenterAlign); + +int image_left_pos_N = 0; /* left position of image in Logical screeen */ +int image_top_pos_N = 0; + +AGifFrameInfo *FastImgCreateAGIFFrameData(unsigned int width, unsigned int height, unsigned char *pEncodedData, unsigned int file_size, unsigned int ui_backcolor, BOOL bLoop) +{ + int header_temp; + int backcolor_index; + unsigned int image_backcolor; + unsigned int backcolor_parsing; + unsigned int transcolor_565 = 0; + int transparent = 0; + int transIndex = 0; + int local_color_table_flag; + + int inputPos = 0; + int inputPos_temp = 0; + + AGifFrameInfo *pFrameData; + if (0 == (pFrameData = IfegMemAlloc(sizeof(AGifFrameInfo)))) { + return 0; + } + + IfegMemset(pFrameData, 0, sizeof(AGifFrameInfo)); + + inputPos += 13; + + pFrameData->logi_wdt = pEncodedData[6] | (pEncodedData[7]<<8); + pFrameData->logi_hgt = pEncodedData[8] | (pEncodedData[9]<<8); +#ifdef INTERNAL_IMGCODEC + thumb_dbg("logi_wdt:%d, logi_hgt:%d\n", pFrameData->logi_wdt, pFrameData->logi_hgt); +#else + thumb_dbg("logi_wdt:%d, logi_hgt:%d\n", pFrameData->logi_wdt, pFrameData->logi_hgt); + if ((pFrameData->logi_wdt > MAXWIDTH) || (pFrameData->logi_hgt > MAXHEIGHT)) { + if (pFrameData) { + IfegMemFree(pFrameData); + pFrameData = 0; + } + return 0; + } +#endif + + /* save nReapeatCount assigned by content */ + + if ((pEncodedData[10]&0x80) == 0x80) { + header_temp = 3 * (1<<((pEncodedData[10] & 0x07) + 1)); + } else { + header_temp = 0; + } + + if (file_size > 30+header_temp && pEncodedData[14+header_temp] == 0xFF) { + pFrameData->nLoopCount = pEncodedData[30+header_temp]<<8 | pEncodedData[29+header_temp]; + } else if (file_size > 30+8+header_temp && pEncodedData[14+8+header_temp] == 0xFF) { + pFrameData->nLoopCount = pEncodedData[30+8+header_temp]<<8 | pEncodedData[29+8+header_temp]; + } else { + pFrameData->nLoopCount = -1; + } + + pFrameData->nRepeatCount = 0; + + thumb_dbg("10st data : 0x%x , global color table num : %d\n", pEncodedData[10], header_temp); + thumb_dbg("13: 0x%x ,14: 0x%x, 15: 0x%x, nRepeatCount : %d, nLoopCount : %d\n", pEncodedData[13+header_temp], pEncodedData[14+header_temp], pEncodedData[15+header_temp], pFrameData->nRepeatCount, pFrameData->nLoopCount); + + backcolor_index = pEncodedData[11]; + + if (pEncodedData[14+header_temp] == 0xF9) { + inputPos_temp = 14+header_temp+17; + transparent = pEncodedData[16+header_temp] & 0x01; + transIndex = pEncodedData[19+header_temp]; + local_color_table_flag = pEncodedData[30+header_temp] & 0x80; + + if (local_color_table_flag == 0x80) { + transcolor_565 = ((pEncodedData[inputPos_temp+transIndex*3]>>3)<<11)|((pEncodedData[inputPos_temp+transIndex*3+1]>>2)<<5)|(pEncodedData[inputPos_temp+transIndex*3+2]>>3); + } else { + transcolor_565 = ((pEncodedData[13+transIndex*3]>>3)<<11)|((pEncodedData[13+transIndex*3+1]>>2)<<5)|(pEncodedData[13+transIndex*3+2]>>3); + } + + backcolor_parsing = (unsigned short)((pEncodedData[inputPos+backcolor_index*3] >> 3)<<11) | ((pEncodedData[inputPos+backcolor_index*3+1] >> 2)<<5) | (pEncodedData[inputPos+backcolor_index*3+2] >> 3); + } else if (pEncodedData[14+19+header_temp] == 0xF9) { + inputPos_temp = 14+19+header_temp+17; + transparent = pEncodedData[35+header_temp] & 0x01; + transIndex = pEncodedData[38+header_temp]; + local_color_table_flag = pEncodedData[49+header_temp] & 0x80; + + if (local_color_table_flag == 0x80) { + transcolor_565 = ((pEncodedData[inputPos_temp+transIndex*3]>>3)<<11)|((pEncodedData[inputPos_temp+transIndex*3+1]>>2)<<5)|(pEncodedData[inputPos_temp+transIndex*3+2]>>3); + } else { + transcolor_565 = ((pEncodedData[13+transIndex*3]>>3)<<11)|((pEncodedData[13+transIndex*3+1]>>2)<<5)|(pEncodedData[13+transIndex*3+2]>>3); + } + + backcolor_parsing = (unsigned short)((pEncodedData[inputPos+backcolor_index*3] >> 3)<<11) | ((pEncodedData[inputPos+backcolor_index*3+1] >> 2)<<5) | (pEncodedData[inputPos+backcolor_index*3+2] >> 3); + } else if ((pEncodedData[10]&0x80) != 0x80) { /* global color table */ + backcolor_parsing = ui_backcolor; + } else { + backcolor_parsing = (unsigned short)((pEncodedData[inputPos+backcolor_index*3] >> 3)<<11) | ((pEncodedData[inputPos+backcolor_index*3+1] >> 2)<<5) | (pEncodedData[inputPos+backcolor_index*3+2] >> 3); + } + + /* graphic extension block */ + if (pEncodedData[14+header_temp] == 0xF9 || pEncodedData[14+19+header_temp] == 0xF9) { + + if (transparent == 1 && backcolor_index == transIndex) { + image_backcolor = ui_backcolor; + } else if (transparent == 1 && backcolor_index != transIndex) { + image_backcolor = backcolor_parsing; + } else { + image_backcolor = backcolor_parsing; + } + } else { + image_backcolor = backcolor_parsing; + } + +#if MODE == 0 + if (0 == (pFrameData->pPrevImg = IfegMemAlloc(sizeof(unsigned char)*width*height*2))) { + if (pFrameData) { + IfegMemFree(pFrameData); + pFrameData = 0; + } + return 0; + } + pFrameData->useBuffer = 0; +#endif + +#if MODE == 1 + if (0 == (pFrameData->pPrevImg = IfegMemAlloc(sizeof(unsigned int)*pFrameData->logi_wdt*pFrameData->logi_hgt))) { + if (pFrameData) { + IfegMemFree(pFrameData); + pFrameData = 0; + } + return 0; + } + pFrameData->useBuffer = 1; +#endif + + +#if MODE == 2 + if (((pFrameData->logi_wdt <= width) && (pFrameData->logi_hgt <= height))) { + if (0 == (pFrameData->pPrevImg = IfegMemAlloc(sizeof(unsigned char)*width*height*2))) { + if (pFrameData) { + IfegMemFree(pFrameData); + pFrameData = 0; + } + return 0; + } + pFrameData->useBuffer = 0; + } else { + if (0 == (pFrameData->pPrevImg = IfegMemAlloc(sizeof(unsigned int)*pFrameData->logi_wdt*pFrameData->logi_hgt))) { + if (pFrameData) { + IfegMemFree(pFrameData); + pFrameData = 0; + } + return 0; + } + pFrameData->useBuffer = 1; + } +#endif + + if (0 == (pFrameData->pOutBits = IfegMemAlloc(sizeof(unsigned char)*width*height*2))) { + if (pFrameData->pPrevImg) { + IfegMemFree(pFrameData->pPrevImg); + pFrameData->pPrevImg = 0; + } + if (pFrameData) { + IfegMemFree(pFrameData); + pFrameData = 0; + } + return 0; + } + + pFrameData->inputSize = file_size; + pFrameData->pEncodedData = pEncodedData; + + if (0 == (pFrameData->pGlobal_table = IfegMemAlloc(sizeof(unsigned int)*256))) { + if (pFrameData->pPrevImg) { + IfegMemFree(pFrameData->pPrevImg); + pFrameData->pPrevImg = 0; + } + + if (pFrameData->pOutBits) { + IfegMemFree(pFrameData->pOutBits); + pFrameData->pOutBits = 0; + } + + if (pFrameData) { + IfegMemFree(pFrameData); + pFrameData = 0; + } + return 0; + } + + if (0 == (pFrameData->pPrefix = IfegMemAlloc(sizeof(unsigned short)*4097))) { + if (pFrameData->pPrevImg) { + IfegMemFree(pFrameData->pPrevImg); + pFrameData->pPrevImg = 0; + } + if (pFrameData->pOutBits) { + IfegMemFree(pFrameData->pOutBits); + pFrameData->pOutBits = 0; + } + if (pFrameData->pGlobal_table) { + IfegMemFree(pFrameData->pGlobal_table); + pFrameData->pGlobal_table = 0; + } + if (pFrameData) { + IfegMemFree(pFrameData); + pFrameData = 0; + } + return 0; + } + + if (0 == (pFrameData->pDstack = IfegMemAlloc(sizeof(unsigned char)*4097))) { + if (pFrameData->pPrevImg) { + IfegMemFree(pFrameData->pPrevImg); + pFrameData->pPrevImg = 0; + } + if (pFrameData->pOutBits) { + IfegMemFree(pFrameData->pOutBits); + pFrameData->pOutBits = 0; + } + if (pFrameData->pGlobal_table) { + IfegMemFree(pFrameData->pGlobal_table); + pFrameData->pGlobal_table = 0; + } + if (pFrameData->pPrefix) { + IfegMemFree(pFrameData->pPrefix); + pFrameData->pPrefix = 0; + } + if (pFrameData) { + IfegMemFree(pFrameData); + pFrameData = 0; + } + return 0; + } + + if (0 == (pFrameData->pSuffix = IfegMemAlloc(sizeof(unsigned char)*4097))) { + if (pFrameData->pPrevImg) { + IfegMemFree(pFrameData->pPrevImg); + pFrameData->pPrevImg = 0; + } + if (pFrameData->pOutBits) { + IfegMemFree(pFrameData->pOutBits); + pFrameData->pOutBits = 0; + } + if (pFrameData->pGlobal_table) { + IfegMemFree(pFrameData->pGlobal_table); + pFrameData->pGlobal_table = 0; + } + if (pFrameData->pPrefix) { + IfegMemFree(pFrameData->pPrefix); + pFrameData->pPrefix = 0; + } + if (pFrameData->pDstack) { + IfegMemFree(pFrameData->pDstack); + pFrameData->pDstack = 0; + } + if (pFrameData) { + IfegMemFree(pFrameData); + pFrameData = 0; + } + return 0; + } + + pFrameData->width = width; + pFrameData->height = height; + pFrameData->imgCount = -1; + pFrameData->offset = 0; + pFrameData->backcolor = image_backcolor; + pFrameData->ui_backcolor = ui_backcolor; + pFrameData->delay = 10; + pFrameData->bLoop = bLoop; + return pFrameData; +} + +void FastImgDestroyAGIFFrameData(AGifFrameInfo *pFrameData) +{ + if (pFrameData == NULL) { + return; + } + + if (pFrameData->pPrevImg) { + IfegMemFree(pFrameData->pPrevImg); + pFrameData->pPrevImg = 0; + } + + if (pFrameData->pEncodedData) { + IfegMemFree(pFrameData->pEncodedData); + pFrameData->pEncodedData = 0; + } + if (pFrameData->pOutBits) { + IfegMemFree(pFrameData->pOutBits); + pFrameData->pOutBits = 0; + } + + if (pFrameData->pGlobal_table) { + IfegMemFree(pFrameData->pGlobal_table); + pFrameData->pGlobal_table = 0; + } + + if (pFrameData->pPrefix) { + IfegMemFree(pFrameData->pPrefix); + pFrameData->pPrefix = 0; + } + + if (pFrameData->pDstack) { + IfegMemFree(pFrameData->pDstack); + pFrameData->pDstack = 0; + } + + if (pFrameData->pSuffix) { + IfegMemFree(pFrameData->pSuffix); + pFrameData->pSuffix = 0; + } + + if (pFrameData) { + IfegMemFree(pFrameData); + pFrameData = 0; + } +} + +/* macro */ +#define __get_next_code_first_nbits_left_0(pInputStream) \ +{\ + {\ + if (navail_bytes == 0) {\ + navail_bytes = (pInputStream)[inputPos++];\ + if ((inputPos + navail_bytes) > filesize) {\ + if (decoderline) {\ + IfegMemFree(decoderline);\ + decoderline = 0;\ + } \ + if (pDecBuf) {\ + IfegMemFree(pDecBuf);\ + pDecBuf = 0;\ + } \ + return -1;\ + } \ + } \ + b1 = (pInputStream)[inputPos++];\ + ret = b1;\ + nbits_left = 8;\ + --navail_bytes;\ + } \ +} + +#define __get_next_code_first_nbits_left_not_0(pInputStream) \ +{\ + {\ + ret = b1 >> (8 - nbits_left); \ + } \ +} + +#define __get_next_code_first_while(pInputStream) \ +{\ + while (curr_size > nbits_left) {\ + if (navail_bytes == 0) {\ + navail_bytes = (pInputStream)[inputPos++];\ + if ((inputPos + navail_bytes) > filesize) {\ + if (decoderline) {\ + IfegMemFree(decoderline);\ + decoderline = 0;\ + } \ + if (pDecBuf) {\ + IfegMemFree(pDecBuf);\ + pDecBuf = 0;\ + } \ + return -1;\ + } \ + } \ + b1 = (pInputStream)[inputPos++];\ + ret |= b1 << nbits_left;\ + nbits_left += 8;\ + --navail_bytes;\ + } \ + nbits_left -= curr_size;\ + ret &= (1<> (8 - nbits_left);\ + } \ +} + +#define __get_next_code_second_while(pInputStream) \ +{\ + while (curr_size > nbits_left) {\ + b1 = (pInputStream)[inputPos++];\ + ret |= b1 << nbits_left;\ + nbits_left += 8;\ + --navail_bytes;\ + } \ + nbits_left -= curr_size;\ + ret &= (1 << curr_size)-1;\ + c = ret;\ +} + +int FastImgGetNextFrameAGIF(AGifFrameInfo *pFrameData, BOOL bCenterAlign) +{ + if (pFrameData->useBuffer) { + return __FastImgGetNextFrameAGIF_UseBuffer(pFrameData, bCenterAlign); + } else { + return __FastImgGetNextFrameAGIF_NoBuffer(pFrameData, bCenterAlign); + } +} + +int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAlign) +{ + unsigned int *pImage32, *pImage32_2; + unsigned short *pImage16; + unsigned char *sp; + unsigned char *bufptr; + unsigned int code, fc, oc, bufcnt; + unsigned char buffer[16]; + unsigned char val1; + unsigned char *buf; + unsigned int *pDacbox; + unsigned char *decoderline = 0; + unsigned int size; + + unsigned int c = 0; + unsigned int clear; + unsigned int ending; + unsigned int newcodes; + unsigned int top_slot; + unsigned int slot; + + int numcolors; + int i, j, k; + int rowcount; + int orgwdt_1, orgwdt, orghgt; + int decwdt, dechgt; + int len; + int inter_step, interLaced; + int transparent = 0; + int startloc = 0; + int transIndex = 0; + int spCount = 0; + int logi_wdt; /* logical screen width */ + int logi_hgt; + int logi_image_size; + int image_backcolor; + int ui_backcolor; + int backcolor; + int image_left_pos; /* left position of image in Logical screeen */ + int image_top_pos; + int disposal_method = 0; + int margin_wdt1_2, margin_hgt1_2; + int inputPos; + + unsigned int dacbox[256]; + + /* Variable for Resize */ + unsigned int a_x, a_y; + unsigned int b_x, b_y; + unsigned int c_x, c_y; + unsigned int d_x, d_y; + int out_x = 0, out_y = 0; + int d1, d2; + int flag = 0; + unsigned int end; + + int count = 0; + + unsigned char *pDecBuf = 0; + + int expected_width = pFrameData->width; + int expected_height = pFrameData->height; + int resized_width; + int resized_height; + + /* macro */ + register unsigned int curr_size; + register int navail_bytes = 0; + register unsigned int nbits_left = 0; + register unsigned int b1 = 0; + register unsigned int ret; + + /* parameter */ + int filesize = pFrameData->inputSize; + unsigned int *global_dacbox = pFrameData->pGlobal_table; + register unsigned char *pInputStream = pFrameData->pEncodedData; + void *pOutBits = pFrameData->pOutBits; + unsigned short *prefix = pFrameData->pPrefix; + unsigned char *dstack = pFrameData->pDstack; + unsigned char *suffix = pFrameData->pSuffix; + + inputPos = pFrameData->offset; + + IfegMemset(prefix, 0, sizeof(unsigned short)*(MAX_CODES+1)); + IfegMemset(dstack, 0, sizeof(unsigned char)*(MAX_CODES+1)); + IfegMemset(suffix, 0, sizeof(unsigned char)*(MAX_CODES+1)); + + image_backcolor = pFrameData->backcolor; + ui_backcolor = pFrameData->ui_backcolor; + + backcolor = image_backcolor; + + if (pFrameData->imgCount == -1) { + /* Input stream index set to 0 */ + inputPos = 0; + inter_step = 1; + interLaced = 0; + transparent = 0; + + /* read a GIF HEADER */ + IfegMemcpy(buffer, pInputStream, 13); + inputPos += 13; + + /* wheather GIF file or not */ + if (buffer[0] != 'G' || buffer[1] != 'I' || buffer[2] != 'F' || + buffer[3] < '0' || buffer[3] > '9' || + buffer[4] < '0' || buffer[4] > '9' || + buffer[5] < 'A' || buffer[5] > 'z') { + if (decoderline != 0) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf != 0) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return -1; + } + + /* Regard the width/height of image block as the size of thumbnails. */ + pFrameData->logi_wdt = logi_wdt = expected_width; + pFrameData->logi_hgt = logi_hgt = expected_height; + logi_image_size = logi_wdt * logi_hgt; + + /* ouput resized image size */ + if (logi_wdt <= expected_width && logi_hgt <= expected_height) { + resized_width = logi_wdt; + resized_height = logi_hgt; + pFrameData->flag = flag = 1; + } else { + if ((logi_wdt/(float)expected_width) >= (logi_hgt/(float)expected_height)) { + resized_height = logi_hgt * expected_width / logi_wdt; + resized_width = expected_width; + } else { + resized_width = logi_wdt * expected_height / logi_hgt; + resized_height = expected_height; + } + } + if (!resized_width || !resized_height) { + if (pDecBuf != 0) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return 0; + } + + /* ouput resized image size */ + pFrameData->resizedwidth = resized_width; + pFrameData->resizedheight = resized_height; + + /* Color Resolution */ + IfegMemset(global_dacbox, 0, 1024); + numcolors = (buffer[10] & 0x7) + 1; + if ((buffer[10] & 0x80) == 0) { /* Global color table */ + global_dacbox[0] = 0x000000; + global_dacbox[1] = 0x3f3f3f; + numcolors = 2; + } else { /* Global color table */ + numcolors = 1 << numcolors; + + /* Make color table */ + for (i = 0 ; i < numcolors; i++) { + global_dacbox[i] = ((pInputStream[inputPos++] >> 2)<<16); + global_dacbox[i] |= ((pInputStream[inputPos++] >> 2)<<8); + global_dacbox[i] |= (pInputStream[inputPos++] >> 2); + } + } + + /* Background Color */ + pImage16 = (unsigned short *)pFrameData->pPrevImg; + for (i = 0; i < expected_width * expected_height; i++) { + *pImage16++ = ui_backcolor; + } + + if (numcolors > 16) { + numcolors = 256; + } + if (numcolors > 2 && numcolors < 16) { + numcolors = 16; + } + + pFrameData->global_numcol = numcolors; + pFrameData->imgCount++; + pFrameData->firstpos = inputPos; + } else { + + logi_wdt = pFrameData->logi_wdt; + logi_hgt = pFrameData->logi_hgt; + resized_width = pFrameData->resizedwidth; + resized_height = pFrameData->resizedheight; + + flag = pFrameData->flag ; + + numcolors = pFrameData->global_numcol; + } + + + while (1) { + if (inputPos > filesize) { + if (decoderline) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + pFrameData->imgCount = 0; + pFrameData->offset = pFrameData->firstpos; + + if (pFrameData->bLoop) { + /* Background Color */ + pImage16 = (unsigned short *)pFrameData->pPrevImg; + for (i = 0; i < expected_width * expected_height; i++) { + *pImage16++ = ui_backcolor; + } + return 1; + } else { + return 0; + } + } + + switch (pInputStream[inputPos++]) { + case 0x3b: /* End of the GIF dataset */ + if (decoderline) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + if (pFrameData->imgCount == 0) { + return -1; + } + pFrameData->imgCount = 0; + pFrameData->offset = pFrameData->firstpos; + +#ifdef INTERNAL_IMGCODEC + pFrameData->nRepeatCount++; + thumb_dbg("(no_buffer) bLoop : %d, nRepeatCount : %d, nLoopCount : %d" , pFrameData->bLoop, pFrameData->nRepeatCount , pFrameData->nLoopCount); + + if (pFrameData->nLoopCount == -1) { + break; + } else if (pFrameData->bLoop || (pFrameData->nRepeatCount <= pFrameData->nLoopCount) || (pFrameData->nLoopCount == 0)) { + /* Background Color */ + pImage16 = (unsigned short *)pFrameData->pPrevImg; + + for (i = 0; i < expected_width * expected_height; i++) { + *pImage16++ = ui_backcolor; + } + + inputPos = pFrameData->offset; + continue; + } else { + /* if there is last frame and bLoop is FALSE, return 2. */ + return 2; + } +#else + if (pFrameData->bLoop) { + /* Background Color */ + pImage16 = (unsigned short *)pFrameData->pPrevImg; + for (i = 0; i < expected_width * expected_height; i++) { + *pImage16++ = backcolor; + } + return 1; + } else { + return 0; + } +#endif + break; + case 0x21: /* Extension Block */ + switch (pInputStream[inputPos++]) { + case 0xf9: /* Graphic control extension block */ + if (4 != pInputStream[inputPos++]) { /* data length : fixed 4 bytes */ + if (decoderline != 0) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf != 0) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return -1; + } + + disposal_method = ((pInputStream[inputPos] & 0x1c) >> 2); + transparent = pInputStream[inputPos++] & 0x01; /* does it use? 1:on 0:off */ + pFrameData->delay = (pInputStream[inputPos] | (pInputStream[inputPos+1] << 8))*10; + inputPos += 2; /* Delay time (skip) */ + transIndex = pInputStream[inputPos++]; + inputPos++; /* block end */ + break; + + case 0x01: /* Plain Text block */ + while ((i = pInputStream[inputPos++]) > 0) {/* get the data length */ + inputPos += i; + if (inputPos > filesize) { + if (decoderline) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return -1; + } + } + break; + + case 0xfe: /* Comment Extension block */ + while ((i = pInputStream[inputPos++]) > 0) { /* get the data length */ + inputPos += i; + if (inputPos > filesize) { + if (decoderline) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return -1; + } + } + break; + + case 0xff: /* Appliation Extension block */ + while ((i = pInputStream[inputPos++]) > 0) { /* get the data length */ + inputPos += i; + if (inputPos > filesize) { + if (decoderline) { + IfegMemFree(decoderline); + decoderline = 0; + } + + if (pDecBuf) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return -1; + } + } + break; + + default: + break; + } + break; + + case 0x2c: /* Start of an image object. Read the image description. */ + + /* initialize */ + IfegMemcpy(pOutBits, pFrameData->pPrevImg, expected_width * expected_height * 2); + pDacbox = global_dacbox; + + IfegMemcpy(buffer, pInputStream+inputPos, 9); + inputPos += 9; + + image_left_pos = (buffer[0] | (buffer[1]<<8)); + image_top_pos = (buffer[2] | (buffer[3]<<8)); + orgwdt_1 = orgwdt = (buffer[4] | (buffer[5] << 8)); + orghgt = (buffer[6] | (buffer[7] << 8)); + +#ifdef INTERNAL_IMGCODEC +#else + if ((orgwdt > MAXWIDTH) || (orghgt > MAXHEIGHT)) { + if (decoderline != 0) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf != 0) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return -1; + } +#endif + + /* Interlaced check */ + interLaced = buffer[8] & 0x40; + if (interLaced) { + startloc = -8; + } + + inter_step = 1; + + if (decoderline) { + IfegMemFree(decoderline); + } + decoderline = (unsigned char *)IfegMemAlloc(orgwdt); + if (!decoderline) { + if (decoderline != 0) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf != 0) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return 0; + } + IfegMemset(decoderline, 0, orgwdt); + + decwdt = ((orgwdt * resized_width+logi_wdt-1) / logi_wdt); + dechgt = ((orghgt * resized_height+logi_hgt-1) / logi_hgt); + + if (!decwdt || !dechgt) { + if (decoderline != 0) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf != 0) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return 0; + } + + if (pDecBuf) { + IfegMemFree(pDecBuf); + } + pDecBuf = (unsigned char *)IfegMemAlloc(decwdt * dechgt * 4); + if (!pDecBuf) { + if (decoderline != 0) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf != 0) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return 0; + } + IfegMemset(pDecBuf, 0, decwdt * dechgt * 4); + + /* assign out_888_image plane */ + pImage32 = (unsigned int *)(pDecBuf); + + /* Initialize */ + a_x = orgwdt>>2, a_y = orghgt>>2; + b_x = ((orgwdt*3)>>2), b_y = orghgt>>2; + c_x = orgwdt>>2, c_y = ((orghgt*3)>>2); + d_x = ((orgwdt*3)>>2), d_y = ((orghgt*3)>>2); + + end = dechgt * orghgt; + out_x = 0, out_y = -dechgt; + + /* Color Resolution */ + if ((buffer[8] & 0x80) == 0) { /* Logical color table */ + /* use global table */ + } else { /* Logical color table */ + IfegMemset(dacbox, 0, 1024); + + numcolors = (buffer[8] & 0x7) + 1; + numcolors = 1 << numcolors; + + count = 0; + + /* Make color table */ + for (i = 0 ; i < numcolors; i++) { + dacbox[i] = ((pInputStream[inputPos++] >> 2)<<16); + dacbox[i] |= ((pInputStream[inputPos++] >> 2)<<8); + dacbox[i] |= (pInputStream[inputPos++] >> 2); + } + pDacbox = dacbox; + } + + if (numcolors > 16) { + numcolors = 256; + } + if (numcolors > 2 && numcolors < 16) { + numcolors = 16; + } + + /**************************************************************************** + decoder(WDT, pInputStream, pBitmapElem->pBits); + int decoder(int linewidth, UCHAR* pInputStream, UCHAR *pBitmapElem->pBits) + ****************************************************************************/ + + size = pInputStream[inputPos++]; + if (size < 2 || 9 < size) { + if (decoderline != 0) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf != 0) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return -1; + } + + rowcount = oc = fc = 0; + buf = decoderline; + sp = dstack; + bufptr = buf; + bufcnt = orgwdt_1; + + /************************ + init_exp(size); + int init_exp(int size) + ************************/ + curr_size = size + 1; + top_slot = 1 << curr_size; + clear = 1 << size; + ending = clear + 1; + slot = newcodes = ending + 1; + navail_bytes = nbits_left = 0; + /************************/ + + + /* __get_next_code(pInputStream) */ + if (navail_bytes < 2) { + if (nbits_left == 0) { + __get_next_code_first_nbits_left_0(pInputStream) + } else + __get_next_code_first_nbits_left_not_0(pInputStream) + + __get_next_code_first_while(pInputStream) + } else { + if (nbits_left == 0) + __get_next_code_second_nbits_left_0(pInputStream) + else + __get_next_code_second_nbits_left_not_0(pInputStream) + + __get_next_code_second_while(pInputStream) + } + + if (c == ending) { + break; + } + /**********************************************************/ + + if (c == clear) { + curr_size = size + 1; + slot = newcodes; + top_slot = 1 << curr_size; + + do { + /* __get_next_code(pInputStream); */ + if (navail_bytes < 2) { + if (nbits_left == 0) + __get_next_code_first_nbits_left_0(pInputStream) + else + __get_next_code_first_nbits_left_not_0(pInputStream) + + __get_next_code_first_while(pInputStream) + } else { + if (nbits_left == 0) + __get_next_code_second_nbits_left_0(pInputStream) + else + __get_next_code_second_nbits_left_not_0(pInputStream) + + __get_next_code_second_while(pInputStream) + } + + } while (c == clear); + + if (c == ending) { + break; + } + + if (c >= slot) { + c = 0; + } + + oc = fc = c; + *sp++ = (unsigned char)c; + } else { + if (c >= slot) { + c = 0; + } + + oc = fc = c; + *sp++ = (unsigned char)c; + } + + while (rowcount < orghgt) { + if ((sp - dstack) > 0) { + spCount = sp - dstack; + } + /* Now that we've pushed the decoded string (in reverse order) + * onto the stack, lets pop it off and put it into our decode + * buffer... And when the decode buffer is full, write another + * line... + */ + while (sp > dstack) { + --sp; + *bufptr++ = *sp; + + if (--bufcnt == 0) { + + /******************************************************************************** + if ((ret = put_line(rowcount++, bufptr - buf, WDT, buf, pBitmapElem->pBits)) < 0) + ********************************************************************************/ + rowcount++; + len = bufptr - buf; + if (len >= orgwdt) { + len = orgwdt; + } + + if (interLaced == 0) { /* interlaced image */ + if (!flag) { + out_x = 0, out_y += dechgt; + } + } else { /* interlaced image */ + if (inter_step == 1) { + startloc += 8; + } else if (inter_step == 2) { + startloc += 8; + } else if (inter_step == 3) { + startloc += 4; + } else if (inter_step == 4) { + startloc += 2; + } + + if (startloc >= orghgt) { + inter_step++; + if (inter_step == 2) { + startloc = 4; + } else if (inter_step == 3) { + startloc = 2; + } else if (inter_step == 4) { + startloc = 1; + } + } + + /* gif to rgb 565 */ + if (flag) { + pImage32 = (unsigned int *)(pDecBuf) + startloc * decwdt; + } else { + out_x = 0, out_y = startloc * dechgt; + a_x = orgwdt>>2; + b_x = ((orgwdt*3)>>2); + c_x = orgwdt>>2; + d_x = ((orgwdt*3)>>2); + if (out_y <= (orghgt >> 2)) { + a_y = orghgt>>2; + b_y = orghgt>>2; + c_y = ((orghgt*3)>>2); + d_y = ((orghgt*3)>>2); + } else { + if (((out_y%orghgt) - (orghgt>>2)) > 0) { + a_y = ((out_y/orghgt)+1) * orghgt + (orghgt>>2); + } else if (((out_y%orghgt) - (orghgt>>2)) < 0 || !(out_y%orghgt)) { + a_y = ((out_y/orghgt)) * orghgt + (orghgt>>2); + } else { + a_y = out_y; + } + + if (((out_y % orghgt) - ((orghgt * 3) >> 2)) > 0) { + c_y = ((out_y/orghgt)+1) * orghgt + ((orghgt*3)>>2); + } else if (((out_y%orghgt) - ((orghgt*3)>>2)) < 0 || !(out_y%orghgt)) { + c_y = ((out_y/orghgt)) * orghgt + ((orghgt * 3) >> 2); + } else { + c_y = out_y; + } + b_y = a_y, d_y = c_y; + } + } + } + + if (transparent == 1) { + if (flag) { + for (i = 0; i < len; i++) { + val1 = buf[i] & (numcolors-1); + + if (val1 == transIndex) { + *pImage32++ = 0x4000000; /* Set *pImage32 MSB 1 */ + } else { + *pImage32++ = pDacbox[val1]<<2; + } + } + } else { + if (c_y < end) { + d1 = a_y - out_y; + d2 = c_y - out_y; + if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/orghgt) * decwdt; + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/orghgt) * decwdt; + + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = a_x - out_x; + d2 = b_x - out_x; + + if (0 <= d1 && d1 < decwdt) { + if (val1 == transIndex) { + *(pImage32 + (a_x/orgwdt)) += 0x1000000; + *(pImage32_2 + (c_x/orgwdt)) += 0x1000000; + a_x += orgwdt, c_x += orgwdt; + } else { + *(pImage32 + (a_x/orgwdt)) += pDacbox[val1]; + *(pImage32_2 + (c_x/orgwdt)) += pDacbox[val1]; + a_x += orgwdt, c_x += orgwdt; + } + } + if (0 <= d2 && d2 < decwdt) { + if (val1 == transIndex) { + *(pImage32 + (b_x/orgwdt)) += 0x1000000; + *(pImage32_2 + (d_x/orgwdt)) += 0x1000000; + b_x += orgwdt, d_x += orgwdt; + } else { + *(pImage32 + (b_x/orgwdt)) += pDacbox[val1]; + *(pImage32_2 + (d_x/orgwdt)) += pDacbox[val1]; + b_x += orgwdt, d_x += orgwdt; + } + } + out_x += decwdt; + } + if (!interLaced) { + a_x = orgwdt>>2, a_y += orghgt; + b_x = ((orgwdt*3)>>2), b_y += orghgt; + c_x = orgwdt>>2, c_y += orghgt; + d_x = ((orgwdt*3)>>2), d_y += orghgt; + } + } else if (0 <= d1 && d1 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/orghgt) * decwdt; + + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + if (val1 == transIndex) { + *(pImage32 + (a_x/orgwdt)) += 0x1000000; + a_x += orgwdt; + } else { + *(pImage32 + (a_x/orgwdt)) += pDacbox[val1]; + a_x += orgwdt; + } + } if (0 <= d2 && d2 < decwdt) { + if (val1 == transIndex) { + *(pImage32 + (b_x/orgwdt)) += 0x1000000; + b_x += orgwdt; + } else { + *(pImage32 + (b_x/orgwdt)) += pDacbox[val1]; + b_x += orgwdt; + } + } + out_x += decwdt; + } + if (!interLaced) { + a_x = orgwdt>>2, a_y += orghgt; + b_x = ((orgwdt*3)>>2), b_y += orghgt; + } + } else if (0 <= d2 && d2 < dechgt) { + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/orghgt) * decwdt; + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + if (val1 == transIndex) { + *(pImage32_2 + (c_x/orgwdt)) += 0x1000000; + c_x += orgwdt; + } else { + *(pImage32_2 + (c_x/orgwdt)) += pDacbox[val1]; + c_x += orgwdt; + } + } + if (0 <= d2 && d2 < decwdt) { + if (val1 == transIndex) { + *(pImage32_2 + (d_x/orgwdt)) += 0x1000000; + d_x += orgwdt; + } else { + *(pImage32_2 + (d_x/orgwdt)) += pDacbox[val1]; + d_x += orgwdt; + } + } + out_x += decwdt; + } + if (!interLaced) { + c_x = orgwdt>>2, c_y += orghgt; + d_x = ((orgwdt*3)>>2), d_y += orghgt; + } + } + } + } + } else { + if (flag) { + for (i = 0; i < len; i++) { + val1 = buf[i] & (numcolors-1); + *pImage32++ = pDacbox[val1]<<2; + } + } else { + if (c_y < end) { + d1 = a_y - out_y; + d2 = c_y - out_y; + if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/orghgt) * decwdt; + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/orghgt) * decwdt; + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/orgwdt)) += pDacbox[val1]; + *(pImage32_2 + (c_x/orgwdt)) += pDacbox[val1]; + a_x += orgwdt, c_x += orgwdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/orgwdt)) += pDacbox[val1]; + *(pImage32_2 + (d_x/orgwdt)) += pDacbox[val1]; + b_x += orgwdt, d_x += orgwdt; + } + out_x += decwdt; + } + if (!interLaced) { + a_x = orgwdt>>2, a_y += orghgt; + b_x = ((orgwdt*3)>>2), b_y += orghgt; + c_x = orgwdt>>2, c_y += orghgt; + d_x = ((orgwdt*3)>>2), d_y += orghgt; + } + } else if (0 <= d1 && d1 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/orghgt) * decwdt; + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/orgwdt)) += pDacbox[val1]; + a_x += orgwdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/orgwdt)) += pDacbox[val1]; + b_x += orgwdt; + } + out_x += decwdt; + } + if (!interLaced) { + a_x = orgwdt>>2, a_y += orghgt; + b_x = ((orgwdt*3)>>2), b_y += orghgt; + } + } else if (0 <= d2 && d2 < dechgt) { + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/orghgt) * decwdt; + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32_2 + (c_x/orgwdt)) += pDacbox[val1]; + c_x += orgwdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32_2 + (d_x/orgwdt)) += pDacbox[val1]; + d_x += orgwdt; + } + out_x += decwdt; + } + + if (!interLaced) { + c_x = orgwdt>>2, c_y += orghgt; + d_x = ((orgwdt*3)>>2), d_y += orghgt; + } + } + } + } + } + bufptr = buf; + bufcnt = orgwdt_1; + } + } + + if (rowcount == orghgt) { + break; + } + + /* __get_next_code(pInputStream) */ + if (navail_bytes < 2) { + if (nbits_left == 0) + __get_next_code_first_nbits_left_0(pInputStream) + else + __get_next_code_first_nbits_left_not_0(pInputStream) + __get_next_code_first_while(pInputStream) + } else { + if (nbits_left == 0) + __get_next_code_second_nbits_left_0(pInputStream) + else + __get_next_code_second_nbits_left_not_0(pInputStream) + + __get_next_code_second_while(pInputStream) + } + + if (c == ending) { + break; + } + /*************************************************************/ + + if (c == clear) { + curr_size = size + 1; + slot = newcodes; + top_slot = 1 << curr_size; + + do { + /* __get_next_code(pInputStream); */ + if (navail_bytes < 2) { + if (nbits_left == 0) + __get_next_code_first_nbits_left_0(pInputStream) + else + __get_next_code_first_nbits_left_not_0(pInputStream) + __get_next_code_first_while(pInputStream) + } else { + if (nbits_left == 0) + __get_next_code_second_nbits_left_0(pInputStream) + else + __get_next_code_second_nbits_left_not_0(pInputStream) + + __get_next_code_second_while(pInputStream) + } + } while (c == clear); + + if (c == ending) { + break; + } + + if (c >= slot) { + c = 0; + } + + oc = fc = c; + *sp++ = (unsigned char)c; + } else { + code = c; + + if (code >= slot) { + code = oc; + *sp++ = (unsigned char)fc; + } + while (code >= newcodes) { + *sp++ = suffix[code]; + code = prefix[code]; + } + + *sp++ = (unsigned char)code; + spCount++; + if (slot < top_slot) { + fc = code; + suffix[slot] = (unsigned char)fc; + prefix[slot++] = oc; + oc = c; + } + if (slot >= top_slot) { + if (curr_size < 12) { + top_slot <<= 1; + ++curr_size; + } + } + } + } + /*************************************************************/ + + if (bCenterAlign) { + margin_wdt1_2 = (expected_width - resized_width)>>1; + margin_hgt1_2 = (expected_height - resized_height)>>1; + } else { + margin_wdt1_2 = 0; + margin_hgt1_2 = 0; + } + + pImage32 = (unsigned int *)(pDecBuf); + + /* Only make a first image frame as a thumbnail */ + image_left_pos = 0; + image_top_pos = 0; + len = decwdt; + + if (orgwdt > logi_wdt) { + decwdt = resized_width; + } + if (orghgt > logi_hgt) { + dechgt = resized_height; + } + + if ((image_left_pos + decwdt) > resized_width) { + decwdt = resized_width - image_left_pos; + if (decwdt < 0) { + decwdt = 0; + } + } + if ((image_top_pos+dechgt) > resized_height) { + dechgt = resized_height - image_top_pos; + if (dechgt < 0) { + dechgt = 0; + } + } + + if (pFrameData->imgCount == 0) { + for (i = 0, k = margin_hgt1_2; i < resized_height; i++) { + pImage16 = (unsigned short *)((unsigned char *)pOutBits + ((margin_wdt1_2 + expected_width * k) << 1)); + for (j = 0; j < resized_width; j++) { + *pImage16++ = backcolor; + } + k++; + } + if (transparent == 1) { + for (i = 0, k = image_top_pos+margin_hgt1_2; i < dechgt; i++) { + pImage16 = (unsigned short *)((unsigned char *)pOutBits + ((image_left_pos+margin_wdt1_2 + expected_width * k) << 1)); + for (j = 0; j < decwdt; j++) { + *pImage16++ = ui_backcolor; + } + k++; + } + } + } + + for (i = 0, k = image_top_pos+margin_hgt1_2; i < dechgt; i++) { + pImage16 = (unsigned short *)((unsigned char*)pOutBits + ((image_left_pos+margin_wdt1_2 + (expected_width) * k) << 1)); + pImage32 = (unsigned int *)(pDecBuf) + (i * len); + + for (j = 0; j < decwdt; j++) { + if ((*pImage32>>24) == 0) { + *(pImage16++) = ((*pImage32 & 0xf80000) >> 8) | ((*pImage32 & 0xfc00) >> 5) | ((*pImage32 & 0xf8) >> 3); + } else if ((*pImage32 >> 24) == 4) { + pImage16++; + } else if ((*pImage32 >> 24) == 3) { + *pImage16 = + (((*pImage32 & 0xf80000) >> 8)+(((((*pImage16) & 0xf800) * 3) >> 2) & 0xf800)) | + (((*pImage32 & 0xfc00) >> 5)+(((((*pImage16) & 0x07c0) * 3) >> 2) & 0x07c0)) | + (((*pImage32 & 0xf8) >> 3)+((((*pImage16) & 0x001f) * 3) >> 2)); + pImage16++; + } else if ((*pImage32 >> 24) == 1) { + *pImage16 = + (((*pImage32 & 0xf80000) >> 8)+((((*pImage16) & 0xf800) >> 2) & 0xf800)) | + (((*pImage32 & 0xfc00) >> 5)+((((*pImage16) & 0x07c0) >> 2) & 0x07c0)) | + (((*pImage32 & 0xf8) >> 3)+((((*pImage16) & 0x001f) >> 2))); + pImage16++; + } else { + *pImage16 = + (((*pImage32 & 0xf80000) >> 8)+((((*pImage16) & 0xf800) >> 1) & 0xf800)) | + (((*pImage32 & 0xfc00) >> 5)+((((*pImage16) & 0x07c0) >> 1) & 0x07c0)) | + (((*pImage32 & 0xf8) >> 3)+((((*pImage16) & 0x001f) >> 1))); + pImage16++; + } + pImage32++; + } + k++; + } + + switch (disposal_method) { + /* No disposal specified. The decoder is not required to take any action */ + case 0: + + /* Do not dispose. The graphic is to be left in place. */ + case 1: + IfegMemcpy(pFrameData->pPrevImg, pOutBits, expected_width * expected_height * 2); + break; + + /* Restore to background color. The area used by the graphic must be restored to the background color. */ + case 2: + IfegMemcpy(pFrameData->pPrevImg, pOutBits, expected_width * expected_height * 2); + + if (transparent == 1) { + for (i = 0, k = image_top_pos+margin_hgt1_2; i < dechgt; i++) { + pImage16 = (unsigned short *)((pFrameData->pPrevImg) + ((image_left_pos+margin_wdt1_2 + expected_width * k) << 1)); + for (j = 0; j < decwdt; j++) { + *pImage16++ = ui_backcolor; + } + k++; + } + } else { + for (i = 0, k = image_top_pos+margin_hgt1_2; i < dechgt; i++) { + pImage16 = (unsigned short *)((pFrameData->pPrevImg) + ((image_left_pos+margin_wdt1_2 + expected_width * k) << 1)); + for (j = 0; j < decwdt; j++) { + *pImage16++ = image_backcolor; + } + k++; + } + } + break; + + /* Restore to previous. The decoder is required to restore the area overwritten by the graphic with what was there prior to rendering the graphic.*/ + case 3: + break; + + default: + IfegMemcpy(pFrameData->pPrevImg, pOutBits, expected_width * expected_height * 2); + /* same with case 1 */ + break; + } + + if (decoderline) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + + pFrameData->offset = inputPos; + pFrameData->imgCount++; + + return 1; + + break; + + default: + break; + + } + } +} + + +/* use buffer */ +int __FastImgGetNextFrameAGIF_UseBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAlign) +{ + unsigned int *pImage32, *pImage32_2, *backGround; + unsigned short *pImage16; + unsigned char *sp; + unsigned char *bufptr; + unsigned int code, fc, oc, bufcnt; + unsigned char buffer[16]; + unsigned char val1; + unsigned char *buf; + unsigned int *pDacbox; + unsigned char *decoderline = 0; + unsigned int size; + unsigned int c = 0; + + unsigned int clear; + unsigned int ending; + unsigned int newcodes; + unsigned int top_slot; + unsigned int slot; + + int numcolors; + int i, j, k; + int rowcount; + int orgwdt_1, orgwdt, orghgt; + int decwdt, dechgt; + int len; + int inter_step, interLaced, intercount; + int transparent = 0; + int startloc = 0; + int backgroundIndex = 0; + int transIndex = 0; + int spCount = 0; + int logi_wdt; /* logical screen width */ + int logi_hgt; + int logi_image_size; + int ui_backcolor565; + int backcolor565; + + int ui_backcolor888; + int backcolor888; + + int image_left_pos; /* left position of image in Logical screeen */ + int image_top_pos; + int disposal_method = 0; + int margin_wdt1_2, margin_hgt1_2; + + int inputPos; + + + unsigned int dacbox[256]; + + /* Variable for Resize */ + + unsigned int a_x, a_y; + unsigned int b_x, b_y; + unsigned int c_x, c_y; + unsigned int d_x, d_y; + int out_x = 0, out_y = 0; + int d1, d2; + int flag = 0; + unsigned int end; + + int count = 0; + + unsigned char *pDecBuf = 0; + + int expected_width = pFrameData->width; + int expected_height = pFrameData->height; + int resized_width; + int resized_height; + + /* macro */ + register unsigned int curr_size; + register int navail_bytes = 0; + register unsigned int nbits_left = 0; + register unsigned int b1 = 0; + register unsigned int ret; + + /* parameter */ + unsigned int *global_dacbox = pFrameData->pGlobal_table; + unsigned char *pInputStream = pFrameData->pEncodedData; + void *pOutBits = pFrameData->pOutBits; + unsigned short *prefix = pFrameData->pPrefix; + unsigned char *dstack = pFrameData->pDstack; + unsigned char *suffix = pFrameData->pSuffix; + int filesize = pFrameData->inputSize; + + inputPos = pFrameData->offset; + + IfegMemset(prefix, 0, sizeof(unsigned short)*(MAX_CODES+1)); + IfegMemset(dstack, 0, sizeof(unsigned char)*(MAX_CODES+1)); + IfegMemset(suffix, 0, sizeof(unsigned char)*(MAX_CODES+1)); + + ui_backcolor565 = pFrameData->ui_backcolor; + ui_backcolor888 = + ((ui_backcolor565&0xf800) << 6)| + ((ui_backcolor565&0x7e0) << 3)| + ((ui_backcolor565&0x1f) << 1); + + backcolor565 = pFrameData->backcolor; + backcolor888 = + ((backcolor565&0xf800) << 6)| + ((backcolor565&0x7e0) << 3)| + ((backcolor565&0x1f) << 1); + + backGround = (unsigned int *)pFrameData->pPrevImg; + + intercount = 0; + + if (pFrameData->imgCount == -1) { + /* Input stream index set to 0 */ + inputPos = 0; + inter_step = 1; + interLaced = 0; + transparent = 0; + + /* read a GIF HEADER */ + IfegMemcpy(buffer, pInputStream, 13); + inputPos += 13; + + /* wheather GIF file or not */ + if (buffer[0] != 'G' || buffer[1] != 'I' || buffer[2] != 'F' || + buffer[3] < '0' || buffer[3] > '9' || + buffer[4] < '0' || buffer[4] > '9' || + buffer[5] < 'A' || buffer[5] > 'z') { + if (pDecBuf != 0) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return -1; + } + + /* get Logical width, height */ + pFrameData->logi_wdt = logi_wdt = buffer[6] | (buffer[7] << 8); + pFrameData->logi_hgt = logi_hgt = buffer[8] | (buffer[9] << 8); + + logi_image_size = logi_wdt * logi_hgt; + + /* ouput resized image size */ + if (logi_wdt <= expected_width && logi_hgt <= expected_height) { + resized_width = logi_wdt; + resized_height = logi_hgt; + pFrameData->flag = flag = 1; + } else { + if ((logi_wdt/(float)expected_width) >= (logi_hgt/(float)expected_height)) { + resized_height = logi_hgt * expected_width / logi_wdt; + resized_width = expected_width; + } else { + resized_width = logi_wdt * expected_height / logi_hgt; + resized_height = expected_height; + } + } + if (!resized_width || !resized_height) { + if (decoderline != 0) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf != 0) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return 0; + } + + /* ouput resized image size */ + pFrameData->resizedwidth = resized_width; + pFrameData->resizedheight = resized_height; + + /* Color Resolution */ + IfegMemset(global_dacbox, 0, 1024); + numcolors = (buffer[10] & 0x7) + 1; + if ((buffer[10] & 0x80) == 0) { /* Global color table */ + global_dacbox[0] = 0x000000; + global_dacbox[1] = 0x3f3f3f; + numcolors = 2; + } else { /* Global color table */ + numcolors = 1 << numcolors; + + /* Make color table */ + for (i = 0; i < numcolors; i++) { + global_dacbox[i] = ((pInputStream[inputPos++] >> 2) << 16); + global_dacbox[i] |= ((pInputStream[inputPos++] >> 2) << 8); + global_dacbox[i] |= (pInputStream[inputPos++] >> 2); + } + } + + backgroundIndex = buffer[11]; + /* Background Color */ + backcolor888 = global_dacbox[backgroundIndex]; + backcolor565 = pFrameData->backcolor = (((backcolor888 & 0xff0000) >> 17) << 11) | (((backcolor888 & 0x00ff00) >> 8) << 5) | (((backcolor888 & 0xff) >> 1)); + + pImage16 = pOutBits; + + ui_backcolor565 = pFrameData->ui_backcolor ; + for (i = 0; i < expected_width * expected_height; i++) { + *pImage16++ = ui_backcolor565; + } + + pImage32 = (unsigned int *)pFrameData->pPrevImg; + + if (numcolors > 16) { + numcolors = 256; + } + if (numcolors > 2 && numcolors < 16) { + numcolors = 16; + } + pFrameData->global_numcol = numcolors; + pFrameData->imgCount++; + pFrameData->firstpos = inputPos; + } else { + logi_wdt = pFrameData->logi_wdt; + logi_hgt = pFrameData->logi_hgt; + resized_width = pFrameData->resizedwidth; + resized_height = pFrameData->resizedheight; + flag = pFrameData->flag ; + + numcolors = pFrameData->global_numcol; + } + + /* still gif image (image_cnt = 1) */ + while (1) { + if (inputPos > filesize) { + + if (decoderline) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + pFrameData->imgCount = 0; + pFrameData->offset = pFrameData->firstpos; + + if (pFrameData->bLoop) { + return 1; + } else { + return 0; + } + } + + switch (pInputStream[inputPos++]) { + case 0x3b:/* End of the GIF dataset */ + if (decoderline) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + if (pFrameData->imgCount == 0) { + return -1; + } + pFrameData->imgCount = 0; + pFrameData->offset = pFrameData->firstpos; +#ifdef INTERNAL_IMGCODEC + pFrameData->nRepeatCount++; + + if (pFrameData->nLoopCount == -1) { + break; + } else if (pFrameData->bLoop || (pFrameData->nRepeatCount <= pFrameData->nLoopCount) || (pFrameData->nLoopCount == 0)) { + inputPos = pFrameData->offset; + continue; + } else { + return 2; + } +#else + if (pFrameData->bLoop) { + return 1; + } else { + return 0; + } + +#endif + break; + case 0x21: /* Extension Block */ + switch (pInputStream[inputPos++]) { + case 0xf9: /* Graphic control extension block */ + if (4 != pInputStream[inputPos++]) { /* data length : fixed 4 bytes */ + if (decoderline != 0) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf != 0) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return -1; + } + + disposal_method = ((pInputStream[inputPos] & 0x1c) >> 2); + transparent = pInputStream[inputPos++] & 0x01; /* does it use? 1:on 0:off */ + pFrameData->delay = (pInputStream[inputPos] | (pInputStream[inputPos+1] << 8))*10; + inputPos += 2; /* Delay time (skip) */ + transIndex = pInputStream[inputPos++]; + inputPos++; /* block end */ + + if (backgroundIndex == transIndex && transparent == 1) { + backcolor888 = 0x1000000; + backcolor565 = pFrameData->ui_backcolor; + } + + break; + case 0x01: /* Plain Text block */ + while ((i = pInputStream[inputPos++]) > 0) { /* get the data length */ + inputPos += i; + if (inputPos > filesize) { + if (decoderline) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return -1; + } + } + break; + case 0xfe: /* Comment Extension block */ + while ((i = pInputStream[inputPos++]) > 0) { /* get the data length */ + inputPos += i; + if (inputPos > filesize) { + if (decoderline) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return -1; + } + } + break; + case 0xff: /* Appliation Extension block */ + + while ((i = pInputStream[inputPos++]) > 0) { /* get the data length */ + inputPos += i; + if (inputPos > filesize) { + if (decoderline) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return -1; + } + } + break; + default: + break; + } + + break; + + case 0x2c: /* Start of an image object. Read the image description. */ + + /* initialize */ + pDacbox = global_dacbox; + + IfegMemcpy(buffer, pInputStream+inputPos, 9); + inputPos += 9; + + if (pFrameData->imgCount == 0) { + image_left_pos_N = (buffer[0] | (buffer[1] << 8)); + image_top_pos_N = (buffer[2] | (buffer[3] << 8)); + + image_left_pos = image_left_pos_N; + image_top_pos = image_top_pos_N; + } + image_left_pos = (buffer[0] | (buffer[1] << 8)); + image_top_pos = (buffer[2] | (buffer[3] << 8)); + orgwdt_1 = orgwdt = (buffer[4] | (buffer[5] << 8)); + orghgt = (buffer[6] | (buffer[7] << 8)); + + +#ifdef INTERNAL_IMGCODEC +#else + if ((orgwdt > MAXWIDTH) || (orghgt > MAXHEIGHT)) { + if (decoderline != 0) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf != 0) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return -1; + } +#endif + + /* Initialize */ + a_x = logi_wdt >> 2, a_y = logi_hgt >> 2; + b_x = ((logi_wdt*3) >> 2), b_y = logi_hgt >> 2; + c_x = logi_wdt >> 2, c_y = ((logi_hgt*3) >> 2); + d_x = ((logi_wdt*3) >> 2), d_y = ((logi_hgt*3) >> 2); + + /* Interlaced check */ + interLaced = buffer[8] & 0x40; + if (interLaced) { + startloc = -8+image_top_pos; + } + + inter_step = 1; + + if (decoderline) { + IfegMemFree(decoderline); + } + decoderline = (unsigned char *)IfegMemAlloc(orgwdt); + if (!decoderline) { + if (decoderline != 0) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf != 0) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return 0; + } + IfegMemset(decoderline, 0, orgwdt); + + decwdt = resized_width; + dechgt = resized_height; + + if (!decwdt || !dechgt) { + if (decoderline != 0) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf != 0) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return 0; + } + + if (pDecBuf) { + IfegMemFree(pDecBuf); + } + pDecBuf = (unsigned char *)IfegMemAlloc(decwdt * dechgt * 4); + if (!pDecBuf) { + if (decoderline != 0) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf != 0) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return 0; + } + + IfegMemset(pDecBuf, 0, decwdt * dechgt * 4); + + /* assign out_888_image plane */ + pImage32 = (unsigned int *)(pDecBuf); + + end = dechgt * logi_hgt; + out_x = 0, out_y = -dechgt; + + /* Color Resolution */ + if ((buffer[8] & 0x80) == 0) { /* Logical color table */ + ;/* use global table */ + } else { /* Logical color table */ + IfegMemset(dacbox, 0, 1024); + + numcolors = (buffer[8] & 0x7) + 1; + numcolors = 1 << numcolors; + + count = 0; + + /* Make color table */ + for (i = 0; i < numcolors; i++) { + dacbox[i] = ((pInputStream[inputPos++] >> 2) << 16); + dacbox[i] |= ((pInputStream[inputPos++] >> 2) << 8); + dacbox[i] |= (pInputStream[inputPos++] >> 2); + } + pDacbox = dacbox; + } + + if (numcolors > 16) { + numcolors = 256; + } + if (numcolors > 2 && numcolors < 16) { + numcolors = 16; + } + + if (logi_wdt < (image_left_pos + orgwdt)) { + if (image_left_pos > logi_wdt) { + image_left_pos = logi_wdt; + } + orgwdt = logi_wdt - image_left_pos; + flag = 0; + } + if (logi_hgt < (image_top_pos + orghgt)) { + flag = 0; + } + + if (pFrameData->imgCount == 0) { + if (disposal_method == 3) { + pImage32 = (unsigned int *)pFrameData->pPrevImg; + for (i = 0; i < logi_wdt * logi_hgt; i++) { + *pImage32++ = 0x1000000; + } + } else { + pImage32 = (unsigned int *)pFrameData->pPrevImg; + for (i = 0; i < logi_wdt * logi_hgt; i++) { + *pImage32++ = backcolor888; + } + } + if (transparent == 1) { + /* Background Color */ + pImage32 = (unsigned int *)pFrameData->pPrevImg; + pImage32 += image_top_pos * logi_wdt + image_left_pos; + if (logi_hgt < (image_top_pos + orghgt)) { + for (i = 0; i < logi_hgt - image_top_pos; i++) { + for (j = 0; j < orgwdt; j++) { + pImage32[j] = 0x1000000; /* set ui color */ + } + pImage32 += logi_wdt; + } + } else { + for (i = 0; i < orghgt; i++) { + for (j = 0; j < orgwdt; j++) { + pImage32[j] = 0x1000000; /* set ui color */ + } + pImage32 += logi_wdt; + } + } + } + } + + /* assign out_888_image plane */ + pImage32 = (unsigned int *)(pDecBuf); + + for (rowcount = 0; rowcount < image_top_pos; rowcount++) { + if (flag) { + for (i = 0; i < logi_wdt; i++) { + *pImage32++ = backGround[i] << 2; + } + } else { + out_x = 0, out_y += dechgt; + if (c_y < end) { + d1 = a_y - out_y; + d2 = c_y - out_y; + if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt; + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt; + for (i = 0; i < logi_wdt; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt, c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt, d_x += logi_wdt; + } + out_x += decwdt; + } + a_x = logi_wdt >> 2, a_y += logi_hgt; + b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt; + c_x = logi_wdt >> 2, c_y += logi_hgt; + d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt; + } else if (0 <= d1 && d1 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt; + for (i = 0; i < logi_wdt; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt; + } + out_x += decwdt; + } + a_x = logi_wdt >> 2, a_y += logi_hgt; + b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt; + } else if (0 <= d2 && d2 < dechgt) { + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt; + for (i = 0; i < logi_wdt; i++) { + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + d_x += logi_wdt; + } + out_x += decwdt; + } + c_x = logi_wdt >> 2, c_y += logi_hgt; + d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt; + } + } + } + backGround += logi_wdt; + } + + + /*************************************************************************** + decoder(WDT, pInputStream, pBitmapElem->pBits); //this does the grunt work + int decoder(int linewidth, UCHAR* pInputStream, UCHAR *pBitmapElem->pBits) + ***************************************************************************/ + + size = pInputStream[inputPos++]; + if (size < 2 || 9 < size) { + if (decoderline != 0) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf != 0) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + return -1; + } + rowcount = oc = fc = 0; + buf = decoderline; + sp = dstack; + bufptr = buf; + bufcnt = orgwdt_1; + + /************************ + init_exp(size); + int init_exp(int size) + ************************/ + curr_size = size + 1; + top_slot = 1 << curr_size; + clear = 1 << size; + ending = clear + 1; + slot = newcodes = ending + 1; + navail_bytes = nbits_left = 0; + /************************/ + + + /* __get_next_code(pInputStream) */ + if (navail_bytes < 2) { + if (nbits_left == 0) + __get_next_code_first_nbits_left_0(pInputStream) + else + __get_next_code_first_nbits_left_not_0(pInputStream) + __get_next_code_first_while(pInputStream) + } else { + if (nbits_left == 0) + __get_next_code_second_nbits_left_0(pInputStream) + else + __get_next_code_second_nbits_left_not_0(pInputStream) + + __get_next_code_second_while(pInputStream) + } + if (c == ending) { + break; + } + + if (c == clear) { + curr_size = size + 1; + slot = newcodes; + top_slot = 1 << curr_size; + + do { + /* __get_next_code(pInputStream); */ + if (navail_bytes < 2) { + if (nbits_left == 0) + __get_next_code_first_nbits_left_0(pInputStream) + else + __get_next_code_first_nbits_left_not_0(pInputStream) + __get_next_code_first_while(pInputStream) + } else { + if (nbits_left == 0) + __get_next_code_second_nbits_left_0(pInputStream) + else + __get_next_code_second_nbits_left_not_0(pInputStream) + + __get_next_code_second_while(pInputStream) + } + } while (c == clear); + + if (c == ending) { + break; + } + + if (c >= slot) { + c = 0; + } + + oc = fc = c; + *sp++ = (unsigned char)c; + } else { + if (c >= slot) { + c = 0; + } + + oc = fc = c; + *sp++ = (unsigned char)c; + } + + switch (disposal_method) { + + /* Restore to previous. The decoder is required to restore the area overwritten by the graphic with what was there prior to rendering the graphic. */ + case 3: + while (rowcount < orghgt) { + if ((sp - dstack) > 0) { + spCount = sp - dstack; + } + /* Now that we've pushed the decoded string (in reverse order) + * onto the stack, lets pop it off and put it into our decode + * buffer... And when the decode buffer is full, write another + * line... + */ + while (sp > dstack) { + --sp; + *bufptr++ = *sp; + + if (--bufcnt == 0) { + /********************************************************************************** + if ((ret = put_line(rowcount++, bufptr - buf, WDT, buf, pBitmapElem->pBits)) < 0) + **********************************************************************************/ + rowcount++; + len = bufptr - buf; + if (len >= orgwdt) { + len = orgwdt; + } + + if (interLaced == 0) { /* interlaced image */ + if (!flag) { + out_x = 0, out_y += dechgt; + } + } else { /* interlaced image */ + if (inter_step == 1) { + startloc += 8; + intercount++; + } else if (inter_step == 2) { + startloc += 8; + intercount++; + } else if (inter_step == 3) { + startloc += 4; + intercount++; + } else if (inter_step == 4) { + startloc += 2; + intercount++; + } + + if (startloc >= orghgt+image_top_pos) { + inter_step++; + if (inter_step == 2) { + startloc = 4+image_top_pos; + } else if (inter_step == 3) { + startloc = 2+image_top_pos; + } else if (inter_step == 4) { + startloc = 1+image_top_pos; + } + } + + backGround = (unsigned int *)(pFrameData->pPrevImg + ((startloc * logi_wdt) << 2)); + /* gif to rgb 565 */ + if (flag) { + pImage32 = (unsigned int *)(pDecBuf) + startloc * decwdt; + } else { + out_x = 0, out_y = startloc * dechgt; + a_x = logi_wdt >> 2; + b_x = ((logi_wdt*3) >> 2); + c_x = logi_wdt >> 2; + d_x = ((logi_wdt*3) >> 2); + if (out_y <= (logi_hgt >> 2)) { + a_y = logi_hgt >> 2; + b_y = logi_hgt >> 2; + c_y = ((logi_hgt*3) >> 2); + d_y = ((logi_hgt*3) >> 2); + } else { + if (((out_y % logi_hgt) - (logi_hgt >> 2)) > 0) { + a_y = ((out_y/logi_hgt)+1) * logi_hgt + (logi_hgt >> 2); + } else if (((out_y % logi_hgt) - (logi_hgt >> 2)) < 0 || !(out_y%logi_hgt)) { + a_y = ((out_y/logi_hgt)) * logi_hgt + (logi_hgt>>2); + } else { + a_y = out_y; + } + + if (((out_y % logi_hgt) - ((logi_hgt*3) >> 2)) > 0) { + c_y = ((out_y/logi_hgt+1) * logi_hgt + ((logi_hgt*3) >> 2)); + } else if (((out_y % logi_hgt) - ((logi_hgt*3) >> 2)) < 0 || !(out_y % logi_hgt)) { + c_y = ((out_y/logi_hgt)) * logi_hgt + ((logi_hgt*3) >> 2); + } else { + c_y = out_y; + } + b_y = a_y, d_y = c_y; + } + } + } + + if (transparent == 1) { + if (flag) { + for (i = 0; i < image_left_pos; i++) { + *pImage32++ = backGround[i]<<2; + } + for (i = 0; i < len; i++) { + val1 = buf[i] & (numcolors-1); + + if (val1 == transIndex) { + *pImage32++ = backGround[i+image_left_pos] << 2; + } else { + *pImage32++ = pDacbox[val1] << 2; + } + } + for (i = orgwdt+image_left_pos; i < logi_wdt; i++) { + *pImage32++ = backGround[i] << 2; + } + } else { + if (c_y < end) { + d1 = a_y - out_y; + d2 = c_y - out_y; + if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt; + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt; + + for (i = 0; i < image_left_pos; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt, c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt, d_x += logi_wdt; + } + out_x += decwdt; + } + + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + if (val1 == transIndex) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i+image_left_pos]; + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i+image_left_pos]; + a_x += logi_wdt, c_x += logi_wdt; + } else { + *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1]; + *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1]; + a_x += logi_wdt, c_x += logi_wdt; + } + } + if (0 <= d2 && d2 < decwdt) { + if (val1 == transIndex) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i+image_left_pos]; + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i+image_left_pos]; + b_x += logi_wdt, d_x += logi_wdt; + } else { + *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1]; + *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1]; + b_x += logi_wdt, d_x += logi_wdt; + } + } + out_x += decwdt; + } + + for (i = image_left_pos+orgwdt; i < logi_wdt; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt, c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt, d_x += logi_wdt; + } + out_x += decwdt; + } + + if (!interLaced) { + a_x = logi_wdt >> 2, a_y += logi_hgt; + b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt; + c_x = logi_wdt>>2, c_y += logi_hgt; + d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt; + } + } else if (0 <= d1 && d1 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt; + for (i = 0; i < image_left_pos; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt; + } + out_x += decwdt; + } + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + if (val1 == transIndex) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i+image_left_pos]; + a_x += logi_wdt; + } else { + *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1]; + a_x += logi_wdt; + } + } + if (0 <= d2 && d2 < decwdt) { + if (val1 == transIndex) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i+image_left_pos]; + b_x += logi_wdt; + } else { + *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1]; + b_x += logi_wdt; + } + } + out_x += decwdt; + } + for (i = image_left_pos+orgwdt; i < logi_wdt; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt; + } + out_x += decwdt; + } + if (!interLaced) { + a_x = logi_wdt >> 2, a_y += logi_hgt; + b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt; + } + } else if (0 <= d2 && d2 < dechgt) { + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt; + for (i = 0; i < image_left_pos; i++) { + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + d_x += logi_wdt; + } + out_x += decwdt; + } + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + if (val1 == transIndex) { + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i+image_left_pos]; + c_x += logi_wdt; + } else { + *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1]; + c_x += logi_wdt; + } + } + if (0 <= d2 && d2 < decwdt) { + if (val1 == transIndex) { + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i+image_left_pos]; + d_x += logi_wdt; + } else { + *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1]; + d_x += logi_wdt; + } + } + out_x += decwdt; + } + for (i = image_left_pos+orgwdt; i < logi_wdt; i++) { + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + d_x += logi_wdt; + } + out_x += decwdt; + } + if (!interLaced) { + c_x = logi_wdt >> 2, c_y += logi_hgt; + d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt; + } + } + } + } + } else { + if (flag) { + for (i = 0; i < image_left_pos; i++) { + *pImage32++ = backGround[i] << 2; + } + for (i = 0; i < len; i++) { + val1 = buf[i] & (numcolors - 1); + *pImage32++ = pDacbox[val1] << 2; + } + for (i = orgwdt+image_left_pos; i < logi_wdt; i++) { + *pImage32++ = backGround[i] << 2; + } + } else { + if (c_y < end) { + d1 = a_y - out_y; + d2 = c_y - out_y; + if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt; + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt; + for (i = 0; i < image_left_pos; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt, c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt, d_x += logi_wdt; + } + out_x += decwdt; + } + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1]; + *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1]; + a_x += logi_wdt, c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1]; + *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1]; + b_x += logi_wdt, d_x += logi_wdt; + } + out_x += decwdt; + } + for (i = image_left_pos+orgwdt; i < logi_wdt; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt, c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt, d_x += logi_wdt; + } + out_x += decwdt; + + } + if (!interLaced) { + a_x = logi_wdt >> 2, a_y += logi_hgt; + b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt; + c_x = logi_wdt >> 2, c_y += logi_hgt; + d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt; + } + } else if (0 <= d1 && d1 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt; + for (i = 0; i < image_left_pos; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt; + } + out_x += decwdt; + + } + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1]; + a_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1]; + b_x += logi_wdt; + } + out_x += decwdt; + } + for (i = image_left_pos+orgwdt; i < logi_wdt; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt; + } + out_x += decwdt; + + } + if (!interLaced) { + a_x = logi_wdt >> 2, a_y += logi_hgt; + b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt; + } + } else if (0 <= d2 && d2 < dechgt) { + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt; + for (i = 0; i < image_left_pos; i++) { + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + d_x += logi_wdt; + } + out_x += decwdt; + } + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1]; + c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1]; + d_x += logi_wdt; + } + out_x += decwdt; + } + for (i = image_left_pos+orgwdt; i < logi_wdt; i++) { + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + d_x += logi_wdt; + } + out_x += decwdt; + + } + if (!interLaced) { + c_x = logi_wdt >> 2, c_y += logi_hgt; + d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt; + } + } + } + } + } + + backGround += logi_wdt; + bufptr = buf; + bufcnt = orgwdt_1; + } + } + + if (rowcount == orghgt) { + break; + } + /* __get_next_code(pInputStream) */ + if (navail_bytes < 2) { + if (nbits_left == 0) + __get_next_code_first_nbits_left_0(pInputStream) + else + __get_next_code_first_nbits_left_not_0(pInputStream) + __get_next_code_first_while(pInputStream) + } else { + if (nbits_left == 0) + __get_next_code_second_nbits_left_0(pInputStream) + else + __get_next_code_second_nbits_left_not_0(pInputStream) + + __get_next_code_second_while(pInputStream) + } + + if (c == ending) { + break; + } + + if (c == clear) { + curr_size = size + 1; + slot = newcodes; + top_slot = 1 << curr_size; + + do { + /* __get_next_code(pInputStream); */ + if (navail_bytes < 2) { + if (nbits_left == 0) + __get_next_code_first_nbits_left_0(pInputStream) + else + __get_next_code_first_nbits_left_not_0(pInputStream) + __get_next_code_first_while(pInputStream) + } else { + if (nbits_left == 0) + __get_next_code_second_nbits_left_0(pInputStream) + else + __get_next_code_second_nbits_left_not_0(pInputStream) + + __get_next_code_second_while(pInputStream) + } + } while (c == clear); + + if (c == ending) { + break; + } + + if (c >= slot) { + c = 0; + } + + oc = fc = c; + + *sp++ = (unsigned char)c; + } else { + code = c; + + if (code >= slot) { + code = oc; + *sp++ = (unsigned char)fc; + } + + while (code >= newcodes) { + *sp++ = suffix[code]; + code = prefix[code]; + } + + *sp++ = (unsigned char)code; + spCount++; + if (slot < top_slot) { + fc = code; + suffix[slot] = (unsigned char)fc; + prefix[slot++] = oc; + oc = c; + } + if (slot >= top_slot) { + if (curr_size < 12) { + top_slot <<= 1; + ++curr_size; + } + } + } + } + break; + + /* Restore to background color. The area used by the graphic must be restored to the background color. */ + case 2: + while (rowcount < orghgt) { + if ((sp - dstack) > 0) { + spCount = sp - dstack; + } + while (sp > dstack) { + --sp; + *bufptr++ = *sp; + + if (--bufcnt == 0) { + /******************************************************************************** + if ((ret = put_line(rowcount++, bufptr - buf, WDT, buf, pBitmapElem->pBits)) < 0) + ********************************************************************************/ + rowcount++; + len = bufptr - buf; + if (len >= orgwdt) { + len = orgwdt; + } + + if (interLaced == 0) { /* interlaced image */ + if (!flag) { + out_x = 0, out_y += dechgt; + } + } else { /* interlaced image */ + if (inter_step == 1) { + startloc += 8; + } else if (inter_step == 2) { + startloc += 8; + } else if (inter_step == 3) { + startloc += 4; + } else if (inter_step == 4) { + startloc += 2; + } + + if (startloc >= orghgt + image_top_pos) { + inter_step++; + if (inter_step == 2) { + startloc = 4 + image_top_pos; + } else if (inter_step == 3) { + startloc = 2+image_top_pos; + } else if (inter_step == 4) { + startloc = 1+image_top_pos; + } + } + backGround = (unsigned int *)(pFrameData->pPrevImg + ((startloc * logi_wdt) << 2)); + /* gif to rgb 565 */ + if (flag) { + pImage32 = (unsigned int *)(pDecBuf) + startloc * decwdt; + } else { + out_x = 0, out_y = startloc * dechgt; + a_x = logi_wdt >> 2; + b_x = ((logi_wdt*3) >> 2); + c_x = logi_wdt>>2; + d_x = ((logi_wdt*3) >> 2); + if (out_y <= (logi_hgt >> 2)) { + a_y = logi_hgt>>2; + b_y = logi_hgt>>2; + c_y = ((logi_hgt*3)>>2); + d_y = ((logi_hgt*3)>>2); + } else { + if (((out_y % logi_hgt) - (logi_hgt >> 2)) > 0) { + a_y = ((out_y/logi_hgt)+1) * logi_hgt + (logi_hgt >> 2); + } else if (((out_y%logi_hgt) - (logi_hgt >> 2)) < 0 || !(out_y%logi_hgt)) { + a_y = ((out_y/logi_hgt)) * logi_hgt + (logi_hgt >> 2); + } else { + a_y = out_y; + } + + if (((out_y%logi_hgt) - ((logi_hgt*3) >> 2)) > 0) { + c_y = ((out_y/logi_hgt+1) * logi_hgt + ((logi_hgt*3) >> 2)); + } else if (((out_y%logi_hgt) - ((logi_hgt*3) >> 2)) < 0 || !(out_y%logi_hgt)) { + c_y = ((out_y/logi_hgt)) * logi_hgt + ((logi_hgt*3) >> 2); + } else { + c_y = out_y; + } + b_y = a_y, d_y = c_y; + } + } + } + + if (transparent == 1) { + if (flag) { + for (i = 0; i < image_left_pos; i++) { + *pImage32++ = backGround[i] << 2; + } + for (i = 0; i < len; i++) { + val1 = buf[i] & (numcolors-1); + + if (val1 == transIndex) { + *pImage32++ = backGround[i+image_left_pos] << 2; + backGround[i+image_left_pos] = 0x1000000; + } else { + *pImage32++ = pDacbox[val1] << 2; + backGround[i+image_left_pos] = 0x1000000; + } + } + for (i = orgwdt+image_left_pos; i < logi_wdt; i++) { + *pImage32++ = backGround[i] << 2; + } + } else { + if (c_y < end) { + d1 = a_y - out_y; + d2 = c_y - out_y; + if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt; + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt; + + for (i = 0; i < image_left_pos; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt, c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt, d_x += logi_wdt; + } + out_x += decwdt; + } + + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + if (val1 == transIndex) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i+image_left_pos]; + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i+image_left_pos]; + a_x += logi_wdt, c_x += logi_wdt; + } else { + *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1]; + *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1]; + a_x += logi_wdt, c_x += logi_wdt; + } + } + if (0 <= d2 && d2 < decwdt) { + if (val1 == transIndex) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i+image_left_pos]; + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i+image_left_pos]; + b_x += logi_wdt, d_x += logi_wdt; + } else { + *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1]; + *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1]; + b_x += logi_wdt, d_x += logi_wdt; + } + } + backGround[i+image_left_pos] = 0x1000000; + out_x += decwdt; + } + + for (i = image_left_pos+orgwdt; i < logi_wdt; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt, c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt, d_x += logi_wdt; + } + out_x += decwdt; + } + + if (!interLaced) { + a_x = logi_wdt >> 2, a_y += logi_hgt; + b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt; + c_x = logi_wdt >> 2, c_y += logi_hgt; + d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt; + } + } else if (0 <= d1 && d1 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt; + for (i = 0; i < image_left_pos; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt; + } + out_x += decwdt; + } + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + if (val1 == transIndex) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i+image_left_pos]; + a_x += logi_wdt; + } else { + *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1]; + a_x += logi_wdt; + } + } + if (0 <= d2 && d2 < decwdt) { + if (val1 == transIndex) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i+image_left_pos]; + b_x += logi_wdt; + } else { + *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1]; + b_x += logi_wdt; + } + } + backGround[i+image_left_pos] = 0x1000000; + out_x += decwdt; + } + for (i = image_left_pos+orgwdt; i < logi_wdt; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt; + } + out_x += decwdt; + + } + if (!interLaced) { + a_x = logi_wdt >> 2, a_y += logi_hgt; + b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt; + } + } else if (0 <= d2 && d2 < dechgt) { + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt; + for (i = 0; i < image_left_pos; i++) { + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + d_x += logi_wdt; + } + out_x += decwdt; + } + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + if (val1 == transIndex) { + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i+image_left_pos]; + c_x += logi_wdt; + } else { + *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1]; + c_x += logi_wdt; + } + } + if (0 <= d2 && d2 < decwdt) { + if (val1 == transIndex) { + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i+image_left_pos]; + d_x += logi_wdt; + } else { + *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1]; + d_x += logi_wdt; + } + } + backGround[i+image_left_pos] = 0x1000000; + out_x += decwdt; + } + for (i = image_left_pos+orgwdt; i < logi_wdt; i++) { + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + d_x += logi_wdt; + } + out_x += decwdt; + } + if (!interLaced) { + c_x = logi_wdt >> 2, c_y += logi_hgt; + d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt; + } + } + } + } + } else { + if (flag) { + for (i = 0; i < image_left_pos; i++) { + *pImage32++ = backGround[i]<<2; + } + for (i = 0; i < len; i++) { + val1 = buf[i] & (numcolors-1); + *pImage32++ = pDacbox[val1] << 2; + backGround[i+image_left_pos] = backcolor888; + } + for (i = orgwdt+image_left_pos; i < logi_wdt; i++) { + *pImage32++ = backGround[i] << 2; + } + } else { + if (c_y < end) { + d1 = a_y - out_y; + d2 = c_y - out_y; + if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt; + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt; + for (i = 0; i < image_left_pos; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt, c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt, d_x += logi_wdt; + } + out_x += decwdt; + } + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1]; + *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1]; + a_x += logi_wdt, c_x += logi_wdt; + backGround[i+image_left_pos] = backcolor888; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1]; + *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1]; + b_x += logi_wdt, d_x += logi_wdt; + backGround[i+image_left_pos] = backcolor888; + } + out_x += decwdt; + } + for (i = image_left_pos+orgwdt; i < logi_wdt; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt, c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt, d_x += logi_wdt; + } + out_x += decwdt; + + } + if (!interLaced) { + a_x = logi_wdt >> 2, a_y += logi_hgt; + b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt; + c_x = logi_wdt >> 2, c_y += logi_hgt; + d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt; + } + } else if (0 <= d1 && d1 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt; + for (i = 0; i < image_left_pos; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt; + } + out_x += decwdt; + + } + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1]; + a_x += logi_wdt; + backGround[i+image_left_pos] = backcolor888; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1]; + b_x += logi_wdt; + backGround[i+image_left_pos] = backcolor888; + } + out_x += decwdt; + } + for (i = image_left_pos+orgwdt; i < logi_wdt; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt; + } + out_x += decwdt; + + } + if (!interLaced) { + a_x = logi_wdt >> 2, a_y += logi_hgt; + b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt; + } + } else if (0 <= d2 && d2 < dechgt) { + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt; + for (i = 0; i < image_left_pos; i++) { + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + d_x += logi_wdt; + } + out_x += decwdt; + } + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1]; + c_x += logi_wdt; + backGround[i+image_left_pos] = backcolor888; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1]; + d_x += logi_wdt; + backGround[i+image_left_pos] = backcolor888; + } + out_x += decwdt; + } + for (i = image_left_pos+orgwdt; i < logi_wdt; i++) { + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + d_x += logi_wdt; + } + out_x += decwdt; + } + if (!interLaced) { + c_x = logi_wdt >> 2, c_y += logi_hgt; + d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt; + } + } + } + } + } + + backGround += logi_wdt; + bufptr = buf; + bufcnt = orgwdt_1; + } + } + + if (rowcount == orghgt) { + break; + } + /* __get_next_code(pInputStream) */ + if (navail_bytes < 2) { + if (nbits_left == 0) + __get_next_code_first_nbits_left_0(pInputStream) + else + __get_next_code_first_nbits_left_not_0(pInputStream) + __get_next_code_first_while(pInputStream) + } else { + if (nbits_left == 0) + __get_next_code_second_nbits_left_0(pInputStream) + else + __get_next_code_second_nbits_left_not_0(pInputStream) + + __get_next_code_second_while(pInputStream) + } + if (c == ending) { + break; + } + + if (c == clear) { + curr_size = size + 1; + slot = newcodes; + top_slot = 1 << curr_size; + + do { + /* __get_next_code(pInputStream); */ + if (navail_bytes < 2) { + if (nbits_left == 0) + __get_next_code_first_nbits_left_0(pInputStream) + else + __get_next_code_first_nbits_left_not_0(pInputStream) + __get_next_code_first_while(pInputStream) + } else { + if (nbits_left == 0) + __get_next_code_second_nbits_left_0(pInputStream) + else + __get_next_code_second_nbits_left_not_0(pInputStream) + + __get_next_code_second_while(pInputStream) + } + } while (c == clear); + + if (c == ending) { + break; + } + + if (c >= slot) { + c = 0; + } + + oc = fc = c; + + *sp++ = (unsigned char)c; + } else { + code = c; + + if (code >= slot) { + code = oc; + *sp++ = (unsigned char)fc; + } + + while (code >= newcodes) { + *sp++ = suffix[code]; + code = prefix[code]; + } + + *sp++ = (unsigned char)code; + spCount++; + if (slot < top_slot) { + fc = code; + suffix[slot] = (unsigned char)fc; + prefix[slot++] = oc; + oc = c; + } + if (slot >= top_slot) { + if (curr_size < 12) { + top_slot <<= 1; + ++curr_size; + } + } + } + + } + + break; + + + /* No disposal specified. The decoder is not required to take any action */ + case 0: + + /* Do not dispose. The graphic is to be left in place. */ + case 1: + + default: + while (rowcount < orghgt) { + if ((sp - dstack) > 0) { + spCount = sp - dstack; + } + /* Now that we've pushed the decoded string (in reverse order) + * onto the stack, lets pop it off and put it into our decode + * buffer... And when the decode buffer is full, write another + * line... + */ + while (sp > dstack) { + --sp; + *bufptr++ = *sp; + + if (--bufcnt == 0) { + /********************************************************************************** + if ((ret = put_line(rowcount++, bufptr - buf, WDT, buf, pBitmapElem->pBits)) < 0) + **********************************************************************************/ + rowcount++; + len = bufptr - buf; + if (len >= orgwdt) { + len = orgwdt; + } + + if (interLaced == 0) { /* interlaced image */ + if (!flag) { + out_x = 0, out_y += dechgt; + } + } else { /* interlaced image */ + if (inter_step == 1) { + startloc += 8; + intercount++; + } else if (inter_step == 2) { + startloc += 8; + intercount++; + } else if (inter_step == 3) { + startloc += 4; + intercount++; + } else if (inter_step == 4) { + startloc += 2; + intercount++; + } + + if (startloc >= orghgt+image_top_pos) { + inter_step++; + if (inter_step == 2) { + startloc = 4+image_top_pos; + } else if (inter_step == 3) { + startloc = 2+image_top_pos; + } else if (inter_step == 4) { + startloc = 1+image_top_pos; + } + } + + backGround = (unsigned int *)(pFrameData->pPrevImg + ((startloc * logi_wdt) << 2)); + /* gif to rgb 565 */ + if (flag) { + pImage32 = (unsigned int *)(pDecBuf) + startloc * decwdt; + } else { + out_x = 0, out_y = startloc * dechgt; + a_x = logi_wdt >> 2; + b_x = ((logi_wdt*3) >> 2); + c_x = logi_wdt >> 2; + d_x = ((logi_wdt*3) >> 2); + if (out_y <= (logi_hgt >> 2)) { + a_y = logi_hgt >> 2; + b_y = logi_hgt >> 2; + c_y = ((logi_hgt*3) >> 2); + d_y = ((logi_hgt*3) >> 2); + } else { + if (((out_y%logi_hgt) - (logi_hgt >> 2)) > 0) { + a_y = ((out_y/logi_hgt)+1) * logi_hgt + (logi_hgt >> 2); + } else if (((out_y%logi_hgt) - (logi_hgt >> 2)) < 0 || !(out_y%logi_hgt)) { + a_y = ((out_y/logi_hgt)) * logi_hgt + (logi_hgt >> 2); + } else { + a_y = out_y; + } + + if (((out_y%logi_hgt) - ((logi_hgt*3) >> 2)) > 0) { + c_y = ((out_y/logi_hgt+1) * logi_hgt + ((logi_hgt*3) >> 2)); + } else if (((out_y%logi_hgt) - ((logi_hgt*3) >> 2)) < 0 || !(out_y%logi_hgt)) { + c_y = ((out_y/logi_hgt)) * logi_hgt + ((logi_hgt*3) >> 2); + } else { + c_y = out_y; + } + b_y = a_y, d_y = c_y; + } + } + } + + if (transparent == 1) { + if (flag) { + for (i = 0; i < image_left_pos; i++) { + *pImage32++ = backGround[i] << 2; + } + for (i = 0; i < len; i++) { + val1 = buf[i] & (numcolors-1); + + if (val1 == transIndex) { + *pImage32++ = backGround[i+image_left_pos] << 2; /* Set *pImage32 MSB 1 */ + } else { + *pImage32++ = pDacbox[val1] << 2; + backGround[i+image_left_pos] = pDacbox[val1]; + } + } + for (i = orgwdt+image_left_pos; i < logi_wdt; i++) { + *pImage32++ = backGround[i] << 2; + } + } else { + if (c_y < end) { + d1 = a_y - out_y; + d2 = c_y - out_y; + if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt; + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt; + + for (i = 0; i < image_left_pos; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt, c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt, d_x += logi_wdt; + } + out_x += decwdt; + } + + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + if (val1 == transIndex) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i+image_left_pos]; + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i+image_left_pos]; + a_x += logi_wdt, c_x += logi_wdt; + } else { + *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1]; + *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1]; + a_x += logi_wdt, c_x += logi_wdt; + backGround[i+image_left_pos] = pDacbox[val1]; + } + } + if (0 <= d2 && d2 < decwdt) { + if (val1 == transIndex) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i+image_left_pos]; + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i+image_left_pos]; + b_x += logi_wdt, d_x += logi_wdt; + } else { + *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1]; + *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1]; + b_x += logi_wdt, d_x += logi_wdt; + backGround[i+image_left_pos] = pDacbox[val1]; + } + } + out_x += decwdt; + } + + for (i = image_left_pos+orgwdt; i < logi_wdt; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt, c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt, d_x += logi_wdt; + } + out_x += decwdt; + } + + if (!interLaced) { + a_x = logi_wdt >> 2, a_y += logi_hgt; + b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt; + c_x = logi_wdt >> 2, c_y += logi_hgt; + d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt; + } + } else if (0 <= d1 && d1 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt; + for (i = 0; i < image_left_pos; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt; + } + out_x += decwdt; + } + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + if (val1 == transIndex) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i+image_left_pos]; + a_x += logi_wdt; + } else { + *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1]; + a_x += logi_wdt; + backGround[i+image_left_pos] = pDacbox[val1]; + } + } + if (0 <= d2 && d2 < decwdt) { + if (val1 == transIndex) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i+image_left_pos]; + b_x += logi_wdt; + } else { + *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1]; + b_x += logi_wdt; + backGround[i+image_left_pos] = pDacbox[val1]; + } + } + out_x += decwdt; + } + for (i = image_left_pos+orgwdt; i < logi_wdt; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt; + } + out_x += decwdt; + + } + if (!interLaced) { + a_x = logi_wdt >> 2, a_y += logi_hgt; + b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt; + } + } else if (0 <= d2 && d2 < dechgt) { + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt; + for (i = 0; i < image_left_pos; i++) { + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + d_x += logi_wdt; + } + out_x += decwdt; + } + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + if (val1 == transIndex) { + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i+image_left_pos]; + c_x += logi_wdt; + } else { + *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1]; + c_x += logi_wdt; + backGround[i+image_left_pos] = pDacbox[val1]; + } + } + if (0 <= d2 && d2 < decwdt) { + if (val1 == transIndex) { + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i+image_left_pos]; + d_x += logi_wdt; + } else { + *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1]; + d_x += logi_wdt; + backGround[i+image_left_pos] = pDacbox[val1]; + } + } + out_x += decwdt; + } + for (i = image_left_pos+orgwdt; i < logi_wdt; i++) { + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + d_x += logi_wdt; + } + out_x += decwdt; + } + if (!interLaced) { + c_x = logi_wdt >> 2, c_y += logi_hgt; + d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt; + } + } + } + } + } else { + if (flag) { + for (i = 0; i < image_left_pos; i++) { + *pImage32++ = backGround[i] << 2; + } + for (i = 0; i < len; i++) { + val1 = buf[i] & (numcolors-1); + *pImage32++ = pDacbox[val1] << 2; + backGround[i+image_left_pos] = pDacbox[val1]; + } + for (i = orgwdt+image_left_pos; i < logi_wdt; i++) { + *pImage32++ = backGround[i] << 2; + } + } else { + if (c_y < end) { + d1 = a_y - out_y; + d2 = c_y - out_y; + if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt; + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt; + for (i = 0; i < image_left_pos; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt, c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt, d_x += logi_wdt; + } + out_x += decwdt; + + } + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1]; + *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1]; + a_x += logi_wdt, c_x += logi_wdt; + backGround[i+image_left_pos] = pDacbox[val1]; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1]; + *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1]; + b_x += logi_wdt, d_x += logi_wdt; + backGround[i+image_left_pos] = pDacbox[val1]; + } + out_x += decwdt; + } + for (i = image_left_pos+orgwdt; i < logi_wdt; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt, c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt, d_x += logi_wdt; + } + out_x += decwdt; + + } + if (!interLaced) { + a_x = logi_wdt >> 2, a_y += logi_hgt; + b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt; + c_x = logi_wdt >> 2, c_y += logi_hgt; + d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt; + } + } else if (0 <= d1 && d1 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt; + for (i = 0; i < image_left_pos; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt; + } + out_x += decwdt; + + } + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1]; + a_x += logi_wdt; + backGround[i+image_left_pos] = pDacbox[val1]; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1]; + b_x += logi_wdt; + backGround[i+image_left_pos] = pDacbox[val1]; + } + out_x += decwdt; + } + for (i = image_left_pos+orgwdt; i < logi_wdt; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt; + } + out_x += decwdt; + } + if (!interLaced) { + a_x = logi_wdt >> 2, a_y += logi_hgt; + b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt; + } + } else if (0 <= d2 && d2 < dechgt) { + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt; + for (i = 0; i < image_left_pos; i++) { + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + d_x += logi_wdt; + } + out_x += decwdt; + } + for (i = 0; i < orgwdt; i++) { + val1 = buf[i] & (numcolors-1); + + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1]; + c_x += logi_wdt; + backGround[i+image_left_pos] = pDacbox[val1]; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1]; + d_x += logi_wdt; + backGround[i+image_left_pos] = pDacbox[val1]; + } + out_x += decwdt; + } + for (i = image_left_pos+orgwdt; i < logi_wdt; i++) { + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + d_x += logi_wdt; + } + out_x += decwdt; + + } + if (!interLaced) { + c_x = logi_wdt >> 2, c_y += logi_hgt; + d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt; + } + } + } + } + } + + backGround += logi_wdt; + bufptr = buf; + bufcnt = orgwdt_1; + } + } + if (rowcount == orghgt) { + break; + } + /* __get_next_code(pInputStream) */ + if (navail_bytes < 2) { + if (nbits_left == 0) + __get_next_code_first_nbits_left_0(pInputStream) + else + __get_next_code_first_nbits_left_not_0(pInputStream) + __get_next_code_first_while(pInputStream) + } else { + if (nbits_left == 0) + __get_next_code_second_nbits_left_0(pInputStream) + else + __get_next_code_second_nbits_left_not_0(pInputStream) + + __get_next_code_second_while(pInputStream) + } + if (c == ending) { + break; + } + + if (c == clear) { + curr_size = size + 1; + slot = newcodes; + top_slot = 1 << curr_size; + + do { + /* __get_next_code(pInputStream); */ + if (navail_bytes < 2) { + if (nbits_left == 0) + __get_next_code_first_nbits_left_0(pInputStream) + else + __get_next_code_first_nbits_left_not_0(pInputStream) + __get_next_code_first_while(pInputStream) + } else { + if (nbits_left == 0) + __get_next_code_second_nbits_left_0(pInputStream) + else + __get_next_code_second_nbits_left_not_0(pInputStream) + + __get_next_code_second_while(pInputStream) + } + } while (c == clear); + + if (c == ending) { + break; + } + + if (c >= slot) { + c = 0; + } + + oc = fc = c; + + *sp++ = (unsigned char)c; + } else { + code = c; + + if (code >= slot) { + code = oc; + *sp++ = (unsigned char)fc; + } + + while (code >= newcodes) { + *sp++ = suffix[code]; + code = prefix[code]; + } + + *sp++ = (unsigned char)code; + spCount++; + if (slot < top_slot) { + fc = code; + suffix[slot] = (unsigned char)fc; + prefix[slot++] = oc; + oc = c; + } + if (slot >= top_slot) { + if (curr_size < 12) { + top_slot <<= 1; + ++curr_size; + } + } + } + } + + break; + } + + if (interLaced) { + startloc = orghgt+image_top_pos; + pImage32 = (unsigned int *)(pDecBuf) + startloc * decwdt; + if (!flag) { + out_x = 0, out_y = startloc * dechgt; + a_x = logi_wdt >> 2; + b_x = ((logi_wdt*3) >> 2); + c_x = logi_wdt >> 2; + d_x = ((logi_wdt*3) >> 2); + if (out_y <= (logi_hgt >> 2)) { + a_y = logi_hgt >> 2; + b_y = logi_hgt >> 2; + c_y = ((logi_hgt*3) >> 2); + d_y = ((logi_hgt*3) >> 2); + } else { + if (((out_y%logi_hgt) - (logi_hgt >> 2)) > 0) { + a_y = ((out_y/logi_hgt)+1) * logi_hgt + (logi_hgt >> 2); + } else if (((out_y%logi_hgt) - (logi_hgt >> 2)) < 0 || !(out_y%logi_hgt)) { + a_y = ((out_y/logi_hgt)) * logi_hgt + (logi_hgt >> 2); + } else { + a_y = out_y; + } + + if (((out_y%logi_hgt) - ((logi_hgt*3) >> 2)) > 0) { + c_y = ((out_y/logi_hgt+1) * logi_hgt + ((logi_hgt*3) >> 2)); + } else if (((out_y%logi_hgt) - ((logi_hgt*3) >> 2)) < 0 || !(out_y%logi_hgt)) { + c_y = ((out_y/logi_hgt)) * logi_hgt + ((logi_hgt*3) >> 2); + } else { + c_y = out_y; + } + b_y = a_y, d_y = c_y; + } + } + out_y -= dechgt; + } + + backGround = (unsigned int *)(pFrameData->pPrevImg + (((image_top_pos+orghgt) * logi_wdt) << 2)); + for (rowcount = image_top_pos+orghgt; rowcount < logi_hgt; rowcount++) { + if (flag) { + for (i = 0; i < logi_wdt; i++) { + *pImage32++ = backGround[i] << 2; + } + } else { + out_x = 0, out_y += dechgt; + if (c_y < end) { + d1 = a_y - out_y; + d2 = c_y - out_y; + if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt; + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt; + for (i = 0; i < logi_wdt; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt, c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt, d_x += logi_wdt; + } + out_x += decwdt; + } + a_x = logi_wdt >> 2, a_y += logi_hgt; + b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt; + c_x = logi_wdt >> 2, c_y += logi_hgt; + d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt; + } else if (0 <= d1 && d1 < dechgt) { + pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt; + for (i = 0; i < logi_wdt; i++) { + d1 = a_x - out_x; + d2 = b_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32 + (a_x/logi_wdt)) += backGround[i]; + a_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32 + (b_x/logi_wdt)) += backGround[i]; + b_x += logi_wdt; + } + out_x += decwdt; + } + a_x = logi_wdt >> 2, a_y += logi_hgt; + b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt; + } else if (0 <= d2 && d2 < dechgt) { + pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt; + for (i = 0; i < logi_wdt; i++) { + d1 = c_x - out_x; + d2 = d_x - out_x; + if (0 <= d1 && d1 < decwdt) { + *(pImage32_2 + (c_x/logi_wdt)) += backGround[i]; + c_x += logi_wdt; + } + if (0 <= d2 && d2 < decwdt) { + *(pImage32_2 + (d_x/logi_wdt)) += backGround[i]; + d_x += logi_wdt; + } + out_x += decwdt; + } + c_x = logi_wdt >> 2, c_y += logi_hgt; + d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt; + } + } + } + backGround += logi_wdt; + } + + + if (bCenterAlign) { + margin_wdt1_2 = (expected_width - resized_width) >> 1; + margin_hgt1_2 = (expected_height - resized_height) >> 1; + } else { + margin_wdt1_2 = 0; + margin_hgt1_2 = 0; + } + + + /* 565 Conversion */ + pImage32 = (unsigned int *)(pDecBuf); + + for (i = 0, k = margin_hgt1_2; i < dechgt; i++) { + pImage16 = (unsigned short *)((unsigned char *)pOutBits + ((margin_wdt1_2 + (expected_width) * k) << 1)); + for (j = 0; j < decwdt; j++) { + if ((*pImage32>>24) == 0) { + *(pImage16++) = ((*pImage32 & 0xf80000) >> 8) | ((*pImage32 & 0xfc00) >> 5) | ((*pImage32 & 0xf8) >> 3); + } else if ((*pImage32 >> 24) == 1) { + *(pImage16++) = (((*pImage32 & 0xf80000) >> 6) / 3) | (((*pImage32 & 0xfc00) >> 3)/3) | (((*pImage32 & 0xf8) >> 1)/3); + } else if ((*pImage32 >> 24) == 2) { + *(pImage16++) = ((*pImage32 & 0xf80000) >> 7) | ((*pImage32 & 0xfc00) >> 4) | ((*pImage32 & 0xf8) >> 2); + } else { + *(pImage16++) = ui_backcolor565; + } + pImage32++; + } + k++; + } + + if (decoderline) { + IfegMemFree(decoderline); + decoderline = 0; + } + if (pDecBuf) { + IfegMemFree(pDecBuf); + pDecBuf = 0; + } + + pFrameData->offset = inputPos; + pFrameData->imgCount++; + + return 1; + + break; + + default: + break; + + } + } +} diff --git a/src/codec/img-codec-osal.c b/src/codec/img-codec-osal.c new file mode 100644 index 0000000..46eb130 --- /dev/null +++ b/src/codec/img-codec-osal.c @@ -0,0 +1,166 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 "media-thumb-debug.h" +#include "img-codec-osal.h" +#include +#include +#include + +//#include +#include + +void *IfegMemAlloc(unsigned int size) +{ + void *pmem; + pmem = malloc(size); + return pmem; +} + +void IfegMemFree(void *pMem) +{ + free(pMem); + pMem = 0; +} + +void *IfegMemcpy(void *dest, const void *src, unsigned int count) +{ + return memcpy(dest, src, count); +} + +void *IfegMemset(void *dest, int c, unsigned int count) +{ + return memset(dest, c, count); +} + +ULONG IfegGetAvailableMemSize(void) +{ + return 1; +} + +int IfegMemcmp(const void *pMem1, const void *pMem2, size_t length) +{ + return memcmp(pMem1, pMem2, length); +} + +static BOOL _is_real_drm = FALSE; + +HFile DrmOpenFile(const char *szPathName) +{ + int ret = 0; + drm_bool_type_e drm_type; + + ret = drm_is_drm_file(szPathName, &drm_type); + if (ret < 0) { + thumb_err("drm_is_drm_file falied : %d", ret); + drm_type = DRM_FALSE; + } + + if (drm_type == DRM_TRUE) { + _is_real_drm = TRUE; + } else { + _is_real_drm = FALSE; + } + + if (!_is_real_drm) { + FILE *fp = fopen(szPathName, "rb"); + + if (fp == NULL) { + return (HFile) INVALID_HOBJ; + thumb_err("file open error: %s", szPathName); + } + + return fp; + + } else { + return (HFile) INVALID_HOBJ; + } +} + +BOOL DrmReadFile(HFile hFile, void *pBuffer, ULONG bufLen, ULONG * pReadLen) +{ + size_t readCnt = -1; + + if (!_is_real_drm) { + readCnt = fread(pBuffer, sizeof(char), bufLen, hFile); + *pReadLen = (ULONG) readCnt; + } else { + return FALSE; + } + return TRUE; +} + +long DrmTellFile(HFile hFile) +{ + if (!_is_real_drm) { + return ftell(hFile); + } else { + return -1; + } +} + +BOOL DrmSeekFile(HFile hFile, long position, long offset) +{ + int ret = 0; + + if (position < 0) { + return FALSE; + } + if (!_is_real_drm) { + ret = fseek(hFile, offset, position); + if (ret < 0) { + thumb_err("fseek failed : %s", strerror(errno)); + return FALSE; + } + } else { + return FALSE; + } + + return TRUE; +} + +BOOL DrmGetFileAttributes(const char *szPathName, FmFileAttribute * pFileAttr) +{ + FILE *f = NULL; + + f = fopen(szPathName, "r"); + + if (f == NULL) { + return FALSE; + } + + fseek(f, 0, SEEK_END); + pFileAttr->fileSize = ftell(f); + fclose(f); + + return TRUE; +} + +BOOL DrmCloseFile(HFile hFile) +{ + if (!_is_real_drm) { + fclose(hFile); + } else { + return FALSE; + } + + return TRUE; +} diff --git a/src/codec/img-codec-parser.c b/src/codec/img-codec-parser.c new file mode 100644 index 0000000..26027b9 --- /dev/null +++ b/src/codec/img-codec-parser.c @@ -0,0 +1,887 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#if defined(_PERFORMANCE_CHECK_) +#include +#include +#endif + +#include "media-thumb-debug.h" +#include "img-codec-common.h" +#include "img-codec-parser.h" + +#define FILE_READ_SIZE 4096 +typedef struct _stream { + HFile fd; + unsigned int buffpos; + unsigned int filepos; + unsigned int filesize; + unsigned int buffend; + unsigned int debugpos; + unsigned char *buffer; +} IFEGSTREAMCTRL; + +ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize, + ImgImageInfo *imgInfo); +BOOL process_EXIF(unsigned char *ExifSection, unsigned int length, + unsigned int *pOrientataion); + +ImgCodecType ImgGetInfoHFile(HFile hFile, unsigned long fileSize, + ImgImageInfo *imgInfo) +{ + ImgCodecType result = 0; + SysAssert(hFile); + SysAssert(fileSize); + + if (imgInfo == NULL) { + result = _ImgGetInfoStreaming(hFile, fileSize, NULL); + } else { + result = _ImgGetInfoStreaming(hFile, fileSize, imgInfo); + } + + DrmSeekFile(hFile, SEEK_SET, 0); + + return result; + +} + +ImgCodecType ImgGetInfoFile(const char *filePath, ImgImageInfo * imgInfo) +{ + HFile hFile; + FmFileAttribute fileAttrib; + ImgCodecType result; + SysAssert(filePath); + hFile = DrmOpenFile(filePath); + + if (hFile == (HFile) INVALID_HOBJ) { + return IMG_CODEC_NONE; + } + DrmGetFileAttributes(filePath, &fileAttrib); + + if ((fileAttrib.fileSize == 0)) { + DrmCloseFile(hFile); + return IMG_CODEC_NONE; + } + + result = ImgGetInfoHFile(hFile, fileAttrib.fileSize, imgInfo); + + DrmCloseFile(hFile); + + return result; + +} + +static unsigned char gIfegPNGHeader[] = { + 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a }; +static unsigned char gIfegJPEGHeader[] = { 0xFF, 0xD8 }; +static unsigned char gIfegGIFHeader[] = { "GIF" }; +static unsigned char gIfegBMPHeader[] = { 0x42, 0x4D }; + +static int _CheckBuffer(IFEGSTREAMCTRL *pIfegstreamctrl, unsigned int size) +{ + unsigned long fileread; + + if ((size + pIfegstreamctrl->buffpos) > pIfegstreamctrl->buffend) { + if (pIfegstreamctrl->filepos == pIfegstreamctrl->filesize) { + return 0; + } + + if (pIfegstreamctrl->buffpos == 0) { + if (DrmReadFile + (pIfegstreamctrl->fd, pIfegstreamctrl->buffer, + FILE_READ_SIZE, &fileread) == FALSE) { + return 0; + } + if (fileread == 0) { + return 0; + } + pIfegstreamctrl->buffend = fileread; + pIfegstreamctrl->filepos += fileread; + pIfegstreamctrl->buffpos = 0; + } else { + + if (size >= 2048 + || pIfegstreamctrl->buffend - + pIfegstreamctrl->buffpos > FILE_READ_SIZE) { + return 0; + } + AcMemcpy(pIfegstreamctrl->buffer, + &pIfegstreamctrl->buffer[pIfegstreamctrl-> + buffpos], + pIfegstreamctrl->buffend - + pIfegstreamctrl->buffpos); + if (DrmReadFile + (pIfegstreamctrl->fd, + &pIfegstreamctrl->buffer[pIfegstreamctrl->buffend - + pIfegstreamctrl->buffpos], + pIfegstreamctrl->buffpos, &fileread) == FALSE) { + return 0; + } + if (fileread == 0) { + return 0; + } + pIfegstreamctrl->buffend = + pIfegstreamctrl->buffend - + pIfegstreamctrl->buffpos + fileread; + pIfegstreamctrl->buffpos = 0; + pIfegstreamctrl->filepos += fileread; + } + return 1; + } + return 2; +} + +static unsigned int _IfegReadUINT(unsigned char *pBuffer) +{ + return (((*pBuffer) << 24) | ((*(pBuffer + 1)) << 16) | + ((*(pBuffer + 2)) << 8) | (*(pBuffer + 3))); +} + +ImgCodecType ImgGetInfo(unsigned char *pEncodedData, unsigned long fileSize, + ImgImageInfo *imgInfo) +{ + unsigned int width = 0, height = 0; + + /* Initialize values */ + if (imgInfo) { + imgInfo->width = 0; + imgInfo->height = 0; + imgInfo->numberOfFrame = 1; + imgInfo->bOrientation = 0; + } + + SysAssert(pEncodedData); + SysAssert(fileSize); + + /*********************** PNG *************************/ + if (AcMemcmp(pEncodedData, gIfegPNGHeader, PNG_HEADER_LENGTH) == 0) { + unsigned char tmp; + + if (fileSize < 40) { + thumb_warn("IMG_CODEC_UNKNOWN_TYPE in PNG"); + return IMG_CODEC_UNKNOWN_TYPE; + } + /* Get Image Width */ + width = _IfegReadUINT((pEncodedData + 16)); + + /* Get Image Height */ + height = _IfegReadUINT((pEncodedData + 20)); + + /* Read Interlace byte */ + tmp = *(pEncodedData + 28); + /* If image is interlaced then multiple should be 2 */ + if (tmp) { + thumb_dbg("Interlaced PNG Image."); + } + + thumb_dbg("type: IMG_CODEC_PNG"); + + if (imgInfo) { + imgInfo->width = width; + imgInfo->height = height; + } + return IMG_CODEC_PNG; + } + /*********************** BMP *************************/ + else if (AcMemcmp(pEncodedData, gIfegBMPHeader, BMP_HEADER_LENGTH) == 0) { + /* Parse BMP File and get image width and image height */ + if (fileSize < 26) { + thumb_warn("IMG_CODEC_UNKNOWN_TYPE in BMP"); + return IMG_CODEC_UNKNOWN_TYPE; + } + if (imgInfo) { + imgInfo->width = + pEncodedData[18] | (pEncodedData[19] << 8) | + (pEncodedData[20] << 16) | (pEncodedData[21] << 24); + imgInfo->height = + pEncodedData[22] | (pEncodedData[23] << 8) | + (pEncodedData[24] << 16) | (pEncodedData[25] << 24); + } + + thumb_dbg("type : IMG_CODEC_BMP"); + return IMG_CODEC_BMP; + + } + /*********************** GIF *************************/ + else if (AcMemcmp(pEncodedData, gIfegGIFHeader, GIF_HEADER_LENGTH) == 0) { + int length; + int inputPos = 0; + int temp; + int finished; + int imagecount = 0; + + if ((unsigned int)inputPos + 13 > fileSize) { + thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF"); + return IMG_CODEC_UNKNOWN_TYPE; + } + + if (pEncodedData[0] != 'G' || pEncodedData[1] != 'I' + || pEncodedData[2] != 'F' || pEncodedData[3] < '0' + || pEncodedData[3] > '9' || pEncodedData[4] < '0' + || pEncodedData[4] > '9' || pEncodedData[5] < 'A' + || pEncodedData[5] > 'z') { + thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF"); + return IMG_CODEC_UNKNOWN_TYPE; + } + /* get Logical width, height */ + if (imgInfo) { + imgInfo->width = + pEncodedData[6] | (pEncodedData[7] << 8); + imgInfo->height = + pEncodedData[8] | (pEncodedData[9] << 8); + } + + if ((pEncodedData[10] & 0x80) != 0) /* Global color table */ { + temp = (pEncodedData[10] & 0x7) + 1; + length = (1 << temp) * 3; + inputPos += length; + if ((unsigned int)inputPos > fileSize) { + thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF"); + return IMG_CODEC_UNKNOWN_TYPE; + } + } + + inputPos += 13; + finished = 0; + + /* still gif image (image_cnt = 1) */ + while (!finished) { + if ((unsigned int)inputPos > fileSize) + break; + + switch (pEncodedData[inputPos++]) { + case 0x3b: /* End of the GIF dataset */ + finished = 1; + break; + + case 0x21: /* Extension Block */ + switch (pEncodedData[inputPos++]) { + case 0xf9: /* Graphic control extension block */ + if (4 != pEncodedData[inputPos++]) { /* data length : fixed 4 bytes */ + thumb_warn + ("IMG_CODEC_UNKNOWN_TYPE in GIF"); + return IMG_CODEC_UNKNOWN_TYPE; + } + inputPos += 4; + inputPos++; /* block end */ + break; + + case 0x01: /* Plain Text block */ + case 0xfe: /* Comment Extension block */ + case 0xff: /* Appliation Extension block */ + while ((length = pEncodedData[inputPos++]) > 0) { /* get the data length */ + inputPos += (length); + if ((unsigned int)inputPos > + fileSize) { + thumb_warn + ("IMG_CODEC_UNKNOWN_TYPE in GIF"); + return + IMG_CODEC_UNKNOWN_TYPE; + } + } + break; + + default: + break; + } + + break; + + case 0x2c: /* Start of an image object. Read the image description. */ + + if ((unsigned int)inputPos + 9 > fileSize) { + thumb_warn + ("IMG_CODEC_UNKNOWN_TYPE in GIF"); + return IMG_CODEC_UNKNOWN_TYPE; + } + /* Color Resolution */ + if ((pEncodedData[inputPos + 8] & 0x80) != 0) { /* Logical color table */ + temp = + (pEncodedData[inputPos + 8] & 0x7) + + 1; + length = (1 << temp) * 3; + inputPos += length; + if ((unsigned int)inputPos > fileSize) { + thumb_warn + ("IMG_CODEC_UNKNOWN_TYPE in GIF"); + return IMG_CODEC_UNKNOWN_TYPE; + } + } + + inputPos += 9; + + temp = pEncodedData[inputPos++]; + if (temp < 2 || 9 < temp) { + thumb_warn + ("IMG_CODEC_UNKNOWN_TYPE in GIF"); + return IMG_CODEC_UNKNOWN_TYPE; + } + + do { + length = pEncodedData[inputPos++]; + inputPos += length; + if ((unsigned int)inputPos > fileSize) { + thumb_warn + ("IMG_CODEC_UNKNOWN_TYPE in GIF"); + return IMG_CODEC_UNKNOWN_TYPE; + } + } while (length); + + if (!imagecount) + imagecount++; + else { + if (imgInfo) + imgInfo->numberOfFrame = 2; + return IMG_CODEC_AGIF; + } + break; + + default: + finished = 0; + break; + + } /* end of switch (pEncodedData[inputPos++]) */ + } /* end of while (pImage->bitmapCount > image_cnt && !finished) */ + + return IMG_CODEC_GIF; + } + + thumb_warn("IMG_CODEC_UNKNOWN_TYPE"); + return IMG_CODEC_UNKNOWN_TYPE; +} + +ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize, + ImgImageInfo *imgInfo) +{ + unsigned int fileleft; + unsigned long fileread; + unsigned char EncodedDataBuffer[4096]; + + unsigned int *pNumberOfFrames = NULL; + unsigned int *pWidth = NULL; + unsigned int *pHeight = NULL; + unsigned int *pOrientation = NULL; + + if (imgInfo == NULL) { + pNumberOfFrames = NULL; + pWidth = NULL; + pHeight = NULL; + pOrientation = NULL; + } else { + pWidth = &(imgInfo->width); + pHeight = &(imgInfo->height); + pOrientation = &(imgInfo->bOrientation); + pNumberOfFrames = &(imgInfo->numberOfFrame); + + *pWidth = 0; + *pHeight = 0; + *pOrientation = 0; + } + + AcMemset(EncodedDataBuffer, 0, 4096); + + /* Initialize values */ + if (pNumberOfFrames) { + *pNumberOfFrames = 1; + } + + SysAssert((const char *)&fileSize); + + if (DrmReadFile(hFile, EncodedDataBuffer, 8, &fileread) == FALSE) { + thumb_err("DrmReadFile was failed"); + return IMG_CODEC_NONE; + } + + if (fileread < MINIMUM_HEADER_BYTES) { + thumb_warn("IMG_CODEC_UNKNOWN_TYPE"); + return IMG_CODEC_UNKNOWN_TYPE; + } + /*********************** PNG *************************/ + if (AcMemcmp(EncodedDataBuffer, gIfegPNGHeader, PNG_HEADER_LENGTH) == 0) { + unsigned char tmp; + + if (DrmReadFile(hFile, EncodedDataBuffer, 32, &fileread) == + FALSE) { + thumb_err("DrmReadFile was failed"); + return IMG_CODEC_NONE; + } + if (fileread < 32) { + thumb_warn("IMG_CODEC_UNKNOWN_TYPE in PNG"); + return IMG_CODEC_UNKNOWN_TYPE; + } + /* Get Image Width */ + if (pWidth) { + *pWidth = _IfegReadUINT((EncodedDataBuffer + 8)); + } + + /* Get Image Height */ + if (pHeight) { + *pHeight = _IfegReadUINT((EncodedDataBuffer + 12)); + } + + /* Read Interlace byte */ + tmp = *(EncodedDataBuffer + 20); + /* If image is interlaced then multiple should be 2 */ + if (tmp) { + thumb_dbg("Interlaced PNG Image.\n"); + } + thumb_dbg("IMG_CODEC_PNG\n"); + return IMG_CODEC_PNG; + } + /*********************** BMP *************************/ + else if (AcMemcmp(EncodedDataBuffer, gIfegBMPHeader, BMP_HEADER_LENGTH) + == 0) { + /* Parse BMP File and get image width and image height */ + if (DrmReadFile(hFile, &EncodedDataBuffer[8], 18, &fileread) == + FALSE) { + thumb_err("DrmReadFile was failed"); + return IMG_CODEC_NONE; + } + if (fileread < 18) { + thumb_warn("IMG_CODEC_UNKNOWN_TYPE in BMP"); + return IMG_CODEC_UNKNOWN_TYPE; + } + if (pWidth == NULL || pHeight == NULL + || pNumberOfFrames == NULL) { + return IMG_CODEC_BMP; + } + if (pWidth) { + *pWidth = + EncodedDataBuffer[18] | (EncodedDataBuffer[19] << 8) + | (EncodedDataBuffer[20] << 16) | + (EncodedDataBuffer[21] << 24); + } + if (pHeight) { + *pHeight = + EncodedDataBuffer[22] | (EncodedDataBuffer[23] << 8) + | (EncodedDataBuffer[24] << 16) | + (EncodedDataBuffer[25] << 24); + } + + thumb_dbg("IMG_CODEC_BMP"); + return IMG_CODEC_BMP; + } + /*********************** GIF *************************/ + else if (AcMemcmp(EncodedDataBuffer, gIfegGIFHeader, GIF_HEADER_LENGTH) + == 0) { + unsigned int tablelength = 0; + unsigned int imagecount = 0; + int finished = 0; + unsigned char temp; + unsigned int length; + IFEGSTREAMCTRL ifegstreamctrl; + + if (13 > fileSize) { + thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF"); + return IMG_CODEC_UNKNOWN_TYPE; + } + + if (DrmReadFile(hFile, &EncodedDataBuffer[8], 5, &fileread) == + FALSE) { + thumb_err("DrmReadFile was failed"); + + return IMG_CODEC_NONE; + } + if (fileread < 5) { + thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF"); + return IMG_CODEC_UNKNOWN_TYPE; + } + + if (EncodedDataBuffer[0] != 'G' || EncodedDataBuffer[1] != 'I' + || EncodedDataBuffer[2] != 'F' || EncodedDataBuffer[3] < '0' + || EncodedDataBuffer[3] > '9' || EncodedDataBuffer[4] < '0' + || EncodedDataBuffer[4] > '9' || EncodedDataBuffer[5] < 'A' + || EncodedDataBuffer[5] > 'z') { + thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF"); + return IMG_CODEC_UNKNOWN_TYPE; + } + + if (!(pWidth && pHeight)) { + return IMG_CODEC_UNKNOWN_TYPE; + } else { + *pWidth = + EncodedDataBuffer[6] | (EncodedDataBuffer[7] << 8); + *pHeight = + EncodedDataBuffer[8] | (EncodedDataBuffer[9] << 8); + } + + thumb_dbg("Logical width : %d, Height : %d", *pWidth, + *pHeight); + + if ((EncodedDataBuffer[10] & 0x80) != 0) { /* Global color table */ + temp = (EncodedDataBuffer[10] & 0x7) + 1; + tablelength = (1 << temp) * 3; + + if ((tablelength * sizeof(char)) > + sizeof(EncodedDataBuffer)) { + thumb_warn + ("_ImgGetInfoStreaming :table length is more than buffer length"); + return IMG_CODEC_UNKNOWN_TYPE; + } + + if (13 + tablelength > fileSize) { + thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF"); + return IMG_CODEC_UNKNOWN_TYPE; + } + /* coverity[ -tainted_data_argument : EncodedDataBuffer ] */ + if (DrmReadFile + (hFile, EncodedDataBuffer, tablelength, + &fileread) == FALSE) { + thumb_err("DrmReadFile was failed"); + + return IMG_CODEC_NONE; + } + if (fileread < tablelength) { + thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF"); + return IMG_CODEC_UNKNOWN_TYPE; + } + } + + fileleft = fileSize - 13 - tablelength; + + ifegstreamctrl.fd = hFile; + ifegstreamctrl.filesize = fileleft; + ifegstreamctrl.filepos = 0; + ifegstreamctrl.buffpos = 0; + ifegstreamctrl.buffend = 0; + ifegstreamctrl.buffer = EncodedDataBuffer; + + while (!finished) { + if (ifegstreamctrl.buffpos > ifegstreamctrl.buffend) + break; + if (_CheckBuffer(&ifegstreamctrl, 1) == 0) { + thumb_warn("_CheckBuffer was failed"); + return IMG_CODEC_UNKNOWN_TYPE; + } + + switch (EncodedDataBuffer[ifegstreamctrl.buffpos++]) { + + case 0x3b: /* End of the GIF dataset */ + finished = 1; + break; + + case 0x21: /* Extension Block */ + if (_CheckBuffer(&ifegstreamctrl, 1) == 0) { + thumb_warn("_CheckBuffer was failed"); + return IMG_CODEC_UNKNOWN_TYPE; + } + + switch (EncodedDataBuffer + [ifegstreamctrl.buffpos++]) { + + case 0xf9: /* Graphic control extension block */ + if (_CheckBuffer(&ifegstreamctrl, 6) == + 0) { + thumb_warn + ("_CheckBuffer was failed"); + return IMG_CODEC_UNKNOWN_TYPE; + } + + if (4 != EncodedDataBuffer[ifegstreamctrl.buffpos++]) { /* data length : fixed 4 bytes */ + return 0; + } + ifegstreamctrl.buffpos += 4; + ifegstreamctrl.buffpos++; /* block end */ + break; + + case 0x01: /* Plain Text block */ + case 0xfe: /* Comment Extension block */ + case 0xff: /* Appliation Extension block */ + if (_CheckBuffer(&ifegstreamctrl, 1) == + 0) { + thumb_warn + ("_CheckBuffer was failed"); + return IMG_CODEC_UNKNOWN_TYPE; + } + + if (ifegstreamctrl.buffpos > + sizeof(EncodedDataBuffer)) { + thumb_warn + ("buffer position exceeds buffer max length "); + return IMG_CODEC_UNKNOWN_TYPE; + } + + while ((ifegstreamctrl.buffpos < sizeof(EncodedDataBuffer)) && ((length = EncodedDataBuffer[ifegstreamctrl.buffpos++]) > 0)) { /* get the data length */ + if (_CheckBuffer + (&ifegstreamctrl, + length) == 0) { + thumb_warn + ("_CheckBuffer was failed"); + return + IMG_CODEC_UNKNOWN_TYPE; + } + + /* Check integer overflow */ + if (ifegstreamctrl.buffpos > 0xffffffff - length) { + thumb_err("Prevent integer overflow.."); + return IMG_CODEC_UNKNOWN_TYPE; + } + + ifegstreamctrl.buffpos += + (length); + /* File End Check */ + } + break; + + default: + break; + } + + break; + + case 0x2c: /* Start of an image object. Read the image description. */ + + if (_CheckBuffer(&ifegstreamctrl, 9) == 0) { + thumb_warn("_CheckBuffer was failed"); + return IMG_CODEC_UNKNOWN_TYPE; + } +#if 1 + if (imagecount == 0) { + /* Regard the width/height of the first image block as the size of thumbnails. */ + int img_block_w, img_block_h, + img_block_left, img_block_top; + img_block_left = + EncodedDataBuffer[ifegstreamctrl. + buffpos] | + (EncodedDataBuffer + [ifegstreamctrl.buffpos + 1] << 8); + img_block_top = + EncodedDataBuffer[ifegstreamctrl. + buffpos + + 2] | + (EncodedDataBuffer + [ifegstreamctrl.buffpos + 3] << 8); + + img_block_w = + EncodedDataBuffer[ifegstreamctrl. + buffpos + + 4] | + (EncodedDataBuffer + [ifegstreamctrl.buffpos + 5] << 8); + img_block_h = + EncodedDataBuffer[ifegstreamctrl. + buffpos + + 6] | + (EncodedDataBuffer + [ifegstreamctrl.buffpos + 7] << 8); + thumb_dbg + ("Image block width : %d, Height : %d, left:%d, top:%d\n", + img_block_w, img_block_h, + img_block_left, img_block_top); + + *pWidth = img_block_w; + *pHeight = img_block_h; + } +#endif + /* Color Resolution */ + if ((EncodedDataBuffer[ifegstreamctrl.buffpos + 8] & 0x80) != 0) { /* Logical color table */ + temp = + (EncodedDataBuffer + [ifegstreamctrl.buffpos + + 8] & 0x7) + 1; + length = (1 << temp) * 3; + if (_CheckBuffer + (&ifegstreamctrl, + length + 9) == 0) { + thumb_warn + ("_CheckBuffer was failed"); + return IMG_CODEC_UNKNOWN_TYPE; + } + + ifegstreamctrl.buffpos += length; + /* File End Check */ + } + + ifegstreamctrl.buffpos += 9; + + if (_CheckBuffer(&ifegstreamctrl, 1) == 0) { + thumb_warn("_CheckBuffer was failed"); + return IMG_CODEC_UNKNOWN_TYPE; + } + + temp = + EncodedDataBuffer[ifegstreamctrl.buffpos++]; + if (temp < 2 || 9 < temp) { + return IMG_CODEC_UNKNOWN_TYPE; + } + + do { + if (_CheckBuffer(&ifegstreamctrl, 1) == + 0) { + thumb_warn + ("_CheckBuffer was failed"); + return IMG_CODEC_UNKNOWN_TYPE; + } + + length = + EncodedDataBuffer[ifegstreamctrl. + buffpos++]; + if ((length + ifegstreamctrl.buffpos) > ifegstreamctrl.buffend) { + length = + length + + ifegstreamctrl.buffpos - + ifegstreamctrl.buffend; + if (DrmSeekFile + (ifegstreamctrl.fd, + SEEK_CUR, + length) == FALSE) { + if (imagecount) { + if (pNumberOfFrames) + *pNumberOfFrames + = 2; + thumb_dbg + ("IMG_CODEC_AGIF"); + return + IMG_CODEC_AGIF; + } + return + IMG_CODEC_UNKNOWN_TYPE; + } + ifegstreamctrl.filepos += + length; + ifegstreamctrl.buffpos = 0; + ifegstreamctrl.buffend = 0; + } else { + ifegstreamctrl.buffpos += + length; + } + + /* File End Check */ + } while (length); + if (!imagecount) + imagecount++; + else { + if (pNumberOfFrames) + *pNumberOfFrames = 2; + thumb_dbg("IMG_CODEC_AGIF"); + return IMG_CODEC_AGIF; + } + break; + + default: + finished = 0; + break; + + } + } + if (pNumberOfFrames) { + *pNumberOfFrames = 1; + } + thumb_dbg("IMG_CODEC_GIF"); + return IMG_CODEC_GIF; + } + + /*********************** Jpeg *************************/ + else if (AcMemcmp(EncodedDataBuffer, gIfegJPEGHeader, JPG_HEADER_LENGTH) + == 0) { +#if 1 + /* + IFEGSTREAMCTRL ifegstreamctrl; + if( DrmReadFile(hFile, &EncodedDataBuffer[8], FILE_READ_SIZE-8, &fileread) == FALSE ) + { + thumb_err( "DrmReadFile was failed"); + + return IMG_CODEC_NONE; + } + + ifegstreamctrl.fd = hFile; + ifegstreamctrl.filesize = fileSize; + ifegstreamctrl.filepos = fileread+8; + ifegstreamctrl.buffpos = 2; + ifegstreamctrl.buffend = 8+fileread; + ifegstreamctrl.buffer = EncodedDataBuffer; + */ + +#else /* Get w / h from jpeg header */ + +#ifdef _PERFORMANCE_CHECK_ + long start = 0L, end = 0L; + start = mediainfo_get_debug_time(); +#endif + unsigned char *img_buf = NULL; + img_buf = (unsigned char *)malloc(fileSize); + + rewind(hFile); + if (DrmReadFile(hFile, img_buf, fileSize, &fileread) == FALSE) { + thumb_err("DrmReadFile was failed"); + + return IMG_CODEC_NONE; + } + + unsigned short block_length = img_buf[4] * 256 + img_buf[5]; + thumb_dbg("block length : %d", block_length); + int i = 4; + + while (i < fileSize) { + i += block_length; + if (i >= fileSize) { + thumb_warn + ("Failed to get w / h from jpeg at index [%d]", + i); + break; + } + + if (img_buf[i] != 0xFF) { + thumb_warn + ("Failed to get w / h from jpeg at index [%d]", + i); + break; + } + + if (img_buf[i + 1] == 0xC0) { + *pWidth = img_buf[i + 5] * 256 + img_buf[i + 6]; + *pHeight = + img_buf[i + 7] * 256 + img_buf[i + 8]; + break; + } else { + i += 2; + block_length = + img_buf[i] * 256 + img_buf[i + 1]; + thumb_dbg("new block length : %d", + block_length); + } + } + thumb_dbg("Jpeg w: %d, h: %d", *pWidth, *pHeight); + + if (img_buf) + free(img_buf); + +#if defined(_PERFORMANCE_CHECK_) && defined(_USE_LOG_FILE_) + end = mediainfo_get_debug_time(); + double get_size = + ((double)(end - start) / (double)CLOCKS_PER_SEC); + thumb_dbg("get_size from jpeg header : %f", get_size); + mediainfo_init_file_debug(); + mediainfo_file_dbg("get_size from jpeg header : %f", get_size); + mediainfo_close_file_debug(); +#endif + +#endif /* End of Get w / h from jpeg header */ + + thumb_dbg("IMG_CODEC_JPEG"); + return IMG_CODEC_JPEG; + } + return IMG_CODEC_UNKNOWN_TYPE; +} diff --git a/src/codec/img-codec.c b/src/codec/img-codec.c new file mode 100644 index 0000000..fadd8c2 --- /dev/null +++ b/src/codec/img-codec.c @@ -0,0 +1,266 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 "media-thumb-debug.h" +#include "img-codec.h" +#include +#include + +unsigned int *ImgGetFirstFrameAGIFAtSize(const char *szFileName, + ImgImageInfo *image_info) +{ + AGifFrameInfo *pFrameInfo = 0; + void *pDecodedRGB888Buf = 0; + unsigned char *raw_data = NULL; + + if (szFileName == NULL) { + thumb_err + ("ImgGetFirstFrameAGIFAtSize: Input File Name is NULL"); + return NULL; + } + + if (image_info == NULL) { + thumb_err + ("ImgGetFirstFrameAGIFAtSize: Input ImgImageInfo is NULL"); + return NULL; + } + + pFrameInfo = + ImgCreateAGIFFrame(szFileName, image_info->width, + image_info->height, 0, FALSE); + + if (pFrameInfo && pFrameInfo->pOutBits) { + ImgGetNextAGIFFrame(pFrameInfo, TRUE); + + if (ImgConvertRGB565ToRGB888 + (pFrameInfo->pOutBits, &pDecodedRGB888Buf, + pFrameInfo->width, pFrameInfo->height)) { + if (pDecodedRGB888Buf) { + free(pFrameInfo->pOutBits); + pFrameInfo->pOutBits = pDecodedRGB888Buf; + unsigned char *src = + ((unsigned char *)(pFrameInfo->pOutBits)); + + unsigned int i = 0; + + if (mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, image_info->width, image_info->height, &i) < 0) { + thumb_err("ImgGetFirstFrameAGIFAtSize: Failed to get buffer size"); + return NULL; + } + thumb_dbg("ImgGetFirstFrameAGIFAtSize: raw data size : %d)", i); + + raw_data = (unsigned char *)malloc(i); + memset(raw_data, 0, i); + unsigned char *dest = raw_data; + while (i--) { + if (dest != NULL) { + *dest = + *((unsigned char *)(src)); + dest++; + src++; + } + } + } + } + } else { + thumb_warn("ImgDecodeAGIFToPixbufFromFile :: Error"); + } + + if (pFrameInfo) { + ImgDestroyAGIFFrame(pFrameInfo); + } + + return (unsigned int *)raw_data; +} + +int ImgConvertRGB565ToRGB888(void *pBuf_rgb565, void **pBuf_rgb888, int width, + int height) +{ + unsigned short *rgb565buf = 0; + unsigned char *rgb888Buf = 0; + unsigned char red, green, blue; + int i; + unsigned int size; + + rgb565buf = (unsigned short *)pBuf_rgb565; + if (rgb565buf == NULL) { + thumb_err("rgb565buf is NULL: Error !!!"); + return FALSE; + } + + if (mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, width, height, &size) < 0) { + thumb_err("ImgGetFirstFrameAGIFAtSize: Failed to get buffer size"); + return FALSE; + } + + rgb888Buf = (unsigned char *)malloc(size); + + if (rgb888Buf == NULL) { + thumb_err("rgb888Buf is NULL: Error !!!"); + return FALSE; + } + + memset(rgb888Buf, 0, size); + + for (i = 0; i < width * height; i++) { + red = ((rgb565buf[i] >> 11) & 0x1F) << 3; + green = ((rgb565buf[i] >> 5) & 0x3F) << 2; + blue = (rgb565buf[i] & 0x1F) << 3; + rgb888Buf[3 * i] = red; + rgb888Buf[3 * i + 1] = green; + rgb888Buf[3 * i + 2] = blue; + } + + *pBuf_rgb888 = (void *)rgb888Buf; + + return TRUE; +} + +/** + * This function is wrapper function for "ImgFastCreateAGIFFrameData". + * + * @param szFileName[in] Specifies the read image data. + * @param width[in] Specifies a width of the image to be created. + * @param height[in] Specifies a height of the image to be created. + * @param bgColor[in] Specifies background color of output buffer. + * @param bLoop[in] Specifies looping condition whether infinte or once play. + * @return This fucntion returns AGifFrameInfo Structure's pointer. + * @see ImgFastCreateAGIFFrameData. + */ + +AGifFrameInfo *ImgCreateAGIFFrame(const char *szFileName, unsigned int width, + unsigned int height, unsigned int bgColor, + BOOL bLoop) +{ + HFile hFile; + FmFileAttribute fileAttrib; + unsigned long size; + unsigned char *pEncodedData = NULL; + int cFileSize; + int mem_alloc_size; + + if (szFileName == NULL) { + thumb_err("Input File Name is NULL"); + return FALSE; + } + + SysRequireEx(szFileName != NULL, FALSE); + + hFile = DrmOpenFile(szFileName); + if (hFile == (HFile) INVALID_HOBJ) { + thumb_err("ImgCreateAGIFFrame: Cannot open file"); + return NULL; + } + + DrmGetFileAttributes(szFileName, &fileAttrib); + + if (fileAttrib.fileSize == 0) { + thumb_err("Zero File Size"); + DrmCloseFile(hFile); + return NULL; + } + + cFileSize = fileAttrib.fileSize; + /* A size of allocated memory - w * h *2 means RGB565 and 4096 means the max of header length */ + mem_alloc_size = width * height * 2 + MAX_GIF_HEADER_SIZE; + + if ((pEncodedData = (unsigned char *)malloc(mem_alloc_size)) == NULL) { + thumb_err("Memory Allocation to pEncodedData failed"); + DrmCloseFile(hFile); + return NULL; + } + /* coverity[ -tainted_data_argument : pEncodedData ] */ + if (DrmReadFile(hFile, pEncodedData, mem_alloc_size, &size) == FALSE) { + thumb_err("DrmReadFile was failed"); + DrmCloseFile(hFile); + + if (pEncodedData) { + free(pEncodedData); + pEncodedData = NULL; + } + + return NULL; + } + + thumb_dbg("ImgCreateAGIFFrame: file (%s) read...", szFileName); + + DrmCloseFile(hFile); + + return FastImgCreateAGIFFrameData(width, height, pEncodedData, + cFileSize, bgColor, bLoop); +} + +/** + * This function is wrapper function for "ImgFastDestroyAGIFFrameData". + * + * @param pFrameData[in] + * @return void + * @see ImgFastDestroyAGIFFrameData. + * @see ImgFastDestroyAGIFFrameData. + * + * @note ImgFastDestroyAGIFFrameData function set free all memory in AGifFrameInfo structure + * even pEncodedData + * + * @author rubric(sinjae4b.lee@samsung.com) + */ + +void ImgDestroyAGIFFrame(AGifFrameInfo *pFrameData) +{ + SysAssert(pFrameData); + + FastImgDestroyAGIFFrameData(pFrameData); +} + +/** + * This function is wrapper function for "ImgFastGetNextFrameAGIF". + * + * @param pFrameData[in] + * @param bCenterAlign Specifies true if you want center align in output buffer, else left top align + * @return This fucntion returns True or False as decoding result. + * @see ImgFastGetNextFrameAGIF. + * + * @note This function returns one frame data it decoded. + * next time, returns next decoded frame data... and so on. + * + * @author rubric(sinjae4b.lee@samsung.com) + */ + +ImgFastCodecInfo ImgGetNextAGIFFrame(AGifFrameInfo *gFrameData, + BOOL bCenterAlign) +{ + int iResult; + + if (gFrameData == NULL) { + thumb_err("Input gFrameData is NULL"); + return IMG_INFO_DECODING_FAIL; + } + + iResult = FastImgGetNextFrameAGIF(gFrameData, bCenterAlign); + + if (iResult == 1) { + return IMG_INFO_DECODING_SUCCESS; + } else if (iResult == 2) { + return IMG_INFO_AGIF_LAST_FRAME; + } else { + return IMG_INFO_DECODING_FAIL; + } + +} diff --git a/src/include/codec/AGifFrameInfo.h b/src/include/codec/AGifFrameInfo.h new file mode 100644 index 0000000..0f5aa81 --- /dev/null +++ b/src/include/codec/AGifFrameInfo.h @@ -0,0 +1,65 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 _AGIFFRAMEINFO_H_ +#define _AGIFFRAMEINFO_H_ + +typedef struct tagFrameInfo +{ + int height; + int width; + unsigned int backcolor; + unsigned int ui_backcolor; + int imgCount; + int inputSize; + + unsigned char *pEncodedData; + void *pOutBits; + + unsigned char *pPrevImg; + unsigned int *pGlobal_table; + unsigned short *pPrefix; + unsigned char *pDstack; + unsigned char *pSuffix; + + int flag; + int size; + int useBuffer; + int bLoop; + int global_numcol; + int resizedwidth; + int resizedheight; + int logi_wdt; + int logi_hgt; + int offset; + int firstpos; + + unsigned short delay; + +#ifdef INTERNAL_IMGCODEC + unsigned int nRepeatCount; + unsigned int nLoopCount; + + unsigned char bOneFrame; +#endif +}AGifFrameInfo; + +#endif // _AGIFFRAMEINFO_H_ diff --git a/src/include/codec/IfegDecodeAGIF.h b/src/include/codec/IfegDecodeAGIF.h new file mode 100644 index 0000000..9510c64 --- /dev/null +++ b/src/include/codec/IfegDecodeAGIF.h @@ -0,0 +1,57 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 _IFEG_DECODE_GIF_H_ +#define _IFEG_DECODE_GIF_H_ + + + +#include "AGifFrameInfo.h" +#include "img-codec-common.h" + + + +#define MODE 0 + +#define MAX_GIF_HEADER_SIZE 4096 + +#if MODE == 2 +#define MAXBUFFMEMORY 330000 +#endif + +#define MAXWIDTH 4096 +#define MAXHEIGHT 4096 + +#ifdef __cplusplus +extern "C" { +#endif + + +int FastImgGetNextFrameAGIF (AGifFrameInfo* pFrameData, BOOL bCenterAlign); +AGifFrameInfo* FastImgCreateAGIFFrameData(unsigned int width, unsigned int height, unsigned char *pEncodedData, unsigned int file_size, unsigned int ui_backcolor, BOOL bLoop); +void FastImgDestroyAGIFFrameData(AGifFrameInfo* pFrameData); + +#ifdef __cplusplus +} +#endif + + +#endif /*_IFEG_DECODER_H_*/ diff --git a/src/include/codec/img-codec-agif.h b/src/include/codec/img-codec-agif.h new file mode 100644 index 0000000..4480bd8 --- /dev/null +++ b/src/include/codec/img-codec-agif.h @@ -0,0 +1,28 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 _IMGCODEC_AGIF_H_ +#define _IMGCODEC_AGIF_H_ + +#include "IfegDecodeAGIF.h" + +#endif /*_IMGCODEC_AGIF_H_*/ + diff --git a/src/include/codec/img-codec-common.h b/src/include/codec/img-codec-common.h new file mode 100644 index 0000000..4cb8922 --- /dev/null +++ b/src/include/codec/img-codec-common.h @@ -0,0 +1,304 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 _IMGCODEC_COMMON_H_ +#define _IMGCODEC_COMMON_H_ + +#include "img-codec-config.h" +#include "img-codec-osal.h" +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +////////////////////////////////////////////////////////////// + +/* Maximum Image File Size Supported */ +#define IMG_MAX_IMAGE_FILE_SIZE (10 * 1024 * 1024) + +////////////////////////////////////////////////////////////// +#define ImgDebug(type, fmt, arg...) \ + do { \ + fprintf(stderr, "[Media-SVC]"fmt, ##arg); \ + }while(0) + +#if 1 +#define SysRequireEx(expr, retValue) \ + if (!(expr)) { \ + fprintf(stderr, "[Media-SVC][%s] INVALID_PARAM (%d lines in %s)\n",__FUNCTION__, __LINE__, __FILE__); \ + return (retValue); \ + } +#define SysDebug(X) ImgDebug X + +#define SysAssert(expr) +#else +#define SysRequireEx(expr, retValue) +#define SysDebug(expr, retValue) +#define SysAssert(expr) +#endif + +////////////////////////////////////////////////////////////// + + +typedef enum +{ + IMG_INFO_DECODING_FAIL = 0, + IMG_INFO_DECODING_SUCCESS = 1, + IMG_INFO_AGIF_LAST_FRAME = 2, + IMG_INFO_TOO_BIG_FILE_SIZE = -1, + IMG_INFO_TOO_LARGE_SCALE = -2, + IMG_INFO_TOO_BIG_PROGRESSIVE= -3, + IMG_INFO_UNKNOWN_FORMAT = -4, + IMG_INFO_FILE_ERR = -5, + IMG_INFO_MEM_ALLOC_FAIL = -6 +}ImgFastCodecInfo; + + + +typedef enum +{ + IMG_CODEC_UNKNOWN_TYPE = -2, + IMG_CODEC_BIG_PROGRESSIVE_JPEG = -1, + IMG_CODEC_NONE = 0, + IMG_CODEC_GIF = ( 1 << 0), + IMG_CODEC_PNG = ( 1 << 1), + IMG_CODEC_WBMP = ( 1 << 2), + IMG_CODEC_JPEG = ( 1 << 3), + IMG_CODEC_BMP = ( 1 << 4), + IMG_CODEC_TIF = ( 1 << 5), + IMG_CODEC_AGIF = ( 1 << 6), + IMG_CODEC_PROGRESSIVE_JPEG = ( 1 << 7), + IMG_CODEC_DRM = ( 1 << 8), +} ImgCodecType; + +typedef enum inputFlag +{ + IMG_RGB_888_OUTPUT = 0x0001, + IMG_RGB_OUTPUT = 0x0002, + IMG_YUV_OUTPUT = 0x0005 +}ImgInputFlag; + +typedef enum resize +{ + /* During resizing aspect ratio will be maintained */ + IMG_RESIZE_MAINTAIN_ASPECT_RATIO = 0x0001, + IMG_RESIZE = 0x0002 +} ImgResizeInput; + + +typedef struct tagImgImageInfo +{ + unsigned int width; + unsigned int height; + unsigned int numberOfFrame; + unsigned int delay; //deprecated. + unsigned int bOrientation; //deprecated. +}ImgImageInfo; + +typedef struct tagImgBitmap +{ + int width; + int height; + UCHAR bitsPerPixel; /* For TIF it should be 8 or 4 or 1 always + * If coming directly from camera and + * bitsperpixel is 16 then its assumed as 8 + * & color type as RGBC and compression + * type as NO_COMP and encode it. + */ + + void *pBits; + BOOL bChromaKeyFlag; /* Flag to indicate chroma key + * Default: FALSE + */ + ULONG chromaKey; /* This is the colour which needs to be (or is) transparent. + * This colour will be in 5, 5, 5 RGB format as below. + * First 16 MS Bits 0, R (5), G (5), 0 (1), B (5) + */ + UCHAR disposal; /* Disposal action to take during + * display of current flag + * Default: 0 + */ + USHORT delay; /* Delay before display of + * next frame. Default: 0 + */ + BOOL inputFlag; /* User input required befflag used + * Default: FALSE + */ + + BOOL interlace; /* Interlace indicator flag + * Default: FALSE + */ + BYTE *pLocalColorMap;/* Local color palette pointer + * Default: NULL + */ + /* For TIF :Should be given if PALETTE color type. + */ + USHORT localColorMapSize; + /* Local color palette size */ + /* In TIF: Should be given if PALETTE color type. + */ + void *pAlphaChannel; /* An alpha channel, representing transparency + * information on a per-pixel basis + */ + BYTE colorType ; /* Indicates the color type of image. It can be + * GRAY, COLOR, PALETTED, GRAY_WITH_ALPHA_CHANNEL or + * COLOR_WITH_ALPHA_CHANNEL + */ + /* For TIF: IT could be TIF_COLORTYPE_BILEVEL, + * TIF_COLORTYPE_GRAY ,TIF_COLORTYPE_RGB, + * TIF_COLORTYPE_PALETTE or + * TIF_COLORTYPE_RGBPALETTE. + */ + BYTE filter ; /* Type of filter to apply. Could be one of NONE, + * SUB, UP, AVERAGE or PAETH + */ + BYTE compressionMethod ; /* Type of compression in zLib to apply. Could be + * one of NONE, FIXED or DYANMIC + */ + /* For TIF : IT could be TIF_COMP_NOCOMP , + * TIF_COMP_PACKBIT or TIF_COMP_HUFFMAN (only for bilevel) + */ + + UCHAR colorConversion; /* Indicates whether color conversion has to + * be done or not + */ + /* For TIF :This represents white is zero or + * black is zero in case of bilevel & gray. + */ + UCHAR downSampling; /* Indicates whether down sampling needs to + * be done or not + */ + + UCHAR downSamplingMethod[3]; + /* Down sampling offsets for every component. Possible + * combinations are + * 1, 1, 1 + * 1, 2, 1 + * 1, 2, 2 + */ +} ImgBitmap; + +typedef struct tagImgCodecColor +{ + UINT16 red; + UINT16 green; + UINT16 blue; +} ImgCodecColor; + + +typedef struct +{ + int width, height, bpp; + + BOOL tRNSFlag; + ImgCodecColor tRNSColor; + + BOOL bKGDFlag; + ImgCodecColor bKGDColor; + + BOOL AlphaChannelFlag; + unsigned short *pAlphaChannel; +} ImgTrnsInfo; + +typedef struct tagImgBitmapElem ImgBitmapElem; + +struct tagImgBitmapElem +{ + int x; + int y; + ImgBitmap *pbmBitmap; + ImgBitmapElem *pNext; +}; + +typedef struct gifDecode ImgGIFFrame ; + +typedef struct tagImgImage +{ + int dataSize; /* Holds the total number of bytes required + * to hold the image + */ + int width; + int height; + + USHORT flag; /* This contains flags as defined + * in ImgCodecFlagType + */ + ULONG backGroundColor; /* The backgroundColor specifies a default background + * color to present the image against. + * Note that viewers are not bound to honor this color. + * A viewer can choose to use a different background. + */ + BYTE *pGlobalColorMap; /* Global color palette pointer + * Default: NULL + */ + USHORT globalColorMapSize; /* Local color palette size */ + ULONG gamma; /* The value is encoded as a 4-byte unsigned integer, + * representing gamma times 100000. For example, a + * gamma of 0.45 would be stored as the integer 45000. + */ + int bitmapCount; /* This will hold the number of bitmaps in the + * ImgImage structure + */ + BYTE function ; /* This will be set as TRUE if this structure is + * used for encoder + */ + + ImgBitmapElem *pHead; + ImgBitmapElem *pTail; + + + ULONG decodedSize ; /* 1 => Same as in the encoded stream + * 0 => Resize to QQVGA if size is more + * than 176 x 144 + */ + + BOOL memAllocEx ; /* TRUE => MemAllocEx is used, + * FALSE => MemAlloc is used + */ + + USHORT loopCount ; /* This will contain the number of times to repeat + * the animation + */ + BOOL bLoopCount ; /* If GIF LoopCount is present then this will be + * TRUE, otherwise it will be false + */ + + ImgGIFFrame *pGifFrame ; /* Stores the intermediate GIF Frame */ + + ImgInputFlag inputFlag; + ImgResizeInput resizeMethod ; + + /* Flag to identify whether image is AGIF or not */ + BOOL bAGIFImage ; + unsigned char *pEncodedData ; + INT32 cFileSize ; + BOOL bFirstFrame ; + BOOL bReservedMemoryFlag; + unsigned int offset ; +} ImgImage; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // _IMGCODEC_COMMON_H_ diff --git a/src/include/codec/img-codec-config.h b/src/include/codec/img-codec-config.h new file mode 100644 index 0000000..a918e16 --- /dev/null +++ b/src/include/codec/img-codec-config.h @@ -0,0 +1,26 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 _IMGCODEC_CONFIG_H_ +#define _IMGCODEC_CONFIG_H_ +#define INTERNAL_IMGCODEC + +#endif // _IMGCODEC_CONFIG_H_ diff --git a/src/include/codec/img-codec-osal.h b/src/include/codec/img-codec-osal.h new file mode 100644 index 0000000..67b6921 --- /dev/null +++ b/src/include/codec/img-codec-osal.h @@ -0,0 +1,129 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 _IMGCODEC_OSAL_H_ +#define _IMGCODEC_OSAL_H_ +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifndef BOOL + +#define BOOL bool//unsigned short +#endif + +#ifndef UCHAR + +#define UCHAR unsigned char +#endif + +#ifndef BYTE + +#define BYTE unsigned char +#endif + +#ifndef USHORT + +#define USHORT unsigned short +#endif + +#ifndef UINT16 + +#define UINT16 unsigned short +#endif + +#ifndef UINT32 + +#define UINT32 unsigned short +#endif + +#ifndef UINT + +#define UINT unsigned int +#endif + +#ifndef INT32 + +#define INT32 unsigned int +#endif + +#ifndef ULONG + +#define ULONG unsigned long +#endif + +#ifndef TRUE +#define TRUE true +#endif + +#ifndef FALSE +#define FALSE false +#endif + +#ifndef INVALID_HOBJ +//#define INVALID_HOBJ (-1) +#define INVALID_HOBJ NULL +#endif + + +typedef void* HFile; + +#define AcMemalloc IfegMemAlloc +#define AcMemfree IfegMemFree +#define AcMemcmp IfegMemcmp +#define AcMemset IfegMemset +#define AcMemcpy IfegMemcpy + +typedef struct +{ + ULONG fileSize; // File size + ULONG* startAddr; // Only used at LFS + ULONG attribute; // file attribute like directory or file, hidden, readonly, system, ... + int iVol; // positioned volume + ULONG allocatedSize; // real allocated size of file & directory in sub System +} FmFileAttribute; + +void * IfegMemAlloc(unsigned int size); +void IfegMemFree(void* pMem); +void * IfegMemcpy( void *dest, const void *src, unsigned int count ); +void * IfegMemset( void *dest, int c, unsigned int count ); +int IfegMemcmp(const void* pMem1, const void* pMem2, size_t length); + +ULONG IfegGetAvailableMemSize(void); + +HFile DrmOpenFile(const char* szPathName); +BOOL DrmReadFile(HFile hFile, void* pBuffer, ULONG bufLen, ULONG* pReadLen); +long DrmTellFile(HFile hFile); +BOOL DrmSeekFile(HFile hFile, long position, long offset); +BOOL DrmGetFileAttributes(const char* szPathName, FmFileAttribute* pFileAttr); +BOOL DrmCloseFile(HFile hFile); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // _IMGCODEC_OSAL_H_ + + diff --git a/src/include/codec/img-codec-parser.h b/src/include/codec/img-codec-parser.h new file mode 100644 index 0000000..097f24d --- /dev/null +++ b/src/include/codec/img-codec-parser.h @@ -0,0 +1,48 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 _IMGCODEC_PARSER_H_ +#define _IMGCODEC_PARSER_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define MINIMUM_HEADER_BYTES 8 + +#define PNG_HEADER_LENGTH 8 +#define JPG_HEADER_LENGTH 2 +#define GIF_HEADER_LENGTH 3 +#define TIFF_HEADER_LENGTH 2 +#define BMP_HEADER_LENGTH 2 +#define TIFF_IMAGE_WIDTH 0x100 +#define TIFF_IMAGE_HEIGHT 0x101 + +ImgCodecType ImgGetInfo(unsigned char* pEncodedData, unsigned long fileSize, ImgImageInfo* imgInfo); +ImgCodecType ImgGetInfoFile(const char*filePath, ImgImageInfo *imgInfo); +ImgCodecType ImgGetInfoHFile(HFile hFile, unsigned long fileSize, ImgImageInfo* imgInfo); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif + diff --git a/src/include/codec/img-codec.h b/src/include/codec/img-codec.h new file mode 100644 index 0000000..07f3a6b --- /dev/null +++ b/src/include/codec/img-codec.h @@ -0,0 +1,49 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 _IMGCODEC_H_ +#define _IMGCODEC_H_ + +#include "img-codec-common.h" +#include "img-codec-parser.h" +#include "img-codec-agif.h" + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +unsigned int* ImgGetFirstFrameAGIFAtSize(const char *szFileName, ImgImageInfo *image_info); + +int ImgConvertRGB565ToRGB888(void *pBuf_rgb565, void **pBuf_rgb888, int width, int height); + + +AGifFrameInfo* ImgCreateAGIFFrame(const char *szFileName, unsigned int width, unsigned int height, unsigned int bgColor, BOOL bLoop); + +void ImgDestroyAGIFFrame(AGifFrameInfo* pFrameData); + +ImgFastCodecInfo ImgGetNextAGIFFrame (AGifFrameInfo *gFrameData, BOOL bCenterAlign); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // _IMGCODEC_H_ diff --git a/src/include/ipc/media-thumb-ipc.h b/src/include/ipc/media-thumb-ipc.h new file mode 100755 index 0000000..f91925f --- /dev/null +++ b/src/include/ipc/media-thumb-ipc.h @@ -0,0 +1,125 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 "media-thumb-error.h" +#include "media-thumb-debug.h" +#include "media-thumb-types.h" +#include "media-thumb-internal.h" + +#ifdef _USE_MEDIA_UTIL_ +#include "media-util-ipc.h" +#include "media-server-ipc.h" +#endif + +#include +#include +#include +#include +#include +#include +#include + +#ifndef _MEDIA_THUMB_IPC_H_ +#define _MEDIA_THUMB_IPC_H_ + +#ifndef _USE_MEDIA_UTIL_ +#define THUMB_DAEMON_PORT 10000 +#endif +#define MAX_PATH_SIZE 4096 + +#ifndef _USE_MEDIA_UTIL_ +#define TIMEOUT_SEC 10 +#endif + +#define MAX_TRIES 3 + +enum { + THUMB_REQUEST_DB_INSERT, + THUMB_REQUEST_SAVE_FILE, + THUMB_REQUEST_ALL_MEDIA, + THUMB_REQUEST_CANCEL_MEDIA, + THUMB_REQUEST_CANCEL_ALL, + THUMB_REQUEST_KILL_SERVER, + THUMB_RESPONSE +}; + +enum { + THUMB_SUCCESS, + THUMB_FAIL +}; + +#ifndef _USE_MEDIA_UTIL_ +enum { + CLIENT_SOCKET, + SERVER_SOCKET +}; + +typedef struct _thumbMsg{ + int msg_type; + media_thumb_type thumb_type; + int status; + int pid; + int thumb_size; + int thumb_width; + int thumb_height; + int origin_width; + int origin_height; + int origin_path_size; + int dest_path_size; + char org_path[MAX_PATH_SIZE]; + char dst_path[MAX_PATH_SIZE]; +} thumbMsg; +#endif + +int +_media_thumb_create_socket(int sock_type, int *sock); + +int +_media_thumb_create_udp_socket(int *sock); + +int +_media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg); + +int +_media_thumb_recv_udp_msg(int sock, int header_size, thumbMsg *msg, struct sockaddr_in *from_addr, unsigned int *from_size); + +int +_media_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size); + +int +_media_thumb_request(int msg_type, + media_thumb_type thumb_type, + const char *origin_path, + char *thumb_path, + int max_length, + media_thumb_info *thumb_info); + +int +_media_thumb_request_async(int msg_type, + media_thumb_type thumb_type, + const char *origin_path, + thumbUserData *userData); + +int +_media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg); + +#endif /*_MEDIA_THUMB_IPC_H_*/ diff --git a/src/include/media-thumb-internal.h b/src/include/media-thumb-internal.h new file mode 100755 index 0000000..0180a29 --- /dev/null +++ b/src/include/media-thumb-internal.h @@ -0,0 +1,81 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 "media-thumbnail.h" +#include "media-thumb-error.h" +#include "media-thumb-types.h" +#include "media-thumb-debug.h" + +#ifndef _MEDIA_THUMB_INTERNAL_H_ +#define _MEDIA_THUMB_INTERNAL_H_ + +#define THUMB_WIDTH_MAX +/* The maximum of resolution to be able to get thumbnail is 3000 x 3000, except for only jpeg */ +#define THUMB_MAX_ALLOWED_MEM_FOR_THUMB 9000000 + +#define THUMB_LARGE_WIDTH 320 +#define THUMB_LARGE_HEIGHT 240 +#define THUMB_SMALL_WIDTH 160 +#define THUMB_SMALL_HEIGHT 120 + +typedef struct { + int size; + int width; + int height; + int origin_width; + int origin_height; + int alpha; + unsigned char *data; +} media_thumb_info; + +enum Exif_Orientation { + NOT_AVAILABLE=0, + NORMAL =1, + HFLIP =2, + ROT_180 =3, + VFLIP =4, + TRANSPOSE =5, + ROT_90 =6, + TRANSVERSE =7, + ROT_270 =8 +}; + +typedef struct { + ThumbFunc func; + void *user_data; +} thumbUserData; + +int +_media_thumb_image(const char *origin_path, + int thumb_width, + int thumb_height, + media_thumb_format format, + media_thumb_info *thumb_info); + +int +_media_thumb_video(const char *origin_path, + int thumb_width, + int thumb_height, + media_thumb_format format, + media_thumb_info *thumb_info); + +#endif /*_MEDIA_THUMB_INTERNAL_H_*/ diff --git a/src/include/util/media-thumb-db.h b/src/include/util/media-thumb-db.h new file mode 100755 index 0000000..f8e37f9 --- /dev/null +++ b/src/include/util/media-thumb-db.h @@ -0,0 +1,79 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include "media-thumb-error.h" +#include "media-thumb-types.h" +#include "media-thumb-debug.h" + +#ifndef _MEDIA_THUMB_DB_H_ +#define _MEDIA_THUMB_DB_H_ + +#define MEDIA_DATABASE_NAME MEDIA_DB_NAME /* defined in media-util.h */ + +#ifndef _USE_NEW_MEDIA_DB_ +#define SELECT_PATH_FROM_UNEXTRACTED_THUMB_MEDIA "SELECT path from visual_media where thumbnail_path='' and valid=1;" +#define SELECT_MEDIA_BY_PATH "SELECT thumbnail_path FROM visual_media WHERE path='%q';" +#define SELECT_TYPE_BY_PATH "SELECT content_type FROM visual_media WHERE path='%q';" +#define UPDATE_THUMB_BY_PATH "UPDATE visual_media SET thumbnail_path = '%q' WHERE path='%q';" +#define UPDATE_WH_BY_PATH "UPDATE image_meta SET width=%d,height=%d WHERE visual_uuid=(SELECT visual_uuid FROM visual_media WHERE path='%q');" + +#else +#define SELECT_PATH_FROM_UNEXTRACTED_THUMB_MEDIA "SELECT path from media where thumbnail_path is null and validity=1 and (media_type=0 or media_type=1);" +#define SELECT_MEDIA_BY_PATH "SELECT thumbnail_path FROM media WHERE path='%q';" +#define SELECT_TYPE_BY_PATH "SELECT media_type FROM media WHERE path='%q';" +#define SELECT_WH_BY_PATH "SELECT width, height FROM media WHERE path='%q';" +#define UPDATE_THUMB_BY_PATH "UPDATE media SET thumbnail_path = '%q' WHERE path='%q';" +#define UPDATE_WH_BY_PATH "UPDATE media SET width=%d,height=%d WHERE path='%q';" +#define UPDATE_THUMB_WH_BY_PATH "UPDATE media SET thumbnail_path = '%q', width=%d,height=%d WHERE path='%q';" +#endif + +sqlite3 *_media_thumb_db_get_handle(); + +int +_media_thumb_db_connect(); + +int +_media_thumb_db_disconnect(); + +int +_media_thumb_get_thumb_from_db(const char *origin_path, + char *thumb_path, + int max_length, + int *need_update_db); + +int +_media_thumb_get_thumb_from_db_with_size(const char *origin_path, + char *thumb_path, + int max_length, + int *need_update_db, + int *width, + int *height); + +int +_media_thumb_update_db(const char *origin_path, + char *thumb_path, + int width, + int height); + +#endif /*_MEDIA_THUMB_DB_H_*/ + diff --git a/src/include/util/media-thumb-debug.h b/src/include/util/media-thumb-debug.h new file mode 100755 index 0000000..65ca53f --- /dev/null +++ b/src/include/util/media-thumb-debug.h @@ -0,0 +1,81 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 _MEDIA_THUMB_DEBUG_H_ +#define _MEDIA_THUMB_DEBUG_H_ + +#include +#include +#include + +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + + +#define _PERFORMANCE_CHECK_ + + +#define LOG_TAG "MEDIA_THUMBNAIL" + +static pid_t gettid(void) +{ + return syscall(__NR_gettid); +} + +#define FONT_COLOR_RESET "\033[0m" +#define FONT_COLOR_RED "\033[31m" +#define FONT_COLOR_GREEN "\033[32m" +#define FONT_COLOR_YELLOW "\033[33m" +#define FONT_COLOR_BLUE "\033[34m" +#define FONT_COLOR_PURPLE "\033[35m" +#define FONT_COLOR_CYAN "\033[36m" +#define FONT_COLOR_GRAY "\033[37m" + +#define thumb_dbg(fmt, arg...) LOGD(FONT_COLOR_RESET"[%d] " fmt "\n", gettid(), ##arg) +#define thumb_warn(fmt, arg...) LOGW(FONT_COLOR_GREEN"[%d] " fmt "\n", gettid(), ##arg) +#define thumb_err(fmt, arg...) LOGE(FONT_COLOR_RED"[%d] " fmt "\n", gettid(), ##arg) + +#ifdef _USE_LOG_FILE_ +void thumb_init_file_debug(); +void thumb_close_file_debug(); +FILE* get_fp(); +#define thumb_file_dbg(fmt,arg...) fprintf( get_fp(), "[%s: %d] " fmt "\n", __FUNCTION__, __LINE__, ##arg) + +#endif + + +#ifdef _PERFORMANCE_CHECK_ +long +thumb_get_debug_time(void); +void +thumb_reset_debug_time(void); +void +thumb_print_debug_time(char* time_string); +void +thumb_print_debug_time_ex(long start, long end, const char* func_name, char* time_string); +#endif + +#endif /*_MEDIA_THUMB_DEBUG_H_*/ + diff --git a/src/include/util/media-thumb-util.h b/src/include/util/media-thumb-util.h new file mode 100755 index 0000000..335c4a5 --- /dev/null +++ b/src/include/util/media-thumb-util.h @@ -0,0 +1,146 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 "media-thumb-error.h" +#include "media-thumb-types.h" +#include "media-thumb-debug.h" +#include "media-util.h" + +#ifndef _MEDIA_THUMB_UTIL_H_ +#define _MEDIA_THUMB_UTIL_H_ + +#define SAFE_FREE(src) { if(src) {free(src); src = NULL;}} + +#ifndef _USE_NEW_MEDIA_DB_ +#define THUMB_NONE_TYPE 0x00000000 /* None */ +#define THUMB_IMAGE_TYPE 0x00000001 /* Image */ +#define THUMB_VIDEO_TYPE 0x00000002 /* Video */ +#else +#define THUMB_NONE_TYPE -1 /* None */ +#define THUMB_IMAGE_TYPE 0 /* Image */ +#define THUMB_VIDEO_TYPE 1 /* Video */ +#endif + +#define THUMB_PATH_PHONE MEDIA_ROOT_PATH_INTERNAL /**< File path prefix of files stored in phone */ +#define THUMB_PATH_MMC MEDIA_ROOT_PATH_SDCARD /**< File path prefix of files stored in mmc card */ + +#define THUMB_PHONE_PATH MEDIA_DATA_PATH"/.thumb/phone" +#define THUMB_MMC_PATH MEDIA_DATA_PATH"/.thumb/mmc" + +#define THUMB_DEFAULT_PATH MEDIA_DATA_PATH"/.thumb/thumb_default.png" + +typedef enum +{ + THUMB_PHONE, /**< Stored only in phone */ + THUMB_MMC /**< Stored only in MMC */ +} media_thumb_store_type; + +int _media_thumb_get_length(media_thumb_type thumb_type); + +int _media_thumb_get_store_type_by_path(const char *full_path); + +int +_media_thumb_get_file_ext(const char *file_path, char *file_ext, int max_len); + +int +_media_thumb_get_file_type(const char *file_full_path); + +int +_media_thumb_remove_file(const char *path); + +char +*_media_thumb_generate_hash_name(const char *file); + +int +_media_thumb_get_hash_name(const char *file_full_path, + char *thumb_hash_path, size_t max_thumb_path); + +int +_media_thumb_save_to_file_with_evas(unsigned char *data, + int w, + int h, + int alpha, + char *thumb_path); + +int +_media_thumb_get_width(media_thumb_type thumb_type); + +int +_media_thumb_get_height(media_thumb_type thumb_type); + +/** + * _thumbnail_get_data: + * This function generates thumbnail raw data, which is wanted by user + * This api is closed for a while until being independent from evas object to be thread-safe + * + * @return This function returns zero(MEDIA_THUMB_ERROR_NONE) on success, or negative value with error code. + * Please refer 'media-thumb-error.h' to know the exact meaning of the error. + * @param[in] origin_path The path of the original image + * @param[in] thumb_type The type of the returned thumbnail data + * @param[in] format The format of the returned data + * @param[out] data The data of generated thumbnail. + * @param[out] size The size of generated thumbnail. + * @param[out] width The width of generated thumbnail. + * @param[out] height The height of generated thumbnail. + * @param[out] origin_width The width of original image. + * @param[out] origin_height The height of original image. + * @see None. + * @pre None. + * @post None. + * @remark None. + * @par example + * @code + +#include + +void test_get_thumb_data() +{ + int ret = MEDIA_THUMB_ERROR_NONE; + int thumb_type = 0; + const char *origin_path = "/opt/usr/media/test.jpg"; + void *data = NULL; + + + ret = _thumbnail_get_data(origin_path, thumb_type, thumb_path, &data); + + if (ret < 0) + { + printf( "_thumbnail_get_data fails. error code->%d", ret); + } + + return; +} + + * @endcode +*/ +int _thumbnail_get_data(const char *origin_path, + media_thumb_type thumb_type, + media_thumb_format format, + unsigned char **data, + int *size, + int *width, + int *height, + int *origin_width, + int *origin_height, + int *alpha); + +#endif /*_MEDIA_THUMB_UTIL_H_*/ + diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c new file mode 100755 index 0000000..67f22bd --- /dev/null +++ b/src/ipc/media-thumb-ipc.c @@ -0,0 +1,634 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 "media-thumbnail.h" +#include "media-thumb-ipc.h" +#include "media-thumb-util.h" +#include "media-thumb-db.h" +#include +#include +#include +#include + + + +int +_media_thumb_create_socket(int sock_type, int *sock) +{ + int sock_fd = 0; + + if ((sock_fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { + thumb_err("socket failed: %s", strerror(errno)); + return MEDIA_THUMB_ERROR_NETWORK; + } + + if (sock_type == CLIENT_SOCKET) { + +#ifdef _USE_MEDIA_UTIL_ + struct timeval tv_timeout = { MS_TIMEOUT_SEC_10, 0 }; +#else + struct timeval tv_timeout = { TIMEOUT_SEC, 0 }; +#endif + + if (setsockopt(sock_fd, SOL_SOCKET, SO_RCVTIMEO, &tv_timeout, sizeof(tv_timeout)) == -1) { + thumb_err("setsockopt failed: %s", strerror(errno)); + close(sock_fd); + return MEDIA_THUMB_ERROR_NETWORK; + } + } else if (sock_type == SERVER_SOCKET) { + + int n_reuse = 1; + + if (setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, &n_reuse, sizeof(n_reuse)) == -1) { + thumb_err("setsockopt failed: %s", strerror(errno)); + close(sock_fd); + return MEDIA_THUMB_ERROR_NETWORK; + } + } + + *sock = sock_fd; + + return MEDIA_THUMB_ERROR_NONE; +} + + +int +_media_thumb_create_udp_socket(int *sock) +{ + int sock_fd = 0; + + if ((sock_fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { + thumb_err("socket failed: %s", strerror(errno)); + return MEDIA_THUMB_ERROR_NETWORK; + } + +#ifdef _USE_MEDIA_UTIL_ + struct timeval tv_timeout = { MS_TIMEOUT_SEC_10, 0 }; +#else + struct timeval tv_timeout = { TIMEOUT_SEC, 0 }; +#endif + + if (setsockopt(sock_fd, SOL_SOCKET, SO_RCVTIMEO, &tv_timeout, sizeof(tv_timeout)) == -1) { + thumb_err("setsockopt failed: %s", strerror(errno)); + close(sock_fd); + return MEDIA_THUMB_ERROR_NETWORK; + } + + *sock = sock_fd; + + return MEDIA_THUMB_ERROR_NONE; +} + +int _media_thumb_get_error() +{ + if (errno == EWOULDBLOCK) { + thumb_err("Timeout. Can't try any more"); + return MEDIA_THUMB_ERROR_TIMEOUT; + } else { + thumb_err("recvfrom failed : %s", strerror(errno)); + return MEDIA_THUMB_ERROR_NETWORK; + } +} + +int +_media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg) +{ + int recv_msg_len = 0; + unsigned char *buf = NULL; + + buf = (unsigned char*)malloc(header_size); + + if ((recv_msg_len = recv(sock, buf, header_size, 0)) <= 0) { + thumb_err("recvfrom failed : %s", strerror(errno)); + SAFE_FREE(buf); + return _media_thumb_get_error(); + } + + memcpy(msg, buf, header_size); + //thumb_dbg("origin_path_size : %d, dest_path_size : %d", msg->origin_path_size, msg->dest_path_size); + + SAFE_FREE(buf); + + buf = (unsigned char*)malloc(msg->origin_path_size); + + if ((recv_msg_len = recv(sock, buf, msg->origin_path_size, 0)) < 0) { + thumb_err("recvfrom failed : %s", strerror(errno)); + SAFE_FREE(buf); + return _media_thumb_get_error(); + } + + strncpy(msg->org_path, (char*)buf, msg->origin_path_size); + //thumb_dbg("original path : %s", msg->org_path); + + SAFE_FREE(buf); + buf = (unsigned char*)malloc(msg->dest_path_size); + + if ((recv_msg_len = recv(sock, buf, msg->dest_path_size, 0)) < 0) { + thumb_err("recvfrom failed : %s", strerror(errno)); + SAFE_FREE(buf); + return _media_thumb_get_error(); + } + + strncpy(msg->dst_path, (char*)buf, msg->dest_path_size); + //thumb_dbg("destination path : %s", msg->dst_path); + + SAFE_FREE(buf); + return MEDIA_THUMB_ERROR_NONE; +} + + +int +_media_thumb_recv_udp_msg(int sock, int header_size, thumbMsg *msg, struct sockaddr_in *from_addr, unsigned int *from_size) +{ + int recv_msg_len = 0; + unsigned int from_addr_size = sizeof(struct sockaddr_in); + unsigned char *buf = NULL; + + buf = (unsigned char*)malloc(sizeof(thumbMsg)); + + if ((recv_msg_len = recvfrom(sock, buf, sizeof(thumbMsg), 0, (struct sockaddr *)from_addr, &from_addr_size)) < 0) { + thumb_err("recvfrom failed : %s", strerror(errno)); + SAFE_FREE(buf); + return _media_thumb_get_error(); + } + + memcpy(msg, buf, header_size); + + if (msg->origin_path_size <= 0 || msg->origin_path_size > MAX_PATH_SIZE) { + SAFE_FREE(buf); + thumb_err("msg->origin_path_size is invalid %d", msg->origin_path_size ); + return MEDIA_THUMB_ERROR_NETWORK; + } + + strncpy(msg->org_path, (char*)buf + header_size, msg->origin_path_size); + //thumb_dbg("original path : %s", msg->org_path); + + if (msg->dest_path_size <= 0 || msg->dest_path_size > MAX_PATH_SIZE) { + SAFE_FREE(buf); + thumb_err("msg->origin_path_size is invalid %d", msg->dest_path_size ); + return MEDIA_THUMB_ERROR_NETWORK; + } + + strncpy(msg->dst_path, (char*)buf + header_size + msg->origin_path_size, msg->dest_path_size); + //thumb_dbg("destination path : %s", msg->dst_path); + + SAFE_FREE(buf); + *from_size = from_addr_size; + + return MEDIA_THUMB_ERROR_NONE; +} + +int +_media_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size) +{ + if (req_msg == NULL || buf == NULL) { + return -1; + } + + int org_path_len = 0; + int dst_path_len = 0; + int size = 0; + int header_size = 0; + + header_size = sizeof(thumbMsg) - MAX_PATH_SIZE*2; + org_path_len = strlen(req_msg->org_path) + 1; + dst_path_len = strlen(req_msg->dst_path) + 1; + + //thumb_dbg("Basic Size : %d, org_path : %s[%d], dst_path : %s[%d]", header_size, req_msg->org_path, org_path_len, req_msg->dst_path, dst_path_len); + + size = header_size + org_path_len + dst_path_len; + *buf = malloc(size); + memcpy(*buf, req_msg, header_size); + memcpy((*buf)+header_size, req_msg->org_path, org_path_len); + memcpy((*buf)+header_size + org_path_len, req_msg->dst_path, dst_path_len); + + *buf_size = size; + + return 0; +} + +int +_media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *origin_path, char *thumb_path, int max_length, media_thumb_info *thumb_info) +{ + int sock; + const char *serv_ip = "127.0.0.1"; + struct sockaddr_in serv_addr; + + int recv_str_len = 0; + int err; + int pid; + + +#ifdef _USE_MEDIA_UTIL_ + if (ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sock) < 0) { + thumb_err("ms_ipc_create_client_socket failed"); + return MEDIA_THUMB_ERROR_NETWORK; + } +#else + /* Creaete a TCP socket */ + if (_media_thumb_create_socket(CLIENT_SOCKET, &sock) < 0) { + thumb_err("_media_thumb_create_socket failed"); + return MEDIA_THUMB_ERROR_NETWORK; + } +#endif + + memset(&serv_addr, 0, sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + serv_addr.sin_addr.s_addr = inet_addr(serv_ip); +#ifdef _USE_MEDIA_UTIL_ + serv_addr.sin_port = htons(MS_THUMB_CREATOR_PORT); +#else + serv_addr.sin_port = htons(THUMB_DAEMON_PORT); +#endif + + /* Connecting to the thumbnail server */ + if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) { + thumb_err("connect error : %s", strerror(errno)); + return MEDIA_THUMB_ERROR_NETWORK; + } + + thumbMsg req_msg; + thumbMsg recv_msg; + + memset((void *)&req_msg, 0, sizeof(thumbMsg)); + memset((void *)&recv_msg, 0, sizeof(thumbMsg)); + + /* Get PID of client*/ + pid = getpid(); + req_msg.pid = pid; + + /* Set requset message */ + req_msg.msg_type = msg_type; + req_msg.thumb_type = thumb_type; + strncpy(req_msg.org_path, origin_path, sizeof(req_msg.org_path)); + req_msg.org_path[strlen(req_msg.org_path)] = '\0'; + + if (msg_type == THUMB_REQUEST_SAVE_FILE) { + strncpy(req_msg.dst_path, thumb_path, sizeof(req_msg.dst_path)); + req_msg.dst_path[strlen(req_msg.dst_path)] = '\0'; + } + + req_msg.origin_path_size = strlen(req_msg.org_path) + 1; + req_msg.dest_path_size = strlen(req_msg.dst_path) + 1; + + if (req_msg.origin_path_size > MAX_PATH_SIZE || req_msg.dest_path_size > MAX_PATH_SIZE) { + thumb_err("path's length exceeds %d", MAX_PATH_SIZE); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + unsigned char *buf = NULL; + int buf_size = 0; + int header_size = 0; + + header_size = sizeof(thumbMsg) - MAX_PATH_SIZE*2; + _media_thumb_set_buffer(&req_msg, &buf, &buf_size); + + if (send(sock, buf, buf_size, 0) != buf_size) { + thumb_err("sendto failed: %d\n", errno); + SAFE_FREE(buf); + close(sock); + return MEDIA_THUMB_ERROR_NETWORK; + } + + thumb_dbg("Sending msg to thumbnail daemon is successful"); + + SAFE_FREE(buf); + + if ((err = _media_thumb_recv_msg(sock, header_size, &recv_msg)) < 0) { + thumb_err("_media_thumb_recv_msg failed "); + close(sock); + return err; + } + + recv_str_len = strlen(recv_msg.org_path); + thumb_dbg("recv %s(%d) from thumb daemon is successful", recv_msg.org_path, recv_str_len); + + close(sock); + + if (recv_str_len > max_length) { + thumb_err("user buffer is too small. Output's length is %d", recv_str_len); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + if (recv_msg.status == THUMB_FAIL) { + thumb_err("Failed to make thumbnail"); + return -1; + } + + if (msg_type != THUMB_REQUEST_SAVE_FILE) { + strncpy(thumb_path, recv_msg.dst_path, max_length); + } + + thumb_info->origin_width = recv_msg.origin_width; + thumb_info->origin_height = recv_msg.origin_height; + + return 0; +} + +int +_media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg) +{ + int err = -1; + unsigned char *data = NULL; + int thumb_size = 0; + int thumb_w = 0; + int thumb_h = 0; + int origin_w = 0; + int origin_h = 0; + int max_length = 0; + char *thumb_path = NULL; + int need_update_db = 0; + int alpha = 0; + + if (req_msg == NULL || res_msg == NULL) { + thumb_err("Invalid msg!"); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + int msg_type = req_msg->msg_type; + media_thumb_type thumb_type = req_msg->thumb_type; + const char *origin_path = req_msg->org_path; + + media_thumb_format thumb_format = MEDIA_THUMB_BGRA; + + thumb_path = res_msg->dst_path; + thumb_path[0] = '\0'; + max_length = sizeof(res_msg->dst_path); + + err = _media_thumb_db_connect(); + if (err < 0) { + thumb_err("_media_thumb_mb_svc_connect failed: %d", err); + return MEDIA_THUMB_ERROR_DB; + } + + if (msg_type == THUMB_REQUEST_DB_INSERT) { + err = _media_thumb_get_thumb_from_db_with_size(origin_path, thumb_path, max_length, &need_update_db, &origin_w, &origin_h); + if (err == 0) { + res_msg->origin_width = origin_w; + res_msg->origin_height = origin_h; + _media_thumb_db_disconnect(); + return MEDIA_THUMB_ERROR_NONE; + } else { + if (strlen(thumb_path) == 0) { + err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length); + if (err < 0) { + thumb_err("_media_thumb_get_hash_name failed - %d\n", err); + strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length); + _media_thumb_db_disconnect(); + return err; + } + + thumb_path[strlen(thumb_path)] = '\0'; + } + } + + } else if (msg_type == THUMB_REQUEST_SAVE_FILE) { + strncpy(thumb_path, req_msg->dst_path, max_length); + + } else if (msg_type == THUMB_REQUEST_ALL_MEDIA) { + err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length); + if (err < 0) { + thumb_err("_media_thumb_get_hash_name failed - %d\n", err); + strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length); + _media_thumb_db_disconnect(); + return err; + } + + thumb_path[strlen(thumb_path)] = '\0'; + } + + thumb_dbg("Thumb path : %s", thumb_path); + + if (g_file_test(thumb_path, + G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { + thumb_warn("thumb path already exists in file system.. remove the existed file"); + _media_thumb_remove_file(thumb_path); + } + + err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha); + if (err < 0) { + thumb_err("_thumbnail_get_data failed - %d\n", err); + SAFE_FREE(data); + + strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length); + _media_thumb_db_disconnect(); + return err; + } + + //thumb_dbg("Size : %d, W:%d, H:%d", thumb_size, thumb_w, thumb_h); + //thumb_dbg("Origin W:%d, Origin H:%d\n", origin_w, origin_h); + //thumb_dbg("Thumb : %s", thumb_path); + + res_msg->msg_type = THUMB_RESPONSE; + res_msg->thumb_size = thumb_size; + res_msg->thumb_width = thumb_w; + res_msg->thumb_height = thumb_h; + res_msg->origin_width = origin_w; + res_msg->origin_height = origin_h; + + /* If the image is transparent PNG format, make png file as thumbnail of this image */ + if (alpha) { + char file_ext[10]; + err = _media_thumb_get_file_ext(origin_path, file_ext, sizeof(file_ext)); + if (strncasecmp(file_ext, "png", 3) == 0) { + int len = strlen(thumb_path); + thumb_path[len - 3] = 'p'; + thumb_path[len - 2] = 'n'; + thumb_path[len - 1] = 'g'; + } + thumb_dbg("Thumb path is changed : %s", thumb_path); + } + + err = _media_thumb_save_to_file_with_evas(data, thumb_w, thumb_h, alpha, thumb_path); + if (err < 0) { + thumb_err("save_to_file_with_evas failed - %d\n", err); + SAFE_FREE(data); + + if (msg_type == THUMB_REQUEST_DB_INSERT || msg_type == THUMB_REQUEST_ALL_MEDIA) + strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length); + + _media_thumb_db_disconnect(); + return err; + } else { + thumb_dbg("file save success\n"); + } + + /* fsync */ + int fd = 0; + fd = open(thumb_path, O_WRONLY); + if (fd < 0) { + thumb_warn("open failed"); + } else { + err = fsync(fd); + if (err == -1) { + thumb_warn("fsync failed"); + } + + close(fd); + } + /* End of fsync */ + + SAFE_FREE(data); + + /* DB update if needed */ + if (need_update_db == 1) { + err = _media_thumb_update_db(origin_path, thumb_path, res_msg->origin_width, res_msg->origin_height); + if (err < 0) { + thumb_err("_media_thumb_update_db failed : %d", err); + } + } + + _media_thumb_db_disconnect(); + + return 0; +} + +gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpointer data) +{ + thumb_err("_media_thumb_write_socket is called"); + + thumbMsg recv_msg; + int header_size = 0; + int recv_str_len = 0; + int sock = 0; + int err = MEDIA_THUMB_ERROR_NONE; + + memset((void *)&recv_msg, 0, sizeof(thumbMsg)); + sock = g_io_channel_unix_get_fd(src); + + header_size = sizeof(thumbMsg) - MAX_PATH_SIZE*2; + + if ((err = _media_thumb_recv_msg(sock, header_size, &recv_msg)) < 0) { + thumb_err("_media_thumb_recv_msg failed "); + g_io_channel_shutdown(src, TRUE, NULL); + return err; + } + + recv_str_len = strlen(recv_msg.dst_path); + thumb_dbg("recv %s(%d) from thumb daemon is successful", recv_msg.dst_path, recv_str_len); + + g_io_channel_shutdown(src, TRUE, NULL); + + if (recv_msg.status == THUMB_FAIL) { + thumb_err("Failed to make thumbnail"); + err = MEDIA_THUMB_ERROR_UNSUPPORTED; + goto callback; + } + +callback: + if (data) { + thumbUserData* cb = (thumbUserData*)data; + cb->func(err, recv_msg.dst_path, cb->user_data); + free(cb); + cb = NULL; + } + + return FALSE; +} + +int +_media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char *origin_path, thumbUserData *userData) +{ + int sock; + const char *serv_ip = "127.0.0.1"; + struct sockaddr_in serv_addr; + + int pid; + + +#ifdef _USE_MEDIA_UTIL_ + if (ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sock) < 0) { + thumb_err("ms_ipc_create_client_socket failed"); + return MEDIA_THUMB_ERROR_NETWORK; + } +#else + /* Creaete a TCP socket */ + if (_media_thumb_create_socket(CLIENT_SOCKET, &sock) < 0) { + thumb_err("_media_thumb_create_socket failed"); + return MEDIA_THUMB_ERROR_NETWORK; + } +#endif + + GIOChannel *channel = NULL; + channel = g_io_channel_unix_new(sock); + + if (msg_type != THUMB_REQUEST_CANCEL_MEDIA) { + g_io_add_watch(channel, G_IO_IN, _media_thumb_write_socket, userData ); + } + + memset(&serv_addr, 0, sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + serv_addr.sin_addr.s_addr = inet_addr(serv_ip); +#ifdef _USE_MEDIA_UTIL_ + serv_addr.sin_port = htons(MS_THUMB_CREATOR_PORT); +#else + serv_addr.sin_port = htons(THUMB_DAEMON_PORT); +#endif + + /* Connecting to the thumbnail server */ + if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) { + thumb_err("connect error : %s", strerror(errno)); + g_io_channel_shutdown(channel, TRUE, NULL); + return MEDIA_THUMB_ERROR_NETWORK; + } + + thumbMsg req_msg; + memset((void *)&req_msg, 0, sizeof(thumbMsg)); + + pid = getpid(); + req_msg.pid = pid; + req_msg.msg_type = msg_type; + req_msg.thumb_type = thumb_type; + strncpy(req_msg.org_path, origin_path, sizeof(req_msg.org_path)); + req_msg.org_path[strlen(req_msg.org_path)] = '\0'; + + req_msg.origin_path_size = strlen(req_msg.org_path) + 1; + req_msg.dest_path_size = strlen(req_msg.dst_path) + 1; + + if (req_msg.origin_path_size > MAX_PATH_SIZE || req_msg.dest_path_size > MAX_PATH_SIZE) { + thumb_err("path's length exceeds %d", MAX_PATH_SIZE); + g_io_channel_shutdown(channel, TRUE, NULL); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + unsigned char *buf = NULL; + int buf_size = 0; + _media_thumb_set_buffer(&req_msg, &buf, &buf_size); + + //thumb_dbg("buffer size : %d", buf_size); + + if (send(sock, buf, buf_size, 0) != buf_size) { + thumb_err("sendto failed: %d\n", errno); + SAFE_FREE(buf); + g_io_channel_shutdown(channel, TRUE, NULL); + return MEDIA_THUMB_ERROR_NETWORK; + } + + SAFE_FREE(buf); + thumb_dbg("Sending msg to thumbnail daemon is successful"); + + if (msg_type == THUMB_REQUEST_CANCEL_MEDIA) { + g_io_channel_shutdown(channel, TRUE, NULL); + } + + return 0; +} + diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c new file mode 100755 index 0000000..c809ead --- /dev/null +++ b/src/media-thumb-internal.c @@ -0,0 +1,1302 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 "media-thumb-debug.h" +#include "media-thumb-util.h" +#include "media-thumb-internal.h" + +#include "AGifFrameInfo.h" +#include "IfegDecodeAGIF.h" +#include "img-codec.h" +#include "img-codec-agif.h" +#include "img-codec-common.h" +#include "img-codec-osal.h" +#include "img-codec-parser.h" + +#include +#include +#include +#include + +//#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MEDA_THUMB_ROUND_UP_4(num) (((num)+3)&~3) + +int _media_thumb_get_proper_thumb_size(media_thumb_type thumb_type, + int orig_w, int orig_h, + int *thumb_w, int *thumb_h) +{ + thumb_dbg("orig w: %d orig h: %d thumb type: %d", orig_w, orig_h, thumb_type); + + BOOL portrait = FALSE; + double ratio; + + if (orig_w < orig_h) { + portrait = TRUE; + } + +#if 0 + /* Set Lager length to default size */ + if (portrait) { + if (orig_h < _media_thumb_get_width(thumb_type)) { + *thumb_h = orig_h; + } else { + *thumb_h = _media_thumb_get_width(thumb_type); + } + + ratio = (double)orig_w / (double)orig_h; + *thumb_w = *thumb_h * ratio; + } else { + if (orig_w < _media_thumb_get_width(thumb_type)) { + *thumb_w = orig_w; + } else { + *thumb_w = _media_thumb_get_width(thumb_type); + } + + ratio = (double)orig_h / (double)orig_w; + *thumb_h = *thumb_w * ratio; + } +#else + /* Set smaller length to default size */ + if (portrait) { + if (orig_w < _media_thumb_get_width(thumb_type)) { + *thumb_w = orig_w; + } else { + *thumb_w = _media_thumb_get_width(thumb_type); + } + + ratio = (double)orig_h / (double)orig_w; + *thumb_h = *thumb_w * ratio; + + } else { + + if (orig_h < _media_thumb_get_width(thumb_type)) { + *thumb_h = orig_h; + } else { + *thumb_h = _media_thumb_get_width(thumb_type); + } + + ratio = (double)orig_w / (double)orig_h; + *thumb_w = *thumb_h * ratio; + } +#endif + + /* The width of RGB888 raw data has to be rounded by 4 */ + *thumb_w = MEDA_THUMB_ROUND_UP_4(*thumb_w); + + thumb_dbg("proper thumb w: %d h: %d", *thumb_w, *thumb_h); + + return 0; +} + +int _media_thumb_get_exif_info(ExifData *ed, char *buf, int max_size, int *value, + int ifdtype, long tagtype) +{ + ExifEntry *entry; + ExifIfd ifd; + ExifTag tag; + + if (ed == NULL) { + return -1; + } + + ifd = ifdtype; + tag = tagtype; + + entry = exif_content_get_entry(ed->ifd[ifd], tag); + if (entry) { + if (tag == EXIF_TAG_ORIENTATION || + tag == EXIF_TAG_PIXEL_X_DIMENSION || + tag == EXIF_TAG_PIXEL_Y_DIMENSION) { + + if (value == NULL) { + thumb_dbg("value is NULL"); + return -1; + } + + ExifByteOrder mByteOrder = exif_data_get_byte_order(ed); + short exif_value = exif_get_short(entry->data, mByteOrder); + thumb_dbg("%s : %d", exif_tag_get_name_in_ifd(tag,ifd), exif_value); + *value = (int)exif_value; + } else { + /* Get the contents of the tag in human-readable form */ + if (buf == NULL) { + thumb_dbg("buf is NULL"); + return -1; + } + exif_entry_get_value(entry, buf, max_size); + buf[strlen(buf)] = '\0'; + + if (*buf) { + thumb_dbg("%s: %s\n", + exif_tag_get_name_in_ifd(tag, ifd), buf); + } + } + } + + return 0; +} + +int +_media_thumb_get_thumb_from_exif(ExifData *ed, + const char *file_full_path, + int orientation, + int required_width, + int required_height, + media_thumb_info *thumb_info) +{ + ExifEntry *entry; + ExifIfd ifd; + ExifTag tag; + + int err = -1; + int size = 0; + int thumb_width = 0; + int thumb_height = 0; + void *thumb = NULL; + + if (ed == NULL) { + return -1; + } + + ExifByteOrder byte_order = exif_data_get_byte_order(ed); + + ifd = EXIF_IFD_1; + tag = EXIF_TAG_COMPRESSION; + + entry = exif_content_get_entry(ed->ifd[ifd], tag); + + if (entry) { + /* Get the contents of the tag in human-readable form */ + ExifShort value = exif_get_short(entry->data, byte_order); + //thumb_dbg("%s: %d\n", exif_tag_get_name_in_ifd(tag,ifd), value); + + if (value == 6) { + thumb_dbg("There's jpeg thumb in this image"); + } else { + thumb_dbg("There's NO jpeg thumb in this image"); + return -1; + } + } else { + thumb_dbg("entry is NULL"); + return -1; + } + + /* Get width and height of thumbnail */ + tag = EXIF_TAG_IMAGE_WIDTH; + + entry = exif_content_get_entry(ed->ifd[ifd], tag); + + if (entry) { + /* Get the contents of the tag in human-readable form */ + ExifShort value = exif_get_short(entry->data, byte_order); + //thumb_dbg("%s: %d\n", exif_tag_get_name_in_ifd(tag,ifd), value); + + thumb_width = value; + } + + tag = EXIF_TAG_IMAGE_LENGTH; + + entry = exif_content_get_entry(ed->ifd[ifd], tag); + + if (entry) { + /* Get the contents of the tag in human-readable form */ + ExifShort value = exif_get_short(entry->data, byte_order); + //thumb_dbg("%s: %d\n", exif_tag_get_name_in_ifd(tag,ifd), value); + + thumb_height = value; + } + + if (ed->data && ed->size) { + //thumb_dbg("Size: %d, thumb: 0x%x\n", ed->size, ed->data); + thumb = (char *)malloc(ed->size); + + if (thumb == NULL) { + thumb_dbg("malloc failed!"); + return -1; + } + + memcpy(thumb, (void *)ed->data, ed->size); + size = ed->size; + } else { + thumb_dbg("data is NULL"); + return -1; + } + + /* Get width and height of original image from exif */ + ifd = EXIF_IFD_EXIF; + tag = EXIF_TAG_PIXEL_X_DIMENSION; + entry = exif_content_get_entry(ed->ifd[ifd], tag); + + if (entry) { + ExifShort value = exif_get_short(entry->data, byte_order); + //thumb_dbg("%s: %d\n", exif_tag_get_name_in_ifd(tag,ifd), value); + thumb_info->origin_width = value; + } else { + thumb_dbg("entry is NULL"); + } + + tag = EXIF_TAG_PIXEL_Y_DIMENSION; + entry = exif_content_get_entry(ed->ifd[ifd], tag); + + if (entry) { + ExifShort value = exif_get_short(entry->data, byte_order); + //thumb_dbg("%s: %d\n", exif_tag_get_name_in_ifd(tag,ifd), value); + thumb_info->origin_height = value; + } else { + thumb_dbg("entry is NULL"); + } + + char thumb_path[1024]; + + err = + _media_thumb_get_hash_name(file_full_path, + thumb_path, + sizeof(thumb_path)); + if (err < 0) { + thumb_dbg("_media_thumb_get_hash_name failed\n"); + SAFE_FREE(thumb); + return err; + } + + thumb_dbg("Thumb is :%s", thumb_path); + + int nwrite; + int fd = open(thumb_path, O_RDWR | O_CREAT | O_EXCL | O_SYNC, 0644); + if (fd < 0) { + if (errno == EEXIST) { + thumb_dbg("thumb alread exist!"); + } else { + thumb_dbg("open failed\n"); + SAFE_FREE(thumb); + return -1; + } + } else { + nwrite = write(fd, thumb, size); + if (nwrite < 0) { + thumb_dbg("write failed\n"); + close(fd); + + SAFE_FREE(thumb); + return -1; + } + close(fd); + } + + SAFE_FREE(thumb); + + mm_util_jpeg_yuv_data decoded = {0,}; + + err = mm_util_decode_from_jpeg_file(&decoded, thumb_path, MM_UTIL_JPEG_FMT_RGB888); + if (err < 0) { + thumb_dbg("mm_util_decode_from_jpeg_turbo_memory failed : %d", err); + return err; + } + + //thumb_dbg("size:%d, w:%d, h:%d\n", decoded.size, decoded.width, decoded.height); + + thumb_width = decoded.width; + thumb_height = decoded.height; + + media_thumb_type thumb_type; + int need_resize = 0; + unsigned int buf_size = decoded.size; + + if (required_width == _media_thumb_get_width(MEDIA_THUMB_LARGE)) { + thumb_type = MEDIA_THUMB_LARGE; + } else { + thumb_type = MEDIA_THUMB_SMALL; + } + + if (thumb_type == MEDIA_THUMB_LARGE) { + if (thumb_width < _media_thumb_get_width(MEDIA_THUMB_LARGE)) { + thumb_dbg("Thumb data in exif is too small for MEDIA_THUMB_LARGE"); + SAFE_FREE(decoded.data); + return -1; + } + } else { + if (thumb_width > _media_thumb_get_width(MEDIA_THUMB_SMALL)) { + need_resize = 1; + } + } + + if (need_resize == 1) { + int resized_w = _media_thumb_get_width(MEDIA_THUMB_LARGE); + int resized_h = _media_thumb_get_height(MEDIA_THUMB_LARGE); + + err = mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, resized_w, resized_h, &buf_size); + if (err < 0) { + thumb_dbg("mm_util_get_image_size failed : %d", err); + + SAFE_FREE(decoded.data); + return err; + } + + //thumb_dbg("size(RGB888) : %d", buf_size); + + unsigned char *dst = (unsigned char *)malloc(buf_size); + if (dst == NULL) { + thumb_err("Failed to allocate memory!"); + SAFE_FREE(decoded.data); + return -1; + } + + if (mm_util_resize_image(decoded.data, thumb_width, + thumb_height, MM_UTIL_IMG_FMT_RGB888, + dst, (unsigned int *)&resized_w, + (unsigned int *)&resized_h) < 0) { + thumb_err("Failed to resize the thumbnails"); + + SAFE_FREE(decoded.data); + SAFE_FREE(dst); + + return -1; + } + + SAFE_FREE(decoded.data); + decoded.data = dst; + decoded.width = thumb_width = resized_w; + decoded.height = thumb_height = resized_h; + } + + if (orientation == ROT_90 || orientation == ROT_180 || orientation == ROT_270) { + /* Start to decode to rotate */ + unsigned char *rotated = NULL; + unsigned int r_w = decoded.height; + unsigned int r_h = decoded.width; + unsigned int r_size = 0; + mm_util_img_rotate_type rot_type = MM_UTIL_ROTATE_0; + + if (orientation == ROT_90) { + rot_type = MM_UTIL_ROTATE_90; + } else if (orientation == ROT_180) { + rot_type = MM_UTIL_ROTATE_180; + r_w = decoded.width; + r_h = decoded.height; + } else if (orientation == ROT_270) { + rot_type = MM_UTIL_ROTATE_270; + } + + err = mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, r_w, r_h, &r_size); + if (err < 0) { + thumb_dbg("mm_util_get_image_size failed : %d", err); + SAFE_FREE(decoded.data); + return err; + } + + //thumb_dbg("Size of Rotated : %d", r_size); + + rotated = (unsigned char *)malloc(r_size); + err = mm_util_rotate_image(decoded.data, decoded.width, decoded.height, + MM_UTIL_IMG_FMT_RGB888, + rotated, &r_w, &r_h, + rot_type); + + if (err < 0) { + thumb_err("mm_util_rotate_image failed : %d", err); + SAFE_FREE(decoded.data); + SAFE_FREE(rotated); + return err; + } else { + thumb_dbg("mm_util_rotate_image succeed"); + } + + SAFE_FREE(decoded.data); + + //thumb_dbg("Width : %d, Height : %d", r_w, r_h); + thumb_info->data = rotated; + thumb_info->size = r_size; + thumb_info->width = r_w; + thumb_info->height = r_h; + } else if (orientation == NORMAL) { + thumb_info->data = decoded.data; + thumb_info->size = buf_size; + thumb_info->width = thumb_width; + thumb_info->height = thumb_height; + } else { + thumb_warn("Unknown orientation"); + SAFE_FREE(decoded.data); + return -1; + } + + return 0; +} + +int _media_thumb_resize_data(unsigned char *src_data, + int src_width, + int src_height, + mm_util_img_format src_format, + media_thumb_info *thumb_info, + int dst_width, + int dst_height) +{ + int thumb_width = dst_width; + int thumb_height = dst_height; + unsigned int buf_size = 0; + + if (mm_util_get_image_size(src_format, thumb_width, + thumb_height, &buf_size) < 0) { + thumb_err("Failed to get buffer size"); + return MEDIA_THUMB_ERROR_MM_UTIL; + } + + thumb_dbg("mm_util_get_image_size : %d", buf_size); + + unsigned char *dst = (unsigned char *)malloc(buf_size); + + if (mm_util_resize_image((unsigned char *)src_data, src_width, + src_height, src_format, + dst, (unsigned int *)&thumb_width, + (unsigned int *)&thumb_height) < 0) { + thumb_err("Failed to resize the thumbnails"); + + SAFE_FREE(dst); + + return MEDIA_THUMB_ERROR_MM_UTIL; + } + + thumb_info->size = buf_size; + thumb_info->width = thumb_width; + thumb_info->height = thumb_height; + thumb_info->data = malloc(buf_size); + memcpy(thumb_info->data, dst, buf_size); + + SAFE_FREE(dst); + + return 0; +} + +int _media_thumb_get_wh_with_evas(const char *origin_path, int *width, int *height) +{ + /* using evas to get w/h */ + Ecore_Evas *ee = + ecore_evas_buffer_new(0, 0); + if (!ee) { + thumb_err("ecore_evas_new fails"); + return -1; + } + Evas *evas = ecore_evas_get(ee); + if (!evas) { + thumb_err("ecore_evas_get fails"); + ecore_evas_free(ee); + return -1; + } + + Evas_Object *image_object = + evas_object_image_add(evas); + if (!image_object) { + thumb_err + ("evas_object_image_add fails"); + ecore_evas_free(ee); + return -1; + } + + evas_object_image_file_set(image_object, + origin_path, + NULL); + evas_object_image_size_get(image_object, + width, height); + + thumb_dbg("Width:%d, Height:%d", *width, *height); + + ecore_evas_free(ee); + + return 0; +} + +int _media_thumb_decode_with_evas(const char *origin_path, + int thumb_width, int thumb_height, + media_thumb_info *thumb_info, int need_scale, int orientation) +{ + Ecore_Evas *resize_img_ee; + resize_img_ee = + ecore_evas_buffer_new(thumb_width, thumb_height); + + if (!resize_img_ee) { + thumb_err("Failed to create a new ecore evas buffer\n"); + return -1; + } + + Evas *resize_img_e = ecore_evas_get(resize_img_ee); + if (!resize_img_e) { + thumb_err("Failed to ecore_evas_get\n"); + ecore_evas_free(resize_img_ee); + return -1; + } + + Evas_Object *source_img = evas_object_image_add(resize_img_e); + if (!source_img) { + thumb_err("evas_object_image_add failed\n"); + ecore_evas_free(resize_img_ee); + return -1; + } + + evas_object_image_file_set(source_img, origin_path, NULL); + + /* Get w/h of original image */ + int width = 0; + int height = 0; + + evas_object_image_size_get(source_img, &width, &height); + thumb_info->origin_width = width; + thumb_info->origin_height = height; + //thumb_dbg("origin width:%d, origin height:%d", width, height); + + if ((need_scale == 1) && (width * height > THUMB_MAX_ALLOWED_MEM_FOR_THUMB)) { + thumb_dbg("This is too large image. so this's scale is going to be down"); + evas_object_image_load_scale_down_set(source_img, 10); + } + + evas_object_image_load_orientation_set(source_img, 1); + + int rotated_orig_w = 0; + int rotated_orig_h = 0; + + if (orientation == ROT_90 || orientation == ROT_270) { + rotated_orig_w = height; + rotated_orig_h = width; + } else { + rotated_orig_w = width; + rotated_orig_h = height; + } + + //thumb_dbg("rotated - origin width:%d, origin height:%d", rotated_orig_w, rotated_orig_h); + + int err = -1; + media_thumb_type thumb_type; + + if (thumb_width == _media_thumb_get_width(MEDIA_THUMB_LARGE)) { + thumb_type = MEDIA_THUMB_LARGE; + } else { + thumb_type = MEDIA_THUMB_SMALL; + } + + err = _media_thumb_get_proper_thumb_size(thumb_type, + rotated_orig_w, rotated_orig_h, + &thumb_width, &thumb_height); + if (err < 0) { + thumb_err("_media_thumb_get_proper_thumb_size failed: %d", err); + ecore_evas_free(resize_img_ee); + return err; + } + + ecore_evas_resize(resize_img_ee, thumb_width, thumb_height); + + evas_object_image_load_size_set(source_img, thumb_width, thumb_height); + evas_object_image_fill_set(source_img, + 0, 0, + thumb_width, + thumb_height); + + evas_object_image_filled_set(source_img, 1); + evas_object_resize(source_img, + thumb_width, + thumb_height); + evas_object_show(source_img); + + /* Set alpha from original */ + thumb_info->alpha = evas_object_image_alpha_get(source_img); + + /* Create target buffer and copy origin resized img to it */ + Ecore_Evas *target_ee = ecore_evas_buffer_new( + thumb_width, thumb_height); + if (!target_ee) { + thumb_err("Failed to create a ecore evas\n"); + ecore_evas_free(resize_img_ee); + return -1; + } + + Evas *target_evas = ecore_evas_get(target_ee); + if (!target_evas) { + thumb_err("Failed to ecore_evas_get\n"); + ecore_evas_free(resize_img_ee); + ecore_evas_free(target_ee); + return -1; + } + + Evas_Object *ret_image = + evas_object_image_add(target_evas); + + evas_object_image_size_set(ret_image, + thumb_width, + thumb_height); + + evas_object_image_fill_set(ret_image, 0, + 0, + thumb_width, + thumb_height); + + evas_object_image_filled_set(ret_image, EINA_TRUE); + evas_object_image_data_set(ret_image, + (int *)ecore_evas_buffer_pixels_get(resize_img_ee)); + evas_object_image_data_update_add(ret_image, 0, 0, thumb_width, + thumb_height); + + unsigned int buf_size = 0; + + if (mm_util_get_image_size(MM_UTIL_IMG_FMT_BGRA8888, thumb_width, + thumb_height, &buf_size) < 0) { + thumb_err("Failed to get buffer size"); + + ecore_evas_free(resize_img_ee); + ecore_evas_free(target_ee); + + return MEDIA_THUMB_ERROR_MM_UTIL; + } + + //thumb_dbg("mm_util_get_image_size : %d", buf_size); + + thumb_info->size = buf_size; + thumb_info->width = thumb_width; + thumb_info->height = thumb_height; + thumb_info->data = malloc(buf_size); + memcpy(thumb_info->data, evas_object_image_data_get(ret_image, 1), buf_size); + + ecore_evas_free(target_ee); + ecore_evas_free(resize_img_ee); + + return 0; +} + +mm_util_img_format _media_thumb_get_format(media_thumb_format src_format) +{ + switch(src_format) { + case MEDIA_THUMB_BGRA: + return MM_UTIL_IMG_FMT_BGRA8888; + case MEDIA_THUMB_RGB888: + return MM_UTIL_IMG_FMT_RGB888; + default: + return -1; + } +} + + +int _media_thumb_convert_data(media_thumb_info *thumb_info, + int thumb_width, + int thumb_height, + mm_util_img_format src_format, + mm_util_img_format dst_format) +{ + int err = -1; + unsigned int buf_size = 0; + unsigned char *src_data = thumb_info->data; + unsigned char *dst_data = NULL; + + thumb_dbg("src format:%d, dst format:%d", src_format, dst_format); + + if (mm_util_get_image_size(dst_format, thumb_width, + thumb_height, &buf_size) < 0) { + thumb_err("Failed to get buffer size"); + return MEDIA_THUMB_ERROR_MM_UTIL; + } + + thumb_dbg("mm_util_get_image_size : %d", buf_size); + + dst_data = (unsigned char *)malloc(buf_size); + + if (src_format == MM_UTIL_IMG_FMT_RGB888 && + dst_format == MM_UTIL_IMG_FMT_BGRA8888) { + + int i = 0, j; + for (j = 0; j < thumb_width * 3 * thumb_height; + j += 3) { + dst_data[i++] = (src_data[j + 2]); + dst_data[i++] = (src_data[j + 1]); + dst_data[i++] = (src_data[j]); + dst_data[i++] = 0x0; + } + + } else { + err = mm_util_convert_colorspace(src_data, + thumb_width, + thumb_height, + src_format, + dst_data, + dst_format); + + if (err < 0) { + thumb_err("Failed to change from rgb888 to argb8888 %d", err); + SAFE_FREE(dst_data); + return MEDIA_THUMB_ERROR_MM_UTIL; + } + } + + SAFE_FREE(thumb_info->data); + thumb_info->data = dst_data; + thumb_info->size = buf_size; + + thumb_dbg("_media_thumb_convert_data success"); + + return 0; +} + +int _media_thumb_convert_format(media_thumb_info *thumb_info, + media_thumb_format src_format, + media_thumb_format dst_format) +{ + int err = -1; + + if (src_format == dst_format) { + //thumb_dbg("src_format == dst_format"); + return 0; + } + + mm_util_img_format src_mm_format; + mm_util_img_format dst_mm_format; + + src_mm_format = _media_thumb_get_format(src_format); + dst_mm_format = _media_thumb_get_format(dst_format); + + if (src_mm_format == -1 || dst_mm_format == -1) { + thumb_err("Format is invalid"); + return MEDIA_THUMB_ERROR_UNSUPPORTED; + } + + err = _media_thumb_convert_data(thumb_info, + thumb_info->width, + thumb_info->height, + src_mm_format, + dst_mm_format); + + if (err < 0) { + thumb_err("media_thumb_convert_format failed : %d", err); + return err; + } + + return 0; +} + +int _media_thumb_agif(const char *origin_path, + ImgImageInfo *image_info, + int thumb_width, + int thumb_height, + media_thumb_format format, + media_thumb_info *thumb_info) +{ + int err = -1; + unsigned int *thumb = NULL; + media_thumb_type thumb_type; + + thumb = ImgGetFirstFrameAGIFAtSize(origin_path, image_info); + + if (!thumb) { + thumb_err("Frame data is NULL!!"); + return MEDIA_THUMB_ERROR_UNSUPPORTED; + } + + if (thumb_width == _media_thumb_get_width(MEDIA_THUMB_LARGE)) { + thumb_type = MEDIA_THUMB_LARGE; + } else { + thumb_type = MEDIA_THUMB_SMALL; + } + + err = _media_thumb_get_proper_thumb_size(thumb_type, + thumb_info->origin_width, thumb_info->origin_height, + &thumb_width, &thumb_height); + if (err < 0) { + thumb_err("_media_thumb_get_proper_thumb_size failed: %d", err); + SAFE_FREE(thumb); + return err; + } + + err = _media_thumb_resize_data((unsigned char *)thumb, + image_info->width, + image_info->height, + MM_UTIL_IMG_FMT_RGB888, + thumb_info, + thumb_width, + thumb_height); + + if (err < 0) { + thumb_err("_media_thumb_resize_data failed: %d", err); + SAFE_FREE(thumb); + return err; + } + + SAFE_FREE(thumb); + + err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_RGB888, format); + if (err < 0) { + thumb_err("_media_thumb_convert_format falied: %d", err); + SAFE_FREE(thumb_info->data); + return err; + } + + return 0; +} + +int _media_thumb_png(const char *origin_path, + int thumb_width, + int thumb_height, + media_thumb_format format, + media_thumb_info *thumb_info) +{ + int err = -1; + err = _media_thumb_decode_with_evas(origin_path, thumb_width, thumb_height, thumb_info, 0, NORMAL); + + if (err < 0) { + thumb_err("decode_with_evas failed : %d", err); + return err; + } + + err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format); + if (err < 0) { + thumb_err("_media_thumb_convert_format falied: %d", err); + SAFE_FREE(thumb_info->data); + return err; + } + + return 0; +} + +int _media_thumb_bmp(const char *origin_path, + int thumb_width, + int thumb_height, + media_thumb_format format, + media_thumb_info *thumb_info) +{ + int err = -1; + err = _media_thumb_decode_with_evas(origin_path, thumb_width, thumb_height, thumb_info, 0, NORMAL); + + if (err < 0) { + thumb_err("decode_with_evas failed : %d", err); + return err; + } + + err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format); + if (err < 0) { + thumb_err("_media_thumb_convert_format falied: %d", err); + SAFE_FREE(thumb_info->data); + return err; + } + + return 0; +} + +int _media_thumb_wbmp(const char *origin_path, + int thumb_width, + int thumb_height, + media_thumb_format format, + media_thumb_info *thumb_info) +{ + int err = -1; + err = _media_thumb_decode_with_evas(origin_path, thumb_width, thumb_height, thumb_info, 0, NORMAL); + + if (err < 0) { + thumb_err("decode_with_evas failed : %d", err); + return err; + } + + err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format); + if (err < 0) { + thumb_err("_media_thumb_convert_format falied: %d", err); + SAFE_FREE(thumb_info->data); + return err; + } + + return 0; +} + +int _media_thumb_gif(const char *origin_path, + int thumb_width, + int thumb_height, + media_thumb_format format, + media_thumb_info *thumb_info) +{ + int err = -1; + err = _media_thumb_decode_with_evas(origin_path, thumb_width, thumb_height, thumb_info, 0, NORMAL); + + if (err < 0) { + thumb_err("decode_with_evas failed : %d", err); + return err; + } + + err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format); + if (err < 0) { + thumb_err("_media_thumb_convert_format falied: %d", err); + SAFE_FREE(thumb_info->data); + return err; + } + + return 0; +} + +int _media_thumb_jpeg(const char *origin_path, + int thumb_width, + int thumb_height, + media_thumb_format format, + media_thumb_info *thumb_info) +{ + int err = -1; + ExifData *ed = NULL; + int thumb_done = 0; + int orientation = NORMAL; + + /* Load an ExifData object from an EXIF file */ + ed = exif_data_new_from_file(origin_path); + + if (ed) { + /* First, Get orientation from exif */ + err = _media_thumb_get_exif_info(ed, NULL, 0, &orientation, EXIF_IFD_0, EXIF_TAG_ORIENTATION); + + if (err < 0) { + thumb_warn("_media_thumb_get_exif_info failed"); + } + + /* Second, Get thumb from exif */ + err = _media_thumb_get_thumb_from_exif(ed, origin_path, orientation, thumb_width, thumb_height, thumb_info); + + if (err < 0) { + thumb_dbg("_media_thumb_get_thumb_from_exif failed"); + } else { + thumb_done = 1; + thumb_dbg("_media_thumb_get_thumb_from_exif succeed"); + + mm_util_img_format dst_format = _media_thumb_get_format(format); + + err = _media_thumb_convert_data(thumb_info, + thumb_info->width, + thumb_info->height, + MM_UTIL_IMG_FMT_RGB888, + dst_format); + + if (err < 0) { + thumb_err("_media_thumb_convert_data failed : %d", err); + exif_data_unref(ed); + return err; + } + } + + exif_data_unref(ed); + } + + if (!thumb_done) { + + err = _media_thumb_decode_with_evas(origin_path, thumb_width, thumb_height, thumb_info, 0, orientation); + + if (err < 0) { + thumb_err("decode_with_evas failed : %d", err); + return err; + } + + err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format); + if (err < 0) { + thumb_err("_media_thumb_convert_format falied: %d", err); + SAFE_FREE(thumb_info->data); + return err; + } + } + + return 0; +} + +int +_media_thumb_image(const char *origin_path, + int thumb_width, + int thumb_height, + media_thumb_format format, + media_thumb_info *thumb_info) +{ + int err = -1; + int image_type = 0; + int origin_w = 0; + int origin_h = 0; + ImgImageInfo image_info = { 0 }; + + image_type = ImgGetInfoFile(origin_path, &image_info); + + thumb_info->origin_width = origin_w = image_info.width; + thumb_info->origin_height = origin_h = image_info.height; + + thumb_dbg("image type is %d\n", image_type); + + if ((image_type != IMG_CODEC_JPEG) && + (origin_w * origin_h > THUMB_MAX_ALLOWED_MEM_FOR_THUMB)) { + thumb_warn("This original image is too big"); + return MEDIA_THUMB_ERROR_UNSUPPORTED; + } + + if (image_type == IMG_CODEC_AGIF) { + err = _media_thumb_agif(origin_path, &image_info, thumb_width, thumb_height, format, thumb_info); + } else if (image_type == IMG_CODEC_JPEG) { + err = _media_thumb_jpeg(origin_path, thumb_width, thumb_height, format, thumb_info); + } else if (image_type == IMG_CODEC_PNG) { + err = _media_thumb_png(origin_path, thumb_width, thumb_height, format, thumb_info); + } else if (image_type == IMG_CODEC_GIF) { + err = _media_thumb_gif(origin_path, thumb_width, thumb_height, format, thumb_info); + } else if (image_type == IMG_CODEC_BMP) { + err = _media_thumb_bmp(origin_path, thumb_width, thumb_height, format, thumb_info); + } else { + char file_ext[10]; + err = _media_thumb_get_file_ext(origin_path, file_ext, sizeof(file_ext)); + if (err < 0) { + thumb_warn("_media_thumb_get_file_ext failed"); + } else { + if (strcasecmp(file_ext, "wbmp") == 0) { + image_type = IMG_CODEC_WBMP; + int wbmp_width = 0; + int wbmp_height = 0; + + err = _media_thumb_get_wh_with_evas(origin_path, &wbmp_width, &wbmp_height); + if (err < 0) { + thumb_err("_media_thumb_get_wh_with_evas in WBMP : %d", err); + return err; + } + + if (wbmp_width * wbmp_height > THUMB_MAX_ALLOWED_MEM_FOR_THUMB) { + thumb_warn("This original image is too big"); + return MEDIA_THUMB_ERROR_UNSUPPORTED; + } + + thumb_info->origin_width = wbmp_width; + thumb_info->origin_height = wbmp_height; + + err = _media_thumb_wbmp(origin_path, thumb_width, thumb_height, format, thumb_info); + + return err; + } + } + + thumb_warn("Unsupported image type"); + return MEDIA_THUMB_ERROR_UNSUPPORTED; + } + + return err; +} + +int +_media_thumb_video(const char *origin_path, + int thumb_width, + int thumb_height, + media_thumb_format format, + media_thumb_info *thumb_info) +{ + int err = -1; + + MMHandleType content = (MMHandleType) NULL; + void *frame = NULL; + int video_track_num = 0; + char *err_msg = NULL; + int is_drm = 0; + int size = 0; + int width = 0; + int height = 0; + int ret = 0; + drm_bool_type_e drm_type; + + ret = (drm_is_drm_file(origin_path, &drm_type) == 1); + if (ret < 0) { + thumb_err("drm_is_drm_file falied : %d", ret); + drm_type = DRM_FALSE; + } + + is_drm = drm_type; + err = mm_file_create_content_attrs(&content, origin_path); + + if (err < 0) { + thumb_err("mm_file_create_content_attrs fails : %d", err); + return MEDIA_THUMB_ERROR_MM_UTIL; + } + + err = + mm_file_get_attrs(content, &err_msg, + MM_FILE_CONTENT_VIDEO_TRACK_COUNT, + &video_track_num, NULL); + + if (err != 0) { + thumb_err("mm_file_get_attrs fails : %s", err_msg); + SAFE_FREE(err_msg); + mm_file_destroy_content_attrs(content); + return MEDIA_THUMB_ERROR_MM_UTIL; + } + + /* MMF api handle both normal and DRM video */ + if (video_track_num > 0 || is_drm) { + + err = mm_file_get_attrs(content, &err_msg, + MM_FILE_CONTENT_VIDEO_WIDTH, + &width, + MM_FILE_CONTENT_VIDEO_HEIGHT, + &height, + MM_FILE_CONTENT_VIDEO_THUMBNAIL, &frame, /* raw image is RGB888 format */ + &size, NULL); + + if (err != 0) { + thumb_err("mm_file_get_attrs fails : %s", err_msg); + SAFE_FREE(err_msg); + mm_file_destroy_content_attrs(content); + return MEDIA_THUMB_ERROR_MM_UTIL; + } + + thumb_dbg("video width: %d", width); + thumb_dbg("video height: %d", height); + thumb_dbg("thumbnail size=%d", size); + thumb_dbg("frame = 0x%x", frame); + + if (frame == NULL || width == 0 || height == 0) { + thumb_err("Failed to get frame data"); + mm_file_destroy_content_attrs(content); + return MEDIA_THUMB_ERROR_MM_UTIL; + } + + media_thumb_type thumb_type; + if (thumb_width == _media_thumb_get_width(MEDIA_THUMB_LARGE)) { + thumb_type = MEDIA_THUMB_LARGE; + } else { + thumb_type = MEDIA_THUMB_SMALL; + } + + thumb_info->origin_width = width; + thumb_info->origin_height = height; + + err = _media_thumb_get_proper_thumb_size(thumb_type, width, height, &thumb_width, &thumb_height); + + if (width > thumb_width || height > thumb_height) { + err = _media_thumb_resize_data(frame, + width, + height, + MM_UTIL_IMG_FMT_RGB888, + thumb_info, + thumb_width, + thumb_height); + + if (err < 0) { + thumb_err("_media_thumb_resize_data failed - %d", err); + SAFE_FREE(thumb_info->data); + mm_file_destroy_content_attrs(content); + return err; + } + } else { + + thumb_info->size = size; + thumb_info->width = width; + thumb_info->height = height; + thumb_info->data = malloc(size); + memcpy(thumb_info->data, frame, size); + } + + mm_file_destroy_content_attrs(content); + + /* Get Content Tag attribute for orientatin */ + MMHandleType tag = (MMHandleType) NULL; + char *p = NULL; + int size = -1; + err = mm_file_create_tag_attrs(&tag, origin_path); + mm_util_img_rotate_type rot_type = MM_UTIL_ROTATE_0; + + if (err == MM_ERROR_NONE) { + err = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_ROTATE, &p, &size, NULL); + if (err == MM_ERROR_NONE && size >= 0) { + + if (p == NULL) { + rot_type = MM_UTIL_ROTATE_0; + } else { + if (strncmp(p, "90", size) == 0) { + rot_type = MM_UTIL_ROTATE_90; + } else if(strncmp(p, "180", size) == 0) { + rot_type = MM_UTIL_ROTATE_180; + } else if(strncmp(p, "270", size) == 0) { + rot_type = MM_UTIL_ROTATE_270; + } else { + rot_type = MM_UTIL_ROTATE_0; + } + } + } else { + rot_type = MM_UTIL_ROTATE_0; + SAFE_FREE(err_msg); + } + } else { + rot_type = MM_UTIL_ROTATE_0; + } + + err = mm_file_destroy_tag_attrs(tag); + if (err != MM_ERROR_NONE) { + thumb_err("fail to free tag attr - err(%x)", err); + } + + if (rot_type == MM_UTIL_ROTATE_90 || rot_type == MM_UTIL_ROTATE_180 || rot_type == MM_UTIL_ROTATE_270) { + /* Start to decode to rotate */ + unsigned char *rotated = NULL; + unsigned int r_w = thumb_info->height; + unsigned int r_h = thumb_info->width; + unsigned int r_size = 0; + + if (rot_type == MM_UTIL_ROTATE_180) { + r_w = thumb_info->width; + r_h = thumb_info->height; + } + + err = mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, r_w, r_h, &r_size); + if (err < 0) { + thumb_dbg("mm_util_get_image_size failed : %d", err); + SAFE_FREE(thumb_info->data); + return err; + } + + //thumb_dbg("Size of Rotated : %d", r_size); + rotated = (unsigned char *)malloc(r_size); + err = mm_util_rotate_image(thumb_info->data, thumb_info->width, thumb_info->height, + MM_UTIL_IMG_FMT_RGB888, + rotated, &r_w, &r_h, + rot_type); + + if (err < 0) { + thumb_err("mm_util_rotate_image failed : %d", err); + SAFE_FREE(thumb_info->data); + SAFE_FREE(rotated); + return err; + } else { + thumb_dbg("mm_util_rotate_image succeed"); + } + + SAFE_FREE(thumb_info->data); + + thumb_info->data = rotated; + thumb_info->size = r_size; + thumb_info->width = r_w; + thumb_info->height = r_h; + } + + err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_RGB888, format); + if (err < 0) { + thumb_err("_media_thumb_convert_format falied: %d", err); + SAFE_FREE(thumb_info->data); + return err; + } + } else { + thumb_dbg("no contents information\n"); + frame = NULL; + mm_file_destroy_content_attrs(content); + + return MEDIA_THUMB_ERROR_UNSUPPORTED; + } + + return 0; +} + diff --git a/src/media-thumbnail.c b/src/media-thumbnail.c new file mode 100755 index 0000000..11bcc0b --- /dev/null +++ b/src/media-thumbnail.c @@ -0,0 +1,288 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 "media-thumbnail.h" +#include "media-thumb-debug.h" +#include "media-thumb-util.h" +#include "media-thumb-internal.h" +#include "media-thumb-ipc.h" +//#include "media-thumb-db.h" + +#include + +int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max_length) +{ + int err = -1; + //int need_update_db = 0; + media_thumb_info thumb_info; + + if (origin_path == NULL || thumb_path == NULL) { + thumb_err("Invalid parameter"); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + if (!g_file_test + (origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { + thumb_err("Original path(%s) doesn't exist.", origin_path); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + if (max_length <= 0) { + thumb_err("Length is invalid"); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + int store_type = -1; + store_type = _media_thumb_get_store_type_by_path(origin_path); + + if ((store_type != THUMB_PHONE) && (store_type != THUMB_MMC)) { + thumb_err("origin path(%s) is invalid", origin_path); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + thumb_err("Path : %s", origin_path); +/* + err = _media_thumb_db_connect(); + if (err < 0) { + thumb_err("_media_thumb_mb_svc_connect failed: %d", err); + return MEDIA_THUMB_ERROR_DB; + } + + err = _media_thumb_get_thumb_from_db(origin_path, thumb_path, max_length, &need_update_db); + if (err == 0) { + _media_thumb_db_disconnect(); + return MEDIA_THUMB_ERROR_NONE; + } +*/ + /* Request for thumb file to the daemon "Thumbnail generator" */ + err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info); + if (err < 0) { + thumb_err("_media_thumb_request failed : %d", err); + //_media_thumb_db_disconnect(); + return err; + } +/* + // Need to update DB once generating thumb is done + if (need_update_db) { + err = _media_thumb_update_db(origin_path, thumb_path, thumb_info.origin_width, thumb_info.origin_height); + if (err < 0) { + thumb_err("_media_thumb_update_db failed : %d", err); + } + } + + _media_thumb_db_disconnect(); +*/ + return MEDIA_THUMB_ERROR_NONE; +} + +int thumbnail_request_save_to_file(const char *origin_path, media_thumb_type thumb_type, const char *thumb_path) +{ + int err = -1; + + if (origin_path == NULL || thumb_path == NULL) { + thumb_err("Invalid parameter"); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + media_thumb_info thumb_info; + char tmp_thumb_path[MAX_PATH_SIZE] = {0,}; + + strncpy(tmp_thumb_path, thumb_path, sizeof(tmp_thumb_path)); + + /* Request for thumb file to the daemon "Thumbnail generator" */ + err = _media_thumb_request(THUMB_REQUEST_SAVE_FILE, thumb_type, origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info); + if (err < 0) { + thumb_err("_media_thumb_request failed : %d", err); + return err; + } + + return MEDIA_THUMB_ERROR_NONE; +} + +int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_path, int max_length, int *origin_width, int *origin_height) +{ + int err = -1; + //int need_update_db = 0; + media_thumb_info thumb_info; + + if (origin_path == NULL || thumb_path == NULL) { + thumb_err("Invalid parameter"); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + if (origin_width == NULL || origin_height == NULL) { + thumb_err("Invalid parameter ( width or height )"); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + if (!g_file_test + (origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { + thumb_err("Original path(%s) doesn't exist.", origin_path); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + if (max_length <= 0) { + thumb_err("Length is invalid"); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + int store_type = -1; + store_type = _media_thumb_get_store_type_by_path(origin_path); + + if ((store_type != THUMB_PHONE) && (store_type != THUMB_MMC)) { + thumb_err("origin path(%s) is invalid", origin_path); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + thumb_err("Path : %s", origin_path); +/* + err = _media_thumb_db_connect(); + if (err < 0) { + thumb_err("_media_thumb_mb_svc_connect failed: %d", err); + return MEDIA_THUMB_ERROR_DB; + } + + err = _media_thumb_get_thumb_from_db_with_size(origin_path, thumb_path, max_length, &need_update_db, &width, &height); + if (err == 0) { + _media_thumb_db_disconnect(); + return MEDIA_THUMB_ERROR_NONE; + } +*/ + /* Request for thumb file to the daemon "Thumbnail generator" */ + err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info); + if (err < 0) { + thumb_err("_media_thumb_request failed : %d", err); + //_media_thumb_db_disconnect(); + return err; + } + + *origin_width = thumb_info.origin_width; + *origin_height = thumb_info.origin_height; + + //_media_thumb_db_disconnect(); + return MEDIA_THUMB_ERROR_NONE; +} + +int thumbnail_request_extract_all_thumbs(void) +{ + int err = -1; + + media_thumb_info thumb_info; + media_thumb_type thumb_type = MEDIA_THUMB_LARGE; + char tmp_origin_path[MAX_PATH_SIZE] = {0,}; + char tmp_thumb_path[MAX_PATH_SIZE] = {0,}; + + /* Request for thumb file to the daemon "Thumbnail generator" */ + err = _media_thumb_request(THUMB_REQUEST_ALL_MEDIA, thumb_type, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info); + if (err < 0) { + thumb_err("_media_thumb_request failed : %d", err); + return err; + } + + return MEDIA_THUMB_ERROR_NONE; +} + +int thumbnail_request_from_db_async(const char *origin_path, ThumbFunc func, void *user_data) +{ + int err = -1; + + if (origin_path == NULL) { + thumb_err("Invalid parameter"); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + if (!g_file_test + (origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { + thumb_err("Original path(%s) doesn't exist.", origin_path); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + int store_type = -1; + store_type = _media_thumb_get_store_type_by_path(origin_path); + + if ((store_type != THUMB_PHONE) && (store_type != THUMB_MMC)) { + thumb_err("origin path(%s) is invalid", origin_path); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + thumb_err("Path : %s", origin_path); + + thumbUserData *userData = (thumbUserData*)malloc(sizeof(thumbUserData)); + userData->func = (ThumbFunc)func; + userData->user_data = user_data; + + /* Request for thumb file to the daemon "Thumbnail generator" */ + err = _media_thumb_request_async(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, userData); + if (err < 0) { + thumb_err("_media_thumb_request failed : %d", err); + SAFE_FREE(userData); + return err; + } + + return MEDIA_THUMB_ERROR_NONE; +} + +int _media_thumbnail_cancel_cb(int error_code, char* path, void* data) +{ + thumb_dbg("Error code : %d", error_code); + if (path) thumb_dbg("Cancel : %s", path); + + return MEDIA_THUMB_ERROR_NONE; +} + +int thumbnail_request_cancel_media(const char *origin_path) +{ + int err = -1; + + media_thumb_type thumb_type = MEDIA_THUMB_LARGE; + + if (origin_path == NULL) { + thumb_err("Invalid parameter"); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + err = _media_thumb_request_async(THUMB_REQUEST_CANCEL_MEDIA, thumb_type, origin_path, NULL); + if (err < 0) { + thumb_err("_media_thumb_request failed : %d", err); + return err; + } + + return MEDIA_THUMB_ERROR_NONE; +} + +int thumbnail_request_cancel_all() +{ + int err = -1; + + media_thumb_info thumb_info; + media_thumb_type thumb_type = MEDIA_THUMB_LARGE; + char tmp_origin_path[MAX_PATH_SIZE] = {0,}; + char tmp_thumb_path[MAX_PATH_SIZE] = {0,}; + + /* Request for thumb file to the daemon "Thumbnail generator" */ + err = _media_thumb_request(THUMB_REQUEST_CANCEL_ALL, thumb_type, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info); + if (err < 0) { + thumb_err("_media_thumb_request failed : %d", err); + return err; + } + + return MEDIA_THUMB_ERROR_NONE; +} diff --git a/src/util/media-thumb-db.c b/src/util/media-thumb-db.c new file mode 100755 index 0000000..e3ca193 --- /dev/null +++ b/src/util/media-thumb-db.c @@ -0,0 +1,609 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 "media-thumb-db.h" +#include "media-thumb-util.h" + +#include +#include +#include +#include + + +#ifdef _USE_MEDIA_UTIL_ +static __thread MediaDBHandle *db_handle; +#else +static __thread sqlite3 *db_handle; +#endif + +static int _media_thumb_busy_handler(void *pData, int count) +{ + usleep(50000); + thumb_dbg("_media_thumb_busy_handler called : %d\n", count); + + return 100 - count; +} + +sqlite3 *_media_thumb_db_get_handle() +{ + return db_handle; +} + +int +_media_thumb_sqlite_connect(sqlite3 **handle) +{ + int err = -1; + + err = db_util_open(MEDIA_DATABASE_NAME, handle, + DB_UTIL_REGISTER_HOOK_METHOD); + + if (SQLITE_OK != err) { + *handle = NULL; + return -1; + } + + /*Register busy handler*/ + if (*handle) { + err = sqlite3_busy_handler(*handle, _media_thumb_busy_handler, NULL); + if (SQLITE_OK != err) { + if (*handle) { + thumb_err("[sqlite] %s\n", sqlite3_errmsg(*handle)); + db_util_close(*handle); + } + *handle = NULL; + + return -1; + } + } else { + *handle = NULL; + return -1; + } + + return MEDIA_THUMB_ERROR_NONE; +} + +int +_media_thumb_sqlite_disconnect(sqlite3 *handle) +{ + int err = -1; + if (handle != NULL) { + err = db_util_close(handle); + + if (SQLITE_OK != err) { + handle = NULL; + return -1; + } + } + + return MEDIA_THUMB_ERROR_NONE; +} + +int +_media_thumb_get_type_from_db(sqlite3 *handle, + const char *origin_path, + int *type) +{ + thumb_dbg("Origin path : %s", origin_path); + + if (handle == NULL) { + thumb_err("DB handle is NULL"); + return -1; + } + + int err = -1; + char *path_string = NULL; + char *query_string = NULL; + sqlite3_stmt *stmt = NULL; + + path_string = sqlite3_mprintf("%s", origin_path); + query_string = sqlite3_mprintf(SELECT_TYPE_BY_PATH, path_string); + + thumb_dbg("Query: %s", query_string); + + err = sqlite3_prepare_v2(handle, query_string, strlen(query_string), &stmt, NULL); + + sqlite3_free(query_string); + sqlite3_free(path_string); + + if (SQLITE_OK != err) { + thumb_err("prepare error [%s]\n", sqlite3_errmsg(handle)); + return -1; + } + + err = sqlite3_step(stmt); + if (err != SQLITE_ROW) { + thumb_err("end of row [%s]\n", sqlite3_errmsg(handle)); + sqlite3_finalize(stmt); + return -1; + } + + *type = sqlite3_column_int(stmt, 0); + sqlite3_finalize(stmt); + + return MEDIA_THUMB_ERROR_NONE; +} + + +int _media_thumb_get_wh_from_db(sqlite3 *handle, + const char *origin_path, + int *width, + int *height) +{ + thumb_dbg("Origin path : %s", origin_path); + + if (handle == NULL) { + thumb_err("DB handle is NULL"); + return -1; + } + + int err = -1; + char *path_string = NULL; + char *query_string = NULL; + sqlite3_stmt *stmt = NULL; + + path_string = sqlite3_mprintf("%s", origin_path); + query_string = sqlite3_mprintf(SELECT_WH_BY_PATH, path_string); + + thumb_dbg("Query: %s", query_string); + + err = sqlite3_prepare_v2(handle, query_string, strlen(query_string), &stmt, NULL); + + sqlite3_free(query_string); + sqlite3_free(path_string); + + if (SQLITE_OK != err) { + thumb_err("prepare error [%s]\n", sqlite3_errmsg(handle)); + return -1; + } + + err = sqlite3_step(stmt); + if (err != SQLITE_ROW) { + thumb_err("end of row [%s]\n", sqlite3_errmsg(handle)); + sqlite3_finalize(stmt); + return -1; + } + + *width = sqlite3_column_int(stmt, 0); + *height = sqlite3_column_int(stmt, 1); + sqlite3_finalize(stmt); + + return MEDIA_THUMB_ERROR_NONE; +} + +int +_media_thumb_get_thumb_path_from_db(sqlite3 *handle, + const char *origin_path, + char *thumb_path, + int max_length) +{ + thumb_dbg("Origin path : %s", origin_path); + + if (handle == NULL) { + thumb_err("DB handle is NULL"); + return -1; + } + + int err = -1; + char *path_string = NULL; + char *query_string = NULL; + sqlite3_stmt *stmt = NULL; + + path_string = sqlite3_mprintf("%s", origin_path); + query_string = sqlite3_mprintf(SELECT_MEDIA_BY_PATH, path_string); + + thumb_dbg("Query: %s", query_string); + + err = sqlite3_prepare_v2(handle, query_string, strlen(query_string), &stmt, NULL); + + sqlite3_free(query_string); + sqlite3_free(path_string); + + if (SQLITE_OK != err) { + thumb_err("prepare error [%s]\n", sqlite3_errmsg(handle)); + return -1; + } + + err = sqlite3_step(stmt); + if (err != SQLITE_ROW) { + thumb_err("end of row [%s]\n", sqlite3_errmsg(handle)); + sqlite3_finalize(stmt); + return -1; + } + + if (sqlite3_column_text(stmt, 0)) + strncpy(thumb_path, (const char *)sqlite3_column_text(stmt, 0), max_length); + else + thumb_path[0] = '\0'; + + sqlite3_finalize(stmt); + + return MEDIA_THUMB_ERROR_NONE; +} + +int +_media_thumb_update_thumb_path_to_db(sqlite3 *handle, + const char *origin_path, + char *thumb_path) +{ + thumb_dbg(""); + int err = -1; + char *path_string = NULL; + char *thumbpath_string = NULL; + char *query_string = NULL; + + if (handle == NULL) { + thumb_err("DB handle is NULL"); + return -1; + } + + path_string = sqlite3_mprintf("%s", origin_path); + thumbpath_string = sqlite3_mprintf("%s", thumb_path); + query_string = sqlite3_mprintf(UPDATE_THUMB_BY_PATH, thumbpath_string, path_string); + +#ifndef _USE_MEDIA_UTIL_ + char *err_msg = NULL; + err = sqlite3_exec(handle, query_string, NULL, NULL, &err_msg); + + thumb_dbg("Query : %s", query_string); + + sqlite3_free(query_string); + sqlite3_free(thumbpath_string); + sqlite3_free(path_string); + + if (SQLITE_OK != err) { + if (err_msg) { + thumb_err("Failed to query[ %s ]", err_msg); + sqlite3_free(err_msg); + err_msg = NULL; + } + + return -1; + } + + if (err_msg) + sqlite3_free(err_msg); +#else + err = media_db_request_update_db(query_string); + if (err < 0) { + thumb_err("media_db_request_update_db failed : %d", err); + return err; + } +#endif + thumb_dbg("Query success"); + + return MEDIA_THUMB_ERROR_NONE; +} + +int +_media_thumb_update_wh_to_db(sqlite3 *handle, + const char *origin_path, + int width, + int height) +{ + thumb_dbg(""); + int err = -1; + char *path_string = NULL; + char *query_string = NULL; + + if (handle == NULL) { + thumb_err("DB handle is NULL"); + return -1; + } + + path_string = sqlite3_mprintf("%s", origin_path); + query_string = sqlite3_mprintf(UPDATE_WH_BY_PATH, width, height, path_string); + +#ifndef _USE_MEDIA_UTIL_ + char *err_msg = NULL; + err = sqlite3_exec(handle, query_string, NULL, NULL, &err_msg); + + thumb_dbg("Query : %s", query_string); + + sqlite3_free(query_string); + sqlite3_free(path_string); + + if (SQLITE_OK != err) { + if (err_msg) { + thumb_err("Failed to query[ %s ]", err_msg); + sqlite3_free(err_msg); + err_msg = NULL; + } + + return -1; + } + + if (err_msg) + sqlite3_free(err_msg); +#else + err = media_db_request_update_db(query_string); + if (err < 0) { + thumb_err("media_db_request_update_db failed : %d", err); + return err; + } +#endif + thumb_dbg("Query success"); + + return MEDIA_THUMB_ERROR_NONE; +} + +int +_media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle, + const char *origin_path, + char *thumb_path, + int width, + int height) +{ + thumb_dbg(""); + int err = -1; + char *path_string = NULL; + char *query_string = NULL; + + if (handle == NULL) { + thumb_err("DB handle is NULL"); + return -1; + } + + path_string = sqlite3_mprintf("%s", origin_path); + query_string = sqlite3_mprintf(UPDATE_THUMB_WH_BY_PATH, thumb_path, width, height, path_string); + + err = media_db_request_update_db(query_string); + if (err < 0) { + thumb_err("media_db_request_update_db failed : %d", err); + return err; + } + + thumb_dbg("Query success"); + + return MEDIA_THUMB_ERROR_NONE; +} + +int +_media_thumb_db_connect() +{ + int err = -1; +/* + err = media_svc_connect(&mb_svc_handle); + if (err < 0) { + thumb_err("media_svc_connect failed: %d", err); + mb_svc_handle = NULL; + return err; + } +*/ +#ifndef _USE_MEDIA_UTIL_ + err = _media_thumb_sqlite_connect(&db_handle); + if (err < 0) { + thumb_err("_media_thumb_sqlite_connect failed: %d", err); + db_handle = NULL; + return err; + } +#else + err = media_db_connect(&db_handle); + if (err < 0) { + thumb_err("media_db_connect failed: %d", err); + db_handle = NULL; + return MEDIA_THUMB_ERROR_DB; + } +#endif + + return MEDIA_THUMB_ERROR_NONE; +} + +int +_media_thumb_db_disconnect() +{ + int err = -1; +/* + err = media_svc_disconnect(mb_svc_handle); + + if (err < 0) { + thumb_err("media_svc_disconnect failed: %d", err); + } + + mb_svc_handle = NULL; +*/ +#ifndef _USE_MEDIA_UTIL_ + err = _media_thumb_sqlite_disconnect(db_handle); + if (err < 0) { + thumb_err("_media_thumb_sqlite_disconnect failed: %d", err); + db_handle = NULL; + return err; + } +#else + err = media_db_disconnect(db_handle); + if (err < 0) { + thumb_err("media_db_disconnect failed: %d", err); + db_handle = NULL; + return MEDIA_THUMB_ERROR_DB; + } +#endif + + db_handle = NULL; + return err; +} + +int +_media_thumb_get_thumb_from_db(const char *origin_path, + char *thumb_path, + int max_length, + int *need_update_db) +{ + thumb_dbg(""); + int err = -1; + + //err = minfo_get_thumb_path(mb_svc_handle, origin_path, thumb_path, max_length); + err = _media_thumb_get_thumb_path_from_db(db_handle, origin_path, thumb_path, max_length); + if (err < 0) { + thumb_warn("Original path doesn't exist in DB"); + return -1; + } + + if (strlen(thumb_path) == 0) { + thumb_warn("thumb path doesn't exist in DB"); + *need_update_db = 1; + return -1; + } + + thumb_dbg("Thumb path in DB is %s", thumb_path); + + if (!g_file_test(thumb_path, + G_FILE_TEST_EXISTS)) { + thumb_warn("thumb path doesn't exist in file system"); + *need_update_db = 1; + return -1; + } else { + thumb_dbg("This thumb path already exist"); + } + + return MEDIA_THUMB_ERROR_NONE; +} + +int +_media_thumb_get_thumb_from_db_with_size(const char *origin_path, + char *thumb_path, + int max_length, + int *need_update_db, + int *width, + int *height) +{ + thumb_dbg(""); + int err = -1; + + //err = minfo_get_thumb_path(mb_svc_handle, origin_path, thumb_path, max_length); + err = _media_thumb_get_thumb_path_from_db(db_handle, origin_path, thumb_path, max_length); + if (err < 0) { + thumb_warn("Original path doesn't exist in DB"); + return -1; + } + + if (strlen(thumb_path) == 0) { + thumb_warn("thumb path doesn't exist in DB"); + *need_update_db = 1; + return -1; + } + + thumb_dbg("Thumb path in DB is %s", thumb_path); + + if (!g_file_test(thumb_path, + G_FILE_TEST_EXISTS)) { + thumb_warn("thumb path doesn't exist in file system"); + *need_update_db = 1; + return -1; + } else { + thumb_dbg("This thumb path already exist"); + int orig_w = 0; + int orig_h = 0; + + err = _media_thumb_get_wh_from_db(db_handle, origin_path, &orig_w, &orig_h); + if (err < 0) { + thumb_err("_media_thumb_get_wh_from_db failed : %d", err); + } else { + thumb_err("_media_thumb_get_wh_from_db Success ( w:%d, h:%d )", orig_w, orig_h); + *width = orig_w; + *height = orig_h; + } + } + + return MEDIA_THUMB_ERROR_NONE; +} + +int +_media_thumb_update_db(const char *origin_path, + char *thumb_path, + int width, + int height) +{ + thumb_dbg(""); + int err = -1; + +#if 0 + Mitem *item = NULL; + + err = minfo_get_item(mb_svc_handle, origin_path, &item); + if (err < 0) { + thumb_err("minfo_get_item (%s) failed: %d", origin_path, err); + return MEDIA_THUMB_ERROR_DB; + } + + err = minfo_update_media_thumb(mb_svc_handle, item->uuid, thumb_path); + if (err < 0) { + thumb_err("minfo_update_media_thumb (ID:%s, %s) failed: %d", + item->uuid, thumb_path, err); + minfo_destroy_mtype_item(item); + return MEDIA_THUMB_ERROR_DB; + } + + if (item->type == MINFO_ITEM_IMAGE) { + err = minfo_update_image_meta_info_int(mb_svc_handle, item->uuid, + MINFO_IMAGE_META_WIDTH, width, + MINFO_IMAGE_META_HEIGHT, height, -1); + + if (err < 0) { + thumb_err("minfo_update_image_meta_info_int failed: %d", err); + minfo_destroy_mtype_item(item); + return MEDIA_THUMB_ERROR_DB; + } + } + + err = minfo_destroy_mtype_item(item); +#endif + + int media_type = THUMB_NONE_TYPE; + err = _media_thumb_get_type_from_db(db_handle, origin_path, &media_type); + if (err < 0) { + thumb_err("_media_thumb_get_type_from_db (%s) failed: %d", origin_path, err); + return MEDIA_THUMB_ERROR_DB; + } + +#if 0 + err = _media_thumb_update_thumb_path_to_db(db_handle, origin_path, thumb_path); + if (err < 0) { + thumb_err("_media_thumb_update_thumb_path_to_db (%s) failed: %d", origin_path, err); + return MEDIA_THUMB_ERROR_DB; + } + + if (media_type == THUMB_IMAGE_TYPE && width > 0 && height > 0) { + err = _media_thumb_update_wh_to_db(db_handle, origin_path, width, height); + if (err < 0) { + thumb_err("_media_thumb_update_wh_to_db (%s) failed: %d", origin_path, err); + return MEDIA_THUMB_ERROR_DB; + } + } +#else + if (media_type == THUMB_IMAGE_TYPE && width > 0 && height > 0) { + err = _media_thumb_update_thumb_path_wh_to_db(db_handle, origin_path, thumb_path, width, height); + if (err < 0) { + thumb_err("_media_thumb_update_wh_to_db (%s) failed: %d", origin_path, err); + return MEDIA_THUMB_ERROR_DB; + } + } else { + err = _media_thumb_update_thumb_path_to_db(db_handle, origin_path, thumb_path); + if (err < 0) { + thumb_err("_media_thumb_update_thumb_path_to_db (%s) failed: %d", origin_path, err); + return MEDIA_THUMB_ERROR_DB; + } + } +#endif + + thumb_dbg("_media_thumb_update_db success"); + + return MEDIA_THUMB_ERROR_NONE; +} + diff --git a/src/util/media-thumb-debug.c b/src/util/media-thumb-debug.c new file mode 100755 index 0000000..b684aa4 --- /dev/null +++ b/src/util/media-thumb-debug.c @@ -0,0 +1,112 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include "media-thumb-debug.h" + +#ifdef _PERFORMANCE_CHECK_ +static long g_time_usec = 0L; +#endif + +#ifdef _USE_LOG_FILE_ +static FILE *g_log_fp = NULL; +static char _g_file_path[1024] = "\0"; + +FILE *get_fp() +{ + return g_log_fp; +} + +void thumb_init_file_debug() +{ + if (g_log_fp == NULL) { + snprintf(_g_file_path, sizeof(_g_file_path), "/tmp/%s", + "media-thumb.log"); + if (access(_g_file_path, R_OK == 0)) { + remove(_g_file_path); + } + + g_log_fp = fopen(_g_file_path, "a"); + } +} + +void thumb_close_file_debug() +{ + if (g_log_fp != NULL) { + fclose(g_log_fp); + g_log_fp = NULL; + } +} + +#endif + +long thumb_get_debug_time(void) +{ +#ifdef _PERFORMANCE_CHECK_ + struct timeval time; + gettimeofday(&time, NULL); + return time.tv_sec * 1000000 + time.tv_usec; +#else + return 0L; +#endif +} + +void thumb_reset_debug_time(void) +{ +#ifdef _PERFORMANCE_CHECK_ + struct timeval time; + gettimeofday(&time, NULL); + g_time_usec = time.tv_sec * 1000000 + time.tv_usec; +#endif +} + +void thumb_print_debug_time(char *time_string) +{ +#ifdef _PERFORMANCE_CHECK_ + struct timeval time; + double totaltime = 0.0; + + gettimeofday(&time, NULL); + totaltime = + (double)(time.tv_sec * 1000000 + time.tv_usec - + g_time_usec) / CLOCKS_PER_SEC; + + thumb_dbg("time [%s] : %f \n", time_string, totaltime); +#endif +} + +void +thumb_print_debug_time_ex(long start, long end, const char *func_name, + char *time_string) +{ +#ifdef _PERFORMANCE_CHECK_ + double totaltime = 0.0; + + totaltime = (double)(end - start) / CLOCKS_PER_SEC; + + thumb_dbg("time [%s: %s] : %f \n", func_name, time_string, + totaltime); +#endif +} + diff --git a/src/util/media-thumb-util.c b/src/util/media-thumb-util.c new file mode 100755 index 0000000..0db4133 --- /dev/null +++ b/src/util/media-thumb-util.c @@ -0,0 +1,374 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * 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 "media-thumb-util.h" +#include "media-thumb-internal.h" + +#include +#include +#include +#include + +#include +#include + +int _media_thumb_get_width(media_thumb_type thumb_type) +{ + if (thumb_type == MEDIA_THUMB_LARGE) { + return THUMB_LARGE_WIDTH; + } else if (thumb_type == MEDIA_THUMB_SMALL) { + return THUMB_SMALL_WIDTH; + } else { + return -1; + } +} + +int _media_thumb_get_height(media_thumb_type thumb_type) +{ + if (thumb_type == MEDIA_THUMB_LARGE) { + return THUMB_LARGE_HEIGHT; + } else if (thumb_type == MEDIA_THUMB_SMALL) { + return THUMB_SMALL_HEIGHT; + } else { + return -1; + } +} + +int _media_thumb_get_file_ext(const char *file_path, char *file_ext, int max_len) +{ + int i = 0; + + for (i = strlen(file_path); i >= 0; i--) { + if ((file_path[i] == '.') && (i < strlen(file_path))) { + strncpy(file_ext, &file_path[i + 1], max_len); + return 0; + } + + /* meet the dir. no ext */ + if (file_path[i] == '/') { + return -1; + } + } + + return -1; +} + +int +_media_thumb_get_file_type(const char *file_full_path) +{ + int ret = 0; + drm_bool_type_e drm_type; + drm_file_type_e drm_file_type; + char mimetype[255]; + + if (file_full_path == NULL) + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + + ret = drm_is_drm_file(file_full_path, &drm_type); + if (ret < 0) { + thumb_err("drm_is_drm_file falied : %d", ret); + drm_type = DRM_FALSE; + } + + if (drm_type == DRM_TRUE) { + thumb_dbg("DRM file : %s", file_full_path); + + ret = drm_get_file_type(file_full_path, &drm_file_type); + if (ret < 0) { + thumb_err("drm_get_file_type falied : %d", ret); + return THUMB_NONE_TYPE; + } + + if (drm_file_type == DRM_TYPE_UNDEFINED) { + return THUMB_NONE_TYPE; + } else { + drm_content_info_s contentInfo; + memset(&contentInfo, 0x00, sizeof(drm_content_info_s)); + + ret = drm_get_content_info(file_full_path, &contentInfo); + if (ret != DRM_RETURN_SUCCESS) { + thumb_err("drm_get_content_info() fails. : %d", ret); + return THUMB_NONE_TYPE; + } + thumb_dbg("DRM mime type: %s", contentInfo.mime_type); + + strncpy(mimetype, contentInfo.mime_type, sizeof(mimetype) - 1); + mimetype[sizeof(mimetype) - 1] = '\0'; + } + } else { + /* get content type and mime type from file. */ + ret = + aul_get_mime_from_file(file_full_path, mimetype, sizeof(mimetype)); + if (ret < 0) { + thumb_warn + ("aul_get_mime_from_file fail.. Now trying to get type by extension"); + + char ext[255] = { 0 }; + int ret = _media_thumb_get_file_ext(file_full_path, ext, sizeof(ext)); + if (ret < 0) { + thumb_err("_media_thumb_get_file_ext failed"); + return THUMB_NONE_TYPE; + } + + if (strcasecmp(ext, "JPG") == 0 || + strcasecmp(ext, "JPEG") == 0 || + strcasecmp(ext, "PNG") == 0 || + strcasecmp(ext, "GIF") == 0 || + strcasecmp(ext, "AGIF") == 0 || + strcasecmp(ext, "XWD") == 0 || + strcasecmp(ext, "BMP") == 0 || + strcasecmp(ext, "WBMP") == 0) { + return THUMB_IMAGE_TYPE; + } else if (strcasecmp(ext, "AVI") == 0 || + strcasecmp(ext, "MPEG") == 0 || + strcasecmp(ext, "MP4") == 0 || + strcasecmp(ext, "DCF") == 0 || + strcasecmp(ext, "WMV") == 0 || + strcasecmp(ext, "3GPP") == 0 || + strcasecmp(ext, "3GP") == 0) { + return THUMB_VIDEO_TYPE; + } else { + return THUMB_NONE_TYPE; + } + } + } + + thumb_dbg("mime type : %s", mimetype); + + /* categorize from mimetype */ + if (strstr(mimetype, "image") != NULL) { + return THUMB_IMAGE_TYPE; + } else if (strstr(mimetype, "video") != NULL) { + return THUMB_VIDEO_TYPE; + } + + return THUMB_NONE_TYPE; +} + +int _media_thumb_get_store_type_by_path(const char *full_path) +{ + if (full_path != NULL) { + if (strncmp + (full_path, THUMB_PATH_PHONE, + strlen(THUMB_PATH_PHONE)) == 0) { + return THUMB_PHONE; + } else + if (strncmp + (full_path, THUMB_PATH_MMC, + strlen(THUMB_PATH_MMC)) == 0) { + return THUMB_MMC; + } + } + + return -1; +} + +int _media_thumb_remove_file(const char *path) +{ + int result = -1; + + result = remove(path); + if (result == 0) { + thumb_dbg("success to remove file"); + return TRUE; + } else { + thumb_err("fail to remove file[%s] result errno = %s", path, strerror(errno)); + return FALSE; + } +} + +int +_media_thumb_get_hash_name(const char *file_full_path, + char *thumb_hash_path, size_t max_thumb_path) +{ + char *hash_name; + char *thumb_dir = NULL; + char file_ext[255] = { 0 }; + media_thumb_store_type store_type = -1; + + if (file_full_path == NULL || thumb_hash_path == NULL + || max_thumb_path <= 0) { + thumb_err + ("file_full_path==NULL || thumb_hash_path == NULL || max_thumb_path <= 0"); + return -1; + } + + _media_thumb_get_file_ext(file_full_path, file_ext, sizeof(file_ext)); + + store_type = _media_thumb_get_store_type_by_path(file_full_path); + if (store_type == THUMB_PHONE) { + thumb_dir = THUMB_PHONE_PATH; + } else if (store_type == THUMB_MMC) { + thumb_dir = THUMB_MMC_PATH; + } else { + thumb_dir = THUMB_PHONE_PATH; + } + + hash_name = _media_thumb_generate_hash_name(file_full_path); + + int ret_len; + ret_len = + snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg", + thumb_dir, file_ext, hash_name); + if (ret_len < 0) { + thumb_err("Error when snprintf"); + return -1; + } else if (ret_len > max_thumb_path) { + thumb_err("Error for the length of thumb pathname"); + return -1; + } + + //thumb_dbg("thumb hash : %s", thumb_hash_path); + + return 0; +} + + +int _media_thumb_save_to_file_with_evas(unsigned char *data, + int w, + int h, + int alpha, + char *thumb_path) +{ + Ecore_Evas *ee = + ecore_evas_buffer_new(w, h); + if (ee == NULL) { + thumb_err("Failed to create a new ecore evas buffer\n"); + return -1; + } + + Evas *evas = ecore_evas_get(ee); + if (evas == NULL) { + thumb_err("Failed to ecore_evas_get\n"); + ecore_evas_free(ee); + return -1; + } + + Evas_Object *img = NULL; + img = evas_object_image_add(evas); + + if (img == NULL) { + thumb_err("image object is NULL\n"); + ecore_evas_free(ee); + return -1; + } + + evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888); + evas_object_image_size_set(img, w, h); + evas_object_image_fill_set(img, 0, 0, w, h); + + if (alpha) evas_object_image_alpha_set(img, 1); + + evas_object_image_data_set(img, data); + evas_object_image_data_update_add(img, 0, 0, w, h); + + if (evas_object_image_save + (img, thumb_path, NULL, "quality=100 compress=1")) { + thumb_dbg("evas_object_image_save success\n"); + ecore_evas_free(ee); + + return 0; + } else { + thumb_dbg("evas_object_image_save failed\n"); + ecore_evas_free(ee); + return -1; + } +} + + +int _thumbnail_get_data(const char *origin_path, + media_thumb_type thumb_type, + media_thumb_format format, + unsigned char **data, + int *size, + int *width, + int *height, + int *origin_width, + int *origin_height, + int *alpha) +{ + int err = -1; + int thumb_width = -1; + int thumb_height = -1; + + if (origin_path == NULL || size == NULL + || width == NULL || height == NULL) { + thumb_err("Invalid parameter"); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + if (format < MEDIA_THUMB_BGRA || format > MEDIA_THUMB_RGB888) { + thumb_err("parameter format is invalid"); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + if (!g_file_test + (origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { + thumb_err("Original path (%s) does not exist", origin_path); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + thumb_width = _media_thumb_get_width(thumb_type); + if (thumb_width < 0) { + thumb_err("media_thumb_type is invalid"); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + thumb_height = _media_thumb_get_height(thumb_type); + if (thumb_height < 0) { + thumb_err("media_thumb_type is invalid"); + return MEDIA_THUMB_ERROR_INVALID_PARAMETER; + } + + thumb_dbg("Origin path : %s", origin_path); + + int file_type = THUMB_NONE_TYPE; + media_thumb_info thumb_info = {0,}; + file_type = _media_thumb_get_file_type(origin_path); + + if (file_type == THUMB_IMAGE_TYPE) { + err = _media_thumb_image(origin_path, thumb_width, thumb_height, format, &thumb_info); + if (err < 0) { + thumb_err("_media_thumb_image failed"); + return err; + } + + } else if (file_type == THUMB_VIDEO_TYPE) { + err = _media_thumb_video(origin_path, thumb_width, thumb_height, format, &thumb_info); + if (err < 0) { + thumb_err("_media_thumb_image failed"); + return err; + } + } + + if (size) *size = thumb_info.size; + if (width) *width = thumb_info.width; + if (height) *height = thumb_info.height; + *data = thumb_info.data; + if (origin_width) *origin_width = thumb_info.origin_width; + if (origin_height) *origin_height = thumb_info.origin_height; + if (alpha) *alpha = thumb_info.alpha; + + thumb_dbg("Thumb data is generated successfully (Size:%d, W:%d, H:%d) 0x%x", + *size, *width, *height, *data); + + return MEDIA_THUMB_ERROR_NONE; +} diff --git a/test/test-thumb.c b/test/test-thumb.c new file mode 100755 index 0000000..41fcb6e --- /dev/null +++ b/test/test-thumb.c @@ -0,0 +1,246 @@ +/* + * libmedia-thumbnail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hyunjun Ko + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "media-thumbnail.h" +#include "media-thumbnail-private.h" +#include "media-thumb-debug.h" +#include "media-thumb-ipc.h" +#include "media-thumb-util.h" + +int save_to_file_with_evas(unsigned char *data, int w, int h, int is_bgra) +{ + ecore_evas_init(); + + Ecore_Evas *ee = + ecore_evas_buffer_new(w, h); + Evas *evas = ecore_evas_get(ee); + + Evas_Object *img = NULL; + img = evas_object_image_add(evas); + + if (img == NULL) { + printf("image object is NULL\n"); + ecore_evas_free(ee); + ecore_evas_shutdown(); + return -1; + } + + evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888); + evas_object_image_size_set(img, w, h); + evas_object_image_fill_set(img, 0, 0, w, h); + + if (!is_bgra) { + unsigned char *m = NULL; + m = evas_object_image_data_get(img, 1); +#if 1 /* Use self-logic to convert from RGB888 to RGBA */ + int i = 0, j; + for (j = 0; j < w * 3 * h; + j += 3) { + m[i++] = (data[j + 2]); + m[i++] = (data[j + 1]); + m[i++] = (data[j]); + m[i++] = 0x0; + } + +#else /* Use mmf api to convert from RGB888 to RGBA */ + int mm_ret = 0; + if ((mm_ret = + mm_util_convert_colorspace(data, + w, + h, + MM_UTIL_IMG_FMT_RGB888, + m, + MM_UTIL_IMG_FMT_BGRA8888)) + < 0) { + printf + ("Failed to change from rgb888 to argb8888 %d\n", + mm_ret); + return -1; + } +#endif /* End of use mmf api to convert from RGB888 to RGBA */ + + evas_object_image_data_set(img, m); + evas_object_image_data_update_add(img, 0, 0, w, h); + } else { + evas_object_image_data_set(img, data); + evas_object_image_data_update_add(img, 0, 0, w, h); + } + + if (evas_object_image_save + (img, "/mnt/nfs/test.jpg", NULL, + "quality=50 compress=2")) { + printf("evas_object_image_save success\n"); + } else { + printf("evas_object_image_save failed\n"); + } + + ecore_evas_shutdown(); + + return 0; +} + +int main(int argc, char *argv[]) +{ + int mode; + int err = -1; + const char *origin_path = NULL; + + if ((argc != 3) && (argc != 4)) { + printf("Usage: %s [test mode number] [path]\n", argv[0]); + return -1; + } + + mode = atoi(argv[1]); + origin_path = argv[2]; + + if (origin_path && (mode == 1)) { + printf("Test _thumbnail_get_data\n"); + + unsigned char *data = NULL; + int thumb_size = 0; + int thumb_w = 0; + int thumb_h = 0; + int origin_w = 0; + int origin_h = 0; + int alpha = FALSE; + + media_thumb_type thumb_type = MEDIA_THUMB_LARGE; + //media_thumb_type thumb_type = MEDIA_THUMB_SMALL; + media_thumb_format thumb_format = MEDIA_THUMB_BGRA; + //media_thumb_format thumb_format = MEDIA_THUMB_RGB888; + int is_bgra = 1; + //int is_bgra = 0; + + long start = thumb_get_debug_time(); + + err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha); + if (err < 0) { + printf("_thumbnail_get_data failed - %d\n", err); + return -1; + } + + printf("Size : %d, W:%d, H:%d\n", thumb_size, thumb_w, thumb_h); + printf("Origin W:%d, Origin H:%d\n", origin_w, origin_h); + + err = save_to_file_with_evas(data, thumb_w, thumb_h, is_bgra); + if (err < 0) { + printf("_thumbnail_get_data failed - %d\n", err); + return -1; + } else { + printf("file save success\n"); + } + + SAFE_FREE(data); + + long end = thumb_get_debug_time(); + printf("Time : %f\n", ((double)(end - start) / (double)CLOCKS_PER_SEC)); + + } else if (mode == 2) { + printf("Test thumbnail_request_from_db\n"); + //const char *origin_path = "/opt/media/test/movie1.mp4"; + //const char *origin_path = "/opt/media/test/high.jpg"; + //const char *origin_path = "/opt/media/test/movie2.avi"; + char thumb_path[MAX_PATH_SIZE + 1]; + + err = thumbnail_request_from_db(origin_path, thumb_path, sizeof(thumb_path)); + if (err < 0) { + printf("thumbnail_request_from_db failed : %d\n", err); + return -1; + } + + printf("Success!! (%s)\n", thumb_path); + } else if (mode == 3) { + printf("Test thumbnail_request_save_to_file\n"); + const char *thumb_path = NULL; + + if (argv[3]) { + thumb_path = argv[3]; + } else { + printf("3 mode requires target path of thumbnail\n"); + return -1; + } + + err = thumbnail_request_save_to_file(origin_path, MEDIA_THUMB_LARGE, thumb_path); + if (err < 0) { + printf("thumbnail_request_save_to_file failed : %d\n", err); + return -1; + } + + printf("Success!!\n"); + } else if (origin_path && mode == 4) { + printf("Test thumbnail_generate_hash_code\n"); + char hash[255] = {0,}; + + err = thumbnail_generate_hash_code(origin_path, hash, sizeof(hash)); + if (err < 0) { + printf("thumbnail_generate_hash_code failed : %d\n", err); + return -1; + } else { + printf("Hash : %s\n", hash); + } + + printf("Success!!\n"); + } else if (mode == 5) { + printf("Test thumbnail_request_extract_all_thumbs\n"); + + err = thumbnail_request_extract_all_thumbs(); + if (err < 0) { + printf("thumbnail_request_extract_all_thumbs failed : %d\n", err); + return -1; + } else { + printf("thumbnail_request_extract_all_thumbs success!\n"); + } + } else if (mode == 6) { + printf("Test thumbnail_request_cancel_media\n"); + + err = thumbnail_request_cancel_media(origin_path); + if (err < 0) { + printf("thumbnail_request_cancel_media failed : %d\n", err); + return -1; + } else { + printf("thumbnail_request_cancel_media success!\n"); + } + } else if (mode == 7) { + printf("Test thumbnail_request_cancel_all\n"); + + err = thumbnail_request_cancel_all(); + if (err < 0) { + printf("thumbnail_request_cancel_all failed : %d\n", err); + return -1; + } else { + printf("thumbnail_request_cancel_all success!\n"); + } + } + + thumb_dbg("Test is Completed"); + + return 0; +} + diff --git a/thumbsvr b/thumbsvr new file mode 100644 index 0000000..cd5b2d7 --- /dev/null +++ b/thumbsvr @@ -0,0 +1,4 @@ +#!/bin/sh +/etc/init.d/network start +/usr/bin/media-thumbnail-server & + -- cgit v1.2.3