summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt102
-rw-r--r--COPYING504
-rw-r--r--LICENSE204
-rwxr-xr-xTC/_export_env.sh16
-rwxr-xr-xTC/build.sh18
-rwxr-xr-xTC/execute.sh32
-rwxr-xr-xTC/making_new_tet_scen.py69
-rw-r--r--TC/tet_scen7
-rw-r--r--TC/tetbuild.cfg5
-rw-r--r--TC/tetclean.cfg5
-rw-r--r--TC/tetexec.cfg5
-rw-r--r--TC/tslist.txt1
-rw-r--r--TC/utc/Makefile43
-rw-r--r--TC/utc/tslist2
-rw-r--r--TC/utc/utc_media_thumb_common.h51
-rw-r--r--TC/utc/utc_thumbnail_get_data_func.c103
-rw-r--r--TC/utc/utc_thumbnail_get_data_func.h52
-rw-r--r--TC/utc/utc_thumbnail_request_from_db_func.c85
-rw-r--r--TC/utc/utc_thumbnail_request_from_db_func.h51
-rwxr-xr-xdebian/changelog31
-rwxr-xr-xdebian/compat1
-rwxr-xr-xdebian/control49
-rwxr-xr-xdebian/copyright15
-rwxr-xr-xdebian/docs1
-rwxr-xr-xdebian/libmedia-thumbnail-dev.install.in2
-rwxr-xr-xdebian/libmedia-thumbnail.install.in1
-rwxr-xr-xdebian/media-thumbnail-server.install.in2
-rwxr-xr-xdebian/rules118
-rwxr-xr-xinclude/media-thumb-error.h62
-rwxr-xr-xinclude/media-thumb-types.h37
-rwxr-xr-xinclude/media-thumbnail-private.h77
-rwxr-xr-xinclude/media-thumbnail.h144
-rw-r--r--license10
-rw-r--r--md5/md5.c253
-rw-r--r--md5/md5.h39
-rw-r--r--md5/media-thumb-hash.c132
-rwxr-xr-xmedia-thumbnail.pc.in13
-rw-r--r--packaging/libmedia-thumbnail.spec88
-rwxr-xr-xserver/include/thumb-server-internal.h52
-rwxr-xr-xserver/thumb-server-internal.c380
-rwxr-xr-xserver/thumb-server.c139
-rw-r--r--src/codec/IfegDecodeAGIF.c4169
-rw-r--r--src/codec/img-codec-osal.c159
-rw-r--r--src/codec/img-codec-parser.c883
-rw-r--r--src/codec/img-codec.c252
-rw-r--r--src/include/codec/AGifFrameInfo.h65
-rw-r--r--src/include/codec/IfegDecodeAGIF.h57
-rw-r--r--src/include/codec/img-codec-agif.h28
-rw-r--r--src/include/codec/img-codec-common.h304
-rw-r--r--src/include/codec/img-codec-config.h26
-rw-r--r--src/include/codec/img-codec-osal.h128
-rw-r--r--src/include/codec/img-codec-parser.h48
-rw-r--r--src/include/codec/img-codec.h49
-rwxr-xr-xsrc/include/ipc/media-thumb-ipc.h81
-rwxr-xr-xsrc/include/media-thumb-internal.h68
-rwxr-xr-xsrc/include/util/media-thumb-db.h43
-rwxr-xr-xsrc/include/util/media-thumb-debug.h73
-rwxr-xr-xsrc/include/util/media-thumb-util.h128
-rwxr-xr-xsrc/ipc/media-thumb-ipc.c277
-rwxr-xr-xsrc/media-thumb-internal.c1103
-rwxr-xr-xsrc/media-thumbnail.c116
-rwxr-xr-xsrc/util/media-thumb-db.c103
-rwxr-xr-xsrc/util/media-thumb-debug.c112
-rwxr-xr-xsrc/util/media-thumb-util.c316
-rwxr-xr-xtest/test-thumb.c223
-rw-r--r--thumbsvr4
66 files changed, 11816 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..1710ff5
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,102 @@
+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(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 libmedia-service mm-fileinfo drm-service aul
+libexif ecore-evas evas mmutil-imgp mmutil-jpeg heynoti)
+
+
+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_")
+
+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 ${BINDIR})
+
+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/COPYING b/COPYING
new file mode 100644
index 0000000..8add30a
--- /dev/null
+++ b/COPYING
@@ -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.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..a06208b
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,204 @@
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
diff --git a/TC/_export_env.sh b/TC/_export_env.sh
new file mode 100755
index 0000000..56e2167
--- /dev/null
+++ b/TC/_export_env.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+export ARCH=target
+
+export TET_INSTALL_PATH=/usr/bin/tetware/TETware # tetware root path
+export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target # tetware target path
+export PATH=$TET_TARGET_PATH/bin:$PATH
+export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH
+
+export TET_ROOT=$TET_TARGET_PATH
+
+set $(pwd)
+export TET_SUITE_ROOT=$1
+
+set $(date +%s)
+FILE_NAME_EXTENSION=$1
+
diff --git a/TC/build.sh b/TC/build.sh
new file mode 100755
index 0000000..dc464e7
--- /dev/null
+++ b/TC/build.sh
@@ -0,0 +1,18 @@
+. ./_export_env.sh # setting environment variables
+
+echo PATH=$PATH
+echo LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH
+echo TET_ROOT=$TET_ROOT
+echo TET_SUITE_ROOT=$TET_SUITE_ROOT
+echo ARCH=$ARCH
+
+RESULT_DIR=results-$ARCH
+HTML_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.html
+JOURNAL_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.journal
+
+mkdir $RESULT_DIR
+
+tcc -c -p ./ # executing tcc, with clean option (-c)
+tcc -b -j $JOURNAL_RESULT -p ./ # executing tcc to build test cases (-b)
+grw -c 3 -f chtml -o $HTML_RESULT $JOURNAL_RESULT # reporting the result
+
diff --git a/TC/execute.sh b/TC/execute.sh
new file mode 100755
index 0000000..9de8291
--- /dev/null
+++ b/TC/execute.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+export ARCH=target
+
+export TET_INSTALL_PATH=/mnt/nfs/tetware/TETware # path to mount
+export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target
+export PATH=$TET_TARGET_PATH/bin:$PATH
+export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH
+
+export TET_ROOT=$TET_TARGET_PATH
+
+set $(pwd)
+export TET_SUITE_ROOT=$1
+
+set $(date +%s)
+FILE_NAME_EXTENSION=$1
+
+echo PATH=$PATH
+echo LD_LIBRARY_PATH=$LD_LIBRARY_PATH
+echo TET_ROOT=$TET_ROOT
+echo TET_SUITE_ROOT=$TET_SUITE_ROOT
+echo ARCH=$ARCH
+
+RESULT_DIR=results-$ARCH
+HTML_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.html
+JOURNAL_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.journal
+
+mkdir $RESULT_DIR
+
+tcc -e -j $JOURNAL_RESULT -p ./
+grw -c 3 -f chtml -o $HTML_RESULT $JOURNAL_RESULT # reporting the result
+
diff --git a/TC/making_new_tet_scen.py b/TC/making_new_tet_scen.py
new file mode 100755
index 0000000..6c5b845
--- /dev/null
+++ b/TC/making_new_tet_scen.py
@@ -0,0 +1,69 @@
+#!/usr/bin/python
+
+#############################################
+# tet_scen auto generator
+#
+# ** argv[1] = TC root
+#############################################
+
+import sys,string,os
+
+
+write_file = open("tet_scen", 'w')
+
+#
+# making new tet_scen
+#
+def making_tet_scen (filename):
+ #tmp_list = filename.strip().split('/')
+ n_filename = filename.replace(' ', '\\ ')
+ #print n_filename
+ #new_path = "/"+ sys.argv[1] +"/"+n_filename[2:-6]
+ new_path = "/"+n_filename[:-6]
+ #print new_path
+ file = open(filename, 'r')
+ lines = file.readlines()
+ for line in lines:
+ if len(line.strip()) > 1:
+ list = line.strip().split('/')
+ #print new_path + list[-1]
+ write_file.write("\t"+new_path+list[-1]+"\n")
+
+#
+# usage()
+#
+def usage():
+ print(" ")
+ print("./making_new_tet_scen.py tc_root")
+ print("Put the Test Case's root directory.")
+ print("Do not include '/' at the end")
+ print(" ")
+
+#
+# main()
+#
+def main():
+ if len(sys.argv) < 2:
+ usage()
+ sys.exit(0)
+
+ os.system('find '+ sys.argv[1] +' -name "tslist" > tslist.txt')
+
+ #write_file = open("tetscen", w)
+ write_file.write("# auto generated tet_scen\n")
+ write_file.write("all\n")
+ write_file.write("\t\"Starting Full Test Suite\"\n")
+
+ for file in open("tslist.txt", 'r'):
+ #print file.strip()
+ making_tet_scen(file.strip())
+
+ write_file.write("\t\"Completed Full Test Suite\"\n")
+ write_file.write("# EOF\n")
+ write_file.close()
+ print(" ")
+ print("==============================")
+ print("New tet_scen file is made~~~~")
+ print("==============================")
+ print(" ")
+main()
diff --git a/TC/tet_scen b/TC/tet_scen
new file mode 100644
index 0000000..b220f82
--- /dev/null
+++ b/TC/tet_scen
@@ -0,0 +1,7 @@
+# auto generated tet_scen
+all
+ "Starting Full Test Suite"
+ /utc/utc_thumbnail_request_from_db_func
+ /utc/utc_thumbnail_get_data_func
+ "Completed Full Test Suite"
+# EOF
diff --git a/TC/tetbuild.cfg b/TC/tetbuild.cfg
new file mode 100644
index 0000000..f7eda55
--- /dev/null
+++ b/TC/tetbuild.cfg
@@ -0,0 +1,5 @@
+TET_OUTPUT_CAPTURE=True # capture option for build operation checking
+TET_BUILD_TOOL=make # build with using make command
+TET_BUILD_FILE=-f Makefile # execution file (Makefile) for build
+TET_API_COMPLIANT=True # use TET API in Test Case ?
+TET_PASS_TC_NAME=True # report passed TC name in Journal file?
diff --git a/TC/tetclean.cfg b/TC/tetclean.cfg
new file mode 100644
index 0000000..02d7030
--- /dev/null
+++ b/TC/tetclean.cfg
@@ -0,0 +1,5 @@
+TET_OUTPUT_CAPTURE=True # capture option
+TET_CLEAN_TOOL= make clean # clean tool
+TET_CLEAN_FILE= Makefile # file for clean
+TET_API_COMPLIANT=True # TET API useage
+TET_PASS_TC_NAME=True # showing name , passed TC
diff --git a/TC/tetexec.cfg b/TC/tetexec.cfg
new file mode 100644
index 0000000..ef3e452
--- /dev/null
+++ b/TC/tetexec.cfg
@@ -0,0 +1,5 @@
+TET_OUTPUT_CAPTURE=True # capturing execution or not
+TET_EXEC_TOOL= # ex) exec : execution tool set up/ Optional
+TET_EXEC_FILE= # ex) exectool : execution file/ Optional
+TET_API_COMPLIANT=True # Test case or Tool usesTET API?
+TET_PASS_TC_NAME=True # showing Passed TC name ?
diff --git a/TC/tslist.txt b/TC/tslist.txt
new file mode 100644
index 0000000..24c0a1a
--- /dev/null
+++ b/TC/tslist.txt
@@ -0,0 +1 @@
+utc/tslist
diff --git a/TC/utc/Makefile b/TC/utc/Makefile
new file mode 100644
index 0000000..c5a63ed
--- /dev/null
+++ b/TC/utc/Makefile
@@ -0,0 +1,43 @@
+ifeq ($(ARCH),target)
+ PKG_CONFIG_PATH=/usr/lib/pkgconfig
+ export PKG_CONFIG_PATH
+ CC=arm-linux-gcc -Wall
+ CXX=arm-linux-g++ -Wall
+else
+ PKG_CONFIG_PATH=/usr/lib/pkgconfig
+ export PKG_CONFIG_PATH
+ CC=gcc -Wall
+ CXX=gcc -Wall
+endif
+
+TS1=utc_thumbnail_request_from_db_func
+TS2=utc_thumbnail_get_data_func
+
+LIBS = `pkg-config --libs libmedia-thumbnail`
+LIBS +=-L/usr/lib/:/usr/lib/pkgconfig
+LIBS +=$(TET_ROOT)/lib/tet3/tcm_s.o
+LIBS +=-L$(TET_ROOT)/lib/tet3 -ltcm_s
+LIBS +=-L$(TET_ROOT)/lib/tet3/ -lapi_s
+
+INCS = -I. `pkg-config --cflags libmedia-thumbnail`
+INCS += -I$(TET_ROOT)/inc/tet3
+INCS += -I/usr/include
+
+CFLAGS = $(INCS)
+CC += $(CFLAGS)
+LDFLAGS = $(LIBS)
+
+all : $(TS10) $(TS11)
+
+$(TS1): $(TS1).c
+ $(CC) -o $(TS1) $(TS1).c $(LDFLAGS)
+
+$(TS2): $(TS2).c
+ $(CC) -o $(TS2) $(TS2).c $(LDFLAGS)
+
+
+clean:
+ rm -rf *~ *.o $(TS1) $(TS2)
+
+
+
diff --git a/TC/utc/tslist b/TC/utc/tslist
new file mode 100644
index 0000000..6ff06c4
--- /dev/null
+++ b/TC/utc/tslist
@@ -0,0 +1,2 @@
+/utc/visual/utc_thumbnail_request_from_db_func
+/utc/visual/utc_thumbnail_get_data_func
diff --git a/TC/utc/utc_media_thumb_common.h b/TC/utc/utc_media_thumb_common.h
new file mode 100644
index 0000000..6cc8496
--- /dev/null
+++ b/TC/utc/utc_media_thumb_common.h
@@ -0,0 +1,51 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+/**
+* @file utc_media_thumb_common.h
+* @author
+* @brief This is the implementaion file for the test case of thumbnail service
+
+* @version Initial Creation Version 0.1
+* @date 2010-10-13
+*/
+
+#ifndef __UTS_MEDIA_THUMB_COMMON_H_
+#define __UTS_MEDIA_THUMB_COMMON_H_
+
+#include <media-thumbnail.h>
+#include <tet_api.h>
+
+#define UTC_THUMB_LOG(fmt, args...) tet_printf("[%s(L%d)]:"fmt"\n", __FUNCTION__, __LINE__, ##args)
+#define API_NAME "libmedia-thumbnail"
+
+
+void startup()
+{
+}
+
+void cleanup()
+{
+}
+
+
+#endif //__UTS_MEDIA_THUMB_COMMON_H_
diff --git a/TC/utc/utc_thumbnail_get_data_func.c b/TC/utc/utc_thumbnail_get_data_func.c
new file mode 100644
index 0000000..ccee472
--- /dev/null
+++ b/TC/utc/utc_thumbnail_get_data_func.c
@@ -0,0 +1,103 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+* @file utc_thumbnail_get_data_func.c
+* @brief This is a suit of unit test cases to test thumbnail_get_data API function
+* @author
+* @version Initial Creation Version 0.1
+* @date 2011-10-13
+*/
+
+#include "utc_thumbnail_get_data_func.h"
+
+
+/**
+* @brief This tests int thumbnail_get_data() API with valid parameters
+* @par ID utc_thumbnail_get_data_func_01
+* @param [in]
+* @return This function returns zero on success, or negative value with error code
+*/
+void utc_thumbnail_get_data_func_01()
+{
+ int ret = -1;
+
+ const char *origin_path = "/opt/media/Images and videos/Wallpapers/Home_default.png";
+
+ unsigned char *data = NULL;
+ int thumb_size = 0;
+ int thumb_w = 0;
+ int thumb_h = 0;
+ int origin_w = 0;
+ int origin_h = 0;
+
+ media_thumb_type thumb_type = MEDIA_THUMB_256x256;
+ media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
+
+ ret = thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h);
+
+ if (ret < MEDIA_THUMB_ERROR_NONE) {
+ UTC_THUMB_LOG( "unable to make thumbnail raw data. error code->%d", ret);
+ tet_result(TET_FAIL);
+ return;
+ } else {
+ tet_result(TET_PASS);
+ }
+
+ return;
+}
+
+
+/**
+* @brief This tests int thumbnail_get_data() API with invalid parameters
+* @par ID utc_thumbnail_get_data_func_02
+* @param [in]
+* @return error code on success
+*/
+void utc_thumbnail_get_data_func_02()
+{
+ int ret = -1;
+
+ const char *origin_path = NULL;
+
+ unsigned char *data = NULL;
+ int thumb_size = 0;
+ int thumb_w = 0;
+ int thumb_h = 0;
+ int origin_w = 0;
+ int origin_h = 0;
+
+ media_thumb_type thumb_type = MEDIA_THUMB_256x256;
+ media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
+
+ ret = thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h);
+
+ if (ret < MEDIA_THUMB_ERROR_NONE) {
+ UTC_THUMB_LOG("abnormal condition test for null, error code->%d", ret);
+ tet_result(TET_PASS);
+ } else {
+ UTC_THUMB_LOG("Creating thumbnail raw data should be failed because the origin_path is NULL");
+ tet_result(TET_FAIL);
+ }
+
+ return ;
+}
+
diff --git a/TC/utc/utc_thumbnail_get_data_func.h b/TC/utc/utc_thumbnail_get_data_func.h
new file mode 100644
index 0000000..82fd272
--- /dev/null
+++ b/TC/utc/utc_thumbnail_get_data_func.h
@@ -0,0 +1,52 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+/**
+* @file utc_thumbnail_get_data_func.h
+* @author
+* @brief This is the implementaion file for the test case of thumbnail_request_from_db API function
+* @version Initial Creation Version 0.1
+* @date 2011-10-13
+*/
+
+#ifndef __UTS_thumbnail_get_data__FUNC_H_
+#define __UTS_thumbnail_get_data__FUNC_H_
+
+
+#include "utc_media_thumb_common.h"
+
+/* Initialize TCM data structures */
+void (*tet_startup)() = NULL;
+void (*tet_cleanup)() = NULL;
+
+void utc_thumbnail_get_data_func_01();
+void utc_thumbnail_get_data_func_02();
+
+struct tet_testlist tet_testlist[] = {
+ {utc_thumbnail_get_data_func_01, 1},
+ {utc_thumbnail_get_data_func_02, 2},
+ {NULL, 0}
+};
+
+
+#endif // __UTS_thumbnail_get_data__FUNC_H_
+
diff --git a/TC/utc/utc_thumbnail_request_from_db_func.c b/TC/utc/utc_thumbnail_request_from_db_func.c
new file mode 100644
index 0000000..a64f1b8
--- /dev/null
+++ b/TC/utc/utc_thumbnail_request_from_db_func.c
@@ -0,0 +1,85 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+* @file utc_thumbnail_request_from_db_func.c
+* @brief This is a suit of unit test cases to test thumbnail_request_from_db API function
+* @author
+* @version Initial Creation Version 0.1
+* @date 2011-10-13
+*/
+
+#include "utc_thumbnail_request_from_db_func.h"
+
+
+/**
+* @brief This tests int thumbnail_request_from_db() API with valid parameters
+* @par ID utc_thumbnail_request_from_db_func_01
+* @param [in]
+* @return This function returns zero on success, or negative value with error code
+*/
+void utc_thumbnail_request_from_db_func_01()
+{
+ int ret = -1;
+
+ const char *origin_path = "/opt/media/Images and videos/Wallpapers/Home_default.png";
+ char thumb_path[1024] = {0,};
+
+ ret = thumbnail_request_from_db(origin_path, thumb_path, sizeof(thumb_path));
+
+ if (ret < MEDIA_THUMB_ERROR_NONE) {
+ UTC_THUMB_LOG( "unable to get thumbnail from thumb-daemon. error code->%d", ret);
+ tet_result(TET_FAIL);
+ return;
+ } else {
+ tet_result(TET_PASS);
+ }
+
+ return;
+}
+
+
+/**
+* @brief This tests int thumbnail_request_from_db() API with invalid parameters
+* @par ID utc_thumbnail_request_from_db_func_02
+* @param [in]
+* @return error code on success
+*/
+void utc_thumbnail_request_from_db_func_02()
+{
+ int ret = -1;
+
+ const char *origin_path = NULL;
+ char thumb_path[1024] = {0,};
+
+ ret = thumbnail_request_from_db(origin_path, thumb_path, sizeof(thumb_path));
+
+ if (ret < MEDIA_THUMB_ERROR_NONE) {
+ UTC_THUMB_LOG("abnormal condition test for null, error code->%d", ret);
+ tet_result(TET_PASS);
+ } else {
+ UTC_THUMB_LOG("Getting thumbnail from thumb-daemon should be failed because the origin_path is NULL");
+ tet_result(TET_FAIL);
+ }
+
+ return ;
+}
+
diff --git a/TC/utc/utc_thumbnail_request_from_db_func.h b/TC/utc/utc_thumbnail_request_from_db_func.h
new file mode 100644
index 0000000..8443dd8
--- /dev/null
+++ b/TC/utc/utc_thumbnail_request_from_db_func.h
@@ -0,0 +1,51 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+* @file utc_thumbnail_request_from_db_func.h
+* @author
+* @brief This is the implementaion file for the test case of thumbnail_request_from_db API function
+* @version Initial Creation Version 0.1
+* @date 2011-10-13
+*/
+
+#ifndef __UTS_thumbnail_request_from_db__FUNC_H_
+#define __UTS_thumbnail_request_from_db__FUNC_H_
+
+
+#include "utc_media_thumb_common.h"
+
+/* Initialize TCM data structures */
+void (*tet_startup)() = 0;
+void (*tet_cleanup)() = 0;
+
+void utc_thumbnail_request_from_db_func_01();
+void utc_thumbnail_request_from_db_func_02();
+
+struct tet_testlist tet_testlist[] = {
+ {utc_thumbnail_request_from_db_func_01, 1},
+ {utc_thumbnail_request_from_db_func_02, 2},
+ {NULL, 0}
+};
+
+
+#endif // __UTS_thumbnail_request_from_db__FUNC_H_
+
diff --git a/debian/changelog b/debian/changelog
new file mode 100755
index 0000000..bac81d5
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,31 @@
+libmedia-thumbnail (0.2.0-3) unstable; urgency=low
+
+ * Separates md5 codes to another shared object
+ * Git : pkgs/l/libmedia-thumbnail
+ * Tag : libmedia-thumbnail_0.2.0-3
+
+ -- Hyunjun Ko <zzoon.ko@samsung.com> Tue, 3 Jan 2011 18:30:00 +0900
+
+libmedia-thumbnail (0.2.0-2) unstable; urgency=low
+
+ * Remove timeout in select for battery
+ * Git : pkgs/l/libmedia-thumbnail
+ * Tag : libmedia-thumbnail_0.2.0-2
+
+ -- Hyunjun Ko <zzoon.ko@samsung.com> Thu, 22 Dec 2011 16:00:00 +0900
+
+libmedia-thumbnail (0.2.0-1) unstable; urgency=low
+
+ * Change the symbolic link path of start script
+ * Git : pkgs/l/libmedia-thumbnail
+ * Tag : libmedia-thumbnail_0.2.0-1
+
+ -- Hyunjun Ko <zzoon.ko@samsung.com> Tue, 20 Dec 2011 18:00:00 +0900
+
+libmedia-thumbnail (0.2.0-0) unstable; urgency=low
+
+ * Initial Release.
+ * Git : pkgs/l/libmedia-thumbnail
+ * Tag : libmedia-thumbnail_0.2.0-0
+
+ -- Hyunjun Ko <zzoon.ko@samsung.com> Wed, 7 Dec 2011 15:50:00 +0900
diff --git a/debian/compat b/debian/compat
new file mode 100755
index 0000000..7ed6ff8
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+5
diff --git a/debian/control b/debian/control
new file mode 100755
index 0000000..a5573b9
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,49 @@
+Source: libmedia-thumbnail
+Section: libs
+Priority: extra
+Maintainer: Hyunjun Ko<zzoon.ko@samsung.com>, Byungwook Jang <bw.jang@samsung.com>
+Uploaders: Hyunjun Ko<zzoon.ko@samsung.com>
+Build-Depends: debhelper (>= 5), libglib2.0-dev,
+ dlog-dev,
+ libmedia-service-dev,
+ libmm-fileinfo-dev,
+ libmm-utility-dev,
+ drm-service-dev,
+ libexif-dev,
+ libheynoti-dev,
+ libevas-dev,
+ libecore-dev,
+ libaul-1-dev
+Standards-Version: 0.1
+Homepage: N/A
+
+Package: media-thumbnail-server
+Section: utils
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends},
+Description: Media Thumbnail Server.
+
+Package: media-thumbnail-server-dbg
+Section: debug
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends},
+Description: Media Thumbnail Server debug pkg.
+
+Package: libmedia-thumbnail
+Section: libs
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: Media thumbnail service library for multimedia applications.
+
+Package: libmedia-thumbnail-dev
+Section: libdevel
+Architecture: any
+Depends: libmedia-thumbnail (= ${Source-Version}), libmedia-service-dev, libmm-fileinfo-dev, libmm-utility-dev, libglib2.0-dev, dlog-dev, drm-service-dev, libevas-dev, libecore-dev, libexif-dev, libaul-1-dev
+Description: Media thumbnail service library for multimedia applications. (development)
+
+Package: libmedia-thumbnail-dbg
+Section: debug
+Architecture: any
+Depends: ${misc:Depends}, libmedia-thumbnail (= ${Source-Version})
+Description: Media thumbnail service library for multimedia applications. (unstripped)
+
diff --git a/debian/copyright b/debian/copyright
new file mode 100755
index 0000000..cfce9f8
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,15 @@
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+
+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/debian/docs b/debian/docs
new file mode 100755
index 0000000..a0f0008
--- /dev/null
+++ b/debian/docs
@@ -0,0 +1 @@
+CMakeLists.txt
diff --git a/debian/libmedia-thumbnail-dev.install.in b/debian/libmedia-thumbnail-dev.install.in
new file mode 100755
index 0000000..bb9b916
--- /dev/null
+++ b/debian/libmedia-thumbnail-dev.install.in
@@ -0,0 +1,2 @@
+@PREFIX@/lib/pkgconfig/*
+@PREFIX@/include/*
diff --git a/debian/libmedia-thumbnail.install.in b/debian/libmedia-thumbnail.install.in
new file mode 100755
index 0000000..636e09d
--- /dev/null
+++ b/debian/libmedia-thumbnail.install.in
@@ -0,0 +1 @@
+@PREFIX@/lib/libmedia-*.so*
diff --git a/debian/media-thumbnail-server.install.in b/debian/media-thumbnail-server.install.in
new file mode 100755
index 0000000..8efa1fd
--- /dev/null
+++ b/debian/media-thumbnail-server.install.in
@@ -0,0 +1,2 @@
+@PREFIX@/bin/media-thumbnail-server
+/etc/*
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..50427cf
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,118 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+CFLAGS += -Wall -g
+LDFLAGS +=
+PREFIX ?= /usr
+DATADIR ?= /usr/share
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+ CFLAGS += -O0 -fPIC
+else
+ CFLAGS += -O2 -fPIC
+endif
+
+LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed -Wl,--hash-style=both
+
+CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build_tmp
+
+configure: configure-stamp
+configure-stamp:
+ dh_testdir
+ # Add here commands to configure the package.
+ mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && \
+ CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" cmake .. -DCMAKE_INSTALL_PREFIX="$(PREFIX)"
+
+ touch configure-stamp
+
+build: build-stamp
+
+build-stamp: configure-stamp
+ dh_testdir
+
+ # Add here commands to compile the package.
+ cd $(CMAKE_BUILD_DIR) && $(MAKE)
+
+ for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
+ cat $$f > $${f%.in}; \
+ sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \
+ sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \
+ done
+
+ touch $@
+
+clean:
+ dh_testdir
+ dh_testroot
+ rm -f build-stamp configure-stamp
+
+ # Add here commands to clean up after the build process.
+ rm -rf $(CMAKE_BUILD_DIR)
+
+ for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
+ rm -f $${f%.in}; \
+ done
+
+ dh_clean
+
+install: build
+ dh_testdir
+ dh_testroot
+ dh_clean -k
+ dh_installdirs
+
+ # Add here commands to install the package into debian/wavplayer.
+ cd $(CMAKE_BUILD_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
+
+ mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc5.d/
+ ln -s /etc/init.d/thumbsvr $(CURDIR)/debian/tmp/etc/rc.d/rc5.d/S47thumbsvr
+ mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc3.d/
+ ln -s /etc/init.d/thumbsvr $(CURDIR)/debian/tmp/etc/rc.d/rc3.d/S47thumbsvr
+
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+ dh_testdir
+ dh_testroot
+ dh_installchangelogs
+ dh_installdocs
+ dh_installexamples
+ dh_install --sourcedir=debian/tmp
+# dh_installmenu
+# dh_installdebconf
+# dh_installlogrotate
+# dh_installemacsen
+# dh_installpam
+# dh_installmime
+# dh_python
+# dh_installinit
+# dh_installcron
+# dh_installinfo
+ dh_installman
+ dh_link
+ dh_strip --dbg-package=libmedia-thumbnail-dbg
+ dh_strip --dbg-package=media-thumbnail-server-dbg
+ dh_compress
+ dh_fixperms
+# dh_perl
+ dh_makeshlibs
+ dh_installdeb
+ dh_shlibdeps
+ dh_gencontrol
+ dh_md5sums
+ dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
diff --git a/include/media-thumb-error.h b/include/media-thumb-error.h
new file mode 100755
index 0000000..36e79c8
--- /dev/null
+++ b/include/media-thumb-error.h
@@ -0,0 +1,62 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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 */
+
+/**
+ @}
+*/
+
+/**
+ @}
+*/
+
+#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..c20e8ba
--- /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 <zzoon.ko@samsung.com>
+ *
+ * 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, /* 256x256 */
+ MEDIA_THUMB_SMALL, /* 96x96 */
+} 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..2fd7b35
--- /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 <zzoon.ko@samsung.com>
+ *
+ * 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 <media-thumbnail.h>
+
+void gen_thumb_hash_code()
+{
+ int ret = MEDIA_THUMB_ERROR_NONE;
+ const char *origin_path = "/opt/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..ab68c4a
--- /dev/null
+++ b/include/media-thumbnail.h
@@ -0,0 +1,144 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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.
+ */
+
+
+/**
+ * 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/dbspace/.media.db".
+ * @par example
+ * @code
+
+#include <media-thumbnail.h>
+
+void gen_thumbs()
+{
+ int ret = MEDIA_THUMB_ERROR_NONE;
+ const char *origin_path = "/opt/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_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 <media-thumbnail.h>
+
+void save_thumbs()
+{
+ int ret = MEDIA_THUMB_ERROR_NONE;
+ const char *origin_path = "/opt/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);
+
+
+
+
+
+/** @} */
+
+/**
+ @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_MEDIA_THUMBNAIL_H_*/
+
diff --git a/license b/license
new file mode 100644
index 0000000..4c20031
--- /dev/null
+++ b/license
@@ -0,0 +1,10 @@
+libmedia-thumbnail:
+
+Most files in libmedia-thumbnail are under the Apache License Version 2.0.
+Read the file LICENSE for details.
+
+Some parts of libmedia-thumbnail are licensed under the GNU Lesser General Public License version 2.1
+See the file COPYING for details.
+
+Specifically, the LGPL parts of libmedia-thumbnail are
+ - md5/media-thumb-hash.c
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 <string.h> /* 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<<s | 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 <stdint.h>
+#include <sys/types.h>
+
+#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 <hp@redhat.com>, Owen Taylor <otaylor@redhat.com
+ *
+ * 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 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/* The array below is taken from gconvert.c, which is licensed by GNU Lesser General Public License
+ * Code to escape string is also taken partially from gconvert.c
+ * File name is changed to media-thumb-hash.c
+ */
+
+#include "md5.h"
+#include "media-thumbnail-private.h"
+#include <string.h>
+#include <alloca.h>
+
+
+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.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..4512f03
--- /dev/null
+++ b/packaging/libmedia-thumbnail.spec
@@ -0,0 +1,88 @@
+Name: libmedia-thumbnail
+Summary: Media thumbnail service library for multimedia applications.
+Version: 0.1.9
+Release: 1
+Group: TO_BE/FILLED_IN
+License: TO_BE/FILLED_IN
+Source0: %{name}-%{version}.tar.gz
+BuildRequires: cmake
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(libmedia-service)
+BuildRequires: pkgconfig(mm-fileinfo)
+BuildRequires: pkgconfig(mmutil-imgp)
+BuildRequires: pkgconfig(mmutil-jpeg)
+BuildRequires: pkgconfig(drm-service)
+BuildRequires: pkgconfig(libexif)
+BuildRequires: pkgconfig(heynoti)
+BuildRequires: pkgconfig(evas)
+BuildRequires: pkgconfig(ecore)
+BuildRequires: pkgconfig(aul)
+
+
+%description
+Description: Media thumbnail service library for multimedia applications.
+
+
+%package devel
+License: TO_BE / FILL_IN
+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: TO_BE / FILL_IN
+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
+
+mkdir -p %{buildroot}%{_sysconfdir}/rc.d/rc5.d/
+ln -s %{_sysconfdir}/init.d/thumbsvr %{buildroot}%{_sysconfdir}/rc.d/rc5.d/S47thumbsvr
+mkdir -p %{buildroot}%{_sysconfdir}/rc.d/rc3.d/
+ln -s %{_sysconfdir}/init.d/thumbsvr %{buildroot}%{_sysconfdir}/rc.d/rc3.d/S47thumbsvr
+
+
+
+%files
+%defattr(-,root,root,-)
+%{_libdir}/libmedia-thumbnail.so.*
+%{_libdir}/libmedia-hash.so.*
+
+
+%files devel
+%defattr(-,root,root,-)
+%{_libdir}/libmedia-thumbnail.so
+%{_libdir}/libmedia-hash.so
+%{_libdir}/pkgconfig/media-thumbnail.pc
+%{_includedir}/media-thumbnail/media-thumb-types.h
+%{_includedir}/media-thumbnail/media-thumb-error.h
+%{_includedir}/media-thumbnail/media-thumbnail.h
+%{_includedir}/media-thumbnail/media-thumbnail-private.h
+
+
+%files -n media-thumbnail-server
+%defattr(-,root,root,-)
+%{_bindir}/media-thumbnail-server
+%{_sysconfdir}/init.d/thumbsvr
+%{_sysconfdir}/rc.d/rc3.d/S47thumbsvr
+%{_sysconfdir}/rc.d/rc5.d/S47thumbsvr
+%exclude %{_bindir}/test-thumb
+
diff --git a/server/include/thumb-server-internal.h b/server/include/thumb-server-internal.h
new file mode 100755
index 0000000..1b19a61
--- /dev/null
+++ b/server/include/thumb-server-internal.h
@@ -0,0 +1,52 @@
+/*
+ * media-thumbnail-server
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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 <glib.h>
+#include "media-thumb-ipc.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;
+
+typedef struct _queueMsg{
+ thumbMsg *recv_msg;
+ thumbMsg *res_msg;
+ struct sockaddr_in *client_addr;
+} queueMsg;
+
+int _thumb_daemon_get_sockfd();
+GAsyncQueue *_thumb_daemon_get_queue();
+gboolean _thumb_daemon_udp_thread(void *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..7e749a3
--- /dev/null
+++ b/server/thumb-server-internal.c
@@ -0,0 +1,380 @@
+/*
+ * media-thumbnail-server
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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 <unistd.h>
+#include <dirent.h>
+#include <stdio.h>
+#include <string.h>
+
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "Thumb-Daemon"
+
+static int sock;
+GAsyncQueue *g_req_queue = NULL;
+
+static __thread _server_mode_e g_server_mode = BLOCK_MODE;
+static __thread int g_media_svr_pid = 0;
+
+int _thumb_daemon_get_sockfd()
+{
+ return sock;
+}
+
+
+GAsyncQueue *_thumb_daemon_get_queue()
+{
+ return g_req_queue;
+}
+
+void _thumb_daemon_destroy_queue_msg(queueMsg *msg)
+{
+ if (msg != NULL) {
+ if (msg->recv_msg != NULL) {
+ free(msg->recv_msg);
+ msg->recv_msg = NULL;
+ }
+
+ if (msg->res_msg != NULL) {
+ free(msg->res_msg);
+ msg->res_msg = NULL;
+ }
+
+ msg = NULL;
+ }
+}
+
+int _thumb_daemon_compare_pid_with_mediaserver_fast(int pid)
+{
+ int find_pid = -1;
+
+ char path[128];
+ char buff[128];
+ snprintf(path, sizeof(path), "/proc/%d/status", g_media_svr_pid);
+
+ FILE *fp = NULL;
+ fp = fopen(path, "rt");
+ if (fp) {
+ fgets(buff, sizeof(buff), fp);
+ fclose(fp);
+
+ if (strstr(buff, "media-server")) {
+ find_pid = g_media_svr_pid;
+ thumb_dbg(" find_pid : %d", find_pid);
+ } else {
+ g_media_svr_pid = 0;
+ return GETPID_FAIL;
+ }
+ } else {
+ thumb_err("Can't read file [%s]", path);
+ g_media_svr_pid = 0;
+ return GETPID_FAIL;
+ }
+
+ if (find_pid == pid) {
+ thumb_dbg("This is a request from media-server");
+ return MEDIA_SERVER_PID;
+ } else {
+ thumb_dbg("This is a request from other apps");
+ return OTHERS_PID;
+ }
+}
+
+int _thumb_daemon_compare_pid_with_mediaserver(int pid)
+{
+ DIR *pdir;
+ struct dirent pinfo;
+ struct dirent *result = NULL;
+
+ pdir = opendir("/proc");
+ if (pdir == NULL) {
+ thumb_err("err: NO_DIR");
+ return GETPID_FAIL;
+ }
+
+ while (!readdir_r(pdir, &pinfo, &result)) {
+ if (result == NULL)
+ break;
+
+ if (pinfo.d_type != 4 || pinfo.d_name[0] == '.'
+ || pinfo.d_name[0] > 57)
+ continue;
+
+ FILE *fp;
+ char buff[128];
+ char path[128];
+
+ snprintf(path, sizeof(path), "/proc/%s/status", pinfo.d_name);
+
+ fp = fopen(path, "rt");
+ if (fp) {
+ fgets(buff, sizeof(buff), fp);
+ fclose(fp);
+
+ if (strstr(buff, "media-server")) {
+ thumb_dbg("pinfo->d_name : %s", pinfo.d_name);
+ g_media_svr_pid = atoi(pinfo.d_name);
+ thumb_dbg("Media Server PID : %d", g_media_svr_pid);
+ }
+ }
+ }
+
+ closedir(pdir);
+
+ if (g_media_svr_pid == pid) {
+ thumb_dbg("This is a request from media-server");
+ return MEDIA_SERVER_PID;
+ } else {
+ thumb_dbg("This is a request from other apps");
+ return OTHERS_PID;
+ }
+}
+
+int _thumb_daemon_recv_by_select(int fd, gboolean is_timeout)
+{
+ thumb_err("");
+ fd_set fds;
+ int ret = -1;
+
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+
+ if (is_timeout) {
+ struct timeval timeout;
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
+
+ ret = select(fd + 1, &fds, 0, 0, &timeout);
+ } else {
+ ret = select(fd + 1, &fds, 0, 0, NULL);
+ }
+
+ return ret;
+}
+
+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) {
+ 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_process_queue_jobs()
+{
+ int length = 0;
+
+ while(1) {
+ length = g_async_queue_length(g_req_queue);
+ if (length > 0) {
+ thumb_dbg("There are %d jobs in the queue", length);
+ queueMsg *data = g_async_queue_pop(g_req_queue);
+
+ _thumb_daemon_process_job(data->recv_msg, data->res_msg);
+
+ if (sendto(sock, data->res_msg, sizeof(thumbMsg), 0, (struct sockaddr *)data->client_addr, sizeof(struct sockaddr_in)) != sizeof(thumbMsg)) {
+ thumb_err("sendto failed\n");
+ } else {
+ thumb_dbg("Sent %s(%d) \n", data->res_msg->dst_path, strlen(data->res_msg->dst_path));
+ }
+
+ _thumb_daemon_destroy_queue_msg(data);
+ } else {
+ break;
+ }
+ }
+
+ g_server_mode = BLOCK_MODE;
+
+ return 0;
+}
+
+gboolean _thumb_daemon_udp_thread(void *data)
+{
+ int err = -1;
+ gboolean is_timeout = FALSE;
+
+ struct sockaddr_in serv_addr;
+ struct sockaddr_in client_addr;
+ unsigned short serv_port;
+ unsigned int client_addr_len;
+
+ queueMsg *queue_msg = NULL;
+ thumbMsg recv_msg;
+ thumbMsg res_msg;
+ int recv_msg_size;
+ char thumb_path[MAX_PATH_SIZE + 1];
+
+ memset((void *)&recv_msg, 0, sizeof(recv_msg));
+ memset((void *)&res_msg, 0, sizeof(res_msg));
+ serv_port = THUMB_DAEMON_PORT;
+
+ if (!g_req_queue) {
+ g_req_queue = g_async_queue_new();
+ }
+
+ /* Creaete a datagram/UDP socket */
+ if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+ thumb_err("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");
+ return FALSE;
+ }
+
+ thumb_dbg("bind success");
+
+ while(1) {
+ if (g_server_mode == TIMEOUT_MODE) {
+ thumb_dbg("Wait for other app's request for 1 sec");
+ is_timeout = TRUE;
+ } else {
+ is_timeout = FALSE;
+ }
+
+ err = _thumb_daemon_recv_by_select(sock, is_timeout);
+
+ if (err == 0) {
+ /* timeout in select() */
+ err = _thumb_daemon_process_queue_jobs();
+ continue;
+
+ } else if (err == -1) {
+ /* error in select() */
+ thumb_err("ERROR in select()");
+ continue;
+
+ } else {
+ _pid_e pid_type = 0;
+ /* Socket is readable */
+ client_addr_len = sizeof(client_addr);
+ if ((recv_msg_size = recvfrom(sock, &recv_msg, sizeof(recv_msg), 0, (struct sockaddr *)&client_addr, &client_addr_len)) < 0) {
+ thumb_err("recvfrom failed\n");
+ continue;
+ }
+
+ 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 (g_media_svr_pid > 0) {
+ pid_type = _thumb_daemon_compare_pid_with_mediaserver_fast(recv_msg.pid);
+ }
+
+ if (g_media_svr_pid <= 0) {
+ pid_type = _thumb_daemon_compare_pid_with_mediaserver(recv_msg.pid);
+ }
+
+ if (pid_type == GETPID_FAIL) {
+ thumb_err("Failed to get media svr pid. So This req is regarded as other app's request.");
+ pid_type = OTHERS_PID;
+ }
+
+ if (g_server_mode == BLOCK_MODE || pid_type == OTHERS_PID) {
+ 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)\n", ((double)(end - start) / (double)CLOCKS_PER_SEC), recv_msg.org_path);
+
+ if (sendto(sock, &res_msg, sizeof(res_msg), 0, (struct sockaddr *)&client_addr, sizeof(client_addr)) != sizeof(res_msg)) {
+ thumb_err("sendto failed\n");
+ } else {
+ thumb_dbg("Sent %s(%d) \n", res_msg.dst_path, strlen(res_msg.dst_path));
+ }
+
+ memset((void *)&recv_msg, 0, sizeof(recv_msg));
+ memset((void *)&res_msg, 0, sizeof(res_msg));
+
+ if (pid_type == OTHERS_PID) {
+ g_server_mode = TIMEOUT_MODE;
+ }
+ } else {
+ /* This is a request from media-server on TIMEOUT mode.
+ So this req is going to be pushed to the queue */
+
+ queue_msg = malloc(sizeof(queueMsg));
+ if (queue_msg == NULL) {
+ thumb_err("malloc failed");
+ continue;
+ }
+ queue_msg->recv_msg = malloc(sizeof(thumbMsg));
+ if (queue_msg->recv_msg == NULL) {
+ thumb_err("malloc failed");
+ SAFE_FREE(queue_msg);
+ continue;
+ }
+ queue_msg->res_msg = malloc(sizeof(thumbMsg));
+ if (queue_msg->res_msg == NULL) {
+ thumb_err("malloc failed");
+ SAFE_FREE(queue_msg->recv_msg);
+ SAFE_FREE(queue_msg);
+ continue;
+ }
+ queue_msg->client_addr = malloc(sizeof(struct sockaddr_in));
+ if (queue_msg->client_addr == NULL) {
+ thumb_err("malloc failed");
+ SAFE_FREE(queue_msg->recv_msg);
+ SAFE_FREE(queue_msg->res_msg);
+ SAFE_FREE(queue_msg);
+ continue;
+ }
+
+ memcpy(queue_msg->recv_msg, &recv_msg, sizeof(thumbMsg));
+ memcpy(queue_msg->res_msg, &res_msg, sizeof(thumbMsg));
+ memcpy(queue_msg->client_addr, &client_addr, sizeof(struct sockaddr_in));
+
+ g_async_queue_push(g_req_queue, GINT_TO_POINTER(queue_msg));
+ g_server_mode = TIMEOUT_MODE;
+ }
+ }
+ }
+
+ close(sock);
+
+ return TRUE;
+}
+
diff --git a/server/thumb-server.c b/server/thumb-server.c
new file mode 100755
index 0000000..16a42fe
--- /dev/null
+++ b/server/thumb-server.c
@@ -0,0 +1,139 @@
+/*
+ * media-thumbnail-server
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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 <pthread.h>
+#include <heynoti.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "Thumb-Daemon"
+
+#ifdef USE_HIB
+#undef USE_HIB
+#endif
+
+#ifdef USE_HIB
+int hib_fd = 0;
+
+void _hibernation_leave_callback(void *data)
+{
+ thumb_dbg("hibernation leave callback\n");
+
+ GMainLoop *mainloop = NULL;
+ GThread *udp_thr = NULL;
+
+ if (!g_thread_supported()) {
+ g_thread_init(NULL);
+ }
+
+ udp_thr = g_thread_create((GThreadFunc)_thumb_daemon_udp_thread, NULL, FALSE, NULL);
+ mainloop = g_main_loop_new(NULL, FALSE);
+
+ thumb_dbg("*****************************************");
+ thumb_dbg("*** Server of thumbnail is running ***");
+ thumb_dbg("*****************************************");
+
+ g_main_loop_run(mainloop);
+
+ g_main_loop_unref(mainloop);
+
+ exit(0);
+}
+
+void _hibernation_enter_callback(void *data)
+{
+ thumb_dbg("hibernation enter callback\n");
+
+ int sock = _thumb_daemon_get_sockfd();
+ if (sock != 0) {
+ close(sock);
+ }
+
+ GAsyncQueue *req_queue = _thumb_daemon_get_queue();
+
+ if (req_queue != NULL) {
+ g_async_queue_unref(req_queue);
+ req_queue = NULL;
+ }
+
+ if (hib_fd != 0) {
+ heynoti_close(hib_fd);
+ hib_fd = 0;
+ }
+}
+
+void _hibernation_initialize(void)
+{
+ hib_fd = heynoti_init();
+ heynoti_subscribe(hib_fd, "HIBERNATION_ENTER",
+ _hibernation_enter_callback, (void *)hib_fd);
+ heynoti_subscribe(hib_fd, "HIBERNATION_LEAVE",
+ _hibernation_leave_callback, (void *)hib_fd);
+ heynoti_attach_handler(hib_fd);
+
+ return;
+}
+
+void _hibernation_fianalize(void)
+{
+ heynoti_close(hib_fd);
+}
+#endif
+
+int main()
+{
+#ifdef USE_HIB
+ _hibernation_initialize();
+#endif
+
+ GMainLoop *mainloop = NULL;
+ GThread *udp_thr = NULL;
+
+ if (!g_thread_supported()) {
+ g_thread_init(NULL);
+ }
+
+ udp_thr = g_thread_create((GThreadFunc)_thumb_daemon_udp_thread, NULL, FALSE, NULL);
+ mainloop = g_main_loop_new(NULL, FALSE);
+
+ thumb_dbg("*****************************************");
+ thumb_dbg("*** Server of thumbnail is running ***");
+ thumb_dbg("*****************************************");
+
+ g_main_loop_run(mainloop);
+
+ g_main_loop_unref(mainloop);
+
+#ifdef USE_HIB
+ _hibernation_fianalize();
+#endif
+
+ 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 <zzoon.ko@samsung.com>
+ *
+ * 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<<curr_size)-1;\
+ c = ret;\
+}
+
+#define __get_next_code_second_nbits_left_0(pInputStream) \
+{\
+ {\
+ b1 = (pInputStream)[inputPos++];\
+ ret = b1;\
+ nbits_left = 8;\
+ --navail_bytes;\
+ } \
+}
+
+#define __get_next_code_second_nbits_left_not_0(pInputStream) \
+{\
+ {\
+ ret = b1 >> (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..c39d57c
--- /dev/null
+++ b/src/codec/img-codec-osal.c
@@ -0,0 +1,159 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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 "img-codec-osal.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <drm-service.h>
+
+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);
+}
+
+DRM_FILE_HANDLE hDrmFile = NULL;
+static BOOL _is_real_drm = FALSE;
+
+HFile DrmOpenFile(const char *szPathName)
+{
+ if (drm_svc_is_drm_file(szPathName) == 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;
+ }
+
+ return fp;
+
+ } else {
+ int ret =
+ drm_svc_open_file(szPathName, DRM_PERMISSION_DISPLAY,
+ &hDrmFile);
+
+ if (ret != DRM_RESULT_SUCCESS) {
+ return (HFile) INVALID_HOBJ;
+ }
+ return hDrmFile;
+ }
+}
+
+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 {
+ drm_svc_read_file((DRM_FILE_HANDLE) hFile, pBuffer, bufLen,
+ &readCnt);
+ *pReadLen = (ULONG) readCnt;
+ }
+ return TRUE;
+}
+
+long DrmTellFile(HFile hFile)
+{
+ if (!_is_real_drm) {
+ return ftell(hFile);
+ } else {
+ return drm_svc_tell_file((DRM_FILE_HANDLE) hFile);
+ }
+}
+
+BOOL DrmSeekFile(HFile hFile, long position, long offset)
+{
+
+ if (position < 0) {
+ return FALSE;
+ }
+ if (!_is_real_drm) {
+ fseek(hFile, offset, position);
+ } else {
+ drm_svc_seek_file((DRM_FILE_HANDLE) hFile, offset, position);
+ }
+
+ 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 {
+ drm_svc_close_file((DRM_FILE_HANDLE) hFile);
+ }
+
+ return TRUE;
+}
diff --git a/src/codec/img-codec-parser.c b/src/codec/img-codec-parser.c
new file mode 100644
index 0000000..c5f9231
--- /dev/null
+++ b/src/codec/img-codec-parser.c
@@ -0,0 +1,883 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(_PERFORMANCE_CHECK_)
+#include <time.h>
+#include <sys/time.h>
+#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;
+ }
+
+ thumb_dbg("file size : %d", fileAttrib.fileSize);
+
+ 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 ((length = EncodedDataBuffer[ifegstreamctrl.buffpos++]) > 0) { /* get the data length */
+ if (_CheckBuffer
+ (&ifegstreamctrl,
+ length) == 0) {
+ thumb_warn
+ ("_CheckBuffer was failed");
+ 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..06a6419
--- /dev/null
+++ b/src/codec/img-codec.c
@@ -0,0 +1,252 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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 <string.h>
+
+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));
+ int i =
+ image_info->width * image_info->height * 3;
+ 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;
+
+ rgb565buf = (unsigned short *)pBuf_rgb565;
+ if (rgb565buf == NULL) {
+ thumb_err("rgb565buf is NULL: Error !!!");
+ return FALSE;
+ }
+
+ rgb888Buf = (unsigned char *)malloc(width * height * 3);
+
+ if (rgb888Buf == NULL) {
+ thumb_err("rgb888Buf is NULL: Error !!!");
+ return FALSE;
+ }
+
+ memset(rgb888Buf, 0, (width * height * 3));
+
+ 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 <zzoon.ko@samsung.com>
+ *
+ * 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 <zzoon.ko@samsung.com>
+ *
+ * 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 <zzoon.ko@samsung.com>
+ *
+ * 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 <zzoon.ko@samsung.com>
+ *
+ * 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 <stdio.h>
+#include <stdbool.h>
+
+#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 <zzoon.ko@samsung.com>
+ *
+ * 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..8289cf0
--- /dev/null
+++ b/src/include/codec/img-codec-osal.h
@@ -0,0 +1,128 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+#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)
+#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 <zzoon.ko@samsung.com>
+ *
+ * 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 <zzoon.ko@samsung.com>
+ *
+ * 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..3c91a1e
--- /dev/null
+++ b/src/include/ipc/media-thumb-ipc.h
@@ -0,0 +1,81 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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"
+
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <signal.h>
+
+#ifndef _MEDIA_THUMB_IPC_H_
+#define _MEDIA_THUMB_IPC_H_
+
+#define THUMB_DAEMON_PORT 10000
+#define MAX_PATH_SIZE 4096
+
+#define TIMEOUT_SEC 10
+#define MAX_TRIES 3
+
+enum {
+ THUMB_REQUEST_DB,
+ THUMB_REQUEST_SAVE,
+ THUMB_RESPONSE
+};
+
+enum {
+ THUMB_SUCCESS,
+ THUMB_FAIL
+};
+
+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;
+ char org_path[MAX_PATH_SIZE];
+ char dst_path[MAX_PATH_SIZE];
+} thumbMsg;
+
+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_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..192524a
--- /dev/null
+++ b/src/include/media-thumb-internal.h
@@ -0,0 +1,68 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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"
+
+#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
+
+
+typedef struct {
+ int size;
+ int width;
+ int height;
+ int origin_width;
+ int origin_height;
+ 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
+};
+
+int
+_media_thumb_image(const char *origin_path,
+ int thumb_length,
+ media_thumb_format format,
+ media_thumb_info *thumb_info);
+
+int
+_media_thumb_video(const char *origin_path,
+ int thumb_length,
+ 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..1c1fd13
--- /dev/null
+++ b/src/include/util/media-thumb-db.h
@@ -0,0 +1,43 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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"
+
+#ifndef _MEDIA_THUMB_DB_H_
+#define _MEDIA_THUMB_DB_H_
+
+int
+_media_thumb_get_thumb_from_db(const char *origin_path,
+ char *thumb_path,
+ int max_length,
+ int *need_update_db);
+
+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..164e269
--- /dev/null
+++ b/src/include/util/media-thumb-debug.h
@@ -0,0 +1,73 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <dlog.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+
+#define _PERFORMANCE_CHECK_
+
+
+#define LOG_TAG "Media-Thumb"
+
+#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"[%s : %d] " fmt "\n", __FUNCTION__, __LINE__, ##arg)
+#define thumb_warn(fmt, arg...) LOGW(FONT_COLOR_GREEN"[%s : %d] " fmt "\n", __FUNCTION__, __LINE__, ##arg)
+#define thumb_err(fmt, arg...) LOGE(FONT_COLOR_RED"[%s : %d] " fmt "\n", __FUNCTION__, __LINE__, ##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..387fe61
--- /dev/null
+++ b/src/include/util/media-thumb-util.h
@@ -0,0 +1,128 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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"
+
+#ifndef _MEDIA_THUMB_UTIL_H_
+#define _MEDIA_THUMB_UTIL_H_
+
+#define SAFE_FREE(src) { if(src) {free(src); src = NULL;}}
+
+#define THUMB_NONE_TYPE 0x00000001 /* Image */
+#define THUMB_IMAGE_TYPE 0x00000001 /* Image */
+#define THUMB_VIDEO_TYPE 0x00000002 /* Image */
+
+#define THUMB_PATH_PHONE "/opt/media" /**< File path prefix of files stored in phone */
+#define THUMB_PATH_MMC "/opt/storage/sdcard" /**< File path prefix of files stored in mmc card */
+
+#define THUMB_PHONE_PATH "/opt/data/file-manager-service/.thumb/phone"
+#define THUMB_MMC_PATH "/opt/data/file-manager-service/.thumb/mmc"
+
+#define THUMB_DEFAULT_PATH "/opt/data/file-manager-service/.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);
+
+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,
+ char *thumb_path);
+
+/**
+ * _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 <media-thumbnail.h>
+
+void test_get_thumb_data()
+{
+ int ret = MEDIA_THUMB_ERROR_NONE;
+ int thumb_type = 0;
+ const char *origin_path = "/opt/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);
+
+#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..3718f6f
--- /dev/null
+++ b/src/ipc/media-thumb-ipc.c
@@ -0,0 +1,277 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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 <glib.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+
+static __thread int g_tries = 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;
+ struct sockaddr_in from_addr;
+
+ unsigned int from_size;
+
+ int send_str_len = strlen(origin_path);
+ int recv_msg_len;
+ int recv_str_len;
+ int pid;
+
+ thumbMsg req_msg;
+ thumbMsg recv_msg;
+
+ memset((void *)&req_msg, 0, sizeof(thumbMsg));
+ memset((void *)&recv_msg, 0, sizeof(thumbMsg));
+
+ 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) {
+ strncpy(req_msg.dst_path, thumb_path, sizeof(req_msg.dst_path));
+ req_msg.dst_path[strlen(req_msg.dst_path)] = '\0';
+ }
+
+ struct timeval tv_timeout = { TIMEOUT_SEC, 0 };
+
+ serv_ip = "127.0.0.1";
+
+ if (send_str_len > MAX_PATH_SIZE) {
+ thumb_err("original path's length exceeds %d(max packet size)", MAX_PATH_SIZE);
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ pid = getpid();
+ req_msg.pid = pid;
+
+ /* Creaete a datagram/UDP socket */
+ if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+ thumb_err("socket failed: %d\n", errno);
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+
+ if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv_timeout, sizeof(tv_timeout)) == -1) {
+ thumb_err("setsockopt failed: %d\n", errno);
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+
+ 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(THUMB_DAEMON_PORT);
+
+ if (sendto(sock, &req_msg, sizeof(req_msg), 0, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) != sizeof(req_msg)) {
+ thumb_err("sendto failed: %d\n", errno);
+ close(sock);
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+
+ thumb_dbg("Sending msg to thumbnail daemon is successful");
+
+ /* recv a response */
+ from_size = sizeof(from_addr);
+
+ while(1) {
+ if ((recv_msg_len = recvfrom(sock, &recv_msg, sizeof(recv_msg), 0, (struct sockaddr *)&from_addr, &from_size)) < 0) {
+
+ if (errno == EWOULDBLOCK) {
+#ifdef DO_RETRY
+ thumb_warn("Timeout..%d more tries", MAX_TRIES - g_tries);
+ if (g_tries < MAX_TRIES) {
+ if (sendto(sock, &req_msg, sizeof(req_msg), 0, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) != sizeof(req_msg)) {
+ thumb_err("sendto failed: %d\n", errno);
+ close(sock);
+ g_tries = 0;
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+ } else {
+ thumb_err("Timeout. Can't try any more");
+ close(sock);
+ g_tries = 0;
+ return MEDIA_THUMB_ERROR_TIMEOUT;
+ }
+ g_tries++;
+#else
+ thumb_warn("Timeout. Can't try any more");
+ g_tries = 0;
+ close(sock);
+ return MEDIA_THUMB_ERROR_TIMEOUT;
+#endif
+ } else {
+ thumb_err("recvfrom failed");
+ g_tries = 0;
+ close(sock);
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+ } else {
+ thumb_dbg("recvfrom done");
+ break;
+ }
+ }
+
+ g_tries = 0;
+
+ if (serv_addr.sin_addr.s_addr != from_addr.sin_addr.s_addr) {
+ thumb_err("addr is different");
+ close(sock);
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+
+ recv_msg.org_path[MAX_PATH_SIZE - 1] = '\0';
+ 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) {
+ 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;
+
+ 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 = req_msg->dst_path;
+ max_length = sizeof(req_msg->dst_path);
+
+ if (msg_type == THUMB_REQUEST_DB) {
+ 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);
+ 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");
+ strncpy(res_msg->dst_path, thumb_path, sizeof(res_msg->dst_path));
+ return 0;
+ }
+
+ err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h);
+ if (err < 0) {
+ thumb_err("_thumbnail_get_data failed - %d\n", err);
+ SAFE_FREE(data);
+
+ strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
+ 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;
+
+ err = _media_thumb_save_to_file_with_evas(data, thumb_w, thumb_h, 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)
+ strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
+
+ 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 */
+
+ strncpy(res_msg->dst_path, thumb_path, sizeof(res_msg->dst_path));
+
+ SAFE_FREE(data);
+
+ return 0;
+}
+
+
diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c
new file mode 100755
index 0000000..7b5b47a
--- /dev/null
+++ b/src/media-thumb-internal.c
@@ -0,0 +1,1103 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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 <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <drm-service.h>
+#include <mm_file.h>
+#include <mm_util_imgp.h>
+#include <mm_util_jpeg.h>
+#include <Evas.h>
+#include <Ecore_Evas.h>
+#include <libexif/exif-data.h>
+
+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 (thumb_width < required_width &&
+ thumb_height < required_height) {
+ thumb_dbg("Size of thumb from exif is small");
+ return -1;
+ }
+*/
+
+ 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);
+#if 1
+ 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);
+
+#if 1
+ /* Temporary fix to rotate jpeg image until libjpeg-turbo is installed */
+ int n_times = 0;
+ if (rot_type == MM_UTIL_ROTATE_180) {
+ r_w = decoded.height;
+ r_h = decoded.width;
+ n_times = 2;
+ } else if (rot_type == MM_UTIL_ROTATE_270) {
+ n_times = 3;
+ } else if (rot_type == MM_UTIL_ROTATE_90) {
+ n_times = 1;
+ }
+
+ rot_type = MM_UTIL_ROTATE_90;
+ unsigned int dst_w = r_w;
+ unsigned int dst_h = r_h;
+ unsigned char *tmp_src = NULL;
+ unsigned char *tmp_dst = NULL;
+ tmp_src = decoded.data;
+ tmp_dst = (unsigned char *)malloc(r_size);
+ r_w = decoded.width;
+ r_h = decoded.height;
+
+ while (n_times > 0) {
+ dst_w = r_h;
+ dst_h = r_w;
+
+ thumb_dbg("Times : %d src w : %d, src h: %d", n_times, r_w, r_h);
+ thumb_dbg("Times : %d dst w : %d, dst h: %d\n\n", n_times, dst_w, dst_h);
+
+
+ err = mm_util_rotate_image(tmp_src, r_w, r_h,
+ MM_UTIL_IMG_FMT_RGB888,
+ tmp_dst, &dst_w, &dst_h,
+ rot_type);
+
+ if (err < 0) {
+ thumb_dbg("mm_util_rotate_image failed : %d", err);
+ SAFE_FREE(tmp_src);
+ SAFE_FREE(tmp_dst);
+ return err;
+ } else {
+ thumb_dbg("mm_util_rotate_image succeed");
+ }
+
+ SAFE_FREE(tmp_src);
+
+ n_times--;
+ if (n_times == 0) {
+ rotated = tmp_dst;
+ } else {
+ tmp_src = tmp_dst;
+ tmp_dst = (unsigned char *)malloc(r_size);
+ thumb_dbg("Times : %d DST w : %d, DST h: %d", n_times, dst_w, dst_h);
+ }
+ r_w = dst_w;
+ r_h = dst_h;
+ }
+
+#else
+ 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_dbg("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);
+#endif
+
+ 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) {
+#endif
+ unsigned int buf_size = 0;
+
+ err = mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, decoded.width, decoded.height, &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);
+
+ thumb_info->data = decoded.data;
+ thumb_info->size = buf_size;
+ thumb_info->width = decoded.width;
+ thumb_info->height = decoded.height;
+#if 1
+ } else {
+ thumb_warn("Unknown orientation");
+ SAFE_FREE(decoded.data);
+ return -1;
+ }
+#endif
+ 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_init();
+
+ 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);
+ ecore_evas_shutdown();
+
+ return 0;
+}
+
+int _media_thumb_decode_with_evas(const char *origin_path, int thumb_length,
+ media_thumb_info *thumb_info, int need_scale)
+{
+ ecore_evas_init();
+
+ Ecore_Evas *ee = ecore_evas_buffer_new(
+ thumb_length, thumb_length);
+ if (!ee) {
+ thumb_err("Failed to create a ecore evas\n");
+ ecore_evas_shutdown();
+ return -1;
+ }
+
+ Evas *evas = ecore_evas_get(ee);
+ if (!evas) {
+ thumb_err("Failed to ecore_evas_get\n");
+ ecore_evas_free(ee);
+ ecore_evas_shutdown();
+ return -1;
+ }
+
+ Ecore_Evas *resize_img_ee;
+ resize_img_ee =
+ ecore_evas_buffer_new(thumb_length, thumb_length);
+
+ if (!resize_img_ee) {
+ thumb_err("Failed to create a new ecore evas buffer\n");
+ ecore_evas_free(ee);
+ ecore_evas_shutdown();
+ 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(ee);
+ ecore_evas_free(resize_img_ee);
+ ecore_evas_shutdown();
+ return -1;
+ }
+
+ Evas_Object *source_img = evas_object_image_add(resize_img_e);
+ if (!source_img) {
+ thumb_dbg
+ ("evas_object_image_add failed\n");
+ ecore_evas_free(ee);
+ ecore_evas_free(resize_img_ee);
+ ecore_evas_shutdown();
+ return -1;
+ }
+
+ evas_object_image_load_size_set(source_img, thumb_length, thumb_length);
+ evas_object_image_load_orientation_set(source_img, 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_fill_set(source_img,
+ 0, 0,
+ thumb_length,
+ thumb_length);
+ evas_object_image_filled_set(source_img, 1);
+ evas_object_resize(source_img,
+ thumb_length,
+ thumb_length);
+ evas_object_show(source_img);
+
+ Evas_Object *ret_image =
+ evas_object_image_add(evas);
+
+ evas_object_image_size_set(ret_image,
+ thumb_length,
+ thumb_length);
+
+ evas_object_image_fill_set(ret_image, 0,
+ 0,
+ thumb_length,
+ thumb_length);
+
+ 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_length,
+ thumb_length);
+
+ unsigned int buf_size = 0;
+
+ if (mm_util_get_image_size(MM_UTIL_IMG_FMT_BGRA8888, thumb_length,
+ thumb_length, &buf_size) < 0) {
+ thumb_err("Failed to get buffer size");
+
+ ecore_evas_free(ee);
+ ecore_evas_free(resize_img_ee);
+ ecore_evas_shutdown();
+
+ 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_length;
+ thumb_info->height = thumb_length;
+ thumb_info->data = malloc(buf_size);
+ memcpy(thumb_info->data, evas_object_image_data_get(ret_image, 1), buf_size);
+
+ ecore_evas_free(ee);
+ ecore_evas_free(resize_img_ee);
+ ecore_evas_shutdown();
+
+ 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_length,
+ media_thumb_format format,
+ media_thumb_info *thumb_info)
+{
+ int err = -1;
+ int thumb_width = thumb_length;
+ int thumb_height = thumb_length;
+ unsigned int *thumb = NULL;
+
+ thumb = ImgGetFirstFrameAGIFAtSize(origin_path, image_info);
+
+ 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_length,
+ media_thumb_format format,
+ media_thumb_info *thumb_info)
+{
+ int err = -1;
+ err = _media_thumb_decode_with_evas(origin_path, thumb_length, thumb_info, 0);
+
+ 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_length,
+ media_thumb_format format,
+ media_thumb_info *thumb_info)
+{
+ int err = -1;
+ err = _media_thumb_decode_with_evas(origin_path, thumb_length, thumb_info, 0);
+
+ 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_length,
+ media_thumb_format format,
+ media_thumb_info *thumb_info)
+{
+ int err = -1;
+ err = _media_thumb_decode_with_evas(origin_path, thumb_length, thumb_info, 0);
+
+ 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_length,
+ media_thumb_format format,
+ media_thumb_info *thumb_info)
+{
+ int err = -1;
+ err = _media_thumb_decode_with_evas(origin_path, thumb_length, thumb_info, 0);
+
+ 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_length,
+ media_thumb_format format,
+ media_thumb_info *thumb_info)
+{
+ int err = -1;
+ ExifData *ed = NULL;
+ int thumb_done = 0;
+
+ /* Load an ExifData object from an EXIF file */
+ ed = exif_data_new_from_file(origin_path);
+
+ if (ed) {
+ /* First, Get orientation from exif */
+ int orientation = NORMAL;
+ 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");
+ }
+
+ thumb_dbg("Orientation: %d", orientation);
+
+ /* Second, Get thumb from exif */
+ err = _media_thumb_get_thumb_from_exif(ed, origin_path, orientation, thumb_length, thumb_length, 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;
+ }
+ }
+
+ thumb_dbg("Done with exif");
+ exif_data_unref(ed);
+ }
+
+ if (!thumb_done) {
+
+ err = _media_thumb_decode_with_evas(origin_path, thumb_length, thumb_info, 0);
+
+ 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_length,
+ 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);
+ thumb_dbg("image width:%d, height:%d \n", origin_w, origin_h);
+
+ 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_length, format, thumb_info);
+ } else if (image_type == IMG_CODEC_JPEG) {
+ err = _media_thumb_jpeg(origin_path, thumb_length, format, thumb_info);
+ } else if (image_type == IMG_CODEC_PNG) {
+ err = _media_thumb_png(origin_path, thumb_length, format, thumb_info);
+ } else if (image_type == IMG_CODEC_GIF) {
+ err = _media_thumb_gif(origin_path, thumb_length, format, thumb_info);
+ } else if (image_type == IMG_CODEC_BMP) {
+ err = _media_thumb_bmp(origin_path, thumb_length, 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_length, 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_length,
+ 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;
+
+ is_drm = (drm_svc_is_drm_file(origin_path) == 1);
+ 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;
+ }
+
+ if (width > thumb_length || height > thumb_length) {
+ err = _media_thumb_resize_data(frame,
+ width,
+ height,
+ MM_UTIL_IMG_FMT_RGB888,
+ thumb_info,
+ thumb_length,
+ thumb_length);
+
+ 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);
+ }
+
+ err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_RGB888, format);
+ if (err < 0) {
+ thumb_err("_media_thumb_convert_format falied: %d", err);
+ mm_file_destroy_content_attrs(content);
+ 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;
+ }
+
+ mm_file_destroy_content_attrs(content);
+
+ return 0;
+}
+
diff --git a/src/media-thumbnail.c b/src/media-thumbnail.c
new file mode 100755
index 0000000..585be8c
--- /dev/null
+++ b/src/media-thumbnail.c
@@ -0,0 +1,116 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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 <glib.h>
+#include <media-svc.h>
+
+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 = minfo_init();
+
+ err = _media_thumb_get_thumb_from_db(origin_path, thumb_path, max_length, &need_update_db);
+ if (err == 0) {
+ minfo_finalize();
+ return MEDIA_THUMB_ERROR_NONE;
+ }
+
+ /* Request for thumb file to the daemon "Thumbnail generator" */
+ err = _media_thumb_request(THUMB_REQUEST_DB, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info);
+ if (err < 0) {
+ thumb_err("_media_thumb_request failed : %d", err);
+ minfo_finalize();
+ 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);
+ }
+ }
+
+ minfo_finalize();
+ 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, 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;
+}
+
+
diff --git a/src/util/media-thumb-db.c b/src/util/media-thumb-db.c
new file mode 100755
index 0000000..f0e41ad
--- /dev/null
+++ b/src/util/media-thumb-db.c
@@ -0,0 +1,103 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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-svc.h>
+#include <glib.h>
+#include <string.h>
+
+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(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 0;
+}
+
+int
+_media_thumb_update_db(const char *origin_path,
+ char *thumb_path,
+ int width,
+ int height)
+{
+ thumb_dbg("");
+ int err = -1;
+ Mitem *item = NULL;
+
+ err = minfo_get_item(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(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(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);
+
+ thumb_dbg("_media_thumb_update_db success");
+
+ return 0;
+}
+
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 <zzoon.ko@samsung.com>
+ *
+ * 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 <unistd.h>
+#include <asm/unistd.h>
+#include <time.h>
+#include <sys/time.h>
+#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..7d34a7a
--- /dev/null
+++ b/src/util/media-thumb-util.c
@@ -0,0 +1,316 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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 <glib.h>
+#include <aul.h>
+#include <string.h>
+#include <drm-service.h>
+
+#include <Evas.h>
+#include <Ecore_Evas.h>
+
+int _media_thumb_get_length(media_thumb_type thumb_type)
+{
+ if (thumb_type == MEDIA_THUMB_LARGE) {
+ return 256;
+ } else if (thumb_type == MEDIA_THUMB_SMALL) {
+ return 96;
+ } 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;
+ char mimetype[255];
+
+ if (file_full_path == NULL)
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+
+ if (drm_svc_is_drm_file(file_full_path) == DRM_TRUE) {
+ DRM_FILE_TYPE drm_type = DRM_FILE_TYPE_NONE;
+ drm_type = drm_svc_get_drm_type(file_full_path);
+ if (drm_type == DRM_FILE_TYPE_NONE) {
+ return THUMB_NONE_TYPE;
+ }
+ else {
+ drm_content_info_t contentInfo = { 0 };
+
+ ret = drm_svc_get_content_info(file_full_path, &contentInfo);
+ if (ret != DRM_RESULT_SUCCESS) {
+ thumb_err("drm_svc_get_content_info() fails. ");
+ return THUMB_NONE_TYPE;
+ }
+
+ strncpy(mimetype, contentInfo.contentType, sizeof(mimetype));
+ }
+ } 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_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,
+ char *thumb_path)
+{
+ 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) {
+ thumb_dbg("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);
+
+ 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);
+ ecore_evas_shutdown();
+
+ return 0;
+ } else {
+ thumb_dbg("evas_object_image_save failed\n");
+ ecore_evas_free(ee);
+ ecore_evas_shutdown();
+ 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 err = -1;
+ int thumb_length = -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_length = _media_thumb_get_length(thumb_type);
+ if (thumb_length < 0) {
+ thumb_err("media_thumb_type is invalid");
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ thumb_dbg("", 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_length, 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_length, 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;
+
+ 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..3dbbd47
--- /dev/null
+++ b/test/test-thumb.c
@@ -0,0 +1,223 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <Evas.h>
+#include <Ecore_Evas.h>
+#include <mm_util_imgp.h>
+#include <mm_util_jpeg.h>
+
+#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");
+ //const char *origin_path = "/opt/media/test/gif_test.gif";
+ //const char *origin_path = "/opt/media/test/praha_01.gif";
+ //const char *origin_path = "/opt/media/test/test_bmp.bmp";
+ //const char *origin_path = "/opt/media/test/normal.jpg";
+ //const char *origin_path = "/opt/media/test/high.jpg";
+ //const char *origin_path = "/opt/media/test/front.jpg";
+ //const char *origin_path = "/opt/media/test/no_rot_high.jpg";
+ //const char *origin_path = "/opt/media/test/no_rot_front.jpg";
+ //const char *origin_path = "/opt/media/test/movie1.mp4";
+ //const char *origin_path = "/opt/media/test/movie2.avi";
+
+ unsigned char *data = NULL;
+ int thumb_size = 0;
+ int thumb_w = 0;
+ int thumb_h = 0;
+ int origin_w = 0;
+ int origin_h = 0;
+
+ 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);
+ 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");
+ }
+
+ 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 &
+