From: Daniel Juyung Seo Date: Mon, 7 Jun 2010 09:56:08 +0000 (+0900) Subject: Merge with EFL svn repo X-Git-Tag: 2.0_alpha~544 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ffcb54235cdd7598204f72799556f576243aed02;p=framework%2Fuifw%2Fevas.git Merge with EFL svn repo Merge branch 'svn_merge' Conflicts: configure.ac m4/evas_check_loader.m4 src/lib/engines/common/evas_image_load.c src/modules/loaders/Makefile.am src/modules/loaders/bmp/Makefile.am src/modules/loaders/bmp/evas_image_load_bmp.c --- ffcb54235cdd7598204f72799556f576243aed02 diff --cc configure.ac index 346cb74,ec0ab30..b847723 mode 100755,100644..100755 --- a/configure.ac +++ b/configure.ac @@@ -95,7 -118,7 +118,8 @@@ want_evas_image_loader_svg="yes want_evas_image_loader_tiff="yes" want_evas_image_loader_xpm="yes" want_evas_image_loader_bmp="yes" +want_evas_image_loader_wbmp="yes" + want_evas_image_loader_tga="yes" want_evas_font_loader_eet="yes" @@@ -685,8 -696,8 +709,10 @@@ EVAS_CHECK_IMAGE_LOADER([XPM], [${want_ EVAS_CHECK_IMAGE_LOADER([BMP], [${want_evas_image_loader_bmp}]) +EVAS_CHECK_IMAGE_LOADER([WBMP], [${want_evas_image_loader_wbmp}]) + + EVAS_CHECK_IMAGE_LOADER([TGA], [${want_evas_image_loader_tga}]) + ##################################################################### ## Cpu based optimizations @@@ -1370,7 -1413,7 +1428,8 @@@ src/modules/loaders/png/Makefil src/modules/loaders/tiff/Makefile src/modules/loaders/xpm/Makefile src/modules/loaders/bmp/Makefile +src/modules/loaders/wbmp/Makefile + src/modules/loaders/tga/Makefile src/modules/loaders/svg/Makefile src/modules/loaders/pmaps/Makefile src/modules/savers/Makefile diff --cc evas.spec.in index d51dcb8,9ef36ae..7ac3dfc mode 100755,100644..100755 --- a/evas.spec.in +++ b/evas.spec.in diff --cc m4/evas_check_loader.m4 index f6b59e4,cd64c9d..45c1ec6 mode 100755,100644..100755 --- a/m4/evas_check_loader.m4 +++ b/m4/evas_check_loader.m4 @@@ -1,459 -1,457 +1,481 @@@ --dnl use: EVAS_CHECK_LOADER_DEP_EDB(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -- --AC_DEFUN([EVAS_CHECK_LOADER_DEP_EDB], --[ -- --requirement="" --have_dep="no" --evas_image_loader_[]$1[]_cflags="" --evas_image_loader_[]$1[]_libs="" -- --PKG_CHECK_MODULES([EDB], [edb], [have_dep="yes" requirement="edb"], [have_dep="no"]) --evas_image_loader_[]$1[]_cflags="${EDB_CFLAGS}" --evas_image_loader_[]$1[]_libs="${EDB_LIBS}" -- --AC_SUBST([evas_image_loader_$1_cflags]) --AC_SUBST([evas_image_loader_$1_libs]) -- --if test "x$2" = "xstatic" ; then -- requirement_evas="${requirement} ${requirement_evas}" --fi -- --if test "x${have_dep}" = "xyes" ; then -- m4_default([$3], [:]) --else -- m4_default([$4], [:]) --fi -- --]) -- --dnl use: EVAS_CHECK_LOADER_DEP_EET(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -- --AC_DEFUN([EVAS_CHECK_LOADER_DEP_EET], --[ -- --requirement="" --have_dep="no" --evas_image_loader_[]$1[]_cflags="" --evas_image_loader_[]$1[]_libs="" -- --PKG_CHECK_MODULES([EET], [eet >= 1.0.1], [have_dep="yes" requirement="eet"], [have_dep="no"]) --evas_image_loader_[]$1[]_cflags="${EET_CFLAGS}" --evas_image_loader_[]$1[]_libs="${EET_LIBS}" -- --AC_SUBST([evas_image_loader_$1_cflags]) --AC_SUBST([evas_image_loader_$1_libs]) -- --if test "x$2" = "xstatic" ; then -- requirement_evas="${requirement} ${requirement_evas}" --fi -- --if test "x${have_dep}" = "xyes" ; then -- m4_default([$3], [:]) --else -- m4_default([$4], [:]) --fi -- --]) -- --dnl use: EVAS_CHECK_LOADER_DEP_GIF(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -- --AC_DEFUN([EVAS_CHECK_LOADER_DEP_GIF], --[ -- --have_dep="no" --evas_image_loader_[]$1[]_cflags="" --evas_image_loader_[]$1[]_libs="" -- --AC_CHECK_HEADER([gif_lib.h], [have_dep="yes"]) -- --if test "x${have_dep}" = "xyes" ; then -- AC_CHECK_LIB([gif], -- [DGifOpenFileName], -- [ -- evas_image_loader_[]$1[]_libs="-lgif" -- ], -- [have_dep="no"] -- ) -- -- if test "x${have_dep}" = "xno" ; then -- AC_CHECK_LIB([ungif], -- [DGifOpenFileName], -- [ -- have_dep="yes" -- evas_image_loader_[]$1[]_libs="-lungif" -- ] -- ) -- fi --fi -- --AC_SUBST([evas_image_loader_$1_cflags]) --AC_SUBST([evas_image_loader_$1_libs]) -- --if test "x${have_dep}" = "xyes" ; then -- m4_default([$3], [:]) --else -- m4_default([$4], [:]) --fi -- --]) -- --dnl use: EVAS_CHECK_LOADER_DEP_JPEG(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -- --AC_DEFUN([EVAS_CHECK_LOADER_DEP_JPEG], --[ -- --have_dep="no" --evas_image_loader_[]$1[]_cflags="" --evas_image_loader_[]$1[]_libs="" -- --AC_CHECK_HEADER([jpeglib.h], [have_dep="yes"]) -- --if test "x${have_dep}" = "xyes" ; then -- AC_CHECK_LIB([jpeg], -- [jpeg_CreateDecompress], -- [ -- evas_image_loader_[]$1[]_libs="-ljpeg" -- AC_COMPILE_IFELSE([[ -- #include -- #include -- #include -- int main(int argc, char **argv) { -- struct jpeg_decompress_struct decomp; -- decomp.region_x = 0; -- } -- ]], -- [have_jpeg_region="yes"], -- [have_jpeg_region="no"]) -- ], -- [have_dep="no"] -- ) -- if test "x${have_jpeg_region}" = "xyes" ; then -- AC_DEFINE(BUILD_LOADER_JPEG_REGION, [1], [JPEG Region Decode Support]) -- fi --fi -- --AC_SUBST([evas_image_loader_$1_cflags]) --AC_SUBST([evas_image_loader_$1_libs]) -- --if test "x${have_dep}" = "xyes" ; then -- m4_default([$3], [:]) --else -- m4_default([$4], [:]) --fi -- --]) -- --dnl use: EVAS_CHECK_LOADER_DEP_PMAPS(loader, want_static[[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -- --AC_DEFUN([EVAS_CHECK_LOADER_DEP_PMAPS], --[ -- --have_dep="yes" --evas_image_loader_[]$1[]_cflags="" --evas_image_loader_[]$1[]_libs="" -- --AC_SUBST([evas_image_loader_$1_cflags]) --AC_SUBST([evas_image_loader_$1_libs]) -- --if test "x${have_dep}" = "xyes" ; then -- m4_default([$3], [:]) --else -- m4_default([$4], [:]) --fi -- --]) -- --dnl use: EVAS_CHECK_LOADER_DEP_PNG(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -- --AC_DEFUN([EVAS_CHECK_LOADER_DEP_PNG], --[ -- --requirement="" --have_dep="no" --evas_image_loader_[]$1[]_cflags="" --evas_image_loader_[]$1[]_libs="" -- --PKG_CHECK_EXISTS([libpng14], [PKG_CHECK_MODULES([PNG], [libpng14], [have_dep="yes" requirement="libpng14"], [have_dep="no"])], -- [PKG_CHECK_EXISTS([libpng12], [PKG_CHECK_MODULES([PNG], [libpng12], [have_dep="yes" requirement="libpng12"], [have_dep="no"])], -- [PKG_CHECK_EXISTS([libpng10], [PKG_CHECK_MODULES([PNG], [libpng10], [have_dep="yes" requirement="libpng10"], [have_dep="no"])], -- [PKG_CHECK_MODULES([PNG], [libpng], [have_dep="yes" requirement="libpng"], [have_dep="no"]) -- ]) -- ]) --]) -- --evas_image_loader_[]$1[]_cflags="${PNG_CFLAGS}" --evas_image_loader_[]$1[]_libs="${PNG_LIBS}" -- --AC_SUBST([evas_image_loader_$1_cflags]) --AC_SUBST([evas_image_loader_$1_libs]) -- --if test "x$2" = "xstatic" ; then -- requirement_evas="${requirement} ${requirement_evas}" --fi -- --if test "x${have_dep}" = "xyes" ; then -- m4_default([$3], [:]) --else -- m4_default([$4], [:]) --fi -- --]) -- --dnl use: EVAS_CHECK_LOADER_DEP_SVG(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -- --AC_DEFUN([EVAS_CHECK_LOADER_DEP_SVG], --[ -- --requirement="" --have_dep="no" --evas_image_loader_[]$1[]_cflags="" --evas_image_loader_[]$1[]_libs="" -- --PKG_CHECK_MODULES([SVG], [librsvg-2.0 >= 2.14.0], -- [have_dep="yes" requirement="librsvg-2.0"], -- [have_svg="no"] --) -- --if test "x${have_dep}" = "xyes" ; then -- evas_image_loader_[]$1[]_cflags="${SVG_CFLAGS}" -- evas_image_loader_[]$1[]_libs="${SVG_LIBS}" --fi -- --AC_SUBST([evas_image_loader_$1_cflags]) --AC_SUBST([evas_image_loader_$1_libs]) -- --if test "x$2" = "xstatic" ; then -- requirement_evas="${requirement} ${requirement_evas}" --fi -- --if test "x${have_dep}" = "xyes" ; then -- m4_default([$3], [:]) --else -- m4_default([$4], [:]) --fi -- --]) -- --dnl use: EVAS_CHECK_LOADER_DEP_TIFF(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -- --AC_DEFUN([EVAS_CHECK_LOADER_DEP_TIFF], --[ -- --have_dep="no" --evas_image_loader_[]$1[]_cflags="" --evas_image_loader_[]$1[]_libs="" -- --AC_CHECK_HEADER([tiffio.h], [have_dep="yes"]) -- --if test "x${have_dep}" = "xyes" ; then -- AC_CHECK_LIB([tiff], -- [TIFFReadScanline], -- [ -- evas_image_loader_[]$1[]_libs="-ltiff" -- ], -- [have_dep="no"] -- ) -- -- if test "x${have_dep}" = "xno" ; then -- AC_CHECK_LIB([tiff], -- [TIFFReadScanline], -- [ -- have_dep="yes" -- evas_image_loader_[]$1[]_libs="-ltiff -ljpeg -lz -lm" -- ] -- ) -- fi -- -- if test "x${have_dep}" = "xno" ; then -- AC_CHECK_LIB([tiff34], -- [TIFFReadScanline], -- [ -- have_dep="yes" -- evas_image_loader_[]$1[]_libs="-ltiff34 -ljpeg -lz -lm" -- ] -- ) -- fi --fi -- --AC_SUBST([evas_image_loader_$1_cflags]) --AC_SUBST([evas_image_loader_$1_libs]) -- --if test "x${have_dep}" = "xyes" ; then -- m4_default([$3], [:]) --else -- m4_default([$4], [:]) --fi -- --]) -- --dnl use: EVAS_CHECK_LOADER_DEP_XPM(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -- --AC_DEFUN([EVAS_CHECK_LOADER_DEP_XPM], --[ -- --have_dep="yes" --evas_image_loader_[]$1[]_cflags="" --evas_image_loader_[]$1[]_libs="" -- --AC_SUBST([evas_image_loader_$1_cflags]) --AC_SUBST([evas_image_loader_$1_libs]) -- --if test "x${have_dep}" = "xyes" ; then -- m4_default([$3], [:]) --else -- m4_default([$4], [:]) --fi -- --]) - -- --dnl use: EVAS_CHECK_LOADER_DEP_BMP(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -- --AC_DEFUN([EVAS_CHECK_LOADER_DEP_BMP], --[ -- --have_dep="yes" --evas_image_loader_[]$1[]_cflags="" --evas_image_loader_[]$1[]_libs="" -- --AC_SUBST([evas_image_loader_$1_cflags]) --AC_SUBST([evas_image_loader_$1_libs]) -- --if test "x${have_dep}" = "xyes" ; then -- m4_default([$3], [:]) --else -- m4_default([$4], [:]) --fi -- --]) - -- - dnl use: EVAS_CHECK_LOADER_DEP_WBMP(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -dnl use: EVAS_CHECK_LOADER_DEP_TGA(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -- - AC_DEFUN([EVAS_CHECK_LOADER_DEP_WBMP], -AC_DEFUN([EVAS_CHECK_LOADER_DEP_TGA], --[ -- --have_dep="yes" --evas_image_loader_[]$1[]_cflags="" --evas_image_loader_[]$1[]_libs="" -- --AC_SUBST([evas_image_loader_$1_cflags]) --AC_SUBST([evas_image_loader_$1_libs]) -- --if test "x${have_dep}" = "xyes" ; then -- m4_default([$3], [:]) --else -- m4_default([$4], [:]) --fi -- --]) -- --dnl use: EVAS_CHECK_IMAGE_LOADER(loader, want_loader, macro) -- -- --AC_DEFUN([EVAS_CHECK_IMAGE_LOADER], --[ -- --m4_pushdef([UP], m4_toupper([$1])) --m4_pushdef([DOWN], m4_tolower([$1])) -- --want_loader="$2" --want_static_loader="no" --have_loader="no" --have_evas_image_loader_[]DOWN="no" -- --AC_ARG_ENABLE([image-loader-[]DOWN], -- [AC_HELP_STRING([--enable-image-loader-[]DOWN], [enable $1 image loader])], -- [ -- if test "x${enableval}" = "xyes" ; then -- want_loader="yes" -- else -- if test "x${enableval}" = "xstatic" ; then -- want_loader="static" -- else -- want_loader="no" -- fi -- fi -- ] --) -- --AC_MSG_CHECKING([whether to enable $1 image loader]) --AC_MSG_RESULT([${want_loader}]) -- --if test "x${want_loader}" = "xyes" -o "x${want_loader}" = "xstatic" -o "x${want_loader}" = "xauto"; then -- m4_default([EVAS_CHECK_LOADER_DEP_]m4_defn([UP]))(DOWN, ${want_loader}, [have_loader="yes"], [have_loader="no"]) --fi -- --if test "x${have_loader}" = "xno" -a "x${want_loader}" = "xyes" -a "x${use_strict}" = "xyes" ; then -- AC_MSG_ERROR([$1 dependencies not found (strict dependencies checking)]) --fi -- --AC_MSG_CHECKING([whether $1 image loader will be built]) --AC_MSG_RESULT([${have_loader}]) -- --if test "x${have_loader}" = "xyes" ; then -- if test "x${want_loader}" = "xstatic" ; then -- have_evas_image_loader_[]DOWN="static" -- want_static_loader="yes" -- else -- have_evas_image_loader_[]DOWN="yes" -- fi --fi -- --if test "x${have_loader}" = "xyes" ; then -- AC_DEFINE(BUILD_LOADER_[]UP, [1], [UP Image Loader Support]) --fi -- --AM_CONDITIONAL(BUILD_LOADER_[]UP, [test "x${have_loader}" = "xyes"]) -- --if test "x${want_static_loader}" = "xyes" ; then -- AC_DEFINE(EVAS_STATIC_BUILD_[]UP, [1], [Build $1 image loader inside libevas]) -- have_static_module="yes" --fi -- --AM_CONDITIONAL(EVAS_STATIC_BUILD_[]UP, [test "x${want_static_loader}" = "xyes"]) -- --m4_popdef([UP]) --m4_popdef([DOWN]) -- --]) -- --dnl use: EVAS_CHECK_FONT_LOADER(want) -- -- --AC_DEFUN([EVAS_CHECK_FONT_LOADER], --[ -- --pushdef([UP], translit([$1], [a-z], [A-Z]))dnl --pushdef([DOWN], translit([$1], [A-Z], [a-z]))dnl -- --want_loader="$1" --have_evas_font_loader_eet="no" -- --AC_ARG_ENABLE([font-loader-eet], -- [AC_HELP_STRING([--disable-font-loader-eet], -- [disable EET font loader. [[default=enabled]]])], -- [want_loader=${enableval}] --) -- --AC_MSG_CHECKING([whether to enable Eet font loader]) --AC_MSG_RESULT([${want_loader}]) -- --if test "x$want_loader" = "xyes" -o "x$want_loader" = "xauto"; then -- PKG_CHECK_MODULES([EET], [eet >= 1.0.1], [have_evas_font_loader_eet="yes"], [have_evas_font_loader_eet="no"]) --fi -- --if test "x${have_evas_font_loader_eet}" = "xno" -a "x$want_loader" = "xyes" -a "x$use_strict" = "xyes" ; then -- AC_MSG_ERROR([Eet dependencies not found (strict dependencies checking)]) --fi -- --if test "x$have_evas_font_loader_eet" = "xyes" ; then -- AC_DEFINE([BUILD_FONT_LOADER_EET], [1], [EET Font Loader Support]) -- requirement_evas="eet ${requirement_evas}" --fi -- --popdef([UP]) --popdef([DOWN]) -- --]) ++dnl use: EVAS_CHECK_LOADER_DEP_EDB(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) ++ ++AC_DEFUN([EVAS_CHECK_LOADER_DEP_EDB], ++[ ++ ++requirement="" ++have_dep="no" ++evas_image_loader_[]$1[]_cflags="" ++evas_image_loader_[]$1[]_libs="" ++ ++PKG_CHECK_MODULES([EDB], [edb], [have_dep="yes" requirement="edb"], [have_dep="no"]) ++evas_image_loader_[]$1[]_cflags="${EDB_CFLAGS}" ++evas_image_loader_[]$1[]_libs="${EDB_LIBS}" ++ ++AC_SUBST ([evas_image_loader_$1_cflags]) ++AC_SUBST([evas_image_loader_$1_libs]) ++ ++if test "x$2" = "xstatic" ; then ++ requirement_evas="${requirement} ${requirement_evas}" ++fi ++ ++if test "x${have_dep}" = "xyes" ; then ++ m4_default([$3], [:]) ++else ++ m4_default([$4], [:]) ++fi ++ ++]) ++ ++dnl use: EVAS_CHECK_LOADER_DEP_EET(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) ++ ++AC_DEFUN([EVAS_CHECK_LOADER_DEP_EET], ++[ ++ ++requirement="" ++have_dep="no" ++evas_image_loader_[]$1[]_cflags="" ++evas_image_loader_[]$1[]_libs="" ++ ++PKG_CHECK_MODULES([EET], [eet >= 1.0.1], [have_dep="yes" requirement="eet"], [have_dep="no"]) ++evas_image_loader_[]$1[]_cflags="${EET_CFLAGS}" ++evas_image_loader_[]$1[]_libs="${EET_LIBS}" ++ ++AC_SUBST ([evas_image_loader_$1_cflags]) ++AC_SUBST([evas_image_loader_$1_libs]) ++ ++if test "x$2" = "xstatic" ; then ++ requirement_evas="${requirement} ${requirement_evas}" ++fi ++ ++if test "x${have_dep}" = "xyes" ; then ++ m4_default([$3], [:]) ++else ++ m4_default([$4], [:]) ++fi ++ ++]) ++ ++dnl use: EVAS_CHECK_LOADER_DEP_GIF(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) ++ ++AC_DEFUN([EVAS_CHECK_LOADER_DEP_GIF], ++[ ++ ++have_dep="no" ++evas_image_loader_[]$1[]_cflags="" ++evas_image_loader_[]$1[]_libs="" ++ ++AC_CHECK_HEADER([gif_lib.h], [have_dep="yes"]) ++ ++if test "x${have_dep}" = "xyes" ; then ++ AC_CHECK_LIB([gif], ++ [DGifOpenFileName], ++ [ ++ evas_image_loader_[]$1[]_libs="-lgif" ++ ], ++ [have_dep="no"] ++ ) ++ ++ if test "x${have_dep}" = "xno" ; then ++ AC_CHECK_LIB([ungif], ++ [DGifOpenFileName], ++ [ ++ have_dep="yes" ++ evas_image_loader_[]$1[]_libs="-lungif" ++ ] ++ ) ++ fi ++fi ++ ++AC_SUBST([evas_image_loader_$1_cflags]) ++AC_SUBST([evas_image_loader_$1_libs]) ++ ++if test "x${have_dep}" = "xyes" ; then ++ m4_default([$3], [:]) ++else ++ m4_default([$4], [:]) ++fi ++ ++]) ++ ++dnl use: EVAS_CHECK_LOADER_DEP_JPEG(loader, want_static [, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) ++ ++AC_DEFUN([EVAS_CHECK_LOADER_DEP_JPEG], ++[ ++ ++have_dep="no" ++evas_image_loader_[]$1[]_cflags="" ++evas_image_loader_[]$1[]_libs="" ++ ++AC_CHECK_HEADER([jpeglib.h], [have_dep="yes"]) ++ ++if test "x${have_dep}" = "xyes" ; then ++ AC_CHECK_LIB([jpeg], ++ [jpeg_CreateDecompress], ++ [ ++ evas_image_loader_[]$1[]_libs="-ljpeg" ++ AC_COMPILE_IFELSE([[ ++ #include ++ #include ++ #include ++ int main(int argc, char **argv) { ++ struct jpeg_decompress_struct decomp; ++ decomp.region_x = 0; ++ } ++ ]], ++ [have_jpeg_region="yes"], ++ [have_jpeg_region="no"]) ++ ], ++ [have_dep="no"] ++ ) ++ if test "x${have_jpeg_region}" = "xyes" ; then ++ AC_DEFINE(BUILD_LOADER_JPEG_REGION, [1], [JPEG Region Decode Support]) ++ fi ++fi ++ ++AC_SUBST ([evas_image_loader_$1_cflags]) ++AC_SUBST([evas_image_loader_$1_libs]) ++ ++if test "x${have_dep}" = "xyes" ; then ++ m4_default([$3], [:]) ++else ++ m4_default ([$4], [:]) ++fi ++ ++]) ++ ++dnl use: EVAS_CHECK_LOADER_DEP_PMAPS(loader, want_static[[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) ++ ++AC_DEFUN ([EVAS_CHECK_LOADER_DEP_PMAPS], ++[ ++ ++have_dep="yes" ++evas_image_loader_[]$1[]_cflags="" ++evas_image_loader_[]$1[]_libs="" ++ ++AC_SUBST ([evas_image_loader_$1_cflags]) ++AC_SUBST([evas_image_loader_$1_libs]) ++ ++if test "x${have_dep}" = "xyes" ; then ++ m4_default([$3], [:]) ++else ++ m4_default ([$4], [:]) ++fi ++ ++]) ++ ++dnl use: EVAS_CHECK_LOADER_DEP_PNG(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) ++ ++AC_DEFUN ([EVAS_CHECK_LOADER_DEP_PNG], ++[ ++ ++requirement="" ++have_dep="no" ++evas_image_loader_[]$1[]_cflags="" ++evas_image_loader_[]$1[]_libs="" ++ ++PKG_CHECK_EXISTS ([libpng14], [PKG_CHECK_MODULES([PNG], [libpng14], [have_dep="yes" requirement="libpng14"], [have_dep="no"])], ++ [PKG_CHECK_EXISTS([libpng12], [PKG_CHECK_MODULES([PNG], [libpng12], [have_dep="yes" requirement="libpng12"], [have_dep="no"])], ++ [PKG_CHECK_EXISTS([libpng10], [PKG_CHECK_MODULES ([PNG], [libpng10], [have_dep="yes" requirement="libpng10"], [have_dep="no"])], ++ [PKG_CHECK_MODULES([PNG], [libpng], [have_dep="yes" requirement="libpng"], [have_dep="no"]) ++ ]) ++ ]) ++]) ++ ++evas_image_loader_[]$1[]_cflags="${PNG_CFLAGS}" ++evas_image_loader_[]$1[]_libs="${PNG_LIBS}" ++ ++AC_SUBST([evas_image_loader_$1_cflags]) ++AC_SUBST([evas_image_loader_$1_libs]) ++ ++if test "x$2" = "xstatic" ; then ++ requirement_evas="${requirement} ${requirement_evas}" ++fi ++ ++if test "x${have_dep}" = "xyes" ; then ++ m4_default([$3], [:]) ++else ++ m4_default([$4], [:]) ++fi ++ ++]) ++ ++dnl use: EVAS_CHECK_LOADER_DEP_SVG(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) ++ ++AC_DEFUN([EVAS_CHECK_LOADER_DEP_SVG], ++[ ++ ++requirement="" ++have_dep="no" ++evas_image_loader_[]$1[]_cflags="" ++evas_image_loader_[]$1[]_libs="" ++ ++PKG_CHECK_MODULES([SVG], [librsvg-2.0 >= 2.14.0], ++ [have_dep="yes" requirement="librsvg-2.0"], ++ [have_svg="no"] ++) ++ ++if test "x${have_dep}" = "xyes" ; then ++ evas_image_loader_[]$1[]_cflags="${SVG_CFLAGS}" ++ evas_image_loader_[]$1[]_libs="${SVG_LIBS}" ++fi ++ ++AC_SUBST([evas_image_loader_$1_cflags]) ++AC_SUBST([evas_image_loader_$1_libs]) ++ ++if test "x$2" = "xstatic" ; then ++ requirement_evas="${requirement} ${requirement_evas}" ++fi ++ ++if test "x${have_dep}" = "xyes" ; then ++ m4_default([$3], [:]) ++else ++ m4_default ([$4], [:]) ++fi ++ ++]) ++ ++dnl use: EVAS_CHECK_LOADER_DEP_TIFF(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) ++ ++AC_DEFUN ([EVAS_CHECK_LOADER_DEP_TIFF], ++[ ++ ++have_dep="no" ++evas_image_loader_[]$1[]_cflags="" ++evas_image_loader_[]$1[]_libs="" ++ ++AC_CHECK_HEADER([tiffio.h], [have_dep="yes"]) ++ ++if test "x${have_dep}" = "xyes" ; then ++ AC_CHECK_LIB([tiff], ++ [TIFFReadScanline], ++ [ ++ evas_image_loader_[]$1[] _libs="-ltiff" ++ ], ++ [have_dep="no"] ++ ) ++ ++ if test "x${have_dep}" = "xno" ; then ++ AC_CHECK_LIB([tiff], ++ [TIFFReadScanline], ++ [ ++ have_dep="yes" ++ evas_image_loader_[]$1[]_libs="-ltiff -ljpeg -lz -lm" ++ ] ++ ) ++ fi ++ ++ if test "x${have_dep}" = "xno" ; then ++ AC_CHECK_LIB([tiff34], ++ [TIFFReadScanline], ++ [ ++ have_dep="yes" ++ evas_image_loader_[]$1[]_libs="- ltiff34 -ljpeg -lz -lm" ++ ] ++ ) ++ fi ++fi ++ ++AC_SUBST([evas_image_loader_$1_cflags]) ++AC_SUBST([evas_image_loader_$1_libs]) ++ ++if test "x${have_dep}" = "xyes" ; then ++ m4_default([$3], [:]) ++else ++ m4_default([$4], [:]) ++fi ++ ++]) ++ ++dnl use: EVAS_CHECK_LOADER_DEP_XPM(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) ++ ++AC_DEFUN([EVAS_CHECK_LOADER_DEP_XPM], ++[ ++ ++have_dep="yes" ++evas_image_loader_[]$1[]_cflags="" ++evas_image_loader_ []$1[]_libs="" ++ ++AC_SUBST([evas_image_loader_$1_cflags]) ++AC_SUBST([evas_image_loader_$1_libs]) ++ ++if test "x${have_dep}" = "xyes" ; then ++ m4_default([$3], [:]) ++else ++ m4_default([$4], [:]) ++fi ++ ++]) ++ ++ ++dnl use: EVAS_CHECK_LOADER_DEP_BMP(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) ++ ++AC_DEFUN([EVAS_CHECK_LOADER_DEP_BMP], ++[ ++ ++have_dep="yes" ++evas_image_loader_[]$1[]_cflags="" ++evas_image_loader_[]$1[]_libs="" ++ ++AC_SUBST([evas_image_loader_$1_cflags]) ++AC_SUBST([evas_image_loader_$1_libs]) ++ ++if test "x${have_dep}" = "xyes" ; then ++ m4_default([$3], [:]) ++else ++ m4_default([$4], [:]) ++fi ++ ++]) ++ ++ ++dnl use: EVAS_CHECK_LOADER_DEP_WBMP(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) ++ ++AC_DEFUN([EVAS_CHECK_LOADER_DEP_WBMP], ++[ ++ ++have_dep="yes" ++evas_image_loader_[]$1[]_cflags="" ++evas_image_loader_[]$1[]_libs="" ++ ++AC_SUBST ([evas_image_loader_$1_cflags]) ++AC_SUBST([evas_image_loader_$1_libs]) ++ ++if test "x${have_dep}" = "xyes" ; then ++ m4_default([$3], [:]) ++else ++ m4_default ([$4], [:]) ++fi ++ ++]) ++ ++ ++dnl use: EVAS_CHECK_LOADER_DEP_TGA(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) ++ ++AC_DEFUN([EVAS_CHECK_LOADER_DEP_TGA], ++[ ++ ++have_dep="yes" ++evas_image_loader_[]$1[]_cflags="" ++evas_image_loader_[]$1[]_libs="" ++ ++AC_SUBST ([evas_image_loader_$1_cflags]) ++AC_SUBST([evas_image_loader_$1_libs]) ++ ++if test "x${have_dep}" = "xyes" ; then ++ m4_default([$3], [:]) ++else ++ m4_default ([$4], [:]) ++fi ++ ++]) ++ ++ ++dnl use: EVAS_CHECK_IMAGE_LOADER(loader, want_loader, macro) ++ ++ ++AC_DEFUN([EVAS_CHECK_IMAGE_LOADER], ++[ ++ ++m4_pushdef([UP], m4_toupper ([$1])) ++m4_pushdef([DOWN], m4_tolower([$1])) ++ ++want_loader="$2" ++want_static_loader="no" ++have_loader="no" ++have_evas_image_loader_[]DOWN="no" ++ ++AC_ARG_ENABLE([image-loader-[]DOWN], ++ [AC_HELP_STRING([--enable-image-loader-[]DOWN], [enable $1 image loader])], ++ [ ++ if test "x${enableval}" = "xyes" ; then ++ want_loader="yes" ++ else ++ if test "x${enableval}" = "xstatic" ; then ++ want_loader="static" ++ else ++ want_loader="no" ++ fi ++ fi ++ ] ++) ++ ++AC_MSG_CHECKING([whether to enable $1 image loader]) ++AC_MSG_RESULT([${want_loader}]) ++ ++if test "x${want_loader}" = "xyes" -o "x${want_loader}" = "xstatic" -o "x${want_loader}" = "xauto"; then ++ m4_default([EVAS_CHECK_LOADER_DEP_]m4_defn([UP]))(DOWN, ${want_loader}, [have_loader="yes"], [have_loader="no"]) ++fi ++ ++if test "x${have_loader}" = "xno" -a "x${want_loader}" = "xyes" -a "x${use_strict}" = "xyes" ; then ++ AC_MSG_ERROR([$1 dependencies not found (strict dependencies checking)]) ++fi ++ ++AC_MSG_CHECKING([whether $1 image loader will be built]) ++AC_MSG_RESULT ([${have_loader}]) ++ ++if test "x${have_loader}" = "xyes" ; then ++ if test "x${want_loader}" = "xstatic" ; then ++ have_evas_image_loader_[] DOWN="static" ++ want_static_loader="yes" ++ else ++ have_evas_image_loader_[]DOWN="yes" ++ fi ++fi ++ ++if test "x${have_loader}" = "xyes" ; then ++ AC_DEFINE(BUILD_LOADER_[]UP, [1], [UP Image Loader Support]) ++fi ++ ++AM_CONDITIONAL(BUILD_LOADER_[]UP, [test "x${have_loader}" = "xyes"]) ++ ++if test "x${want_static_loader}" = "xyes" ; then ++ AC_DEFINE(EVAS_STATIC_BUILD_[]UP, [1], [Build $1 image loader inside libevas]) ++ have_static_module="yes" ++fi ++ ++AM_CONDITIONAL(EVAS_STATIC_BUILD_[]UP, [test "x${want_static_loader}" = "xyes"]) ++ ++m4_popdef([UP]) ++m4_popdef([DOWN]) ++ ++]) ++ ++dnl use: EVAS_CHECK_FONT_LOADER(want) ++ ++ ++AC_DEFUN([EVAS_CHECK_FONT_LOADER], ++[ ++ ++pushdef([UP], translit([$1], [a-z], [A-Z]))dnl ++pushdef([DOWN], translit([$1], [A-Z], [a-z]))dnl ++ ++want_loader="$1" ++have_evas_font_loader_eet="no" ++ ++AC_ARG_ENABLE([font-loader-eet], ++ [AC_HELP_STRING([--disable-font-loader-eet], ++ [disable EET font loader. [[default=enabled]]])], ++ [want_loader=${enableval}] ++) ++ ++AC_MSG_CHECKING([whether to enable Eet font loader]) ++AC_MSG_RESULT ([${want_loader}]) ++ ++if test "x$want_loader" = "xyes" -o "x$want_loader" = "xauto"; then ++ PKG_CHECK_MODULES([EET], [eet >= 1.0.1], [have_evas_font_loader_eet="yes"], [have_evas_font_loader_eet="no"]) ++fi ++ ++if test "x${have_evas_font_loader_eet}" = "xno" -a "x$want_loader" = "xyes" -a "x$use_strict" = "xyes" ; then ++ AC_MSG_ERROR([Eet dependencies not found (strict dependencies checking)]) ++fi ++ ++if test "x$have_evas_font_loader_eet" = "xyes" ; then ++ AC_DEFINE([BUILD_FONT_LOADER_EET], [1], [EET Font Loader Support]) ++ requirement_evas="eet ${requirement_evas}" ++fi ++ ++popdef([UP]) ++popdef([DOWN]) ++ ++]) diff --cc src/lib/canvas/evas_object_textblock.c index 8c6232e,4082bb6..2a0cb14 mode 100755,100644..100755 --- a/src/lib/canvas/evas_object_textblock.c +++ b/src/lib/canvas/evas_object_textblock.c diff --cc src/lib/engines/common/evas_image_load.c index cecaacc,e776fcf..590e706 mode 100755,100644..100755 --- a/src/lib/engines/common/evas_image_load.c +++ b/src/lib/engines/common/evas_image_load.c @@@ -1,256 -1,259 +1,260 @@@ --/* -- * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 -- */ -- --#include "evas_common.h" --#include "evas_private.h" --#include "evas_cs.h" -- - struct ext_loader_s { - const char* extention; - const char* loader; -struct ext_loader_s -{ - const char *extention; - const char *loader; --}; -- - static struct ext_loader_s const loaders[] = { -static const struct ext_loader_s loaders[] = -{ -- { "png", "png" }, -- { "jpg", "jpeg" }, -- { "jpeg", "jpeg" }, -- { "jfif", "jpeg" }, -- { "eet", "eet" }, -- { "edj", "eet" }, -- { "eap", "eet" }, -- { "edb", "edb" }, -- { "xpm", "xpm" }, - { "bmp", "bmp" }, - { "wbmp", "wbmp" }, -- { "tiff", "tiff" }, -- { "tif", "tiff" }, -- { "svg", "svg" }, -- { "svgz", "svg" }, -- { "gif", "gif" }, -- { "pbm", "pmaps" }, -- { "pgm", "pmaps" }, -- { "ppm", "pmaps" }, - { "pnm", "pmaps" } - { "pnm", "pmaps" }, - { "bmp", "bmp" }, - { "tga", "tga" } --}; -- - static const char *loaders_name[] = { - "png", "jpeg", "eet", "xpm", "bmp", "wbmp", "tiff", "gif", "svg", "pmaps", "edb" -static const char *loaders_name[] = -{ - "png", "jpeg", "eet", "xpm", "tiff", "gif", "svg", "pmaps", "edb", "bmp", "tga" --}; -- --struct evas_image_foreach_loader_data --{ -- Image_Entry *ie; -- int *error; -- Evas_Module *em; --}; -- -- --static Eina_Bool --_evas_image_foreach_loader(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *data, void *fdata) --{ -- Evas_Image_Load_Func *evas_image_load_func = NULL; -- Evas_Module *em = data; -- struct evas_image_foreach_loader_data *d = fdata; -- Image_Entry *ie = d->ie; -- -- if (!evas_module_load(em)) return EINA_TRUE; -- evas_image_load_func = em->functions; -- evas_module_use(em); -- *(d->error) = EVAS_LOAD_ERROR_NONE; -- if (evas_image_load_func && -- evas_image_load_func->file_head(ie, ie->file, ie->key, d->error) && -- (*(d->error) == EVAS_LOAD_ERROR_NONE)) -- { -- d->em = em; -- return EINA_FALSE; -- } -- -- return EINA_TRUE; --} -- --EAPI int --evas_common_load_rgba_image_module_from_file(Image_Entry *ie) --{ -- Evas_Image_Load_Func *evas_image_load_func = NULL; -- const char *loader = NULL; -- Evas_Module *em; -- char *dot; -- int i; -- int ret = EVAS_LOAD_ERROR_NONE; -- struct evas_image_foreach_loader_data fdata; -- -- --#ifdef EVAS_CSERVE -- if (evas_cserve_use_get()) -- { -- // TODO: handle errors from server and return them? -- DBG("try cserve '%s' '%s'", ie->file, ie->key ? ie->key : ""); -- if (evas_cserve_image_load(ie, ie->file, ie->key, &(ie->load_opts))) -- { -- DBG("try cserve '%s' '%s' loaded!", -- ie->file, ie->key ? ie->key : ""); -- return EVAS_LOAD_ERROR_NONE; -- } -- } --#endif -- dot = strrchr (ie->file, '.'); -- if (dot) -- { -- for (i = 0, ++dot; i < (sizeof (loaders) / sizeof (struct ext_loader_s)); ++i) -- { -- if (!strcasecmp(dot, loaders[i].extention)) -- { -- loader = loaders[i].loader; -- DBG("known loader '%s' handles extension '%s' of file '%s'", -- loader, dot, ie->file); -- break; -- } -- } -- } -- -- if (loader) -- { -- em = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, loader); -- if (em) -- { -- DBG("found image loader '%s' (%p)", loader, em); -- if (evas_module_load(em)) -- { -- evas_module_use(em); -- evas_image_load_func = em->functions; -- ret = EVAS_LOAD_ERROR_NONE; -- if (evas_image_load_func->file_head(ie, ie->file, ie->key, &ret)) -- { -- DBG("loaded file head using module '%s' (%p): %s", -- loader, em, ie->file); -- goto end; -- } -- evas_module_unload(em); -- DBG("failed to load file head using module '%s' (%p): " -- "%s (%s)", -- loader, em, ie->file, evas_load_error_str(ret)); -- } -- else -- WRN("failed to load module '%s' (%p)", loader, em); -- } -- else -- DBG("image loader '%s' is not enabled or missing!", loader); -- } -- -- fdata.ie = ie; -- fdata.error = &ret; -- fdata.em = NULL; -- ret = EVAS_LOAD_ERROR_NONE; -- evas_module_foreach_image_loader(_evas_image_foreach_loader, &fdata); -- em = fdata.em; -- evas_image_load_func = em ? em->functions : NULL; -- if (em) goto end; -- -- /* This is our last chance, try all known image loader. */ -- /* FIXME: We could use eina recursive module search ability. */ -- for (i = 0; i < sizeof (loaders_name) / sizeof (char *); i++) -- { -- em = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, loaders_name[i]); -- if (em) -- { -- if (evas_module_load(em)) -- { -- evas_module_use(em); -- evas_image_load_func = em->functions; -- ret = EVAS_LOAD_ERROR_NONE; -- if (evas_image_load_func->file_head(ie, ie->file, ie->key, &ret)) -- { -- DBG("brute force loader '%s' (%p) worked on %s", -- loaders_name[i], em, ie->file); -- goto end; -- } -- else -- DBG("brute force loader '%s' (%p) failed on %s (%s)", -- loaders_name[i], em, ie->file, -- evas_load_error_str(ret)); -- -- evas_module_unload(em); -- } -- else -- WRN("failed to load module '%s' (%p)", loaders_name[i], em); -- } -- else -- DBG("could not find module '%s'", loaders_name[i]); -- } -- -- DBG("exhausted all means to load image '%s'", ie->file); -- return EVAS_LOAD_ERROR_UNKNOWN_FORMAT; -- -- end: -- -- if (ret != EVAS_LOAD_ERROR_NONE) -- { -- const char *modname = NULL; -- int modversion = -1; -- if (em && em->definition) -- { -- modname = em->definition->name; -- modversion = em->definition->version; -- } -- WRN("loader '%s' (version %d) " -- "handled file '%s', key '%s' with errors: %s", -- modname ? modname : "", modversion, -- ie->file, ie->key ? ie->key : "", -- evas_load_error_str(ret)); -- goto end; -- } -- -- DBG("loader '%s' used for file %s", -- (em && em->definition && em->definition->name) ? -- em->definition->name : "", -- ie->file); -- -- ie->info.module = (void*) em; -- ie->info.loader = (void*) evas_image_load_func; -- evas_module_ref((Evas_Module*) ie->info.module); -- return ret; --} -- --EAPI int --evas_common_load_rgba_image_data_from_file(Image_Entry *ie) --{ -- Evas_Image_Load_Func *evas_image_load_func = NULL; -- int ret = EVAS_LOAD_ERROR_NONE; -- -- if (ie->flags.loaded) return EVAS_LOAD_ERROR_GENERIC; -- --#ifdef EVAS_CSERVE -- if (ie->data1) -- { -- if (evas_cserve_image_data_load(ie)) -- { -- RGBA_Image *im = (RGBA_Image *)ie; -- Mem *mem = ie->data2; -- if (mem) -- { -- im->image.data = (void*) (mem->data + mem->offset); -- im->image.no_free = 1; -- return EVAS_LOAD_ERROR_NONE; -- } -- } -- return EVAS_LOAD_ERROR_GENERIC; -- } --#endif -- -- if (!ie->info.module) return EVAS_LOAD_ERROR_GENERIC; -- --// printf("load data [%p] %s %s\n", ie, ie->file, ie->key); -- -- evas_image_load_func = ie->info.loader; -- evas_module_use((Evas_Module*) ie->info.module); -- if (!evas_image_load_func->file_data(ie, ie->file, ie->key, &ret)) -- { -- return ret; -- } -- --// evas_module_unref((Evas_Module*) ie->info.module); --// ie->info.module = NULL; -- -- return EVAS_LOAD_ERROR_NONE; --} ++/* ++ * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 ++ */ ++ ++#include "evas_common.h" ++#include "evas_private.h" ++#include "evas_cs.h" ++ ++struct ext_loader_s ++{ ++ const char *extention; ++ const char *loader; ++}; ++ ++static const struct ext_loader_s loaders[] = ++{ ++ { "png", "png" }, ++ { "jpg", "jpeg" }, ++ { "jpeg", "jpeg" }, ++ { "jfif", "jpeg" }, ++ { "eet", "eet" }, ++ { "edj", "eet" }, ++ { "eap", "eet" }, ++ { "edb", "edb" }, ++ { "xpm", "xpm" }, ++ { "tiff", "tiff" }, ++ { "tif", "tiff" }, ++ { "svg", "svg" }, ++ { "svgz", "svg" }, ++ { "gif", "gif" }, ++ { "pbm", "pmaps" }, ++ { "pgm", "pmaps" }, ++ { "ppm", "pmaps" }, ++ { "pnm", "pmaps" }, ++ { "bmp", "bmp" }, ++ { "wbmp", "wbmp" }, ++ { "tga", "tga" } ++}; ++ ++static const char *loaders_name[] = ++{ ++ "png", "jpeg", "eet", "xpm", "tiff", "gif", "svg", "pmaps", "edb", "bmp", "wbmp", "tga" ++}; ++ ++struct evas_image_foreach_loader_data ++{ ++ Image_Entry *ie; ++ int *error; ++ Evas_Module *em; ++}; ++ ++ ++static Eina_Bool ++_evas_image_foreach_loader(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *data, void *fdata) ++{ ++ Evas_Image_Load_Func *evas_image_load_func = NULL; ++ Evas_Module *em = data; ++ struct evas_image_foreach_loader_data *d = fdata; ++ Image_Entry *ie = d->ie; ++ ++ if (!evas_module_load(em)) return EINA_TRUE; ++ evas_image_load_func = em->functions; ++ evas_module_use(em); ++ *(d->error) = EVAS_LOAD_ERROR_NONE; ++ if (evas_image_load_func && ++ evas_image_load_func->file_head(ie, ie->file, ie->key, d->error) && ++ (*(d->error) == EVAS_LOAD_ERROR_NONE)) ++ { ++ d->em = em; ++ return EINA_FALSE; ++ } ++ ++ return EINA_TRUE; ++} ++ ++EAPI int ++evas_common_load_rgba_image_module_from_file(Image_Entry *ie) ++{ ++ Evas_Image_Load_Func *evas_image_load_func = NULL; ++ const char *loader = NULL; ++ Evas_Module *em; ++ char *dot; ++ int i; ++ int ret = EVAS_LOAD_ERROR_NONE; ++ struct evas_image_foreach_loader_data fdata; ++ ++ ++#ifdef EVAS_CSERVE ++ if (evas_cserve_use_get()) ++ { ++ // TODO: handle errors from server and return them? ++ DBG("try cserve '%s' '%s'", ie->file, ie->key ? ie->key : ""); ++ if (evas_cserve_image_load(ie, ie->file, ie->key, &(ie->load_opts))) ++ { ++ DBG("try cserve '%s' '%s' loaded!", ++ ie->file, ie->key ? ie->key : ""); ++ return EVAS_LOAD_ERROR_NONE; ++ } ++ } ++#endif ++ dot = strrchr (ie->file, '.'); ++ if (dot) ++ { ++ for (i = 0, ++dot; i < (sizeof (loaders) / sizeof (struct ext_loader_s)); ++i) ++ { ++ if (!strcasecmp(dot, loaders[i].extention)) ++ { ++ loader = loaders[i].loader; ++ DBG("known loader '%s' handles extension '%s' of file '%s'", ++ loader, dot, ie->file); ++ break; ++ } ++ } ++ } ++ ++ if (loader) ++ { ++ em = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, loader); ++ if (em) ++ { ++ DBG("found image loader '%s' (%p)", loader, em); ++ if (evas_module_load(em)) ++ { ++ evas_module_use(em); ++ evas_image_load_func = em->functions; ++ ret = EVAS_LOAD_ERROR_NONE; ++ if (evas_image_load_func->file_head(ie, ie->file, ie->key, &ret)) ++ { ++ DBG("loaded file head using module '%s' (%p): %s", ++ loader, em, ie->file); ++ goto end; ++ } ++ evas_module_unload(em); ++ DBG("failed to load file head using module '%s' (%p): " ++ "%s (%s)", ++ loader, em, ie->file, evas_load_error_str(ret)); ++ } ++ else ++ WRN("failed to load module '%s' (%p)", loader, em); ++ } ++ else ++ DBG("image loader '%s' is not enabled or missing!", loader); ++ } ++ ++ fdata.ie = ie; ++ fdata.error = &ret; ++ fdata.em = NULL; ++ ret = EVAS_LOAD_ERROR_NONE; ++ evas_module_foreach_image_loader(_evas_image_foreach_loader, &fdata); ++ em = fdata.em; ++ evas_image_load_func = em ? em->functions : NULL; ++ if (em) goto end; ++ ++ /* This is our last chance, try all known image loader. */ ++ /* FIXME: We could use eina recursive module search ability. */ ++ for (i = 0; i < sizeof (loaders_name) / sizeof (char *); i++) ++ { ++ em = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, loaders_name[i]); ++ if (em) ++ { ++ if (evas_module_load(em)) ++ { ++ evas_module_use(em); ++ evas_image_load_func = em->functions; ++ ret = EVAS_LOAD_ERROR_NONE; ++ if (evas_image_load_func->file_head(ie, ie->file, ie->key, &ret)) ++ { ++ DBG("brute force loader '%s' (%p) worked on %s", ++ loaders_name[i], em, ie->file); ++ goto end; ++ } ++ else ++ DBG("brute force loader '%s' (%p) failed on %s (%s)", ++ loaders_name[i], em, ie->file, ++ evas_load_error_str(ret)); ++ ++ evas_module_unload(em); ++ } ++ else ++ WRN("failed to load module '%s' (%p)", loaders_name[i], em); ++ } ++ else ++ DBG("could not find module '%s'", loaders_name[i]); ++ } ++ ++ DBG("exhausted all means to load image '%s'", ie->file); ++ return EVAS_LOAD_ERROR_UNKNOWN_FORMAT; ++ ++ end: ++ ++ if (ret != EVAS_LOAD_ERROR_NONE) ++ { ++ const char *modname = NULL; ++ int modversion = -1; ++ if (em && em->definition) ++ { ++ modname = em->definition->name; ++ modversion = em->definition->version; ++ } ++ WRN("loader '%s' (version %d) " ++ "handled file '%s', key '%s' with errors: %s", ++ modname ? modname : "", modversion, ++ ie->file, ie->key ? ie->key : "", ++ evas_load_error_str(ret)); ++ goto end; ++ } ++ ++ DBG("loader '%s' used for file %s", ++ (em && em->definition && em->definition->name) ? ++ em->definition->name : "", ++ ie->file); ++ ++ ie->info.module = (void*) em; ++ ie->info.loader = (void*) evas_image_load_func; ++ evas_module_ref((Evas_Module*) ie->info.module); ++ return ret; ++} ++ ++EAPI int ++evas_common_load_rgba_image_data_from_file(Image_Entry *ie) ++{ ++ Evas_Image_Load_Func *evas_image_load_func = NULL; ++ int ret = EVAS_LOAD_ERROR_NONE; ++ ++ if (ie->flags.loaded) return EVAS_LOAD_ERROR_GENERIC; ++ ++#ifdef EVAS_CSERVE ++ if (ie->data1) ++ { ++ if (evas_cserve_image_data_load(ie)) ++ { ++ RGBA_Image *im = (RGBA_Image *)ie; ++ Mem *mem = ie->data2; ++ if (mem) ++ { ++ im->image.data = (void*) (mem->data + mem->offset); ++ im->image.no_free = 1; ++ return EVAS_LOAD_ERROR_NONE; ++ } ++ } ++ return EVAS_LOAD_ERROR_GENERIC; ++ } ++#endif ++ ++ if (!ie->info.module) return EVAS_LOAD_ERROR_GENERIC; ++ ++// printf("load data [%p] %s %s\n", ie, ie->file, ie->key); ++ ++ evas_image_load_func = ie->info.loader; ++ evas_module_use((Evas_Module*) ie->info.module); ++ if (!evas_image_load_func->file_data(ie, ie->file, ie->key, &ret)) ++ { ++ return ret; ++ } ++ ++// evas_module_unref((Evas_Module*) ie->info.module); ++// ie->info.module = NULL; ++ ++ return EVAS_LOAD_ERROR_NONE; ++} diff --cc src/lib/file/evas_module.c index 2176fdc,9d8cfbc..9a0130a mode 100755,100644..100755 --- a/src/lib/file/evas_module.c +++ b/src/lib/file/evas_module.c diff --cc src/modules/loaders/Makefile.am index 67bd86f,7aa6cff..845a8a7 mode 100755,100644..100755 --- a/src/modules/loaders/Makefile.am +++ b/src/modules/loaders/Makefile.am @@@ -62,9 -62,9 +62,13 @@@ SUBDIRS += bm endif endif +if BUILD_LOADER_WBMP +if !EVAS_STATIC_BUILD_WBMP +SUBDIRS += wbmp ++ + if BUILD_LOADER_TGA + if !EVAS_STATIC_BUILD_TGA + SUBDIRS += tga endif endif diff --cc src/modules/loaders/bmp/Makefile.am index fa36193,430156a..5e0d199 mode 100755,100644..100755 --- a/src/modules/loaders/bmp/Makefile.am +++ b/src/modules/loaders/bmp/Makefile.am @@@ -1,34 -1,32 +1,32 @@@ -- --MAINTAINERCLEANFILES = Makefile.in -- --AM_CPPFLAGS = \ ---I. \ ---I$(top_srcdir)/src/lib \ ---I$(top_srcdir)/src/lib/include \ --@FREETYPE_CFLAGS@ \ - @evas_image_loader_bmp_cflags@ \ - @EINA_CFLAGS@ - - AM_CFLAGS = @WIN32_CFLAGS@ -@EINA_CFLAGS@ \ -@EVIL_CFLAGS@ \ -@WIN32_CPPFLAGS@ -- --if BUILD_LOADER_BMP --if !EVAS_STATIC_BUILD_BMP -- --pkgdir = $(libdir)/evas/modules/loaders/bmp/$(MODULE_ARCH) --pkg_LTLIBRARIES = module.la -- --module_la_SOURCES = evas_image_load_bmp.c -- - module_la_LIBADD = @EINA_LIBS@ @evas_image_loader_bmp_libs@ $(top_builddir)/src/lib/libevas.la -module_la_LIBADD = @EINA_LIBS@ @EVIL_LIBS@ $(top_builddir)/src/lib/libevas.la --module_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -module -avoid-version --module_la_LIBTOOLFLAGS = --tag=disable-static -- --else -- --noinst_LTLIBRARIES = libevas_loader_bmp.la - --libevas_loader_bmp_la_SOURCES = evas_image_load_bmp.c - libevas_loader_bmp_la_LIBADD = @evas_image_loader_bmp_libs@ -libevas_loader_bmp_la_LIBADD = -- --endif --endif ++ ++MAINTAINERCLEANFILES = Makefile.in ++ ++AM_CPPFLAGS = \ ++-I. \ ++-I$(top_srcdir)/src/lib \ ++-I$(top_srcdir)/src/lib/include \ ++@FREETYPE_CFLAGS@ \ ++@EINA_CFLAGS@ \ ++@EVIL_CFLAGS@ \ ++@WIN32_CPPFLAGS@ ++ ++if BUILD_LOADER_BMP ++if !EVAS_STATIC_BUILD_BMP ++ ++pkgdir = $(libdir)/evas/modules/loaders/bmp/$(MODULE_ARCH) ++pkg_LTLIBRARIES = module.la ++ ++module_la_SOURCES = evas_image_load_bmp.c ++ ++module_la_LIBADD = @EINA_LIBS@ @EVIL_LIBS@ $(top_builddir)/src/lib/libevas.la ++module_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -module -avoid-version ++module_la_LIBTOOLFLAGS = --tag=disable-static ++ ++else ++ ++noinst_LTLIBRARIES = libevas_loader_bmp.la ++libevas_loader_bmp_la_SOURCES = evas_image_load_bmp.c ++libevas_loader_bmp_la_LIBADD = ++ ++endif ++endif diff --cc src/modules/loaders/bmp/evas_image_load_bmp.c index b30e98e,8b0d6f0..b4b72e5 mode 100755,100644..100755 --- a/src/modules/loaders/bmp/evas_image_load_bmp.c +++ b/src/modules/loaders/bmp/evas_image_load_bmp.c @@@ -1,711 -1,1111 +1,1123 @@@ - --#ifdef HAVE_CONFIG_H --# include --#endif -- - #ifdef HAVE_EVIL - # include -#ifndef _GNU_SOURCE -#define _GNU_SOURCE --#endif -- --#include - #include - -#ifdef HAVE_EVIL -# include -#endif -- --#include "evas_common.h" --#include "evas_private.h" - - #define EVAS_WINK_MODULE_NAME bmp - #include "evas_wink.h" -- --static Eina_Bool evas_image_load_file_head_bmp(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4); --static Eina_Bool evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4); -- --static Evas_Image_Load_Func evas_image_load_bmp_func = --{ -- EINA_TRUE, -- evas_image_load_file_head_bmp, -- evas_image_load_file_data_bmp - }; - - - typedef struct tagRGBQUAD { - unsigned char rgbBlue; - unsigned char rgbGreen; - unsigned char rgbRed; - unsigned char rgbReserved; - } RGBQUAD; - - #define BI_RGB 0 - #define BI_RLE8 1 - #define BI_RLE4 2 - #define BI_BITFIELDS 3 - - /* 21.3.3006 - Use enumeration for RLE encoding. This makes it more readable */ - enum { - RLE_NEXT = 0, /* Next line */ - RLE_END = 1, /* End of RLE encoding */ - RLE_MOVE = 2 /* Move by X and Y (Offset is stored in two next bytes) */ --}; - - # define IMAGE_DIMENSIONS_OK(w, h) \ - ( ((w) > 0) && ((h) > 0) && \ - ((unsigned long long)(w) * (unsigned long long)(w) <= (1ULL << 29) - 1) ) -- --static int - ReadleShort(FILE * file, unsigned short *ret) -read_short(FILE *file, short *ret) --{ - unsigned char b[2]; - - if (fread(b, sizeof(unsigned char), 2, file) != 2) - return 0; - - *ret = (b[1] << 8) | b[0]; - return 1; - unsigned char b[2]; - if (fread(b, sizeof(unsigned char), 2, file) != 2) return 0; - *ret = (b[1] << 8) | b[0]; - return 1; --} - - --static int - ReadleLong(FILE * file, unsigned long *ret) -read_int(FILE *file, int *ret) --{ - unsigned char b[4]; - - if (fread(b, sizeof(unsigned char), 4, file) != 4) - return 0; - - *ret = (b[3] << 24) | (b[2] << 16) | (b[1] << 8) | b[0]; - return 1; - unsigned char b[4]; - if (fread(b, sizeof(unsigned char), 4, file) != 4) return 0; - *ret = (b[3] << 24) | (b[2] << 16) | (b[1] << 8) | b[0]; - return 1; --} -- --static Eina_Bool --evas_image_load_file_head_bmp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error) --{ - #ifdef USE_WINK_CODEC - return evas_image_load_file_head_bmp_wink(ie, file, key, error); - #endif - FILE *f; - unsigned char buf[4096]; - char hasa = 0; - int w = 0, h = 0, planes = 0, bit_count = 0, - image_size = 0, comp = 0, hdpi = 0, vdpi = 0, - palette_size = -1, important_colors = 0, rowlen = 0; - unsigned int offset, head_size, rmask = 0, gmask = 0, bmask = 0, amask = 0; - unsigned int *pal = NULL, pal_num = 0; - int right_way_up = 0; - int fsize = 0; - unsigned int bmpsize; - unsigned short res1, res2; -- - FILE *f; - char type[2]; - unsigned long size, offset, headSize; - unsigned short tmpShort; - unsigned long w, h; - -- f = fopen(file, "rb"); -- if (!f) -- { - *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; - return EINA_FALSE; - *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; - return EINA_FALSE; -- } - - /* header */ - { - struct stat statbuf; - - if (stat(file, &statbuf) == -1) - { - *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; - fclose(f); - return EINA_FALSE; - } - size = statbuf.st_size; -- - if (fread(type, 1, 2, f) != 2) - { - *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; - fclose(f); - return EINA_FALSE; - } - if (strncmp(type, "BM", 2)) - { - *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; - fclose(f); - return EINA_FALSE; - } - *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; - fseek(f, 0, SEEK_END); - fsize = ftell(f); - fseek(f, 0, SEEK_SET); - if (fsize < 2) goto close_file; - - if (fread(buf, 2, 1, f) != 1) goto close_file; - if (strncmp(buf, "BM", 2)) goto close_file; // magic number - *error = EVAS_LOAD_ERROR_CORRUPT_FILE; - if (!read_int(f, &bmpsize)) goto close_file; - if (!read_short(f, &res1)) goto close_file; - if (!read_short(f, &res2)) goto close_file; - if (!read_int(f, &offset)) goto close_file; - if (!read_int(f, &head_size)) goto close_file; - if (head_size == 12) // OS/2 V1 + Windows 3.0 - { - short tmp; - - if (!read_short(f, &tmp)) goto close_file; - w = tmp; // width - if (!read_short(f, &tmp)) goto close_file; - h = tmp; // height - if (!read_short(f, &tmp)) goto close_file; - planes = tmp; // must be 1 - if (!read_short(f, &tmp)) goto close_file; - bit_count = tmp; // bits per pixel: 1, 4, 8 & 24 - } - else if (head_size == 64) // OS/2 V2 - { - short tmp; - int tmp2; - - if (!read_int(f, &tmp2)) goto close_file; - w = tmp2; // width - if (!read_int(f, &tmp2)) goto close_file; - h = tmp2; // height - if (!read_short(f, &tmp)) goto close_file; - planes = tmp; // must be 1 - if (!read_short(f, &tmp)) goto close_file; - bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 - if (!read_int(f, &tmp2)) goto close_file; - comp = tmp2; // compression method - if (!read_int(f, &tmp2)) goto close_file; - image_size = tmp2; // bitmap data size - if (!read_int(f, &tmp2)) goto close_file; - hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter - if (!read_int(f, &tmp2)) goto close_file; - vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter - if (!read_int(f, &tmp2)) goto close_file; - palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) - if (!read_int(f, &tmp2)) goto close_file; - important_colors = tmp2; // number of important colors - 0 if all - if (fread(buf, 24, 1, f) != 1) goto close_file; // skip unused header - if (image_size == 0) image_size = fsize - offset; - } - else if (head_size == 40) // Windows 3.0 + (v3) - { - short tmp; - int tmp2; - - if (!read_int(f, &tmp2)) goto close_file; - w = tmp2; // width - if (!read_int(f, &tmp2)) goto close_file; - h = tmp2; // height - if (!read_short(f, &tmp)) goto close_file; - planes = tmp; // must be 1 - if (!read_short(f, &tmp)) goto close_file; - bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 - if (!read_int(f, &tmp2)) goto close_file; - comp = tmp2; // compression method - if (!read_int(f, &tmp2)) goto close_file; - image_size = tmp2; // bitmap data size - if (!read_int(f, &tmp2)) goto close_file; - hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter - if (!read_int(f, &tmp2)) goto close_file; - vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter - if (!read_int(f, &tmp2)) goto close_file; - palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) - if (!read_int(f, &tmp2)) goto close_file; - important_colors = tmp2; // number of important colors - 0 if all - if (image_size == 0) image_size = fsize - offset; - } - else if (head_size == 108) // Windows 95/NT4 + (v4) - { - short tmp; - int tmp2; - - if (!read_int(f, &tmp2)) goto close_file; - w = tmp2; // width - if (!read_int(f, &tmp2)) goto close_file; - h = tmp2; // height - if (!read_short(f, &tmp)) goto close_file; - planes = tmp; // must be 1 - if (!read_short(f, &tmp)) goto close_file; - bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 - if (!read_int(f, &tmp2)) goto close_file; - comp = tmp2; // compression method - if (!read_int(f, &tmp2)) goto close_file; - image_size = tmp2; // bitmap data size - if (!read_int(f, &tmp2)) goto close_file; - hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter - if (!read_int(f, &tmp2)) goto close_file; - vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter - if (!read_int(f, &tmp2)) goto close_file; - palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) - if (!read_int(f, &tmp2)) goto close_file; - important_colors = tmp2; // number of important colors - 0 if all - if (!read_int(f, &tmp2)) goto close_file; - rmask = tmp2; // red mask - if (!read_int(f, &tmp2)) goto close_file; - gmask = tmp2; // green mask - if (!read_int(f, &tmp2)) goto close_file; - bmask = tmp2; // blue mask - if (!read_int(f, &tmp2)) goto close_file; - amask = tmp2; // alpha mask - if (fread(buf, 36, 1, f) != 1) goto close_file; // skip unused cie - if (fread(buf, 12, 1, f) != 1) goto close_file; // skip unused gamma - if (image_size == 0) image_size = fsize - offset; - if ((amask) && (bit_count == 32)) hasa = 1; - } - else if (head_size == 124) // Windows 98/2000 + (v5) - { - short tmp; - int tmp2; - - if (!read_int(f, &tmp2)) goto close_file; - w = tmp2; // width - if (!read_int(f, &tmp2)) goto close_file; - h = tmp2; // height - if (!read_short(f, &tmp)) goto close_file; - planes = tmp; // must be 1 - if (!read_short(f, &tmp)) goto close_file; - bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 - if (!read_int(f, &tmp2)) goto close_file; - comp = tmp2; // compression method - if (!read_int(f, &tmp2)) goto close_file; - image_size = tmp2; // bitmap data size - if (!read_int(f, &tmp2)) goto close_file; - hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter - if (!read_int(f, &tmp2)) goto close_file; - vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter - if (!read_int(f, &tmp2)) goto close_file; - palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) - if (!read_int(f, &tmp2)) goto close_file; - important_colors = tmp2; // number of important colors - 0 if all - if (!read_int(f, &tmp2)) goto close_file; - rmask = tmp2; // red mask - if (!read_int(f, &tmp2)) goto close_file; - gmask = tmp2; // green mask - if (!read_int(f, &tmp2)) goto close_file; - bmask = tmp2; // blue mask - if (!read_int(f, &tmp2)) goto close_file; - amask = tmp2; // alpha mask - if (fread(buf, 36, 1, f) != 1) goto close_file; // skip unused cie - if (fread(buf, 12, 1, f) != 1) goto close_file; // skip unused gamma - if (fread(buf, 16, 1, f) != 1) goto close_file; // skip others - if (image_size == 0) image_size = fsize - offset; - if ((amask) && (bit_count == 32)) hasa = 1; - } - else - goto close_file; -- - fseek(f, 8, SEEK_CUR); - ReadleLong(f, &offset); - ReadleLong(f, &headSize); - if (offset >= size) - { - *error = EVAS_LOAD_ERROR_CORRUPT_FILE; - fclose(f); - return EINA_FALSE; - } - if (headSize == 12) - { - ReadleShort(f, &tmpShort); - w = tmpShort; - ReadleShort(f, &tmpShort); - h = tmpShort; - } - else if (headSize == 40) - { - ReadleLong(f, &w); - ReadleLong(f, &h); - } - } - if (h < 0) - { - h = -h; - right_way_up = 1; - } - - if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) || - IMG_TOO_BIG(w, h)) - { - if (IMG_TOO_BIG(w, h)) - *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; - else - *error = EVAS_LOAD_ERROR_GENERIC; - goto close_file; - } - - if (bit_count < 16) - { - int i; - - if ((palette_size < 0) || (palette_size > 256)) pal_num = 256; - else pal_num = palette_size; - if (bit_count == 1) - { - if (comp == 0) // no compression - { - } - else - goto close_file; - } - else if (bit_count == 4) - { - if (comp == 0) // no compression - { - } - else if (comp == 2) // rle 4bit/pixel - { - } - else - goto close_file; - } - else if (bit_count == 8) - { - if (comp == 0) // no compression - { - } - else if (comp == 1) // rle 8bit/pixel - { - } - else - goto close_file; - } - } - else if ((bit_count == 16) || (bit_count == 24) || (bit_count == 32)) - { - if (comp == 0) // no compression - { - // handled - } - else if (comp == 3) // bit field - { - // handled - } - else if (comp == 4) // jpeg - only printer drivers - goto close_file; - else if (comp == 3) // png - only printer drivers - goto close_file; - else - goto close_file; - } - else - goto close_file; -- -- ie->w = w; - ie->h = (h > 0 ? h : -h); - - ie->h = h; - if (hasa) ie->flags.alpha = 1; - - fclose(f); -- *error = EVAS_LOAD_ERROR_NONE; - -- return EINA_TRUE; - - close_file: - fclose(f); - return EINA_FALSE; --} -- --static Eina_Bool --evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error) --{ - #ifdef USE_WINK_CODEC - return evas_image_load_file_data_bmp_wink(ie, file, key, error); - #endif - - FILE *f; - char type[2]; - unsigned long size, offset, headSize, comp, imgsize, j, k, l; - unsigned short tmpShort, planes, bitcount, ncols, skip; - unsigned char byte = 0, g, b, r; - long i, w, h; - unsigned short x, y; - DATA32 *dst_data; - DATA32 *ptr, *data_end; - unsigned char *buffer_ptr, *buffer, *buffer_end; - RGBQUAD rgbQuads[256]; - unsigned long rmask = 0xff, gmask = 0xff, bmask = 0xff; - unsigned long rshift = 0, gshift = 0, bshift = 0; - unsigned long rleftshift = 0, gleftshift = 0, bleftshift = 0; - - /* - * 21.3.2006: - * Added these two variables for RLE. - */ - unsigned char byte1, byte2; - - FILE *f; - unsigned char buf[4096], *buffer = NULL, *buffer_end = NULL, *p; - char hasa = 0; - int x = 0, y = 0, w = 0, h = 0, planes = 0, bit_count = 0, image_size = 0, - comp = 0, hdpi = 0, vdpi = 0, palette_size = -1, important_colors = 0, - offset = 0, head_size = 0; - unsigned int *pal = NULL, pal_num = 0, *pix = NULL, *surface = NULL, fix, - rmask = 0, gmask = 0, bmask = 0, amask = 0; - int right_way_up = 0; - unsigned char r, g, b, a; - int fsize = 0; - unsigned int bmpsize; - unsigned short res1, res2; - -- f = fopen(file, "rb"); -- if (!f) -- { - *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; - return EINA_FALSE; - *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; - return EINA_FALSE; -- } - - /* header */ - { - struct stat statbuf; - - if (stat(file, &statbuf) == -1) - { - *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; - fclose(f); - return EINA_FALSE; - } - size = statbuf.st_size; - - if (fread(type, 1, 2, f) != 2) - { - *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; - fclose(f); - return EINA_FALSE; - } - if (strncmp(type, "BM", 2)) - { - *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; - fclose(f); - return EINA_FALSE; - } - - fseek(f, 8, SEEK_CUR); - ReadleLong(f, &offset); - ReadleLong(f, &headSize); - if (offset >= size) - { - *error = EVAS_LOAD_ERROR_CORRUPT_FILE; - fclose(f); - return EINA_FALSE; - } - if (headSize == 12) - { - ReadleShort(f, &tmpShort); - w = tmpShort; - ReadleShort(f, &tmpShort); - h = tmpShort; - ReadleShort(f, &planes); - ReadleShort(f, &bitcount); - imgsize = size - offset; - comp = BI_RGB; - } - else if (headSize == 40) - { - ReadleLong(f, &w); - ReadleLong(f, &h); - ReadleShort(f, &planes); - ReadleShort(f, &bitcount); - ReadleLong(f, &comp); - ReadleLong(f, &imgsize); - imgsize = size - offset; - fseek(f, 16, SEEK_CUR); - } - else - { - *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; - fclose(f); - return EINA_FALSE; - } - - h = h > 0 ? h : -h; - - if (!IMAGE_DIMENSIONS_OK(w, h)) - { - *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; - fclose(f); - return EINA_FALSE; - } - - if (bitcount < 16) - { - ncols = (offset - headSize - 14); - if (headSize == 12) - { - ncols /= 3; - if (ncols > 256) ncols = 256; - for (i = 0; i < ncols; i++) - fread(&rgbQuads[i], 3, 1, f); - } - else - { - ncols /= 4; - if (ncols > 256) ncols = 256; - fread(rgbQuads, 4, ncols, f); - } - } - else if (bitcount == 16 || bitcount == 32) - { - if (comp == BI_BITFIELDS) - { - int bit; - - ReadleLong(f, &rmask); - ReadleLong(f, &gmask); - ReadleLong(f, &bmask); - for (bit = bitcount - 1; bit >= 0; bit--) - { - if (bmask & (1 << bit)) bshift = bit; - if (gmask & (1 << bit)) gshift = bit; - if (rmask & (1 << bit)) rshift = bit; - } - while(((((0xffffL & bmask) >> bshift) << bleftshift) & 0x80) == 0) - { - bleftshift++; - } - while(((((0xffffL & gmask) >> gshift) << gleftshift) & 0x80) == 0) - { - gleftshift++; - } - while(((((0xffffL & rmask) >> rshift) << rleftshift) & 0x80) == 0) - { - rleftshift++; - } - } - else if (bitcount == 16) - { - rmask = 0x7C00; - gmask = 0x03E0; - bmask = 0x001F; - rshift = 10; - gshift = 5; - bshift = 0; - rleftshift = gleftshift = bleftshift = 3; - } - else if (bitcount == 32) - { - rmask = 0x00FF0000; - gmask = 0x0000FF00; - bmask = 0x000000FF; - rshift = 16; - gshift = 8; - bshift = 0; - } - } - - ie->w = w; - ie->h = h; - } - - *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; - fseek(f, 0, SEEK_END); - fsize = ftell(f); - fseek(f, 0, SEEK_SET); - if (fsize < 2) goto close_file; - - if (fread(buf, 2, 1, f) != 1) goto close_file; - if (strncmp(buf, "BM", 2)) goto close_file; // magic number - *error = EVAS_LOAD_ERROR_CORRUPT_FILE; - if (!read_int(f, &bmpsize)) goto close_file; - if (!read_short(f, &res1)) goto close_file; - if (!read_short(f, &res2)) goto close_file; - if (!read_int(f, &offset)) goto close_file; - if (!read_int(f, &head_size)) goto close_file; - image_size = fsize - offset; - if (image_size < 1) goto close_file; - - if (head_size == 12) // OS/2 V1 + Windows 3.0 - { - short tmp; - - if (!read_short(f, &tmp)) goto close_file; - w = tmp; // width - if (!read_short(f, &tmp)) goto close_file; - h = tmp; // height - if (!read_short(f, &tmp)) goto close_file; - planes = tmp; // must be 1 - if (!read_short(f, &tmp)) goto close_file; - bit_count = tmp; // bits per pixel: 1, 4, 8 & 24 - } - else if (head_size == 64) // OS/2 V2 - { - short tmp; - int tmp2; - - if (!read_int(f, &tmp2)) goto close_file; - w = tmp2; // width - if (!read_int(f, &tmp2)) goto close_file; - h = tmp2; // height - if (!read_short(f, &tmp)) goto close_file; - planes = tmp; // must be 1 - if (!read_short(f, &tmp)) goto close_file; - bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 - if (!read_int(f, &tmp2)) goto close_file; - comp = tmp2; // compression method - if (!read_int(f, &tmp2)) goto close_file; - image_size = tmp2; // bitmap data size - if (!read_int(f, &tmp2)) goto close_file; - hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter - if (!read_int(f, &tmp2)) goto close_file; - vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter - if (!read_int(f, &tmp2)) goto close_file; - palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) - if (!read_int(f, &tmp2)) goto close_file; - important_colors = tmp2; // number of important colors - 0 if all - if (fread(buf, 24, 1, f) != 1) goto close_file; // skip unused header - if (image_size == 0) image_size = fsize - offset; - } - else if (head_size == 40) // Windows 3.0 + (v3) - { - short tmp; - int tmp2; - - if (!read_int(f, &tmp2)) goto close_file; - w = tmp2; // width - if (!read_int(f, &tmp2)) goto close_file; - h = tmp2; // height - if (!read_short(f, &tmp)) goto close_file; - planes = tmp; // must be 1 - if (!read_short(f, &tmp)) goto close_file; - bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 - if (!read_int(f, &tmp2)) goto close_file; - comp = tmp2; // compression method - if (!read_int(f, &tmp2)) goto close_file; - image_size = tmp2; // bitmap data size - if (!read_int(f, &tmp2)) goto close_file; - hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter - if (!read_int(f, &tmp2)) goto close_file; - vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter - if (!read_int(f, &tmp2)) goto close_file; - palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) - if (!read_int(f, &tmp2)) goto close_file; - important_colors = tmp2; // number of important colors - 0 if all - if (image_size == 0) image_size = fsize - offset; - } - else if (head_size == 108) // Windows 95/NT4 + (v4) - { - short tmp; - int tmp2; - - if (!read_int(f, &tmp2)) goto close_file; - w = tmp2; // width - if (!read_int(f, &tmp2)) goto close_file; - h = tmp2; // height - if (!read_short(f, &tmp)) goto close_file; - planes = tmp; // must be 1 - if (!read_short(f, &tmp)) goto close_file; - bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 - if (!read_int(f, &tmp2)) goto close_file; - comp = tmp2; // compression method - if (!read_int(f, &tmp2)) goto close_file; - image_size = tmp2; // bitmap data size - if (!read_int(f, &tmp2)) goto close_file; - hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter - if (!read_int(f, &tmp2)) goto close_file; - vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter - if (!read_int(f, &tmp2)) goto close_file; - palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) - if (!read_int(f, &tmp2)) goto close_file; - important_colors = tmp2; // number of important colors - 0 if all - if (!read_int(f, &tmp2)) goto close_file; - rmask = tmp2; // red mask - if (!read_int(f, &tmp2)) goto close_file; - gmask = tmp2; // green mask - if (!read_int(f, &tmp2)) goto close_file; - bmask = tmp2; // blue mask - if (!read_int(f, &tmp2)) goto close_file; - amask = tmp2; // alpha mask - if (fread(buf, 36, 1, f) != 1) goto close_file; // skip unused cie - if (fread(buf, 12, 1, f) != 1) goto close_file; // skip unused gamma - if (image_size == 0) image_size = fsize - offset; - if ((amask) && (bit_count == 32)) hasa = 1; - } - else if (head_size == 124) // Windows 98/2000 + (v5) - { - short tmp; - int tmp2; - - if (!read_int(f, &tmp2)) goto close_file; - w = tmp2; // width - if (!read_int(f, &tmp2)) goto close_file; - h = tmp2; // height - if (!read_short(f, &tmp)) goto close_file; - planes = tmp; // must be 1 - if (!read_short(f, &tmp)) goto close_file; - bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 - if (!read_int(f, &tmp2)) goto close_file; - comp = tmp2; // compression method - if (!read_int(f, &tmp2)) goto close_file; - image_size = tmp2; // bitmap data size - if (!read_int(f, &tmp2)) goto close_file; - hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter - if (!read_int(f, &tmp2)) goto close_file; - vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter - if (!read_int(f, &tmp2)) goto close_file; - palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) - if (!read_int(f, &tmp2)) goto close_file; - important_colors = tmp2; // number of important colors - 0 if all - if (!read_int(f, &tmp2)) goto close_file; - rmask = tmp2; // red mask - if (!read_int(f, &tmp2)) goto close_file; - gmask = tmp2; // green mask - if (!read_int(f, &tmp2)) goto close_file; - bmask = tmp2; // blue mask - if (!read_int(f, &tmp2)) goto close_file; - amask = tmp2; // alpha mask - if (fread(buf, 36, 1, f) != 1) goto close_file; // skip unused cie - if (fread(buf, 12, 1, f) != 1) goto close_file; // skip unused gamma - if (fread(buf, 16, 1, f) != 1) goto close_file; // skip others - if (image_size == 0) image_size = fsize - offset; - if ((amask) && (bit_count == 32)) hasa = 1; - } - else - goto close_file; -- - if (1) - if (h < 0) - { - h = -h; - right_way_up = 1; - } - if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) || - IMG_TOO_BIG(w, h)) - { - if (IMG_TOO_BIG(w, h)) - *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; - else - *error = EVAS_LOAD_ERROR_GENERIC; - goto close_file; - } - - if ((w != ie->w) || (h != ie->h)) - { - *error = EVAS_LOAD_ERROR_GENERIC; - goto close_file; - } - evas_cache_image_surface_alloc(ie, w, h); - surface = evas_cache_image_pixels(ie); - if (!surface) - { - *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; - goto close_file; - } - - if (bit_count < 16) -- { - int i; - - if (bit_count == 1) - { - if ((palette_size <= 0) || (palette_size > 2)) pal_num = 2; - else pal_num = palette_size; - } - else if (bit_count == 4) - { - if ((palette_size <= 0) || (palette_size > 16)) pal_num = 16; - else pal_num = palette_size; - } - else if (bit_count == 8) - { - if ((palette_size <= 0) || (palette_size > 256)) pal_num = 256; - else pal_num = palette_size; - } - pal = alloca(256 * 4); - for (i = 0; i < pal_num; i++) - { - if (fread(&b, 1, 1, f) != 1) goto close_file; - if (fread(&g, 1, 1, f) != 1) goto close_file; - if (fread(&r, 1, 1, f) != 1) goto close_file; - if ((head_size != 12) /*&& (palette_size != 0)*/) - { // OS/2 V1 doesnt do the pad byte - if (fread(&a, 1, 1, f) != 1) goto close_file; - } - a = 0xff; // fillin a as solid for paletted images - pal[i] = (a << 24) | (r << 16) | (g << 8) | b; - } -- fseek(f, offset, SEEK_SET); - buffer = malloc(imgsize); - buffer = malloc(image_size + 8); // add 8 for padding to avoid checks -- if (!buffer) -- { -- *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; - fclose(f); - return EINA_FALSE; - goto close_file; -- } - - evas_cache_image_surface_alloc(ie, ie->w, ie->h); - dst_data = evas_cache_image_pixels(ie); - - fread(buffer, imgsize, 1, f); - fclose(f); - buffer_ptr = buffer; - buffer_end = buffer + imgsize; - - data_end = dst_data + w * h; - ptr = dst_data + ((h - 1) * w); - - if (bitcount == 1) - buffer_end = buffer + image_size; - p = buffer; - if (fread(buffer, image_size, 1, f) != 1) goto close_file; - - if (bit_count == 1) -- { - if (comp == BI_RGB) - if (comp == 0) // no compression -- { - skip = ((((w + 31) / 32) * 32) - w) / 8; - pix = surface; -- for (y = 0; y < h; y++) -- { - for (x = 0; x < w && buffer_ptr < buffer_end; x++) - if (!right_way_up) pix = surface + ((h - 1 - y) * w); - for (x = 0; x < w; x++) -- { - if ((x & 7) == 0) - byte = *(buffer_ptr++); - k = (byte >> 7) & 1; - *ptr++ = 0xff000000 | - (rgbQuads[k].rgbRed << 16) | - (rgbQuads[k].rgbGreen << 8) | - rgbQuads[k].rgbBlue; - byte <<= 1; - if ((x & 0x7) == 0x0) - { - *pix = pal[*p >> 7]; - } - else if ((x & 0x7) == 0x1) - { - *pix = pal[(*p >> 6) & 0x1]; - } - else if ((x & 0x7) == 0x2) - { - *pix = pal[(*p >> 5) & 0x1]; - } - else if ((x & 0x7) == 0x3) - { - *pix = pal[(*p >> 4) & 0x1]; - } - else if ((x & 0x7) == 0x4) - { - *pix = pal[(*p >> 3) & 0x1]; - } - else if ((x & 0x7) == 0x5) - { - *pix = pal[(*p >> 2) & 0x1]; - } - else if ((x & 0x7) == 0x6) - { - *pix = pal[(*p >> 1) & 0x1]; - } - else - { - *pix = pal[*p & 0x1]; - p++; - } - if (p >= buffer_end) break; - pix++; -- } - buffer_ptr += skip; - ptr -= w * 2; - } - if ((x & 0x7) != 0) p++; - fix = (int)(((unsigned long)p) & 0x3); - if (fix > 0) p += 4 - fix; // align row read - if (p >= buffer_end) break; - } -- } - else - goto close_file; -- } - - /* - * 21.3.2006 - * Bug fixes and optimization: - * - * RLE encoding is dangerous and can be used by attackers by creating special files. - * We has 'buffer_ptr' and 'buffer_end' variables and buffer_end points to first - * unaccessible byte in buffer. - * - If we use 'byte = *(buffer_ptr++) in main loop we must check if - * 'buffer_ptr != buffer_end', because special or incomplete bmp file can generate - * segfault (I was writing it, because in RLE we need to read depending count of - * bytes that depends on requester operation). - * SOLUTION: Don't read one byte, read two bytes and check. - * - If RLE teels us than single color length will be larger than allowed, we can - * stop, because bitmap is corrupted or crawled. - * SOLUTION: Check for length ('l' variable in RLE) and break loop if it's invalid - * IMPROVEMENTS: We can stop checking if 'x' is out of rangle, because it never be. - * - In RLE4 use one bigger loop that fills two pixels. This is faster and cleaner. - * If one pixel remains (the tail), do it on end of the loop. - * - If we will check x and y (new line and skipping), we can't go outsize imlib - * image buffer. - */ - - if (bitcount == 4) - else if (bit_count == 4) -- { - if (comp == BI_RLE4) - if (comp == 0) // no compression -- { - /* - * 21.3.2006: This is better than using 'if buffer_ptr + 1 < buffer_end' - */ - unsigned char *buffer_end_minus_1 = buffer_end - 1; - x = 0; - y = 0; - - for (i = 0; i < imgsize && buffer_ptr < buffer_end_minus_1; i++) - pix = surface; - for (y = 0; y < h; y++) -- { - byte1 = buffer_ptr[0]; - byte2 = buffer_ptr[1]; - buffer_ptr += 2; - if (byte1) - if (!right_way_up) pix = surface + ((h - 1 - y) * w); - for (x = 0; x < w; x++) -- { - DATA32 t1, t2; - - l = byte1; - /* Check for invalid length */ - if (l + x > w) goto _bail; - if ((x & 0x1) == 0x1) - { - *pix = pal[*p & 0x0f]; - p++; - } - else - { - *pix = pal[*p >> 4]; - } - if (p >= buffer_end) break; - pix++; - } - if ((x & 0x1) != 0) p++; - fix = (int)(((unsigned long)p) & 0x3); - if (fix > 0) p += 4 - fix; // align row read - if (p >= buffer_end) break; - } - } - else if (comp == 2) // rle 4bit/pixel - { - int count = 0, done = 0, wpad; -- - t1 = 0xff000000 | (rgbQuads[byte2 >> 4].rgbRed << 16) | - (rgbQuads[byte2 >> 4].rgbGreen << 8) | - (rgbQuads[byte2 >> 4].rgbBlue ) ; - t2 = 0xff000000 | (rgbQuads[byte2 & 0xF].rgbRed << 16) | - (rgbQuads[byte2 & 0xF].rgbGreen << 8) | - (rgbQuads[byte2 & 0xF].rgbBlue ) ; - for (j = l/2; j; j--) { - ptr[0] = t1; - ptr[1] = t2; - ptr += 2; - } - /* tail */ - if (l & 1) *ptr++ = t1; - x += l; - pix = surface; - if (!right_way_up) pix = surface + ((h - 1 - y) * w); - wpad = ((w + 1) / 2) * 2; - while (p < buffer_end) - { - if (p[0]) - { - unsigned int col1 = pal[p[1] >> 4]; - unsigned int col2 = pal[p[1] & 0xf]; - - if ((x + p[0]) > wpad) break; - count = p[0] / 2; - while (count > 0) - { - if (x < w) - { - pix[0] = col1; - x++; - } - if (x < w) - { - pix[1] = col2; - x++; - } - pix += 2; - count--; - } - if (p[0] & 0x1) - { - *pix = col1; - x++; - pix++; - } - p += 2; -- } -- else -- { - switch (byte2) - switch (p[1]) -- { - case RLE_NEXT: - x = 0; - if (++y >= h) goto _bail; - ptr = dst_data + (h - y - 1) * w; - break; - case RLE_END: - goto _bail; - case RLE_MOVE: - /* Need to read two bytes */ - if (buffer_ptr >= buffer_end_minus_1) goto _bail; - x += buffer_ptr[0]; - y += buffer_ptr[1]; - buffer_ptr += 2; - /* Check for correct coordinates */ - if (x >= w) goto _bail; - if (y >= h) goto _bail; - ptr = dst_data + (h - y - 1) * w + x; - break; - default: - l = byte2; - /* Check for invalid length and valid buffer size */ - if (l + x > w) goto _bail; - if (buffer_ptr + (l >> 1) + (l & 1) > buffer_end) goto _bail; - - for (j = l/2; j; j--) { - byte = *buffer_ptr++; - ptr[0] = 0xff000000 | (rgbQuads[byte >> 4].rgbRed << 16) | - (rgbQuads[byte >> 4].rgbGreen << 8) | - (rgbQuads[byte >> 4].rgbBlue ) ; - ptr[1] = 0xff000000 | (rgbQuads[byte & 0xF].rgbRed << 16) | - (rgbQuads[byte & 0xF].rgbGreen << 8) | - (rgbQuads[byte & 0xF].rgbBlue ) ; - ptr += 2; - case 0: // EOL - x = 0; - y++; - if (!right_way_up) - pix = surface + ((h - 1 - y) * w); - else - pix = surface + (y * w); - if (y >= h) - { - p = buffer_end; -- } - if (l & 1) { - byte = *buffer_ptr++; - *ptr++ = 0xff000000 | (rgbQuads[byte >> 4].rgbRed << 16) | - (rgbQuads[byte >> 4].rgbGreen << 8) | - (rgbQuads[byte >> 4].rgbBlue ) ; - p += 2; - break; - case 1: // EOB - p = buffer_end; - break; - case 2: // DELTA - x += p[2]; - y += p[3]; - if ((x >= w) || (y >= h)) - { - p = buffer_end; -- } - x += l; - - if ((l & 3) == 1) - buffer_ptr += 2; - else if ((l & 3) == 2) - buffer_ptr++; - break; - if (!right_way_up) - pix = surface + x + ((h - 1 - y) * w); - else - pix = surface + x + (y * w); - p += 4; - break; - default: - count = p[1]; - if (((p + count) > buffer_end) || - ((x + count) > w)) - { - p = buffer_end; - break; - } - p += 2; - done = count; - count /= 2; - while (count > 0) - { - pix[0] = pal[*p >> 4]; - pix[1] = pal[*p & 0xf]; - pix += 2; - p++; - count--; - } - x += done; - if (done & 0x1) - { - *pix = pal[*p >> 4]; - p++; - } - if ((done & 0x3) == 0x1) - p += 2; - else if ((done & 0x3) == 0x2) - p += 1; - break; -- } -- } -- } -- } - else if (comp == BI_RGB) - else - goto close_file; - } - else if (bit_count == 8) - { - if (comp == 0) // no compression -- { - skip = ((((w + 7) / 8) * 8) - w) / 2; - pix = surface; -- for (y = 0; y < h; y++) -- { - for (x = 0; x < w && buffer_ptr < buffer_end; x++) - if (!right_way_up) pix = surface + ((h - 1 - y) * w); - for (x = 0; x < w; x++) -- { - if ((x & 1) == 0) - byte = *(buffer_ptr++); - k = (byte & 0xF0) >> 4; - *ptr++ = 0xff000000 | - (rgbQuads[k].rgbRed << 16) | - (rgbQuads[k].rgbGreen << 8) | - rgbQuads[k].rgbBlue; - byte <<= 4; - *pix = pal[*p]; - p++; - if (p >= buffer_end) break; - pix++; -- } - buffer_ptr += skip; - ptr -= w * 2; - } - fix = (int)(((unsigned long)p) & 0x3); - if (fix > 0) p += 4 - fix; // align row read - if (p >= buffer_end) break; - } -- } - } - if (bitcount == 8) - { - if (comp == BI_RLE8) - else if (comp == 1) // rle 8bit/pixel -- { - /* - * 21.3.2006: This is better than using 'if buffer_ptr + 1 < buffer_end' - */ - unsigned char *buffer_end_minus_1 = buffer_end - 1; - x = 0; - y = 0; - for (i = 0; i < imgsize && buffer_ptr < buffer_end_minus_1; i++) - int count = 0, done = 0; - - pix = surface; - if (!right_way_up) pix = surface + ((h - 1 - y) * w); - while (p < buffer_end) -- { - byte1 = buffer_ptr[0]; - byte2 = buffer_ptr[1]; - buffer_ptr += 2; - if (byte1) - if (p[0]) -- { - DATA32 pix = 0xff000000 | (rgbQuads[byte2].rgbRed << 16) | - (rgbQuads[byte2].rgbGreen << 8) | - (rgbQuads[byte2].rgbBlue ) ; - l = byte1; - if (x + l > w) goto _bail; - for (j = l; j; j--) *ptr++ = pix; - x += l; - unsigned int col = pal[p[1]]; - - count = p[0]; - if ((x + p[0]) > w) break; - while (count > 0) - { - *pix = col; - pix++; - count--; - } - x += p[0]; - p += 2; -- } -- else -- { - switch (byte2) - switch (p[1]) -- { - case RLE_NEXT: - x = 0; - if (++y >= h) goto _bail; - ptr = dst_data + ((h - y - 1) * w) + x; - break; - case RLE_END: - goto _bail; - case RLE_MOVE: - /* Need to read two bytes */ - if (buffer_ptr >= buffer_end_minus_1) goto _bail; - x += buffer_ptr[0]; - y += buffer_ptr[1]; - buffer_ptr += 2; - /* Check for correct coordinates */ - if (x >= w) goto _bail; - if (y >= h) goto _bail; - ptr = dst_data + ((h - y - 1) * w) + x; - break; - default: - l = byte2; - if (x + l > w) goto _bail; - if (buffer_ptr + l > buffer_end) goto _bail; - for (j = 0; j < l; j++) - { - byte = *(buffer_ptr++); - - *ptr++ = 0xff000000 | - (rgbQuads[byte].rgbRed << 16) | - (rgbQuads[byte].rgbGreen << 8) | - rgbQuads[byte].rgbBlue; - } - x += l; - if (l & 1) - buffer_ptr++; - break; - case 0: // EOL - x = 0; - y++; - if (!right_way_up) - pix = surface + ((h - 1 - y) * w); - else - pix = surface + (y * w); - if (y >= h) - { - p = buffer_end; - } - p += 2; - break; - case 1: // EOB - p = buffer_end; - break; - case 2: // DELTA - x += p[2]; - y += p[3]; - if ((x >= w) || (y >= h)) - { - p = buffer_end; - } - if (!right_way_up) - pix = surface + x + ((h - 1 - y) * w); - else - pix = surface + x + (y * w); - p += 4; - break; - default: - count = p[1]; - if (((p + count) > buffer_end) || - ((x + count) > w)) - { - p = buffer_end; - break; - } - p += 2; - done = count; - while (count > 0) - { - *pix = pal[*p]; - pix++; - p++; - count--; - } - x += done; - if (done & 0x1) p++; - break; -- } -- } -- } - } - else if (comp == BI_RGB) - } - else - goto close_file; - } - } - else if ((bit_count == 16) || (bit_count == 24) || (bit_count == 32)) - { - if (comp == 0) // no compression - { - fseek(f, offset, SEEK_SET); - buffer = malloc(image_size + 8); // add 8 for padding to avoid checks - if (!buffer) -- { - skip = (((w + 3) / 4) * 4) - w; - *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; - goto close_file; - } - buffer_end = buffer + image_size; - p = buffer; - if (fread(buffer, image_size, 1, f) != 1) goto close_file; - if (bit_count == 16) - { - unsigned short tmp; - - pix = surface; -- for (y = 0; y < h; y++) -- { - for (x = 0; x < w && buffer_ptr < buffer_end; x++) - if (!right_way_up) pix = surface + ((h - 1 - y) * w); - for (x = 0; x < w; x++) -- { - byte = *(buffer_ptr++); - *ptr++ = 0xff000000 | - (rgbQuads[byte].rgbRed << 16) | - (rgbQuads[byte].rgbGreen << 8) | - rgbQuads[byte].rgbBlue; - tmp = *((unsigned short *)(p)); - - r = (tmp >> 7) & 0xf8; r |= r >> 5; - g = (tmp >> 2) & 0xf8; g |= g >> 5; - b = (tmp << 3) & 0xf8; b |= b >> 5; - *pix = 0xff000000 | (r << 16) | (g << 8) | (b); - p += 2; - if (p >= buffer_end) break; - pix++; -- } - ptr -= w * 2; - buffer_ptr += skip; - } - fix = (int)(((unsigned long)p) & 0x3); - if (fix > 0) p += 4 - fix; // align row read - if (p >= buffer_end) break; - } -- } - - } - else if (bitcount == 16) - { - /* 21.3.2006 - Need to check for buffer_ptr + 1 < buffer_end */ - unsigned char *buffer_end_minus_1 = buffer_end - 1; - skip = (((w * 16 + 31) / 32) * 4) - (w * 2); - for (y = 0; y < h; y++) - else if (bit_count == 24) -- { - for (x = 0; x < w && buffer_ptr < buffer_end_minus_1; x++) - pix = surface; - for (y = 0; y < h; y++) -- { - /* - * THIS WAS OLD CODE - * - * r = ((unsigned short)(*buffer_ptr) & rmask) >> rshift; - * g = ((unsigned short)(*buffer_ptr) & gmask) >> gshift; - * b = ((unsigned short)(*(buffer_ptr++)) & bmask) >> - * bshift; - * *ptr++ = 0xff000000 | (r << 16) | (g << 8) | b; - */ - unsigned short pix = *(unsigned short *)buffer_ptr; - *ptr++ = 0xff000000 | ((((pix & rmask) >> rshift) << rleftshift) << 16) | - ((((pix & gmask) >> gshift) << gleftshift) << 8) | - ((((pix & bmask) >> bshift) << bleftshift) ) ; - buffer_ptr += 2; - if (!right_way_up) pix = surface + ((h - 1 - y) * w); - for (x = 0; x < w; x++) - { - b = p[0]; - g = p[1]; - r = p[2]; - *pix = 0xff000000 | (r << 16) | (g << 8) | (b); - p += 3; - if (p >= buffer_end) break; - pix++; - } - fix = (int)(((unsigned long)p) & 0x3); - if (fix > 0) p += 4 - fix; // align row read - if (p >= buffer_end) break; -- } - ptr -= w * 2; - buffer_ptr += skip; - } - } - else if (bitcount == 24) - { - /* 21.3.2006 - Fix: need to check for buffer_ptr + 2 < buffer_end */ - unsigned char *buffer_end_minus_2 = buffer_end - 2; - skip = (4 - ((w * 3) % 4)) & 3; - for (y = 0; y < h; y++) - } - else if (bit_count == 32) -- { - for (x = 0; x < w && buffer_ptr < buffer_end_minus_2; x++) - pix = surface; - for (y = 0; y < h; y++) -- { - b = *(buffer_ptr++); - g = *(buffer_ptr++); - r = *(buffer_ptr++); - *ptr++ = 0xff000000 | (r << 16) | (g << 8) | b; - if (!right_way_up) pix = surface + ((h - 1 - y) * w); - for (x = 0; x < w; x++) - { - b = p[0]; - g = p[1]; - r = p[2]; - a = p[3]; - if (!hasa) a = 0xff; - *pix = (a << 24) | (r << 16) | (g << 8) | (b); - p += 4; - if (p >= buffer_end) break; - pix++; - } - fix = (int)(((unsigned long)p) & 0x3); - if (fix > 0) p += 4 - fix; // align row read - if (p >= buffer_end) break; -- } - ptr -= w * 2; - buffer_ptr += skip; - } - } - else - goto close_file; -- } - else if (bitcount == 32) - else if (comp == 3) // bit field -- { - /* 21.3.2006 - Need to check buffer_ptr + 3 < buffer_end */ - unsigned char *buffer_end_minus_3 = buffer_end_minus_3; - skip = (((w * 32 + 31) / 32) * 4) - (w * 4); - for (y = 0; y < h; y++) - if (!read_int(f, &rmask)) goto close_file; - if (!read_int(f, &gmask)) goto close_file; - if (!read_int(f, &bmask)) goto close_file; - - fseek(f, offset, SEEK_SET); - buffer = malloc(image_size + 8); // add 8 for padding to avoid checks - if (!buffer) -- { - for (x = 0; x < w && buffer_ptr < buffer_end_minus_3; x++) - *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; - goto close_file; - } - buffer_end = buffer + image_size; - p = buffer; - if (fread(buffer, image_size, 1, f) != 1) goto close_file; - if ((bit_count == 16) && - (rmask == 0xf800) && (gmask == 0x07e0) && (bmask == 0x001f) - ) - { - unsigned short tmp; - - pix = surface; - for (y = 0; y < h; y++) -- { - /* - * THIS WAS OLD CODE: I don't understand it and it's invalid. - * - * r = ((unsigned long)(*buffer_ptr) & rmask) >> rshift; - * g = ((unsigned long)(*buffer_ptr) & gmask) >> gshift; - * b = ((unsigned long)(*buffer_ptr) & bmask) >> bshift; - * *ptr++ = 0xff000000 | (r << 16) | (g << 8) | b; - * r = *(buffer_ptr++); - * r = *(buffer_ptr++); - */ - if (!right_way_up) pix = surface + ((h - 1 - y) * w); - for (x = 0; x < w; x++) - { - tmp = *((unsigned short *)(p)); -- - /* TODO: What about alpha channel...Is used? */ - DATA32 pix = *(unsigned int *)buffer_ptr; - *ptr++ = 0xff000000 | (((pix & rmask) >> rshift) << 16) | - (((pix & gmask) >> gshift) << 8) | - (((pix & bmask) >> bshift) ) ; - buffer_ptr += 4; - r = (tmp >> 8) & 0xf8; r |= r >> 5; - g = (tmp >> 3) & 0xfc; g |= g >> 6; - b = (tmp << 3) & 0xf8; b |= b >> 5; - *pix = 0xff000000 | (r << 16) | (g << 8) | (b); - p += 2; - if (p >= buffer_end) break; - pix++; - } - fix = (int)(((unsigned long)p) & 0x3); - if (fix > 0) p += 4 - fix; // align row read - if (p >= buffer_end) break; -- } - ptr -= w * 2; - buffer_ptr += skip; - } - } - else if ((bit_count == 16) && - (rmask == 0x7c00) && (gmask == 0x03e0) && (bmask == 0x001f) - ) - { - unsigned short tmp; - - pix = surface; - for (y = 0; y < h; y++) - { - if (!right_way_up) pix = surface + ((h - 1 - y) * w); - for (x = 0; x < w; x++) - { - tmp = *((unsigned short *)(p)); - - r = (tmp >> 7) & 0xf8; r |= r >> 5; - g = (tmp >> 2) & 0xf8; g |= g >> 5; - b = (tmp << 3) & 0xf8; b |= b >> 5; - *pix = 0xff000000 | (r << 16) | (g << 8) | (b); - p += 2; - if (p >= buffer_end) break; - pix++; - } - fix = (int)(((unsigned long)p) & 0x3); - if (fix > 0) p += 4 - fix; // align row read - if (p >= buffer_end) break; - } - } - else if (bit_count == 32) - { - pix = surface; - for (y = 0; y < h; y++) - { - if (!right_way_up) pix = surface + ((h - 1 - y) * w); - for (x = 0; x < w; x++) - { - b = p[0]; - g = p[1]; - r = p[2]; - a = p[3]; - if (!hasa) a = 0xff; - *pix = (a << 24) | (r << 16) | (g << 8) | (b); - p += 4; - if (p >= buffer_end) break; - pix++; - } - fix = (int)(((unsigned long)p) & 0x3); - if (fix > 0) p += 4 - fix; // align row read - if (p >= buffer_end) break; - } - } - else - goto close_file; -- } - _bail: - free(buffer); - else if (comp == 4) // jpeg - only printer drivers - { - goto close_file; - } - else if (comp == 3) // png - only printer drivers - { - goto close_file; - } - else - goto close_file; -- } - else - goto close_file; - - if (buffer) free(buffer); - fclose(f); -- - evas_common_image_premul(ie); - *error = EVAS_LOAD_ERROR_NONE; -- return EINA_TRUE; - - close_file: - if (buffer) free(buffer); - fclose(f); - return EINA_FALSE; --} -- --static int --module_open(Evas_Module *em) --{ -- if (!em) return 0; -- em->functions = (void *)(&evas_image_load_bmp_func); -- return 1; --} -- --static void --module_close(Evas_Module *em) --{ --} -- --static Evas_Module_Api evas_modapi = --{ - EVAS_MODULE_API_VERSION, - "bmp", - "none", - { - module_open, - module_close - } - EVAS_MODULE_API_VERSION, - "bmp", - "none", - { - module_open, - module_close - } --}; -- --EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_IMAGE_LOADER, image_loader, bmp); -- --#ifndef EVAS_STATIC_BUILD_BMP --EVAS_EINA_MODULE_DEFINE(image_loader, bmp); --#endif ++ ++#ifdef HAVE_CONFIG_H ++# include ++#endif ++ ++#ifndef _GNU_SOURCE ++#define _GNU_SOURCE ++#endif ++ ++#include ++ ++#ifdef HAVE_EVIL ++# include ++#endif ++ ++#include "evas_common.h" ++#include "evas_private.h" ++ ++#define EVAS_WINK_MODULE_NAME bmp ++#include "evas_wink.h" ++ ++static Eina_Bool evas_image_load_file_head_bmp(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4); ++static Eina_Bool evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4); ++ ++static Evas_Image_Load_Func evas_image_load_bmp_func = ++{ ++ EINA_TRUE, ++ evas_image_load_file_head_bmp, ++ evas_image_load_file_data_bmp ++}; ++ ++ ++static int ++read_short(FILE *file, short *ret) ++{ ++ unsigned char b[2]; ++ if (fread(b, sizeof(unsigned char), 2, file) != 2) return 0; ++ *ret = (b[1] << 8) | b[0]; ++ return 1; ++} ++ ++static int ++read_int(FILE *file, int *ret) ++{ ++ unsigned char b[4]; ++ if (fread(b, sizeof(unsigned char), 4, file) != 4) return 0; ++ *ret = (b[3] << 24) | (b[2] << 16) | (b[1] << 8) | b[0]; ++ return 1; ++} ++ ++static Eina_Bool ++evas_image_load_file_head_bmp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error) ++{ ++#ifdef USE_WINK_CODEC ++ return evas_image_load_file_head_bmp_wink(ie, file, key, error); ++#endif ++ ++ FILE *f; ++ unsigned char buf[4096]; ++ char hasa = 0; ++ int w = 0, h = 0, planes = 0, bit_count = 0, ++ image_size = 0, comp = 0, hdpi = 0, vdpi = 0, ++ palette_size = -1, important_colors = 0, rowlen = 0; ++ unsigned int offset, head_size, rmask = 0, gmask = 0, bmask = 0, amask = 0; ++ unsigned int *pal = NULL, pal_num = 0; ++ int right_way_up = 0; ++ int fsize = 0; ++ unsigned int bmpsize; ++ unsigned short res1, res2; ++ ++ f = fopen(file, "rb"); ++ if (!f) ++ { ++ *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; ++ return EINA_FALSE; ++ } ++ ++ *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; ++ fseek(f, 0, SEEK_END); ++ fsize = ftell(f); ++ fseek(f, 0, SEEK_SET); ++ if (fsize < 2) goto close_file; ++ ++ if (fread(buf, 2, 1, f) != 1) goto close_file; ++ if (strncmp(buf, "BM", 2)) goto close_file; // magic number ++ *error = EVAS_LOAD_ERROR_CORRUPT_FILE; ++ if (!read_int(f, &bmpsize)) goto close_file; ++ if (!read_short(f, &res1)) goto close_file; ++ if (!read_short(f, &res2)) goto close_file; ++ if (!read_int(f, &offset)) goto close_file; ++ if (!read_int(f, &head_size)) goto close_file; ++ if (head_size == 12) // OS/2 V1 + Windows 3.0 ++ { ++ short tmp; ++ ++ if (!read_short(f, &tmp)) goto close_file; ++ w = tmp; // width ++ if (!read_short(f, &tmp)) goto close_file; ++ h = tmp; // height ++ if (!read_short(f, &tmp)) goto close_file; ++ planes = tmp; // must be 1 ++ if (!read_short(f, &tmp)) goto close_file; ++ bit_count = tmp; // bits per pixel: 1, 4, 8 & 24 ++ } ++ else if (head_size == 64) // OS/2 V2 ++ { ++ short tmp; ++ int tmp2; ++ ++ if (!read_int(f, &tmp2)) goto close_file; ++ w = tmp2; // width ++ if (!read_int(f, &tmp2)) goto close_file; ++ h = tmp2; // height ++ if (!read_short(f, &tmp)) goto close_file; ++ planes = tmp; // must be 1 ++ if (!read_short(f, &tmp)) goto close_file; ++ bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 ++ if (!read_int(f, &tmp2)) goto close_file; ++ comp = tmp2; // compression method ++ if (!read_int(f, &tmp2)) goto close_file; ++ image_size = tmp2; // bitmap data size ++ if (!read_int(f, &tmp2)) goto close_file; ++ hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter ++ if (!read_int(f, &tmp2)) goto close_file; ++ vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter ++ if (!read_int(f, &tmp2)) goto close_file; ++ palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) ++ if (!read_int(f, &tmp2)) goto close_file; ++ important_colors = tmp2; // number of important colors - 0 if all ++ if (fread(buf, 24, 1, f) != 1) goto close_file; // skip unused header ++ if (image_size == 0) image_size = fsize - offset; ++ } ++ else if (head_size == 40) // Windows 3.0 + (v3) ++ { ++ short tmp; ++ int tmp2; ++ ++ if (!read_int(f, &tmp2)) goto close_file; ++ w = tmp2; // width ++ if (!read_int(f, &tmp2)) goto close_file; ++ h = tmp2; // height ++ if (!read_short(f, &tmp)) goto close_file; ++ planes = tmp; // must be 1 ++ if (!read_short(f, &tmp)) goto close_file; ++ bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 ++ if (!read_int(f, &tmp2)) goto close_file; ++ comp = tmp2; // compression method ++ if (!read_int(f, &tmp2)) goto close_file; ++ image_size = tmp2; // bitmap data size ++ if (!read_int(f, &tmp2)) goto close_file; ++ hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter ++ if (!read_int(f, &tmp2)) goto close_file; ++ vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter ++ if (!read_int(f, &tmp2)) goto close_file; ++ palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) ++ if (!read_int(f, &tmp2)) goto close_file; ++ important_colors = tmp2; // number of important colors - 0 if all ++ if (image_size == 0) image_size = fsize - offset; ++ } ++ else if (head_size == 108) // Windows 95/NT4 + (v4) ++ { ++ short tmp; ++ int tmp2; ++ ++ if (!read_int(f, &tmp2)) goto close_file; ++ w = tmp2; // width ++ if (!read_int(f, &tmp2)) goto close_file; ++ h = tmp2; // height ++ if (!read_short(f, &tmp)) goto close_file; ++ planes = tmp; // must be 1 ++ if (!read_short(f, &tmp)) goto close_file; ++ bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 ++ if (!read_int(f, &tmp2)) goto close_file; ++ comp = tmp2; // compression method ++ if (!read_int(f, &tmp2)) goto close_file; ++ image_size = tmp2; // bitmap data size ++ if (!read_int(f, &tmp2)) goto close_file; ++ hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter ++ if (!read_int(f, &tmp2)) goto close_file; ++ vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter ++ if (!read_int(f, &tmp2)) goto close_file; ++ palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) ++ if (!read_int(f, &tmp2)) goto close_file; ++ important_colors = tmp2; // number of important colors - 0 if all ++ if (!read_int(f, &tmp2)) goto close_file; ++ rmask = tmp2; // red mask ++ if (!read_int(f, &tmp2)) goto close_file; ++ gmask = tmp2; // green mask ++ if (!read_int(f, &tmp2)) goto close_file; ++ bmask = tmp2; // blue mask ++ if (!read_int(f, &tmp2)) goto close_file; ++ amask = tmp2; // alpha mask ++ if (fread(buf, 36, 1, f) != 1) goto close_file; // skip unused cie ++ if (fread(buf, 12, 1, f) != 1) goto close_file; // skip unused gamma ++ if (image_size == 0) image_size = fsize - offset; ++ if ((amask) && (bit_count == 32)) hasa = 1; ++ } ++ else if (head_size == 124) // Windows 98/2000 + (v5) ++ { ++ short tmp; ++ int tmp2; ++ ++ if (!read_int(f, &tmp2)) goto close_file; ++ w = tmp2; // width ++ if (!read_int(f, &tmp2)) goto close_file; ++ h = tmp2; // height ++ if (!read_short(f, &tmp)) goto close_file; ++ planes = tmp; // must be 1 ++ if (!read_short(f, &tmp)) goto close_file; ++ bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 ++ if (!read_int(f, &tmp2)) goto close_file; ++ comp = tmp2; // compression method ++ if (!read_int(f, &tmp2)) goto close_file; ++ image_size = tmp2; // bitmap data size ++ if (!read_int(f, &tmp2)) goto close_file; ++ hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter ++ if (!read_int(f, &tmp2)) goto close_file; ++ vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter ++ if (!read_int(f, &tmp2)) goto close_file; ++ palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) ++ if (!read_int(f, &tmp2)) goto close_file; ++ important_colors = tmp2; // number of important colors - 0 if all ++ if (!read_int(f, &tmp2)) goto close_file; ++ rmask = tmp2; // red mask ++ if (!read_int(f, &tmp2)) goto close_file; ++ gmask = tmp2; // green mask ++ if (!read_int(f, &tmp2)) goto close_file; ++ bmask = tmp2; // blue mask ++ if (!read_int(f, &tmp2)) goto close_file; ++ amask = tmp2; // alpha mask ++ if (fread(buf, 36, 1, f) != 1) goto close_file; // skip unused cie ++ if (fread(buf, 12, 1, f) != 1) goto close_file; // skip unused gamma ++ if (fread(buf, 16, 1, f) != 1) goto close_file; // skip others ++ if (image_size == 0) image_size = fsize - offset; ++ if ((amask) && (bit_count == 32)) hasa = 1; ++ } ++ else ++ goto close_file; ++ ++ if (h < 0) ++ { ++ h = -h; ++ right_way_up = 1; ++ } ++ ++ if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) || ++ IMG_TOO_BIG(w, h)) ++ { ++ if (IMG_TOO_BIG(w, h)) ++ *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; ++ else ++ *error = EVAS_LOAD_ERROR_GENERIC; ++ goto close_file; ++ } ++ ++ if (bit_count < 16) ++ { ++ int i; ++ ++ if ((palette_size < 0) || (palette_size > 256)) pal_num = 256; ++ else pal_num = palette_size; ++ if (bit_count == 1) ++ { ++ if (comp == 0) // no compression ++ { ++ } ++ else ++ goto close_file; ++ } ++ else if (bit_count == 4) ++ { ++ if (comp == 0) // no compression ++ { ++ } ++ else if (comp == 2) // rle 4bit/pixel ++ { ++ } ++ else ++ goto close_file; ++ } ++ else if (bit_count == 8) ++ { ++ if (comp == 0) // no compression ++ { ++ } ++ else if (comp == 1) // rle 8bit/pixel ++ { ++ } ++ else ++ goto close_file; ++ } ++ } ++ else if ((bit_count == 16) || (bit_count == 24) || (bit_count == 32)) ++ { ++ if (comp == 0) // no compression ++ { ++ // handled ++ } ++ else if (comp == 3) // bit field ++ { ++ // handled ++ } ++ else if (comp == 4) // jpeg - only printer drivers ++ goto close_file; ++ else if (comp == 3) // png - only printer drivers ++ goto close_file; ++ else ++ goto close_file; ++ } ++ else ++ goto close_file; ++ ++ ie->w = w; ++ ie->h = h; ++ if (hasa) ie->flags.alpha = 1; ++ ++ fclose(f); ++ *error = EVAS_LOAD_ERROR_NONE; ++ return EINA_TRUE; ++ ++ close_file: ++ fclose(f); ++ return EINA_FALSE; ++} ++ ++static Eina_Bool ++evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error) ++{ ++#ifdef USE_WINK_CODEC ++ return evas_image_load_file_data_bmp_wink(ie, file, key, error); ++#endif ++ ++ FILE *f; ++ unsigned char buf[4096], *buffer = NULL, *buffer_end = NULL, *p; ++ char hasa = 0; ++ int x = 0, y = 0, w = 0, h = 0, planes = 0, bit_count = 0, image_size = 0, ++ comp = 0, hdpi = 0, vdpi = 0, palette_size = -1, important_colors = 0, ++ offset = 0, head_size = 0; ++ unsigned int *pal = NULL, pal_num = 0, *pix = NULL, *surface = NULL, fix, ++ rmask = 0, gmask = 0, bmask = 0, amask = 0; ++ int right_way_up = 0; ++ unsigned char r, g, b, a; ++ int fsize = 0; ++ unsigned int bmpsize; ++ unsigned short res1, res2; ++ ++ f = fopen(file, "rb"); ++ if (!f) ++ { ++ *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; ++ return EINA_FALSE; ++ } ++ ++ *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; ++ fseek(f, 0, SEEK_END); ++ fsize = ftell(f); ++ fseek(f, 0, SEEK_SET); ++ if (fsize < 2) goto close_file; ++ ++ if (fread(buf, 2, 1, f) != 1) goto close_file; ++ if (strncmp(buf, "BM", 2)) goto close_file; // magic number ++ *error = EVAS_LOAD_ERROR_CORRUPT_FILE; ++ if (!read_int(f, &bmpsize)) goto close_file; ++ if (!read_short(f, &res1)) goto close_file; ++ if (!read_short(f, &res2)) goto close_file; ++ if (!read_int(f, &offset)) goto close_file; ++ if (!read_int(f, &head_size)) goto close_file; ++ image_size = fsize - offset; ++ if (image_size < 1) goto close_file; ++ ++ if (head_size == 12) // OS/2 V1 + Windows 3.0 ++ { ++ short tmp; ++ ++ if (!read_short(f, &tmp)) goto close_file; ++ w = tmp; // width ++ if (!read_short(f, &tmp)) goto close_file; ++ h = tmp; // height ++ if (!read_short(f, &tmp)) goto close_file; ++ planes = tmp; // must be 1 ++ if (!read_short(f, &tmp)) goto close_file; ++ bit_count = tmp; // bits per pixel: 1, 4, 8 & 24 ++ } ++ else if (head_size == 64) // OS/2 V2 ++ { ++ short tmp; ++ int tmp2; ++ ++ if (!read_int(f, &tmp2)) goto close_file; ++ w = tmp2; // width ++ if (!read_int(f, &tmp2)) goto close_file; ++ h = tmp2; // height ++ if (!read_short(f, &tmp)) goto close_file; ++ planes = tmp; // must be 1 ++ if (!read_short(f, &tmp)) goto close_file; ++ bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 ++ if (!read_int(f, &tmp2)) goto close_file; ++ comp = tmp2; // compression method ++ if (!read_int(f, &tmp2)) goto close_file; ++ image_size = tmp2; // bitmap data size ++ if (!read_int(f, &tmp2)) goto close_file; ++ hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter ++ if (!read_int(f, &tmp2)) goto close_file; ++ vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter ++ if (!read_int(f, &tmp2)) goto close_file; ++ palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) ++ if (!read_int(f, &tmp2)) goto close_file; ++ important_colors = tmp2; // number of important colors - 0 if all ++ if (fread(buf, 24, 1, f) != 1) goto close_file; // skip unused header ++ if (image_size == 0) image_size = fsize - offset; ++ } ++ else if (head_size == 40) // Windows 3.0 + (v3) ++ { ++ short tmp; ++ int tmp2; ++ ++ if (!read_int(f, &tmp2)) goto close_file; ++ w = tmp2; // width ++ if (!read_int(f, &tmp2)) goto close_file; ++ h = tmp2; // height ++ if (!read_short(f, &tmp)) goto close_file; ++ planes = tmp; // must be 1 ++ if (!read_short(f, &tmp)) goto close_file; ++ bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 ++ if (!read_int(f, &tmp2)) goto close_file; ++ comp = tmp2; // compression method ++ if (!read_int(f, &tmp2)) goto close_file; ++ image_size = tmp2; // bitmap data size ++ if (!read_int(f, &tmp2)) goto close_file; ++ hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter ++ if (!read_int(f, &tmp2)) goto close_file; ++ vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter ++ if (!read_int(f, &tmp2)) goto close_file; ++ palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) ++ if (!read_int(f, &tmp2)) goto close_file; ++ important_colors = tmp2; // number of important colors - 0 if all ++ if (image_size == 0) image_size = fsize - offset; ++ } ++ else if (head_size == 108) // Windows 95/NT4 + (v4) ++ { ++ short tmp; ++ int tmp2; ++ ++ if (!read_int(f, &tmp2)) goto close_file; ++ w = tmp2; // width ++ if (!read_int(f, &tmp2)) goto close_file; ++ h = tmp2; // height ++ if (!read_short(f, &tmp)) goto close_file; ++ planes = tmp; // must be 1 ++ if (!read_short(f, &tmp)) goto close_file; ++ bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 ++ if (!read_int(f, &tmp2)) goto close_file; ++ comp = tmp2; // compression method ++ if (!read_int(f, &tmp2)) goto close_file; ++ image_size = tmp2; // bitmap data size ++ if (!read_int(f, &tmp2)) goto close_file; ++ hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter ++ if (!read_int(f, &tmp2)) goto close_file; ++ vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter ++ if (!read_int(f, &tmp2)) goto close_file; ++ palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) ++ if (!read_int(f, &tmp2)) goto close_file; ++ important_colors = tmp2; // number of important colors - 0 if all ++ if (!read_int(f, &tmp2)) goto close_file; ++ rmask = tmp2; // red mask ++ if (!read_int(f, &tmp2)) goto close_file; ++ gmask = tmp2; // green mask ++ if (!read_int(f, &tmp2)) goto close_file; ++ bmask = tmp2; // blue mask ++ if (!read_int(f, &tmp2)) goto close_file; ++ amask = tmp2; // alpha mask ++ if (fread(buf, 36, 1, f) != 1) goto close_file; // skip unused cie ++ if (fread(buf, 12, 1, f) != 1) goto close_file; // skip unused gamma ++ if (image_size == 0) image_size = fsize - offset; ++ if ((amask) && (bit_count == 32)) hasa = 1; ++ } ++ else if (head_size == 124) // Windows 98/2000 + (v5) ++ { ++ short tmp; ++ int tmp2; ++ ++ if (!read_int(f, &tmp2)) goto close_file; ++ w = tmp2; // width ++ if (!read_int(f, &tmp2)) goto close_file; ++ h = tmp2; // height ++ if (!read_short(f, &tmp)) goto close_file; ++ planes = tmp; // must be 1 ++ if (!read_short(f, &tmp)) goto close_file; ++ bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 ++ if (!read_int(f, &tmp2)) goto close_file; ++ comp = tmp2; // compression method ++ if (!read_int(f, &tmp2)) goto close_file; ++ image_size = tmp2; // bitmap data size ++ if (!read_int(f, &tmp2)) goto close_file; ++ hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter ++ if (!read_int(f, &tmp2)) goto close_file; ++ vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter ++ if (!read_int(f, &tmp2)) goto close_file; ++ palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) ++ if (!read_int(f, &tmp2)) goto close_file; ++ important_colors = tmp2; // number of important colors - 0 if all ++ if (!read_int(f, &tmp2)) goto close_file; ++ rmask = tmp2; // red mask ++ if (!read_int(f, &tmp2)) goto close_file; ++ gmask = tmp2; // green mask ++ if (!read_int(f, &tmp2)) goto close_file; ++ bmask = tmp2; // blue mask ++ if (!read_int(f, &tmp2)) goto close_file; ++ amask = tmp2; // alpha mask ++ if (fread(buf, 36, 1, f) != 1) goto close_file; // skip unused cie ++ if (fread(buf, 12, 1, f) != 1) goto close_file; // skip unused gamma ++ if (fread(buf, 16, 1, f) != 1) goto close_file; // skip others ++ if (image_size == 0) image_size = fsize - offset; ++ if ((amask) && (bit_count == 32)) hasa = 1; ++ } ++ else ++ goto close_file; ++ ++ if (h < 0) ++ { ++ h = -h; ++ right_way_up = 1; ++ } ++ if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) || ++ IMG_TOO_BIG(w, h)) ++ { ++ if (IMG_TOO_BIG(w, h)) ++ *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; ++ else ++ *error = EVAS_LOAD_ERROR_GENERIC; ++ goto close_file; ++ } ++ ++ if ((w != ie->w) || (h != ie->h)) ++ { ++ *error = EVAS_LOAD_ERROR_GENERIC; ++ goto close_file; ++ } ++ evas_cache_image_surface_alloc(ie, w, h); ++ surface = evas_cache_image_pixels(ie); ++ if (!surface) ++ { ++ *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; ++ goto close_file; ++ } ++ ++ if (bit_count < 16) ++ { ++ int i; ++ ++ if (bit_count == 1) ++ { ++ if ((palette_size <= 0) || (palette_size > 2)) pal_num = 2; ++ else pal_num = palette_size; ++ } ++ else if (bit_count == 4) ++ { ++ if ((palette_size <= 0) || (palette_size > 16)) pal_num = 16; ++ else pal_num = palette_size; ++ } ++ else if (bit_count == 8) ++ { ++ if ((palette_size <= 0) || (palette_size > 256)) pal_num = 256; ++ else pal_num = palette_size; ++ } ++ pal = alloca(256 * 4); ++ for (i = 0; i < pal_num; i++) ++ { ++ if (fread(&b, 1, 1, f) != 1) goto close_file; ++ if (fread(&g, 1, 1, f) != 1) goto close_file; ++ if (fread(&r, 1, 1, f) != 1) goto close_file; ++ if ((head_size != 12) /*&& (palette_size != 0)*/) ++ { // OS/2 V1 doesnt do the pad byte ++ if (fread(&a, 1, 1, f) != 1) goto close_file; ++ } ++ a = 0xff; // fillin a as solid for paletted images ++ pal[i] = (a << 24) | (r << 16) | (g << 8) | b; ++ } ++ fseek(f, offset, SEEK_SET); ++ buffer = malloc(image_size + 8); // add 8 for padding to avoid checks ++ if (!buffer) ++ { ++ *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; ++ goto close_file; ++ } ++ buffer_end = buffer + image_size; ++ p = buffer; ++ if (fread(buffer, image_size, 1, f) != 1) goto close_file; ++ ++ if (bit_count == 1) ++ { ++ if (comp == 0) // no compression ++ { ++ pix = surface; ++ for (y = 0; y < h; y++) ++ { ++ if (!right_way_up) pix = surface + ((h - 1 - y) * w); ++ for (x = 0; x < w; x++) ++ { ++ if ((x & 0x7) == 0x0) ++ { ++ *pix = pal[*p >> 7]; ++ } ++ else if ((x & 0x7) == 0x1) ++ { ++ *pix = pal[(*p >> 6) & 0x1]; ++ } ++ else if ((x & 0x7) == 0x2) ++ { ++ *pix = pal[(*p >> 5) & 0x1]; ++ } ++ else if ((x & 0x7) == 0x3) ++ { ++ *pix = pal[(*p >> 4) & 0x1]; ++ } ++ else if ((x & 0x7) == 0x4) ++ { ++ *pix = pal[(*p >> 3) & 0x1]; ++ } ++ else if ((x & 0x7) == 0x5) ++ { ++ *pix = pal[(*p >> 2) & 0x1]; ++ } ++ else if ((x & 0x7) == 0x6) ++ { ++ *pix = pal[(*p >> 1) & 0x1]; ++ } ++ else ++ { ++ *pix = pal[*p & 0x1]; ++ p++; ++ } ++ if (p >= buffer_end) break; ++ pix++; ++ } ++ if ((x & 0x7) != 0) p++; ++ fix = (int)(((unsigned long)p) & 0x3); ++ if (fix > 0) p += 4 - fix; // align row read ++ if (p >= buffer_end) break; ++ } ++ } ++ else ++ goto close_file; ++ } ++ else if (bit_count == 4) ++ { ++ if (comp == 0) // no compression ++ { ++ pix = surface; ++ for (y = 0; y < h; y++) ++ { ++ if (!right_way_up) pix = surface + ((h - 1 - y) * w); ++ for (x = 0; x < w; x++) ++ { ++ if ((x & 0x1) == 0x1) ++ { ++ *pix = pal[*p & 0x0f]; ++ p++; ++ } ++ else ++ { ++ *pix = pal[*p >> 4]; ++ } ++ if (p >= buffer_end) break; ++ pix++; ++ } ++ if ((x & 0x1) != 0) p++; ++ fix = (int)(((unsigned long)p) & 0x3); ++ if (fix > 0) p += 4 - fix; // align row read ++ if (p >= buffer_end) break; ++ } ++ } ++ else if (comp == 2) // rle 4bit/pixel ++ { ++ int count = 0, done = 0, wpad; ++ ++ pix = surface; ++ if (!right_way_up) pix = surface + ((h - 1 - y) * w); ++ wpad = ((w + 1) / 2) * 2; ++ while (p < buffer_end) ++ { ++ if (p[0]) ++ { ++ unsigned int col1 = pal[p[1] >> 4]; ++ unsigned int col2 = pal[p[1] & 0xf]; ++ ++ if ((x + p[0]) > wpad) break; ++ count = p[0] / 2; ++ while (count > 0) ++ { ++ if (x < w) ++ { ++ pix[0] = col1; ++ x++; ++ } ++ if (x < w) ++ { ++ pix[1] = col2; ++ x++; ++ } ++ pix += 2; ++ count--; ++ } ++ if (p[0] & 0x1) ++ { ++ *pix = col1; ++ x++; ++ pix++; ++ } ++ p += 2; ++ } ++ else ++ { ++ switch (p[1]) ++ { ++ case 0: // EOL ++ x = 0; ++ y++; ++ if (!right_way_up) ++ pix = surface + ((h - 1 - y) * w); ++ else ++ pix = surface + (y * w); ++ if (y >= h) ++ { ++ p = buffer_end; ++ } ++ p += 2; ++ break; ++ case 1: // EOB ++ p = buffer_end; ++ break; ++ case 2: // DELTA ++ x += p[2]; ++ y += p[3]; ++ if ((x >= w) || (y >= h)) ++ { ++ p = buffer_end; ++ } ++ if (!right_way_up) ++ pix = surface + x + ((h - 1 - y) * w); ++ else ++ pix = surface + x + (y * w); ++ p += 4; ++ break; ++ default: ++ count = p[1]; ++ if (((p + count) > buffer_end) || ++ ((x + count) > w)) ++ { ++ p = buffer_end; ++ break; ++ } ++ p += 2; ++ done = count; ++ count /= 2; ++ while (count > 0) ++ { ++ pix[0] = pal[*p >> 4]; ++ pix[1] = pal[*p & 0xf]; ++ pix += 2; ++ p++; ++ count--; ++ } ++ x += done; ++ if (done & 0x1) ++ { ++ *pix = pal[*p >> 4]; ++ p++; ++ } ++ if ((done & 0x3) == 0x1) ++ p += 2; ++ else if ((done & 0x3) == 0x2) ++ p += 1; ++ break; ++ } ++ } ++ } ++ } ++ else ++ goto close_file; ++ } ++ else if (bit_count == 8) ++ { ++ if (comp == 0) // no compression ++ { ++ pix = surface; ++ for (y = 0; y < h; y++) ++ { ++ if (!right_way_up) pix = surface + ((h - 1 - y) * w); ++ for (x = 0; x < w; x++) ++ { ++ *pix = pal[*p]; ++ p++; ++ if (p >= buffer_end) break; ++ pix++; ++ } ++ fix = (int)(((unsigned long)p) & 0x3); ++ if (fix > 0) p += 4 - fix; // align row read ++ if (p >= buffer_end) break; ++ } ++ } ++ else if (comp == 1) // rle 8bit/pixel ++ { ++ int count = 0, done = 0; ++ ++ pix = surface; ++ if (!right_way_up) pix = surface + ((h - 1 - y) * w); ++ while (p < buffer_end) ++ { ++ if (p[0]) ++ { ++ unsigned int col = pal[p[1]]; ++ ++ count = p[0]; ++ if ((x + p[0]) > w) break; ++ while (count > 0) ++ { ++ *pix = col; ++ pix++; ++ count--; ++ } ++ x += p[0]; ++ p += 2; ++ } ++ else ++ { ++ switch (p[1]) ++ { ++ case 0: // EOL ++ x = 0; ++ y++; ++ if (!right_way_up) ++ pix = surface + ((h - 1 - y) * w); ++ else ++ pix = surface + (y * w); ++ if (y >= h) ++ { ++ p = buffer_end; ++ } ++ p += 2; ++ break; ++ case 1: // EOB ++ p = buffer_end; ++ break; ++ case 2: // DELTA ++ x += p[2]; ++ y += p[3]; ++ if ((x >= w) || (y >= h)) ++ { ++ p = buffer_end; ++ } ++ if (!right_way_up) ++ pix = surface + x + ((h - 1 - y) * w); ++ else ++ pix = surface + x + (y * w); ++ p += 4; ++ break; ++ default: ++ count = p[1]; ++ if (((p + count) > buffer_end) || ++ ((x + count) > w)) ++ { ++ p = buffer_end; ++ break; ++ } ++ p += 2; ++ done = count; ++ while (count > 0) ++ { ++ *pix = pal[*p]; ++ pix++; ++ p++; ++ count--; ++ } ++ x += done; ++ if (done & 0x1) p++; ++ break; ++ } ++ } ++ } ++ } ++ else ++ goto close_file; ++ } ++ } ++ else if ((bit_count == 16) || (bit_count == 24) || (bit_count == 32)) ++ { ++ if (comp == 0) // no compression ++ { ++ fseek(f, offset, SEEK_SET); ++ buffer = malloc(image_size + 8); // add 8 for padding to avoid checks ++ if (!buffer) ++ { ++ *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; ++ goto close_file; ++ } ++ buffer_end = buffer + image_size; ++ p = buffer; ++ if (fread(buffer, image_size, 1, f) != 1) goto close_file; ++ if (bit_count == 16) ++ { ++ unsigned short tmp; ++ ++ pix = surface; ++ for (y = 0; y < h; y++) ++ { ++ if (!right_way_up) pix = surface + ((h - 1 - y) * w); ++ for (x = 0; x < w; x++) ++ { ++ tmp = *((unsigned short *)(p)); ++ ++ r = (tmp >> 7) & 0xf8; r |= r >> 5; ++ g = (tmp >> 2) & 0xf8; g |= g >> 5; ++ b = (tmp << 3) & 0xf8; b |= b >> 5; ++ *pix = 0xff000000 | (r << 16) | (g << 8) | (b); ++ p += 2; ++ if (p >= buffer_end) break; ++ pix++; ++ } ++ fix = (int)(((unsigned long)p) & 0x3); ++ if (fix > 0) p += 4 - fix; // align row read ++ if (p >= buffer_end) break; ++ } ++ } ++ else if (bit_count == 24) ++ { ++ pix = surface; ++ for (y = 0; y < h; y++) ++ { ++ if (!right_way_up) pix = surface + ((h - 1 - y) * w); ++ for (x = 0; x < w; x++) ++ { ++ b = p[0]; ++ g = p[1]; ++ r = p[2]; ++ *pix = 0xff000000 | (r << 16) | (g << 8) | (b); ++ p += 3; ++ if (p >= buffer_end) break; ++ pix++; ++ } ++ fix = (int)(((unsigned long)p) & 0x3); ++ if (fix > 0) p += 4 - fix; // align row read ++ if (p >= buffer_end) break; ++ } ++ } ++ else if (bit_count == 32) ++ { ++ pix = surface; ++ for (y = 0; y < h; y++) ++ { ++ if (!right_way_up) pix = surface + ((h - 1 - y) * w); ++ for (x = 0; x < w; x++) ++ { ++ b = p[0]; ++ g = p[1]; ++ r = p[2]; ++ a = p[3]; ++ if (!hasa) a = 0xff; ++ *pix = (a << 24) | (r << 16) | (g << 8) | (b); ++ p += 4; ++ if (p >= buffer_end) break; ++ pix++; ++ } ++ fix = (int)(((unsigned long)p) & 0x3); ++ if (fix > 0) p += 4 - fix; // align row read ++ if (p >= buffer_end) break; ++ } ++ } ++ else ++ goto close_file; ++ } ++ else if (comp == 3) // bit field ++ { ++ if (!read_int(f, &rmask)) goto close_file; ++ if (!read_int(f, &gmask)) goto close_file; ++ if (!read_int(f, &bmask)) goto close_file; ++ ++ fseek(f, offset, SEEK_SET); ++ buffer = malloc(image_size + 8); // add 8 for padding to avoid checks ++ if (!buffer) ++ { ++ *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; ++ goto close_file; ++ } ++ buffer_end = buffer + image_size; ++ p = buffer; ++ if (fread(buffer, image_size, 1, f) != 1) goto close_file; ++ if ((bit_count == 16) && ++ (rmask == 0xf800) && (gmask == 0x07e0) && (bmask == 0x001f) ++ ) ++ { ++ unsigned short tmp; ++ ++ pix = surface; ++ for (y = 0; y < h; y++) ++ { ++ if (!right_way_up) pix = surface + ((h - 1 - y) * w); ++ for (x = 0; x < w; x++) ++ { ++ tmp = *((unsigned short *)(p)); ++ ++ r = (tmp >> 8) & 0xf8; r |= r >> 5; ++ g = (tmp >> 3) & 0xfc; g |= g >> 6; ++ b = (tmp << 3) & 0xf8; b |= b >> 5; ++ *pix = 0xff000000 | (r << 16) | (g << 8) | (b); ++ p += 2; ++ if (p >= buffer_end) break; ++ pix++; ++ } ++ fix = (int)(((unsigned long)p) & 0x3); ++ if (fix > 0) p += 4 - fix; // align row read ++ if (p >= buffer_end) break; ++ } ++ } ++ else if ((bit_count == 16) && ++ (rmask == 0x7c00) && (gmask == 0x03e0) && (bmask == 0x001f) ++ ) ++ { ++ unsigned short tmp; ++ ++ pix = surface; ++ for (y = 0; y < h; y++) ++ { ++ if (!right_way_up) pix = surface + ((h - 1 - y) * w); ++ for (x = 0; x < w; x++) ++ { ++ tmp = *((unsigned short *)(p)); ++ ++ r = (tmp >> 7) & 0xf8; r |= r >> 5; ++ g = (tmp >> 2) & 0xf8; g |= g >> 5; ++ b = (tmp << 3) & 0xf8; b |= b >> 5; ++ *pix = 0xff000000 | (r << 16) | (g << 8) | (b); ++ p += 2; ++ if (p >= buffer_end) break; ++ pix++; ++ } ++ fix = (int)(((unsigned long)p) & 0x3); ++ if (fix > 0) p += 4 - fix; // align row read ++ if (p >= buffer_end) break; ++ } ++ } ++ else if (bit_count == 32) ++ { ++ pix = surface; ++ for (y = 0; y < h; y++) ++ { ++ if (!right_way_up) pix = surface + ((h - 1 - y) * w); ++ for (x = 0; x < w; x++) ++ { ++ b = p[0]; ++ g = p[1]; ++ r = p[2]; ++ a = p[3]; ++ if (!hasa) a = 0xff; ++ *pix = (a << 24) | (r << 16) | (g << 8) | (b); ++ p += 4; ++ if (p >= buffer_end) break; ++ pix++; ++ } ++ fix = (int)(((unsigned long)p) & 0x3); ++ if (fix > 0) p += 4 - fix; // align row read ++ if (p >= buffer_end) break; ++ } ++ } ++ else ++ goto close_file; ++ } ++ else if (comp == 4) // jpeg - only printer drivers ++ { ++ goto close_file; ++ } ++ else if (comp == 3) // png - only printer drivers ++ { ++ goto close_file; ++ } ++ else ++ goto close_file; ++ } ++ else ++ goto close_file; ++ ++ if (buffer) free(buffer); ++ fclose(f); ++ ++ evas_common_image_premul(ie); ++ *error = EVAS_LOAD_ERROR_NONE; ++ return EINA_TRUE; ++ ++ close_file: ++ if (buffer) free(buffer); ++ fclose(f); ++ return EINA_FALSE; ++} ++ ++static int ++module_open(Evas_Module *em) ++{ ++ if (!em) return 0; ++ em->functions = (void *)(&evas_image_load_bmp_func); ++ return 1; ++} ++ ++static void ++module_close(Evas_Module *em) ++{ ++} ++ ++static Evas_Module_Api evas_modapi = ++{ ++ EVAS_MODULE_API_VERSION, ++ "bmp", ++ "none", ++ { ++ module_open, ++ module_close ++ } ++}; ++ ++EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_IMAGE_LOADER, image_loader, bmp); ++ ++#ifndef EVAS_STATIC_BUILD_BMP ++EVAS_EINA_MODULE_DEFINE(image_loader, bmp); ++#endif diff --cc src/modules/loaders/png/evas_image_load_png.c index 97d0d7a,78216e7..6b480f0 mode 100755,100644..100755 --- a/src/modules/loaders/png/evas_image_load_png.c +++ b/src/modules/loaders/png/evas_image_load_png.c