DELETED Android_R4.2.0.mk Index: Android_R4.2.0.mk ================================================================== --- Android_R4.2.0.mk +++ Android_R4.2.0.mk @@ -1,50 +0,0 @@ -# ------------------- -# Android_R4.2.0.mk -# ndk-build clean -# ndk-build -# ------------------- -LOCAL_PATH := $(call my-dir) -JSQLITE_PATH := javasqlite-20120209 -SPATIALITE_PATH := libspatialite-4.2.0-rc1 -GEOS_PATH := geos-3.4.2 -PROJ4_PATH := proj-4.8.0 -SQLITE_PATH := sqlite-amalgamation-3080403 -ICONV_PATH := libiconv-1.13.1 -RASTERLITE2_PATH := librasterlite2-4.2.0 -GEOTIFF_PATH := libgeotiff-1.4.0 -TIFF_PATH := tiff-4.0.3/libtiff -JPEG_PATH := jpeg-8d -GIF_PATH := giflib-5.0.6/lib -CAIRO_PATH := cairo-1.12.14/src -FREETYPE_PATH := freetype-2.5.3 -FONTCONFIG_PATH := fontconfig-2.11.1 -EXPAT_PATH := expat-2.1.0 -PIXMAN_PATH := pixman-0.32.4 -PNG_PATH := libpng-1.6.10 -WEBP_PATH := libwebp-0.4.0 -XML2_PATH := libxml2-2.9.1 -CURL_PATH := curl-7.36.0 -LZMA_PATH := xz-5.1.3alpha - -include $(LOCAL_PATH)/jsqlite-R4.2.0.mk -include $(LOCAL_PATH)/iconv-1.13.1.mk -include $(LOCAL_PATH)/sqlite-3080403.mk -include $(LOCAL_PATH)/proj4-4.8.0.mk -include $(LOCAL_PATH)/geos-3.4.2.mk -include $(LOCAL_PATH)/spatialite-4.2.0.mk -include $(LOCAL_PATH)/libjpeg-8d.mk -include $(LOCAL_PATH)/giflib-5.0.6.mk -include $(LOCAL_PATH)/libpng-1.6.10.mk -include $(LOCAL_PATH)/libtiff-4.0.3.mk -include $(LOCAL_PATH)/libwebp-0.4.0.mk -include $(LOCAL_PATH)/pixman-0.32.4.mk -include $(LOCAL_PATH)/freetype-2.5.3.mk -include $(LOCAL_PATH)/fontconfig-2.11.1.mk -include $(LOCAL_PATH)/expat-2.1.0.mk -include $(LOCAL_PATH)/cairo-1.12.14.mk -include $(LOCAL_PATH)/libgeotiff-1.4.0.mk -include $(LOCAL_PATH)/libxml2-2.9.1.mk -include $(LOCAL_PATH)/libcurl-7.36.0.mk -include $(LOCAL_PATH)/lzma-xz-5.1.3a.mk -include $(LOCAL_PATH)/rasterlite2-4.2.0.mk -$(call import-module,android/cpufeatures) ADDED Android_R4.3.0.mk Index: Android_R4.3.0.mk ================================================================== --- Android_R4.3.0.mk +++ Android_R4.3.0.mk @@ -0,0 +1,54 @@ +# ------------------- +# Android_R4.3.0.mk +# ndk-build clean +# ndk-build +# ------------------- +LOCAL_PATH := $(call my-dir) +JSQLITE_PATH := javasqlite-20120209 +SPATIALITE_PATH := libspatialite-4.3.0 +GEOS_PATH := geos-3.4.2 +PROJ4_PATH := proj-4.9.1 +SQLITE_PATH := sqlite-amalgamation-3081002 +ICONV_PATH := libiconv-1.13.1 +RASTERLITE2_PATH := librasterlite2-4.3.0 +GEOTIFF_PATH := libgeotiff-1.4.0 +TIFF_PATH := tiff-4.0.3/libtiff +JPEG_PATH := jpeg-8d +GIF_PATH := giflib-5.0.6/lib +CAIRO_PATH := cairo-1.12.14/src +FREETYPE_PATH := freetype-2.5.3 +FONTCONFIG_PATH := fontconfig-2.11.1 +EXPAT_PATH := expat-2.1.0 +PIXMAN_PATH := pixman-0.32.4 +PNG_PATH := libpng-1.6.10 +WEBP_PATH := libwebp-0.4.0 +XML2_PATH := libxml2-2.9.1 +CURL_PATH := curl-7.36.0 +LZMA_PATH := xz-5.1.3alpha +CHARLS_PATH := charls-1.0 +OPENJPEG_PATH := openjpeg-2.0.0 + +include $(LOCAL_PATH)/charls-1.0.mk +include $(LOCAL_PATH)/jsqlite-R4.2.0.mk +include $(LOCAL_PATH)/iconv-1.13.1.mk +include $(LOCAL_PATH)/sqlite-3081002.mk +include $(LOCAL_PATH)/proj4-4.9.1.mk +include $(LOCAL_PATH)/geos-3.4.2.mk +include $(LOCAL_PATH)/spatialite-4.3.0.mk +include $(LOCAL_PATH)/libjpeg-8d.mk +include $(LOCAL_PATH)/openjpeg-2.0.0.mk +include $(LOCAL_PATH)/giflib-5.0.6.mk +include $(LOCAL_PATH)/libpng-1.6.10.mk +include $(LOCAL_PATH)/libtiff-4.0.3.mk +include $(LOCAL_PATH)/libwebp-0.4.0.mk +include $(LOCAL_PATH)/pixman-0.32.4.mk +include $(LOCAL_PATH)/freetype-2.5.3.mk +include $(LOCAL_PATH)/fontconfig-2.11.1.mk +include $(LOCAL_PATH)/expat-2.1.0.mk +include $(LOCAL_PATH)/cairo-1.12.14.mk +include $(LOCAL_PATH)/libgeotiff-1.4.0.mk +include $(LOCAL_PATH)/libxml2-2.9.1.mk +include $(LOCAL_PATH)/libcurl-7.36.0.mk +include $(LOCAL_PATH)/lzma-xz-5.1.3a.mk +include $(LOCAL_PATH)/rasterlite2-4.3.0.mk +$(call import-module,android/cpufeatures) Index: Makefile-static-MinGW ================================================================== --- Makefile-static-MinGW +++ Makefile-static-MinGW @@ -11,11 +11,11 @@ ./static_bin/rl2sniff.exe: ./tools/rl2sniff.o $(GG) ./tools/rl2sniff.o -o ./static_bin/rl2sniff.exe \ /usr/local/lib/librasterlite2.a \ /usr/local/lib/libspatialite.a \ /usr/local/lib/libsqlite3.a \ - /usr/local/lib/liblwgeom.a \ + /usr/local/lib/librttopo.a \ /usr/local/lib/libproj.a \ /usr/local/lib/libgeos_c.a \ /usr/local/lib/libgeos.a \ /usr/local/lib/libfreexl.a \ /usr/local/lib/libcairo.a \ @@ -44,11 +44,11 @@ ./static_bin/rl2tool.exe: ./tools/rl2tool.o $(GG) ./tools/rl2tool.o -o ./static_bin/rl2tool.exe \ /usr/local/lib/librasterlite2.a \ /usr/local/lib/libspatialite.a \ /usr/local/lib/libsqlite3.a \ - /usr/local/lib/liblwgeom.a \ + /usr/local/lib/librttopo.a \ /usr/local/lib/libproj.a \ /usr/local/lib/libgeos_c.a \ /usr/local/lib/libgeos.a \ /usr/local/lib/libfreexl.a \ /usr/local/lib/libcairo.a \ @@ -77,11 +77,11 @@ ./static_bin/wmslite.exe: ./tools/wmslite.o $(GG) ./tools/wmslite.o -o ./static_bin/wmslite.exe \ /usr/local/lib/librasterlite2.a \ /usr/local/lib/libspatialite.a \ /usr/local/lib/libsqlite3.a \ - /usr/local/lib/liblwgeom.a \ + /usr/local/lib/librttopo.a \ /usr/local/lib/libproj.a \ /usr/local/lib/libgeos_c.a \ /usr/local/lib/libgeos.a \ /usr/local/lib/libfreexl.a \ /usr/local/lib/libcairo.a \ Index: Makefile.am ================================================================== --- Makefile.am +++ Makefile.am @@ -1,20 +1,21 @@ ACLOCAL_AMFLAGS = -I m4 SUBDIRS = headers src test tools -EXTRA_DIST = mainpage.doxy Android_R4.2.0.mk rasterlite2-4.2.0.mk \ +EXTRA_DIST = mainpage.doxy Android_R4.3.0.mk rasterlite2-4.3.0.mk \ Makefile-static-MinGW -AUTOMAKE_OPTIONS = dist-zip +AUTOMAKE_OPTIONS = dist-zip foreign pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = rasterlite2.pc coverage-init: lcov --directory src --capture --initial --output-file rasterlite2_cov.info coverage:: lcov --rc lcov_branch_coverage=1 --directory src --output-file rasterlite2_cov.info --capture + lcov --rc lcov_branch_coverage=1 --remove rasterlite2_cov.info "*include/*" --output-file rasterlite2_cov.info genhtml --rc lcov_branch_coverage=1 -o covresults rasterlite2_cov.info MOSTLYCLEANFILES = rasterlite2_cov.info Index: Makefile.in ================================================================== --- Makefile.in +++ Makefile.in @@ -1,9 +1,9 @@ -# Makefile.in generated by automake 1.14.1 from Makefile.am. +# Makefile.in generated by automake 1.15 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2013 Free Software Foundation, Inc. +# Copyright (C) 1994-2014 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -13,11 +13,21 @@ # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ @@ -77,23 +87,19 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ subdir = . -DIST_COMMON = INSTALL NEWS README AUTHORS ChangeLog \ - $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ - $(top_srcdir)/configure $(am__configure_deps) \ - $(srcdir)/config.h.in $(srcdir)/Doxyfile.in \ - $(srcdir)/rasterlite2.pc.in COPYING compile config.guess \ - config.sub depcomp install-sh missing ltmain.sh ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \ + $(am__configure_deps) $(am__DIST_COMMON) am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ configure.lineno config.status.lineno mkinstalldirs = $(install_sh) -d CONFIG_HEADER = config.h CONFIG_CLEAN_FILES = Doxyfile rasterlite2.pc @@ -182,10 +188,14 @@ done | $(am__uniquify_input)` ETAGS = etags CTAGS = ctags CSCOPE = cscope DIST_SUBDIRS = $(SUBDIRS) +am__DIST_COMMON = $(srcdir)/Doxyfile.in $(srcdir)/Makefile.in \ + $(srcdir)/config.h.in $(srcdir)/rasterlite2.pc.in AUTHORS \ + COPYING ChangeLog INSTALL NEWS README compile config.guess \ + config.sub depcomp install-sh ltmain.sh missing DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) top_distdir = $(distdir) am__remove_distdir = \ if test -d "$(distdir)"; then \ @@ -368,14 +378,14 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ ACLOCAL_AMFLAGS = -I m4 SUBDIRS = headers src test tools -EXTRA_DIST = mainpage.doxy Android_R4.2.0.mk rasterlite2-4.2.0.mk \ +EXTRA_DIST = mainpage.doxy Android_R4.3.0.mk rasterlite2-4.3.0.mk \ Makefile-static-MinGW -AUTOMAKE_OPTIONS = dist-zip +AUTOMAKE_OPTIONS = dist-zip foreign pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = rasterlite2.pc MOSTLYCLEANFILES = rasterlite2_cov.info all: config.h $(MAKE) $(AM_MAKEFLAGS) all-recursive @@ -385,20 +395,19 @@ @: $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ - echo ' cd $(srcdir) && $(AUTOMAKE) --gnu'; \ - $(am__cd) $(srcdir) && $(AUTOMAKE) --gnu \ + echo ' cd $(srcdir) && $(AUTOMAKE) --foreign'; \ + $(am__cd) $(srcdir) && $(AUTOMAKE) --foreign \ && exit 0; \ exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu Makefile'; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \ $(am__cd) $(top_srcdir) && \ - $(AUTOMAKE) --gnu Makefile -.PRECIOUS: Makefile + $(AUTOMAKE) --foreign Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ echo ' $(SHELL) ./config.status'; \ $(SHELL) ./config.status;; \ @@ -650,19 +659,19 @@ dist-xz: distdir tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz $(am__post_remove_distdir) dist-tarZ: distdir - @echo WARNING: "Support for shar distribution archives is" \ - "deprecated." >&2 + @echo WARNING: "Support for distribution archives compressed with" \ + "legacy program 'compress' is deprecated." >&2 @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z $(am__post_remove_distdir) dist-shar: distdir - @echo WARNING: "Support for distribution archives compressed with" \ - "legacy program 'compress' is deprecated." >&2 + @echo WARNING: "Support for shar distribution archives is" \ + "deprecated." >&2 @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz $(am__post_remove_distdir) dist-zip: distdir -rm -f $(distdir).zip @@ -693,21 +702,21 @@ *.zip*) \ unzip $(distdir).zip ;;\ esac chmod -R a-w $(distdir) chmod u+w $(distdir) - mkdir $(distdir)/_build $(distdir)/_inst + mkdir $(distdir)/_build $(distdir)/_build/sub $(distdir)/_inst chmod a-w $(distdir) test -d $(distdir)/_build || exit 0; \ dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \ && am__cwd=`pwd` \ - && $(am__cd) $(distdir)/_build \ - && ../configure \ + && $(am__cd) $(distdir)/_build/sub \ + && ../../configure \ $(AM_DISTCHECK_CONFIGURE_FLAGS) \ $(DISTCHECK_CONFIGURE_FLAGS) \ - --srcdir=.. --prefix="$$dc_install_base" \ + --srcdir=../.. --prefix="$$dc_install_base" \ && $(MAKE) $(AM_MAKEFLAGS) \ && $(MAKE) $(AM_MAKEFLAGS) dvi \ && $(MAKE) $(AM_MAKEFLAGS) check \ && $(MAKE) $(AM_MAKEFLAGS) install \ && $(MAKE) $(AM_MAKEFLAGS) installcheck \ @@ -884,16 +893,19 @@ installcheck-am installdirs installdirs-am maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-generic \ mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ uninstall-am uninstall-pkgconfigDATA +.PRECIOUS: Makefile + coverage-init: lcov --directory src --capture --initial --output-file rasterlite2_cov.info coverage:: lcov --rc lcov_branch_coverage=1 --directory src --output-file rasterlite2_cov.info --capture + lcov --rc lcov_branch_coverage=1 --remove rasterlite2_cov.info "*include/*" --output-file rasterlite2_cov.info genhtml --rc lcov_branch_coverage=1 -o covresults rasterlite2_cov.info # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: Index: aclocal.m4 ================================================================== --- aclocal.m4 +++ aclocal.m4 @@ -1,8 +1,8 @@ -# generated automatically by aclocal 1.14.1 -*- Autoconf -*- +# generated automatically by aclocal 1.15 -*- Autoconf -*- -# Copyright (C) 1996-2013 Free Software Foundation, Inc. +# Copyright (C) 1996-2014 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -233,11 +233,11 @@ AS_VAR_COPY([$1], [pkg_cv_][$1]) AS_VAR_IF([$1], [""], [$5], [$4])dnl ])# PKG_CHECK_VAR -# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -245,14 +245,14 @@ # ---------------------------- # Automake X.Y traces this macro to ensure aclocal.m4 has been # generated from the m4 files accompanying Automake X.Y. # (This private macro should not be called outside this file.) AC_DEFUN([AM_AUTOMAKE_VERSION], -[am__api_version='1.14' +[am__api_version='1.15' dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to dnl require some minimum version. Point them to the right macro. -m4_if([$1], [1.14.1], [], +m4_if([$1], [1.15], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) # _AM_AUTOCONF_VERSION(VERSION) # ----------------------------- @@ -264,18 +264,18 @@ # AM_SET_CURRENT_AUTOMAKE_VERSION # ------------------------------- # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. # This function is AC_REQUIREd by AM_INIT_AUTOMAKE. AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], -[AM_AUTOMAKE_VERSION([1.14.1])dnl +[AM_AUTOMAKE_VERSION([1.15])dnl m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) # AM_AUX_DIR_EXPAND -*- Autoconf -*- -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -316,19 +316,18 @@ # Another solution, used here, is to always expand $ac_aux_dir to an # absolute PATH. The drawback is that using absolute paths prevent a # configured tree to be moved without reconfiguration. AC_DEFUN([AM_AUX_DIR_EXPAND], -[dnl Rely on autoconf to set up CDPATH properly. -AC_PREREQ([2.50])dnl -# expand $ac_aux_dir to an absolute path -am_aux_dir=`cd $ac_aux_dir && pwd` +[AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl +# Expand $ac_aux_dir to an absolute path. +am_aux_dir=`cd "$ac_aux_dir" && pwd` ]) # AM_CONDITIONAL -*- Autoconf -*- -# Copyright (C) 1997-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -355,11 +354,11 @@ [if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then AC_MSG_ERROR([[conditional "$1" was never defined. Usually this means the macro was only invoked conditionally.]]) fi])]) -# Copyright (C) 1999-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -546,11 +545,11 @@ _AM_SUBST_NOTMAKE([am__nodep])dnl ]) # Generate code to set up dependency tracking. -*- Autoconf -*- -# Copyright (C) 1999-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -622,11 +621,11 @@ [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"]) ]) # Do all the work for Automake. -*- Autoconf -*- -# Copyright (C) 1996-2013 Free Software Foundation, Inc. +# Copyright (C) 1996-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -712,12 +711,12 @@ # For better backward compatibility. To be removed once Automake 1.9.x # dies out for good. For more background, see: # # AC_SUBST([mkdir_p], ['$(MKDIR_P)']) -# We need awk for the "check" target. The system "awk" is bad on -# some platforms. +# We need awk for the "check" target (and possibly the TAP driver). The +# system "awk" is bad on some platforms. AC_REQUIRE([AC_PROG_AWK])dnl AC_REQUIRE([AC_PROG_MAKE_SET])dnl AC_REQUIRE([AM_SET_LEADING_DOT])dnl _AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], @@ -786,11 +785,15 @@ to "yes", and re-run configure. END AC_MSG_ERROR([Your 'rm' program is bad, sorry.]) fi -fi]) +fi +dnl The trailing newline in this macro's definition is deliberate, for +dnl backward compatibility and to allow trailing 'dnl'-style comments +dnl after the AM_INIT_AUTOMAKE invocation. See automake bug#16841. +]) dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion. Do not dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further dnl mangled by Autoconf and run in a shell conditional statement. m4_define([_AC_COMPILER_EXEEXT], @@ -815,11 +818,11 @@ _am_stamp_count=`expr $_am_stamp_count + 1` ;; esac done echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -826,21 +829,21 @@ # AM_PROG_INSTALL_SH # ------------------ # Define $install_sh. AC_DEFUN([AM_PROG_INSTALL_SH], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl -if test x"${install_sh}" != xset; then +if test x"${install_sh+set}" != xset; then case $am_aux_dir in *\ * | *\ *) install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; *) install_sh="\${SHELL} $am_aux_dir/install-sh" esac fi AC_SUBST([install_sh])]) -# Copyright (C) 2003-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -858,11 +861,11 @@ AC_SUBST([am__leading_dot])]) # Add --enable-maintainer-mode option to configure. -*- Autoconf -*- # From Jim Meyering -# Copyright (C) 1996-2013 Free Software Foundation, Inc. +# Copyright (C) 1996-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -893,11 +896,11 @@ ] ) # Check to see how 'make' treats includes. -*- Autoconf -*- -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -943,11 +946,11 @@ rm -f confinc confmf ]) # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- -# Copyright (C) 1997-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -984,11 +987,11 @@ # -*- Autoconf -*- # Obsolete and "removed" macros, that must however still report explicit # error messages when used, to smooth transition. # -# Copyright (C) 1996-2013 Free Software Foundation, Inc. +# Copyright (C) 1996-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -1011,11 +1014,11 @@ [AC_FATAL([automatic de-ANSI-fication support has been removed])]) AU_DEFUN([fp_C_PROTOTYPES], [AM_C_PROTOTYPES]) # Helper functions for option handling. -*- Autoconf -*- -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -1040,11 +1043,11 @@ # ------------------------------------------- # Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. AC_DEFUN([_AM_IF_OPTION], [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) -# Copyright (C) 1999-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -1087,11 +1090,11 @@ AC_LANG_POP([C])]) # For backward compatibility. AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])]) -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -1106,11 +1109,11 @@ echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD (exit $ac_status); }]) # Check to make sure that the build environment is sane. -*- Autoconf -*- -# Copyright (C) 1996-2013 Free Software Foundation, Inc. +# Copyright (C) 1996-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -1187,11 +1190,11 @@ fi AC_MSG_RESULT([done])]) rm -f conftest.file ]) -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -1247,11 +1250,11 @@ AM_BACKSLASH='\' AC_SUBST([AM_BACKSLASH])dnl _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl ]) -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -1275,11 +1278,11 @@ AC_CHECK_TOOL([STRIP], [strip], :) fi INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" AC_SUBST([INSTALL_STRIP_PROGRAM])]) -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -1294,11 +1297,11 @@ # Public sister of _AM_SUBST_NOTMAKE. AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) # Check how to create a tarball. -*- Autoconf -*- -# Copyright (C) 2004-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. Index: configure ================================================================== --- configure +++ configure @@ -1,8 +1,8 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for librasterlite2 1.0.0-rc1. +# Generated by GNU Autoconf 2.69 for librasterlite2 1.0.0-devel. # # Report bugs to . # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @@ -588,12 +588,12 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='librasterlite2' PACKAGE_TARNAME='librasterlite2' -PACKAGE_VERSION='1.0.0-rc1' -PACKAGE_STRING='librasterlite2 1.0.0-rc1' +PACKAGE_VERSION='1.0.0-devel' +PACKAGE_STRING='librasterlite2 1.0.0-devel' PACKAGE_BUGREPORT='a.furieri@lqt.it' PACKAGE_URL='' # Factoring default headers for most tests. ac_includes_default="\ @@ -1370,11 +1370,11 @@ # if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures librasterlite2 1.0.0-rc1 to adapt to many kinds of systems. +\`configure' configures librasterlite2 1.0.0-devel to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. @@ -1440,11 +1440,11 @@ _ACEOF fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of librasterlite2 1.0.0-rc1:";; + short | recursive ) echo "Configuration of librasterlite2 1.0.0-devel:";; esac cat <<\_ACEOF Optional Features: --disable-option-checking ignore unrecognized --enable/--with options @@ -1592,11 +1592,11 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -librasterlite2 configure 1.0.0-rc1 +librasterlite2 configure 1.0.0-devel generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. @@ -2136,11 +2136,11 @@ } # ac_fn_c_check_type cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by librasterlite2 $as_me 1.0.0-rc1, which was +It was created by librasterlite2 $as_me 1.0.0-devel, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ _ACEOF @@ -2521,11 +2521,11 @@ ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. -am__api_version='1.14' +am__api_version='1.15' # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or # incompatible versions: # SysV /etc/install, /usr/sbin/install @@ -2693,12 +2693,12 @@ # Double any \ or $. # By default was `s,x,x', remove it if useless. ac_script='s/[\\$]/&&/g;s/;s,x,x,$//' program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"` -# expand $ac_aux_dir to an absolute path -am_aux_dir=`cd $ac_aux_dir && pwd` +# Expand $ac_aux_dir to an absolute path. +am_aux_dir=`cd "$ac_aux_dir" && pwd` if test x"${MISSING+set}" != xset; then case $am_aux_dir in *\ * | *\ *) MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; @@ -2713,11 +2713,11 @@ am_missing_run= { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5 $as_echo "$as_me: WARNING: 'missing' script is too old or missing" >&2;} fi -if test x"${install_sh}" != xset; then +if test x"${install_sh+set}" != xset; then case $am_aux_dir in *\ * | *\ *) install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; *) install_sh="\${SHELL} $am_aux_dir/install-sh" @@ -3007,11 +3007,11 @@ fi # Define the identity of the package. PACKAGE='librasterlite2' - VERSION='1.0.0-rc1' + VERSION='1.0.0-devel' cat >>confdefs.h <<_ACEOF #define PACKAGE "$PACKAGE" _ACEOF @@ -3041,12 +3041,12 @@ # dies out for good. For more background, see: # # mkdir_p='$(MKDIR_P)' -# We need awk for the "check" target. The system "awk" is bad on -# some platforms. +# We need awk for the "check" target (and possibly the TAP driver). The +# system "awk" is bad on some platforms. # Always define AMTAR for backward compatibility. Yes, it's still used # in the wild :-( We should find a proper way to deprecate it ... AMTAR='$${TAR-tar}' @@ -3099,10 +3099,11 @@ END as_fn_error $? "Your 'rm' program is bad, sorry." "$LINENO" 5 fi fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 $as_echo_n "checking whether to enable maintainer-specific portions of Makefiles... " >&6; } # Check whether --enable-maintainer-mode was given. if test "${enable_maintainer_mode+set}" = set; then : @@ -19158,11 +19159,11 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Save the log message, to keep $0 and so on meaningful, and to # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by librasterlite2 $as_me 1.0.0-rc1, which was +This file was extended by librasterlite2 $as_me 1.0.0-devel, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS CONFIG_LINKS = $CONFIG_LINKS @@ -19224,11 +19225,11 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -librasterlite2 config.status 1.0.0-rc1 +librasterlite2 config.status 1.0.0-devel configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" Copyright (C) 2012 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -1,10 +1,10 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ(2.61) -AC_INIT(librasterlite2, 1.0.0-rc1, a.furieri@lqt.it) +AC_INIT(librasterlite2, 1.0.0-devel, a.furieri@lqt.it) AC_LANG(C) AC_CONFIG_AUX_DIR([.]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE Index: headers/Makefile.in ================================================================== --- headers/Makefile.in +++ headers/Makefile.in @@ -1,9 +1,9 @@ -# Makefile.in generated by automake 1.14.1 from Makefile.am. +# Makefile.in generated by automake 1.15 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2013 Free Software Foundation, Inc. +# Copyright (C) 1994-2014 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -13,11 +13,21 @@ # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ @@ -77,19 +87,19 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ subdir = headers -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ - $(nobase_include_HEADERS) $(noinst_HEADERS) ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(nobase_include_HEADERS) \ + $(noinst_HEADERS) $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = AM_V_P = $(am__v_P_@AM_V@) @@ -157,10 +167,11 @@ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` ETAGS = etags CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ @@ -323,11 +334,10 @@ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu headers/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu headers/Makefile -.PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ @@ -572,10 +582,12 @@ install-ps install-ps-am install-strip installcheck \ installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-generic \ mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ uninstall-am uninstall-nobase_includeHEADERS + +.PRECIOUS: Makefile # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: Index: headers/rasterlite2/rasterlite2.h ================================================================== --- headers/rasterlite2/rasterlite2.h +++ headers/rasterlite2/rasterlite2.h @@ -3467,19 +3467,52 @@ rl2CoveragePtr cvg, const char *sctn_name, rl2RasterPtr rst, int pyramidize); + RL2_DECLARE int rl2_load_raw_tiles_into_dbms (sqlite3 * sqlite, + rl2CoveragePtr cvg, + const char *sctn_name, + unsigned int sctn_width, + unsigned int sctn_height, + int sctn_srid, + double sctn_minx, + double sctn_miny, + double sctn_maxx, + double sctn_maxy, + int (*getTile) (void *data, + double + tile_minx, + double + tile_miny, + double + tile_maxx, + double + tile_maxy, + unsigned char + *bufpix, + rl2PalettePtr + * palette), + void *data, int pyramidize); + RL2_DECLARE int rl2_get_raw_raster_data (sqlite3 * handle, int max_threads, rl2CoveragePtr cvg, unsigned int width, unsigned int height, double minx, double miny, double maxx, double maxy, double x_res, double y_res, unsigned char **buffer, int *buf_size, rl2PalettePtr * palette, unsigned char out_pixel); + RL2_DECLARE int + rl2_get_raw_raster_mask (sqlite3 * handle, int max_threads, + rl2CoveragePtr cvg, unsigned int width, + unsigned int height, double minx, double miny, + double maxx, double maxy, double x_res, + double y_res, unsigned char **mask, + int *mask_size); + RL2_DECLARE int rl2_get_section_raw_raster_data (sqlite3 * handle, int max_threads, rl2CoveragePtr cvg, sqlite3_int64 section_id, unsigned int width, @@ -3488,10 +3521,20 @@ double x_res, double y_res, unsigned char **buffer, int *buf_size, rl2PalettePtr * palette, unsigned char out_pixel); + RL2_DECLARE int + rl2_get_section_raw_raster_mask (sqlite3 * handle, int max_threads, + rl2CoveragePtr cvg, + sqlite3_int64 section_id, + unsigned int width, + unsigned int height, double minx, + double miny, double maxx, double maxy, + double x_res, double y_res, + unsigned char **mask, int *mask_size); + RL2_DECLARE int rl2_get_triple_band_raw_raster_data (sqlite3 * handle, rl2CoveragePtr cvg, unsigned int width, unsigned int height, @@ -3675,10 +3718,15 @@ RL2_DECLARE int rl2_check_dbms_palette (sqlite3 * handle, rl2CoveragePtr cvg, rl2TiffOriginPtr tiff); + RL2_DECLARE int + rl2_install_dbms_palette_from_tiff (sqlite3 * handle, + rl2CoveragePtr cvg, + rl2TiffOriginPtr tiff); + RL2_DECLARE int rl2_serialize_dbms_pixel (rl2PixelPtr pixel, unsigned char **blob, int *blob_size); RL2_DECLARE int Index: headers/rasterlite2/rl2graphics.h ================================================================== --- headers/rasterlite2/rl2graphics.h +++ headers/rasterlite2/rl2graphics.h @@ -1341,10 +1341,31 @@ rl2GraphicsBitmapPtr bitmap, double scale_x, double scale_y, double x, double y); +/** + Rescales a raw pixbuf (RGB or GRAYSCALE) + + \param inbuf pointer to the input pixbuf. + \param inwidth the width (measured in pixels) of the input pixbuf. + \param inheight the height (measured in pixels) of the input pixbuf. + \param pixtype either RL2_PIXEL_RGB or RL2_PIXEL_GRAYSCALE. + \param outbuf pointer to the input pixbuf. + \param outwidth the width (measured in pixels) of the output pixbuf. + \param outheight the height (measured in pixels) of the output pixbuf. + + \return 0 (false) on error, any other value on success. + */ + RL2_DECLARE int rl2_rescale_pixbuf (const unsigned char *inbuf, + unsigned int inwidth, + unsigned int inheight, + unsigned char pixtype, + const unsigned char *outbuf, + unsigned int outwidth, + unsigned int outheight); + /** Creates an RGB Array corresponding to the current Canvass \param context the pointer to a valid Graphics Context (aka Canvass). Index: headers/rasterlite2/sqlite.h ================================================================== --- headers/rasterlite2/sqlite.h +++ headers/rasterlite2/sqlite.h @@ -49,7 +49,12 @@ #include extern const sqlite3_api_routines *sqlite3_api; #else /* ordinary lib */ #include #endif + +#ifndef SQLITE_DETERMINISTIC +/* probably SQLite < 3.8.3 - attempting to fix */ +#define SQLITE_DETERMINISTIC SQLITE_UTF8 +#endif #endif Index: headers/rasterlite2_private.h ================================================================== --- headers/rasterlite2_private.h +++ headers/rasterlite2_private.h @@ -1099,18 +1099,26 @@ typedef struct rl2_linestring { int points; double *coords; + double minx; + double miny; + double maxx; + double maxy; struct rl2_linestring *next; } rl2Linestring; typedef rl2Linestring *rl2LinestringPtr; typedef struct rl2_ring { int points; double *coords; + double minx; + double miny; + double maxx; + double maxy; struct rl2_ring *next; } rl2Ring; typedef rl2Ring *rl2RingPtr; typedef struct rl2_polygon @@ -1204,10 +1212,31 @@ rl2PrivPalettePtr palette; int retcode; } rl2AuxDecoder; typedef rl2AuxDecoder *rl2AuxDecoderPtr; + typedef struct rl2_aux_mask_decoder + { + void *opaque_thread_id; + sqlite3_int64 tile_id; + unsigned char *blob_odd; + int blob_odd_sz; + unsigned char *maskbuf; + unsigned int width; + unsigned int height; + double x_res; + double y_res; + int scale; + double minx; + double maxy; + double tile_minx; + double tile_maxy; + rl2PrivRasterPtr raster; + int retcode; + } rl2AuxMaskDecoder; + typedef rl2AuxMaskDecoder *rl2AuxMaskDecoderPtr; + typedef struct rl2_aux_shadower { void *opaque_thread_id; unsigned int width; unsigned int height; @@ -1255,16 +1284,16 @@ unsigned char pixel_type, unsigned char num_bands, unsigned char **pixels, int *pixels_sz); RL2_PRIVATE int - rl2_data_to_png (const unsigned char *pixels, const unsigned char *mask, - double opacity, rl2PalettePtr plt, - unsigned int width, unsigned int height, - unsigned char sample_type, unsigned char pixel_type, - unsigned char num_bands, unsigned char **compr_data, - int *compressed_size); + rl2_data_to_png (const unsigned char *pixels, + const unsigned char *mask, double opacity, + rl2PalettePtr plt, unsigned int width, + unsigned int height, unsigned char sample_type, + unsigned char pixel_type, unsigned char num_bands, + unsigned char **compr_data, int *compressed_size); RL2_PRIVATE int rl2_decode_png (const unsigned char *png, int png_sz, unsigned int *width, unsigned int *height, unsigned char *sample_type, unsigned char *pixel_type, @@ -1280,12 +1309,13 @@ RL2_PRIVATE int rl2_decode_charls (const unsigned char *charls, int charls_sz, unsigned int *width, unsigned int *height, unsigned char *sample_type, - unsigned char *pixel_type, unsigned char *num_bands, - unsigned char **pixels, int *pixels_sz); + unsigned char *pixel_type, + unsigned char *num_bands, unsigned char **pixels, + int *pixels_sz); RL2_PRIVATE int rl2_data_to_gif (const unsigned char *pixels, rl2PalettePtr plt, unsigned int width, unsigned int height, unsigned char sample_type, @@ -1345,13 +1375,13 @@ unsigned char num_bands, unsigned char auto_ndvi, unsigned char red_band_index, unsigned char nir_band_index, double x_res, double y_res, - double minx, double miny, double maxx, - double maxy, int level, int scale, - rl2PalettePtr palette, + double minx, double miny, + double maxx, double maxy, int level, + int scale, rl2PalettePtr palette, rl2PixelPtr no_data, rl2RasterSymbolizerPtr style, rl2RasterStatisticsPtr stats); RL2_PRIVATE int rl2_load_dbms_tiles_section (sqlite3 * handle, @@ -1366,12 +1396,13 @@ unsigned char num_bands, unsigned char auto_ndvi, unsigned char red_band_index, unsigned char nir_band_index, double x_res, double y_res, - double minx, double maxy, - int scale, + double minx, double miny, + double maxx, double maxy, + int level, int scale, rl2PalettePtr palette, rl2PixelPtr no_data); RL2_PRIVATE void compute_aggregate_sq_diff (rl2RasterStatisticsPtr aggreg_stats); @@ -1391,10 +1422,13 @@ RL2_PRIVATE rl2PixelPtr default_nodata (unsigned char sample, unsigned char pixel, unsigned char num_bands); + RL2_PRIVATE int + do_check_initial_palette (sqlite3 * handle, rl2CoveragePtr cvg); + RL2_PRIVATE WmsRetryListPtr alloc_retry_list (); RL2_PRIVATE void free_retry_list (WmsRetryListPtr lst); RL2_PRIVATE void add_retry (WmsRetryListPtr lst, double minx, double miny, @@ -1449,11 +1483,12 @@ RL2_PRIVATE int rl2_find_best_resolution_level (sqlite3 * handle, const char *coverage, int by_section, sqlite3_int64 section_id, - double x_res, double y_res, + double x_res, + double y_res, int *level_id, int *scale, int *real_scale, double *xx_res, double *yy_res); @@ -1499,29 +1534,34 @@ unsigned char **image, int *image_sz); RL2_PRIVATE int get_payload_from_palette_transparent (unsigned int width, unsigned int height, - unsigned char *pixels, - rl2PalettePtr palette, - unsigned char format, - int quality, - unsigned char **image, + unsigned char + *pixels, + rl2PalettePtr + palette, + unsigned char + format, int quality, + unsigned char + **image, int *image_sz, - unsigned char bg_red, + unsigned char + bg_red, unsigned char bg_green, unsigned char bg_blue, double opacity); RL2_PRIVATE int get_payload_from_grayscale_opaque (unsigned int width, unsigned int height, sqlite3 * handle, - double minx, double miny, - double maxx, double maxy, - int srid, + double minx, + double miny, + double maxx, + double maxy, int srid, unsigned char *pixels, unsigned char format, int quality, unsigned char **image, int *image_sz); @@ -1531,23 +1571,25 @@ unsigned int height, unsigned char *pixels, unsigned char - format, int quality, + format, + int quality, unsigned char **image, int *image_sz, unsigned char bg_gray, double opacity); RL2_PRIVATE int get_payload_from_rgb_opaque (unsigned int width, unsigned int height, - sqlite3 * handle, double minx, - double miny, double maxx, - double maxy, int srid, + sqlite3 * handle, + double minx, double miny, + double maxx, double maxy, + int srid, unsigned char *pixels, unsigned char format, int quality, unsigned char **image, int *image_sz); @@ -1576,11 +1618,12 @@ unsigned char *pixels, unsigned char *rgba); RL2_PRIVATE int get_rgba_from_monochrome_transparent (unsigned int width, unsigned int height, - unsigned char *pixels, + unsigned char + *pixels, unsigned char *rgba); RL2_PRIVATE int get_rgba_from_palette_mask (unsigned int base_width, unsigned int base_height, unsigned char *pixels, @@ -1616,11 +1659,12 @@ unsigned char *pixels, unsigned char *rgba); RL2_PRIVATE int get_rgba_from_grayscale_transparent (unsigned int width, unsigned int height, - unsigned char *pixels, + unsigned char + *pixels, unsigned char *rgba, unsigned char bg_gray); RL2_PRIVATE int get_rgba_from_rgb_mask (unsigned int width, unsigned int height, @@ -1660,13 +1704,14 @@ unsigned char *rgba); RL2_PRIVATE int get_payload_from_gray_rgba_opaque (unsigned int width, unsigned int height, sqlite3 * handle, - double minx, double miny, - double maxx, double maxy, - int srid, + double minx, + double miny, + double maxx, + double maxy, int srid, unsigned char *rgb, unsigned char format, int quality, unsigned char **image, int *image_sz); @@ -1673,26 +1718,29 @@ RL2_PRIVATE int get_payload_from_gray_rgba_transparent (unsigned int width, unsigned int height, - unsigned char *rgb, + unsigned char + *rgb, unsigned char *alpha, unsigned char - format, int quality, + format, + int quality, unsigned char **image, int *image_sz, double opacity); RL2_PRIVATE int get_payload_from_rgb_rgba_opaque (unsigned int width, unsigned int height, sqlite3 * handle, - double minx, double miny, - double maxx, double maxy, - int srid, + double minx, + double miny, + double maxx, + double maxy, int srid, unsigned char *rgb, unsigned char format, int quality, unsigned char **image, int *image_sz); @@ -1699,12 +1747,14 @@ RL2_PRIVATE int get_payload_from_rgb_rgba_transparent (unsigned int width, unsigned int height, unsigned char *rgb, - unsigned char *alpha, - unsigned char format, + unsigned char + *alpha, + unsigned char + format, int quality, unsigned char **image, int *image_sz, double opacity, @@ -1711,11 +1761,12 @@ int half_transparent); RL2_PRIVATE int build_rgb_alpha (unsigned int width, unsigned int height, unsigned char *rgba, - unsigned char **rgb, unsigned char **alpha, + unsigned char **rgb, + unsigned char **alpha, unsigned char bg_red, unsigned char bg_green, unsigned char bg_blue); RL2_PRIVATE int get_rgba_from_multiband8 (unsigned int width, @@ -1744,11 +1795,12 @@ RL2_PRIVATE rl2CoverageStylePtr coverage_style_from_xml (char *name, unsigned char *xml); - RL2_PRIVATE rl2FeatureTypeStylePtr feature_type_style_from_xml (char *name, + RL2_PRIVATE rl2FeatureTypeStylePtr feature_type_style_from_xml (char + *name, unsigned char *xml); RL2_PRIVATE rl2GroupStylePtr group_style_from_sld_xml (char *name, unsigned char *xml); @@ -1833,12 +1885,12 @@ symbolizer); RL2_PRIVATE void rl2_destroy_line_symbolizer (rl2PrivLineSymbolizerPtr symbolizer); - RL2_PRIVATE void rl2_destroy_polygon_symbolizer (rl2PrivPolygonSymbolizerPtr - symbolizer); + RL2_PRIVATE void + rl2_destroy_polygon_symbolizer (rl2PrivPolygonSymbolizerPtr symbolizer); RL2_PRIVATE void rl2_destroy_text_symbolizer (rl2PrivTextSymbolizerPtr symbolizer); RL2_PRIVATE rl2PrivRuleSingleArgPtr @@ -1878,25 +1930,36 @@ double minx, double maxy, double tile_minx, double tile_maxy, rl2PixelPtr no_data, rl2RasterSymbolizerPtr style, rl2RasterStatisticsPtr stats); + + RL2_PRIVATE int rl2_copy_raw_mask (rl2RasterPtr raster, + unsigned char *maskbuf, + unsigned int width, + unsigned int height, + double x_res, double y_res, + double minx, double maxy, + double tile_minx, double tile_maxy); RL2_PRIVATE unsigned char *rl2_copy_endian_raw_pixels (const unsigned char *pixels, int pixels_sz, unsigned int width, - unsigned int height, + unsigned int + height, unsigned char sample_type, unsigned char num_bands, int big_endian); RL2_PRIVATE int rl2_build_shaded_relief_mask (sqlite3 * handle, int max_threads, rl2CoveragePtr cvg, + int by_section, + sqlite3_int64 section_id, double relief_factor, double scale_factor, unsigned int width, unsigned int height, double minx, double miny, @@ -1912,19 +1975,28 @@ RL2_PRIVATE int rl2_test_layer_group (sqlite3 * handle, const char *group_name); RL2_PRIVATE int rl2_rgba_raster_data (sqlite3 * handle, - const char *coverage_name, void *ctx, - int level, double minx, double miny, - double maxx, double maxy, - rl2PalettePtr palette, + const char *coverage_name, + void *ctx, int level, double minx, + double miny, double maxx, + double maxy, rl2PalettePtr palette, rl2PixelPtr no_data); RL2_PRIVATE int rl2_aux_render_image (struct aux_renderer *aux, unsigned char **ximage, int *ximage_size); + + RL2_PRIVATE int rl2_aux_default_image (unsigned int width, + unsigned int height, + unsigned char red, + unsigned char green, + unsigned char blue, int format_id, + int transparent, int quality, + unsigned char **ximage, + int *ximage_size); RL2_PRIVATE void rl2_aux_group_renderer (struct aux_group_renderer *auxgrp); RL2_PRIVATE double rl2_get_shaded_relief_scale_factor (sqlite3 * handle, const char @@ -1952,20 +2024,38 @@ sqlite3_int64 section_id, unsigned int width, unsigned int height, double minx, double miny, double maxx, double maxy, - double x_res, double y_res, + double x_res, + double y_res, unsigned char **buffer, int *buf_size, rl2PalettePtr * palette, unsigned char out_pixel, rl2PixelPtr bgcolor, rl2RasterSymbolizerPtr style, rl2RasterStatisticsPtr stats); + + RL2_PRIVATE int rl2_get_raw_raster_mask_common (sqlite3 * handle, + int max_threads, + rl2CoveragePtr cvg, + int by_section, + sqlite3_int64 section_id, + unsigned int width, + unsigned int height, + double minx, double miny, + double maxx, double maxy, + double x_res, double y_res, + unsigned char **mask, + int *mask_size); + + RL2_PRIVATE rl2RasterPtr + rl2_raster_decode_mask (int scale, const unsigned char *blob_odd, + int blob_odd_sz, int *status); RL2_PRIVATE char *rl2_double_quoted_sql (const char *value); RL2_PRIVATE int rl2_parse_point (sqlite3 * sqlite, const unsigned char *blob, int blob_sz, @@ -1974,17 +2064,19 @@ RL2_PRIVATE int rl2_parse_point_generic (sqlite3 * sqlite, const unsigned char *blob, int blob_sz, double *x, double *y); RL2_PRIVATE int rl2_parse_bbox_srid (sqlite3 * sqlite, - const unsigned char *blob, int blob_sz, - int *srid, double *minx, double *miny, - double *maxx, double *maxy); + const unsigned char *blob, + int blob_sz, int *srid, double *minx, + double *miny, double *maxx, + double *maxy); - RL2_PRIVATE int rl2_parse_bbox (sqlite3 * sqlite, const unsigned char *blob, - int blob_sz, double *minx, double *miny, - double *maxx, double *maxy); + RL2_PRIVATE int rl2_parse_bbox (sqlite3 * sqlite, + const unsigned char *blob, int blob_sz, + double *minx, double *miny, double *maxx, + double *maxy); RL2_PRIVATE int rl2_build_bbox (sqlite3 * sqlite, int srid, double minx, double miny, double maxx, double maxy, unsigned char **blob, int *blob_sz); @@ -1992,11 +2084,12 @@ int distance); RL2_PRIVATE int rl2_delta_decode (unsigned char *buffer, int size, int distance); - RL2_PRIVATE rl2PrivVariantValuePtr rl2_create_variant_int (const char *name, + RL2_PRIVATE rl2PrivVariantValuePtr rl2_create_variant_int (const char + *name, sqlite3_int64 value); RL2_PRIVATE rl2PrivVariantValuePtr rl2_create_variant_double (const char *name, @@ -2014,14 +2107,16 @@ *name); RL2_PRIVATE void rl2_destroy_variant_value (rl2PrivVariantValuePtr value); RL2_PRIVATE void rl2_draw_vector_feature (void *ctx, sqlite3 * handle, - rl2VectorSymbolizerPtr symbolizer, - int height, double minx, - double miny, double x_res, - double y_res, + const void *priv_data, + rl2VectorSymbolizerPtr + symbolizer, int height, + double minx, double miny, + double maxx, double maxy, + double x_res, double y_res, rl2GeometryPtr geom, rl2VariantArrayPtr variant); RL2_PRIVATE rl2GeometryPtr rl2_geometry_from_blob (const unsigned char *blob, int blob_sz); @@ -2035,16 +2130,20 @@ unsigned char **blob, int *blob_sz); RL2_PRIVATE int rl2_serialize_ring (rl2RingPtr ring, unsigned char **blob, int *blob_sz); + + RL2_PRIVATE int rl2_serialize_ring_as_linestring (rl2RingPtr ring, + unsigned char **blob, + int *blob_sz); RL2_PRIVATE double rl2_compute_curve_length (rl2GeometryPtr geom); RL2_PRIVATE rl2GeometryPtr - rl2_curve_substring (sqlite3 * handle, rl2GeometryPtr geom, double from, - double to); + rl2_curve_substring (sqlite3 * handle, rl2GeometryPtr geom, + double from, double to); RL2_PRIVATE rl2GeometryPtr rl2_clone_curve (rl2GeometryPtr in); RL2_PRIVATE rl2GeometryPtr rl2_clone_linestring (rl2LinestringPtr in); @@ -2055,11 +2154,26 @@ unsigned char *blob, int blob_sz); RL2_PRIVATE int rl2_get_font_from_dbms (sqlite3 * handle, const char *facename, unsigned char **font, int *font_sz); + + RL2_PRIVATE rl2LinestringPtr rl2_linestring_to_image (rl2LinestringPtr line, + int height, + double minx, + double miny, + double x_res, + double y_res); + + RL2_PRIVATE rl2RingPtr rl2_ring_to_image (rl2RingPtr ring, int height, + double minx, double miny, + double x_res, double y_res); + + RL2_PRIVATE void rl2DestroyLinestring (rl2LinestringPtr ptr); + + RL2_PRIVATE void rl2DestroyRing (rl2RingPtr ptr); #ifdef __cplusplus } #endif #endif /* _RASTERLITE2_PRIVATE_H */ Index: headers/rl2svg_private.h ================================================================== --- headers/rl2svg_private.h +++ headers/rl2svg_private.h @@ -504,26 +504,26 @@ RL2_PRIVATE rl2PrivSvgLinePtr svg_alloc_line (double x1, double y1, double x2, double y2); RL2_PRIVATE rl2PrivSvgLinePtr svg_clone_line (rl2PrivSvgLinePtr in); - RL2_PRIVATE rl2PrivSvgPolylinePtr svg_alloc_polyline (int points, double *x, - double *y); + RL2_PRIVATE rl2PrivSvgPolylinePtr svg_alloc_polyline (int points, + double *x, double *y); - RL2_PRIVATE rl2PrivSvgPolylinePtr svg_clone_polyline (rl2PrivSvgPolylinePtr - in); + RL2_PRIVATE rl2PrivSvgPolylinePtr + svg_clone_polyline (rl2PrivSvgPolylinePtr in); RL2_PRIVATE rl2PrivSvgPolygonPtr svg_alloc_polygon (int points, double *x, double *y); RL2_PRIVATE rl2PrivSvgPolygonPtr svg_clone_polygon (rl2PrivSvgPolygonPtr in); RL2_PRIVATE rl2PrivSvgPathMovePtr svg_alloc_path_move (double x, double y); - RL2_PRIVATE rl2PrivSvgPathMovePtr svg_clone_path_move (rl2PrivSvgPathMovePtr - in); + RL2_PRIVATE rl2PrivSvgPathMovePtr + svg_clone_path_move (rl2PrivSvgPathMovePtr in); RL2_PRIVATE rl2PrivSvgPathBezierPtr svg_alloc_path_bezier (double x1, double y1, double x2, double y2, @@ -608,24 +608,25 @@ rl2PrivSvgGroupPtr grp); RL2_PRIVATE rl2PrivSvgGradientStopPtr svg_alloc_gradient_stop (double offset, double red, - double green, - double blue, + double + green, + double + blue, double opacity); RL2_PRIVATE rl2PrivSvgGradientStopPtr svg_clone_gradient_stop (rl2PrivSvgGradientStopPtr in); RL2_PRIVATE rl2PrivSvgGradientPtr svg_alloc_gradient (void); - RL2_PRIVATE rl2PrivSvgGradientPtr svg_clone_gradient (rl2PrivSvgGradientPtr - in, - rl2PrivSvgGradientPtr - old); + RL2_PRIVATE rl2PrivSvgGradientPtr + svg_clone_gradient (rl2PrivSvgGradientPtr in, + rl2PrivSvgGradientPtr old); RL2_PRIVATE rl2PrivSvgDocumentPtr svg_alloc_document (void); RL2_PRIVATE void svg_close_group (rl2PrivSvgDocumentPtr svg_doc); @@ -633,40 +634,41 @@ RL2_PRIVATE void svg_close_clip (rl2PrivSvgDocumentPtr svg_doc); RL2_PRIVATE void svg_insert_clip (rl2PrivSvgDocumentPtr svg_doc); - RL2_PRIVATE rl2PrivSvgUsePtr svg_insert_use (rl2PrivSvgDocumentPtr svg_doc, + RL2_PRIVATE rl2PrivSvgUsePtr svg_insert_use (rl2PrivSvgDocumentPtr + svg_doc, const char *xlink_href, double x, double y, double width, double height); - RL2_PRIVATE void svg_insert_shape (rl2PrivSvgDocumentPtr svg_doc, int type, - void *data); + RL2_PRIVATE void svg_insert_shape (rl2PrivSvgDocumentPtr svg_doc, + int type, void *data); RL2_PRIVATE void svg_insert_gradient_stop (rl2PrivSvgGradientPtr gradient, double offset, double red, double green, double blue, double opacity); RL2_PRIVATE rl2PrivSvgGradientPtr svg_insert_linear_gradient (rl2PrivSvgDocumentPtr svg_doc, const char *id, const char *xlink_href, - double x1, double y1, double x2, double y2, - int units); + double x1, double y1, double x2, + double y2, int units); RL2_PRIVATE rl2PrivSvgGradientPtr svg_insert_radial_gradient (rl2PrivSvgDocumentPtr svg_doc, const char *id, const char *xlink_href, - double cx, double cy, double fx, double fy, - double r, int units); + double cx, double cy, double fx, + double fy, double r, int units); RL2_PRIVATE rl2PrivSvgGradientPtr svg_insert_radial_gradient (rl2PrivSvgDocumentPtr svg_doc, const char *id, const char *xlink_href, - double cx, double cy, double fx, double fy, - double r, int units); + double cx, double cy, double fx, + double fy, double r, int units); RL2_PRIVATE void svg_init_style (rl2PrivSvgStylePtr style); RL2_PRIVATE void svg_style_cleanup (rl2PrivSvgStylePtr style); DELETED rasterlite2-4.2.0.mk Index: rasterlite2-4.2.0.mk ================================================================== --- rasterlite2-4.2.0.mk +++ rasterlite2-4.2.0.mk @@ -1,86 +0,0 @@ -include $(CLEAR_VARS) -# ./configure --build=x86_64-pc-linux-gnu --host=arm-linux-eabi -LOCAL_MODULE := rasterlite2 - -# SQLite flags copied from ASOP [may not be needed for rasterlite2] -common_sqlite_flags := \ - -DHAVE_USLEEP=1 \ - -DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576 \ - -DSQLITE_THREADSAFE=1 \ - -DNDEBUG=1 \ - -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1 \ - -DSQLITE_DEFAULT_AUTOVACUUM=1 \ - -DSQLITE_TEMP_STORE=3 \ - -DSQLITE_ENABLE_FTS3 \ - -DSQLITE_ENABLE_FTS3_BACKWARDS \ - -DSQLITE_ENABLE_RTREE=1 \ - -DSQLITE_DEFAULT_FILE_FORMAT=4 - -# comment out TARGET_CPU in config.h - will be replaced with TARGET_ARCH_ABI -spatialite_flags := \ - -DOMIT_FREEXL \ - -DTARGET_CPU=\"$(TARGET_ARCH_ABI)\" \ - -Dfdatasync=fsync \ - -DSQLITE_ENABLE_RTREE=1 \ - -DSQLITE_OMIT_BUILTIN_TEST=1 - -# comment out TARGET_CPU in config.h - will be replaced with TARGET_ARCH_ABI -rasterlite2_flags := \ - -DTARGET_CPU=\"$(TARGET_ARCH_ABI)\" \ - -O - -LOCAL_CFLAGS := \ - $(common_sqlite_flags) \ - $(spatialite_flags) \ - $(rasterlite2_flags) - -LOCAL_C_INCLUDES := \ - $(SQLITE_PATH) \ - $(GEOTIFF_PATH)/libxtiff \ - $(GEOTIFF_PATH) \ - $(TIFF_PATH) \ - $(JPEG_PATH) \ - $(GIF_PATH) \ - $(PNG_PATH) \ - $(WEBP_PATH)/src/webp \ - $(WEBP_PATH)/src/dec \ - $(WEBP_PATH)/src/dsp \ - $(WEBP_PATH)/src/enc \ - $(WEBP_PATH)/src/utils \ - $(WEBP_PATH)/src \ - $(WEBP_PATH) \ - $(CAIRO_PATH) \ - $(ICONV_PATH)/include \ - $(ICONV_PATH)/libcharset/include \ - $(XML2_PATH)/include \ - $(CURL_PATH) \ - $(CURL_PATH)/include \ - $(CURL_PATH)/lib \ - $(RASTERLITE2_PATH) \ - $(RASTERLITE2_PATH)/headers \ - $(SPATIALITE_PATH)/src/headers \ - $(LZMA_PATH)/src/liblzma/api -LOCAL_SRC_FILES := \ - $(RASTERLITE2_PATH)/src/rasterlite2.c \ - $(RASTERLITE2_PATH)/src/rl2ascii.c \ - $(RASTERLITE2_PATH)/src/rl2codec.c \ - $(RASTERLITE2_PATH)/src/rl2dbms.c \ - $(RASTERLITE2_PATH)/src/rl2gif.c \ - $(RASTERLITE2_PATH)/src/rl2import.c \ - $(RASTERLITE2_PATH)/src/rl2jpeg.c \ - $(RASTERLITE2_PATH)/src/rl2paint.c \ - $(RASTERLITE2_PATH)/src/rl2png.c \ - $(RASTERLITE2_PATH)/src/rl2rastersym.c \ - $(RASTERLITE2_PATH)/src/rl2raw.c \ - $(RASTERLITE2_PATH)/src/rl2sql.c \ - $(RASTERLITE2_PATH)/src/rl2sqlaux.c \ - $(RASTERLITE2_PATH)/src/rl2svg.c \ - $(RASTERLITE2_PATH)/src/rl2svgaux.c \ - $(RASTERLITE2_PATH)/src/rl2svgxml.c \ - $(RASTERLITE2_PATH)/src/rl2symbolizer.c \ - $(RASTERLITE2_PATH)/src/rl2tiff.c \ - $(RASTERLITE2_PATH)/src/rl2version.c \ - $(RASTERLITE2_PATH)/src/rl2webp.c \ - $(RASTERLITE2_PATH)/src/rl2wms.c -LOCAL_STATIC_LIBRARIES := libpng libwebp libxml2 spatialite libfreetype libcairo libcurl libgeotiff libtiff libgif libjpeg -include $(BUILD_STATIC_LIBRARY) ADDED rasterlite2-4.3.0.mk Index: rasterlite2-4.3.0.mk ================================================================== --- rasterlite2-4.3.0.mk +++ rasterlite2-4.3.0.mk @@ -0,0 +1,106 @@ +include $(CLEAR_VARS) +# ./configure --build=x86_64-pc-linux-gnu --host=arm-linux-eabi +LOCAL_MODULE := rasterlite2 + +# SQLite flags copied from ASOP [may not be needed for rasterlite2] +common_sqlite_flags := \ + -DHAVE_USLEEP=1 \ + -DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576 \ + -DSQLITE_THREADSAFE=1 \ + -DNDEBUG=1 \ + -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1 \ + -DSQLITE_DEFAULT_AUTOVACUUM=1 \ + -DSQLITE_TEMP_STORE=3 \ + -DSQLITE_ENABLE_FTS3 \ + -DSQLITE_ENABLE_FTS3_BACKWARDS \ + -DSQLITE_ENABLE_RTREE=1 \ + -DSQLITE_DEFAULT_FILE_FORMAT=4 + +# comment out TARGET_CPU in config.h - will be replaced with TARGET_ARCH_ABI +spatialite_flags := \ + -DOMIT_FREEXL \ + -DTARGET_CPU=\"$(TARGET_ARCH_ABI)\" \ + -Dfdatasync=fsync \ + -DSQLITE_ENABLE_RTREE=1 \ + -DENABLE_GCP=1 \ + -DENABLE_GEOPACKAGE=1 \ + -DENABLE_LIBXML2=1 \ + -DSQLITE_OMIT_BUILTIN_TEST=1 + +# comment out TARGET_CPU in config.h - will be replaced with TARGET_ARCH_ABI +# comment out VERSION in config.h - manually set to avoid conflict with other packages +rasterlite2_flags := \ + -DTARGET_CPU=\"$(TARGET_ARCH_ABI)\" \ + -DVERSION=\"0.9\" \ + -O + +LOCAL_CFLAGS := \ + $(common_sqlite_flags) \ + $(spatialite_flags) \ + $(rasterlite2_flags) + +# 2014-10-03 - adapted based on ls -1 result +LOCAL_C_INCLUDES := \ + $(SQLITE_PATH) \ + $(GEOTIFF_PATH)/libxtiff \ + $(GEOTIFF_PATH) \ + $(TIFF_PATH) \ + $(JPEG_PATH) \ + $(GIF_PATH) \ + $(PNG_PATH) \ + $(WEBP_PATH)/src/webp \ + $(WEBP_PATH)/src/dec \ + $(WEBP_PATH)/src/dsp \ + $(WEBP_PATH)/src/enc \ + $(WEBP_PATH)/src/utils \ + $(WEBP_PATH)/src \ + $(WEBP_PATH) \ + $(CAIRO_PATH) \ + $(FONTCONFIG_PATH) \ + $(ICONV_PATH)/include \ + $(FREETYPE_PATH)/include \ + $(ICONV_PATH)/libcharset/include \ + $(XML2_PATH)/include \ + $(CURL_PATH) \ + $(CURL_PATH)/include \ + $(CURL_PATH)/lib \ + $(RASTERLITE2_PATH) \ + $(RASTERLITE2_PATH)/headers \ + $(SPATIALITE_PATH)/src/headers \ + $(LZMA_PATH)/src/liblzma/api \ + $(OPENJPEG_PATH)/src/lib/openjp2 \ + $(CHARLS_PATH) + +LOCAL_SRC_FILES := \ + $(RASTERLITE2_PATH)/src/md5.c \ + $(RASTERLITE2_PATH)/src/rasterlite2.c \ + $(RASTERLITE2_PATH)/src/rl2ascii.c \ + $(RASTERLITE2_PATH)/src/rl2auxfont.c \ + $(RASTERLITE2_PATH)/src/rl2auxgeom.c \ + $(RASTERLITE2_PATH)/src/rl2auxrender.c \ + $(RASTERLITE2_PATH)/src/rl2charls.c \ + $(RASTERLITE2_PATH)/src/rl2codec.c \ + $(RASTERLITE2_PATH)/src/rl2dbms.c \ + $(RASTERLITE2_PATH)/src/rl2gif.c \ + $(RASTERLITE2_PATH)/src/rl2import.c \ + $(RASTERLITE2_PATH)/src/rl2jpeg.c \ + $(RASTERLITE2_PATH)/src/rl2md5.c \ + $(RASTERLITE2_PATH)/src/rl2openjpeg.c \ + $(RASTERLITE2_PATH)/src/rl2paint.c \ + $(RASTERLITE2_PATH)/src/rl2png.c \ + $(RASTERLITE2_PATH)/src/rl2pyramid.c \ + $(RASTERLITE2_PATH)/src/rl2rastersym.c \ + $(RASTERLITE2_PATH)/src/rl2raw.c \ + $(RASTERLITE2_PATH)/src/rl2sql.c \ + $(RASTERLITE2_PATH)/src/rl2sqlaux.c \ + $(RASTERLITE2_PATH)/src/rl2svg.c \ + $(RASTERLITE2_PATH)/src/rl2svgaux.c \ + $(RASTERLITE2_PATH)/src/rl2svgxml.c \ + $(RASTERLITE2_PATH)/src/rl2symbaux.c \ + $(RASTERLITE2_PATH)/src/rl2symbolizer.c \ + $(RASTERLITE2_PATH)/src/rl2tiff.c \ + $(RASTERLITE2_PATH)/src/rl2version.c \ + $(RASTERLITE2_PATH)/src/rl2webp.c \ + $(RASTERLITE2_PATH)/src/rl2wms.c +LOCAL_STATIC_LIBRARIES := libcharls libopenjpeg libpng libwebp libxml2 spatialite libfreetype libcairo libcurl libgeotiff libtiff libgif libjpeg +include $(BUILD_STATIC_LIBRARY) Index: src/Makefile.am ================================================================== --- src/Makefile.am +++ src/Makefile.am @@ -23,11 +23,11 @@ if MINGW librasterlite2_la_LDFLAGS = -avoid-version -no-undefined librasterlite2_la_LIBADD += -lm else -librasterlite2_la_LDFLAGS = -version-info 0:0:0 +librasterlite2_la_LDFLAGS = -version-info 1:0:0 librasterlite2_la_LIBADD += -lpthread -lm endif mod_rasterlite2_la_SOURCES = rasterlite2.c rl2raw.c rl2codec.c \ rl2jpeg.c rl2png.c rl2gif.c rl2webp.c rl2tiff.c rl2wms.c \ @@ -48,10 +48,10 @@ if MINGW mod_rasterlite2_la_LDFLAGS = -module -avoid-version -no-undefined mod_rasterlite2_la_LIBADD += -lm else -mod_rasterlite2_la_LDFLAGS = -module -version-info 0:0:0 +mod_rasterlite2_la_LDFLAGS = -module -version-info 1:0:0 mod_rasterlite2_la_LIBADD += -lpthread -lm endif MOSTLYCLEANFILES = *.gcna *.gcno *.gcda Index: src/Makefile.in ================================================================== --- src/Makefile.in +++ src/Makefile.in @@ -1,9 +1,9 @@ -# Makefile.in generated by automake 1.14.1 from Makefile.am. +# Makefile.in generated by automake 1.15 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2013 Free Software Foundation, Inc. +# Copyright (C) 1994-2014 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -14,11 +14,21 @@ @SET_MAKE@ VPATH = @srcdir@ -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ @@ -82,19 +92,19 @@ @MINGW_TRUE@am__append_1 = -lm @MINGW_FALSE@am__append_2 = -lpthread -lm @MINGW_TRUE@am__append_3 = -lm @MINGW_FALSE@am__append_4 = -lpthread -lm subdir = src -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ - $(top_srcdir)/depcomp $(noinst_HEADERS) ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ + $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; @@ -232,10 +242,11 @@ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` ETAGS = etags CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ @@ -393,11 +404,11 @@ rl2auxgeom.c rl2auxfont.c librasterlite2_la_LIBADD = @LIBPNG_LIBS@ @LIBWEBP_LIBS@ @LIBLZMA_LIBS@ \ @LIBCAIRO_LIBS@ @LIBCURL_LIBS@ @LIBXML2_LIBS@ \ @LIBFREETYPE2_LIBS@ $(am__append_1) $(am__append_2) -@MINGW_FALSE@librasterlite2_la_LDFLAGS = -version-info 0:0:0 +@MINGW_FALSE@librasterlite2_la_LDFLAGS = -version-info 1:0:0 @MINGW_TRUE@librasterlite2_la_LDFLAGS = -avoid-version -no-undefined mod_rasterlite2_la_SOURCES = rasterlite2.c rl2raw.c rl2codec.c \ rl2jpeg.c rl2png.c rl2gif.c rl2webp.c rl2tiff.c rl2wms.c \ rl2ascii.c rl2paint.c rl2dbms.c rl2import.c rl2pyramid.c \ rl2sql.c rl2sqlaux.c rl2auxrender.c rl2svg.c rl2svgxml.c \ @@ -409,11 +420,11 @@ @LIBLZMA_LIBS@ @LIBCAIRO_LIBS@ @LIBCURL_LIBS@ @LIBXML2_LIBS@ \ @LIBFREETYPE2_LIBS@ $(am__append_3) $(am__append_4) mod_rasterlite2_la_CPPFLAGS = @CFLAGS@ -I$(top_srcdir)/headers -I. \ -DLOADABLE_EXTENSION mod_rasterlite2_la_LIBTOOLFLAGS = --tag=disable-static -@MINGW_FALSE@mod_rasterlite2_la_LDFLAGS = -module -version-info 0:0:0 +@MINGW_FALSE@mod_rasterlite2_la_LDFLAGS = -module -version-info 1:0:0 @MINGW_TRUE@mod_rasterlite2_la_LDFLAGS = -module -avoid-version -no-undefined MOSTLYCLEANFILES = *.gcna *.gcno *.gcda all: all-am .SUFFIXES: @@ -428,11 +439,10 @@ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu src/Makefile -.PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ @@ -998,10 +1008,12 @@ install-pdf-am install-ps install-ps-am install-strip \ installcheck installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-compile \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags tags-am uninstall uninstall-am uninstall-libLTLIBRARIES + +.PRECIOUS: Makefile # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: Index: src/rasterlite2.c ================================================================== --- src/rasterlite2.c +++ src/rasterlite2.c @@ -512,12 +512,13 @@ }; return RL2_ERROR; } static int -check_coverage_no_data (rl2PrivPixelPtr pxl_no_data, unsigned char sample_type, - unsigned char pixel_type, unsigned char num_samples) +check_coverage_no_data (rl2PrivPixelPtr pxl_no_data, + unsigned char sample_type, unsigned char pixel_type, + unsigned char num_samples) { /* checking if the NoData pixel is consistent with the Coverage */ if (pxl_no_data == NULL) return 1; if (pxl_no_data->sampleType != sample_type) @@ -1253,12 +1254,12 @@ RL2_DECLARE rl2RasterPtr rl2_create_raster (unsigned int width, unsigned int height, unsigned char sample_type, unsigned char pixel_type, unsigned char num_samples, unsigned char *bufpix, - int bufpix_size, rl2PalettePtr palette, unsigned char *mask, - int mask_size, rl2PixelPtr no_data) + int bufpix_size, rl2PalettePtr palette, + unsigned char *mask, int mask_size, rl2PixelPtr no_data) { /* allocating and initializing a Raster object with an optional Transparency Mask */ return create_raster_common (width, height, sample_type, pixel_type, num_samples, bufpix, bufpix_size, palette, mask, mask_size, no_data, 0); @@ -1430,12 +1431,13 @@ rst->maxY = cy + vExt; return RL2_OK; } RL2_DECLARE int -rl2_raster_georeference_upper_left (rl2RasterPtr ptr, int srid, double horz_res, - double vert_res, double x, double y) +rl2_raster_georeference_upper_left (rl2RasterPtr ptr, int srid, + double horz_res, double vert_res, + double x, double y) { /* setting the Raster's georeferencing infos - UpperLeft corner */ rl2PrivRasterPtr rst = (rl2PrivRasterPtr) ptr; double hExt; double vExt; @@ -1453,12 +1455,12 @@ return RL2_OK; } RL2_DECLARE int rl2_raster_georeference_upper_right (rl2RasterPtr ptr, int srid, - double horz_res, double vert_res, double x, - double y) + double horz_res, double vert_res, + double x, double y) { /* setting the Raster's georeferencing infos - UpperRight corner */ rl2PrivRasterPtr rst = (rl2PrivRasterPtr) ptr; double hExt; double vExt; @@ -1475,12 +1477,13 @@ rst->maxY = y; return RL2_OK; } RL2_DECLARE int -rl2_raster_georeference_lower_left (rl2RasterPtr ptr, int srid, double horz_res, - double vert_res, double x, double y) +rl2_raster_georeference_lower_left (rl2RasterPtr ptr, int srid, + double horz_res, double vert_res, + double x, double y) { /* setting the Raster's georeferencing infos - LowerLeft corner */ rl2PrivRasterPtr rst = (rl2PrivRasterPtr) ptr; double hExt; double vExt; @@ -1498,12 +1501,12 @@ return RL2_OK; } RL2_DECLARE int rl2_raster_georeference_lower_right (rl2RasterPtr ptr, int srid, - double horz_res, double vert_res, double x, - double y) + double horz_res, double vert_res, + double x, double y) { /* setting the Raster's georeferencing infos - LowerRight corner */ rl2PrivRasterPtr rst = (rl2PrivRasterPtr) ptr; double hExt; double vExt; @@ -1805,12 +1808,12 @@ entry->blue = b; return RL2_OK; } RL2_DECLARE int -rl2_get_palette_index (rl2PalettePtr ptr, unsigned char *index, unsigned char r, - unsigned char g, unsigned char b) +rl2_get_palette_index (rl2PalettePtr ptr, unsigned char *index, + unsigned char r, unsigned char g, unsigned char b) { /* finding the index corresponding to the given color (if any) */ int i; rl2PrivPaletteEntryPtr entry; rl2PrivPalettePtr plt = (rl2PrivPalettePtr) ptr; Index: src/rl2ascii.c ================================================================== --- src/rl2ascii.c +++ src/rl2ascii.c @@ -318,12 +318,12 @@ fprintf (stderr, "ASCII Origin: invalid Header found on %s\n", path); goto error; } ascii = - alloc_ascii_origin (path, srid, sample_type, width, height, minx, miny, - maxx, maxy, xres, yres, no_data); + alloc_ascii_origin (path, srid, sample_type, width, height, minx, + miny, maxx, maxy, xres, yres, no_data); if (ascii == NULL) goto error; *buf = '\0'; col_no = width; @@ -616,12 +616,12 @@ { if (verbose) fprintf (stderr, "Mismatching SRID !!!\n"); return RL2_FALSE; } - if (rl2_get_ascii_grid_origin_resolution (ascii, &hResolution, &vResolution) - != RL2_OK) + if (rl2_get_ascii_grid_origin_resolution + (ascii, &hResolution, &vResolution) != RL2_OK) return RL2_FALSE; confidence = coverage->hResolution / 100.0; if (hResolution < (coverage->hResolution - confidence) || hResolution > (coverage->hResolution + confidence)) { @@ -750,12 +750,12 @@ return 0; for (x = 0, col = startCol; x < width && col < origin->width; x++, col++) { unsigned short uint16; - if (fread (&uint16, sizeof (unsigned short), 1, origin->tmp) <= - 0) + if (fread (&uint16, sizeof (unsigned short), 1, origin->tmp) + <= 0) return 0; *p_out++ = uint16; } } return 1; @@ -1070,12 +1070,12 @@ } } } raster = rl2_create_raster (coverage->tileWidth, coverage->tileHeight, - coverage->sampleType, RL2_PIXEL_DATAGRID, 1, pixels, - pixels_sz, NULL, mask, mask_size, NULL); + coverage->sampleType, RL2_PIXEL_DATAGRID, 1, + pixels, pixels_sz, NULL, mask, mask_size, NULL); if (raster == NULL) goto error; return raster; error: if (pixels != NULL) Index: src/rl2auxfont.c ================================================================== --- src/rl2auxfont.c +++ src/rl2auxfont.c @@ -692,12 +692,12 @@ if (xfont != NULL) { free (xfont); xfont = NULL; } - if (rl2_font_decode (blob, blob_sz, &xfont, &xfont_sz) == - RL2_OK) + if (rl2_font_decode (blob, blob_sz, &xfont, &xfont_sz) + == RL2_OK) { *font = xfont; *font_sz = xfont_sz; } } @@ -725,11 +725,10 @@ /* attempting to fetch a BLOB-encoded TrueType Font */ const char *sql; int ret; sqlite3_stmt *stmt = NULL; unsigned char *xfont = NULL; - int xfont_sz; if (facename == NULL) return RL2_ERROR; *font = NULL; *font_sz = 0; @@ -784,14 +783,18 @@ RL2_DECLARE rl2GraphicsFontPtr rl2_search_TrueType_font (sqlite3 * handle, const void *priv_data, const char *facename, double size) { /* attempting to fetch and create a TrueType Font */ + rl2GraphicsFontPtr font; unsigned char *ttf = NULL; int ttf_sz; if (facename == NULL) return NULL; if (rl2_get_TrueType_font (handle, facename, &ttf, &ttf_sz) != RL2_OK) return NULL; - return rl2_graph_create_TrueType_font (priv_data, ttf, ttf_sz, size); + font = rl2_graph_create_TrueType_font (priv_data, ttf, ttf_sz, size); + if (ttf != NULL) + free (ttf); + return font; } Index: src/rl2auxgeom.c ================================================================== --- src/rl2auxgeom.c +++ src/rl2auxgeom.c @@ -124,15 +124,19 @@ { /* LINESTRING object constructor */ rl2LinestringPtr p = malloc (sizeof (rl2Linestring)); p->coords = malloc (sizeof (double) * (vert * 2)); p->points = vert; + p->minx = DBL_MAX; + p->miny = DBL_MAX; + p->maxx = 0.0 - DBL_MAX; + p->maxy = 0.0 - DBL_MAX; p->next = NULL; return p; } -static void +RL2_PRIVATE void rl2DestroyLinestring (rl2LinestringPtr ptr) { /* LINESTRING object desctructror */ if (ptr) { @@ -139,23 +143,83 @@ if (ptr->coords) free (ptr->coords); free (ptr); } } + +RL2_PRIVATE rl2LinestringPtr +rl2_linestring_to_image (rl2LinestringPtr line, int height, double minx, + double miny, double x_res, double y_res) +{ +/* creating a Linestring in image coordinates */ + rl2LinestringPtr out = NULL; + int iv; + double x; + double y; + double dx; + double dy; + + if (line == NULL) + return NULL; + out = rl2CreateLinestring (line->points); + if (out == NULL) + return out; + for (iv = 0; iv < line->points; iv++) + { + /* populating the X and Y arrays */ + rl2GetPoint (line->coords, iv, &x, &y); + dx = (x - minx) / x_res; + dy = (double) height - ((y - miny) / y_res); + rl2SetPoint (out->coords, iv, dx, dy); + } + return out; +} static rl2RingPtr rl2CreateRing (int vert) { /* ring object constructor */ rl2RingPtr p = malloc (sizeof (rl2Ring)); p->coords = malloc (sizeof (double) * (vert * 2)); p->points = vert; + p->minx = DBL_MAX; + p->miny = DBL_MAX; + p->maxx = 0.0 - DBL_MAX; + p->maxy = 0.0 - DBL_MAX; p->next = NULL; return p; } -static void +RL2_PRIVATE rl2RingPtr +rl2_ring_to_image (rl2RingPtr ring, int height, double minx, double miny, + double x_res, double y_res) +{ +/* creating a Ring in image coordinates */ + rl2RingPtr out = NULL; + int iv; + double x; + double y; + double dx; + double dy; + + if (ring == NULL) + return NULL; + out = rl2CreateRing (ring->points); + if (out == NULL) + return out; + for (iv = 0; iv < ring->points; iv++) + { + /* populating the X and Y arrays */ + rl2GetPoint (ring->coords, iv, &x, &y); + dx = (x - minx) / x_res; + dy = (double) height - ((y - miny) / y_res); + rl2SetPoint (out->coords, iv, dx, dy); + } + return out; +} + +RL2_PRIVATE void rl2DestroyRing (rl2RingPtr ptr) { /* ring object destructor */ if (ptr) { @@ -183,10 +247,14 @@ for (ind = 0; ind < p->num_interiors; ind++) { pP = p->interiors + ind; pP->points = 0; pP->coords = NULL; + pP->minx = DBL_MAX; + pP->miny = DBL_MAX; + pP->maxx = 0.0 - DBL_MAX; + pP->maxy = 0.0 - DBL_MAX; } return p; } static void @@ -624,10 +692,18 @@ for (iv = 0; iv < points; iv++) { x = rl2GeomImport64 (blob + *offset, endian, endian_arch); y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch); rl2SetPoint (line->coords, iv, x, y); + if (x < line->minx) + line->minx = x; + if (x > line->maxx) + line->maxx = x; + if (y < line->miny) + line->miny = y; + if (y > line->maxy) + line->maxy = y; *offset += 16; } } static void @@ -650,10 +726,18 @@ for (iv = 0; iv < points; iv++) { x = rl2GeomImport64 (blob + *offset, endian, endian_arch); y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch); rl2SetPoint (line->coords, iv, x, y); + if (x < line->minx) + line->minx = x; + if (x > line->maxx) + line->maxx = x; + if (y < line->miny) + line->miny = y; + if (y > line->maxy) + line->maxy = y; *offset += 24; } } static void @@ -676,10 +760,18 @@ for (iv = 0; iv < points; iv++) { x = rl2GeomImport64 (blob + *offset, endian, endian_arch); y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch); rl2SetPoint (line->coords, iv, x, y); + if (x < line->minx) + line->minx = x; + if (x > line->maxx) + line->maxx = x; + if (y < line->miny) + line->miny = y; + if (y > line->maxy) + line->maxy = y; *offset += 24; } } static void @@ -702,10 +794,18 @@ for (iv = 0; iv < points; iv++) { x = rl2GeomImport64 (blob + *offset, endian, endian_arch); y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch); rl2SetPoint (line->coords, iv, x, y); + if (x < line->minx) + line->minx = x; + if (x > line->maxx) + line->maxx = x; + if (y < line->miny) + line->miny = y; + if (y > line->maxy) + line->maxy = y; *offset += 32; } } static rl2PolygonPtr @@ -767,10 +867,18 @@ { x = rl2GeomImport64 (blob + *offset, endian, endian_arch); y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch); *offset += 16; rl2SetPoint (ring->coords, iv, x, y); + if (x < ring->minx) + ring->minx = x; + if (x > ring->maxx) + ring->maxx = x; + if (y < ring->miny) + ring->miny = y; + if (y > ring->maxy) + ring->maxy = y; } } } static void @@ -809,10 +917,18 @@ { x = rl2GeomImport64 (blob + *offset, endian, endian_arch); y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch); *offset += 24; rl2SetPoint (ring->coords, iv, x, y); + if (x < ring->minx) + ring->minx = x; + if (x > ring->maxx) + ring->maxx = x; + if (y < ring->miny) + ring->miny = y; + if (y > ring->maxy) + ring->maxy = y; } } } static void @@ -851,10 +967,18 @@ { x = rl2GeomImport64 (blob + *offset, endian, endian_arch); y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch); *offset += 24; rl2SetPoint (ring->coords, iv, x, y); + if (x < ring->minx) + ring->minx = x; + if (x > ring->maxx) + ring->maxx = x; + if (y < ring->miny) + ring->miny = y; + if (y > ring->maxy) + ring->maxy = y; } } } static void @@ -893,10 +1017,18 @@ { x = rl2GeomImport64 (blob + *offset, endian, endian_arch); y = rl2GeomImport64 (blob + (*offset + 8), endian, endian_arch); *offset += 32; rl2SetPoint (ring->coords, iv, x, y); + if (x < ring->minx) + ring->minx = x; + if (x > ring->maxx) + ring->maxx = x; + if (y < ring->miny) + ring->miny = y; + if (y > ring->maxy) + ring->maxy = y; } } } static void @@ -938,10 +1070,18 @@ x = last_x + fx; y = last_y + fy; *offset += 8; } rl2SetPoint (line->coords, iv, x, y); + if (x < line->minx) + line->minx = x; + if (x > line->maxx) + line->maxx = x; + if (y < line->miny) + line->miny = y; + if (y > line->maxy) + line->maxy = y; last_x = x; last_y = y; } } @@ -984,10 +1124,18 @@ x = last_x + fx; y = last_y + fy; *offset += 12; } rl2SetPoint (line->coords, iv, x, y); + if (x < line->minx) + line->minx = x; + if (x > line->maxx) + line->maxx = x; + if (y < line->miny) + line->miny = y; + if (y > line->maxy) + line->maxy = y; last_x = x; last_y = y; } } @@ -1030,10 +1178,18 @@ x = last_x + fx; y = last_y + fy; *offset += 16; } rl2SetPoint (line->coords, iv, x, y); + if (x < line->minx) + line->minx = x; + if (x > line->maxx) + line->maxx = x; + if (y < line->miny) + line->miny = y; + if (y > line->maxy) + line->maxy = y; last_x = x; last_y = y; } } @@ -1076,10 +1232,18 @@ x = last_x + fx; y = last_y + fy; *offset += 20; } rl2SetPoint (line->coords, iv, x, y); + if (x < line->minx) + line->minx = x; + if (x > line->maxx) + line->maxx = x; + if (y < line->miny) + line->miny = y; + if (y > line->maxy) + line->maxy = y; last_x = x; last_y = y; } } @@ -1139,10 +1303,18 @@ x = last_x + fx; y = last_y + fy; *offset += 8; } rl2SetPoint (ring->coords, iv, x, y); + if (x < ring->minx) + ring->minx = x; + if (x > ring->maxx) + ring->maxx = x; + if (y < ring->miny) + ring->miny = y; + if (y > ring->maxy) + ring->maxy = y; last_x = x; last_y = y; } } } @@ -1203,10 +1375,18 @@ x = last_x + fx; y = last_y + fy; *offset += 12; } rl2SetPoint (ring->coords, iv, x, y); + if (x < ring->minx) + ring->minx = x; + if (x > ring->maxx) + ring->maxx = x; + if (y < ring->miny) + ring->miny = y; + if (y > ring->maxy) + ring->maxy = y; last_x = x; last_y = y; } } } @@ -1267,10 +1447,18 @@ x = last_x + fx; y = last_y + fy; *offset += 16; } rl2SetPoint (ring->coords, iv, x, y); + if (x < ring->minx) + ring->minx = x; + if (x > ring->maxx) + ring->maxx = x; + if (y < ring->miny) + ring->miny = y; + if (y > ring->maxy) + ring->maxy = y; last_x = x; last_y = y; } } } @@ -1331,10 +1519,18 @@ x = last_x + fx; y = last_y + fy; *offset += 20; } rl2SetPoint (ring->coords, iv, x, y); + if (x < ring->minx) + ring->minx = x; + if (x > ring->maxx) + ring->maxx = x; + if (y < ring->miny) + ring->miny = y; + if (y > ring->maxy) + ring->maxy = y; last_x = x; last_y = y; } } } @@ -1401,20 +1597,20 @@ case GAIA_COMPRESSED_LINESTRING: rl2ParseCompressedLine (geom, blob, size, endian, endian_arch, offset); break; case GAIA_COMPRESSED_LINESTRINGZ: - rl2ParseCompressedLineZ (geom, blob, size, endian, endian_arch, - offset); + rl2ParseCompressedLineZ (geom, blob, size, endian, + endian_arch, offset); break; case GAIA_COMPRESSED_LINESTRINGM: - rl2ParseCompressedLineM (geom, blob, size, endian, endian_arch, - offset); + rl2ParseCompressedLineM (geom, blob, size, endian, + endian_arch, offset); break; case GAIA_COMPRESSED_LINESTRINGZM: - rl2ParseCompressedLineZM (geom, blob, size, endian, endian_arch, - offset); + rl2ParseCompressedLineZM (geom, blob, size, endian, + endian_arch, offset); break; case GAIA_COMPRESSED_POLYGON: rl2ParseCompressedPolygon (geom, blob, size, endian, endian_arch, offset); break; @@ -1508,20 +1704,20 @@ case GAIA_POLYGONZM: rl2ParsePolygonZM (geom, blob, size, little_endian, endian_arch, &offset); break; case GAIA_COMPRESSED_LINESTRING: - rl2ParseCompressedLine (geom, blob, size, little_endian, endian_arch, - &offset); + rl2ParseCompressedLine (geom, blob, size, little_endian, + endian_arch, &offset); break; case GAIA_COMPRESSED_LINESTRINGZ: - rl2ParseCompressedLineZ (geom, blob, size, little_endian, endian_arch, - &offset); + rl2ParseCompressedLineZ (geom, blob, size, little_endian, + endian_arch, &offset); break; case GAIA_COMPRESSED_LINESTRINGM: - rl2ParseCompressedLineM (geom, blob, size, little_endian, endian_arch, - &offset); + rl2ParseCompressedLineM (geom, blob, size, little_endian, + endian_arch, &offset); break; case GAIA_COMPRESSED_LINESTRINGZM: rl2ParseCompressedLineZM (geom, blob, size, little_endian, endian_arch, &offset); break; @@ -1721,10 +1917,71 @@ ptr += 16; } *ptr = GAIA_MARK_END; /* END signature */ return 1; } + +RL2_PRIVATE int +rl2_serialize_ring_as_linestring (rl2RingPtr ring, unsigned char **result, + int *size) +{ +/* serializing a BLOB Geometry - polygon ring as linestring */ + int iv; + unsigned char *ptr; + int endian_arch = rl2GeomEndianArch (); + double minx = DBL_MAX; + double maxx = 0.0 - DBL_MAX; + double miny = DBL_MAX; + double maxy = 0.0 - DBL_MAX; + double x; + double y; + + *result = NULL; + *size = 0; + if (ring == NULL) + return 0; + +/* computing the MBR */ + for (iv = 0; iv < ring->points; iv++) + { + rl2GetPoint (ring->coords, iv, &x, &y); + if (x < minx) + minx = x; + if (x > maxx) + maxx = x; + if (y < miny) + miny = y; + if (y > maxy) + maxy = y; + } +/* computing the size of BLOB */ + *size = 44; /* header size */ + *size += (4 + ((sizeof (double) * 2) * ring->points)); /* # points + [x,y] for each vertex */ + *result = malloc (*size); + ptr = *result; +/* building the BLOB */ + *ptr = GAIA_MARK_START; /* START signature */ + *(ptr + 1) = GAIA_LITTLE_ENDIAN; /* byte ordering */ + rl2GeomExport32 (ptr + 2, 4326, 1, endian_arch); /* the SRID */ + rl2GeomExport64 (ptr + 6, minx, 1, endian_arch); /* MBR - minimum X */ + rl2GeomExport64 (ptr + 14, miny, 1, endian_arch); /* MBR - minimum Y */ + rl2GeomExport64 (ptr + 22, maxx, 1, endian_arch); /* MBR - maximum X */ + rl2GeomExport64 (ptr + 30, maxy, 1, endian_arch); /* MBR - maximum Y */ + *(ptr + 38) = GAIA_MARK_MBR; /* MBR signature */ + rl2GeomExport32 (ptr + 39, GAIA_LINESTRING, 1, endian_arch); /* class LINESTRING */ + rl2GeomExport32 (ptr + 43, ring->points, 1, endian_arch); /* # points */ + ptr += 47; + for (iv = 0; iv < ring->points; iv++) + { + rl2GetPoint (ring->coords, iv, &x, &y); + rl2GeomExport64 (ptr, x, 1, endian_arch); + rl2GeomExport64 (ptr + 8, y, 1, endian_arch); + ptr += 16; + } + *ptr = GAIA_MARK_END; /* END signature */ + return 1; +} RL2_PRIVATE rl2GeometryPtr rl2_curve_from_XY (int points, double *x, double *y) { /* creating a Linestring Geometry from X,Y coordinate arrays */ @@ -1735,11 +1992,21 @@ if (points <= 0 || x == NULL || y == NULL) return 0; geom = rl2CreateGeometry (); ln = rl2AddLinestringToGeometry (geom, points); for (iv = 0; iv < points; iv++) - rl2SetPoint (ln->coords, iv, *(x + iv), *(y + iv)); + { + rl2SetPoint (ln->coords, iv, *(x + iv), *(y + iv)); + if (*(x + iv) < ln->minx) + ln->minx = *(x + iv); + if (*(x + iv) > ln->maxx) + ln->maxx = *(x + iv); + if (*(y + iv) < ln->miny) + ln->miny = *(y + iv); + if (*(y + iv) > ln->maxy) + ln->maxy = *(y + iv); + } return geom; } RL2_PRIVATE double rl2_compute_curve_length (rl2GeometryPtr geom) @@ -1852,10 +2119,18 @@ { double x; double y; rl2GetPoint (ln_in->coords, iv, &x, &y); rl2SetPoint (ln_out->coords, iv, x, y); + if (x < ln_out->minx) + ln_out->minx = x; + if (x > ln_out->maxx) + ln_out->maxx = x; + if (y < ln_out->miny) + ln_out->miny = y; + if (y > ln_out->maxy) + ln_out->maxy = y; } return out; } RL2_PRIVATE rl2GeometryPtr @@ -1872,18 +2147,26 @@ { double x; double y; rl2GetPoint (in->coords, iv, &x, &y); rl2SetPoint (ln_out->coords, iv, x, y); + if (x < ln_out->minx) + ln_out->minx = x; + if (x > ln_out->maxx) + ln_out->maxx = x; + if (y < ln_out->miny) + ln_out->miny = y; + if (y > ln_out->maxy) + ln_out->maxy = y; } return out; } RL2_PRIVATE rl2GeometryPtr rl2_build_circle (double cx, double cy, double radius) { -/* creating a cicrle */ +/* creating a circle */ int iv = 0; double pi = 3.14159265359; double rads; double x; double y; @@ -1893,12 +2176,20 @@ for (rads = 0.0; rads <= (pi * 2.0); rads += pi / 64.0) { x = cx + (radius * cos (rads)); y = cy + (radius * sin (rads)); rl2SetPoint (ln->coords, iv, x, y); + if (x < ln->minx) + ln->minx = x; + if (x > ln->maxx) + ln->maxx = x; + if (y < ln->miny) + ln->miny = y; + if (y > ln->maxy) + ln->maxy = y; iv++; } /* closure */ rl2GetPoint (ln->coords, 0, &x, &y); rl2SetPoint (ln->coords, 128, x, y); return out; } Index: src/rl2auxrender.c ================================================================== --- src/rl2auxrender.c +++ src/rl2auxrender.c @@ -290,12 +290,13 @@ } } static void copy_palette (unsigned char *rgba, unsigned int width, unsigned int height, - unsigned char *inbuf, rl2PalettePtr palette, unsigned char bg_red, - unsigned char bg_green, unsigned char bg_blue) + unsigned char *inbuf, rl2PalettePtr palette, + unsigned char bg_red, unsigned char bg_green, + unsigned char bg_blue) { /* copying from Palette to RGBA */ unsigned int x; unsigned int y; rl2PrivPalettePtr plt = (rl2PrivPalettePtr) palette; @@ -452,12 +453,12 @@ if (aux->base_width == aux->width && aux->base_height == aux->height) { if (aux->out_pixel == RL2_PIXEL_MONOCHROME) { /* Monochrome */ - copy_monochrome (aggreg_rgba, aux->base_width, aux->base_height, - aux->outbuf); + copy_monochrome (aggreg_rgba, aux->base_width, + aux->base_height, aux->outbuf); aux->outbuf = NULL; } else if (aux->out_pixel == RL2_PIXEL_PALETTE) { /* Palette */ @@ -467,12 +468,12 @@ aux->outbuf = NULL; } else if (aux->out_pixel == RL2_PIXEL_GRAYSCALE) { /* Grayscale */ - copy_grayscale (aggreg_rgba, aux->base_width, aux->base_height, - aux->outbuf, aux->bg_red); + copy_grayscale (aggreg_rgba, aux->base_width, + aux->base_height, aux->outbuf, aux->bg_red); aux->outbuf = NULL; } else { /* RGB */ @@ -609,12 +610,12 @@ else { if (!get_payload_from_monochrome_opaque (aux->base_width, aux->base_height, aux->sqlite, aux->minx, aux->miny, aux->maxx, aux->maxy, - aux->srid, aux->outbuf, aux->format_id, aux->quality, - &image, &image_size)) + aux->srid, aux->outbuf, aux->format_id, + aux->quality, &image, &image_size)) { aux->outbuf = NULL; goto error; } } @@ -638,12 +639,12 @@ else { if (!get_payload_from_palette_opaque (aux->base_width, aux->base_height, aux->sqlite, aux->minx, aux->miny, aux->maxx, aux->maxy, - aux->srid, aux->outbuf, aux->palette, aux->format_id, - aux->quality, &image, &image_size)) + aux->srid, aux->outbuf, aux->palette, + aux->format_id, aux->quality, &image, &image_size)) { aux->outbuf = NULL; goto error; } } @@ -666,12 +667,12 @@ else { if (!get_payload_from_grayscale_opaque (aux->base_width, aux->base_height, aux->sqlite, aux->minx, aux->miny, aux->maxx, aux->maxy, - aux->srid, aux->outbuf, aux->format_id, aux->quality, - &image, &image_size)) + aux->srid, aux->outbuf, aux->format_id, + aux->quality, &image, &image_size)) { aux->outbuf = NULL; goto error; } } @@ -695,12 +696,12 @@ else { if (!get_payload_from_rgb_opaque (aux->base_width, aux->base_height, aux->sqlite, aux->minx, aux->miny, aux->maxx, aux->maxy, - aux->srid, aux->outbuf, aux->format_id, aux->quality, - &image, &image_size)) + aux->srid, aux->outbuf, aux->format_id, + aux->quality, &image, &image_size)) { aux->outbuf = NULL; goto error; } } @@ -741,11 +742,11 @@ } aux->outbuf = NULL; } else if (aux->out_pixel == RL2_PIXEL_PALETTE) { - /* Monochrome - upsampled */ + /* Palette - upsampled */ if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG) { if (!get_rgba_from_palette_transparent (aux->base_width, aux->base_height, aux->outbuf, aux->palette, rgba, aux->bg_red, aux->bg_green, @@ -771,12 +772,12 @@ { /* Grayscale */ if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG) { if (!get_rgba_from_grayscale_transparent - (aux->base_width, aux->base_height, aux->outbuf, rgba, - aux->bg_red)) + (aux->base_width, aux->base_height, aux->outbuf, + rgba, aux->bg_red)) { aux->outbuf = NULL; goto error; } } @@ -796,12 +797,12 @@ { /* RGB */ if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG) { if (!get_rgba_from_rgb_transparent - (aux->base_width, aux->base_height, aux->outbuf, rgba, - aux->bg_red, aux->bg_green, aux->bg_blue)) + (aux->base_width, aux->base_height, aux->outbuf, + rgba, aux->bg_red, aux->bg_green, aux->bg_blue)) { aux->outbuf = NULL; goto error; } } @@ -840,12 +841,13 @@ if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG) { if (alpha == NULL) goto error; if (!get_payload_from_gray_rgba_transparent - (aux->width, aux->height, rgb, alpha, aux->format_id, - aux->quality, &image, &image_size, aux->opacity)) + (aux->width, aux->height, rgb, alpha, + aux->format_id, aux->quality, &image, &image_size, + aux->opacity)) goto error; } else { if (alpha != NULL) @@ -864,12 +866,13 @@ if (aux->transparent && aux->format_id == RL2_OUTPUT_FORMAT_PNG) { if (alpha == NULL) goto error; if (!get_payload_from_rgb_rgba_transparent - (aux->width, aux->height, rgb, alpha, aux->format_id, - aux->quality, &image, &image_size, aux->opacity, 0)) + (aux->width, aux->height, rgb, alpha, + aux->format_id, aux->quality, &image, &image_size, + aux->opacity, 0)) goto error; } else { if (alpha != NULL) @@ -953,12 +956,13 @@ free (alpha); return 0; } static int -aux_shaded_relief_mask (struct aux_renderer *aux, double relief_factor, - unsigned char **shaded_relief) +aux_shaded_relief_mask (struct aux_renderer *aux, + int by_section, sqlite3_int64 section_id, + double relief_factor, unsigned char **shaded_relief) { /* attempting to create a Shaded Relief brightness-only mask */ rl2GraphicsBitmapPtr base_img = NULL; rl2GraphicsContextPtr ctx = NULL; float *shr_mask; @@ -979,14 +983,14 @@ if (coverage == NULL) return 0; scale_factor = rl2_get_shaded_relief_scale_factor (aux->sqlite, coverage); if (rl2_build_shaded_relief_mask - (aux->sqlite, aux->max_threads, aux->coverage, relief_factor, - scale_factor, aux->base_width, aux->base_height, aux->minx, aux->miny, - aux->maxx, aux->maxy, aux->xx_res, aux->yy_res, &shr_mask, - &shr_size) != RL2_OK) + (aux->sqlite, aux->max_threads, aux->coverage, by_section, section_id, + relief_factor, scale_factor, aux->base_width, aux->base_height, + aux->minx, aux->miny, aux->maxx, aux->maxy, aux->xx_res, aux->yy_res, + &shr_mask, &shr_size) != RL2_OK) return 0; /* allocating the RGBA buffer */ rgba = malloc (aux->base_width * aux->base_height * 4); if (rgba == NULL) @@ -1327,11 +1331,11 @@ { /* requesting a shaded relief mask */ if (shaded_relief_mask != NULL) free (shaded_relief_mask); if (!aux_shaded_relief_mask - (&aux, symbolizer->reliefFactor, &shaded_relief_mask)) + (&aux, 0, 0, symbolizer->reliefFactor, &shaded_relief_mask)) goto error; } else { /* rendering an image */ @@ -1536,11 +1540,12 @@ rl2CoveragePtr cvg, unsigned int width, unsigned int height, double minx, double miny, double maxx, double maxy, double x_res, - double y_res, unsigned char **buffer, + double y_res, + unsigned char **buffer, int *buf_size, rl2PalettePtr * palette, unsigned char *out_pixel, unsigned char bg_red, unsigned char bg_green, @@ -1674,10 +1679,12 @@ int level_id; int scale; int xscale; unsigned int w; unsigned int h; + unsigned int w2; + unsigned int h2; int base_x; int base_y; unsigned char *bufpix = NULL; int bufpix_size; double img_res_x = (maxx - minx) / (double) width; @@ -1684,12 +1691,10 @@ double img_res_y = (maxy - miny) / (double) height; double mnx = minx; double mny = miny; double mxx = maxx; double mxy = maxy; - if (section_id > 3) - continue; /* normalizing the visible portion of the Section */ if (mnx < section_minx) mnx = section_minx; if (mny < section_miny) mny = section_miny; @@ -1708,20 +1713,53 @@ h = (unsigned int) ((mxy - mny) / yy_res); if (((double) h * yy_res) < (mxy - mny)) h++; base_x = (int) ((mnx - minx) / img_res_x); base_y = (int) ((maxy - mxy) / img_res_y); + if (rl2_get_raw_raster_data_common (handle, max_threads, cvg, 1, section_id, w, h, mnx, mny, mxx, mxy, xx_res, yy_res, &bufpix, &bufpix_size, palette, *out_pixel, no_data, xstyle, stats) != RL2_OK) goto error; + + w2 = (unsigned int) ((mxx - mnx) / img_res_x); + if (((double) w2 * img_res_x) < (mxx - mnx)) + w2++; + h2 = (unsigned int) ((mxy - mny) / img_res_y); + if (((double) h2 * img_res_y) < (mxy - mny)) + h2++; + if (w == w2 && h == h2) + { + /* already rescaled */ + } + else + { + /* rescaling the pixbuf */ + unsigned char *rescaled = NULL; + int pix_sz = 1; + if (*out_pixel == RL2_PIXEL_RGB) + pix_sz = 3; + rescaled = malloc (pix_sz * w2 * h2); + if (rescaled == NULL) + { + fprintf (stderr, + "rl2_get_raw_raster_data_mixed_resolutions: Insufficient Memory !!!\n"); + goto error; + } + if (!rl2_rescale_pixbuf + (bufpix, w, h, *out_pixel, rescaled, w2, h2)) + goto error; + free (bufpix); + bufpix = rescaled; + } + if (*out_pixel == RL2_PIXEL_RGB) - do_copy_rgb (outbuf, bufpix, width, height, w, h, base_x, + do_copy_rgb (outbuf, bufpix, width, height, w2, h2, base_x, base_y, bg_red, bg_green, bg_blue); else - do_copy_gray (outbuf, bufpix, width, height, w, h, base_x, + do_copy_gray (outbuf, bufpix, width, height, w2, h2, base_x, base_y, bg_red); free (bufpix); } else { @@ -1747,201 +1785,31 @@ if (outbuf != NULL) free (outbuf); return RL2_ERROR; } -static rl2GraphicsPatternPtr -load_external_graphic_from_dbms (sqlite3 * handle, rl2PrivGraphicPtr graphic) -{ -/* attempting to load an External Graphic from the DBMS */ - int ret; - sqlite3_stmt *stmt = NULL; - const char *sql; - const char *xlink_href = NULL; - rl2GraphicsPatternPtr pattern = NULL; - rl2PrivGraphicItemPtr item; - - if (graphic == NULL) - return NULL; - /* searching for an xlink_href pseudo-URL */ - item = graphic->first; - while (item != NULL) - { - if (item->type == RL2_EXTERNAL_GRAPHIC && item->item != NULL) - { - rl2PrivExternalGraphicPtr ext = - (rl2PrivExternalGraphicPtr) (item->item); - if (ext->xlink_href != NULL) - { - xlink_href = ext->xlink_href; - break; - } - } - item = item->next; - } - if (xlink_href == NULL) - return NULL; - - sql = "SELECT resource, GetMimeType(resource) FROM SE_external_graphics " - "WHERE xlink_href = ?"; - ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL); - if (ret != SQLITE_OK) - return NULL; - - sqlite3_reset (stmt); - sqlite3_clear_bindings (stmt); - sqlite3_bind_text (stmt, 1, xlink_href, strlen (xlink_href), SQLITE_STATIC); - while (1) - { - /* scrolling the result set rows */ - ret = sqlite3_step (stmt); - if (ret == SQLITE_DONE) - break; /* end of result set */ - if (ret == SQLITE_ROW) - { - rl2RasterPtr raster = NULL; - if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB - && sqlite3_column_type (stmt, 1) == SQLITE_TEXT) - { - const unsigned char *blob = sqlite3_column_blob (stmt, 0); - int blob_sz = sqlite3_column_bytes (stmt, 0); - const char *mime_type = - (const char *) sqlite3_column_text (stmt, 1); - if (strcmp (mime_type, "image/gif") == 0) - raster = rl2_raster_from_gif (blob, blob_sz); - if (strcmp (mime_type, "image/png") == 0) - raster = rl2_raster_from_png (blob, blob_sz, 1); - if (strcmp (mime_type, "image/jpeg") == 0) - raster = rl2_raster_from_jpeg (blob, blob_sz); - if (strcmp (mime_type, "image/tiff") == 0) - raster = rl2_raster_from_tiff (blob, blob_sz); - } - if (raster != NULL) - { - unsigned char *rgba; - int rgba_sz; - unsigned int width; - unsigned int height; - if (rl2_get_raster_size (raster, &width, &height) != - RL2_OK) - { - rl2_destroy_raster (raster); - goto error; - } - if (rl2_raster_data_to_RGBA (raster, &rgba, &rgba_sz) != - RL2_OK) - { - rl2_destroy_raster (raster); - goto error; - } - pattern = - rl2_graph_create_pattern (rgba, width, height, 0); - rl2_destroy_raster (raster); - } - } - else - { - fprintf (stderr, "SQL error: %s\n%s\n", sql, - sqlite3_errmsg (handle)); - goto error; - } - } - return pattern; - - error: - if (stmt != NULL) - sqlite3_finalize (stmt); - return NULL; -} - -static rl2GraphicsBitmapPtr -load_external_bitmap_from_dbms (sqlite3 * handle, const char *xlink_href) -{ -/* attempting to load an External Graphic from the DBMS */ - int ret; - sqlite3_stmt *stmt = NULL; - const char *sql; - rl2GraphicsBitmapPtr bitmap = NULL; - - if (xlink_href == NULL) - return NULL; - - sql = "SELECT resource, GetMimeType(resource) FROM SE_external_graphics " - "WHERE xlink_href = ?"; - ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL); - if (ret != SQLITE_OK) - return NULL; - - sqlite3_reset (stmt); - sqlite3_clear_bindings (stmt); - sqlite3_bind_text (stmt, 1, xlink_href, strlen (xlink_href), SQLITE_STATIC); - while (1) - { - /* scrolling the result set rows */ - ret = sqlite3_step (stmt); - if (ret == SQLITE_DONE) - break; /* end of result set */ - if (ret == SQLITE_ROW) - { - rl2RasterPtr raster = NULL; - if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB - && sqlite3_column_type (stmt, 1) == SQLITE_TEXT) - { - const unsigned char *blob = sqlite3_column_blob (stmt, 0); - int blob_sz = sqlite3_column_bytes (stmt, 0); - const char *mime_type = - (const char *) sqlite3_column_text (stmt, 1); - if (strcmp (mime_type, "image/gif") == 0) - raster = rl2_raster_from_gif (blob, blob_sz); - if (strcmp (mime_type, "image/png") == 0) - raster = rl2_raster_from_png (blob, blob_sz, 1); - if (strcmp (mime_type, "image/jpeg") == 0) - raster = rl2_raster_from_jpeg (blob, blob_sz); - if (strcmp (mime_type, "image/tiff") == 0) - raster = rl2_raster_from_tiff (blob, blob_sz); - } - if (raster != NULL) - { - unsigned char *rgba; - int rgba_sz; - unsigned int width; - unsigned int height; - if (rl2_get_raster_size (raster, &width, &height) != - RL2_OK) - { - rl2_destroy_raster (raster); - goto error; - } - if (rl2_raster_data_to_RGBA (raster, &rgba, &rgba_sz) != - RL2_OK) - { - rl2_destroy_raster (raster); - goto error; - } - bitmap = rl2_graph_create_bitmap (rgba, width, height); - rl2_destroy_raster (raster); - } - } - else - { - fprintf (stderr, "SQL error: %s\n%s\n", sql, - sqlite3_errmsg (handle)); - goto error; - } - } - return bitmap; - - error: - if (stmt != NULL) - sqlite3_finalize (stmt); - return NULL; +static int +point_bbox_matches (rl2PointPtr point, double minx, double miny, double maxx, + double maxy) +{ +/* checks if the Point is visible */ + if (minx > point->x) + return 0; + if (maxx < point->x) + return 0; + if (miny > point->y) + return 0; + if (maxy < point->y) + return 0; + return 1; } static void draw_points (rl2GraphicsContextPtr ctx, sqlite3 * handle, rl2PrivVectorSymbolizerPtr sym, int height, double minx, - double miny, double x_res, double y_res, rl2GeometryPtr geom) + double miny, double maxx, double maxy, double x_res, + double y_res, rl2GeometryPtr geom) { /* drawing Point-type features */ rl2PrivVectorSymbolizerItemPtr item; rl2PointPtr point; @@ -1970,11 +1838,11 @@ int stroke = 0; int pen_cap; int pen_join; double opacity; unsigned char norm_opacity; - rl2GraphicsBitmapPtr pattern = NULL; + rl2GraphicsPatternPtr pattern = NULL; rl2GraphicsPatternPtr pattern_fill = NULL; rl2GraphicsPatternPtr pattern_stroke = NULL; if (graphic->type == RL2_MARK_GRAPHIC) { @@ -1987,19 +1855,101 @@ if (mark->fill != NULL) { if (mark->fill->graphic != NULL) { /* external Graphic fill */ - pattern_fill = - load_external_graphic_from_dbms - (handle, mark->fill->graphic); + const char *xlink_href = NULL; + int recolor = 0; + unsigned char red; + unsigned char green; + unsigned char blue; + pattern_fill = NULL; + if (mark->fill->graphic->first != + NULL) + { + if (mark->fill-> + graphic->first->type == + RL2_EXTERNAL_GRAPHIC) + { + rl2PrivExternalGraphicPtr + ext = + (rl2PrivExternalGraphicPtr) + (mark-> + fill->graphic-> + first->item); + xlink_href = + ext->xlink_href; + if (ext->first != + NULL) + { + recolor = 1; + red = + ext-> + first->red; + green = + ext-> + first->green; + blue = + ext-> + first->blue; + } + } + } + if (xlink_href != NULL) + pattern_fill = + rl2_create_pattern_from_external_graphic + (handle, xlink_href, 1); if (pattern_fill != NULL) { + if (recolor) + { + /* attempting to recolor the External Graphic resource */ + rl2_graph_pattern_recolor + (pattern_fill, + red, green, + blue); + } + if (mark->fill->opacity <= + 0.0) + norm_opacity = 0; + else if (mark-> + fill->opacity >= + 1.0) + norm_opacity = 255; + else + { + opacity = + 255.0 * + mark-> + fill->opacity; + if (opacity <= 0.0) + norm_opacity = 0; + else if (opacity >= + 255.0) + norm_opacity = + 255; + else + norm_opacity = + opacity; + } + if (norm_opacity < 1.0) + rl2_graph_pattern_transparency + (pattern_fill, + norm_opacity); rl2_graph_set_pattern_brush (ctx, pattern_fill); - fill = 1; + } + else + { + /* invalid Pattern: defaulting to a Gray brush */ + rl2_graph_set_brush (ctx, + 128, + 128, + 128, + 255); } + fill = 1; } else { /* solid RGB fill */ if (gr->opacity <= 0.0) @@ -2030,74 +1980,153 @@ } if (mark->stroke != NULL) { if (mark->stroke->graphic != NULL) { - /* external Graphic stroke */ - pattern_stroke = - load_external_graphic_from_dbms - (handle, - mark->stroke->graphic); - if (pattern_stroke != NULL) + const char *xlink_href = NULL; + int recolor = 0; + unsigned char red; + unsigned char green; + unsigned char blue; + pattern_stroke = NULL; + if (mark->stroke-> + graphic->first != NULL) { - switch (mark-> - stroke->linecap) + if (mark->stroke-> + graphic->first->type == + RL2_EXTERNAL_GRAPHIC) { - case RL2_STROKE_LINECAP_ROUND: - pen_cap = - RL2_PEN_CAP_ROUND; - break; - case RL2_STROKE_LINECAP_SQUARE: - pen_cap = - RL2_PEN_CAP_SQUARE; - break; - default: - pen_cap = - RL2_PEN_CAP_BUTT; - break; - }; - switch (mark-> - stroke->linejoin) + rl2PrivExternalGraphicPtr + ext = + (rl2PrivExternalGraphicPtr) + (mark-> + stroke->graphic-> + first->item); + xlink_href = + ext->xlink_href; + if (ext->first != + NULL) + { + recolor = 1; + red = + ext-> + first->red; + green = + ext-> + first->green; + blue = + ext-> + first->blue; + } + } + } + if (xlink_href != NULL) + pattern_stroke = + rl2_create_pattern_from_external_graphic + (handle, xlink_href, 1); + if (pattern != NULL) + { + if (recolor) { - case RL2_STROKE_LINEJOIN_BEVEL: - pen_join = - RL2_PEN_JOIN_BEVEL; - break; - case RL2_STROKE_LINEJOIN_ROUND: - pen_join = - RL2_PEN_JOIN_ROUND; - break; - default: - pen_join = - RL2_PEN_JOIN_MITER; - break; - }; - if (mark-> - stroke->dash_count > 0 - && mark-> - stroke->dash_list != - NULL) - rl2_graph_set_pattern_dashed_pen - (ctx, - pattern_stroke, - mark-> - stroke->width, - pen_cap, pen_join, - mark-> - stroke->dash_count, - mark-> - stroke->dash_list, - mark-> - stroke->dash_offset); + /* attempting to recolor the External Graphic resource */ + rl2_graph_pattern_recolor + (pattern_stroke, + red, green, + blue); + } + if (mark->stroke->opacity <= + 0.0) + norm_opacity = 0; + else if (mark-> + stroke->opacity >= + 1.0) + norm_opacity = 255; else - rl2_graph_set_pattern_solid_pen - (ctx, - pattern_stroke, - mark-> - stroke->width, - pen_cap, pen_join); - stroke = 1; + { + opacity = + 255.0 * + mark-> + stroke->opacity; + if (opacity <= 0.0) + norm_opacity = 0; + else if (opacity >= + 255.0) + norm_opacity = + 255; + else + norm_opacity = + opacity; + } + if (norm_opacity < 1.0) + rl2_graph_pattern_transparency + (pattern_stroke, + norm_opacity); + if (pattern_stroke != NULL) + { + switch + (mark-> + stroke->linecap) + { + case RL2_STROKE_LINECAP_ROUND: + pen_cap = + RL2_PEN_CAP_ROUND; + break; + case RL2_STROKE_LINECAP_SQUARE: + pen_cap = + RL2_PEN_CAP_SQUARE; + break; + default: + pen_cap = + RL2_PEN_CAP_BUTT; + break; + }; + switch + (mark-> + stroke->linejoin) + { + case RL2_STROKE_LINEJOIN_BEVEL: + pen_join = + RL2_PEN_JOIN_BEVEL; + break; + case RL2_STROKE_LINEJOIN_ROUND: + pen_join = + RL2_PEN_JOIN_ROUND; + break; + default: + pen_join = + RL2_PEN_JOIN_MITER; + break; + }; + if (mark-> + stroke->dash_count + > 0 + && mark-> + stroke->dash_list + != NULL) + rl2_graph_set_pattern_dashed_pen + (ctx, + pattern_stroke, + mark-> + stroke->width, + pen_cap, + pen_join, + mark-> + stroke->dash_count, + mark-> + stroke->dash_list, + mark-> + stroke->dash_offset); + else + rl2_graph_set_pattern_solid_pen + (ctx, + pattern_stroke, + mark-> + stroke->width, + pen_cap, + pen_join); + stroke = 1; + } } } else { /* solid RGB stroke */ @@ -2153,236 +2182,384 @@ mark->stroke->blue, norm_opacity, mark->stroke->width, pen_cap, pen_join, - mark->stroke->dash_count, - mark->stroke->dash_list, - mark->stroke->dash_offset); + mark-> + stroke->dash_count, + mark-> + stroke->dash_list, + mark-> + stroke->dash_offset); else - rl2_graph_set_solid_pen (ctx, - mark->stroke->red, - mark->stroke->green, - mark->stroke->blue, - norm_opacity, - mark->stroke->width, - pen_cap, - pen_join); + rl2_graph_set_solid_pen + (ctx, mark->stroke->red, + mark->stroke->green, + mark->stroke->blue, + norm_opacity, + mark->stroke->width, + pen_cap, pen_join); stroke = 1; } } } } if (graphic->type == RL2_EXTERNAL_GRAPHIC) { rl2PrivExternalGraphicPtr ext = (rl2PrivExternalGraphicPtr) (graphic->item); + const char *xlink_href = NULL; + int recolor = 0; + unsigned char red; + unsigned char green; + unsigned char blue; + pattern = NULL; if (ext != NULL) { is_external = 1; - pattern = - load_external_bitmap_from_dbms (handle, - ext->xlink_href); + if (ext->xlink_href != NULL) + xlink_href = ext->xlink_href; + if (ext->first != NULL) + { + recolor = 1; + red = ext->first->red; + green = ext->first->green; + blue = ext->first->blue; + } + if (xlink_href != NULL) + { + /* first attempt: Bitmap */ + pattern = + rl2_create_pattern_from_external_graphic + (handle, xlink_href, 1); + if (pattern == NULL) + { + /* second attempt: SVG */ + pattern = + rl2_create_pattern_from_external_svg + (handle, xlink_href, + point_sym->graphic->size); + } + } + } + if (pattern != NULL) + { + if (recolor) + { + /* attempting to recolor the External Graphic resource */ + rl2_graph_pattern_recolor (pattern, + red, green, + blue); + } + if (point_sym->graphic->opacity <= 0.0) + norm_opacity = 0; + else if (point_sym->graphic->opacity >= 1.0) + norm_opacity = 255; + else + { + opacity = + 255.0 * point_sym->graphic->opacity; + if (opacity <= 0.0) + norm_opacity = 0; + else if (opacity >= 255.0) + norm_opacity = 255; + else + norm_opacity = opacity; + } + if (norm_opacity < 1.0) + rl2_graph_pattern_transparency + (pattern, norm_opacity); + rl2_graph_set_pattern_brush (ctx, pattern); + } + else + { + /* invalid Pattern: defaulting to a Gray brush */ + rl2_graph_set_brush (ctx, 128, 128, 128, 255); } } /* actual Point rendering */ point = geom->first_point; while (point) { /* drawing a POINT */ - double x = (point->x - minx) / x_res; - double y = - (double) height - ((point->y - miny) / y_res); - double size2 = gr->size / 2.0; - double size4 = gr->size / 4.0; - double size6 = gr->size / 6.0; - double size13 = gr->size / 3.0; - double size23 = (gr->size / 3.0) * 2.0; - int i; - double rads; - if (size2 <= 0.0) - size2 = 1.0; - if (size4 <= 0.0) - size4 = 1.0; - if (size6 <= 0.0) - size6 = 1.0; - if (size13 <= 0.0) - size13 = 1.0; - if (size23 <= 0.0) - size23 = 1.0; - if (is_mark) - { - /* drawing a well-known Mark */ - switch (well_known_type) - { - case RL2_GRAPHIC_MARK_CIRCLE: - rads = 0.0; - for (i = 0; i < 32; i++) + if (point_bbox_matches + (point, minx, miny, maxx, maxy)) + { + double x = (point->x - minx) / x_res; + double y = + (double) height - + ((point->y - miny) / y_res); + double size2 = gr->size / 2.0; + double size4 = gr->size / 4.0; + double size6 = gr->size / 6.0; + double size13 = gr->size / 3.0; + double size23 = (gr->size / 3.0) * 2.0; + int i; + double rads; + if (size2 <= 0.0) + size2 = 1.0; + if (size4 <= 0.0) + size4 = 1.0; + if (size6 <= 0.0) + size6 = 1.0; + if (size13 <= 0.0) + size13 = 1.0; + if (size23 <= 0.0) + size23 = 1.0; + if (is_mark) + { + /* drawing a well-known Mark */ + switch (well_known_type) { - double tic = 6.28318530718 / 32.0; - double cx = - x + (size2 * sin (rads)); - double cy = - y + (size2 * cos (rads)); - if (i == 0) - rl2_graph_move_to_point (ctx, - cx, - cy); - else - rl2_graph_add_line_to_path - (ctx, cx, cy); - rads += tic; - } - rl2_graph_close_subpath (ctx); - break; - case RL2_GRAPHIC_MARK_TRIANGLE: - rl2_graph_move_to_point (ctx, x, - y - size23); - rl2_graph_add_line_to_path (ctx, - x - size2, - y + size13); - rl2_graph_add_line_to_path (ctx, - x + size2, - y + size13); - rl2_graph_close_subpath (ctx); - break; - case RL2_GRAPHIC_MARK_STAR: - rads = 3.14159265359; - for (i = 0; i < 10; i++) + case RL2_GRAPHIC_MARK_CIRCLE: + rads = 0.0; + for (i = 0; i < 32; i++) + { + double tic = + 6.28318530718 / 32.0; + double cx = + x + + (size2 * sin (rads)); + double cy = + y + + (size2 * cos (rads)); + if (i == 0) + rl2_graph_move_to_point + (ctx, cx, cy); + else + rl2_graph_add_line_to_path + (ctx, cx, cy); + rads += tic; + } + rl2_graph_close_subpath (ctx); + break; + case RL2_GRAPHIC_MARK_TRIANGLE: + rl2_graph_move_to_point (ctx, x, + y - + size23); + rl2_graph_add_line_to_path (ctx, + x - + size2, + y + + size13); + rl2_graph_add_line_to_path (ctx, + x + + size2, + y + + size13); + rl2_graph_close_subpath (ctx); + break; + case RL2_GRAPHIC_MARK_STAR: + rads = 3.14159265359; + for (i = 0; i < 10; i++) + { + double tic = + (i % 2) ? size6 : size2; + double cx = + x + (tic * sin (rads)); + double cy = + y + (tic * cos (rads)); + if (i == 0) + rl2_graph_move_to_point + (ctx, cx, cy); + else + rl2_graph_add_line_to_path + (ctx, cx, cy); + rads += 0.628318530718; + } + rl2_graph_close_subpath (ctx); + break; + case RL2_GRAPHIC_MARK_CROSS: + rl2_graph_move_to_point (ctx, + x - + size6, + y - + size2); + rl2_graph_add_line_to_path (ctx, + x + + size6, + y - + size2); + rl2_graph_add_line_to_path (ctx, + x + + size6, + y - + size6); + rl2_graph_add_line_to_path (ctx, + x + + size2, + y - + size6); + rl2_graph_add_line_to_path (ctx, + x + + size2, + y + + size6); + rl2_graph_add_line_to_path (ctx, + x + + size6, + y + + size6); + rl2_graph_add_line_to_path (ctx, + x + + size6, + y + + size2); + rl2_graph_add_line_to_path (ctx, + x - + size6, + y + + size2); + rl2_graph_add_line_to_path (ctx, + x - + size6, + y + + size6); + rl2_graph_add_line_to_path (ctx, + x - + size2, + y + + size6); + rl2_graph_add_line_to_path (ctx, + x - + size2, + y - + size6); + rl2_graph_add_line_to_path (ctx, + x - + size6, + y - + size6); + rl2_graph_close_subpath (ctx); + break; + case RL2_GRAPHIC_MARK_X: + rl2_graph_move_to_point (ctx, + x - + size2, + y - + size2); + rl2_graph_add_line_to_path (ctx, + x - + size4, + y - + size2); + rl2_graph_add_line_to_path (ctx, + x, + y - + size6); + rl2_graph_add_line_to_path (ctx, + x + + size6, + y - + size2); + rl2_graph_add_line_to_path (ctx, + x + + size2, + y - + size2); + rl2_graph_add_line_to_path (ctx, + x + + size4, + y); + rl2_graph_add_line_to_path (ctx, + x + + size2, + y + + size2); + rl2_graph_add_line_to_path (ctx, + x + + size4, + y + + size2); + rl2_graph_add_line_to_path (ctx, + x, + y + + size6); + rl2_graph_add_line_to_path (ctx, + x - + size6, + y + + size2); + rl2_graph_add_line_to_path (ctx, + x - + size2, + y + + size2); + rl2_graph_add_line_to_path (ctx, + x - + size4, + y); + rl2_graph_close_subpath (ctx); + break; + case RL2_GRAPHIC_MARK_SQUARE: + default: + rl2_graph_move_to_point (ctx, + x - + size2, + y - + size2); + rl2_graph_add_line_to_path (ctx, + x - + size2, + y + + size2); + rl2_graph_add_line_to_path (ctx, + x + + size2, + y + + size2); + rl2_graph_add_line_to_path (ctx, + x + + size2, + y - + size2); + rl2_graph_close_subpath (ctx); + break; + }; + if (fill) { - double tic = - (i % 2) ? size6 : size2; - double cx = - x + (tic * sin (rads)); - double cy = - y + (tic * cos (rads)); - if (i == 0) - rl2_graph_move_to_point (ctx, - cx, - cy); + if (stroke) + rl2_graph_fill_path (ctx, + RL2_PRESERVE_PATH); else - rl2_graph_add_line_to_path - (ctx, cx, cy); - rads += 0.628318530718; + rl2_graph_fill_path (ctx, + RL2_CLEAR_PATH); } - rl2_graph_close_subpath (ctx); - break; - case RL2_GRAPHIC_MARK_CROSS: - rl2_graph_move_to_point (ctx, x - size6, - y - size2); - rl2_graph_add_line_to_path (ctx, - x + size6, - y - size2); - rl2_graph_add_line_to_path (ctx, - x + size6, - y - size6); - rl2_graph_add_line_to_path (ctx, - x + size2, - y - size6); - rl2_graph_add_line_to_path (ctx, - x + size2, - y + size6); - rl2_graph_add_line_to_path (ctx, - x + size6, - y + size6); - rl2_graph_add_line_to_path (ctx, - x + size6, - y + size2); - rl2_graph_add_line_to_path (ctx, - x - size6, - y + size2); - rl2_graph_add_line_to_path (ctx, - x - size6, - y + size6); - rl2_graph_add_line_to_path (ctx, - x - size2, - y + size6); - rl2_graph_add_line_to_path (ctx, - x - size2, - y - size6); - rl2_graph_add_line_to_path (ctx, - x - size6, - y - size6); - rl2_graph_close_subpath (ctx); - break; - case RL2_GRAPHIC_MARK_X: - rl2_graph_move_to_point (ctx, x - size2, - y - size2); - rl2_graph_add_line_to_path (ctx, - x - size4, - y - size2); - rl2_graph_add_line_to_path (ctx, x, - y - size6); - rl2_graph_add_line_to_path (ctx, - x + size6, - y - size2); - rl2_graph_add_line_to_path (ctx, - x + size2, - y - size2); - rl2_graph_add_line_to_path (ctx, - x + size4, - y); - rl2_graph_add_line_to_path (ctx, - x + size2, - y + size2); - rl2_graph_add_line_to_path (ctx, - x + size4, - y + size2); - rl2_graph_add_line_to_path (ctx, x, - y + size6); - rl2_graph_add_line_to_path (ctx, - x - size6, - y + size2); - rl2_graph_add_line_to_path (ctx, - x - size2, - y + size2); - rl2_graph_add_line_to_path (ctx, - x - size4, - y); - rl2_graph_close_subpath (ctx); - break; - case RL2_GRAPHIC_MARK_SQUARE: - default: - rl2_graph_move_to_point (ctx, x - size2, - y - size2); - rl2_graph_add_line_to_path (ctx, - x - size2, - y + size2); - rl2_graph_add_line_to_path (ctx, - x + size2, - y + size2); - rl2_graph_add_line_to_path (ctx, - x + size2, - y - size2); - rl2_graph_close_subpath (ctx); - break; - }; - if (fill) - { if (stroke) - rl2_graph_fill_path (ctx, - RL2_PRESERVE_PATH); - else - rl2_graph_fill_path (ctx, - RL2_CLEAR_PATH); + rl2_graph_stroke_path (ctx, + RL2_CLEAR_PATH); } - if (stroke) - rl2_graph_stroke_path (ctx, - RL2_CLEAR_PATH); - } - if (is_external && pattern != NULL) - { - /* drawing an External Graphic bitmap */ - rl2_graph_draw_bitmap (ctx, pattern, x, y); + if (is_external && pattern != NULL) + { + /* drawing an External Graphic pattern */ + unsigned int width; + unsigned int height; + rl2_graph_get_pattern_size (pattern, + &width, + &height); + double out_width = width; + double out_height = height; + rl2_graph_draw_graphic_symbol (ctx, + pattern, + out_width, + out_height, + x + + point_sym->graphic->displacement_x, + y - + point_sym->graphic->displacement_y, + point_sym->graphic->rotation, + point_sym->graphic->anchor_point_x, + point_sym->graphic->anchor_point_y); + } } point = point->next; } /* releasing Patterns */ if (pattern != NULL) - rl2_graph_destroy_bitmap (pattern); + rl2_graph_destroy_pattern (pattern); if (pattern_fill != NULL) { rl2_graph_release_pattern_pen (ctx); rl2_graph_destroy_pattern (pattern_fill); } @@ -2395,20 +2572,37 @@ } } item = item->next; } } + +static int +linestring_bbox_matches (rl2LinestringPtr ring, double minx, double miny, + double maxx, double maxy) +{ +/* checks if the Linestring BBOX is visible */ + if (minx > ring->maxx) + return 0; + if (maxx < ring->minx) + return 0; + if (miny > ring->maxy) + return 0; + if (maxy < ring->miny) + return 0; + return 1; +} static void draw_lines (rl2GraphicsContextPtr ctx, sqlite3 * handle, rl2PrivVectorSymbolizerPtr sym, int height, double minx, - double miny, double x_res, double y_res, rl2GeometryPtr geom) + double miny, double maxx, double maxy, double x_res, double y_res, + rl2GeometryPtr geom) { /* drawing Linear-type features */ rl2PrivVectorSymbolizerItemPtr item; - int pen_cap; - int pen_join; + int pen_cap = RL2_PEN_CAP_BUTT; + int pen_join = RL2_PEN_JOIN_MITER; double opacity; unsigned char norm_opacity; rl2LinestringPtr line; rl2GraphicsPatternPtr pattern = NULL; rl2PrivMultiStrokePtr multi_stroke = rl2_create_multi_stroke (); @@ -2423,38 +2617,66 @@ if (line_sym->stroke != NULL) { if (line_sym->stroke->graphic != NULL) { /* external Graphic stroke */ - pattern = load_external_graphic_from_dbms (handle, - line_sym->stroke->graphic); + const char *xlink_href = NULL; + int recolor = 0; + unsigned char red; + unsigned char green; + unsigned char blue; + pattern = NULL; + if (line_sym->stroke->graphic->first != NULL) + { + if (line_sym->stroke->graphic->first->type == + RL2_EXTERNAL_GRAPHIC) + { + rl2PrivExternalGraphicPtr ext = + (rl2PrivExternalGraphicPtr) + (line_sym->stroke->graphic-> + first->item); + xlink_href = ext->xlink_href; + if (ext->first != NULL) + { + recolor = 1; + red = ext->first->red; + green = ext->first->green; + blue = ext->first->blue; + } + } + } + if (xlink_href != NULL) + pattern = + rl2_create_pattern_from_external_graphic + (handle, xlink_href, 1); if (pattern != NULL) { - switch (line_sym->stroke->linecap) - { - case RL2_STROKE_LINECAP_ROUND: - pen_cap = RL2_PEN_CAP_ROUND; - break; - case RL2_STROKE_LINECAP_SQUARE: - pen_cap = RL2_PEN_CAP_SQUARE; - break; - default: - pen_cap = RL2_PEN_CAP_BUTT; - break; - }; - switch (line_sym->stroke->linejoin) - { - case RL2_STROKE_LINEJOIN_BEVEL: - pen_join = RL2_PEN_JOIN_BEVEL; - break; - case RL2_STROKE_LINEJOIN_ROUND: - pen_join = RL2_PEN_JOIN_ROUND; - break; - default: - pen_join = RL2_PEN_JOIN_MITER; - break; - }; + if (recolor) + { + /* attempting to recolor the External Graphic resource */ + rl2_graph_pattern_recolor (pattern, + red, green, + blue); + } + if (line_sym->stroke->opacity <= 0.0) + norm_opacity = 0; + else if (line_sym->stroke->opacity >= 1.0) + norm_opacity = 255; + else + { + opacity = + 255.0 * line_sym->stroke->opacity; + if (opacity <= 0.0) + norm_opacity = 0; + else if (opacity >= 255.0) + norm_opacity = 255; + else + norm_opacity = opacity; + } + if (norm_opacity < 1.0) + rl2_graph_pattern_transparency + (pattern, norm_opacity); if (line_sym->stroke->dash_count > 0 && line_sym->stroke->dash_list != NULL) rl2_add_pattern_to_multi_stroke_dash (multi_stroke, pattern, line_sym->stroke->width, pen_cap, @@ -2466,10 +2688,15 @@ rl2_add_pattern_to_multi_stroke (multi_stroke, pattern, line_sym->stroke->width, pen_cap, pen_join); } + else + { + /* invalid Pattern: defaulting to a Gray brush */ + rl2_graph_set_brush (ctx, 128, 128, 128, 255); + } } else { /* solid RGB stroke */ if (line_sym->stroke->opacity <= 0.0) @@ -2549,105 +2776,127 @@ line = geom->first_linestring; while (line) { /* drawing a LINESTRING */ - rl2PrivMultiStrokeItemPtr stroke_item; - int iv; - double dx; - double dy; - int x; - int y; - int lastX = 0; - int lastY = 0; - for (iv = 0; iv < line->points; iv++) - { - rl2GetPoint (line->coords, iv, &dx, &dy); - x = (int) ((dx - minx) / x_res); - y = height - (int) ((dy - miny) / y_res); - if (iv == 0) - { - rl2_graph_move_to_point (ctx, x, y); - lastX = x; - lastY = y; - } - else - { - if (x == lastX && y == lastY) - ; - else - { - rl2_graph_add_line_to_path (ctx, x, y); + if (linestring_bbox_matches (line, minx, miny, maxx, maxy)) + { + rl2PrivMultiStrokeItemPtr stroke_item; + int iv; + double dx; + double dy; + int x; + int y; + int lastX = 0; + int lastY = 0; + for (iv = 0; iv < line->points; iv++) + { + rl2GetPoint (line->coords, iv, &dx, &dy); + x = (int) ((dx - minx) / x_res); + y = height - (int) ((dy - miny) / y_res); + if (iv == 0) + { + rl2_graph_move_to_point (ctx, x, y); lastX = x; lastY = y; } - } - } - stroke_item = multi_stroke->first; - while (stroke_item != NULL) - { - /* applying all strokes, one after the other */ - if (stroke_item->dash_count > 0 - && stroke_item->dash_list != NULL) - { - if (stroke_item->pattern != NULL) - rl2_graph_set_pattern_dashed_pen (ctx, - stroke_item->pattern, - stroke_item->width, - stroke_item->pen_cap, - stroke_item->pen_join, - stroke_item->dash_count, - stroke_item->dash_list, - stroke_item->dash_offset); + else + { + if (x == lastX && y == lastY) + ; + else + { + rl2_graph_add_line_to_path (ctx, x, y); + lastX = x; + lastY = y; + } + } + } + stroke_item = multi_stroke->first; + while (stroke_item != NULL) + { + /* applying all strokes, one after the other */ + if (stroke_item->dash_count > 0 + && stroke_item->dash_list != NULL) + { + if (stroke_item->pattern != NULL) + rl2_graph_set_pattern_dashed_pen (ctx, + stroke_item->pattern, + stroke_item->width, + stroke_item->pen_cap, + stroke_item->pen_join, + stroke_item->dash_count, + stroke_item->dash_list, + stroke_item->dash_offset); + else + rl2_graph_set_dashed_pen (ctx, + stroke_item->red, + stroke_item->green, + stroke_item->blue, + stroke_item->opacity, + stroke_item->width, + stroke_item->pen_cap, + stroke_item->pen_join, + stroke_item->dash_count, + stroke_item->dash_list, + stroke_item->dash_offset); + } else - rl2_graph_set_dashed_pen (ctx, stroke_item->red, - stroke_item->green, - stroke_item->blue, - stroke_item->opacity, - stroke_item->width, - stroke_item->pen_cap, - stroke_item->pen_join, - stroke_item->dash_count, - stroke_item->dash_list, - stroke_item->dash_offset); - } - else - { - if (stroke_item->pattern != NULL) - rl2_graph_set_pattern_solid_pen (ctx, - stroke_item->pattern, - stroke_item->width, - stroke_item->pen_cap, - stroke_item->pen_join); + { + if (stroke_item->pattern != NULL) + rl2_graph_set_pattern_solid_pen (ctx, + stroke_item->pattern, + stroke_item->width, + stroke_item->pen_cap, + stroke_item->pen_join); + else + rl2_graph_set_solid_pen (ctx, + stroke_item->red, + stroke_item->green, + stroke_item->blue, + stroke_item->opacity, + stroke_item->width, + stroke_item->pen_cap, + stroke_item->pen_join); + } + + if (stroke_item == multi_stroke->last) + rl2_graph_stroke_path (ctx, RL2_CLEAR_PATH); else - rl2_graph_set_solid_pen (ctx, stroke_item->red, - stroke_item->green, - stroke_item->blue, - stroke_item->opacity, - stroke_item->width, - stroke_item->pen_cap, - stroke_item->pen_join); + rl2_graph_stroke_path (ctx, RL2_PRESERVE_PATH); + + stroke_item = stroke_item->next; + if (stroke_item == multi_stroke->last) + rl2_graph_release_pattern_pen (ctx); } - - if (stroke_item == multi_stroke->last) - rl2_graph_stroke_path (ctx, RL2_CLEAR_PATH); - else - rl2_graph_stroke_path (ctx, RL2_PRESERVE_PATH); - - stroke_item = stroke_item->next; - if (stroke_item == multi_stroke->last) - rl2_graph_release_pattern_pen (ctx); } line = line->next; } rl2_destroy_multi_stroke (multi_stroke); } + +static int +ring_bbox_matches (rl2RingPtr ring, double minx, double miny, double maxx, + double maxy) +{ +/* checks if the Ring BBOX is visible */ + if (minx > ring->maxx) + return 0; + if (maxx < ring->minx) + return 0; + if (miny > ring->maxy) + return 0; + if (maxy < ring->miny) + return 0; + return 1; +} static void draw_polygons (rl2GraphicsContextPtr ctx, sqlite3 * handle, rl2PrivVectorSymbolizerPtr sym, int height, double minx, - double miny, double x_res, double y_res, rl2GeometryPtr geom) + double miny, double maxx, double maxy, double x_res, + double y_res, rl2GeometryPtr geom) { /* drawing Polygonal-type features */ rl2PrivVectorSymbolizerItemPtr item; int stroke = 0; int fill = 0; @@ -2706,13 +2955,12 @@ if (pattern_fill != NULL) { if (recolor) { /* attempting to recolor the External Graphic resource */ - rl2_graph_pattern_recolor (pattern_fill, - red, green, - blue); + rl2_graph_pattern_recolor + (pattern_fill, red, green, blue); } if (polyg_sym->fill->opacity <= 0.0) norm_opacity = 0; else if (polyg_sym->fill->opacity >= 1.0) norm_opacity = 255; @@ -2767,59 +3015,74 @@ if (polyg_sym->stroke != NULL) { if (polyg_sym->stroke->graphic != NULL) { /* external Graphic stroke */ - pattern_stroke = - load_external_graphic_from_dbms (handle, - polyg_sym->stroke->graphic); + const char *xlink_href = NULL; + int recolor = 0; + unsigned char red; + unsigned char green; + unsigned char blue; + pattern_stroke = NULL; + if (polyg_sym->stroke->graphic->first != NULL) + { + if (polyg_sym->stroke->graphic->first->type == + RL2_EXTERNAL_GRAPHIC) + { + rl2PrivExternalGraphicPtr ext = + (rl2PrivExternalGraphicPtr) + (polyg_sym->stroke->graphic-> + first->item); + xlink_href = ext->xlink_href; + if (ext->first != NULL) + { + recolor = 1; + red = ext->first->red; + green = ext->first->green; + blue = ext->first->blue; + } + } + } + if (xlink_href != NULL) + pattern_stroke = + rl2_create_pattern_from_external_graphic + (handle, xlink_href, 1); if (pattern_stroke != NULL) { - switch (polyg_sym->stroke->linecap) + if (recolor) { - case RL2_STROKE_LINECAP_ROUND: - pen_cap = RL2_PEN_CAP_ROUND; - break; - case RL2_STROKE_LINECAP_SQUARE: - pen_cap = RL2_PEN_CAP_SQUARE; - break; - default: - pen_cap = RL2_PEN_CAP_BUTT; - break; - }; - switch (polyg_sym->stroke->linejoin) + /* attempting to recolor the External Graphic resource */ + rl2_graph_pattern_recolor + (pattern_stroke, red, green, blue); + } + if (polyg_sym->stroke->opacity <= 0.0) + norm_opacity = 0; + else if (polyg_sym->stroke->opacity >= 1.0) + norm_opacity = 255; + else { - case RL2_STROKE_LINEJOIN_BEVEL: - pen_join = RL2_PEN_JOIN_BEVEL; - break; - case RL2_STROKE_LINEJOIN_ROUND: - pen_join = RL2_PEN_JOIN_ROUND; - break; - default: - pen_join = RL2_PEN_JOIN_MITER; - break; - }; - if (polyg_sym->stroke->dash_count > 0 - && polyg_sym->stroke->dash_list != NULL) - rl2_graph_set_pattern_dashed_pen (ctx, - pattern_stroke, - polyg_sym-> - stroke->width, - pen_cap, - pen_join, - polyg_sym->stroke->dash_count, - polyg_sym->stroke->dash_list, - polyg_sym->stroke->dash_offset); - else - rl2_graph_set_pattern_solid_pen (ctx, - pattern_stroke, - polyg_sym-> - stroke->width, - pen_cap, - pen_join); - stroke = 1; + opacity = + 255.0 * polyg_sym->stroke->opacity; + if (opacity <= 0.0) + norm_opacity = 0; + else if (opacity >= 255.0) + norm_opacity = 255; + else + norm_opacity = opacity; + } + if (norm_opacity < 1.0) + rl2_graph_pattern_transparency + (pattern_stroke, norm_opacity); + rl2_graph_set_pattern_brush (ctx, + pattern_stroke); + } + else + { + /* invalid Pattern: defaulting to a Gray brush */ + rl2_graph_set_brush (ctx, 128, 128, 128, 255); } + stroke = 1; } else { /* solid RGB stroke */ if (polyg_sym->stroke->opacity <= 0.0) @@ -2912,38 +3175,12 @@ int lastX = 0; int lastY = 0; int ib; rl2RingPtr ring = polyg->exterior; /* exterior border */ - for (iv = 0; iv < ring->points; iv++) + if (ring_bbox_matches (ring, minx, miny, maxx, maxy)) { - rl2GetPoint (ring->coords, iv, &dx, &dy); - x = (int) ((dx - minx) / x_res); - y = height - (int) ((dy - miny) / y_res); - if (iv == 0) - { - rl2_graph_move_to_point (ctx, x, y); - lastX = x; - lastY = y; - } - else - { - if (x == lastX && y == lastY) - ; - else - { - rl2_graph_add_line_to_path (ctx, x, y); - lastX = x; - lastY = y; - } - } - } - rl2_graph_close_subpath (ctx); - for (ib = 0; ib < polyg->num_interiors; ib++) - { - /* interior borders */ - ring = polyg->interiors + ib; for (iv = 0; iv < ring->points; iv++) { rl2GetPoint (ring->coords, iv, &dx, &dy); x = (int) ((dx - minx) / x_res); y = height - (int) ((dy - miny) / y_res); @@ -2964,10 +3201,49 @@ lastY = y; } } } rl2_graph_close_subpath (ctx); + } + else + { + /* if the exterior ring is invisible we'll ignore all internal rings */ + polyg = polyg->next; + continue; + } + for (ib = 0; ib < polyg->num_interiors; ib++) + { + /* interior borders */ + ring = polyg->interiors + ib; + if (ring_bbox_matches (ring, minx, miny, maxx, maxy)) + { + for (iv = 0; iv < ring->points; iv++) + { + rl2GetPoint (ring->coords, iv, &dx, &dy); + x = (int) ((dx - minx) / x_res); + y = height - (int) ((dy - miny) / y_res); + if (iv == 0) + { + rl2_graph_move_to_point (ctx, x, y); + lastX = x; + lastY = y; + } + else + { + if (x == lastX && y == lastY) + ; + else + { + rl2_graph_add_line_to_path (ctx, + x, y); + lastX = x; + lastY = y; + } + } + } + rl2_graph_close_subpath (ctx); + } } if (fill) { if (stroke) rl2_graph_fill_path (ctx, RL2_PRESERVE_PATH); @@ -2991,12 +3267,12 @@ item = item->next; } } static int -label_get_xy (sqlite3 * handle, const unsigned char *blob, int size, double *x, - double *y) +label_get_xy (sqlite3 * handle, const unsigned char *blob, int size, + double *x, double *y) { /* resolving Point XY coords */ const char *sql; int ret; sqlite3_stmt *stmt = NULL; @@ -3063,11 +3339,12 @@ if (ret == SQLITE_ROW) { if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB) { const unsigned char *g_blob = - (const unsigned char *) sqlite3_column_blob (stmt, 0); + (const unsigned char *) sqlite3_column_blob (stmt, + 0); int g_size = sqlite3_column_bytes (stmt, 0); if (label_get_xy (handle, g_blob, g_size, x, y)) ok = 1; } } @@ -3110,26 +3387,517 @@ if (ret == SQLITE_ROW) { if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB) { const unsigned char *g_blob = - (const unsigned char *) sqlite3_column_blob (stmt, 0); + (const unsigned char *) sqlite3_column_blob (stmt, + 0); + int g_size = sqlite3_column_bytes (stmt, 0); + if (label_get_xy (handle, g_blob, g_size, x, y)) + ok = 1; + } + } + } + sqlite3_finalize (stmt); + return ok; +} + +static int +label_get_ring_midpoint (sqlite3 * handle, rl2RingPtr ring, double *x, + double *y) +{ +/* computing a Ring MidPoint */ + unsigned char *blob; + int blob_sz; + const char *sql; + int ret; + sqlite3_stmt *stmt = NULL; + int ok = 0; + + if (ring == NULL) + return 0; + if (!rl2_serialize_ring_as_linestring (ring, &blob, &blob_sz)) + return 0; + + sql = "SELECT ST_Line_Interpolate_Point(?, 0.5)"; + ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL); + if (ret != SQLITE_OK) + return 0; + + sqlite3_reset (stmt); + sqlite3_clear_bindings (stmt); + sqlite3_bind_blob (stmt, 1, blob, blob_sz, free); + while (1) + { + /* scrolling the result set rows */ + ret = sqlite3_step (stmt); + if (ret == SQLITE_DONE) + break; /* end of result set */ + if (ret == SQLITE_ROW) + { + if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB) + { + const unsigned char *g_blob = + (const unsigned char *) sqlite3_column_blob (stmt, + 0); int g_size = sqlite3_column_bytes (stmt, 0); if (label_get_xy (handle, g_blob, g_size, x, y)) ok = 1; } } } sqlite3_finalize (stmt); return ok; } + +static rl2GeometryPtr +do_generalize_linestring (sqlite3 * handle, rl2LinestringPtr line, + double generalize_factor) +{ +/* simplifying a Linestring */ + rl2GeometryPtr geom = NULL; + unsigned char *blob; + int blob_sz; + const char *sql; + int ret; + sqlite3_stmt *stmt = NULL; + + if (line == NULL) + return NULL; + if (line->points < 2) + return NULL; + if (!rl2_serialize_linestring (line, &blob, &blob_sz)) + return NULL; + + sql = "SELECT ST_Simplify(?, ?)"; + ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL); + if (ret != SQLITE_OK) + return NULL; + + sqlite3_reset (stmt); + sqlite3_clear_bindings (stmt); + sqlite3_bind_blob (stmt, 1, blob, blob_sz, free); + sqlite3_bind_double (stmt, 2, generalize_factor); + while (1) + { + /* scrolling the result set rows */ + ret = sqlite3_step (stmt); + if (ret == SQLITE_DONE) + break; /* end of result set */ + if (ret == SQLITE_ROW) + { + if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB) + { + const unsigned char *g_blob = + (const unsigned char *) sqlite3_column_blob (stmt, + 0); + int g_blob_sz = sqlite3_column_bytes (stmt, 0); + geom = rl2_geometry_from_blob (g_blob, g_blob_sz); + } + } + } + sqlite3_finalize (stmt); + return geom; +} + +static rl2GeometryPtr +do_generalize_ring (sqlite3 * handle, rl2RingPtr ring, double generalize_factor) +{ +/* simplifying a Ring */ + rl2GeometryPtr geom = NULL; + unsigned char *blob; + int blob_sz; + const char *sql; + int ret; + sqlite3_stmt *stmt = NULL; + + if (ring == NULL) + return NULL; + if (ring->points < 2) + return NULL; + if (!rl2_serialize_ring (ring, &blob, &blob_sz)) + return NULL; + + sql = "SELECT ST_SimplifyPreserveTopology(?, ?)"; + ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL); + if (ret != SQLITE_OK) + return NULL; + + sqlite3_reset (stmt); + sqlite3_clear_bindings (stmt); + sqlite3_bind_blob (stmt, 1, blob, blob_sz, free); + sqlite3_bind_double (stmt, 2, generalize_factor); + while (1) + { + /* scrolling the result set rows */ + ret = sqlite3_step (stmt); + if (ret == SQLITE_DONE) + break; /* end of result set */ + if (ret == SQLITE_ROW) + { + if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB) + { + const unsigned char *g_blob = + (const unsigned char *) sqlite3_column_blob (stmt, + 0); + int g_blob_sz = sqlite3_column_bytes (stmt, 0); + geom = rl2_geometry_from_blob (g_blob, g_blob_sz); + } + } + } + sqlite3_finalize (stmt); + return geom; +} + +static int +check_valid_line (rl2LinestringPtr line) +{ +/* testing for a valid linestring */ + int iv; + int pts = 0; + double x; + double y; + double x0; + double y0; + + if (line == NULL) + return 0; + if (line->points < 2) + return 0; + rl2GetPoint (line->coords, 0, &x0, &y0); + for (iv = 1; iv < line->points; iv++) + { + rl2GetPoint (line->coords, iv, &x, &y); + if (x != x0 || y != y0) + { + pts++; + break; + } + } + if (pts == 0) + return 0; + return 1; +} + +static rl2GeometryPtr +do_offset_linestring (sqlite3 * handle, rl2LinestringPtr line, + double perpendicular_offset) +{ +/* Offest Curve (from Linestring) */ + rl2GeometryPtr geom = NULL; + unsigned char *blob; + int blob_sz; + const char *sql; + int ret; + sqlite3_stmt *stmt = NULL; + + if (!check_valid_line (line)) + return NULL; + if (!rl2_serialize_linestring (line, &blob, &blob_sz)) + return NULL; + + sql = "SELECT ST_OffsetCurve(?, ?)"; + ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL); + if (ret != SQLITE_OK) + return NULL; + + sqlite3_reset (stmt); + sqlite3_clear_bindings (stmt); + sqlite3_bind_blob (stmt, 1, blob, blob_sz, free); + sqlite3_bind_double (stmt, 2, perpendicular_offset); + while (1) + { + /* scrolling the result set rows */ + ret = sqlite3_step (stmt); + if (ret == SQLITE_DONE) + break; /* end of result set */ + if (ret == SQLITE_ROW) + { + if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB) + { + const unsigned char *g_blob = + (const unsigned char *) sqlite3_column_blob (stmt, + 0); + int g_blob_sz = sqlite3_column_bytes (stmt, 0); + geom = rl2_geometry_from_blob (g_blob, g_blob_sz); + } + } + } + sqlite3_finalize (stmt); + return geom; +} + +static int +check_valid_ring (rl2RingPtr ring) +{ +/* testing for a valid ring */ + int iv; + int pts = 0; + int last; + double x; + double y; + double x0; + double y0; + double x1; + double y1; + + if (ring == NULL) + return 0; + if (ring->points < 4) + return 0; + rl2GetPoint (ring->coords, 0, &x0, &y0); + for (iv = 1; iv < ring->points; iv++) + { + rl2GetPoint (ring->coords, iv, &x, &y); + if (pts == 0) + { + if (x != x0 || y != y0) + { + pts++; + x1 = x; + y1 = y; + } + } + else + { + if ((x != x0 || y != y0) && (x != x1 || y != y1)) + { + pts++; + break; + } + } + } + last = ring->points - 1; + rl2GetPoint (ring->coords, last, &x1, &y1); + if (pts == 2 && x0 == x1 && y0 == y1) + return 1; + return 0; +} + +static rl2GeometryPtr +do_buffered_ring (sqlite3 * handle, rl2RingPtr ring, + double perpendicular_offset) +{ +/* Buffer (from Ring) */ + rl2GeometryPtr geom = NULL; + unsigned char *blob; + int blob_sz; + const char *sql; + int ret; + sqlite3_stmt *stmt = NULL; + + if (!check_valid_ring (ring)) + return NULL; + if (!rl2_serialize_ring (ring, &blob, &blob_sz)) + return NULL; + + sql = "SELECT ST_Buffer(?, ?)"; + ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL); + if (ret != SQLITE_OK) + return NULL; + + sqlite3_reset (stmt); + sqlite3_clear_bindings (stmt); + sqlite3_bind_blob (stmt, 1, blob, blob_sz, free); + sqlite3_bind_double (stmt, 2, perpendicular_offset); + while (1) + { + /* scrolling the result set rows */ + ret = sqlite3_step (stmt); + if (ret == SQLITE_DONE) + break; /* end of result set */ + if (ret == SQLITE_ROW) + { + if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB) + { + const unsigned char *g_blob = + (const unsigned char *) sqlite3_column_blob (stmt, + 0); + int g_blob_sz = sqlite3_column_bytes (stmt, 0); + geom = rl2_geometry_from_blob (g_blob, g_blob_sz); + } + } + } + sqlite3_finalize (stmt); + return geom; +} + +static void +create_line_array_from_linestring (sqlite3 * handle, rl2LinestringPtr line, + double perpendicular_offset, int *points, + double **x_array, double **y_array, + int generalize_line, + double generalize_factor, int height, + double minx, double miny, double x_res, + double y_res) +{ +/* creating the X and Y arrays required by rl2_graph_draw_warped_text() */ + rl2GeometryPtr geom = NULL; + rl2GeometryPtr geom2 = NULL; + rl2LinestringPtr aux_line; + rl2LinestringPtr in_line; + double *xx = NULL; + double *yy = NULL; + int iv; + double x; + double y; + + *points = 0; + *x_array = NULL; + *y_array = NULL; + if (line == NULL) + goto error; + + aux_line = rl2_linestring_to_image (line, height, minx, miny, x_res, y_res); + if (aux_line == NULL) + goto error; + in_line = aux_line; + if (generalize_line) + { + geom = do_generalize_linestring (handle, in_line, generalize_factor); + if (geom == NULL) + goto error; + in_line = geom->first_linestring; + if (in_line == NULL) + goto error; + } + if (perpendicular_offset != 0.0) + { + geom2 = do_offset_linestring (handle, in_line, perpendicular_offset); + if (geom2 == NULL) + goto error; + in_line = geom2->first_linestring; + if (in_line == NULL) + goto error; + } + +/* allocating the X and Y arrays */ + if (in_line->points < 2) + goto error; + xx = malloc (sizeof (double) * in_line->points); + yy = malloc (sizeof (double) * in_line->points); + if (xx == NULL || yy == NULL) + { + if (xx != NULL) + free (xx); + if (yy != NULL) + free (yy); + goto error; + } + for (iv = 0; iv < in_line->points; iv++) + { + /* populating the X and Y arrays */ + rl2GetPoint (in_line->coords, iv, &x, &y); + *(xx + iv) = x; + *(yy + iv) = y; + } + *points = in_line->points; + *x_array = xx; + *y_array = yy; + + error: + if (aux_line) + rl2DestroyLinestring (aux_line); + if (geom) + rl2_destroy_geometry (geom); + if (geom2) + rl2_destroy_geometry (geom2); +} + +static void +create_line_array_from_ring (sqlite3 * handle, rl2RingPtr ring, + double perpendicular_offset, int *points, + double **x_array, double **y_array, + int generalize_line, double generalize_factor, + int height, double minx, double miny, double x_res, + double y_res) +{ +/* creating the X and Y arrays required by rl2_graph_draw_warped_text() */ + rl2GeometryPtr geom = NULL; + rl2GeometryPtr geom2 = NULL; + rl2PolygonPtr pg; + rl2RingPtr aux_ring; + rl2RingPtr in_ring; + double *xx = NULL; + double *yy = NULL; + int iv; + double x; + double y; + + *points = 0; + *x_array = NULL; + *y_array = NULL; + if (ring == NULL) + goto error; + + aux_ring = rl2_ring_to_image (ring, height, minx, miny, x_res, y_res); + if (aux_ring == NULL) + goto error; + in_ring = aux_ring; + if (generalize_line) + { + geom = do_generalize_ring (handle, in_ring, generalize_factor); + if (geom == NULL) + goto error; + pg = geom->first_polygon; + if (pg == NULL) + goto error; + in_ring = pg->exterior; + if (in_ring == NULL) + goto error; + } + if (perpendicular_offset != 0.0) + { + geom2 = do_buffered_ring (handle, in_ring, perpendicular_offset); + if (geom2 == NULL) + goto error; + pg = geom2->first_polygon; + if (pg == NULL) + goto error; + in_ring = pg->exterior; + if (in_ring == NULL) + goto error; + } + +/* allocating the X and Y arrays */ + if (in_ring->points < 2) + goto error; + xx = malloc (sizeof (double) * in_ring->points); + yy = malloc (sizeof (double) * in_ring->points); + if (xx == NULL || yy == NULL) + { + if (xx != NULL) + free (xx); + if (yy != NULL) + free (yy); + goto error; + } + for (iv = 0; iv < in_ring->points; iv++) + { + /* populating the X and Y arrays */ + rl2GetPoint (in_ring->coords, iv, &x, &y); + *(xx + iv) = x; + *(yy + iv) = y; + } + *points = in_ring->points; + *x_array = xx; + *y_array = yy; + + error: + if (aux_ring) + rl2DestroyRing (aux_ring); + if (geom) + rl2_destroy_geometry (geom); + if (geom2) + rl2_destroy_geometry (geom2); +} static void draw_labels (rl2GraphicsContextPtr ctx, sqlite3 * handle, - rl2PrivTextSymbolizerPtr sym, int height, double minx, double miny, - double x_res, double y_res, rl2GeometryPtr geom, - rl2PrivVariantValuePtr value) + const void *priv_data, rl2PrivTextSymbolizerPtr sym, int height, + double minx, double miny, double maxx, double maxy, double x_res, + double y_res, rl2GeometryPtr geom, rl2PrivVariantValuePtr value) { /* drawing TextLabels */ rl2GraphicsFontPtr font = NULL; char *dummy = NULL; const char *label = NULL; @@ -3138,10 +3906,22 @@ double opacity; unsigned char norm_opacity; rl2PointPtr point; rl2LinestringPtr line; rl2PolygonPtr polyg; + double rotation = 0.0; + double anchor_point_x = 0.0; + double anchor_point_y = 0.0; + double displacement_x = 0.0; + double displacement_y = 0.0; + double perpendicular_offset = 0.0; + int is_repeated = 0; + double initial_gap = 0.0; + double gap = 0.0; + int is_aligned = 0; + int generalize_line = 0; + int i; /* preparing the Text */ if (value->sqlite3_type == SQLITE_INTEGER) { dummy = sqlite3_malloc (1024); @@ -3184,13 +3964,27 @@ case RL2_FONT_WEIGHT_NORMAL: default: font_weight = RL2_FONTWEIGHT_NORMAL; break; }; - font = - rl2_graph_create_toy_font (NULL, sym->font_size, font_style, - font_weight); + for (i = 0; i < RL2_MAX_FONT_FAMILIES; i++) + { + const char *facename = sym->font_families[i]; + if (facename != NULL) + font = + rl2_search_TrueType_font (handle, priv_data, facename, + sym->font_size); + if (font != NULL) + break; + } + if (font == NULL) + { + /* defaulting to a toy font */ + font = + rl2_graph_create_toy_font (NULL, sym->font_size, font_style, + font_weight); + } if (font == NULL) goto stop; if (sym->fill != NULL) { if (sym->fill->opacity <= 0.0) @@ -3225,116 +4019,323 @@ norm_opacity = 255; else norm_opacity = opacity; } rl2_graph_font_set_halo (font, sym->halo->radius, - sym->halo->fill->red, sym->halo->fill->green, + sym->halo->fill->red, + sym->halo->fill->green, sym->halo->fill->blue, norm_opacity); } rl2_graph_set_font (ctx, font); - polyg = geom->first_polygon; - while (polyg) + if (sym->label_placement_type == RL2_LABEL_PLACEMENT_POINT) + { + /* retrieving eventual Point Placement arguments */ + rl2PrivPointPlacementPtr ptpl = + (rl2PrivPointPlacementPtr) (sym->label_placement); + if (ptpl != NULL) + { + anchor_point_x = ptpl->anchor_point_x; + anchor_point_y = ptpl->anchor_point_y; + displacement_x = ptpl->displacement_x; + displacement_y = ptpl->displacement_y; + rotation = ptpl->rotation; + } + } + else if (sym->label_placement_type == RL2_LABEL_PLACEMENT_LINE) + { + /* retrieving eventual Lineo Placement arguments */ + rl2PrivLinePlacementPtr lnpl = + (rl2PrivLinePlacementPtr) (sym->label_placement); + if (lnpl != NULL) + { + perpendicular_offset = lnpl->perpendicular_offset; + is_repeated = lnpl->is_repeated; + initial_gap = lnpl->initial_gap; + gap = lnpl->gap; + is_aligned = lnpl->is_aligned; + generalize_line = lnpl->generalize_line; + } + } + + if (sym->label_placement_type == RL2_LABEL_PLACEMENT_POINT) { - /* drawing a POLYGON-based text label */ - double pre_x; - double pre_y; - double lbl_width = 0.0; - double lbl_height = 0.0; - double post_x; - double post_y; - double shift_x; - double shift_y; + /* POINT PLACEMENT */ + rl2Point pt; double cx; double cy; double x; double y; - if (!label_get_centroid (handle, polyg, &cx, &cy)) + + polyg = geom->first_polygon; + while (polyg) { + /* drawing a POLYGON-based text label */ + if (!label_get_centroid (handle, polyg, &cx, &cy)) + { + polyg = polyg->next; + continue; + } + pt.x = cx; + pt.y = cy; + if (point_bbox_matches (&pt, minx, miny, maxx, maxy)) + { + x = (cx - minx) / x_res; + y = (double) height - ((cy - miny) / y_res); + rl2_graph_draw_text (ctx, label, x + displacement_x, + y - displacement_y, rotation, + anchor_point_x, anchor_point_y); + } polyg = polyg->next; - continue; + } + + line = geom->first_linestring; + while (line) + { + /* drawing a LINESTRING-based text label */ + label_get_midpoint (handle, line, &cx, &cy); + pt.x = cx; + pt.y = cy; + if (point_bbox_matches (&pt, minx, miny, maxx, maxy)) + { + x = (cx - minx) / x_res; + y = (double) height - ((cy - miny) / y_res); + rl2_graph_draw_text (ctx, label, x + displacement_x, + y - displacement_y, rotation, + anchor_point_x, anchor_point_y); + } + line = line->next; + } + + point = geom->first_point; + while (point) + { + /* drawing a POINT-based text label */ + if (point_bbox_matches (point, minx, miny, maxx, maxy)) + { + double x = (point->x - minx) / x_res; + double y = (double) height - ((point->y - miny) / y_res); + rl2_graph_draw_text (ctx, label, x + displacement_x, + y - displacement_y, rotation, + anchor_point_x, anchor_point_y); + } + point = point->next; } - x = (cx - minx) / x_res; - y = (double) height - ((cy - miny) / y_res); - rl2_graph_get_text_extent (ctx, label, &pre_x, &pre_y, &lbl_width, - &lbl_height, &post_x, &post_y); - shift_x = 0.0 - (lbl_width / 2.0); - shift_y = 0.0 + (lbl_height / 2.0); - rl2_graph_draw_text (ctx, label, x + shift_x, y + shift_y, 0.0, 0.0, - 0.0); - polyg = polyg->next; + } - - line = geom->first_linestring; - while (line) + else if (sym->label_placement_type == RL2_LABEL_PLACEMENT_LINE) { - /* drawing a LINESTRING-based text label */ - double pre_x; - double pre_y; - double lbl_width = 0.0; - double lbl_height = 0.0; - double post_x; - double post_y; - double shift_x; - double shift_y; + /* LINE PLACEMENT */ + rl2Point pt; + int ib; double cx; double cy; double x; double y; - label_get_midpoint (handle, line, &cx, &cy); - if (!rl2_graph_get_text_extent - (ctx, label, &pre_x, &pre_y, &lbl_width, &lbl_height, &post_x, - &post_y)) + double generalize_factor = 8.0; + + line = geom->first_linestring; + while (line) { + /* drawing a LINESTRING-based text label */ + if (!is_aligned) + { + /* horizontal label aligned to center point */ + label_get_midpoint (handle, line, &cx, &cy); + pt.x = cx; + pt.y = cy; + if (point_bbox_matches (&pt, minx, miny, maxx, maxy)) + { + x = (cx - minx) / x_res; + y = (double) height - ((cy - miny) / y_res); + rl2_graph_draw_text (ctx, label, x, y, 0.0, 0.5, + 0.5); + } + } + else + { + /* label is warped along the line */ + double *x_array = NULL; + double *y_array = NULL; + int points; + if (linestring_bbox_matches + (line, minx, miny, maxx, maxy)) + { + create_line_array_from_linestring (handle, line, + perpendicular_offset, + &points, + &x_array, + &y_array, + generalize_line, + generalize_factor, + height, minx, + miny, x_res, + y_res); + if (x_array != NULL && y_array != NULL) + rl2_graph_draw_warped_text (handle, ctx, label, + points, x_array, + y_array, + initial_gap, gap, + is_repeated); + if (x_array) + free (x_array); + if (y_array) + free (y_array); + } + } line = line->next; - continue; } - x = (cx - minx) / x_res; - y = (double) height - ((cy - miny) / y_res); - shift_x = 0.0 - (lbl_width / 2.0); - shift_y = 0.0 + (lbl_height / 2.0); - rl2_graph_draw_text (ctx, label, x + shift_x, y + shift_y, 0.0, 0.0, - 0.0); - line = line->next; - } - - point = geom->first_point; - while (point) - { - /* drawing a POINT-based text label */ - double pre_x; - double pre_y; - double lbl_width = 0.0; - double lbl_height = 0.0; - double post_x; - double post_y; - double shift_x; - double shift_y; - double x = (point->x - minx) / x_res; - double y = (double) height - ((point->y - miny) / y_res); - rl2_graph_get_text_extent (ctx, label, &pre_x, &pre_y, &lbl_width, - &lbl_height, &post_x, &post_y); - shift_x = 0.0 - (lbl_width / 2.0); - shift_y = 0.0 + (lbl_height / 2.0); - rl2_graph_draw_text (ctx, label, x + shift_x, y + shift_y, 0.0, 0.0, - 0.0); - point = point->next; + + polyg = geom->first_polygon; + while (polyg) + { + /* drawing a POLYGON-based text label */ + rl2RingPtr ring = polyg->exterior; + /* exterior border */ + if (ring_bbox_matches (ring, minx, miny, maxx, maxy)) + { + if (!is_aligned) + { + /* horizontal label aligned to Ring's center point */ + label_get_ring_midpoint (handle, ring, &cx, &cy); + pt.x = cx; + pt.y = cy; + if (point_bbox_matches + (&pt, minx, miny, maxx, maxy)) + { + x = (cx - minx) / x_res; + y = (double) height - ((cy - miny) / y_res); + rl2_graph_draw_text (ctx, label, x, y, 0.0, + 0.5, 0.5); + } + } + else + { + /* label is warped along the Ring */ + double *x_array = NULL; + double *y_array = NULL; + int points; + if (ring_bbox_matches + (ring, minx, miny, maxx, maxy)) + { + create_line_array_from_ring (handle, ring, + perpendicular_offset, + &points, + &x_array, + &y_array, + generalize_line, + generalize_factor, + height, minx, + miny, x_res, + y_res); + if (x_array != NULL && y_array != NULL) + { + rl2_graph_draw_warped_text (handle, ctx, + label, + points, + x_array, + y_array, + initial_gap, + gap, + is_repeated); + } + if (x_array) + free (x_array); + if (y_array) + free (y_array); + } + } + } + else + { + /* if the exterior ring is invisible we'll ignore all internal rings */ + polyg = polyg->next; + continue; + } + for (ib = 0; ib < polyg->num_interiors; ib++) + { + /* interior borders */ + ring = polyg->interiors + ib; + if (ring_bbox_matches (ring, minx, miny, maxx, maxy)) + { + if (!is_aligned) + { + /* horizontal label aligned to Ring's center point */ + label_get_ring_midpoint (handle, ring, &cx, + &cy); + pt.x = cx; + pt.y = cy; + if (point_bbox_matches + (&pt, minx, miny, maxx, maxy)) + { + x = (cx - minx) / x_res; + y = (double) height - + ((cy - miny) / y_res); + rl2_graph_draw_text (ctx, label, x, y, + 0.0, 0.5, 0.5); + } + } + else + { + /* label is warped along the Ring */ + double *x_array = NULL; + double *y_array = NULL; + int points; + if (ring_bbox_matches + (ring, minx, miny, maxx, maxy)) + { + create_line_array_from_ring (handle, + ring, + perpendicular_offset, + &points, + &x_array, + &y_array, + generalize_line, + generalize_factor, + height, + minx, miny, + x_res, + y_res); + if (x_array != NULL && y_array != NULL) + rl2_graph_draw_warped_text (handle, + ctx, + label, + points, + x_array, + y_array, + initial_gap, + gap, + is_repeated); + if (x_array) + free (x_array); + if (y_array) + free (y_array); + } + } + } + } + polyg = polyg->next; + } } /* final cleanup - relasing resources */ stop: if (dummy != NULL) sqlite3_free (dummy); if (font != NULL) - rl2_graph_destroy_font (font); + { + rl2_graph_release_font (ctx); + rl2_graph_destroy_font (font); + } } RL2_PRIVATE void -rl2_draw_vector_feature (void *p_ctx, sqlite3 * handle, +rl2_draw_vector_feature (void *p_ctx, sqlite3 * handle, const void *priv_data, rl2VectorSymbolizerPtr symbolizer, int height, - double minx, double miny, double x_res, double y_res, - rl2GeometryPtr geom, rl2VariantArrayPtr variant) + double minx, double miny, double maxx, double maxy, + double x_res, double y_res, rl2GeometryPtr geom, + rl2VariantArrayPtr variant) { /* drawing a vector feature on the current canvass */ rl2PrivVectorSymbolizerItemPtr item; rl2GraphicsContextPtr ctx = (rl2GraphicsContextPtr) p_ctx; rl2PrivVectorSymbolizerPtr sym = (rl2PrivVectorSymbolizerPtr) symbolizer; @@ -3421,16 +4422,18 @@ sym = default_symbolizer; } /* we'll render all geometries first */ if (geom->first_polygon != NULL) - draw_polygons (ctx, handle, sym, height, minx, miny, x_res, y_res, - geom); + draw_polygons (ctx, handle, sym, height, minx, miny, maxx, maxy, + x_res, y_res, geom); if (geom->first_linestring != NULL) - draw_lines (ctx, handle, sym, height, minx, miny, x_res, y_res, geom); + draw_lines (ctx, handle, sym, height, minx, miny, maxx, maxy, x_res, + y_res, geom); if (geom->first_point != NULL) - draw_points (ctx, handle, sym, height, minx, miny, x_res, y_res, geom); + draw_points (ctx, handle, sym, height, minx, miny, maxx, maxy, x_res, + y_res, geom); if (sym != NULL) { /* then we'll render any eventual TextSymbolizer */ item = sym->first; @@ -3444,23 +4447,32 @@ if (text->label != NULL) { int v; rl2PrivVariantArrayPtr var = (rl2PrivVariantArrayPtr) variant; - for (v = 0; v < var->count; v++) + if (var != NULL) { - rl2PrivVariantValuePtr val = - *(var->array + v); - if (val == NULL) - continue; - if (val->column_name == NULL) - continue; - if (strcasecmp (text->label, val->column_name) - != 0) - continue; - draw_labels (ctx, handle, text, height, minx, - miny, x_res, y_res, geom, val); + for (v = 0; v < var->count; v++) + { + rl2PrivVariantValuePtr val = + *(var->array + v); + if (val == NULL) + continue; + if (val->column_name == NULL) + continue; + if (strcasecmp + (text->label, + val->column_name) != 0) + continue; +/* to be fixed - sometimes it raises a Cairo exception about Fonts + draw_labels (ctx, handle, priv_data, + text, height, minx, miny, + maxx, maxy, x_res, y_res, + geom, val); + +*/ + } } } } item = item->next; } @@ -3467,5 +4479,85 @@ } if (default_symbolizer != NULL) rl2_destroy_vector_symbolizer (default_symbolizer); } + +RL2_PRIVATE int +rl2_aux_default_image (unsigned int width, unsigned int height, + unsigned char red, unsigned char green, + unsigned char blue, int format, int transparent, + int quality, unsigned char **ximage, int *ximage_sz) +{ +/* creating a default image */ + unsigned int x; + unsigned int y; + unsigned char *pixels = malloc (width * height * 3); + unsigned char *po = pixels; + unsigned char *mask = NULL; + unsigned char *pm; + + *ximage = NULL; + *ximage_sz = 0; + if (pixels == NULL) + return 0; + + mask = malloc (width * height); + if (mask == NULL) + goto error; + pm = mask; + +/* priming the image buffer to background color */ + for (y = 0; y < height; y++) + { + for (x = 0; x < width; x++) + { + *po++ = red; + *po++ = green; + *po++ = blue; + if (mask != NULL) + *pm++ = 0; + } + } + + if (format == RL2_OUTPUT_FORMAT_PNG) + { + if (transparent) + { + if (rl2_rgb_alpha_to_png + (width, height, pixels, mask, ximage, ximage_sz, + 1.0) != RL2_OK) + goto error; + } + else + { + if (rl2_rgb_to_png (width, height, pixels, ximage, ximage_sz) + != RL2_OK) + goto error; + } + } + else if (format == RL2_OUTPUT_FORMAT_JPEG) + { + if (rl2_rgb_to_jpeg + (width, height, pixels, quality, ximage, ximage_sz) != RL2_OK) + goto error; + } + else if (format == RL2_OUTPUT_FORMAT_TIFF) + { + if (rl2_rgb_to_tiff (width, height, pixels, ximage, ximage_sz) != + RL2_OK) + goto error; + } + else + goto error; + free (pixels); + if (mask != NULL) + free (mask); + return 1; + + error: + if (pixels != NULL) + free (pixels); + if (mask != NULL) + free (mask); + return 0; +} Index: src/rl2charls.c ================================================================== --- src/rl2charls.c +++ src/rl2charls.c @@ -54,11 +54,15 @@ #include "rasterlite2/rasterlite2.h" #include "rasterlite2_private.h" #ifndef OMIT_CHARLS /* only if CharLS is enabled */ +#ifdef __ANDROID__ /* Android specific */ +#include +#else #include +#endif static int endianness () { /* checking if target CPU is a little-endian one */ @@ -280,12 +284,12 @@ } } } static void -from_ilv_buffer_8 (unsigned char *out, unsigned char *in, int width, int height, - int num_bands) +from_ilv_buffer_8 (unsigned char *out, unsigned char *in, int width, + int height, int num_bands) { /* rearranging pixels from separate LINE components - UINT 8 */ int x; int y; int ib; @@ -451,12 +455,12 @@ from_ilv_buffer_16 ((unsigned short *) (*pixels), (unsigned short *) out_buffer, *width, *height, *num_bands); else from_ilv_buffer_8 ((unsigned char *) (*pixels), - (unsigned char *) out_buffer, *width, *height, - *num_bands); + (unsigned char *) out_buffer, *width, + *height, *num_bands); } free (out_buffer); return RL2_OK; error: Index: src/rl2codec.c ================================================================== --- src/rl2codec.c +++ src/rl2codec.c @@ -2020,13 +2020,14 @@ *size_even = e_size; return 1; } RL2_DECLARE int -rl2_raster_encode (rl2RasterPtr rst, int compression, unsigned char **blob_odd, - int *blob_odd_sz, unsigned char **blob_even, - int *blob_even_sz, int quality, int little_endian) +rl2_raster_encode (rl2RasterPtr rst, int compression, + unsigned char **blob_odd, int *blob_odd_sz, + unsigned char **blob_even, int *blob_even_sz, int quality, + int little_endian) { /* encoding a Raster into the internal RL2 binary format */ rl2PrivRasterPtr raster = (rl2PrivRasterPtr) rst; int odd_rows; unsigned char *pixels_odd = NULL; @@ -2124,12 +2125,12 @@ /* preparing the pixels buffers */ if (raster->sampleType == RL2_SAMPLE_1_BIT) { /* packing 1-BIT data */ if (!pack_1bit_rows - (raster, raster->rasterBuffer, &row_stride_odd, &pixels_odd, - &size_odd)) + (raster, raster->rasterBuffer, &row_stride_odd, + &pixels_odd, &size_odd)) return RL2_ERROR; odd_rows = raster->height; } else if (raster->sampleType == RL2_SAMPLE_2_BIT) { @@ -2149,13 +2150,13 @@ } else { /* Odd/Even raster */ if (!odd_even_rows - (raster, &odd_rows, &row_stride_odd, &pixels_odd, &size_odd, - &even_rows, &row_stride_even, &pixels_even, &size_even, - little_endian)) + (raster, &odd_rows, &row_stride_odd, &pixels_odd, + &size_odd, &even_rows, &row_stride_even, &pixels_even, + &size_even, little_endian)) return RL2_ERROR; } } else if (compression == RL2_COMPRESSION_PNG) { @@ -2167,13 +2168,13 @@ } else { /* Odd/Even raster */ if (!odd_even_rows - (raster, &odd_rows, &row_stride_odd, &pixels_odd, &size_odd, - &even_rows, &row_stride_even, &pixels_even, &size_even, - little_endian)) + (raster, &odd_rows, &row_stride_odd, &pixels_odd, + &size_odd, &even_rows, &row_stride_even, &pixels_even, + &size_even, little_endian)) return RL2_ERROR; } } else if (compression == RL2_COMPRESSION_CHARLS) { @@ -2469,12 +2470,12 @@ } else if (compression == RL2_COMPRESSION_LOSSY_WEBP) { #ifndef OMIT_WEBP /* only if WebP is enabled */ /* compressing as lossy WEBP */ - if (rl2_raster_to_lossy_webp (rst, &compr_data, &compressed, quality) - == RL2_OK) + if (rl2_raster_to_lossy_webp + (rst, &compr_data, &compressed, quality) == RL2_OK) { /* ok, lossy WEBP compression was successful */ uncompressed = raster->width * raster->height * raster->nBands; to_clean1 = compr_data; } @@ -2589,12 +2590,12 @@ } else if (compression == RL2_COMPRESSION_LOSSLESS_JP2) { #ifndef OMIT_OPENJPEG /* only if OpenJpeg is enabled */ /* compressing as lossless Jpeg2000 */ - if (rl2_raster_to_lossless_jpeg2000 (rst, &compr_data, &compressed) == - RL2_OK) + if (rl2_raster_to_lossless_jpeg2000 (rst, &compr_data, &compressed) + == RL2_OK) { /* ok, lossless Jpeg2000 compression was successful */ uncompressed = raster->width * raster->height * raster->nBands; to_clean1 = compr_data; } @@ -2721,12 +2722,12 @@ to_clean2 = zip_buf; } else if (ret == Z_BUF_ERROR) { /* ZIP compression actually causes inflation: saving uncompressed data */ - if (rl2_delta_decode (pixels_even, size_even, delta_dist) - != RL2_OK) + if (rl2_delta_decode + (pixels_even, size_even, delta_dist) != RL2_OK) goto error; uncompressed = size_even; compressed = size_even; compr_data = pixels_even; free (zip_buf); @@ -3131,14 +3132,15 @@ *xcrc = crc; return 1; } static int -check_blob_even (const unsigned char *blob, int blob_sz, unsigned short xwidth, - unsigned short xheight, unsigned char xsample_type, - unsigned char xpixel_type, unsigned char xnum_bands, - unsigned char xcompression, uLong xcrc) +check_blob_even (const unsigned char *blob, int blob_sz, + unsigned short xwidth, unsigned short xheight, + unsigned char xsample_type, unsigned char xpixel_type, + unsigned char xnum_bands, unsigned char xcompression, + uLong xcrc) { /* checking the EvenBlock for validity */ const unsigned char *ptr; unsigned short width; unsigned short height; @@ -3216,11 +3218,12 @@ { /* checking if the encoded raster could be decoded at given scale */ switch (scale) { case RL2_SCALE_1: - if (sample_type == RL2_SAMPLE_1_BIT || sample_type == RL2_SAMPLE_2_BIT + if (sample_type == RL2_SAMPLE_1_BIT + || sample_type == RL2_SAMPLE_2_BIT || sample_type == RL2_SAMPLE_4_BIT) ; else if (compression == RL2_COMPRESSION_JPEG || compression == RL2_COMPRESSION_LOSSY_WEBP || compression == RL2_COMPRESSION_LOSSLESS_WEBP @@ -3232,10 +3235,36 @@ return 0; } else if (blob_even == NULL) return 0; break; + case RL2_SCALE_2: + case RL2_SCALE_4: + case RL2_SCALE_8: + break; + default: + return 0; + }; + switch (sample_type) + { + case RL2_SAMPLE_1_BIT: + case RL2_SAMPLE_2_BIT: + case RL2_SAMPLE_4_BIT: + if (scale != RL2_SCALE_1) + return 0; + break; + }; + return 1; +} + +static int +check_scale2 (int scale, unsigned char sample_type) +{ +/* checking if the encoded raster could be decoded at given scale */ + switch (scale) + { + case RL2_SCALE_1: case RL2_SCALE_2: case RL2_SCALE_4: case RL2_SCALE_8: break; default: @@ -4192,13 +4221,14 @@ } } } static void -do_copy_uint32 (int swap, const unsigned int *p_odd, const unsigned int *p_even, - unsigned int *buf, unsigned short width, - unsigned short odd_rows, unsigned short even_rows) +do_copy_uint32 (int swap, const unsigned int *p_odd, + const unsigned int *p_even, unsigned int *buf, + unsigned short width, unsigned short odd_rows, + unsigned short even_rows) { /* reassembling an UINT32 raster - scale 1:1 */ int row; int col; unsigned int *p_out; @@ -4880,12 +4910,12 @@ RL2_DECLARE int rl2_is_valid_dbms_raster_tile (unsigned short level, unsigned int tile_width, unsigned int tile_height, const unsigned char *blob_odd, int blob_odd_sz, - const unsigned char *blob_even, int blob_even_sz, - unsigned char sample_type, + const unsigned char *blob_even, + int blob_even_sz, unsigned char sample_type, unsigned char pixel_type, unsigned char num_bands, unsigned char compression) { /* testing a serialized Raster Tile object for validity */ @@ -4939,12 +4969,12 @@ if (xsample_type == RL2_SAMPLE_UINT8 && xpixel_type == RL2_PIXEL_RGB && xnum_bands == 3 && xcompression == RL2_COMPRESSION_PNG) return RL2_OK; } - if (sample_type == RL2_SAMPLE_UINT8 && pixel_type == RL2_PIXEL_PALETTE - && num_bands == 1) + if (sample_type == RL2_SAMPLE_UINT8 + && pixel_type == RL2_PIXEL_PALETTE && num_bands == 1) { /* PALETTE 8bits: expecting an RGB/PNG Pyramid tile */ if (xsample_type == RL2_SAMPLE_UINT8 && xpixel_type == RL2_PIXEL_RGB && xnum_bands == 3 && xcompression == RL2_COMPRESSION_PNG) @@ -5012,12 +5042,12 @@ &num_bands, &compression, &crc)) return NULL; if (blob_even != NULL) { if (!check_blob_even - (blob_even, blob_even_sz, width, height, sample_type, pixel_type, - num_bands, compression, crc)) + (blob_even, blob_even_sz, width, height, sample_type, + pixel_type, num_bands, compression, crc)) return NULL; } if (!check_scale (scale, sample_type, compression, blob_even)) return NULL; @@ -5148,12 +5178,12 @@ if (even_data == NULL) goto error; if (uncompress (even_data, &refLen, in, compressed_even) != Z_OK) goto error; - if (rl2_delta_decode (even_data, uncompressed_even, delta_dist) - != RL2_OK) + if (rl2_delta_decode + (even_data, uncompressed_even, delta_dist) != RL2_OK) goto error; pixels_even = even_data; } } if (compression == RL2_COMPRESSION_DEFLATE_NO @@ -5306,30 +5336,30 @@ switch (scale) { case RL2_SCALE_1: ret = rl2_decode_jpeg_scaled (1, pixels_odd, compressed_odd, - &width, &height, &pix_typ, &pixels, - &pixels_sz); + &width, &height, &pix_typ, + &pixels, &pixels_sz); break; case RL2_SCALE_2: ret = rl2_decode_jpeg_scaled (2, pixels_odd, compressed_odd, - &width, &height, &pix_typ, &pixels, - &pixels_sz); + &width, &height, &pix_typ, + &pixels, &pixels_sz); break; case RL2_SCALE_4: ret = rl2_decode_jpeg_scaled (4, pixels_odd, compressed_odd, - &width, &height, &pix_typ, &pixels, - &pixels_sz); + &width, &height, &pix_typ, + &pixels, &pixels_sz); break; case RL2_SCALE_8: ret = rl2_decode_jpeg_scaled (8, pixels_odd, compressed_odd, - &width, &height, &pix_typ, &pixels, - &pixels_sz); + &width, &height, &pix_typ, + &pixels, &pixels_sz); break; }; if (ret != RL2_OK) goto error; goto done; @@ -5382,21 +5412,22 @@ } if (compression == RL2_COMPRESSION_PNG) { /* decompressing from PNG */ int ret; - if (sample_type == RL2_SAMPLE_1_BIT || sample_type == RL2_SAMPLE_2_BIT + if (sample_type == RL2_SAMPLE_1_BIT + || sample_type == RL2_SAMPLE_2_BIT || sample_type == RL2_SAMPLE_4_BIT) { /* Palette or Grayscale - 1,2 or 4 bit isn't scalable */ if (scale != RL2_SCALE_1) goto error; ret = rl2_decode_png (pixels_odd, compressed_odd, - &width, &height, &sample_type, &pixel_type, - &num_bands, &pixels, &pixels_sz, &mask, - &mask_sz, &palette, 0); + &width, &height, &sample_type, + &pixel_type, &num_bands, &pixels, + &pixels_sz, &mask, &mask_sz, &palette, 0); if (ret != RL2_OK) goto error; goto done; } else @@ -5411,13 +5442,14 @@ pixels_odd = odd_data; if (scale == RL2_SCALE_1) { ret = rl2_decode_png (pixels_even, compressed_even, &width, &even_rows, &sample_type, - &pixel_type, &num_bands, &even_data, - &pixels_sz, &even_mask, - &even_mask_sz, &palette2, 0); + &pixel_type, &num_bands, + &even_data, &pixels_sz, + &even_mask, &even_mask_sz, + &palette2, 0); if (ret != RL2_OK) goto error; rl2_destroy_palette (palette2); } pixels_even = even_data; @@ -5484,33 +5516,33 @@ { case RL2_SCALE_1: ret = rl2_decode_jpeg2000_scaled (1, pixels_odd, compressed_odd, &width, &height, sample_type, - pixel_type, num_bands, &pixels, - &pixels_sz); + pixel_type, num_bands, + &pixels, &pixels_sz); break; case RL2_SCALE_2: ret = rl2_decode_jpeg2000_scaled (2, pixels_odd, compressed_odd, &width, &height, sample_type, - pixel_type, num_bands, &pixels, - &pixels_sz); + pixel_type, num_bands, + &pixels, &pixels_sz); break; case RL2_SCALE_4: ret = rl2_decode_jpeg2000_scaled (4, pixels_odd, compressed_odd, &width, &height, sample_type, - pixel_type, num_bands, &pixels, - &pixels_sz); + pixel_type, num_bands, + &pixels, &pixels_sz); break; case RL2_SCALE_8: ret = rl2_decode_jpeg2000_scaled (8, pixels_odd, compressed_odd, &width, &height, sample_type, - pixel_type, num_bands, &pixels, - &pixels_sz); + pixel_type, num_bands, + &pixels, &pixels_sz); break; }; if (ret != RL2_OK) goto error; goto done; @@ -5560,12 +5592,12 @@ unsigned char *mask_pix; int mask_pix_sz; if (uncompressed_mask != (mask_width * mask_height)) goto error; if (!unpack_rle - (mask_width, mask_height, pixels_mask, compressed_mask, &mask_pix, - &mask_pix_sz)) + (mask_width, mask_height, pixels_mask, compressed_mask, + &mask_pix, &mask_pix_sz)) goto error; if (!rescale_mask (scale, &mask_width, &mask_height, mask_pix, &mask, &mask_sz)) { free (mask_pix); @@ -5611,10 +5643,121 @@ rl2_destroy_palette (palette); if (ext_palette != NULL) rl2_destroy_palette (ext_palette); return NULL; } + +RL2_PRIVATE rl2RasterPtr +rl2_raster_decode_mask (int scale, const unsigned char *blob_odd, + int blob_odd_sz, int *status) +{ +/* decoding from internal RL2 binary format to Raster - transparency mask only */ + rl2RasterPtr raster; + unsigned int width; + unsigned int height; + unsigned short mask_width = 0; + unsigned short mask_height = 0; + unsigned char sample_type; + unsigned char pixel_type; + unsigned char num_bands; + unsigned char compression; + int compressed_odd; + int uncompressed_mask; + int compressed_mask; + uLong crc; + const unsigned char *pixels_mask = NULL; + unsigned char *pixels = NULL; + int pixels_sz; + unsigned char *mask = NULL; + int mask_sz = 0; + const unsigned char *ptr; + int endian; + int endian_arch = endianArch (); + + *status = RL2_ERROR; + if (blob_odd == NULL) + return NULL; + if (!check_blob_odd + (blob_odd, blob_odd_sz, &width, &height, &sample_type, &pixel_type, + &num_bands, &compression, &crc)) + return NULL; + if (!check_scale2 (scale, sample_type)) + return NULL; + + endian = *(blob_odd + 2); + num_bands = *(blob_odd + 6); + ptr = blob_odd + 11; + ptr += 2; + ptr += 2; + ptr += 4; + compressed_odd = importU32 (ptr, endian, endian_arch); + ptr += 4; + uncompressed_mask = importU32 (ptr, endian, endian_arch); + ptr += 4; + compressed_mask = importU32 (ptr, endian, endian_arch); + ptr += 4; + if (*ptr++ != RL2_DATA_START) + return NULL; + if (uncompressed_mask > 0) + { + /* retrieving the mask */ + ptr += compressed_odd; + if (*ptr++ != RL2_DATA_END) + return NULL; + if (*ptr++ != RL2_MASK_START) + return NULL; + pixels_mask = ptr; + mask_width = width; + mask_height = height; + ptr += compressed_mask; + if (*ptr++ != RL2_MASK_END) + return NULL; + } + + if (pixels_mask == NULL) + { + /* not existing Mask - not an error */ + *status = RL2_OK; + return NULL; + } + + /* unpacking the mask */ + unsigned char *mask_pix; + int mask_pix_sz; + if (uncompressed_mask != (mask_width * mask_height)) + goto error; + if (!unpack_rle + (mask_width, mask_height, pixels_mask, compressed_mask, + &mask_pix, &mask_pix_sz)) + goto error; + if (!rescale_mask + (scale, &mask_width, &mask_height, mask_pix, &mask, &mask_sz)) + { + free (mask_pix); + goto error; + } + free (mask_pix); + + /* will always return a full BLACK grayscale UINT8 raster */ + pixels_sz = width * height; + pixels = malloc (pixels_sz); + memset (pixels, 0, pixels_sz); + raster = + rl2_create_raster (width, height, RL2_SAMPLE_UINT8, RL2_PIXEL_GRAYSCALE, + 1, pixels, pixels_sz, NULL, mask, mask_sz, NULL); + if (raster == NULL) + goto error; + *status = RL2_OK; + return raster; + error: + if (pixels != NULL) + free (pixels); + if (mask != NULL) + free (mask); + *status = RL2_ERROR; + return NULL; +} static void add_pooled_variance (rl2PrivBandStatisticsPtr band_in, rl2PrivBandStatisticsPtr band_out, double count) { @@ -5885,11 +6028,12 @@ if (rl2_get_pixel_type (no_data, &sample_type, &pixel_type, &nbands) != RL2_OK) ignore_no_data = 1; if (nbands != num_bands) ignore_no_data = 1; - if (sample_type == RL2_SAMPLE_1_BIT || sample_type == RL2_SAMPLE_2_BIT + if (sample_type == RL2_SAMPLE_1_BIT + || sample_type == RL2_SAMPLE_2_BIT || sample_type == RL2_SAMPLE_4_BIT || sample_type == RL2_SAMPLE_UINT8) ; else ignore_no_data = 1; @@ -6495,11 +6639,12 @@ compute_int32_histogram (width, height, pixels, mask, st, no_data); } static void compute_uint32_histogram (unsigned short width, unsigned short height, - const unsigned int *pixels, const unsigned char *mask, + const unsigned int *pixels, + const unsigned char *mask, rl2PrivRasterStatisticsPtr st, rl2PixelPtr no_data) { /* computing INT16 tile histogram */ int x; int y; Index: src/rl2dbms.c ================================================================== --- src/rl2dbms.c +++ src/rl2dbms.c @@ -77,14 +77,14 @@ unsigned char compression, int quality, unsigned int tile_width, unsigned int tile_height, int srid, double x_res, double y_res, unsigned char *blob, int blob_sz, - unsigned char *blob_no_data, int blob_no_data_sz, - int strict_resolution, int mixed_resolutions, - int section_paths, int section_md5, - int section_summary) + unsigned char *blob_no_data, + int blob_no_data_sz, int strict_resolution, + int mixed_resolutions, int section_paths, + int section_md5, int section_summary) { /* inserting into "raster_coverages" */ int ret; char *sql; sqlite3_stmt *stmt; @@ -278,12 +278,12 @@ "\ty_resolution_1_8 DOUBLE)\n", xxcoverage); ret = sqlite3_exec (handle, sql, NULL, NULL, &sql_err); sqlite3_free (sql); if (ret != SQLITE_OK) { - fprintf (stderr, "CREATE TABLE \"%s_levels\" error: %s\n", xxcoverage, - sql_err); + fprintf (stderr, "CREATE TABLE \"%s_levels\" error: %s\n", + xxcoverage, sql_err); sqlite3_free (sql_err); free (xxcoverage); return 0; } free (xxcoverage); @@ -338,12 +338,12 @@ free (xpk_name); free (xfk_name); free (xmother); if (ret != SQLITE_OK) { - fprintf (stderr, "CREATE TABLE \"%s_levels\" error: %s\n", xxcoverage, - sql_err); + fprintf (stderr, "CREATE TABLE \"%s_levels\" error: %s\n", + xxcoverage, sql_err); sqlite3_free (sql_err); free (xxcoverage); return 0; } free (xxcoverage); @@ -1246,11 +1246,12 @@ return RL2_ERROR; } RL2_DECLARE int rl2_resolve_base_resolution_from_dbms (sqlite3 * handle, const char *coverage, - int by_section, sqlite3_int64 section_id, + int by_section, + sqlite3_int64 section_id, double *x_res, double *y_res) { /* resolving the Base Resolution */ int ret; char *sql; @@ -1441,12 +1442,12 @@ *duplicate = 0; table = sqlite3_mprintf ("%s_sections", coverage); xtable = rl2_double_quoted_sql (table); sqlite3_free (table); sql = - sqlite3_mprintf ("SELECT section_id FROM \"%s\" WHERE section_name = ?", - xtable); + sqlite3_mprintf + ("SELECT section_id FROM \"%s\" WHERE section_name = ?", xtable); free (xtable); ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL); sqlite3_free (sql); if (ret != SQLITE_OK) { @@ -2388,13 +2389,14 @@ { section_summary = sqlite3_column_int (stmt, 15); ok_summary = 1; } if (ok_sample && ok_pixel && ok_num_bands && ok_compression - && ok_quality && ok_tile_width && ok_tile_height && ok_x_res - && ok_y_res && ok_srid && ok_nodata && ok_strict && ok_mixed - && ok_paths && ok_md5 && ok_summary) + && ok_quality && ok_tile_width && ok_tile_height + && ok_x_res && ok_y_res && ok_srid && ok_nodata + && ok_strict && ok_mixed && ok_paths && ok_md5 + && ok_summary) ok = 1; } } sqlite3_finalize (stmt); @@ -2422,12 +2424,12 @@ coverage); rl2_destroy_coverage (cvg); return NULL; } if (rl2_set_coverage_policies - (cvg, strict_resolution, mixed_resolutions, section_paths, section_md5, - section_summary) != RL2_OK) + (cvg, strict_resolution, mixed_resolutions, section_paths, + section_md5, section_summary) != RL2_OK) { fprintf (stderr, "ERROR: unable to set the Policies on the Coverage Object supporting \"%s\"\n", coverage); rl2_destroy_coverage (cvg); @@ -2535,12 +2537,12 @@ free (f_geometry_column); return NULL; } vector = - rl2_create_vector_layer (f_table_name, f_geometry_column, geometry_type, - srid, spatial_index); + rl2_create_vector_layer (f_table_name, f_geometry_column, + geometry_type, srid, spatial_index); free (f_table_name); free (f_geometry_column); if (vector == NULL) { fprintf (stderr, @@ -2601,11 +2603,11 @@ for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { for (b = 0; b < num_bands; b++) - *p++ = 0; + *p++ = 255; } } } else { @@ -2890,11 +2892,12 @@ static void do_decode_tile (rl2AuxDecoderPtr decoder) { /* servicing an AuxDecoder Tile request */ decoder->raster = - (rl2PrivRasterPtr) rl2_raster_decode (decoder->scale, decoder->blob_odd, + (rl2PrivRasterPtr) rl2_raster_decode (decoder->scale, + decoder->blob_odd, decoder->blob_odd_sz, decoder->blob_even, decoder->blob_even_sz, (rl2PalettePtr) (decoder->palette)); @@ -2925,10 +2928,42 @@ } rl2_destroy_raster ((rl2RasterPtr) (decoder->raster)); decoder->raster = NULL; decoder->retcode = RL2_OK; } + +static void +do_decode_masktile (rl2AuxMaskDecoderPtr decoder) +{ +/* servicing an AuxMaskDecoder Tile request */ + int status; + decoder->raster = + (rl2PrivRasterPtr) rl2_raster_decode_mask (decoder->scale, + decoder->blob_odd, + decoder->blob_odd_sz, + &status); + if (decoder->blob_odd != NULL) + free (decoder->blob_odd); + decoder->blob_odd = NULL; + if (decoder->raster == NULL) + { + decoder->retcode = status; + return; + } + if (!rl2_copy_raw_mask + ((rl2RasterPtr) (decoder->raster), decoder->maskbuf, decoder->width, + decoder->height, decoder->x_res, decoder->y_res, decoder->minx, + decoder->maxy, decoder->tile_minx, decoder->tile_maxy)) + { + decoder->retcode = RL2_ERROR; + return; + } + + rl2_destroy_raster ((rl2RasterPtr) (decoder->raster)); + decoder->raster = NULL; + decoder->retcode = RL2_OK; +} #ifdef _WIN32 DWORD WINAPI doRunDecoderThread (void *arg) #else @@ -2939,10 +2974,28 @@ /* threaded function: decoding a Tile */ rl2AuxDecoderPtr decoder = (rl2AuxDecoderPtr) arg; do_decode_tile (decoder); #ifdef _WIN32 return 0; +#else + pthread_exit (NULL); +#endif +} + +#ifdef _WIN32 +DWORD WINAPI +doRunMaskDecoderThread (void *arg) +#else +void * +doRunMaskDecoderThread (void *arg) +#endif +{ +/* threaded function: decoding a Tile */ + rl2AuxMaskDecoderPtr decoder = (rl2AuxMaskDecoderPtr) arg; + do_decode_masktile (decoder); +#ifdef _WIN32 + return 0; #else pthread_exit (NULL); #endif } @@ -2988,10 +3041,60 @@ if (!ok_prior) { /* failure: using standard priority */ pthread_create (&thread_id, NULL, doRunDecoderThread, decoder); } + p_thread = malloc (sizeof (pthread_t)); + *p_thread = thread_id; + decoder->opaque_thread_id = p_thread; +#endif +} + +static void +start_mask_decoder_thread (rl2AuxMaskDecoderPtr decoder) +{ +/* starting a concurrent thread */ +#ifdef _WIN32 + HANDLE thread_handle; + HANDLE *p_thread; + DWORD dwThreadId; + thread_handle = + CreateThread (NULL, 0, doRunMaskDecoderThread, decoder, 0, &dwThreadId); + SetThreadPriority (thread_handle, THREAD_PRIORITY_IDLE); + p_thread = malloc (sizeof (HANDLE)); + *p_thread = thread_handle; + decoder->opaque_thread_id = p_thread; +#else + pthread_t thread_id; + pthread_t *p_thread; + int ok_prior = 0; + int policy; + int min_prio; + pthread_attr_t attr; + struct sched_param sp; + pthread_attr_init (&attr); + if (pthread_attr_setschedpolicy (&attr, SCHED_RR) == 0) + { + /* attempting to set the lowest priority */ + if (pthread_attr_getschedpolicy (&attr, &policy) == 0) + { + min_prio = sched_get_priority_min (policy); + sp.sched_priority = min_prio; + if (pthread_attr_setschedparam (&attr, &sp) == 0) + { + /* ok, setting the lowest priority */ + ok_prior = 1; + pthread_create (&thread_id, &attr, doRunMaskDecoderThread, + decoder); + } + } + } + if (!ok_prior) + { + /* failure: using standard priority */ + pthread_create (&thread_id, NULL, doRunMaskDecoderThread, decoder); + } p_thread = malloc (sizeof (pthread_t)); *p_thread = thread_id; decoder->opaque_thread_id = p_thread; #endif } @@ -3072,16 +3175,285 @@ return 1; error: return 0; } + +static int +do_run_mask_decoder_children (rl2AuxMaskDecoderPtr * thread_slots, + int thread_count) +{ +/* concurrent execution of all mask decoder children threads */ + rl2AuxMaskDecoderPtr decoder; + int i; +#ifdef _WIN32 + HANDLE *handles; +#endif + + for (i = 0; i < thread_count; i++) + { + /* starting all children threads */ + decoder = *(thread_slots + i); + start_mask_decoder_thread (decoder); + } + +/* waiting until all child threads exit */ +#ifdef _WIN32 + handles = malloc (sizeof (HANDLE) * thread_count); + for (i = 0; i < thread_count; i++) + { + /* initializing the HANDLEs array */ + HANDLE *pOpaque; + decoder = *(thread_slots + i); + pOpaque = (HANDLE *) (decoder->opaque_thread_id); + *(handles + i) = *pOpaque; + } + WaitForMultipleObjects (thread_count, handles, TRUE, INFINITE); + free (handles); +#else + for (i = 0; i < thread_count; i++) + { + pthread_t *pOpaque; + decoder = *(thread_slots + i); + pOpaque = (pthread_t *) (decoder->opaque_thread_id); + pthread_join (*pOpaque, NULL); + } +#endif + +/* all children threads have now finished: resuming the main thread */ + for (i = 0; i < thread_count; i++) + { + /* cleaning up a request slot */ + decoder = *(thread_slots + i); + if (decoder->blob_odd != NULL) + free (decoder->blob_odd); + if (decoder->raster != NULL) + rl2_destroy_raster ((rl2RasterPtr) (decoder->raster)); + if (decoder->opaque_thread_id != NULL) + free (decoder->opaque_thread_id); + decoder->blob_odd = NULL; + decoder->blob_odd_sz = 0; + decoder->raster = NULL; + decoder->opaque_thread_id = NULL; + } + for (i = 0; i < thread_count; i++) + { + /* checking for eventual errors */ + decoder = *(thread_slots + i); + if (decoder->retcode != RL2_OK) + { + fprintf (stderr, ERR_FRMT64, decoder->tile_id); + goto error; + } + } + return 1; + + error: + return 0; +} + +static int +rl2_load_dbms_masktiles (sqlite3 * handle, int max_threads, int by_section, + sqlite3_int64 section_id, sqlite3_stmt * stmt_tiles, + sqlite3_stmt * stmt_data, unsigned char *maskbuf, + unsigned int width, unsigned int height, double x_res, + double y_res, double minx, double miny, double maxx, + double maxy, int level, int scale) +{ +/* retrieving a transparenct mask from DBMS tiles */ + rl2RasterPtr raster = NULL; + int ret; + rl2AuxMaskDecoderPtr aux = NULL; + rl2AuxMaskDecoderPtr decoder; + rl2AuxMaskDecoderPtr *thread_slots = NULL; + int thread_count; + int iaux; + + if (max_threads < 1) + max_threads = 1; + if (max_threads > 64) + max_threads = 64; +/* allocating the AuxDecoder array */ + aux = malloc (sizeof (rl2AuxMaskDecoder) * max_threads); + if (aux == NULL) + return 0; + for (iaux = 0; iaux < max_threads; iaux++) + { + /* initializing an empty AuxDecoder */ + decoder = aux + iaux; + decoder->opaque_thread_id = NULL; + decoder->blob_odd = NULL; + decoder->blob_odd_sz = 0; + decoder->maskbuf = maskbuf; + decoder->width = width; + decoder->height = height; + decoder->x_res = x_res; + decoder->y_res = y_res; + decoder->scale = scale; + decoder->minx = minx; + decoder->maxy = maxy; + decoder->raster = NULL; + } + +/* preparing the thread_slots stuct */ + thread_slots = malloc (sizeof (rl2AuxMaskDecoderPtr) * max_threads); + for (thread_count = 0; thread_count < max_threads; thread_count++) + *(thread_slots + thread_count) = NULL; + thread_count = 0; + +/* binding the query args */ + sqlite3_reset (stmt_tiles); + sqlite3_clear_bindings (stmt_tiles); + if (by_section) + { + sqlite3_bind_int (stmt_tiles, 1, section_id); + sqlite3_bind_int (stmt_tiles, 2, level); + sqlite3_bind_double (stmt_tiles, 3, minx); + sqlite3_bind_double (stmt_tiles, 4, miny); + sqlite3_bind_double (stmt_tiles, 5, maxx); + sqlite3_bind_double (stmt_tiles, 6, maxy); + } + else + { + sqlite3_bind_int (stmt_tiles, 1, level); + sqlite3_bind_double (stmt_tiles, 2, minx); + sqlite3_bind_double (stmt_tiles, 3, miny); + sqlite3_bind_double (stmt_tiles, 4, maxx); + sqlite3_bind_double (stmt_tiles, 5, maxy); + } + +/* querying the tiles */ + while (1) + { + ret = sqlite3_step (stmt_tiles); + if (ret == SQLITE_DONE) + break; + if (ret == SQLITE_ROW) + { + int ok = 0; + const unsigned char *blob_odd = NULL; + int blob_odd_sz = 0; + sqlite3_int64 tile_id = sqlite3_column_int64 (stmt_tiles, 0); + double tile_minx = sqlite3_column_double (stmt_tiles, 1); + double tile_maxy = sqlite3_column_double (stmt_tiles, 2); + decoder = aux + thread_count; + decoder->tile_id = tile_id; + decoder->tile_minx = tile_minx; + decoder->tile_maxy = tile_maxy; + + /* retrieving tile raw data from BLOBs */ + sqlite3_reset (stmt_data); + sqlite3_clear_bindings (stmt_data); + sqlite3_bind_int64 (stmt_data, 1, tile_id); + ret = sqlite3_step (stmt_data); + if (ret == SQLITE_DONE) + break; + if (ret == SQLITE_ROW) + { + /* decoding a Tile - may be by using concurrent multithreading */ + if (sqlite3_column_type (stmt_data, 0) == SQLITE_BLOB) + { + blob_odd = sqlite3_column_blob (stmt_data, 0); + blob_odd_sz = sqlite3_column_bytes (stmt_data, 0); + decoder->blob_odd = malloc (blob_odd_sz); + if (decoder->blob_odd == NULL) + goto error; + memcpy (decoder->blob_odd, blob_odd, blob_odd_sz); + decoder->blob_odd_sz = blob_odd_sz; + ok = 1; + } + } + else + { + fprintf (stderr, + "SELECT tiles data; sqlite3_step() error: %s\n", + sqlite3_errmsg (handle)); + goto error; + } + if (!ok) + { + if (decoder->blob_odd != NULL) + free (decoder->blob_odd); + decoder->blob_odd = NULL; + decoder->blob_odd_sz = 0; + } + else + { + /* processing a Tile request (may be under parallel execution) */ + if (max_threads > 1) + { + /* adopting a multithreaded strategy */ + *(thread_slots + thread_count) = decoder; + thread_count++; + if (thread_count == max_threads) + { + if (!do_run_mask_decoder_children + (thread_slots, thread_count)) + goto error; + thread_count = 0; + } + } + else + { + /* single thread execution */ + do_decode_masktile (decoder); + if (decoder->retcode != RL2_OK) + { + fprintf (stderr, ERR_FRMT64, tile_id); + goto error; + } + } + } + } + else + { + fprintf (stderr, + "SELECT tiles; sqlite3_step() error: %s\n", + sqlite3_errmsg (handle)); + goto error; + } + } + if (max_threads > 1 && thread_count > 0) + { + /* launching the last multithreaded burst */ + if (!do_run_mask_decoder_children (thread_slots, thread_count)) + goto error; + } + + free (aux); + free (thread_slots); + return 1; + + error: + if (aux != NULL) + { + /* AuxMaskDecoder cleanup */ + for (iaux = 0; iaux < max_threads; iaux++) + { + decoder = aux + iaux; + if (decoder->blob_odd != NULL) + free (decoder->blob_odd); + if (decoder->raster != NULL) + rl2_destroy_raster ((rl2RasterPtr) (decoder->raster)); + if (decoder->opaque_thread_id != NULL) + free (decoder->opaque_thread_id); + } + free (aux); + } + if (thread_slots != NULL) + free (thread_slots); + if (raster != NULL) + rl2_destroy_raster (raster); + return 0; +} static int rl2_load_dbms_tiles_common (sqlite3 * handle, int max_threads, - sqlite3_stmt * stmt_tiles, sqlite3_stmt * stmt_data, - unsigned char *outbuf, unsigned int width, - unsigned int height, unsigned char sample_type, + sqlite3_stmt * stmt_tiles, + sqlite3_stmt * stmt_data, unsigned char *outbuf, + unsigned int width, unsigned int height, + unsigned char sample_type, unsigned char num_bands, unsigned char auto_ndvi, unsigned char red_band_index, unsigned char nir_band_index, double x_res, double y_res, double minx, double maxy, int scale, rl2PalettePtr palette, rl2PixelPtr no_data, @@ -3706,21 +4078,21 @@ "SELECT tiles data; sqlite3_step() error: %s\n", sqlite3_errmsg (handle)); goto error; } raster = - rl2_raster_decode (scale, blob_odd, blob_odd_sz, blob_even, - blob_even_sz, NULL); + rl2_raster_decode (scale, blob_odd, blob_odd_sz, + blob_even, blob_even_sz, NULL); if (raster == NULL) { fprintf (stderr, ERR_FRMT64, tile_id); goto error; } if (!copy_triple_band_raw_pixels (raster, outbuf, width, height, red_band, green_band, - blue_band, x_res, y_res, minx, maxy, tile_minx, tile_maxy, - no_data)) + blue_band, x_res, y_res, minx, maxy, tile_minx, + tile_maxy, no_data)) goto error; rl2_destroy_raster (raster); raster = NULL; } else @@ -3868,13 +4240,14 @@ } static int copy_mono_band_raw_pixels (rl2RasterPtr raster, unsigned char *outbuf, unsigned int width, unsigned int height, - unsigned char mono_band, double x_res, double y_res, - double minx, double maxy, double tile_minx, - double tile_maxy, rl2PixelPtr no_data) + unsigned char mono_band, double x_res, + double y_res, double minx, double maxy, + double tile_minx, double tile_maxy, + rl2PixelPtr no_data) { /* copying raw pixels into the output buffer */ unsigned int tile_width; unsigned int tile_height; unsigned int x; @@ -4001,13 +4374,14 @@ static int load_mono_band_dbms_tiles (sqlite3 * handle, sqlite3_stmt * stmt_tiles, sqlite3_stmt * stmt_data, unsigned char *outbuf, unsigned int width, unsigned int height, - unsigned char mono_band, double x_res, double y_res, - double minx, double miny, double maxx, double maxy, - int level, int scale, rl2PixelPtr no_data) + unsigned char mono_band, double x_res, + double y_res, double minx, double miny, + double maxx, double maxy, int level, int scale, + rl2PixelPtr no_data) { /* retrieving a full image from DBMS tiles */ rl2RasterPtr raster = NULL; int ret; @@ -4062,12 +4436,12 @@ "SELECT tiles data; sqlite3_step() error: %s\n", sqlite3_errmsg (handle)); goto error; } raster = - rl2_raster_decode (scale, blob_odd, blob_odd_sz, blob_even, - blob_even_sz, NULL); + rl2_raster_decode (scale, blob_odd, blob_odd_sz, + blob_even, blob_even_sz, NULL); if (raster == NULL) { fprintf (stderr, ERR_FRMT64, tile_id); goto error; } @@ -4099,15 +4473,16 @@ rl2_load_dbms_tiles (sqlite3 * handle, int max_threads, sqlite3_stmt * stmt_tiles, sqlite3_stmt * stmt_data, unsigned char *outbuf, unsigned int width, unsigned int height, unsigned char sample_type, unsigned char num_bands, unsigned char auto_ndvi, - unsigned char red_band_index, unsigned char nir_band_index, - double x_res, double y_res, double minx, double miny, - double maxx, double maxy, int level, int scale, - rl2PalettePtr palette, rl2PixelPtr no_data, - rl2RasterSymbolizerPtr style, rl2RasterStatisticsPtr stats) + unsigned char red_band_index, + unsigned char nir_band_index, double x_res, double y_res, + double minx, double miny, double maxx, double maxy, + int level, int scale, rl2PalettePtr palette, + rl2PixelPtr no_data, rl2RasterSymbolizerPtr style, + rl2RasterStatisticsPtr stats) { /* binding the query args */ sqlite3_reset (stmt_tiles); sqlite3_clear_bindings (stmt_tiles); sqlite3_bind_int (stmt_tiles, 1, level); @@ -4128,21 +4503,27 @@ rl2_load_dbms_tiles_section (sqlite3 * handle, int max_threads, sqlite3_int64 section_id, sqlite3_stmt * stmt_tiles, sqlite3_stmt * stmt_data, unsigned char *outbuf, unsigned int width, unsigned int height, - unsigned char sample_type, unsigned char num_bands, - unsigned char auto_ndvi, + unsigned char sample_type, + unsigned char num_bands, unsigned char auto_ndvi, unsigned char red_band_index, unsigned char nir_band_index, double x_res, - double y_res, double minx, double maxy, int scale, + double y_res, double minx, double miny, + double maxx, double maxy, int level, int scale, rl2PalettePtr palette, rl2PixelPtr no_data) { /* binding the query args */ sqlite3_reset (stmt_tiles); sqlite3_clear_bindings (stmt_tiles); sqlite3_bind_int (stmt_tiles, 1, section_id); + sqlite3_bind_int (stmt_tiles, 2, level); + sqlite3_bind_double (stmt_tiles, 3, minx); + sqlite3_bind_double (stmt_tiles, 4, miny); + sqlite3_bind_double (stmt_tiles, 5, maxx); + sqlite3_bind_double (stmt_tiles, 6, maxy); if (!rl2_load_dbms_tiles_common (handle, max_threads, stmt_tiles, stmt_data, outbuf, width, height, sample_type, num_bands, auto_ndvi, red_band_index, nir_band_index, x_res, y_res, minx, maxy, scale, palette, no_data, NULL, NULL)) @@ -4433,10 +4814,161 @@ for (i = 1; i <= rows; i++) scale_factor = 11.1120; sqlite3_free_table (results); return scale_factor; } + +RL2_DECLARE int +rl2_get_raw_raster_mask (sqlite3 * handle, int max_threads, + rl2CoveragePtr cvg, unsigned int width, + unsigned int height, double minx, double miny, + double maxx, double maxy, double x_res, + double y_res, unsigned char **mask, int *mask_size) +{ +/* attempting to return a transparency mask from the DBMS Coverage */ + return rl2_get_raw_raster_mask_common (handle, max_threads, + cvg, 0, 0, width, height, minx, miny, + maxx, maxy, x_res, y_res, mask, + mask_size); +} + +RL2_DECLARE int +rl2_get_section_raw_raster_mask (sqlite3 * handle, int max_threads, + rl2CoveragePtr cvg, + sqlite3_int64 section_id, + unsigned int width, + unsigned int height, double minx, + double miny, double maxx, double maxy, + double x_res, double y_res, + unsigned char **mask, int *mask_size) +{ +/* attempting to return a transparency mask from the DBMS Coverage */ + return rl2_get_raw_raster_mask_common (handle, max_threads, + cvg, 1, section_id, width, height, + minx, miny, maxx, maxy, x_res, y_res, + mask, mask_size); +} + +RL2_PRIVATE int +rl2_get_raw_raster_mask_common (sqlite3 * handle, int max_threads, + rl2CoveragePtr cvg, int by_section, + sqlite3_int64 section_id, unsigned int width, + unsigned int height, double minx, double miny, + double maxx, double maxy, double x_res, + double y_res, unsigned char **mask, + int *mask_size) +{ +/* attempting to return a transparency mask from the DBMS Coverage */ + const char *coverage; + unsigned char level; + unsigned char scale; + double xx_res = x_res; + double yy_res = y_res; + unsigned char *bufpix = NULL; + int bufpix_size; + char *xtiles; + char *xxtiles; + char *xdata; + char *xxdata; + char *sql; + sqlite3_stmt *stmt_tiles = NULL; + sqlite3_stmt *stmt_data = NULL; + int ret; + + if (cvg == NULL || handle == NULL) + goto error; + coverage = rl2_get_coverage_name (cvg); + if (coverage == NULL) + goto error; + if (rl2_find_matching_resolution + (handle, cvg, by_section, section_id, &xx_res, &yy_res, &level, + &scale) != RL2_OK) + goto error; + + bufpix_size = width * height; + bufpix = malloc (bufpix_size); + if (bufpix == NULL) + { + fprintf (stderr, + "rl2_get_raw_raster_mask: Insufficient Memory !!!\n"); + goto error; + } + +/* preparing the "tiles" SQL query */ + xtiles = sqlite3_mprintf ("%s_tiles", coverage); + xxtiles = rl2_double_quoted_sql (xtiles); + if (by_section) + { + /* only from a single Section */ + sql = + sqlite3_mprintf + ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) " + "FROM \"%s\" " + "WHERE section_id = ? AND pyramid_level = ? AND ROWID IN ( " + "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q " + "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles, xtiles); + } + else + { + /* whole Coverage */ + sql = + sqlite3_mprintf + ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) " + "FROM \"%s\" " "WHERE pyramid_level = ? AND ROWID IN ( " + "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q " + "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles, xtiles); + } + sqlite3_free (xtiles); + free (xxtiles); + ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_tiles, NULL); + sqlite3_free (sql); + if (ret != SQLITE_OK) + { + printf ("SELECT raw tiles SQL error: %s\n", sqlite3_errmsg (handle)); + goto error; + } + + /* preparing the data SQL query - only ODD */ + xdata = sqlite3_mprintf ("%s_tile_data", coverage); + xxdata = rl2_double_quoted_sql (xdata); + sqlite3_free (xdata); + sql = sqlite3_mprintf ("SELECT tile_data_odd " + "FROM \"%s\" WHERE tile_id = ?", xxdata); + free (xxdata); + ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_data, NULL); + sqlite3_free (sql); + if (ret != SQLITE_OK) + { + printf ("SELECT raw tiles data(1) SQL error: %s\n", + sqlite3_errmsg (handle)); + goto error; + } + +/* preparing a fully opaque mask */ + memset (bufpix, 0, bufpix_size); + + if (!rl2_load_dbms_masktiles + (handle, max_threads, by_section, section_id, stmt_tiles, stmt_data, + bufpix, width, height, xx_res, yy_res, minx, miny, maxx, maxy, level, + scale)) + goto error; + sqlite3_finalize (stmt_tiles); + sqlite3_finalize (stmt_data); + *mask = bufpix; + *mask_size = bufpix_size; + + return RL2_OK; + + error: + if (stmt_tiles != NULL) + sqlite3_finalize (stmt_tiles); + if (stmt_data != NULL) + sqlite3_finalize (stmt_data); + if (bufpix != NULL) + free (bufpix); + return RL2_ERROR; +} RL2_PRIVATE int rl2_get_raw_raster_data_common (sqlite3 * handle, int max_threads, rl2CoveragePtr cvg, int by_section, sqlite3_int64 section_id, unsigned int width, @@ -4585,14 +5117,14 @@ if (!ok) { /* default: white */ rl2_set_pixel_sample_uint8 (no_data, RL2_RED_BAND, 255); - rl2_set_pixel_sample_uint8 (no_data, RL2_GREEN_BAND, - 255); - rl2_set_pixel_sample_uint8 (no_data, RL2_BLUE_BAND, - 255); + rl2_set_pixel_sample_uint8 (no_data, + RL2_GREEN_BAND, 255); + rl2_set_pixel_sample_uint8 (no_data, + RL2_BLUE_BAND, 255); } } } if (plt != NULL) rl2_destroy_palette (plt); @@ -4679,13 +5211,14 @@ rl2_get_shaded_relief_scale_factor (handle, coverage); if (rl2_get_raster_symbolizer_shaded_relief (style, &brightness_only, &relief_factor) != RL2_OK) goto error; if (rl2_build_shaded_relief_mask - (handle, max_threads, cvg, relief_factor, scale_factor, - width, height, minx, miny, maxx, maxy, x_res, y_res, - &shaded_relief, &shaded_relief_sz) != RL2_OK) + (handle, max_threads, cvg, by_section, section_id, + relief_factor, scale_factor, width, height, minx, miny, + maxx, maxy, x_res, y_res, &shaded_relief, + &shaded_relief_sz) != RL2_OK) goto error; if (brightness_only || !rl2_has_styled_rgb_colors (style)) { /* returning a Grayscale ShadedRelief (BrightnessOnly) */ @@ -4725,24 +5258,17 @@ xtiles = sqlite3_mprintf ("%s_tiles", coverage); xxtiles = rl2_double_quoted_sql (xtiles); if (by_section) { /* only from a single Section */ - char sctn[1024]; -#if defined(_WIN32) && !defined(__MINGW32__) - sprintf (sctn, "%I64d", section_id); -#else - sprintf (sctn, "%lld", section_id); -#endif sql = sqlite3_mprintf ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) " "FROM \"%s\" " - "WHERE section_id = %s AND pyramid_level = ? AND ROWID IN ( " + "WHERE section_id = ? AND pyramid_level = ? AND ROWID IN ( " "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q " - "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles, sctn, - xtiles); + "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles, xtiles); } else { /* whole Coverage */ sql = @@ -4811,15 +5337,30 @@ bgcolor); else void_raw_buffer (bufpix, width, height, sample_type, num_bands, no_data); } - if (!rl2_load_dbms_tiles - (handle, max_threads, stmt_tiles, stmt_data, bufpix, width, height, - sample_type, num_bands, auto_ndvi, red_band, nir_band, xx_res, yy_res, - minx, miny, maxx, maxy, level, scale, plt, no_data, style, stats)) - goto error; + if (by_section) + { + /* only from a single Section */ + if (!rl2_load_dbms_tiles_section + (handle, max_threads, section_id, stmt_tiles, stmt_data, bufpix, + width, height, sample_type, num_bands, auto_ndvi, red_band, + nir_band, xx_res, yy_res, minx, miny, maxx, maxy, level, scale, + plt, no_data)) + goto error; + } + else + { + /* whole Coverage */ + if (!rl2_load_dbms_tiles + (handle, max_threads, stmt_tiles, stmt_data, bufpix, width, + height, sample_type, num_bands, auto_ndvi, red_band, nir_band, + xx_res, yy_res, minx, miny, maxx, maxy, level, scale, plt, + no_data, style, stats)) + goto error; + } if (kill_no_data != NULL) rl2_destroy_pixel (kill_no_data); sqlite3_finalize (stmt_tiles); sqlite3_finalize (stmt_data); if (shaded_relief != NULL) @@ -4870,23 +5411,23 @@ free (shaded_relief); return RL2_ERROR; } RL2_DECLARE int -rl2_get_raw_raster_data (sqlite3 * handle, int max_threads, rl2CoveragePtr cvg, - unsigned int width, unsigned int height, - double minx, double miny, double maxx, double maxy, - double x_res, double y_res, unsigned char **buffer, - int *buf_size, rl2PalettePtr * palette, - unsigned char out_pixel) +rl2_get_raw_raster_data (sqlite3 * handle, int max_threads, + rl2CoveragePtr cvg, unsigned int width, + unsigned int height, double minx, double miny, + double maxx, double maxy, double x_res, double y_res, + unsigned char **buffer, int *buf_size, + rl2PalettePtr * palette, unsigned char out_pixel) { /* attempting to return a buffer containing raw pixels from the DBMS Coverage */ return rl2_get_raw_raster_data_common (handle, max_threads, cvg, 0, 0, width, height, minx, miny, maxx, - maxy, x_res, y_res, buffer, buf_size, - palette, out_pixel, NULL, NULL, - NULL); + maxy, x_res, y_res, buffer, + buf_size, palette, out_pixel, NULL, + NULL, NULL); } RL2_DECLARE int rl2_get_section_raw_raster_data (sqlite3 * handle, int max_threads, rl2CoveragePtr cvg, sqlite3_int64 section_id, @@ -4899,21 +5440,22 @@ { /* attempting to return a buffer containing raw pixels from the DBMS Coverage/Section */ return rl2_get_raw_raster_data_common (handle, max_threads, cvg, 1, section_id, width, height, minx, miny, maxx, maxy, x_res, y_res, - buffer, buf_size, palette, out_pixel, - NULL, NULL, NULL); + buffer, buf_size, palette, + out_pixel, NULL, NULL, NULL); } static int get_triple_band_raw_raster_data_common (int by_section, sqlite3 * handle, rl2CoveragePtr cvg, sqlite3_int64 section_id, - unsigned int width, unsigned int height, - double minx, double miny, double maxx, - double maxy, double x_res, double y_res, + unsigned int width, + unsigned int height, double minx, + double miny, double maxx, double maxy, + double x_res, double y_res, unsigned char red_band, unsigned char green_band, unsigned char blue_band, unsigned char **buffer, int *buf_size, rl2PixelPtr bgcolor) @@ -5074,13 +5616,14 @@ rl2PixelPtr bgcolor) { /* attempting to return a buffer containing raw pixels from the DBMS Coverage */ return get_triple_band_raw_raster_data_common (0, handle, cvg, 0, width, height, minx, miny, maxx, - maxy, x_res, y_res, red_band, - green_band, blue_band, - buffer, buf_size, bgcolor); + maxy, x_res, y_res, + red_band, green_band, + blue_band, buffer, + buf_size, bgcolor); } RL2_DECLARE int rl2_get_section_triple_band_raw_raster_data (sqlite3 * handle, rl2CoveragePtr cvg, @@ -5099,12 +5642,12 @@ /* attempting to return a buffer containing raw pixels - Section */ return get_triple_band_raw_raster_data_common (1, handle, cvg, section_id, width, height, minx, miny, maxx, maxy, x_res, y_res, red_band, green_band, - blue_band, buffer, buf_size, - bgcolor); + blue_band, buffer, + buf_size, bgcolor); } static int get_mono_band_raw_raster_data_common (int by_section, sqlite3 * handle, rl2CoveragePtr cvg, @@ -5265,17 +5808,18 @@ unsigned char **buffer, int *buf_size, rl2PixelPtr no_data) { /* attempting to return a buffer containing raw pixels from the DBMS Coverage */ return get_mono_band_raw_raster_data_common (0, handle, cvg, 0, width, - height, minx, miny, maxx, maxy, - x_res, y_res, buffer, buf_size, - mono_band, no_data); + height, minx, miny, maxx, + maxy, x_res, y_res, buffer, + buf_size, mono_band, no_data); } RL2_DECLARE int -rl2_get_section_mono_band_raw_raster_data (sqlite3 * handle, rl2CoveragePtr cvg, +rl2_get_section_mono_band_raw_raster_data (sqlite3 * handle, + rl2CoveragePtr cvg, sqlite3_int64 section_id, unsigned int width, unsigned int height, double minx, double miny, double maxx, double maxy, double x_res, @@ -5293,16 +5837,18 @@ } RL2_DECLARE int rl2_get_raw_raster_data_bgcolor (sqlite3 * handle, int max_threads, rl2CoveragePtr cvg, unsigned int width, - unsigned int height, double minx, double miny, - double maxx, double maxy, double x_res, - double y_res, unsigned char **buffer, - int *buf_size, rl2PalettePtr * palette, - unsigned char *out_pixel, unsigned char bg_red, - unsigned char bg_green, unsigned char bg_blue, + unsigned int height, double minx, + double miny, double maxx, double maxy, + double x_res, double y_res, + unsigned char **buffer, int *buf_size, + rl2PalettePtr * palette, + unsigned char *out_pixel, + unsigned char bg_red, unsigned char bg_green, + unsigned char bg_blue, rl2RasterSymbolizerPtr style, rl2RasterStatisticsPtr stats) { /* attempting to return a buffer containing raw pixels from the DBMS Coverage + bgcolor */ int ret; @@ -5382,33 +5928,33 @@ /* palette color found */ switch (sample_type) { case RL2_SAMPLE_1_BIT: no_data = - rl2_create_pixel (RL2_SAMPLE_1_BIT, RL2_PIXEL_PALETTE, - 1); + rl2_create_pixel (RL2_SAMPLE_1_BIT, + RL2_PIXEL_PALETTE, 1); rl2_set_pixel_sample_1bit (no_data, (unsigned char) index); break; case RL2_SAMPLE_2_BIT: no_data = - rl2_create_pixel (RL2_SAMPLE_2_BIT, RL2_PIXEL_PALETTE, - 1); + rl2_create_pixel (RL2_SAMPLE_2_BIT, + RL2_PIXEL_PALETTE, 1); rl2_set_pixel_sample_2bit (no_data, (unsigned char) index); break; case RL2_SAMPLE_4_BIT: no_data = - rl2_create_pixel (RL2_SAMPLE_4_BIT, RL2_PIXEL_PALETTE, - 1); + rl2_create_pixel (RL2_SAMPLE_4_BIT, + RL2_PIXEL_PALETTE, 1); rl2_set_pixel_sample_4bit (no_data, (unsigned char) index); break; case RL2_SAMPLE_UINT8: no_data = - rl2_create_pixel (RL2_SAMPLE_UINT8, RL2_PIXEL_PALETTE, - 1); + rl2_create_pixel (RL2_SAMPLE_UINT8, + RL2_PIXEL_PALETTE, 1); rl2_set_pixel_sample_uint8 (no_data, RL2_PALETTE_BAND, (unsigned char) index); break; }; @@ -5705,12 +6251,13 @@ int ret; if (handle == NULL || coverage == NULL || palette == NULL) return RL2_ERROR; sql = - sqlite3_mprintf ("SELECT sample_type, pixel_type FROM raster_coverages " - "WHERE Lower(coverage_name) = Lower(%Q)", coverage); + sqlite3_mprintf + ("SELECT sample_type, pixel_type FROM raster_coverages " + "WHERE Lower(coverage_name) = Lower(%Q)", coverage); ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL); sqlite3_free (sql); if (ret != SQLITE_OK) { fprintf (stderr, "SQL error: %s\n%s\n", sql, sqlite3_errmsg (handle)); @@ -6233,11 +6780,12 @@ rl2_destroy_coverage_style (stl); return NULL; } RL2_DECLARE rl2FeatureTypeStylePtr -rl2_create_feature_type_style_from_dbms (sqlite3 * handle, const char *coverage, +rl2_create_feature_type_style_from_dbms (sqlite3 * handle, + const char *coverage, const char *style) { /* attempting to load and parse a Feature Type Style */ const char *sql; int ret; @@ -6377,15 +6925,16 @@ int columns; int i; int ok = 0; /* testing if the Layer Style exists */ char *sql = - sqlite3_mprintf ("SELECT style_name FROM SE_raster_styled_layers AS r " - "JOIN SE_raster_styles AS s ON (r.style_id = s.style_id) " - "WHERE Lower(r.coverage_name) = Lower(%Q) AND " - "Lower(s.style_name) = Lower(%Q)", namedLayer, - namedStyle); + sqlite3_mprintf + ("SELECT style_name FROM SE_raster_styled_layers AS r " + "JOIN SE_raster_styles AS s ON (r.style_id = s.style_id) " + "WHERE Lower(r.coverage_name) = Lower(%Q) AND " + "Lower(s.style_name) = Lower(%Q)", namedLayer, + namedStyle); ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, NULL); sqlite3_free (sql); if (ret != SQLITE_OK) return 0; for (i = 1; i <= rows; i++) @@ -7003,10 +7552,11 @@ rl2PalettePtr palette = NULL; char *title = NULL; char *abstract = NULL; unsigned char *statistics = NULL; int statistics_sz; + int ok_geo = 0; int ok_bbox = 0; double geo_minx; double geo_miny; double geo_maxx; double geo_maxy; @@ -7401,33 +7951,32 @@ if (sqlite3_column_type (stmt, 18) == SQLITE_BLOB) { statistics_sz = sqlite3_column_bytes (stmt, 18); statistics = malloc (statistics_sz); memcpy (statistics, - (const unsigned char *) sqlite3_column_blob (stmt, - 18), - statistics_sz); + (const unsigned char *) + sqlite3_column_blob (stmt, 18), statistics_sz); } if (sqlite3_column_type (stmt, 19) == SQLITE_FLOAT) { geo_minx = sqlite3_column_double (stmt, 19); - ok_bbox++; + ok_geo++; } if (sqlite3_column_type (stmt, 20) == SQLITE_FLOAT) { geo_miny = sqlite3_column_double (stmt, 20); - ok_bbox++; + ok_geo++; } if (sqlite3_column_type (stmt, 21) == SQLITE_FLOAT) { geo_maxx = sqlite3_column_double (stmt, 21); - ok_bbox++; + ok_geo++; } if (sqlite3_column_type (stmt, 22) == SQLITE_FLOAT) { geo_maxy = sqlite3_column_double (stmt, 22); - ok_bbox++; + ok_geo++; } if (sqlite3_column_type (stmt, 23) == SQLITE_FLOAT) { ext_minx = sqlite3_column_double (stmt, 23); ok_bbox++; @@ -7483,15 +8032,18 @@ sqlite3_column_blob (stmt, 33); int blob_sz = sqlite3_column_bytes (stmt, 33); palette = rl2_deserialize_dbms_palette (blob, blob_sz); } if (ok_sample && ok_pixel && ok_num_bands && ok_compression - && ok_quality && ok_tile_width && ok_tile_height && ok_x_res - && ok_y_res && ok_srid && ok_nodata && ok_strict && ok_mixed - && ok_paths && ok_md5 && ok_summary) + && ok_quality && ok_tile_width && ok_tile_height + && ok_x_res && ok_y_res && ok_srid && ok_nodata + && ok_strict && ok_mixed && ok_paths && ok_md5 + && ok_summary) ok = 1; - if (ok_bbox != 8) + if (ok_geo != 4) + ok_geo = 0; + if (ok_bbox != 4) ok_bbox = 0; } } sqlite3_finalize (stmt); stmt = NULL; @@ -7506,14 +8058,14 @@ (unsigned short) tile_height, srid, horz_res, vert_res, no_data, palette, strict_resolution, mixed_resolutions, section_paths, section_md5, section_summary); - if (no_data != NULL) - rl2_destroy_pixel(no_data); - if (palette != NULL) - rl2_destroy_palette(palette); + if (no_data != NULL) + rl2_destroy_pixel (no_data); + if (palette != NULL) + rl2_destroy_palette (palette); if (ret != RL2_OK) goto error; /* completing the destination coverage */ sql = "UPDATE main.raster_coverages SET title = ?, " @@ -7540,27 +8092,33 @@ sqlite3_bind_text (stmt, 2, abstract, strlen (abstract), free); if (statistics == NULL) sqlite3_bind_null (stmt, 3); else sqlite3_bind_blob (stmt, 3, statistics, statistics_sz, free); - if (ok_bbox) + if (ok_geo) { sqlite3_bind_double (stmt, 4, geo_minx); sqlite3_bind_double (stmt, 5, geo_miny); sqlite3_bind_double (stmt, 6, geo_maxx); sqlite3_bind_double (stmt, 7, geo_maxy); - sqlite3_bind_double (stmt, 8, ext_minx); - sqlite3_bind_double (stmt, 9, ext_miny); - sqlite3_bind_double (stmt, 10, ext_maxx); - sqlite3_bind_double (stmt, 11, ext_maxy); } else { sqlite3_bind_null (stmt, 4); sqlite3_bind_null (stmt, 5); sqlite3_bind_null (stmt, 6); sqlite3_bind_null (stmt, 7); + } + if (ok_bbox) + { + sqlite3_bind_double (stmt, 8, ext_minx); + sqlite3_bind_double (stmt, 9, ext_miny); + sqlite3_bind_double (stmt, 10, ext_maxx); + sqlite3_bind_double (stmt, 11, ext_maxy); + } + else + { sqlite3_bind_null (stmt, 8); sqlite3_bind_null (stmt, 9); sqlite3_bind_null (stmt, 10); sqlite3_bind_null (stmt, 11); } @@ -7589,11 +8147,12 @@ else sqlite3_bind_int (stmt, 17, enable_auto_ndvi); sqlite3_bind_text (stmt, 18, coverage_name, strlen (coverage_name), SQLITE_STATIC); ret = sqlite3_step (stmt); - sqlite3_finalize(stmt); + sqlite3_finalize (stmt); + stmt = NULL; if (ret == SQLITE_DONE || ret == SQLITE_ROW) goto ok_continue; fprintf (stderr, "sqlite3_step() error: UPDATE raster_coverages \"%s\"\n", sqlite3_errmsg (sqlite)); @@ -7611,26 +8170,27 @@ "y_resolution_1_2, x_resolution_1_4, y_resolution_1_4, x_resolution_1_8, " "y_resolution_1_8 FROM \"%s\".\"%s\"", xxcoverage, xdb, xxcoverage); free (xxcoverage); ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL); - sqlite3_free(sql); + sqlite3_free (sql); if (ret != SQLITE_OK) goto error; /* copying coverage-SECTIONS */ xcoverage = sqlite3_mprintf ("%s_sections", coverage_name); xxcoverage = rl2_double_quoted_sql (xcoverage); sqlite3_free (xcoverage); - sql = sqlite3_mprintf ("INSERT INTO main.\"%s\" (section_id, section_name, " - "width, height, file_path, md5_checksum, summary, statistics, geometry) " - "SELECT section_id, section_name, width, height, file_path, md5_checksum, " - "summary, statistics, geometry FROM \"%s\".\"%s\"", - xxcoverage, xdb, xxcoverage); + sql = + sqlite3_mprintf ("INSERT INTO main.\"%s\" (section_id, section_name, " + "width, height, file_path, md5_checksum, summary, statistics, geometry) " + "SELECT section_id, section_name, width, height, file_path, md5_checksum, " + "summary, statistics, geometry FROM \"%s\".\"%s\"", + xxcoverage, xdb, xxcoverage); free (xxcoverage); ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL); - sqlite3_free(sql); + sqlite3_free (sql); if (ret != SQLITE_OK) goto error; /* copying coverage-TILES */ xcoverage = sqlite3_mprintf ("%s_tiles", coverage_name); @@ -7639,11 +8199,11 @@ sql = sqlite3_mprintf ("INSERT INTO main.\"%s\" (tile_id, pyramid_level, " "section_id, geometry) SELECT tile_id, pyramid_level, section_id, geometry " "FROM \"%s\".\"%s\"", xxcoverage, xdb, xxcoverage); free (xxcoverage); ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL); - sqlite3_free(sql); + sqlite3_free (sql); if (ret != SQLITE_OK) goto error; /* copying coverage-TILE_DATA */ xcoverage = sqlite3_mprintf ("%s_tile_data", coverage_name); @@ -7652,30 +8212,30 @@ sql = sqlite3_mprintf ("INSERT INTO main.\"%s\" (tile_id, tile_data_odd, " "tile_data_even) SELECT tile_id, tile_data_odd, tile_data_even " "FROM \"%s\".\"%s\"", xxcoverage, xdb, xxcoverage); free (xxcoverage); ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL); - sqlite3_free(sql); + sqlite3_free (sql); if (ret != SQLITE_OK) goto error; /* copying KEYWORDS */ sql = sqlite3_mprintf ("INSERT INTO main.raster_coverages_keyword " "(coverage_name, keyword) SELECT coverage_name, keyword " "FROM \"%s\".raster_coverages_keyword", xdb); ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL); - sqlite3_free(sql); + sqlite3_free (sql); if (ret != SQLITE_OK) goto error; /* copying SRID */ sql = sqlite3_mprintf ("INSERT INTO main.raster_coverages_srid " "(coverage_name, srid, extent_minx, extent_miny, extent_maxx, extent_maxx) " "SELECT coverage_name, srid, extent_minx, extent_miny, extent_maxx, extent_maxx " "FROM \"%s\".raster_coverages_srid", xdb); ret = sqlite3_exec (sqlite, sql, NULL, NULL, NULL); - sqlite3_free(sql); + sqlite3_free (sql); if (ret != SQLITE_OK) goto error; free (xdb); return RL2_OK; @@ -7685,5 +8245,115 @@ free (xdb); if (stmt != NULL) sqlite3_finalize (stmt); return RL2_ERROR; } + +RL2_PRIVATE int +do_check_initial_palette (sqlite3 * handle, rl2CoveragePtr cvg) +{ +/* testing for an empty Palette Coverage */ + rl2PrivCoveragePtr coverage = (rl2PrivCoveragePtr) cvg; + int ret; + char **results; + int rows; + int columns; + int i; + int initial = 0; + char *xcoverage; + char *xxcoverage; + + if (coverage == NULL) + return RL2_ERROR; + if (coverage->coverageName == NULL) + return RL2_ERROR; + + xcoverage = sqlite3_mprintf ("%s_tiles", coverage->coverageName); + xxcoverage = rl2_double_quoted_sql (xcoverage); + sqlite3_free (xcoverage); + char *sql = sqlite3_mprintf ("SELECT Count(*) FROM \"%s\"", + xxcoverage); + free (xxcoverage); + ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, NULL); + sqlite3_free (sql); + if (ret != SQLITE_OK) + return RL2_ERROR; + for (i = 1; i <= rows; i++) + { + if (atoi (results[(i * columns) + 0]) == 0) + initial = 1; + } + sqlite3_free_table (results); + if (initial) + return RL2_TRUE; + return RL2_FALSE; +} + +RL2_DECLARE int +rl2_install_dbms_palette_from_tiff (sqlite3 * handle, rl2CoveragePtr coverage, + rl2TiffOriginPtr tiff) +{ +/*attempting to merge/update a Coverage's Palette */ + int i; + int j; + int changed = 0; + int maxPalette = 0; + unsigned char red[256]; + unsigned char green[256]; + unsigned char blue[256]; + int ok; + rl2PalettePtr palette = NULL; + rl2PrivCoveragePtr cvg = (rl2PrivCoveragePtr) coverage; + rl2PrivTiffOriginPtr origin = (rl2PrivTiffOriginPtr) tiff; + if (cvg == NULL || origin == NULL) + return RL2_ERROR; + + for (i = 0; i < origin->maxPalette; i++) + { + /* checking TIFF palette entries */ + unsigned char tiff_red = origin->red[i]; + unsigned char tiff_green = origin->green[i]; + unsigned char tiff_blue = origin->blue[i]; + ok = 0; + for (j = 0; j < maxPalette; j++) + { + if (tiff_red == red[j] && tiff_green == green[j] + && tiff_blue == blue[j]) + { + /* found a matching color */ + ok = 1; + break; + } + } + if (!ok) + { + /* attempting to insert a new color into the pseudo-Palette */ + if (maxPalette == 256) + goto error; + red[maxPalette] = tiff_red; + green[maxPalette] = tiff_green; + blue[maxPalette] = tiff_blue; + maxPalette++; + changed = 1; + } + } + if (changed) + { + /* updating the DBMS Palette */ + palette = rl2_create_palette (maxPalette); + if (palette == NULL) + goto error; + for (j = 0; j < maxPalette; j++) + rl2_set_palette_color (palette, j, red[j], green[j], blue[j]); + if (rl2_update_dbms_palette (handle, cvg->coverageName, palette) != + RL2_OK) + goto error; + } + set_remapped_palette (origin, palette); + rl2_destroy_palette (palette); + return RL2_OK; + + error: + if (palette != NULL) + rl2_destroy_palette (palette); + return RL2_ERROR; +} Index: src/rl2gif.c ================================================================== --- src/rl2gif.c +++ src/rl2gif.c @@ -604,12 +604,12 @@ } RL2_PRIVATE int rl2_decode_gif (const unsigned char *gif, int gif_size, unsigned int *xwidth, unsigned int *xheight, unsigned char *xsample_type, - unsigned char *xpixel_type, unsigned char **blob, int *blob_sz, - rl2PalettePtr * palette) + unsigned char *xpixel_type, unsigned char **blob, + int *blob_sz, rl2PalettePtr * palette) { /* attempting to create a raster from a GIF image - raw block */ struct gif_memory_buffer membuf; #ifdef GIFLIB_MAJOR int ErrorCode; Index: src/rl2import.c ================================================================== --- src/rl2import.c +++ src/rl2import.c @@ -102,12 +102,12 @@ rl2_destroy_raster (tile->raster); tile->raster = NULL; } static void -addTile2AuxImporter (rl2AuxImporterPtr aux, unsigned int row, unsigned int col, - double minx, double maxy) +addTile2AuxImporter (rl2AuxImporterPtr aux, unsigned int row, + unsigned int col, double minx, double maxy) { /* adding a Tile to some AuxImporter container */ rl2AuxImporterTilePtr tile; if (aux == NULL) return; @@ -348,36 +348,40 @@ case RL2_ORIGIN_ASCII_GRID: ascii_grid_origin = (rl2AsciiGridOriginPtr) (aux->origin); tile->raster = rl2_get_tile_from_ascii_grid_origin ((rl2CoveragePtr) (aux->coverage), - ascii_grid_origin, tile->row, - tile->col, aux->verbose); + ascii_grid_origin, + tile->row, tile->col, + aux->verbose); break; case RL2_ORIGIN_JPEG: raster_origin = (rl2RasterPtr) (aux->origin); tile->raster = rl2_get_tile_from_jpeg_origin ((rl2CoveragePtr) (aux->coverage), raster_origin, tile->row, - tile->col, aux->forced_conversion, + tile->col, + aux->forced_conversion, aux->verbose); break; case RL2_ORIGIN_JPEG2000: raster_origin = (rl2RasterPtr) (aux->origin); tile->raster = rl2_get_tile_from_jpeg2000_origin ((rl2CoveragePtr) - (aux->coverage), raster_origin, - tile->row, tile->col, + (aux->coverage), + raster_origin, tile->row, + tile->col, aux->forced_conversion, aux->verbose); break; case RL2_ORIGIN_TIFF: tiff_origin = (rl2TiffOriginPtr) (aux->origin); tile->raster = rl2_get_tile_from_tiff_origin ((rl2CoveragePtr) (aux->coverage), - tiff_origin, tile->row, tile->col, - aux->srid, aux->verbose); + tiff_origin, tile->row, + tile->col, aux->srid, + aux->verbose); break; case RL2_ORIGIN_RAW: raster_origin = (rl2RasterPtr) (aux->origin); tile->raster = rl2_get_tile_from_raw_pixels ((rl2CoveragePtr) (aux->coverage), @@ -590,19 +594,23 @@ { /* accepting any resolution */ } else if (coverage->strictResolution) { - /* enforcing Strict Resolution check */ - if (res_x != coverage->hResolution) + /* enforcing Strict Resolution check */ double x_diff = + fabs (coverage->hResolution - res_x); + double y_diff = fabs (coverage->vResolution - res_y); + double x_lim = coverage->hResolution / 1000000.0; + double y_lim = coverage->vResolution / 1000000.0; + if (x_diff > x_lim) { if (verbose) fprintf (stderr, "Mismatching Horizontal Resolution (Strict) !!!\n"); goto error; } - if (res_y != coverage->vResolution) + if (y_diff > y_lim) { if (verbose) fprintf (stderr, "Mismatching Vertical Resolution (Strict) !!!\n"); goto error; @@ -639,12 +647,12 @@ } no_data = rl2_get_coverage_no_data (cvg); /* INSERTing the section */ if (!rl2_do_insert_section - (handle, src_path, section, srid, width, height, minx, miny, maxx, maxy, - xml_summary, coverage->sectionPaths, coverage->sectionMD5, + (handle, src_path, section, srid, width, height, minx, miny, maxx, + maxy, xml_summary, coverage->sectionPaths, coverage->sectionMD5, coverage->sectionSummary, stmt_sect, §ion_id)) goto error; section_stats = rl2_create_raster_statistics (sample_type, 1); if (section_stats == NULL) goto error; @@ -665,12 +673,12 @@ } /* preparing all Tile Requests */ aux = createAuxImporter (coverage, srid, maxx, miny, tile_w, tile_h, res_x, - res_y, RL2_ORIGIN_ASCII_GRID, origin, RL2_CONVERT_NO, - verbose, compression, 100); + res_y, RL2_ORIGIN_ASCII_GRID, origin, + RL2_CONVERT_NO, verbose, compression, 100); tile_maxy = maxy; for (row = 0; row < height; row += tile_h) { tile_minx = minx; for (col = 0; col < width; col += tile_w) @@ -910,11 +918,12 @@ #ifndef OMIT_OPENJPEG /* only if OpenJpeg is enabled */ static int check_jpeg2000_origin_compatibility (rl2RasterPtr raster, rl2CoveragePtr coverage, - unsigned int *width, unsigned int *height, + unsigned int *width, + unsigned int *height, unsigned char *forced_conversion) { /* checking if the Jpeg2000 and the Coverage are mutually compatible */ rl2PrivRasterPtr rst = (rl2PrivRasterPtr) raster; rl2PrivCoveragePtr cvg = (rl2PrivCoveragePtr) coverage; @@ -996,12 +1005,12 @@ *height = rst->height; *forced_conversion = RL2_CONVERT_NO; return 1; } } - if (rst->sampleType == RL2_SAMPLE_UINT16 && rst->pixelType == RL2_PIXEL_RGB - && rst->nBands == 3) + if (rst->sampleType == RL2_SAMPLE_UINT16 + && rst->pixelType == RL2_PIXEL_RGB && rst->nBands == 3) { if (cvg->sampleType == RL2_SAMPLE_UINT16 && cvg->pixelType == RL2_PIXEL_RGB && cvg->nBands == 3) { *width = rst->width; @@ -1231,12 +1240,12 @@ res_y = 1.0; } raster_in = (rl2PrivRasterPtr) rst_in; xml_summary = rl2_build_jpeg_xml_summary (width, height, raster_in->pixelType, - is_georeferenced, res_x, res_y, minx, miny, - maxx, maxy); + is_georeferenced, res_x, res_y, minx, + miny, maxx, maxy); printf ("------------------\n"); if (total > 1) printf ("%d/%d) Importing: %s\n", current, total, src_path); else @@ -1268,19 +1277,23 @@ { /* accepting any resolution */ } else if (coverage->strictResolution) { - /* enforcing Strict Resolution check */ - if (res_x != coverage->hResolution) + /* enforcing Strict Resolution check */ double x_diff = + fabs (coverage->hResolution - res_x); + double y_diff = fabs (coverage->vResolution - res_y); + double x_lim = coverage->hResolution / 1000000.0; + double y_lim = coverage->vResolution / 1000000.0; + if (x_diff > x_lim) { if (verbose) fprintf (stderr, "Mismatching Horizontal Resolution (Strict) !!!\n"); goto error; } - if (res_y != coverage->vResolution) + if (y_diff > y_lim) { if (verbose) fprintf (stderr, "Mismatching Vertical Resolution (Strict) !!!\n"); goto error; @@ -1311,12 +1324,12 @@ no_data = rl2_get_coverage_no_data (cvg); /* INSERTing the section */ if (!rl2_do_insert_section - (handle, src_path, section, srid, width, height, minx, miny, maxx, maxy, - xml_summary, coverage->sectionPaths, coverage->sectionMD5, + (handle, src_path, section, srid, width, height, minx, miny, maxx, + maxy, xml_summary, coverage->sectionPaths, coverage->sectionMD5, coverage->sectionSummary, stmt_sect, §ion_id)) goto error; section_stats = rl2_create_raster_statistics (sample_type, num_bands); if (section_stats == NULL) goto error; @@ -1679,14 +1692,14 @@ res_y = 1.0; } raster_in = (rl2PrivRasterPtr) rst_in; xml_summary = rl2_build_jpeg2000_xml_summary (width, height, raster_in->sampleType, - raster_in->pixelType, raster_in->nBands, - is_georeferenced, res_x, res_y, minx, - miny, maxx, maxy, tile_width, - tile_height); + raster_in->pixelType, + raster_in->nBands, is_georeferenced, + res_x, res_y, minx, miny, maxx, maxy, + tile_width, tile_height); printf ("------------------\n"); if (total > 1) printf ("%d/%d) Importing: %s\n", current, total, src_path); else @@ -1719,18 +1732,22 @@ /* accepting any resolution */ } else if (coverage->strictResolution) { /* enforcing Strict Resolution check */ - if (res_x != coverage->hResolution) + double x_diff = fabs (coverage->hResolution - res_x); + double y_diff = fabs (coverage->vResolution - res_y); + double x_lim = coverage->hResolution / 1000000.0; + double y_lim = coverage->vResolution / 1000000.0; + if (x_diff > x_lim) { if (verbose) fprintf (stderr, "Mismatching Horizontal Resolution (Strict) !!!\n"); goto error; } - if (res_y != coverage->vResolution) + if (y_diff > y_lim) { if (verbose) fprintf (stderr, "Mismatching Vertical Resolution (Strict) !!!\n"); goto error; @@ -1761,12 +1778,12 @@ no_data = rl2_get_coverage_no_data (cvg); /* INSERTing the section */ if (!rl2_do_insert_section - (handle, src_path, section, srid, width, height, minx, miny, maxx, maxy, - xml_summary, coverage->sectionPaths, coverage->sectionMD5, + (handle, src_path, section, srid, width, height, minx, miny, maxx, + maxy, xml_summary, coverage->sectionPaths, coverage->sectionMD5, coverage->sectionSummary, stmt_sect, §ion_id)) goto error; section_stats = rl2_create_raster_statistics (sample_type, num_bands); if (section_stats == NULL) goto error; @@ -2072,20 +2089,21 @@ if (is_ascii_grid (src_path)) return do_import_ascii_grid (handle, max_threads, src_path, cvg, section, force_srid, tile_w, tile_h, pyramidize, sample_type, compression, - stmt_data, stmt_tils, stmt_sect, stmt_levl, - stmt_upd_sect, verbose, current, total); + stmt_data, stmt_tils, stmt_sect, + stmt_levl, stmt_upd_sect, verbose, + current, total); if (is_jpeg_image (src_path)) return do_import_jpeg_image (handle, max_threads, src_path, cvg, section, force_srid, tile_w, tile_h, pyramidize, sample_type, num_bands, - compression, quality, stmt_data, stmt_tils, - stmt_sect, stmt_levl, stmt_upd_sect, - verbose, current, total); + compression, quality, stmt_data, + stmt_tils, stmt_sect, stmt_levl, + stmt_upd_sect, verbose, current, total); #ifndef OMIT_OPENJPEG /* only if OpenJpeg is enabled */ if (is_jpeg2000_image (src_path)) return do_import_jpeg2000_image (handle, max_threads, src_path, cvg, section, force_srid, tile_w, tile_h, @@ -2173,18 +2191,22 @@ /* accepting any resolution */ } else if (coverage->strictResolution) { /* enforcing Strict Resolution check */ - if (res_x != coverage->hResolution) + double x_diff = fabs (coverage->hResolution - res_x); + double y_diff = fabs (coverage->vResolution - res_y); + double x_lim = coverage->hResolution / 1000000.0; + double y_lim = coverage->vResolution / 1000000.0; + if (x_diff > x_lim) { if (verbose) fprintf (stderr, "Mismatching Horizontal Resolution (Strict) !!!\n"); goto error; } - if (res_y != coverage->vResolution) + if (y_diff > y_lim) { if (verbose) fprintf (stderr, "Mismatching Vertical Resolution (Strict) !!!\n"); goto error; @@ -2214,29 +2236,39 @@ } if (pixel_type == RL2_PIXEL_PALETTE) { /* remapping the Palette */ + if (do_check_initial_palette (handle, cvg) == RL2_TRUE) + { + if (rl2_install_dbms_palette_from_tiff (handle, cvg, origin) != + RL2_OK) + { + fprintf (stderr, + "Unable to install the initial Palette !!!\n"); + goto error; + } + } if (rl2_check_dbms_palette (handle, cvg, origin) != RL2_OK) { fprintf (stderr, "Mismatching Palette !!!\n"); goto error; } } - if (rl2_eval_tiff_origin_compatibility (cvg, origin, force_srid, verbose) != - RL2_TRUE) + if (rl2_eval_tiff_origin_compatibility (cvg, origin, force_srid, verbose) + != RL2_TRUE) { fprintf (stderr, "Coverage/TIFF mismatch\n"); goto error; } no_data = rl2_get_coverage_no_data (cvg); /* INSERTing the section */ if (!rl2_do_insert_section - (handle, src_path, section, srid, width, height, minx, miny, maxx, maxy, - xml_summary, coverage->sectionPaths, coverage->sectionMD5, + (handle, src_path, section, srid, width, height, minx, miny, maxx, + maxy, xml_summary, coverage->sectionPaths, coverage->sectionMD5, coverage->sectionSummary, stmt_sect, §ion_id)) goto error; section_stats = rl2_create_raster_statistics (sample_type, num_bands); if (section_stats == NULL) goto error; @@ -2536,18 +2568,20 @@ { path = sqlite3_mprintf ("%s/%s", dir_path, c_file.name); ret = - do_import_file (handle, max_threads, path, cvg, - section, worldfile, force_srid, - pyramidize, sample_type, - pixel_type, num_bands, tile_w, - tile_h, compression, quality, - stmt_data, stmt_tils, stmt_sect, - stmt_levl, stmt_upd_sect, - verbose, cnt + 1, total); + do_import_file (handle, max_threads, path, + cvg, section, worldfile, + force_srid, pyramidize, + sample_type, pixel_type, + num_bands, tile_w, tile_h, + compression, quality, + stmt_data, stmt_tils, + stmt_sect, stmt_levl, + stmt_upd_sect, verbose, + cnt + 1, total); sqlite3_free (path); if (!ret) goto error; cnt++; } @@ -2774,14 +2808,14 @@ } else { /* importing all Image files from a whole directory */ if (!do_import_dir - (handle, max_threads, dir_path, file_ext, cvg, section, worldfile, - force_srid, pyramidize, sample_type, pixel_type, num_bands, - tile_w, tile_h, compression, quality, stmt_data, stmt_tils, - stmt_sect, stmt_levl, stmt_upd_sect, verbose)) + (handle, max_threads, dir_path, file_ext, cvg, section, + worldfile, force_srid, pyramidize, sample_type, pixel_type, + num_bands, tile_w, tile_h, compression, quality, stmt_data, + stmt_tils, stmt_sect, stmt_levl, stmt_upd_sect, verbose)) goto error; } sqlite3_finalize (stmt_upd_sect); sqlite3_finalize (stmt_sect); @@ -2896,15 +2930,14 @@ } } static void copy_uint8_outbuf_to_tile (const unsigned char *outbuf, unsigned char *tile, - unsigned char num_bands, unsigned int width, - unsigned int height, - unsigned int tile_width, - unsigned int tile_height, unsigned int base_y, - unsigned int base_x) + unsigned char pixel_type, unsigned char num_bands, + unsigned int width, unsigned int height, + unsigned int tile_width, unsigned int tile_height, + unsigned int base_y, unsigned int base_x) { /* copying UINT8 pixels from the output buffer into the tile */ unsigned int x; unsigned int y; int b; @@ -2924,12 +2957,31 @@ { p_out += num_bands; p_in += num_bands; continue; } - for (b = 0; b < num_bands; b++) - *p_out++ = *p_in++; + if (pixel_type == RL2_PIXEL_MONOCHROME) + { + unsigned char pxl = *p_in++; + if (pxl == 0) + *p_out++ = 1; + else + *p_out++ = 0; + } + else if (pixel_type == RL2_PIXEL_PALETTE) + { + unsigned char pxl = *p_in++; + if (pxl == 0) + *p_out++ = 1; + else + *p_out++ = 0; + } + else + { + for (b = 0; b < num_bands; b++) + *p_out++ = *p_in++; + } } } } static void @@ -2963,16 +3015,15 @@ } } } static void -copy_uint16_outbuf_to_tile (const unsigned short *outbuf, unsigned short *tile, - unsigned char num_bands, unsigned int width, - unsigned int height, - unsigned int tile_width, - unsigned int tile_height, unsigned int base_y, - unsigned int base_x) +copy_uint16_outbuf_to_tile (const unsigned short *outbuf, + unsigned short *tile, unsigned char num_bands, + unsigned int width, unsigned int height, + unsigned int tile_width, unsigned int tile_height, + unsigned int base_y, unsigned int base_x) { /* copying UINT16 pixels from the output buffer into the tile */ unsigned int x; unsigned int y; int b; @@ -3127,14 +3178,15 @@ } } static void copy_from_outbuf_to_tile (const unsigned char *outbuf, unsigned char *tile, - unsigned char sample_type, unsigned char num_bands, - unsigned int width, unsigned int height, - unsigned int tile_width, unsigned int tile_height, - unsigned int base_y, unsigned int base_x) + unsigned char sample_type, unsigned char pixel_type, + unsigned char num_bands, unsigned int width, + unsigned int height, unsigned int tile_width, + unsigned int tile_height, unsigned int base_y, + unsigned int base_x) { /* copying pixels from the output buffer into the tile */ switch (sample_type) { case RL2_SAMPLE_INT8: @@ -3142,12 +3194,12 @@ (char *) tile, width, height, tile_width, tile_height, base_y, base_x); break; case RL2_SAMPLE_INT16: copy_int16_outbuf_to_tile ((short *) outbuf, - (short *) tile, width, height, tile_width, - tile_height, base_y, base_x); + (short *) tile, width, height, + tile_width, tile_height, base_y, base_x); break; case RL2_SAMPLE_UINT16: copy_uint16_outbuf_to_tile ((unsigned short *) outbuf, (unsigned short *) tile, num_bands, width, height, tile_width, tile_height, @@ -3163,33 +3215,33 @@ (unsigned int *) tile, width, height, tile_width, tile_height, base_y, base_x); break; case RL2_SAMPLE_FLOAT: copy_float_outbuf_to_tile ((float *) outbuf, - (float *) tile, width, height, tile_width, - tile_height, base_y, base_x); + (float *) tile, width, height, + tile_width, tile_height, base_y, base_x); break; case RL2_SAMPLE_DOUBLE: copy_double_outbuf_to_tile ((double *) outbuf, (double *) tile, width, height, tile_width, tile_height, base_y, base_x); break; default: copy_uint8_outbuf_to_tile ((unsigned char *) outbuf, - (unsigned char *) tile, num_bands, width, - height, tile_width, tile_height, base_y, - base_x); + (unsigned char *) tile, pixel_type, + num_bands, width, height, tile_width, + tile_height, base_y, base_x); break; }; } static int -export_geotiff_common (sqlite3 * handle, int max_threads, const char *dst_path, - rl2CoveragePtr cvg, int by_section, - sqlite3_int64 section_id, double x_res, double y_res, - double minx, double miny, double maxx, double maxy, - unsigned int width, unsigned int height, +export_geotiff_common (sqlite3 * handle, int max_threads, + const char *dst_path, rl2CoveragePtr cvg, + int by_section, sqlite3_int64 section_id, double x_res, + double y_res, double minx, double miny, double maxx, + double maxy, unsigned int width, unsigned int height, unsigned char compression, unsigned int tile_sz, int with_worldfile) { /* exporting a GeoTIFF common implementation */ rl2RasterPtr raster = NULL; @@ -3256,21 +3308,21 @@ if (by_section) { /* just a single Section */ if (rl2_get_section_raw_raster_data - (handle, max_threads, cvg, section_id, width, height, minx, miny, - maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, &palette, - pixel_type) != RL2_OK) + (handle, max_threads, cvg, section_id, width, height, minx, + miny, maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, + &palette, pixel_type) != RL2_OK) goto error; } else { /* whole Coverage */ if (rl2_get_raw_raster_data - (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy, - xx_res, yy_res, &outbuf, &outbuf_size, &palette, + (handle, max_threads, cvg, width, height, minx, miny, maxx, + maxy, xx_res, yy_res, &outbuf, &outbuf_size, &palette, pixel_type) != RL2_OK) goto error; } /* computing the sample size */ @@ -3313,15 +3365,15 @@ } if (pixel_type == RL2_PIXEL_PALETTE && palette != NULL) rl2_prime_void_tile_palette (bufpix, tile_sz, tile_sz, no_data); else - rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type, - num_bands, no_data); + rl2_prime_void_tile (bufpix, tile_sz, tile_sz, + sample_type, num_bands, no_data); copy_from_outbuf_to_tile (outbuf, bufpix, sample_type, - num_bands, width, height, tile_sz, - tile_sz, base_y, base_x); + pixel_type, num_bands, width, height, + tile_sz, tile_sz, base_y, base_x); plt2 = rl2_clone_palette (palette); raster = rl2_create_raster (tile_sz, tile_sz, sample_type, pixel_type, num_bands, bufpix, bufpix_size, plt2, NULL, 0, NULL); @@ -3378,11 +3430,12 @@ height, compression, tile_sz, with_worldfile); } RL2_DECLARE int rl2_export_section_geotiff_from_dbms (sqlite3 * handle, int max_threads, - const char *dst_path, rl2CoveragePtr cvg, + const char *dst_path, + rl2CoveragePtr cvg, sqlite3_int64 section_id, double x_res, double y_res, double minx, double miny, double maxx, double maxy, unsigned int width, unsigned int height, unsigned char compression, @@ -3469,21 +3522,21 @@ if (by_section) { /* just a single select Section */ if (rl2_get_section_raw_raster_data - (handle, max_threads, cvg, section_id, width, height, minx, miny, - maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, &palette, - pixel_type) != RL2_OK) + (handle, max_threads, cvg, section_id, width, height, minx, + miny, maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, + &palette, pixel_type) != RL2_OK) goto error; } else { /* whole Coverage */ if (rl2_get_raw_raster_data - (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy, - xx_res, yy_res, &outbuf, &outbuf_size, &palette, + (handle, max_threads, cvg, width, height, minx, miny, maxx, + maxy, xx_res, yy_res, &outbuf, &outbuf_size, &palette, pixel_type) != RL2_OK) goto error; } /* computing the sample size */ @@ -3504,13 +3557,14 @@ }; tiff = rl2_create_tiff_worldfile_destination (dst_path, width, height, sample_type, pixel_type, - num_bands, palette, compression, - 1, tile_sz, srid, minx, miny, - maxx, maxy, xx_res, yy_res); + num_bands, palette, + compression, 1, tile_sz, srid, + minx, miny, maxx, maxy, xx_res, + yy_res); if (tiff == NULL) goto error; for (base_y = 0; base_y < height; base_y += tile_sz) { for (base_x = 0; base_x < width; base_x += tile_sz) @@ -3526,15 +3580,15 @@ } if (pixel_type == RL2_PIXEL_PALETTE && palette != NULL) rl2_prime_void_tile_palette (bufpix, tile_sz, tile_sz, no_data); else - rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type, - num_bands, no_data); + rl2_prime_void_tile (bufpix, tile_sz, tile_sz, + sample_type, num_bands, no_data); copy_from_outbuf_to_tile (outbuf, bufpix, sample_type, - num_bands, width, height, tile_sz, - tile_sz, base_y, base_x); + pixel_type, num_bands, width, height, + tile_sz, tile_sz, base_y, base_x); plt2 = rl2_clone_palette (palette); raster = rl2_create_raster (tile_sz, tile_sz, sample_type, pixel_type, num_bands, bufpix, bufpix_size, plt2, NULL, 0, NULL); @@ -3582,16 +3636,18 @@ unsigned char compression, unsigned int tile_sz) { /* exporting a TIFF+TFW from the DBMS into the file-system */ return export_tiff_worlfile_common (handle, max_threads, dst_path, cvg, 0, - 0, x_res, y_res, minx, miny, maxx, maxy, - width, height, compression, tile_sz); + 0, x_res, y_res, minx, miny, maxx, + maxy, width, height, compression, + tile_sz); } RL2_DECLARE int -rl2_export_section_tiff_worldfile_from_dbms (sqlite3 * handle, int max_threads, +rl2_export_section_tiff_worldfile_from_dbms (sqlite3 * handle, + int max_threads, const char *dst_path, rl2CoveragePtr cvg, sqlite3_int64 section_id, double x_res, double y_res, double minx, double miny, @@ -3602,12 +3658,12 @@ unsigned int tile_sz) { /* exporting a TIFF+TFW - single Section */ return export_tiff_worlfile_common (handle, max_threads, dst_path, cvg, 1, section_id, x_res, y_res, minx, miny, - maxx, maxy, width, height, compression, - tile_sz); + maxx, maxy, width, height, + compression, tile_sz); } static int export_tiff_common (sqlite3 * handle, int max_threads, const char *dst_path, rl2CoveragePtr cvg, int by_section, @@ -3683,21 +3739,21 @@ if (by_section) { /* just a single Section */ if (rl2_get_section_raw_raster_data - (handle, max_threads, cvg, section_id, width, height, minx, miny, - maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, &palette, - pixel_type) != RL2_OK) + (handle, max_threads, cvg, section_id, width, height, minx, + miny, maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, + &palette, pixel_type) != RL2_OK) goto error; } else { /* whole Coverage */ if (rl2_get_raw_raster_data - (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy, - xx_res, yy_res, &outbuf, &outbuf_size, &palette, + (handle, max_threads, cvg, width, height, minx, miny, maxx, + maxy, xx_res, yy_res, &outbuf, &outbuf_size, &palette, pixel_type) != RL2_OK) goto error; } /* computing the sample size */ @@ -3738,15 +3794,15 @@ } if (pixel_type == RL2_PIXEL_PALETTE && palette != NULL) rl2_prime_void_tile_palette (bufpix, tile_sz, tile_sz, no_data); else - rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type, - num_bands, no_data); + rl2_prime_void_tile (bufpix, tile_sz, tile_sz, + sample_type, num_bands, no_data); copy_from_outbuf_to_tile (outbuf, bufpix, sample_type, - num_bands, width, height, tile_sz, - tile_sz, base_y, base_x); + pixel_type, num_bands, width, height, + tile_sz, tile_sz, base_y, base_x); plt2 = rl2_clone_palette (palette); raster = rl2_create_raster (tile_sz, tile_sz, sample_type, pixel_type, num_bands, bufpix, bufpix_size, plt2, NULL, 0, NULL); @@ -3782,43 +3838,44 @@ } RL2_DECLARE int rl2_export_tiff_from_dbms (sqlite3 * handle, int max_threads, const char *dst_path, rl2CoveragePtr cvg, - double x_res, double y_res, double minx, double miny, - double maxx, double maxy, unsigned int width, - unsigned int height, unsigned char compression, - unsigned int tile_sz) + double x_res, double y_res, double minx, + double miny, double maxx, double maxy, + unsigned int width, unsigned int height, + unsigned char compression, unsigned int tile_sz) { /* exporting a plain TIFF from the DBMS into the file-system */ - return export_tiff_common (handle, max_threads, dst_path, cvg, 0, 0, x_res, - y_res, minx, miny, maxx, maxy, width, height, - compression, tile_sz); + return export_tiff_common (handle, max_threads, dst_path, cvg, 0, 0, + x_res, y_res, minx, miny, maxx, maxy, width, + height, compression, tile_sz); } RL2_DECLARE int rl2_export_section_tiff_from_dbms (sqlite3 * handle, int max_threads, const char *dst_path, rl2CoveragePtr cvg, sqlite3_int64 section_id, double x_res, double y_res, double minx, double miny, - double maxx, double maxy, unsigned int width, - unsigned int height, + double maxx, double maxy, + unsigned int width, unsigned int height, unsigned char compression, unsigned int tile_sz) { /* exporting a plain TIFF - single Section*/ return export_tiff_common (handle, max_threads, dst_path, cvg, 1, - section_id, x_res, y_res, minx, miny, maxx, maxy, - width, height, compression, tile_sz); + section_id, x_res, y_res, minx, miny, maxx, + maxy, width, height, compression, tile_sz); } static int export_triple_band_geotiff_common (int by_section, sqlite3 * handle, const char *dst_path, - rl2CoveragePtr cvg, sqlite3_int64 section_id, - double x_res, double y_res, double minx, - double miny, double maxx, double maxy, + rl2CoveragePtr cvg, + sqlite3_int64 section_id, double x_res, + double y_res, double minx, double miny, + double maxx, double maxy, unsigned int width, unsigned int height, unsigned char red_band, unsigned char green_band, unsigned char blue_band, unsigned char compression, @@ -3894,12 +3951,12 @@ tiff = rl2_create_geotiff_destination (dst_path, handle, width, height, sample_type, RL2_PIXEL_RGB, 3, NULL, compression, 1, tile_sz, srid, - minx, miny, maxx, maxy, xx_res, yy_res, - with_worldfile); + minx, miny, maxx, maxy, xx_res, + yy_res, with_worldfile); if (tiff == NULL) goto error; for (base_y = 0; base_y < height; base_y += tile_sz) { for (base_x = 0; base_x < width; base_x += tile_sz) @@ -3916,16 +3973,16 @@ goto error; } rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type, 3, no_data); copy_from_outbuf_to_tile (outbuf, bufpix, sample_type, - 3, width, height, tile_sz, + pixel_type, 3, width, height, tile_sz, tile_sz, base_y, base_x); raster = rl2_create_raster (tile_sz, tile_sz, sample_type, - RL2_PIXEL_RGB, 3, bufpix, - bufpix_size, NULL, NULL, 0, NULL); + RL2_PIXEL_RGB, 3, bufpix, bufpix_size, + NULL, NULL, 0, NULL); bufpix = NULL; if (raster == NULL) goto error; if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) != RL2_OK) @@ -4092,12 +4149,12 @@ tiff = rl2_create_geotiff_destination (dst_path, handle, width, height, sample_type, out_pixel, 1, NULL, compression, 1, tile_sz, srid, - minx, miny, maxx, maxy, xx_res, yy_res, - with_worldfile); + minx, miny, maxx, maxy, xx_res, + yy_res, with_worldfile); if (tiff == NULL) goto error; for (base_y = 0; base_y < height; base_y += tile_sz) { for (base_x = 0; base_x < width; base_x += tile_sz) @@ -4114,16 +4171,16 @@ goto error; } rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type, 1, no_data); copy_from_outbuf_to_tile (outbuf, bufpix, sample_type, - 1, width, height, tile_sz, + pixel_type, 1, width, height, tile_sz, tile_sz, base_y, base_x); raster = - rl2_create_raster (tile_sz, tile_sz, sample_type, - out_pixel, 1, bufpix, - bufpix_size, NULL, NULL, 0, NULL); + rl2_create_raster (tile_sz, tile_sz, sample_type, out_pixel, + 1, bufpix, bufpix_size, NULL, NULL, 0, + NULL); bufpix = NULL; if (raster == NULL) goto error; if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) != RL2_OK) @@ -4172,13 +4229,13 @@ unsigned char compression, unsigned int tile_sz, int with_worldfile) { /* exporting a Mono-Band GeoTIFF from the DBMS into the file-system */ - return export_mono_band_geotiff_common (0, handle, dst_path, cvg, 0, x_res, - y_res, minx, miny, maxx, maxy, - width, height, mono_band, + return export_mono_band_geotiff_common (0, handle, dst_path, cvg, 0, + x_res, y_res, minx, miny, maxx, + maxy, width, height, mono_band, compression, tile_sz, with_worldfile); } RL2_DECLARE int @@ -4208,12 +4265,13 @@ export_triple_band_tiff_worldfile_common (int by_section, sqlite3 * handle, const char *dst_path, rl2CoveragePtr cvg, sqlite3_int64 section_id, double x_res, double y_res, - double minx, double miny, double maxx, - double maxy, unsigned int width, + double minx, double miny, + double maxx, double maxy, + unsigned int width, unsigned int height, unsigned char red_band, unsigned char green_band, unsigned char blue_band, unsigned char compression, @@ -4288,13 +4346,13 @@ } tiff = rl2_create_tiff_worldfile_destination (dst_path, width, height, sample_type, RL2_PIXEL_RGB, - 3, NULL, compression, 1, tile_sz, - srid, minx, miny, maxx, maxy, - xx_res, yy_res); + 3, NULL, compression, 1, + tile_sz, srid, minx, miny, + maxx, maxy, xx_res, yy_res); if (tiff == NULL) goto error; for (base_y = 0; base_y < height; base_y += tile_sz) { for (base_x = 0; base_x < width; base_x += tile_sz) @@ -4311,16 +4369,16 @@ goto error; } rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type, 3, no_data); copy_from_outbuf_to_tile (outbuf, bufpix, sample_type, - 3, width, height, tile_sz, + pixel_type, 3, width, height, tile_sz, tile_sz, base_y, base_x); raster = rl2_create_raster (tile_sz, tile_sz, sample_type, - RL2_PIXEL_RGB, 3, bufpix, - bufpix_size, NULL, NULL, 0, NULL); + RL2_PIXEL_RGB, 3, bufpix, bufpix_size, + NULL, NULL, 0, NULL); bufpix = NULL; if (raster == NULL) goto error; if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) != RL2_OK) @@ -4390,11 +4448,12 @@ double miny, double maxx, double maxy, unsigned int width, unsigned int height, - unsigned char red_band, + unsigned char + red_band, unsigned char green_band, unsigned char blue_band, unsigned char @@ -4412,14 +4471,15 @@ static int export_mono_band_tiff_worldfile_common (int by_section, sqlite3 * handle, const char *dst_path, rl2CoveragePtr cvg, - sqlite3_int64 section_id, double x_res, - double y_res, double minx, double miny, - double maxx, double maxy, - unsigned int width, unsigned int height, + sqlite3_int64 section_id, + double x_res, double y_res, + double minx, double miny, double maxx, + double maxy, unsigned int width, + unsigned int height, unsigned char mono_band, unsigned char compression, unsigned int tile_sz) { /* exporting a Mono-Band TIFF+TFW - common implementation */ @@ -4490,13 +4550,13 @@ out_pixel = RL2_PIXEL_GRAYSCALE; tiff = rl2_create_tiff_worldfile_destination (dst_path, width, height, sample_type, out_pixel, - 1, NULL, compression, 1, tile_sz, - srid, minx, miny, maxx, maxy, - xx_res, yy_res); + 1, NULL, compression, 1, + tile_sz, srid, minx, miny, + maxx, maxy, xx_res, yy_res); if (tiff == NULL) goto error; for (base_y = 0; base_y < height; base_y += tile_sz) { for (base_x = 0; base_x < width; base_x += tile_sz) @@ -4513,16 +4573,16 @@ goto error; } rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type, 1, no_data); copy_from_outbuf_to_tile (outbuf, bufpix, sample_type, - 1, width, height, tile_sz, + pixel_type, 1, width, height, tile_sz, tile_sz, base_y, base_x); raster = - rl2_create_raster (tile_sz, tile_sz, sample_type, - out_pixel, 1, bufpix, - bufpix_size, NULL, NULL, 0, NULL); + rl2_create_raster (tile_sz, tile_sz, sample_type, out_pixel, + 1, bufpix, bufpix_size, NULL, NULL, 0, + NULL); bufpix = NULL; if (raster == NULL) goto error; if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) != RL2_OK) @@ -4568,29 +4628,33 @@ unsigned char mono_band, unsigned char compression, unsigned int tile_sz) { /* exporting a Mono-Band TIFF+TFW from the DBMS into the file-system */ - return export_mono_band_tiff_worldfile_common (0, handle, dst_path, cvg, 0, - x_res, y_res, minx, miny, - maxx, maxy, width, height, - mono_band, compression, - tile_sz); + return export_mono_band_tiff_worldfile_common (0, handle, dst_path, cvg, + 0, x_res, y_res, minx, + miny, maxx, maxy, width, + height, mono_band, + compression, tile_sz); } RL2_DECLARE int rl2_export_section_mono_band_tiff_worldfile_from_dbms (sqlite3 * handle, const char *dst_path, rl2CoveragePtr cvg, - sqlite3_int64 section_id, + sqlite3_int64 + section_id, double x_res, double y_res, - double minx, double miny, - double maxx, double maxy, + double minx, + double miny, + double maxx, + double maxy, unsigned int width, unsigned int height, - unsigned char mono_band, + unsigned char + mono_band, unsigned char compression, unsigned int tile_sz) { /* exporting a Mono-Band TIFF+TFW - Section */ @@ -4702,16 +4766,16 @@ goto error; } rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type, 3, no_data); copy_from_outbuf_to_tile (outbuf, bufpix, sample_type, - 3, width, height, tile_sz, + pixel_type, 3, width, height, tile_sz, tile_sz, base_y, base_x); raster = rl2_create_raster (tile_sz, tile_sz, sample_type, - RL2_PIXEL_RGB, 3, bufpix, - bufpix_size, NULL, NULL, 0, NULL); + RL2_PIXEL_RGB, 3, bufpix, bufpix_size, + NULL, NULL, 0, NULL); bufpix = NULL; if (raster == NULL) goto error; if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) != RL2_OK) @@ -4754,13 +4818,14 @@ unsigned char compression, unsigned int tile_sz) { /* exporting a plain Band-Composed TIFF from the DBMS into the file-system */ return export_triple_band_tiff_common (0, handle, dst_path, cvg, 0, x_res, - y_res, minx, miny, maxx, maxy, width, - height, red_band, green_band, - blue_band, compression, tile_sz); + y_res, minx, miny, maxx, maxy, + width, height, red_band, + green_band, blue_band, compression, + tile_sz); } RL2_DECLARE int rl2_export_section_triple_band_tiff_from_dbms (sqlite3 * handle, const char *dst_path, @@ -4776,14 +4841,15 @@ unsigned char blue_band, unsigned char compression, unsigned int tile_sz) { /* exporting a plain Band-Composed TIFF - Section */ - return export_triple_band_tiff_common (1, handle, dst_path, cvg, section_id, - x_res, y_res, minx, miny, maxx, maxy, - width, height, red_band, green_band, - blue_band, compression, tile_sz); + return export_triple_band_tiff_common (1, handle, dst_path, cvg, + section_id, x_res, y_res, minx, + miny, maxx, maxy, width, height, + red_band, green_band, blue_band, + compression, tile_sz); } static int export_mono_band_tiff_common (int by_section, sqlite3 * handle, const char *dst_path, rl2CoveragePtr cvg, @@ -4882,16 +4948,16 @@ goto error; } rl2_prime_void_tile (bufpix, tile_sz, tile_sz, sample_type, 1, no_data); copy_from_outbuf_to_tile (outbuf, bufpix, sample_type, - 1, width, height, tile_sz, + pixel_type, 1, width, height, tile_sz, tile_sz, base_y, base_x); raster = - rl2_create_raster (tile_sz, tile_sz, sample_type, - out_pixel, 1, bufpix, - bufpix_size, NULL, NULL, 0, NULL); + rl2_create_raster (tile_sz, tile_sz, sample_type, out_pixel, + 1, bufpix, bufpix_size, NULL, NULL, 0, + NULL); bufpix = NULL; if (raster == NULL) goto error; if (rl2_write_tiff_tile (tiff, raster, base_y, base_x) != RL2_OK) @@ -4954,12 +5020,12 @@ unsigned int tile_sz) { /* exporting a plain Mono-Band TIFF from the DBMS - Section */ return export_mono_band_tiff_common (1, handle, dst_path, cvg, section_id, x_res, y_res, minx, miny, maxx, maxy, - width, height, mono_band, compression, - tile_sz); + width, height, mono_band, + compression, tile_sz); } static int export_ascii_grid_common (int by_section, sqlite3 * handle, int max_threads, const char *dst_path, rl2CoveragePtr cvg, @@ -5063,21 +5129,21 @@ if (by_section) { /* single Section */ if (rl2_get_section_raw_raster_data - (handle, max_threads, cvg, section_id, width, height, minx, miny, - maxx, maxy, res, res, &pixels, &pixels_size, &palette, + (handle, max_threads, cvg, section_id, width, height, minx, + miny, maxx, maxy, res, res, &pixels, &pixels_size, &palette, RL2_PIXEL_DATAGRID) != RL2_OK) goto error; } else { /* whole Coverage */ if (rl2_get_raw_raster_data - (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy, - res, res, &pixels, &pixels_size, &palette, + (handle, max_threads, cvg, width, height, minx, miny, maxx, + maxy, res, res, &pixels, &pixels_size, &palette, RL2_PIXEL_DATAGRID) != RL2_OK) goto error; } ascii = @@ -5122,21 +5188,22 @@ unsigned int height, int is_centered, int decimal_digits) { /* exporting an ASCII Grid from the DBMS into the file-system */ return export_ascii_grid_common (0, handle, max_threads, dst_path, cvg, 0, - res, minx, miny, maxx, maxy, width, height, - is_centered, decimal_digits); + res, minx, miny, maxx, maxy, width, + height, is_centered, decimal_digits); } RL2_DECLARE int rl2_export_section_ascii_grid_from_dbms (sqlite3 * handle, int max_threads, const char *dst_path, rl2CoveragePtr cvg, sqlite3_int64 section_id, double res, - double minx, double miny, double maxx, - double maxy, unsigned int width, + double minx, double miny, + double maxx, double maxy, + unsigned int width, unsigned int height, int is_centered, int decimal_digits) { /* exporting an ASCII Grid - Section */ return export_ascii_grid_common (1, handle, max_threads, dst_path, cvg, @@ -5186,13 +5253,14 @@ } return 0; } static float -compute_ndvi (void *pixels, unsigned char sample_type, unsigned char num_bands, - unsigned short width, unsigned char red_band, - unsigned char nir_band, unsigned short row, unsigned short col, +compute_ndvi (void *pixels, unsigned char sample_type, + unsigned char num_bands, unsigned short width, + unsigned char red_band, unsigned char nir_band, + unsigned short row, unsigned short col, rl2PrivPixelPtr in_no_data, float out_no_data) { /* computing a Normalized Difference Vegetaion Index -NDVI */ float red; float nir; @@ -5225,12 +5293,13 @@ export_ndvi_ascii_grid_common (int by_section, sqlite3 * handle, int max_threads, const char *dst_path, rl2CoveragePtr cvg, sqlite3_int64 section_id, double res, double minx, double miny, double maxx, double maxy, unsigned int width, - unsigned int height, int red_band, int nir_band, - int is_centered, int decimal_digits) + unsigned int height, int red_band, + int nir_band, int is_centered, + int decimal_digits) { /* exporting an NDVI ASCII Grid common implementation */ rl2PalettePtr palette = NULL; rl2PixelPtr in_no_data; rl2AsciiGridDestinationPtr ascii = NULL; @@ -5279,21 +5348,21 @@ if (by_section) { /* single Section */ if (rl2_get_section_raw_raster_data - (handle, max_threads, cvg, section_id, width, height, minx, miny, - maxx, maxy, res, res, &pixels, &pixels_size, &palette, + (handle, max_threads, cvg, section_id, width, height, minx, + miny, maxx, maxy, res, res, &pixels, &pixels_size, &palette, RL2_PIXEL_MULTIBAND) != RL2_OK) goto error; } else { /* whole Coverage */ if (rl2_get_raw_raster_data - (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy, - res, res, &pixels, &pixels_size, &palette, + (handle, max_threads, cvg, width, height, minx, miny, maxx, + maxy, res, res, &pixels, &pixels_size, &palette, RL2_PIXEL_MULTIBAND) != RL2_OK) goto error; } /* creating the output NDVI raster */ @@ -5305,12 +5374,12 @@ for (row = 0; row < height; row++) { /* computing NDVI */ for (col = 0; col < width; col++) *po++ = - compute_ndvi (pixels, sample_type, num_bands, width, red_band, - nir_band, row, col, + compute_ndvi (pixels, sample_type, num_bands, width, + red_band, nir_band, row, col, (rl2PrivPixelPtr) in_no_data, out_no_data); } free (pixels); pixels = NULL; @@ -5349,40 +5418,43 @@ return RL2_ERROR; } RL2_DECLARE int rl2_export_ndvi_ascii_grid_from_dbms (sqlite3 * handle, int max_threads, - const char *dst_path, rl2CoveragePtr cvg, - double res, double minx, double miny, - double maxx, double maxy, - unsigned int width, unsigned int height, - int red_band, int nir_band, - int is_centered, int decimal_digits) + const char *dst_path, + rl2CoveragePtr cvg, double res, + double minx, double miny, double maxx, + double maxy, unsigned int width, + unsigned int height, int red_band, + int nir_band, int is_centered, + int decimal_digits) { /* exporting an ASCII Grid from the DBMS into the file-system */ - return export_ndvi_ascii_grid_common (0, handle, max_threads, dst_path, cvg, - 0, res, minx, miny, maxx, maxy, width, - height, red_band, nir_band, + return export_ndvi_ascii_grid_common (0, handle, max_threads, dst_path, + cvg, 0, res, minx, miny, maxx, maxy, + width, height, red_band, nir_band, is_centered, decimal_digits); } RL2_DECLARE int -rl2_export_section_ndvi_ascii_grid_from_dbms (sqlite3 * handle, int max_threads, +rl2_export_section_ndvi_ascii_grid_from_dbms (sqlite3 * handle, + int max_threads, const char *dst_path, rl2CoveragePtr cvg, sqlite3_int64 section_id, double res, double minx, double miny, double maxx, double maxy, unsigned int width, - unsigned int height, int red_band, - int nir_band, int is_centered, + unsigned int height, + int red_band, int nir_band, + int is_centered, int decimal_digits) { /* exporting an ASCII Grid - Section */ - return export_ndvi_ascii_grid_common (1, handle, max_threads, dst_path, cvg, - section_id, res, minx, miny, maxx, - maxy, width, height, red_band, + return export_ndvi_ascii_grid_common (1, handle, max_threads, dst_path, + cvg, section_id, res, minx, miny, + maxx, maxy, width, height, red_band, nir_band, is_centered, decimal_digits); } static int @@ -5429,21 +5501,21 @@ if (by_section) { /* single Section */ if (rl2_get_section_raw_raster_data - (handle, max_threads, cvg, section_id, width, height, minx, miny, - maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, NULL, + (handle, max_threads, cvg, section_id, width, height, minx, + miny, maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, NULL, pixel_type) != RL2_OK) goto error; } else { /* whole Coverage */ if (rl2_get_raw_raster_data - (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy, - xx_res, yy_res, &outbuf, &outbuf_size, NULL, + (handle, max_threads, cvg, width, height, minx, miny, maxx, + maxy, xx_res, yy_res, &outbuf, &outbuf_size, NULL, pixel_type) != RL2_OK) goto error; } raster = @@ -5480,42 +5552,43 @@ } RL2_DECLARE int rl2_export_jpeg_from_dbms (sqlite3 * handle, int max_threads, const char *dst_path, rl2CoveragePtr cvg, - double x_res, double y_res, double minx, double miny, - double maxx, double maxy, unsigned int width, - unsigned int height, int quality, int with_worldfile) + double x_res, double y_res, double minx, + double miny, double maxx, double maxy, + unsigned int width, unsigned int height, + int quality, int with_worldfile) { /* exporting a JPEG (with possible JGW) from the DBMS into the file-system */ - return export_jpeg_common (0, handle, max_threads, dst_path, cvg, 0, x_res, - y_res, minx, miny, maxx, maxy, width, height, - quality, with_worldfile); + return export_jpeg_common (0, handle, max_threads, dst_path, cvg, 0, + x_res, y_res, minx, miny, maxx, maxy, width, + height, quality, with_worldfile); } RL2_DECLARE int rl2_export_section_jpeg_from_dbms (sqlite3 * handle, int max_threads, const char *dst_path, rl2CoveragePtr cvg, sqlite3_int64 section_id, double x_res, double y_res, double minx, double miny, - double maxx, double maxy, unsigned int width, - unsigned int height, int quality, - int with_worldfile) + double maxx, double maxy, + unsigned int width, unsigned int height, + int quality, int with_worldfile) { /* exporting a JPEG (with possible JGW) - Section */ return export_jpeg_common (1, handle, max_threads, dst_path, cvg, - section_id, x_res, y_res, minx, miny, maxx, maxy, - width, height, quality, with_worldfile); + section_id, x_res, y_res, minx, miny, maxx, + maxy, width, height, quality, with_worldfile); } static int export_raw_pixels_common (int by_section, sqlite3 * handle, int max_threads, rl2CoveragePtr cvg, sqlite3_int64 section_id, - double x_res, double y_res, double minx, double miny, - double maxx, double maxy, unsigned int width, - unsigned int height, int big_endian, - unsigned char **blob, int *blob_size) + double x_res, double y_res, double minx, + double miny, double maxx, double maxy, + unsigned int width, unsigned int height, + int big_endian, unsigned char **blob, int *blob_size) { /* common implementation for Export RAW pixels */ unsigned char level; unsigned char scale; double xx_res = x_res; @@ -5542,21 +5615,21 @@ if (by_section) { /* single Section */ if (rl2_get_section_raw_raster_data - (handle, max_threads, cvg, section_id, width, height, minx, miny, - maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, NULL, + (handle, max_threads, cvg, section_id, width, height, minx, + miny, maxx, maxy, xx_res, yy_res, &outbuf, &outbuf_size, NULL, pixel_type) != RL2_OK) goto error; } else { /* whole Coverage */ if (rl2_get_raw_raster_data - (handle, max_threads, cvg, width, height, minx, miny, maxx, maxy, - xx_res, yy_res, &outbuf, &outbuf_size, NULL, + (handle, max_threads, cvg, width, height, minx, miny, maxx, + maxy, xx_res, yy_res, &outbuf, &outbuf_size, NULL, pixel_type) != RL2_OK) goto error; } bufpix = rl2_copy_endian_raw_pixels (outbuf, outbuf_size, width, height, @@ -5582,13 +5655,14 @@ unsigned int width, unsigned int height, int big_endian, unsigned char **blob, int *blob_size) { /* exporting RAW pixel buffer and Transparency Mask from the DBMS */ - return export_raw_pixels_common (0, handle, max_threads, coverage, 0, x_res, - y_res, minx, miny, maxx, maxy, width, - height, big_endian, blob, blob_size); + return export_raw_pixels_common (0, handle, max_threads, coverage, 0, + x_res, y_res, minx, miny, maxx, maxy, + width, height, big_endian, blob, + blob_size); } RL2_DECLARE int rl2_export_section_raw_pixels_from_dbms (sqlite3 * handle, int max_threads, rl2CoveragePtr coverage, @@ -5601,13 +5675,13 @@ int big_endian, unsigned char **blob, int *blob_size) { /* exporting RAW pixel buffer and Transparency Mask - Section */ return export_raw_pixels_common (1, handle, max_threads, coverage, - section_id, x_res, y_res, minx, miny, maxx, - maxy, width, height, big_endian, blob, - blob_size); + section_id, x_res, y_res, minx, miny, + maxx, maxy, width, height, big_endian, + blob, blob_size); } RL2_DECLARE int rl2_load_raw_raster_into_dbms (sqlite3 * handle, int max_threads, rl2CoveragePtr cvg, const char *section, @@ -6007,10 +6081,394 @@ error: if (aux != NULL) destroyAuxImporter (aux); if (thread_slots != NULL) free (thread_slots); + if (stmt_upd_sect != NULL) + sqlite3_finalize (stmt_upd_sect); + if (stmt_sect != NULL) + sqlite3_finalize (stmt_sect); + if (stmt_levl != NULL) + sqlite3_finalize (stmt_levl); + if (stmt_tils != NULL) + sqlite3_finalize (stmt_tils); + if (stmt_data != NULL) + sqlite3_finalize (stmt_data); + return RL2_ERROR; +} + +RL2_DECLARE int +rl2_load_raw_tiles_into_dbms (sqlite3 * handle, + rl2CoveragePtr cvg, const char *section, + unsigned int sctn_width, + unsigned int sctn_height, + int sctn_srid, + double sctn_minx, + double sctn_miny, + double sctn_maxx, + double sctn_maxy, + int (*getTile) (void *data, double tile_minx, + double tile_miny, + double tile_maxx, + double tile_maxy, + unsigned char *bufpix, + rl2PalettePtr * palette), + void *data, int pyramidize) +{ +/* callback-based IMPORT Raster function */ + rl2PrivCoveragePtr privcvg = (rl2PrivCoveragePtr) cvg; + int ret; + char *sql; + const char *coverage; + unsigned char sample_type; + unsigned char pixel_type; + unsigned char num_bands; + unsigned int tile_w; + unsigned int tile_h; + unsigned char compression; + int quality; + char *table; + char *xtable; + unsigned int tileWidth; + unsigned int tileHeight; + unsigned int width = sctn_width; + unsigned int height = sctn_height; + int srid; + double minx = sctn_minx; + double miny = sctn_miny; + double maxx = sctn_maxx; + double maxy = sctn_maxy; + double tile_minx; + double tile_miny; + double tile_maxx; + double tile_maxy; + rl2RasterStatisticsPtr section_stats = NULL; + rl2PixelPtr no_data = NULL; + rl2PalettePtr palette = NULL; + rl2PalettePtr aux_palette = NULL; + unsigned int row; + unsigned int col; + double res_x; + double res_y; + double hResolution; + double vResolution; + double base_res_x; + double base_res_y; + char *xml_summary = NULL; + sqlite3_stmt *stmt_data = NULL; + sqlite3_stmt *stmt_tils = NULL; + sqlite3_stmt *stmt_sect = NULL; + sqlite3_stmt *stmt_levl = NULL; + sqlite3_stmt *stmt_upd_sect = NULL; + sqlite3_int64 section_id; + int pixel_size; + int bufpix_sz; + + if (cvg == NULL) + goto error; + if (section == NULL) + goto error; + if (width == 0 || height == 0) + goto error; + if (minx >= maxx || miny >= maxy) + goto error; + hResolution = (sctn_maxx - sctn_minx) / (double) sctn_width; + vResolution = (sctn_maxy - sctn_miny) / (double) sctn_height; + + if (rl2_get_coverage_tile_size (cvg, &tileWidth, &tileHeight) != RL2_OK) + goto error; + if (rl2_get_coverage_srid (cvg, &srid) != RL2_OK) + goto error; + if (srid != sctn_srid) + goto error; + srid = sctn_srid; + + tile_w = tileWidth; + tile_h = tileHeight; + rl2_get_coverage_compression (cvg, &compression, &quality); + rl2_get_coverage_type (cvg, &sample_type, &pixel_type, &num_bands); + coverage = rl2_get_coverage_name (cvg); + switch (sample_type) + { + case RL2_SAMPLE_INT16: + case RL2_SAMPLE_UINT16: + pixel_size = 2; + break; + case RL2_SAMPLE_INT32: + case RL2_SAMPLE_UINT32: + case RL2_SAMPLE_FLOAT: + pixel_size = 4; + break; + case RL2_SAMPLE_DOUBLE: + pixel_size = 8; + break; + default: + pixel_size = 1; + break; + }; + pixel_size *= num_bands; + bufpix_sz = tile_w * tile_h * pixel_size; + + table = sqlite3_mprintf ("%s_sections", coverage); + xtable = rl2_double_quoted_sql (table); + sqlite3_free (table); + sql = + sqlite3_mprintf + ("INSERT INTO \"%s\" (section_id, section_name, file_path, " + "md5_checksum, summary, width, height, geometry) " + "VALUES (NULL, ?, ?, ?, XB_Create(?), ?, ?, ?)", xtable); + free (xtable); + ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_sect, NULL); + sqlite3_free (sql); + if (ret != SQLITE_OK) + { + printf ("INSERT INTO sections SQL error: %s\n", + sqlite3_errmsg (handle)); + goto error; + } + + table = sqlite3_mprintf ("%s_sections", coverage); + xtable = rl2_double_quoted_sql (table); + sqlite3_free (table); + sql = + sqlite3_mprintf + ("UPDATE \"%s\" SET statistics = ? WHERE section_id = ?", xtable); + free (xtable); + ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_upd_sect, NULL); + sqlite3_free (sql); + if (ret != SQLITE_OK) + { + printf ("UPDATE sections SQL error: %s\n", sqlite3_errmsg (handle)); + goto error; + } + + if (privcvg->mixedResolutions) + { + /* mixed resolutions Coverage */ + table = sqlite3_mprintf ("%s_section_levels", coverage); + xtable = rl2_double_quoted_sql (table); + sqlite3_free (table); + sql = + sqlite3_mprintf + ("INSERT OR IGNORE INTO \"%s\" (section_id, pyramid_level, " + "x_resolution_1_1, y_resolution_1_1, " + "x_resolution_1_2, y_resolution_1_2, x_resolution_1_4, " + "y_resolution_1_4, x_resolution_1_8, y_resolution_1_8) " + "VALUES (?, 0, ?, ?, ?, ?, ?, ?, ?, ?)", xtable); + free (xtable); + ret = + sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_levl, NULL); + sqlite3_free (sql); + if (ret != SQLITE_OK) + { + printf ("INSERT INTO section_levels SQL error: %s\n", + sqlite3_errmsg (handle)); + goto error; + } + } + else + { + /* single resolution Coverage */ + table = sqlite3_mprintf ("%s_levels", coverage); + xtable = rl2_double_quoted_sql (table); + sqlite3_free (table); + sql = + sqlite3_mprintf + ("INSERT OR IGNORE INTO \"%s\" (pyramid_level, " + "x_resolution_1_1, y_resolution_1_1, " + "x_resolution_1_2, y_resolution_1_2, x_resolution_1_4, " + "y_resolution_1_4, x_resolution_1_8, y_resolution_1_8) " + "VALUES (0, ?, ?, ?, ?, ?, ?, ?, ?)", xtable); + free (xtable); + ret = + sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_levl, NULL); + sqlite3_free (sql); + if (ret != SQLITE_OK) + { + printf ("INSERT INTO levels SQL error: %s\n", + sqlite3_errmsg (handle)); + goto error; + } + } + + table = sqlite3_mprintf ("%s_tiles", coverage); + xtable = rl2_double_quoted_sql (table); + sqlite3_free (table); + sql = + sqlite3_mprintf + ("INSERT INTO \"%s\" (tile_id, pyramid_level, section_id, geometry) " + "VALUES (NULL, 0, ?, BuildMBR(?, ?, ?, ?, ?))", xtable); + free (xtable); + ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_tils, NULL); + sqlite3_free (sql); + if (ret != SQLITE_OK) + { + printf ("INSERT INTO tiles SQL error: %s\n", sqlite3_errmsg (handle)); + goto error; + } + + table = sqlite3_mprintf ("%s_tile_data", coverage); + xtable = rl2_double_quoted_sql (table); + sqlite3_free (table); + sql = + sqlite3_mprintf + ("INSERT INTO \"%s\" (tile_id, tile_data_odd, tile_data_even) " + "VALUES (?, ?, ?)", xtable); + free (xtable); + ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_data, NULL); + sqlite3_free (sql); + if (ret != SQLITE_OK) + { + printf ("INSERT INTO tile_data SQL error: %s\n", + sqlite3_errmsg (handle)); + goto error; + } + res_x = hResolution; + res_y = vResolution; + base_res_x = privcvg->hResolution; + base_res_y = privcvg->vResolution; + +/* INSERTing the section */ + if (!rl2_do_insert_section + (handle, "loaded from RAW pixels", section, srid, width, height, minx, + miny, maxx, maxy, xml_summary, privcvg->sectionPaths, + privcvg->sectionMD5, privcvg->sectionSummary, stmt_sect, §ion_id)) + goto error; + section_stats = rl2_create_raster_statistics (sample_type, num_bands); + if (section_stats == NULL) + goto error; +/* INSERTing the base-levels */ + if (privcvg->mixedResolutions) + { + /* multiple resolutions Coverage */ + if (!rl2_do_insert_section_levels + (handle, section_id, res_x, res_y, 1.0, sample_type, stmt_levl)) + goto error; + } + else + { + /* single resolution Coverage */ + if (!rl2_do_insert_levels + (handle, base_res_x, base_res_y, 1.0, sample_type, stmt_levl)) + goto error; + } + +/* looping on tiles */ + tile_maxy = maxy; + for (row = 0; row < height; row += tile_h) + { + tile_miny = tile_maxy - ((double) tile_h * res_y); + tile_minx = minx; + for (col = 0; col < width; col += tile_w) + { + /* requesting a Tile */ + rl2RasterPtr tile; + unsigned char *blob_odd; + unsigned char *blob_even; + int blob_odd_sz; + int blob_even_sz; + unsigned char *bufpix = malloc (bufpix_sz); + + if (pixel_type == RL2_PIXEL_PALETTE) + rl2_prime_void_tile_palette (bufpix, tile_w, tile_h, + no_data); + else + rl2_prime_void_tile (bufpix, tile_w, tile_h, + sample_type, num_bands, no_data); + + tile_maxx = tile_minx + ((double) tile_w * res_x); + if (!getTile + (data, tile_minx, tile_miny, tile_maxx, tile_maxy, bufpix, + &palette)) + { + if (bufpix != NULL) + free (bufpix); + goto error; + } + + /* building a raster Tile */ + tile = + rl2_create_raster (tile_w, tile_h, sample_type, pixel_type, + num_bands, bufpix, bufpix_sz, palette, + NULL, 0, no_data); + if (tile == NULL) + { + if (bufpix != NULL) + free (bufpix); + goto error; + } + + /* encoding the Tile */ + if (rl2_raster_encode + (tile, compression, &blob_odd, &blob_odd_sz, &blob_even, + &blob_even_sz, quality, 1) != RL2_OK) + { + fprintf (stderr, + "ERROR: unable to encode a tile [Row=%d Col=%d]\n", + row, col); + rl2_destroy_raster (tile); + goto error; + } + aux_palette = rl2_clone_palette (rl2_get_raster_palette (tile)); + rl2_destroy_raster (tile); + + /* INSERTing the tile */ + if (!do_insert_tile + (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz, + section_id, srid, tile_minx, tile_miny, tile_maxx, + tile_maxy, aux_palette, no_data, stmt_tils, stmt_data, + section_stats)) + goto error; + + /* next tile */ + tile_minx += (double) tile_w *res_x; + } + tile_maxy -= (double) tile_h *res_y; + } + +/* updating the Section's Statistics */ + compute_aggregate_sq_diff (section_stats); + if (!rl2_do_insert_stats (handle, section_stats, section_id, stmt_upd_sect)) + goto error; + + rl2_destroy_raster_statistics (section_stats); + section_stats = NULL; + + if (pyramidize) + { + /* immediately building the Section's Pyramid */ + const char *coverage_name = rl2_get_coverage_name (cvg); + if (coverage_name == NULL) + goto error; + if (rl2_build_section_pyramid + (handle, 1, coverage_name, section_id, 1, 0) != RL2_OK) + { + fprintf (stderr, "unable to build the Section's Pyramid\n"); + goto error; + } + } + + sqlite3_finalize (stmt_upd_sect); + sqlite3_finalize (stmt_sect); + sqlite3_finalize (stmt_levl); + sqlite3_finalize (stmt_tils); + sqlite3_finalize (stmt_data); + stmt_upd_sect = NULL; + stmt_sect = NULL; + stmt_levl = NULL; + stmt_tils = NULL; + stmt_data = NULL; + + if (rl2_update_dbms_coverage (handle, coverage) != RL2_OK) + { + fprintf (stderr, "unable to update the Coverage\n"); + goto error; + } + + return RL2_OK; + + error: if (stmt_upd_sect != NULL) sqlite3_finalize (stmt_upd_sect); if (stmt_sect != NULL) sqlite3_finalize (stmt_sect); if (stmt_levl != NULL) Index: src/rl2jpeg.c ================================================================== --- src/rl2jpeg.c +++ src/rl2jpeg.c @@ -228,11 +228,12 @@ * the first one. */ if (cinfo->src == NULL) { /* first time for this JPEG object? */ cinfo->src = (struct jpeg_source_mgr *) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, + JPOOL_PERMANENT, sizeof (struct jpeg_source_mgr)); } src = cinfo->src; src->init_source = init_mem_source; @@ -263,11 +264,12 @@ * can be written to the same buffer without re-executing jpeg_mem_dest. */ if (cinfo->dest == NULL) { /* first time for this JPEG object? */ cinfo->dest = (struct jpeg_destination_mgr *) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, + JPOOL_PERMANENT, sizeof (jpeg_mem_destination_mgr)); dest = (jpeg_mem_dest_ptr) cinfo->dest; dest->newbuffer = NULL; } @@ -755,12 +757,12 @@ unsigned char *blob; int blob_size; if (rst == NULL) return RL2_ERROR; - if (check_jpeg_compatibility (rst->sampleType, rst->pixelType, rst->nBands) - != RL2_OK) + if (check_jpeg_compatibility + (rst->sampleType, rst->pixelType, rst->nBands) != RL2_OK) return RL2_ERROR; if (rl2_data_to_jpeg (rst->rasterBuffer, rst->maskBuffer, (rl2PalettePtr) (rst->Palette), rst->width, rst->height, rst->sampleType, rst->pixelType, &blob, &blob_size, quality) != RL2_OK) @@ -780,32 +782,32 @@ int blob_size; if (rgb == NULL) return RL2_ERROR; if (rl2_data_to_jpeg - (rgb, NULL, NULL, width, height, RL2_SAMPLE_UINT8, RL2_PIXEL_RGB, &blob, - &blob_size, quality) != RL2_OK) + (rgb, NULL, NULL, width, height, RL2_SAMPLE_UINT8, RL2_PIXEL_RGB, + &blob, &blob_size, quality) != RL2_OK) return RL2_ERROR; *jpeg = blob; *jpeg_size = blob_size; return RL2_OK; } RL2_DECLARE int rl2_gray_to_jpeg (unsigned int width, unsigned int height, - const unsigned char *gray, int quality, unsigned char **jpeg, - int *jpeg_size) + const unsigned char *gray, int quality, + unsigned char **jpeg, int *jpeg_size) { /* creating a PNG image from a Grayscale buffer */ unsigned char *blob; int blob_size; if (gray == NULL) return RL2_ERROR; if (rl2_data_to_jpeg - (gray, NULL, NULL, width, height, RL2_SAMPLE_UINT8, RL2_PIXEL_GRAYSCALE, - &blob, &blob_size, quality) != RL2_OK) + (gray, NULL, NULL, width, height, RL2_SAMPLE_UINT8, + RL2_PIXEL_GRAYSCALE, &blob, &blob_size, quality) != RL2_OK) return RL2_ERROR; *jpeg = blob; *jpeg_size = blob_size; return RL2_OK; } @@ -849,12 +851,13 @@ if (rst == NULL) return NULL; /* creating the raster section */ scn = - rl2_create_section (path, RL2_COMPRESSION_JPEG, RL2_TILESIZE_UNDEFINED, - RL2_TILESIZE_UNDEFINED, rst); + rl2_create_section (path, RL2_COMPRESSION_JPEG, + RL2_TILESIZE_UNDEFINED, RL2_TILESIZE_UNDEFINED, + rst); return scn; } RL2_DECLARE rl2RasterPtr rl2_raster_from_jpeg (const unsigned char *jpeg, int jpeg_size) @@ -876,12 +879,12 @@ if (pixel_type == RL2_PIXEL_RGB) nBands = 3; /* creating the raster */ rst = - rl2_create_raster (width, height, RL2_SAMPLE_UINT8, pixel_type, nBands, - data, data_size, NULL, NULL, 0, NULL); + rl2_create_raster (width, height, RL2_SAMPLE_UINT8, pixel_type, + nBands, data, data_size, NULL, NULL, 0, NULL); if (rst == NULL) goto error; return rst; error: @@ -891,12 +894,12 @@ free (data); return NULL; } RL2_DECLARE int -rl2_get_jpeg_infos (const char *path, unsigned int *width, unsigned int *height, - unsigned char *pixel_type) +rl2_get_jpeg_infos (const char *path, unsigned int *width, + unsigned int *height, unsigned char *pixel_type) { /* attempting to retrieve basic infos from a JPEG image */ int jpeg_size; unsigned char *jpeg = NULL; struct jpeg_decompress_struct cinfo; @@ -1062,12 +1065,12 @@ if (cinfo.out_color_space == JCS_CMYK) { JSAMPROW row = buffer[0]; for (i = 0; i < (int) (cinfo.output_width); i++) { - CMYK2RGB (*(row + 0), *(row + 1), *(row + 2), *(row + 3), - inverted, p_data); + CMYK2RGB (*(row + 0), *(row + 1), *(row + 2), + *(row + 3), inverted, p_data); row += 4; p_data += 3; } } else if (cinfo.out_color_space == JCS_GRAYSCALE) @@ -1296,12 +1299,12 @@ /* checking for strict compatibility */ if (coverage->sampleType == RL2_SAMPLE_UINT8 && coverage->pixelType == RL2_PIXEL_GRAYSCALE && coverage->nBands == 1) { if (raster->sampleType == RL2_SAMPLE_UINT8 - && raster->pixelType == RL2_PIXEL_GRAYSCALE && raster->nBands == 1 - && forced_conversion == RL2_CONVERT_NO) + && raster->pixelType == RL2_PIXEL_GRAYSCALE + && raster->nBands == 1 && forced_conversion == RL2_CONVERT_NO) return 1; if (raster->sampleType == RL2_SAMPLE_UINT8 && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3 && forced_conversion == RL2_CONVERT_RGB_TO_GRAYSCALE) return 1; @@ -1312,11 +1315,12 @@ if (raster->sampleType == RL2_SAMPLE_UINT8 && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3 && forced_conversion == RL2_CONVERT_NO) return 1; if (raster->sampleType == RL2_SAMPLE_UINT8 - && raster->pixelType == RL2_PIXEL_GRAYSCALE && raster->nBands == 1 + && raster->pixelType == RL2_PIXEL_GRAYSCALE + && raster->nBands == 1 && forced_conversion == RL2_CONVERT_GRAYSCALE_TO_RGB) return 1; } if (verbose) fprintf (stderr, "Mismatching JPEG colorspace !!!\n"); @@ -1530,12 +1534,13 @@ prev = xml; xml = sqlite3_mprintf ("%s", prev); sqlite3_free (prev); prev = xml; xml = - sqlite3_mprintf ("%s%1.10f", - prev, maxx - minx); + sqlite3_mprintf + ("%s%1.10f", prev, + maxx - minx); sqlite3_free (prev); prev = xml; xml = sqlite3_mprintf ("%s%1.10f", prev, maxy - miny); Index: src/rl2openjpeg.c ================================================================== --- src/rl2openjpeg.c +++ src/rl2openjpeg.c @@ -57,12 +57,16 @@ #ifndef OMIT_OPENJPEG /* only if OpenJpeg is enabled */ #ifdef HAVE_OPENJPEG_2_1_OPENJPEG_H #include +#else +#ifdef __ANDROID__ /* Android specific */ +#include #else #include +#endif #endif struct jp2_memfile { /* a struct emulating a file [memory mapped] */ @@ -690,12 +694,13 @@ RL2_PRIVATE int rl2_decode_jpeg2000_scaled (int scale, const unsigned char *jpeg2000, int jpeg2000_sz, unsigned int *xwidth, unsigned int *xheight, unsigned char xsample_type, - unsigned char xpixel_type, unsigned char xnum_bands, - unsigned char **pixels, int *pixels_size) + unsigned char xpixel_type, + unsigned char xnum_bands, unsigned char **pixels, + int *pixels_size) { /* attempting to create a raster from a Jpeg2000 image - supporting rescaled size */ unsigned char *buf = NULL; int buf_size = 0; unsigned int width; @@ -856,12 +861,13 @@ goto error; } if (sample_type == RL2_SAMPLE_UINT16) save_tile_u16 ((unsigned short *) buf, (unsigned short *) jp2_data, tile_x0 / scale, - tile_y0 / scale, tile_x1 / scale, tile_y1 / scale, - num_bands, width / scale, height / scale); + tile_y0 / scale, tile_x1 / scale, + tile_y1 / scale, num_bands, width / scale, + height / scale); else save_tile_u8 ((unsigned char *) buf, (unsigned char *) jp2_data, tile_x0 / scale, tile_y0 / scale, tile_x1 / scale, tile_y1 / scale, num_bands, width / scale, height / scale); @@ -899,12 +905,12 @@ /* checking for strict compatibility */ if (coverage->sampleType == RL2_SAMPLE_UINT8 && coverage->pixelType == RL2_PIXEL_GRAYSCALE && coverage->nBands == 1) { if (raster->sampleType == RL2_SAMPLE_UINT8 - && raster->pixelType == RL2_PIXEL_GRAYSCALE && raster->nBands == 1 - && forced_conversion == RL2_CONVERT_NO) + && raster->pixelType == RL2_PIXEL_GRAYSCALE + && raster->nBands == 1 && forced_conversion == RL2_CONVERT_NO) return 1; if (raster->sampleType == RL2_SAMPLE_UINT8 && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3 && forced_conversion == RL2_CONVERT_RGB_TO_GRAYSCALE) return 1; @@ -915,26 +921,26 @@ if (raster->sampleType == RL2_SAMPLE_UINT8 && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3 && forced_conversion == RL2_CONVERT_NO) return 1; if (raster->sampleType == RL2_SAMPLE_UINT8 - && raster->pixelType == RL2_PIXEL_GRAYSCALE && raster->nBands == 1 + && raster->pixelType == RL2_PIXEL_GRAYSCALE + && raster->nBands == 1 && forced_conversion == RL2_CONVERT_GRAYSCALE_TO_RGB) return 1; } if (coverage->sampleType == RL2_SAMPLE_UINT8 && coverage->pixelType == RL2_PIXEL_DATAGRID && coverage->nBands == 1) { if (raster->sampleType == RL2_SAMPLE_UINT8 - && raster->pixelType == RL2_PIXEL_DATAGRID && raster->nBands == 1 - && forced_conversion == RL2_CONVERT_NO) + && raster->pixelType == RL2_PIXEL_DATAGRID + && raster->nBands == 1 && forced_conversion == RL2_CONVERT_NO) return 1; } if (coverage->sampleType == RL2_SAMPLE_UINT8 - && coverage->pixelType == RL2_PIXEL_MULTIBAND && (coverage->nBands == 3 - || coverage->nBands == - 4)) + && coverage->pixelType == RL2_PIXEL_MULTIBAND + && (coverage->nBands == 3 || coverage->nBands == 4)) { if (raster->sampleType == RL2_SAMPLE_UINT8 && raster->pixelType == RL2_PIXEL_MULTIBAND && raster->nBands == coverage->nBands && forced_conversion == RL2_CONVERT_NO) @@ -942,12 +948,12 @@ } if (coverage->sampleType == RL2_SAMPLE_UINT16 && coverage->pixelType == RL2_PIXEL_DATAGRID && coverage->nBands == 1) { if (raster->sampleType == RL2_SAMPLE_UINT16 - && raster->pixelType == RL2_PIXEL_DATAGRID && raster->nBands == 1 - && forced_conversion == RL2_CONVERT_NO) + && raster->pixelType == RL2_PIXEL_DATAGRID + && raster->nBands == 1 && forced_conversion == RL2_CONVERT_NO) return 1; } if (coverage->sampleType == RL2_SAMPLE_UINT16 && coverage->pixelType == RL2_PIXEL_RGB && coverage->nBands == 3) { @@ -955,13 +961,12 @@ && raster->pixelType == RL2_PIXEL_RGB && raster->nBands == 3 && forced_conversion == RL2_CONVERT_NO) return 1; } if (coverage->sampleType == RL2_SAMPLE_UINT16 - && coverage->pixelType == RL2_PIXEL_MULTIBAND && (coverage->nBands == 3 - || coverage->nBands == - 4)) + && coverage->pixelType == RL2_PIXEL_MULTIBAND + && (coverage->nBands == 3 || coverage->nBands == 4)) { if (raster->sampleType == RL2_SAMPLE_UINT16 && raster->pixelType == RL2_PIXEL_MULTIBAND && raster->nBands == coverage->nBands && forced_conversion == RL2_CONVERT_NO) @@ -971,12 +976,13 @@ fprintf (stderr, "Mismatching Jpeg2000 colorspace !!!\n"); return 0; } static int -read_jpeg2000_pixels_gray_to_rgb (rl2PrivRasterPtr origin, unsigned short width, - unsigned short height, unsigned int startRow, +read_jpeg2000_pixels_gray_to_rgb (rl2PrivRasterPtr origin, + unsigned short width, unsigned short height, + unsigned int startRow, unsigned int startCol, unsigned char *pixels) { /* Grayscale -> RGB */ unsigned short x; unsigned short y; @@ -1000,12 +1006,13 @@ } return 1; } static int -read_jpeg2000_pixels_rgb_to_gray (rl2PrivRasterPtr origin, unsigned short width, - unsigned short height, unsigned int startRow, +read_jpeg2000_pixels_rgb_to_gray (rl2PrivRasterPtr origin, + unsigned short width, unsigned short height, + unsigned int startRow, unsigned int startCol, unsigned char *pixels) { /* RGB -> Grayscale */ unsigned short x; unsigned short y; @@ -1188,11 +1195,12 @@ return RL2_ERROR; } RL2_DECLARE rl2RasterPtr rl2_get_tile_from_jpeg2000_origin (rl2CoveragePtr cvg, rl2RasterPtr jpeg2000, - unsigned int startRow, unsigned int startCol, + unsigned int startRow, + unsigned int startCol, unsigned char forced_conversion, int verbose) { /* attempting to create a Coverage-tile from a Jpeg2000 origin */ unsigned int x; rl2PrivCoveragePtr coverage = (rl2PrivCoveragePtr) cvg; @@ -1602,12 +1610,13 @@ prev = xml; xml = sqlite3_mprintf ("%s", prev); sqlite3_free (prev); prev = xml; xml = - sqlite3_mprintf ("%s%1.10f", - prev, maxx - minx); + sqlite3_mprintf + ("%s%1.10f", prev, + maxx - minx); sqlite3_free (prev); prev = xml; xml = sqlite3_mprintf ("%s%1.10f", prev, maxy - miny); Index: src/rl2paint.c ================================================================== --- src/rl2paint.c +++ src/rl2paint.c @@ -184,10 +184,20 @@ unsigned char *rgba; cairo_surface_t *bitmap; cairo_pattern_t *pattern; } RL2GraphBitmap; typedef RL2GraphBitmap *RL2GraphBitmapPtr; + +static unsigned char +unpremultiply (unsigned char c, unsigned char a) +{ +/* Cairo has premultiplied alphas */ + double x = ((double) c * 255.0) / (double) a; + if (a == 0) + return 0; + return (unsigned char) x; +} RL2_DECLARE rl2GraphicsContextPtr rl2_graph_create_context (int width, int height) { /* creating a generic Graphics Context */ @@ -770,12 +780,13 @@ unsigned char blue1, unsigned char alpha1, unsigned char red2, unsigned char green2, unsigned char blue2, - unsigned char alpha2, double pen_width, - int line_cap, int line_join) + unsigned char alpha2, + double pen_width, int line_cap, + int line_join) { /* setting up a Linear Gradient Pen - solid style */ double d_red = (double) red1 / 255.0; double d_green = (double) green1 / 255.0; double d_blue = (double) blue1 / 255.0; @@ -1045,12 +1056,13 @@ RL2_DECLARE int rl2_graph_set_linear_gradient_brush (rl2GraphicsContextPtr context, double x, double y, double width, double height, unsigned char red1, unsigned char green1, - unsigned char blue1, unsigned char alpha1, - unsigned char red2, unsigned char green2, + unsigned char blue1, + unsigned char alpha1, unsigned char red2, + unsigned char green2, unsigned char blue2, unsigned char alpha2) { /* setting up a Linear Gradient Brush */ double d_red = (double) red1 / 255.0; double d_green = (double) green1 / 255.0; @@ -1166,10 +1178,11 @@ style = CAIRO_FONT_SLANT_OBLIQUE; if (fnt->weight == RL2_FONTWEIGHT_BOLD) weight = CAIRO_FONT_WEIGHT_BOLD; cairo_select_font_face (cairo, fnt->facename, style, weight); cairo_set_font_size (cairo, size); + fnt->cairo_font = cairo_get_font_face (cairo); } else { /* using a TrueType font */ cairo_font_options_t *font_options = cairo_font_options_create (); @@ -1556,11 +1569,13 @@ unsigned char blue; unsigned char alpha; unsigned char xred; unsigned char xgreen; unsigned char xblue; + unsigned char xalpha; int valid = 0; + int has_black = 0; unsigned char *bitmap; RL2PrivGraphPatternPtr pattern = (RL2PrivGraphPatternPtr) ptrn; if (pattern == NULL) return RL2_ERROR; @@ -1573,26 +1588,30 @@ /* checking for a Monochrome Pattern */ for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { - aux_pattern_get_pixel (x, y, width, bitmap, &red, &green, &blue, - &alpha); + aux_pattern_get_pixel (x, y, width, bitmap, &red, &green, + &blue, &alpha); if (alpha != 0) { + if (red < 64 && green < 64 && blue < 64) + has_black++; if (valid) { - if (xred == red && xgreen == green && xblue == blue) + if (xred == red && xgreen == green + && xblue == blue && alpha == xalpha) ; else - return RL2_ERROR; + goto not_mono; } else { xred = red; xgreen = green; xblue = blue; + xalpha = alpha; valid = 1; } } } } @@ -1599,18 +1618,38 @@ /* all right, applying the new color */ for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { - aux_pattern_get_pixel (x, y, width, bitmap, &red, &green, &blue, - &alpha); + aux_pattern_get_pixel (x, y, width, bitmap, &red, &green, + &blue, &alpha); if (alpha != 0) aux_pattern_set_pixel (x, y, width, bitmap, r, g, b, alpha); } } cairo_surface_mark_dirty (pattern->bitmap); return RL2_OK; + + not_mono: + if (has_black) + { + /* recoloring only the black pixels */ + for (y = 0; y < height; y++) + { + for (x = 0; x < width; x++) + { + aux_pattern_get_pixel (x, y, width, bitmap, &red, + &green, &blue, &alpha); + if (red < 64 && green < 64 && blue < 64) + aux_pattern_set_pixel (x, y, width, bitmap, r, g, b, + alpha); + } + } + cairo_surface_mark_dirty (pattern->bitmap); + return RL2_OK; + } + return RL2_ERROR; } RL2_DECLARE int rl2_graph_pattern_transparency (rl2GraphicsPatternPtr ptrn, unsigned char aleph) { @@ -1637,12 +1676,12 @@ /* applying the new transparency */ for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { - aux_pattern_get_pixel (x, y, width, bitmap, &red, &green, &blue, - &alpha); + aux_pattern_get_pixel (x, y, width, bitmap, &red, &green, + &blue, &alpha); if (alpha != 0) aux_pattern_set_pixel (x, y, width, bitmap, red, green, blue, aleph); } } @@ -1767,12 +1806,13 @@ /* destroying the cached font */ rl2_destroy_private_tt_font (font); } RL2_DECLARE rl2GraphicsFontPtr -rl2_graph_create_TrueType_font (const void *priv_data, const unsigned char *ttf, - int ttf_bytes, double size) +rl2_graph_create_TrueType_font (const void *priv_data, + const unsigned char *ttf, int ttf_bytes, + double size) { /* creating a TrueType font */ RL2GraphFontPtr fnt; char *facename; int is_bold; @@ -1910,26 +1950,28 @@ RL2_DECLARE void rl2_graph_destroy_font (rl2GraphicsFontPtr font) { /* destroying a font */ RL2GraphFontPtr fnt = (RL2GraphFontPtr) font; - if (fnt == NULL) return; if (fnt->toy_font == 0) { if (fnt->cairo_scaled_font != NULL) cairo_scaled_font_destroy (fnt->cairo_scaled_font); - if (fnt->cairo_font != NULL) - cairo_font_face_destroy (fnt->cairo_font); } else { if (fnt->facename != NULL) free (fnt->facename); - free (fnt); } + if (fnt->cairo_font != NULL) + { + if (cairo_font_face_get_reference_count (fnt->cairo_font) > 0) + cairo_font_face_destroy (fnt->cairo_font); + } + free (fnt); } RL2_DECLARE int rl2_graph_font_set_color (rl2GraphicsFontPtr font, unsigned char red, unsigned char green, unsigned char blue, @@ -2264,12 +2306,12 @@ return 1; } RL2_DECLARE int rl2_graph_draw_circle_sector (rl2GraphicsContextPtr context, double center_x, - double center_y, double radius, double from_angle, - double to_angle) + double center_y, double radius, + double from_angle, double to_angle) { /* drawing a filled circular sector */ cairo_t *cairo; RL2GraphContextPtr ctx = (RL2GraphContextPtr) context; if (ctx == NULL) @@ -2429,12 +2471,12 @@ *post_y = extents.y_advance; return 1; } RL2_DECLARE int -rl2_graph_draw_text (rl2GraphicsContextPtr context, const char *text, double x, - double y, double angle, double anchor_point_x, +rl2_graph_draw_text (rl2GraphicsContextPtr context, const char *text, + double x, double y, double angle, double anchor_point_x, double anchor_point_y) { /* drawing a text string (using the current font) */ double rads; double pre_x; @@ -2578,10 +2620,11 @@ break; if (result->first_point == NULL) break; *x = result->first_point->x; *y = result->first_point->y; + rl2_destroy_geometry (result); ok = 1; } } else goto error; @@ -2611,12 +2654,12 @@ return 1; return 0; } static rl2GeometryPtr -aux_reduce_curve (sqlite3 * handle, rl2GeometryPtr geom, rl2GeometryPtr circle, - double x, double y) +aux_reduce_curve (sqlite3 * handle, rl2GeometryPtr geom, + rl2GeometryPtr circle, double x, double y) { /* reducing a Curve by discarding the alreasdy processed portion */ sqlite3_stmt *stmt = NULL; const char *sql; int ret; @@ -2624,11 +2667,10 @@ int size1; unsigned char *blob2; int size2; rl2GeometryPtr out = NULL; rl2LinestringPtr ln; - rl2LinestringPtr save_ln = NULL; int count = 0; rl2_serialize_linestring (geom->first_linestring, &blob1, &size1); rl2_serialize_linestring (circle->first_linestring, &blob2, &size2); @@ -2662,31 +2704,89 @@ { if (aux_is_discarded_portion (ln, x, y)) ; else { - save_ln = ln; + if (out != NULL) + rl2_destroy_geometry (out); + out = rl2_clone_linestring (ln); count++; } ln = ln->next; } + rl2_destroy_geometry (result); } } else goto error; } - if (save_ln == NULL || count != 1) + if (out == NULL || count != 1) goto error; - out = rl2_clone_linestring (save_ln); sqlite3_finalize (stmt); return out; error: if (stmt != NULL) sqlite3_finalize (stmt); + if (out != NULL) + rl2_destroy_geometry (out); return NULL; } + +static int +check_reverse (rl2GeometryPtr geom) +{ +/* testing for an inverse label */ + rl2LinestringPtr ln; + double x0; + double y0; + double x1; + double y1; + double width; + double height; + int last; + + if (geom == NULL) + return 0; + ln = geom->first_linestring; + if (ln == NULL) + return 0; + if (ln->points < 2) + return 0; + last = ln->points - 1; + + rl2GetPoint (ln->coords, 0, &x0, &y0); + rl2GetPoint (ln->coords, last, &x1, &y1); + width = fabs (x0 - x1); + height = fabs (y0 - y1); + if (width > 3.0) + { + if (x0 > x1) + return 1; + } + else + { + if (y0 > y1) + return 1; + } + return 0; +} + +static void +reverse_text (const char *in, char *dest, int len) +{ +/* reversing a text string */ + char *out; + int n = 1; + while (*in != '\0') + { + out = dest + len - n; + *out = *in++; + n++; + } + *(dest + len) = '\0'; +} static rl2GeometryPtr rl2_draw_wrapped_label (sqlite3 * handle, rl2GraphicsContextPtr context, cairo_t * cairo, const char *text, rl2GeometryPtr geom) { @@ -2701,17 +2801,26 @@ double angle; char buf[2]; rl2GeometryPtr g2; rl2GeometryPtr g = rl2_clone_curve (geom); rl2GeometryPtr circle; + char *rev_text = NULL; const char *c = text; cairo_font_extents_t extents; cairo_font_extents (cairo, &extents); radius = sqrt ((extents.max_x_advance * extents.max_x_advance) + (extents.height * extents.height)) / 2.0; + if (check_reverse (g)) + { + /* reverse text */ + int len = strlen (text); + rev_text = malloc (len + 1); + reverse_text (text, rev_text, len); + c = rev_text; + } while (*c != '\0' && g != NULL) { buf[0] = *c; buf[1] = '\0'; get_aux_start_point (g, &x0, &y0); @@ -2724,35 +2833,39 @@ break; } m = (y1 - y0) / (x1 - x0); rads = atan (m); angle = rads / .0174532925199432958; - if (x1 < x0) + if (x1 < x0 && rev_text == NULL) angle += 180.0; rl2_graph_draw_text (context, buf, x0, y0, angle, 0.5, 0.5); c++; g2 = aux_reduce_curve (handle, g, circle, x0, y0); rl2_destroy_geometry (circle); rl2_destroy_geometry (g); g = g2; } + if (rev_text) + free (rev_text); return g; } RL2_DECLARE int rl2_graph_draw_warped_text (sqlite3 * handle, rl2GraphicsContextPtr context, - const char *text, int points, double *x, double *y, - double initial_gap, double gap, int repeated) + const char *text, int points, double *x, + double *y, double initial_gap, double gap, + int repeated) { /* drawing a text string warped along a modelling curve (using the current font) */ double curve_len; double text_len; double extra_len; double start; double from; rl2GeometryPtr geom = NULL; rl2GeometryPtr geom2 = NULL; + rl2GeometryPtr geom3 = NULL; cairo_t *cairo; RL2GraphContextPtr ctx = (RL2GraphContextPtr) context; if (ctx == NULL) return 0; @@ -2767,18 +2880,18 @@ if (geom == NULL) return 0; curve_len = rl2_compute_curve_length (geom); do_estimate_text_length (cairo, text, &text_len, &extra_len); - if ((text_len + (2.0 * extra_len)) > curve_len) + if ((initial_gap + text_len + (2.0 * extra_len)) > curve_len) return 0; /* not enough room to place the label */ if (repeated) { /* repeated labels */ int first = 1; - rl2GeometryPtr geom3 = rl2_clone_linestring (geom->first_linestring); + geom3 = rl2_clone_linestring (geom->first_linestring); while (geom3 != NULL) { if (first) { start = initial_gap + extra_len; @@ -2785,10 +2898,12 @@ first = 0; } else start = gap + extra_len; curve_len = rl2_compute_curve_length (geom3); + if ((start + text_len + extra_len) > curve_len) + break; /* not enough room to place the label */ from = start / curve_len; /* extracting the sub-path modelling the label */ geom2 = rl2_curve_substring (handle, geom3, from, 1.0); rl2_destroy_geometry (geom3); if (geom2 == NULL) @@ -2806,12 +2921,13 @@ from = start / curve_len; /* extracting the sub-path modelling the label */ geom2 = rl2_curve_substring (handle, geom, from, 1.0); if (geom2 == NULL) goto error; - rl2_draw_wrapped_label (handle, context, cairo, text, geom2); + geom3 = rl2_draw_wrapped_label (handle, context, cairo, text, geom2); rl2_destroy_geometry (geom2); + rl2_destroy_geometry (geom3); } rl2_destroy_geometry (geom); return 1; @@ -2889,10 +3005,164 @@ cairo_paint (cairo); cairo_restore (cairo); cairo_surface_flush (surface); return 1; } + +RL2_DECLARE int +rl2_rescale_pixbuf (const unsigned char *inbuf, unsigned int inwidth, + unsigned int inheight, unsigned char pixtype, + const unsigned char *outbuf, unsigned int outwidth, + unsigned int outheight) +{ +/* drawing a rescaled pixbufx (RGB or GRAYSCALE) */ + unsigned char *pixbuf = NULL; + int bufsz; + const unsigned char *p_in; + unsigned char *p_out; + unsigned int x; + unsigned int y; + int stride; + double scale_x = (double) outwidth / (double) inwidth; + double scale_y = (double) outheight / (double) inheight; + int little_endian = rl2cr_endian_arch (); + cairo_t *cairo; + cairo_surface_t *surface; + cairo_surface_t *bitmap; + cairo_pattern_t *pattern; + if (pixtype != RL2_PIXEL_RGB && pixtype != RL2_PIXEL_GRAYSCALE) + return 0; + +/* creating a Cairo context */ + surface = + cairo_image_surface_create (CAIRO_FORMAT_ARGB32, outwidth, outheight); + if (cairo_surface_status (surface) == CAIRO_STATUS_SUCCESS) + ; + else + goto error1; + cairo = cairo_create (surface); + if (cairo_status (cairo) == CAIRO_STATUS_NO_MEMORY) + goto error2; + +/* allocating and populating data for Cairo */ + stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, inwidth); + bufsz = stride * inheight; + pixbuf = malloc (bufsz); + if (pixbuf == NULL) + { + goto error2; + } + p_in = inbuf; + p_out = pixbuf; + for (y = 0; y < inheight; y++) + { + for (x = 0; x < inwidth; x++) + { + unsigned char r; + unsigned char g; + unsigned char b; + if (pixtype == RL2_PIXEL_RGB) + { + r = *p_in++; + g = *p_in++; + b = *p_in++; + } + else + { + r = *p_in++; + g = r; + b = r; + } + if (little_endian) + { + *p_out++ = b; + *p_out++ = g; + *p_out++ = r; + *p_out++ = 0xff; + } + else + { + *p_out++ = 0xff; + *p_out++ = r; + *p_out++ = g; + *p_out++ = b; + } + } + } + +/* creating the input pattern */ + bitmap = + cairo_image_surface_create_for_data (pixbuf, CAIRO_FORMAT_ARGB32, + inwidth, inheight, stride); + pattern = cairo_pattern_create_for_surface (bitmap); + cairo_pattern_set_extend (pattern, CAIRO_EXTEND_NONE); + +/* rescaling the image */ + cairo_save (cairo); + cairo_scale (cairo, scale_x, scale_y); + cairo_set_source (cairo, pattern); + cairo_paint (cairo); + cairo_restore (cairo); + cairo_surface_flush (surface); + +/* cleaning up the input pattern */ + cairo_pattern_destroy (pattern); + cairo_surface_destroy (bitmap); + free (pixbuf); + +/* exporting the rescaled image */ + p_in = cairo_image_surface_get_data (surface); + p_out = (unsigned char *) outbuf; + for (y = 0; y < outheight; y++) + { + for (x = 0; x < outwidth; x++) + { + unsigned char r; + unsigned char g; + unsigned char b; + unsigned char a; + if (little_endian) + { + b = *p_in++; + g = *p_in++; + r = *p_in++; + a = *p_in++; + } + else + { + a = *p_in++; + r = *p_in++; + g = *p_in++; + b = *p_in++; + } + if (pixtype == RL2_PIXEL_RGB) + { + *p_out++ = unpremultiply (r, a); + *p_out++ = unpremultiply (g, a); + *p_out++ = unpremultiply (b, a); + + } + else + *p_out++ = unpremultiply (r, a); + } + } + +/* destroying the Cairo context */ + cairo_destroy (cairo); + cairo_surface_destroy (surface); + return 1; + + error2: + if (pixbuf != NULL) + free (pixbuf); + cairo_destroy (cairo); + cairo_surface_destroy (surface); + return 0; + error1: + cairo_surface_destroy (surface); + return 0; +} RL2_DECLARE int rl2_graph_draw_graphic_symbol (rl2GraphicsContextPtr context, rl2GraphicsPatternPtr symbol, double width, double height, double x, @@ -3121,20 +3391,10 @@ cairo_surface_flush (surface); return 1; } -static unsigned char -unpremultiply (unsigned char c, unsigned char a) -{ -/* Cairo has premultiplied alphas */ - double x = ((double) c * 255.0) / (double) a; - if (a == 0) - return 0; - return (unsigned char) x; -} - RL2_DECLARE unsigned char * rl2_graph_get_context_rgb_array (rl2GraphicsContextPtr context) { /* creating an RGB buffer from the given Context */ int width; Index: src/rl2png.c ================================================================== --- src/rl2png.c +++ src/rl2png.c @@ -226,15 +226,15 @@ rl2_free (blue); return RL2_ERROR; } static int -compress_grayscale_png8 (const unsigned char *pixels, const unsigned char *mask, - double opacity, unsigned int width, - unsigned int height, unsigned char sample_type, - unsigned char pixel_type, unsigned char **png, - int *png_size) +compress_grayscale_png8 (const unsigned char *pixels, + const unsigned char *mask, double opacity, + unsigned int width, unsigned int height, + unsigned char sample_type, unsigned char pixel_type, + unsigned char **png, int *png_size) { /* compressing a PNG image of the GRAYSCALE type - 8 bits */ png_structp png_ptr; png_infop info_ptr; int bit_depth; @@ -1082,12 +1082,13 @@ return RL2_OK; } RL2_DECLARE int rl2_rgb_real_alpha_to_png (unsigned int width, unsigned int height, - const unsigned char *rgb, const unsigned char *alpha, - unsigned char **png, int *png_size) + const unsigned char *rgb, + const unsigned char *alpha, unsigned char **png, + int *png_size) { /* creating a PNG image from two distinct RGB + Alpha buffer */ unsigned char *blob; int blob_size; if (rgb == NULL || alpha == NULL) @@ -1173,13 +1174,13 @@ ret = compress_grayscale_png16 (pixels, width, height, sample_type, &blob, &blob_size); else ret = - compress_grayscale_png8 (pixels, mask, opacity, width, height, - sample_type, pixel_type, &blob, - &blob_size); + compress_grayscale_png8 (pixels, mask, opacity, width, + height, sample_type, pixel_type, + &blob, &blob_size); break; case RL2_PIXEL_RGB: if (sample_type == RL2_SAMPLE_UINT8) ret = compress_rgb_png8 (pixels, mask, opacity, width, height, @@ -1191,12 +1192,12 @@ case RL2_PIXEL_MULTIBAND: if (sample_type == RL2_SAMPLE_UINT8) { if (num_bands == 3) ret = - compress_rgb_png8 (pixels, mask, opacity, width, height, - &blob, &blob_size); + compress_rgb_png8 (pixels, mask, opacity, width, + height, &blob, &blob_size); else if (num_bands == 4) ret = compress_4bands_png8 (pixels, width, height, &blob, &blob_size); } @@ -1413,12 +1414,13 @@ } if (*xpixel_type == RL2_PIXEL_DATAGRID) pixel_type = RL2_PIXEL_DATAGRID; if (pixel_type == RL2_PIXEL_PALETTE) { - if (png_get_tRNS (png_ptr, info_ptr, &transp, &nTransp, &transpValues) - == PNG_INFO_tRNS) + if (png_get_tRNS + (png_ptr, info_ptr, &transp, &nTransp, + &transpValues) == PNG_INFO_tRNS) { /* a Transparency palette is defined */ int i; for (i = 0; i < nTransp; i++) *(alpha + i) = *(transp + i); Index: src/rl2pyramid.c ================================================================== --- src/rl2pyramid.c +++ src/rl2pyramid.c @@ -257,12 +257,12 @@ table = sqlite3_mprintf ("%s_tiles", coverage); xtable = rl2_double_quoted_sql (table); sqlite3_free (table); sql = sqlite3_mprintf ("SELECT Count(*) FROM \"%s\" " - "WHERE section_id = %s AND pyramid_level > 0", xtable, - sect_id); + "WHERE section_id = %s AND pyramid_level > 0", + xtable, sect_id); free (xtable); ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL); sqlite3_free (sql); if (ret != SQLITE_OK) return 1; @@ -349,12 +349,13 @@ stmt = NULL; if (!ok) goto error; /* Coverage's palette and no-data */ - sql = sqlite3_mprintf ("SELECT palette, nodata_pixel FROM raster_coverages " - "WHERE Lower(coverage_name) = Lower(%Q)", coverage); + sql = + sqlite3_mprintf ("SELECT palette, nodata_pixel FROM raster_coverages " + "WHERE Lower(coverage_name) = Lower(%Q)", coverage); ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL); sqlite3_free (sql); if (ret != SQLITE_OK) { fprintf (stderr, "SQL error: %s\n%s\n", sql, sqlite3_errmsg (handle)); @@ -489,13 +490,13 @@ } free (pyr); } static int -insert_tile_into_section_pyramid (SectionPyramidPtr pyr, sqlite3_int64 tile_id, - double minx, double miny, double maxx, - double maxy) +insert_tile_into_section_pyramid (SectionPyramidPtr pyr, + sqlite3_int64 tile_id, double minx, + double miny, double maxx, double maxy) { /* inserting a base tile into the Pyramid level */ SectionPyramidTileInPtr tile; if (pyr == NULL) return 0; @@ -574,12 +575,12 @@ && tile->cy < maxy) { if (first) { out = - add_pyramid_out_tile (pyr, row, col, minx, miny, maxx, - maxy); + add_pyramid_out_tile (pyr, row, col, minx, miny, + maxx, maxy); first = 0; } if (out != NULL) add_pyramid_sub_tile (out, tile); } @@ -765,12 +766,12 @@ unsigned int xx = col + x; char *p_out = p_out_base + xx; if (xx >= tileWidth) break; *p_out = - rescale_pixel_int8 (buf_in, tileWidth, tileHeight, col * 8, - row * 8, nd); + rescale_pixel_int8 (buf_in, tileWidth, tileHeight, + col * 8, row * 8, nd); } } } static double @@ -845,12 +846,12 @@ unsigned int xx = col + x; unsigned char *p_out = p_out_base + xx; if (xx >= tileWidth) break; *p_out = - rescale_pixel_uint8 (buf_in, tileWidth, tileHeight, col * 8, - row * 8, nd); + rescale_pixel_uint8 (buf_in, tileWidth, tileHeight, + col * 8, row * 8, nd); } } } static double @@ -925,12 +926,12 @@ unsigned int xx = col + x; short *p_out = p_out_base + xx; if (xx >= tileWidth) break; *p_out = - rescale_pixel_int16 (buf_in, tileWidth, tileHeight, col * 8, - row * 8, nd); + rescale_pixel_int16 (buf_in, tileWidth, tileHeight, + col * 8, row * 8, nd); } } } static double @@ -1085,12 +1086,12 @@ unsigned int xx = col + x; int *p_out = p_out_base + xx; if (xx >= tileWidth) break; *p_out = - rescale_pixel_int32 (buf_in, tileWidth, tileHeight, col * 8, - row * 8, nd); + rescale_pixel_int32 (buf_in, tileWidth, tileHeight, + col * 8, row * 8, nd); } } } static double @@ -1245,12 +1246,12 @@ unsigned int xx = col + x; float *p_out = p_out_base + xx; if (xx >= tileWidth) break; *p_out = - rescale_pixel_float (buf_in, tileWidth, tileHeight, col * 8, - row * 8, nd); + rescale_pixel_float (buf_in, tileWidth, tileHeight, + col * 8, row * 8, nd); } } } static double @@ -1346,13 +1347,13 @@ rescale_grid_int8 ((char *) buf_out, tileWidth, tileHeight, (const char *) buf_in, x, y, tic_x, tic_y, no_data); break; case RL2_SAMPLE_UINT8: - rescale_grid_uint8 ((unsigned char *) buf_out, tileWidth, tileHeight, - (const unsigned char *) buf_in, x, y, tic_x, - tic_y, no_data); + rescale_grid_uint8 ((unsigned char *) buf_out, tileWidth, + tileHeight, (const unsigned char *) buf_in, x, + y, tic_x, tic_y, no_data); break; case RL2_SAMPLE_INT16: rescale_grid_int16 ((short *) buf_out, tileWidth, tileHeight, (const short *) buf_in, x, y, tic_x, tic_y, no_data); @@ -1366,13 +1367,13 @@ rescale_grid_int32 ((int *) buf_out, tileWidth, tileHeight, (const int *) buf_in, x, y, tic_x, tic_y, no_data); break; case RL2_SAMPLE_UINT32: - rescale_grid_uint32 ((unsigned int *) buf_out, tileWidth, tileHeight, - (const unsigned int *) buf_in, x, y, tic_x, - tic_y, no_data); + rescale_grid_uint32 ((unsigned int *) buf_out, tileWidth, + tileHeight, (const unsigned int *) buf_in, x, + y, tic_x, tic_y, no_data); break; case RL2_SAMPLE_FLOAT: rescale_grid_float ((float *) buf_out, tileWidth, tileHeight, (const float *) buf_in, x, y, tic_x, tic_y, no_data); @@ -1517,12 +1518,13 @@ pos_x += geo_x; } pos_y -= geo_y; } rst = (rl2PrivRasterPtr) raster_in; - rescale_grid (buf_out, tileWidth, tileHeight, rst->rasterBuffer, - sample_type, x, y, tic_x, tic_y, no_data); + rescale_grid (buf_out, tileWidth, tileHeight, + rst->rasterBuffer, sample_type, x, y, tic_x, + tic_y, no_data); rl2_destroy_raster (raster_in); raster_in = NULL; tile_in = tile_in->next; } @@ -1548,13 +1550,14 @@ rl2_destroy_raster (raster_out); raster_out = NULL; /* INSERTing the tile */ if (!do_insert_pyramid_tile - (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz, id_level, - pyr->section_id, pyr->srid, tile_out->minx, tile_out->miny, - tile_out->maxx, tile_out->maxy, stmt_tils, stmt_data)) + (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz, + id_level, pyr->section_id, pyr->srid, tile_out->minx, + tile_out->miny, tile_out->maxx, tile_out->maxy, stmt_tils, + stmt_data)) goto error; tile_out = tile_out->next; } @@ -1572,12 +1575,12 @@ return 0; } static double rescale_mb_pixel_uint8 (const unsigned char *buf_in, unsigned int tileWidth, - unsigned int tileHeight, unsigned int x, unsigned int y, - unsigned char nd, unsigned char nb, + unsigned int tileHeight, unsigned int x, + unsigned int y, unsigned char nd, unsigned char nb, unsigned char num_bands) { /* rescaling a MultiBand pixel sample (8x8) - UINT8 */ unsigned int row; unsigned int col; @@ -1650,13 +1653,13 @@ rl2PrivSamplePtr sample = pxl->Samples + nb; nd = sample->uint8; } } *(p_out + nb) = - rescale_mb_pixel_uint8 (buf_in, tileWidth, tileHeight, - col * 8, row * 8, nd, nb, - num_bands); + rescale_mb_pixel_uint8 (buf_in, tileWidth, + tileHeight, col * 8, + row * 8, nd, nb, num_bands); } } } } @@ -1740,12 +1743,12 @@ nd = sample->uint16; } } *(p_out + nb) = rescale_mb_pixel_uint16 (buf_in, tileWidth, - tileHeight, col * 8, row * 8, - nd, nb, num_bands); + tileHeight, col * 8, + row * 8, nd, nb, num_bands); } } } } @@ -1764,12 +1767,13 @@ tileHeight, (const unsigned char *) buf_in, x, y, tic_x, tic_y, num_bands, no_data); break; case RL2_SAMPLE_UINT16: rescale_multiband_uint16 ((unsigned short *) buf_out, tileWidth, - tileHeight, (const unsigned short *) buf_in, - x, y, tic_x, tic_y, num_bands, no_data); + tileHeight, + (const unsigned short *) buf_in, x, y, + tic_x, tic_y, num_bands, no_data); break; }; } static int @@ -1898,12 +1902,12 @@ } pos_y -= geo_y; } rst = (rl2PrivRasterPtr) raster_in; rescale_multiband (buf_out, tileWidth, tileHeight, - rst->rasterBuffer, sample_type, num_bands, x, - y, tic_x, tic_y, no_data); + rst->rasterBuffer, sample_type, num_bands, + x, y, tic_x, tic_y, no_data); rl2_destroy_raster (raster_in); raster_in = NULL; tile_in = tile_in->next; } @@ -1929,13 +1933,14 @@ rl2_destroy_raster (raster_out); raster_out = NULL; /* INSERTing the tile */ if (!do_insert_pyramid_tile - (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz, id_level, - pyr->section_id, pyr->srid, tile_out->minx, tile_out->miny, - tile_out->maxx, tile_out->maxy, stmt_tils, stmt_data)) + (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz, + id_level, pyr->section_id, pyr->srid, tile_out->minx, + tile_out->miny, tile_out->maxx, tile_out->maxy, stmt_tils, + stmt_data)) goto error; tile_out = tile_out->next; } @@ -2120,24 +2125,24 @@ compression = RL2_COMPRESSION_PNG; } else nd = rl2_clone_pixel (no_data); raster = - rl2_create_raster (tileWidth, tileHeight, RL2_SAMPLE_UINT8, - RL2_PIXEL_GRAYSCALE, 1, gray, - tileWidth * tileHeight, NULL, alpha, - tileWidth * tileHeight, nd); + rl2_create_raster (tileWidth, tileHeight, + RL2_SAMPLE_UINT8, RL2_PIXEL_GRAYSCALE, + 1, gray, tileWidth * tileHeight, NULL, + alpha, tileWidth * tileHeight, nd); } else if (pyr->pixel_type == RL2_PIXEL_RGB) { /* RGB Pyramid */ nd = rl2_clone_pixel (no_data); raster = - rl2_create_raster (tileWidth, tileHeight, RL2_SAMPLE_UINT8, - RL2_PIXEL_RGB, 3, rgb, - tileWidth * tileHeight * 3, NULL, alpha, - tileWidth * tileHeight, nd); + rl2_create_raster (tileWidth, tileHeight, + RL2_SAMPLE_UINT8, RL2_PIXEL_RGB, 3, + rgb, tileWidth * tileHeight * 3, NULL, + alpha, tileWidth * tileHeight, nd); } if (raster == NULL) { fprintf (stderr, "ERROR: unable to create a Pyramid Tile\n"); goto error; @@ -2154,13 +2159,14 @@ rl2_graph_destroy_context (ctx); ctx = NULL; /* INSERTing the tile */ if (!do_insert_pyramid_tile - (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz, id_level, - pyr->section_id, pyr->srid, tile_out->minx, tile_out->miny, - tile_out->maxx, tile_out->maxy, stmt_tils, stmt_data)) + (handle, blob_odd, blob_odd_sz, blob_even, blob_even_sz, + id_level, pyr->section_id, pyr->srid, tile_out->minx, + tile_out->miny, tile_out->maxx, tile_out->maxy, stmt_tils, + stmt_data)) goto error; tile_out = tile_out->next; } @@ -2342,13 +2348,13 @@ } #define floor2(exp) ((long) exp) static rl2RasterPtr -create_124_rescaled_raster (const unsigned char *rgba, unsigned char pixel_type, - unsigned int tileWidth, unsigned int tileHeight, - int scale) +create_124_rescaled_raster (const unsigned char *rgba, + unsigned char pixel_type, unsigned int tileWidth, + unsigned int tileHeight, int scale) { /* creating a rescaled raster (1,2 or 4 bit pyramids) / / this function builds an high quality rescaled sub-image by applying pixel interpolation / @@ -2531,12 +2537,13 @@ } } } raster = - rl2_create_raster (out_width, out_height, RL2_SAMPLE_UINT8, pixel_type, - num_bands, rgb, rgb_sz, NULL, mask, mask_sz, NULL); + rl2_create_raster (out_width, out_height, RL2_SAMPLE_UINT8, + pixel_type, num_bands, rgb, rgb_sz, NULL, mask, + mask_sz, NULL); return raster; } static void copy_124_rescaled (rl2RasterPtr raster_out, rl2RasterPtr raster_in, @@ -2742,12 +2749,12 @@ rgba = load_tile_base (stmt_data, tile_id, palette, no_data); if (rgba == NULL) goto error; base_tile = - create_124_rescaled_raster (rgba, out_pixel_type, tileWidth, - tileHeight, factor); + create_124_rescaled_raster (rgba, out_pixel_type, + tileWidth, tileHeight, factor); free (rgba); if (base_tile == NULL) goto error; shift_x = tile_x - minx; shift_y = maxy - tile_y; @@ -3117,12 +3124,13 @@ free (sum); *p_msk = 1; } static void -mb_prime_nodata_u8 (unsigned char *buf, unsigned int width, unsigned int height, - unsigned char num_bands, rl2PixelPtr no_data) +mb_prime_nodata_u8 (unsigned char *buf, unsigned int width, + unsigned int height, unsigned char num_bands, + rl2PixelPtr no_data) { /* priming a void buffer */ rl2PrivPixelPtr nd = (rl2PrivPixelPtr) no_data; unsigned int x; unsigned int y; @@ -3246,13 +3254,13 @@ ox, oy, no_data); break; case RL2_SAMPLE_UINT16: rescale_multiband_u16 (tileWidth, tileHeight, num_bands, out_width, out_height, factor, - (unsigned short *) buf_in, mask_in, - (unsigned short *) buf, mask, x, y, - ox, oy, no_data); + (unsigned short *) buf_in, + mask_in, (unsigned short *) buf, + mask, x, y, ox, oy, no_data); break; }; ox++; } oy++; @@ -4038,20 +4046,20 @@ (unsigned char *) buf, mask, x, y, ox, oy, no_data_u8); break; case RL2_SAMPLE_INT16: rescale_datagrid_16 (tileWidth, tileHeight, out_width, - out_height, factor, (short *) buf_in, - (short *) buf, mask, x, y, ox, oy, - no_data_16); + out_height, factor, + (short *) buf_in, (short *) buf, + mask, x, y, ox, oy, no_data_16); break; case RL2_SAMPLE_UINT16: rescale_datagrid_u16 (tileWidth, tileHeight, out_width, out_height, factor, (unsigned short *) buf_in, - (unsigned short *) buf, mask, x, y, - ox, oy, no_data_u16); + (unsigned short *) buf, mask, x, + y, ox, oy, no_data_u16); break; case RL2_SAMPLE_INT32: rescale_datagrid_32 (tileWidth, tileHeight, out_width, out_height, factor, (int *) buf_in, (int *) buf, mask, x, y, ox, oy, @@ -4091,14 +4099,15 @@ static int rescale_monolithic_multiband (int id_level, unsigned int tileWidth, unsigned int tileHeight, unsigned char sample_type, - unsigned char num_bands, int factor, double res_x, - double res_y, double minx, double miny, - double maxx, double maxy, unsigned char *buffer, - int buf_size, unsigned char *mask, int *mask_size, + unsigned char num_bands, int factor, + double res_x, double res_y, double minx, + double miny, double maxx, double maxy, + unsigned char *buffer, int buf_size, + unsigned char *mask, int *mask_size, rl2PixelPtr no_data, sqlite3_stmt * stmt_geo, sqlite3_stmt * stmt_data) { /* rescaling monolithic MultiBand */ rl2RasterPtr raster = NULL; @@ -4120,12 +4129,12 @@ { /* priming full transparency */ for (x = 0; x < tileWidth; x++) *p_out++ = 0; } - rl2_prime_void_tile (buffer, tileWidth, tileHeight, sample_type, num_bands, - no_data); + rl2_prime_void_tile (buffer, tileWidth, tileHeight, sample_type, + num_bands, no_data); /* creating the output raster */ raster = rl2_create_raster (tileWidth, tileHeight, sample_type, RL2_PIXEL_MULTIBAND, num_bands, buffer, buf_size, NULL, mask, *mask_size, nd); @@ -4331,11 +4340,12 @@ return 0; } static int prepare_section_pyramid_stmts (sqlite3 * handle, const char *coverage, - int mixed_resolutions, sqlite3_stmt ** xstmt_rd, + int mixed_resolutions, + sqlite3_stmt ** xstmt_rd, sqlite3_stmt ** xstmt_levl, sqlite3_stmt ** xstmt_tils, sqlite3_stmt ** xstmt_data) { /* preparing the section pyramid related SQL statements */ @@ -4502,12 +4512,12 @@ (handle, coverage, section_id, §_width, §_height, &minx, &miny, &maxx, &maxy, &palette, &no_data)) goto error; if (!prepare_section_pyramid_stmts - (handle, coverage, mixed_resolutions, &stmt_rd, &stmt_levl, &stmt_tils, - &stmt_data)) + (handle, coverage, mixed_resolutions, &stmt_rd, &stmt_levl, + &stmt_tils, &stmt_data)) goto error; while (1) { /* looping on pyramid levels */ @@ -4582,17 +4592,18 @@ { pyr = alloc_sect_pyramid (section_id, sect_width, sect_height, sample_type, pixel_type, num_samples, - compression, quality, srid, - new_res_x, new_res_y, + compression, quality, + srid, new_res_x, + new_res_y, (double) tileWidth * new_res_x, (double) tileHeight * - new_res_y, minx, miny, maxx, - maxy, scale); + new_res_y, minx, miny, + maxx, maxy, scale); first = 0; if (pyr == NULL) goto error; } if (!insert_tile_into_section_pyramid @@ -4614,14 +4625,18 @@ out_maxy = maxy; for (row = 0; row < pyr->scaled_height; row += tileHeight) { out_miny = out_maxy - pyr->tile_height; + if (out_miny < miny) + out_miny = miny; out_minx = minx; for (col = 0; col < pyr->scaled_width; col += tileWidth) { out_maxx = out_minx + pyr->tile_width; + if (out_maxx > maxx) + out_maxx = maxx; set_pyramid_tile_destination (pyr, out_minx, out_miny, out_maxx, out_maxy, row, col); out_minx += pyr->tile_width; } @@ -4956,12 +4971,13 @@ static int get_section_raw_raster_data (sqlite3 * handle, int max_threads, const char *coverage, sqlite3_int64 sect_id, unsigned int width, unsigned int height, unsigned char sample_type, - unsigned char pixel_type, unsigned char num_bands, - double minx, double maxy, double x_res, + unsigned char pixel_type, + unsigned char num_bands, double minx, double miny, + double maxx, double maxy, double x_res, double y_res, unsigned char **buffer, int *buf_size, rl2PalettePtr palette, rl2PixelPtr no_data) { /* attempting to return a buffer containing raw pixels from the whole DBMS Section */ @@ -5004,11 +5020,14 @@ xtiles = sqlite3_mprintf ("%s_tiles", coverage); xxtiles = rl2_double_quoted_sql (xtiles); sql = sqlite3_mprintf ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) " "FROM \"%s\" " - "WHERE pyramid_level = 0 AND section_id = ?", xxtiles); + "WHERE section_id = ? AND pyramid_level = ? AND ROWID IN ( " + "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q " + "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles, + xtiles); sqlite3_free (xtiles); free (xxtiles); ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_tiles, NULL); sqlite3_free (sql); if (ret != SQLITE_OK) @@ -5040,12 +5059,12 @@ else void_raw_buffer (bufpix, width, height, sample_type, num_bands, no_data); if (!rl2_load_dbms_tiles_section (handle, max_threads, sect_id, stmt_tiles, stmt_data, bufpix, width, - height, sample_type, num_bands, 0, 0, 0, x_res, y_res, minx, maxy, - RL2_SCALE_1, palette, no_data)) + height, sample_type, num_bands, 0, 0, 0, x_res, y_res, minx, miny, + maxx, maxy, 0, RL2_SCALE_1, palette, no_data)) goto error; sqlite3_finalize (stmt_tiles); sqlite3_finalize (stmt_data); *buffer = bufpix; *buf_size = bufpix_size; @@ -5061,11 +5080,12 @@ return 0; } static void raster_tile_124_rescaled (unsigned char *outbuf, - unsigned char pixel_type, const unsigned char *inbuf, + unsigned char pixel_type, + const unsigned char *inbuf, unsigned int section_width, unsigned int section_height, unsigned int out_width, unsigned int out_height, rl2PalettePtr palette) { /* @@ -5359,12 +5379,13 @@ sqlite3_int64 section_id, unsigned char sample_type, unsigned char pixel_type, unsigned char num_samples, int srid, unsigned int tileWidth, - unsigned int tileHeight, unsigned char bgRed, - unsigned char bgGreen, unsigned char bgBlue) + unsigned int tileHeight, + unsigned char bgRed, unsigned char bgGreen, + unsigned char bgBlue) { /* attempting to (re)build a 1,2,4-bit section pyramid from scratch */ double base_res_x; double base_res_y; unsigned int sect_width; @@ -5422,17 +5443,17 @@ (handle, coverage, &base_res_x, &base_res_y)) goto error; } if (!get_section_raw_raster_data (handle, max_threads, coverage, section_id, sect_width, sect_height, - sample_type, pixel_type, num_samples, minx, maxy, base_res_x, - base_res_y, &inbuf, &inbuf_size, palette, no_data)) + sample_type, pixel_type, num_samples, minx, miny, maxx, maxy, + base_res_x, base_res_y, &inbuf, &inbuf_size, palette, no_data)) goto error; if (!prepare_section_pyramid_stmts - (handle, coverage, mixed_resolutions, &stmt_rd, &stmt_levl, &stmt_tils, - &stmt_data)) + (handle, coverage, mixed_resolutions, &stmt_rd, &stmt_levl, + &stmt_tils, &stmt_data)) goto error; id_level = 1; scale = 2; x_res = base_res_x * 2.0; @@ -5504,10 +5525,12 @@ for (row = 0; row < out_height; row += tileHeight) { t_minx = minx; t_miny = t_maxy - (tileHeight * y_res); + if (t_miny < miny) + t_miny = miny; for (col = 0; col < out_width; col += tileWidth) { if (pixel_type == RL2_PIXEL_MONOCHROME) { if (no_data == NULL) @@ -5530,20 +5553,24 @@ else { /* converting the NO-DATA pixel */ nd = rl2_create_pixel (RL2_SAMPLE_UINT8, RL2_PIXEL_RGB, 3); - rl2_set_pixel_sample_uint8 (nd, RL2_RED_BAND, + rl2_set_pixel_sample_uint8 (nd, + RL2_RED_BAND, bgRed); rl2_set_pixel_sample_uint8 (nd, RL2_GREEN_BAND, bgGreen); - rl2_set_pixel_sample_uint8 (nd, RL2_BLUE_BAND, + rl2_set_pixel_sample_uint8 (nd, + RL2_BLUE_BAND, bgBlue); } } t_maxx = t_minx + (tileWidth * x_res); + if (t_maxx > maxx) + t_maxx = maxx; if (!copy_124_tile (out_pixel_type, outbuf, &tilebuf, &tilebuf_sz, &tilemask, &tilemask_sz, row, col, out_width, out_height, tileWidth, tileHeight, no_data)) @@ -5565,12 +5592,13 @@ fprintf (stderr, "ERROR: unable to create a Pyramid Tile\n"); goto error; } if (rl2_raster_encode - (raster, RL2_COMPRESSION_PNG, &blob_odd, &blob_odd_sz, - &blob_even, &blob_even_sz, 100, 1) != RL2_OK) + (raster, RL2_COMPRESSION_PNG, &blob_odd, + &blob_odd_sz, &blob_even, &blob_even_sz, 100, + 1) != RL2_OK) { fprintf (stderr, "ERROR: unable to encode a Pyramid tile\n"); goto error; } @@ -5636,12 +5664,13 @@ static int do_build_palette_section_pyramid (sqlite3 * handle, int max_threads, const char *coverage, int mixed_resolutions, sqlite3_int64 section_id, int srid, unsigned int tileWidth, - unsigned int tileHeight, unsigned char bgRed, - unsigned char bgGreen, unsigned char bgBlue) + unsigned int tileHeight, + unsigned char bgRed, unsigned char bgGreen, + unsigned char bgBlue) { /* attempting to (re)build a Palette section pyramid from scratch */ double base_res_x; double base_res_y; unsigned int sect_width; @@ -5701,17 +5730,17 @@ (handle, coverage, &base_res_x, &base_res_y)) goto error; } if (!get_section_raw_raster_data (handle, max_threads, coverage, section_id, sect_width, sect_height, - RL2_SAMPLE_UINT8, RL2_PIXEL_PALETTE, 1, minx, maxy, base_res_x, - base_res_y, &inbuf, &inbuf_size, palette, no_data)) + RL2_SAMPLE_UINT8, RL2_PIXEL_PALETTE, 1, minx, miny, maxx, maxy, + base_res_x, base_res_y, &inbuf, &inbuf_size, palette, no_data)) goto error; if (!prepare_section_pyramid_stmts - (handle, coverage, mixed_resolutions, &stmt_rd, &stmt_levl, &stmt_tils, - &stmt_data)) + (handle, coverage, mixed_resolutions, &stmt_rd, &stmt_levl, + &stmt_tils, &stmt_data)) goto error; id_level = 1; scale = 2; x_res = base_res_x * 2.0; @@ -5763,10 +5792,12 @@ for (row = 0; row < out_height; row += tileHeight) { t_minx = minx; t_miny = t_maxy - (tileHeight * y_res); + if (t_miny < miny) + t_miny = miny; for (col = 0; col < out_width; col += tileWidth) { if (no_data == NULL) nd = NULL; else @@ -5781,14 +5812,17 @@ bgGreen); rl2_set_pixel_sample_uint8 (nd, RL2_BLUE_BAND, bgBlue); } t_maxx = t_minx + (tileWidth * x_res); + if (t_maxx > maxx) + t_maxx = maxx; if (!copy_124_tile (out_pixel_type, outbuf, &tilebuf, - &tilebuf_sz, &tilemask, &tilemask_sz, - row, col, out_width, out_height, - tileWidth, tileHeight, no_data)) + &tilebuf_sz, &tilemask, + &tilemask_sz, row, col, out_width, + out_height, tileWidth, tileHeight, + no_data)) { fprintf (stderr, "ERROR: unable to extract a Pyramid Tile\n"); goto error; } @@ -6051,12 +6085,12 @@ else { /* ordinary RGB, Grayscale, MultiBand or DataGrid Pyramid */ if (!do_build_section_pyramid (handle, coverage, section_id, sample_type, pixel_type, - num_bands, compression, ptrcvg->mixedResolutions, quality, - srid, tileWidth, tileHeight)) + num_bands, compression, ptrcvg->mixedResolutions, + quality, srid, tileWidth, tileHeight)) goto error; } if (verbose) { printf (" ----------\n"); @@ -6109,12 +6143,12 @@ break; if (ret == SQLITE_ROW) { sqlite3_int64 section_id = sqlite3_column_int64 (stmt, 0); if (rl2_build_section_pyramid - (handle, max_threads, coverage, section_id, forced_rebuild, - verbose) != RL2_OK) + (handle, max_threads, coverage, section_id, + forced_rebuild, verbose) != RL2_OK) goto error; } else { fprintf (stderr, @@ -6283,12 +6317,12 @@ out_num_bands = 3; out_compression = RL2_COMPRESSION_PNG; out_quality = 100; virt_levels = 1; } - else if (sample_type == RL2_SAMPLE_UINT8 && pixel_type == RL2_PIXEL_PALETTE - && num_bands == 1) + else if (sample_type == RL2_SAMPLE_UINT8 + && pixel_type == RL2_PIXEL_PALETTE && num_bands == 1) { /* palette 8: output colorspace is RGB compression PNG */ out_sample_type = RL2_SAMPLE_UINT8; out_pixel_type = RL2_PIXEL_RGB; out_num_bands = 3; @@ -6405,22 +6439,23 @@ if ((sample_type == RL2_SAMPLE_UINT8 && pixel_type == RL2_PIXEL_GRAYSCALE && num_bands == 1) || (sample_type == RL2_SAMPLE_UINT8 - && pixel_type == RL2_PIXEL_RGB && num_bands == 3) + && pixel_type == RL2_PIXEL_RGB + && num_bands == 3) || (sample_type == RL2_SAMPLE_UINT8 && pixel_type == RL2_PIXEL_PALETTE && num_bands == 1)) { /* RGB, PALETTE or GRAYSCALE datasource (UINT8) */ if (!rescale_monolithic_rgba - (id_level, tileWidth, tileHeight, resize_factor, - res_x, res_y, tile_minx, tile_miny, - tile_maxx, tile_maxy, buffer, buf_size, mask, - &mask_size, palette, no_data, stmt_geo, - stmt_rd)) + (id_level, tileWidth, tileHeight, + resize_factor, res_x, res_y, tile_minx, + tile_miny, tile_maxx, tile_maxy, buffer, + buf_size, mask, &mask_size, palette, no_data, + stmt_geo, stmt_rd)) goto error; if (mask_size == 0) mask = NULL; } else if (((sample_type == RL2_SAMPLE_1_BIT @@ -6462,12 +6497,12 @@ /* DataGrid */ if (!rescale_monolithic_datagrid (id_level, tileWidth, tileHeight, sample_type, resize_factor, res_x, res_y, tile_minx, tile_miny, tile_maxx, tile_maxy, buffer, - buf_size, mask, &mask_size, no_data, stmt_geo, - stmt_rd)) + buf_size, mask, &mask_size, no_data, + stmt_geo, stmt_rd)) goto error; if (mask_size == 0) mask = NULL; } else @@ -6515,16 +6550,18 @@ nd = NULL; else { nd = rl2_create_pixel (RL2_SAMPLE_UINT8, RL2_PIXEL_RGB, 3); - rl2_set_pixel_sample_uint8 (nd, RL2_RED_BAND, + rl2_set_pixel_sample_uint8 (nd, + RL2_RED_BAND, 255); rl2_set_pixel_sample_uint8 (nd, RL2_GREEN_BAND, 255); - rl2_set_pixel_sample_uint8 (nd, RL2_BLUE_BAND, + rl2_set_pixel_sample_uint8 (nd, + RL2_BLUE_BAND, 255); } } else nd = rl2_clone_pixel (no_data); @@ -6608,12 +6645,13 @@ sqlite3_finalize (stmt_tils); sqlite3_finalize (stmt_data); if (verbose) { printf (" ----------\n"); - printf (" Monolithic Pyramid levels successfully built for: %s\n", - coverage); + printf + (" Monolithic Pyramid levels successfully built for: %s\n", + coverage); } free (buffer); free (mask); rl2_destroy_coverage (cvg); Index: src/rl2rastersym.c ================================================================== --- src/rl2rastersym.c +++ src/rl2rastersym.c @@ -692,11 +692,12 @@ } else { /* opaque pixel */ p_out = - mono_int8_pixel_handler (p_in, p_out, mono_band, + mono_int8_pixel_handler (p_in, p_out, + mono_band, mono_handling); } } else { @@ -709,11 +710,12 @@ match++; if (match != 1) { /* opaque pixel */ p_out = - mono_int8_pixel_handler (p_in, p_out, mono_band, + mono_int8_pixel_handler (p_in, p_out, + mono_band, mono_handling); } else { /* NO-DATA pixel */ @@ -731,11 +733,11 @@ unsigned char *outbuf, unsigned short width, unsigned short height, unsigned char num_bands, double x_res, double y_res, double minx, double maxy, double tile_minx, double tile_maxy, unsigned short tile_width, unsigned short tile_height, - rl2PixelPtr no_data) + rl2PixelPtr no_data, unsigned char raster_type) { /* copying UINT8 raw pixels from the DBMS tile into the output image */ int x; int y; int b; @@ -760,18 +762,18 @@ if (rl2_get_pixel_type (no_data, &sample_type, &pixel_type, &nbands) != RL2_OK) ignore_no_data = 1; if (nbands != num_bands) ignore_no_data = 1; - if (sample_type == RL2_SAMPLE_1_BIT || sample_type == RL2_SAMPLE_2_BIT + if (sample_type == RL2_SAMPLE_1_BIT + || sample_type == RL2_SAMPLE_2_BIT || sample_type == RL2_SAMPLE_4_BIT || sample_type == RL2_SAMPLE_UINT8) ; else ignore_no_data = 1; } - geo_y = tile_maxy + y_res2; for (y = 0; y < tile_height; y++) { geo_y -= y_res; out_y = (maxy - geo_y) / y_res; @@ -820,44 +822,59 @@ else { /* testing for NO-DATA values */ int match = 0; const unsigned char *p_save = p_in; - for (b = 0; b < num_bands; b++) + if (raster_type == RL2_SAMPLE_1_BIT && num_bands == 1) { - unsigned char sample = 0; - switch (sample_type) - { - case RL2_SAMPLE_1_BIT: - rl2_get_pixel_sample_1bit (no_data, &sample); - break; - case RL2_SAMPLE_2_BIT: - rl2_get_pixel_sample_2bit (no_data, &sample); - break; - case RL2_SAMPLE_4_BIT: - rl2_get_pixel_sample_4bit (no_data, &sample); - break; - case RL2_SAMPLE_UINT8: - rl2_get_pixel_sample_uint8 (no_data, b, - &sample); - break; - }; - if (sample == *p_in++) - match++; + /* special case: MONOCHROME */ + if (*p_in++ == 1) + *p_out++ = 0; + else + p_out++; + match++; } - if (match != num_bands) + else { - /* opaque pixel */ - p_in = p_save; for (b = 0; b < num_bands; b++) - *p_out++ = *p_in++; - } - else - { - /* NO-DATA pixel */ - for (b = 0; b < num_bands; b++) - p_out++; + { + unsigned char sample = 0; + switch (sample_type) + { + case RL2_SAMPLE_1_BIT: + rl2_get_pixel_sample_1bit (no_data, + &sample); + break; + case RL2_SAMPLE_2_BIT: + rl2_get_pixel_sample_2bit (no_data, + &sample); + break; + case RL2_SAMPLE_4_BIT: + rl2_get_pixel_sample_4bit (no_data, + &sample); + break; + case RL2_SAMPLE_UINT8: + rl2_get_pixel_sample_uint8 (no_data, b, + &sample); + break; + }; + if (sample == *p_in++) + match++; + } + if (match != num_bands) + { + /* opaque pixel */ + p_in = p_save; + for (b = 0; b < num_bands; b++) + *p_out++ = *p_in++; + } + else + { + /* NO-DATA pixel */ + for (b = 0; b < num_bands; b++) + p_out++; + } } } } } } @@ -879,16 +896,17 @@ static void copy_uint8_raw_selected_pixels (const unsigned char *buffer, const unsigned char *mask, unsigned char *outbuf, unsigned short width, - unsigned short height, unsigned char num_bands, - double x_res, double y_res, double minx, - double maxy, double tile_minx, double tile_maxy, + unsigned short height, + unsigned char num_bands, double x_res, + double y_res, double minx, double maxy, + double tile_minx, double tile_maxy, unsigned short tile_width, - unsigned short tile_height, rl2PixelPtr no_data, - unsigned char red_band, + unsigned short tile_height, + rl2PixelPtr no_data, unsigned char red_band, unsigned char green_band, unsigned char blue_band, rl2BandHandlingPtr red_handling, rl2BandHandlingPtr green_handling, rl2BandHandlingPtr blue_handling) @@ -967,11 +985,12 @@ } else { /* opaque pixel */ p_out = - mono_uint8_pixel_handler (p_in, p_out, red_band, + mono_uint8_pixel_handler (p_in, p_out, + red_band, red_handling); p_out = mono_uint8_pixel_handler (p_in, p_out, green_band, green_handling); @@ -995,11 +1014,12 @@ } if (match != num_bands) { /* opaque pixel */ p_out = - mono_uint8_pixel_handler (p_in, p_out, red_band, + mono_uint8_pixel_handler (p_in, p_out, + red_band, red_handling); p_out = mono_uint8_pixel_handler (p_in, p_out, green_band, green_handling); @@ -1022,13 +1042,14 @@ static void copy_uint8_raw_mono_pixels (const unsigned char *buffer, const unsigned char *mask, unsigned char *outbuf, unsigned short width, unsigned short height, unsigned char out_num_bands, - unsigned char num_bands, double x_res, double y_res, - double minx, double maxy, double tile_minx, - double tile_maxy, unsigned short tile_width, + unsigned char num_bands, double x_res, + double y_res, double minx, double maxy, + double tile_minx, double tile_maxy, + unsigned short tile_width, unsigned short tile_height, rl2PixelPtr no_data, unsigned char mono_band, rl2BandHandlingPtr mono_handling) { /* copying UINT8 raw pixels from the DBMS tile into the output image */ @@ -1395,17 +1416,17 @@ } } } static void -copy_uint16_raw_pixels (const unsigned short *buffer, const unsigned char *mask, - unsigned short *outbuf, unsigned short width, - unsigned short height, unsigned char num_bands, - double x_res, double y_res, double minx, double maxy, - double tile_minx, double tile_maxy, - unsigned short tile_width, unsigned short tile_height, - rl2PixelPtr no_data) +copy_uint16_raw_pixels (const unsigned short *buffer, + const unsigned char *mask, unsigned short *outbuf, + unsigned short width, unsigned short height, + unsigned char num_bands, double x_res, double y_res, + double minx, double maxy, double tile_minx, + double tile_maxy, unsigned short tile_width, + unsigned short tile_height, rl2PixelPtr no_data) { /* copying UINT16 raw pixels from the DBMS tile into the output image */ int x; int y; int b; @@ -1532,14 +1553,15 @@ static void copy_uint16_raw_selected_pixels (const unsigned short *buffer, const unsigned char *mask, unsigned char *outbuf, unsigned short width, - unsigned short height, unsigned char num_bands, - double x_res, double y_res, double minx, - double maxy, double tile_minx, - double tile_maxy, unsigned short tile_width, + unsigned short height, + unsigned char num_bands, double x_res, + double y_res, double minx, double maxy, + double tile_minx, double tile_maxy, + unsigned short tile_width, unsigned short tile_height, rl2PixelPtr no_data, unsigned char red_band, unsigned char green_band, unsigned char blue_band, rl2BandHandlingPtr red_handling, @@ -3077,12 +3099,12 @@ { r = malloc (sizeof (rl2BandHandling)); r->colorMap = NULL; r->contrastEnhancement = RL2_CONTRAST_ENHANCEMENT_NORMALIZE; - compute_stretching (band, &(r->minValue), &(r->maxValue), - &(r->scaleFactor)); + compute_stretching (band, &(r->minValue), + &(r->maxValue), &(r->scaleFactor)); } else if (style->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NONE) { r = malloc (sizeof (rl2BandHandling)); @@ -3163,12 +3185,12 @@ { g = malloc (sizeof (rl2BandHandling)); g->colorMap = NULL; g->contrastEnhancement = RL2_CONTRAST_ENHANCEMENT_NORMALIZE; - compute_stretching (band, &(g->minValue), &(g->maxValue), - &(g->scaleFactor)); + compute_stretching (band, &(g->minValue), + &(g->maxValue), &(g->scaleFactor)); } else if (style->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NONE) { g = malloc (sizeof (rl2BandHandling)); @@ -3249,12 +3271,12 @@ { b = malloc (sizeof (rl2BandHandling)); b->colorMap = NULL; b->contrastEnhancement = RL2_CONTRAST_ENHANCEMENT_NORMALIZE; - compute_stretching (band, &(b->minValue), &(b->maxValue), - &(b->scaleFactor)); + compute_stretching (band, &(b->minValue), + &(b->maxValue), &(b->scaleFactor)); } else if (style->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NONE) { b = malloc (sizeof (rl2BandHandling)); @@ -3601,12 +3623,12 @@ { g = malloc (sizeof (rl2BandHandling)); g->colorMap = NULL; g->contrastEnhancement = RL2_CONTRAST_ENHANCEMENT_NORMALIZE; - compute_stretching (band, &(g->minValue), &(g->maxValue), - &(g->scaleFactor)); + compute_stretching (band, &(g->minValue), + &(g->maxValue), &(g->scaleFactor)); } else if (style->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NONE) { g = malloc (sizeof (rl2BandHandling)); @@ -3895,13 +3917,14 @@ static int do_copy_raw_selected_pixels (rl2PrivRasterPtr rst, unsigned char *outbuf, unsigned int width, unsigned int height, double x_res, double y_res, double minx, double maxy, double tile_minx, double tile_maxy, - unsigned int tile_width, unsigned int tile_height, - rl2PixelPtr no_data, unsigned char red_band, - unsigned char green_band, unsigned char blue_band, + unsigned int tile_width, + unsigned int tile_height, rl2PixelPtr no_data, + unsigned char red_band, unsigned char green_band, + unsigned char blue_band, rl2BandHandlingPtr red_handling, rl2BandHandlingPtr green_handling, rl2BandHandlingPtr blue_handling) { switch (rst->sampleType) @@ -4159,17 +4182,16 @@ } static int do_copy_raw_pixels (rl2PrivRasterPtr rst, unsigned char *outbuf, unsigned int width, unsigned int height, - unsigned char sample_type, unsigned char num_bands, - double x_res, double y_res, double minx, double maxy, - double tile_minx, double tile_maxy, unsigned int tile_width, + unsigned char raster_type, unsigned char sample_type, + unsigned char num_bands, double x_res, double y_res, + double minx, double maxy, double tile_minx, + double tile_maxy, unsigned int tile_width, unsigned int tile_height, rl2PixelPtr no_data) { - - switch (sample_type) { case RL2_SAMPLE_INT8: copy_int8_raw_pixels ((const char *) (rst->rasterBuffer), (const unsigned char *) (rst->maskBuffer), @@ -4183,11 +4205,12 @@ (short *) outbuf, width, height, x_res, y_res, minx, maxy, tile_minx, tile_maxy, tile_width, tile_height, no_data); return 1; case RL2_SAMPLE_UINT16: - copy_uint16_raw_pixels ((const unsigned short *) (rst->rasterBuffer), + copy_uint16_raw_pixels ((const unsigned short + *) (rst->rasterBuffer), (const unsigned char *) (rst->maskBuffer), (unsigned short *) outbuf, width, height, num_bands, x_res, y_res, minx, maxy, tile_minx, tile_maxy, tile_width, tile_height, no_data); @@ -4224,12 +4247,13 @@ return 1; default: copy_uint8_raw_pixels ((const unsigned char *) (rst->rasterBuffer), (const unsigned char *) (rst->maskBuffer), (unsigned char *) outbuf, width, height, - num_bands, x_res, y_res, minx, maxy, tile_minx, - tile_maxy, tile_width, tile_height, no_data); + num_bands, x_res, y_res, minx, maxy, + tile_minx, tile_maxy, tile_width, + tile_height, no_data, raster_type); return 1; }; return 0; } @@ -4236,13 +4260,14 @@ RL2_PRIVATE int rl2_copy_raw_pixels (rl2RasterPtr raster, unsigned char *outbuf, unsigned int width, unsigned int height, unsigned char sample_type, unsigned char num_bands, unsigned char auto_ndvi, - unsigned char red_band_index, unsigned char nir_band_index, - double x_res, double y_res, double minx, double maxy, - double tile_minx, double tile_maxy, rl2PixelPtr no_data, + unsigned char red_band_index, + unsigned char nir_band_index, double x_res, double y_res, + double minx, double maxy, double tile_minx, + double tile_maxy, rl2PixelPtr no_data, rl2RasterSymbolizerPtr style, rl2RasterStatisticsPtr stats) { /* copying raw pixels into the output buffer */ unsigned int tile_width; unsigned int tile_height; @@ -4254,12 +4279,12 @@ { /* attempting to apply a RasterSymbolizer */ int yes_no; int categorize; int interpolate; - if (rl2_is_raster_symbolizer_triple_band_selected (style, &yes_no) == - RL2_OK) + if (rl2_is_raster_symbolizer_triple_band_selected (style, &yes_no) + == RL2_OK) { if ((rst->sampleType == RL2_SAMPLE_UINT8 || rst->sampleType == RL2_SAMPLE_UINT16) && (rst->pixelType == RL2_PIXEL_RGB || rst->pixelType == RL2_PIXEL_MULTIBAND) && yes_no) @@ -4289,14 +4314,15 @@ &blue_handling); if (red_handling == NULL || green_handling == NULL || blue_handling == NULL) return 0; if (do_copy_raw_selected_pixels - (rst, outbuf, width, height, x_res, y_res, minx, maxy, - tile_minx, tile_maxy, tile_width, tile_height, - no_data, red_band, green_band, blue_band, - red_handling, green_handling, blue_handling)) + (rst, outbuf, width, height, x_res, y_res, minx, + maxy, tile_minx, tile_maxy, tile_width, + tile_height, no_data, red_band, green_band, + blue_band, red_handling, green_handling, + blue_handling)) return 1; if (red_handling != NULL) free (red_handling); if (green_handling != NULL) free (green_handling); @@ -4318,14 +4344,14 @@ build_ndvi_handling ((rl2PrivRasterSymbolizerPtr) style, &ndvi_handling); if (ndvi_handling == NULL) return 0; if (do_auto_ndvi_pixels - (rst, outbuf, width, height, num_bands, x_res, y_res, - minx, maxy, tile_minx, tile_maxy, tile_width, - tile_height, no_data, red_band_index, nir_band_index, - ndvi_handling)) + (rst, outbuf, width, height, num_bands, x_res, + y_res, minx, maxy, tile_minx, tile_maxy, + tile_width, tile_height, no_data, red_band_index, + nir_band_index, ndvi_handling)) return 1; if (ndvi_handling != NULL) destroy_ndvi_handling (ndvi_handling); } if (((rst->sampleType == RL2_SAMPLE_UINT8 @@ -4346,27 +4372,99 @@ stats, mono_band, &mono_handling); if (mono_handling == NULL) return 0; if (do_copy_raw_mono_pixels - (rst, outbuf, width, height, num_bands, x_res, y_res, - minx, maxy, tile_minx, tile_maxy, tile_width, - tile_height, no_data, mono_band, mono_handling)) + (rst, outbuf, width, height, num_bands, x_res, + y_res, minx, maxy, tile_minx, tile_maxy, + tile_width, tile_height, no_data, mono_band, + mono_handling)) return 1; if (mono_handling != NULL) destroy_mono_handling (mono_handling); } } } if (do_copy_raw_pixels - (rst, outbuf, width, height, sample_type, num_bands, x_res, y_res, minx, - maxy, tile_minx, tile_maxy, tile_width, tile_height, no_data)) + (rst, outbuf, width, height, rst->sampleType, sample_type, num_bands, + x_res, y_res, minx, maxy, tile_minx, tile_maxy, tile_width, + tile_height, no_data)) return 1; return 0; } + +static void +do_copy_raw_mask (rl2PrivRasterPtr rst, unsigned char *maskbuf, + unsigned int width, unsigned int height, double x_res, + double y_res, double minx, double maxy, double tile_minx, + double tile_maxy, unsigned int tile_width, + unsigned int tile_height) +{ +/* copying mask pixels from the DBMS tile into the output mask */ + unsigned int x; + unsigned int y; + int out_x; + int out_y; + double geo_x; + double geo_y; + const unsigned char *p_in = rst->maskBuffer; + unsigned char *p_out; + double y_res2 = y_res / 2.0; + double x_res2 = x_res / 2.0; + + geo_y = tile_maxy + y_res2; + for (y = 0; y < tile_height; y++) + { + geo_y -= y_res; + out_y = (maxy - geo_y) / y_res; + if (out_y < 0 || out_y >= (int) height) + { + p_in += tile_width; + continue; + } + geo_x = tile_minx - x_res2; + for (x = 0; x < tile_width; x++) + { + geo_x += x_res; + out_x = (geo_x - minx) / x_res; + if (out_x < 0 || out_x >= (int) width) + { + p_in++; + continue; + } + p_out = maskbuf + (out_y * width) + out_x; + if (*p_in++ == 0) + *p_out++ = 255; + } + } +} + +RL2_PRIVATE int +rl2_copy_raw_mask (rl2RasterPtr raster, unsigned char *maskbuf, + unsigned int width, + unsigned int height, double x_res, double y_res, + double minx, double maxy, double tile_minx, double tile_maxy) +{ +/* copying a raw transparency mask into the output buffer */ + unsigned int tile_width; + unsigned int tile_height; + rl2PrivRasterPtr rst = (rl2PrivRasterPtr) raster; + + if (rl2_get_raster_size (raster, &tile_width, &tile_height) != RL2_OK) + return 0; + + if (rst->maskBuffer == NULL) + { + /* tile without mask - ok */ + return 1; + } + do_copy_raw_mask (rst, maskbuf, width, height, x_res, y_res, minx, maxy, + tile_minx, tile_maxy, tile_width, tile_height); + return 1; +} static void get_int8_ennuple (const char *rawbuf, unsigned short row, unsigned short col, unsigned short row_stride, rl2PixelPtr no_data, double ennuple[], int *has_no_data) @@ -4453,13 +4551,13 @@ *has_no_data = 1; } } static void -get_int16_ennuple (const short *rawbuf, unsigned short row, unsigned short col, - unsigned short row_stride, rl2PixelPtr no_data, - double ennuple[], int *has_no_data) +get_int16_ennuple (const short *rawbuf, unsigned short row, + unsigned short col, unsigned short row_stride, + rl2PixelPtr no_data, double ennuple[], int *has_no_data) { /* extracting a 3x3 "super-pixel" - INT16 */ const short *p_in; short nd_val = 0; int i; @@ -4629,13 +4727,13 @@ *has_no_data = 1; } } static void -get_float_ennuple (const float *rawbuf, unsigned short row, unsigned short col, - unsigned short row_stride, rl2PixelPtr no_data, - double ennuple[], int *has_no_data) +get_float_ennuple (const float *rawbuf, unsigned short row, + unsigned short col, unsigned short row_stride, + rl2PixelPtr no_data, double ennuple[], int *has_no_data) { /* extracting a 3x3 "super-pixel" - FLOAT */ const float *p_in; float nd_val = 0.0; int i; @@ -4939,16 +5037,17 @@ } } RL2_PRIVATE int rl2_build_shaded_relief_mask (sqlite3 * handle, int max_threads, - rl2CoveragePtr cvg, double relief_factor, - double scale_factor, unsigned int width, - unsigned int height, double minx, double miny, - double maxx, double maxy, double x_res, - double y_res, float **shaded_relief, - int *shaded_relief_sz) + rl2CoveragePtr cvg, + int by_section, sqlite3_int64 section_id, + double relief_factor, double scale_factor, + unsigned int width, unsigned int height, + double minx, double miny, double maxx, + double maxy, double x_res, double y_res, + float **shaded_relief, int *shaded_relief_sz) { /* attempting to return a Shaded Relief mask from the DBMS Coverage */ rl2PixelPtr no_data = NULL; const char *coverage; unsigned char level; @@ -4983,11 +5082,12 @@ goto error; coverage = rl2_get_coverage_name (cvg); if (coverage == NULL) goto error; if (rl2_find_matching_resolution - (handle, cvg, 0, 0, &xx_res, &yy_res, &level, &scale) != RL2_OK) + (handle, cvg, by_section, section_id, &xx_res, &yy_res, &level, + &scale) != RL2_OK) goto error; if (rl2_get_coverage_type (cvg, &sample_type, &pixel_type, &num_bands) != RL2_OK) goto error; if (pixel_type != RL2_PIXEL_DATAGRID && num_bands != 1) @@ -4998,16 +5098,15 @@ /* preparing the "tiles" SQL query */ xtiles = sqlite3_mprintf ("%s_tiles", coverage); xxtiles = rl2_double_quoted_sql (xtiles); sql = - sqlite3_mprintf ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) " - "FROM \"%s\" " - "WHERE pyramid_level = ? AND ROWID IN ( " - "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q " - "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles, - xtiles); + sqlite3_mprintf + ("SELECT tile_id, MbrMinX(geometry), MbrMaxY(geometry) " + "FROM \"%s\" " "WHERE pyramid_level = ? AND ROWID IN ( " + "SELECT ROWID FROM SpatialIndex WHERE f_table_name = %Q " + "AND search_frame = BuildMBR(?, ?, ?, ?))", xxtiles, xtiles); sqlite3_free (xtiles); free (xxtiles); ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt_tiles, NULL); sqlite3_free (sql); if (ret != SQLITE_OK) @@ -5114,13 +5213,13 @@ for (row = 0; row < height; row++) { for (col = 0; col < width; col++) *p_out++ = shaded_relief_value (relief_factor, scale_factor, - altRadians, azRadians, rawbuf, row, - col, row_stride, sample_type, - no_data); + altRadians, azRadians, rawbuf, + row, col, row_stride, + sample_type, no_data); } } else { /* executing as many concurrent threads */ Index: src/rl2raw.c ================================================================== --- src/rl2raw.c +++ src/rl2raw.c @@ -369,12 +369,12 @@ case RL2_PIXEL_GRAYSCALE: grayscale_as_rgb (rst->sampleType, no_data->Samples->uint8, &transpR, &transpG, &transpB); break; case RL2_PIXEL_RGB: - rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data, RL2_RED_BAND, - &transpR); + rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data, + RL2_RED_BAND, &transpR); rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data, RL2_GREEN_BAND, &transpG); rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data, RL2_BLUE_BAND, &transpB); break; @@ -603,12 +603,12 @@ case RL2_PIXEL_GRAYSCALE: grayscale_as_rgb (rst->sampleType, no_data->Samples->uint8, &transpR, &transpG, &transpB); break; case RL2_PIXEL_RGB: - rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data, RL2_RED_BAND, - &transpR); + rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data, + RL2_RED_BAND, &transpR); rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data, RL2_GREEN_BAND, &transpG); rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data, RL2_BLUE_BAND, &transpB); break; @@ -891,12 +891,12 @@ case RL2_PIXEL_GRAYSCALE: grayscale_as_rgb (rst->sampleType, no_data->Samples->uint8, &transpR, &transpG, &transpB); break; case RL2_PIXEL_RGB: - rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data, RL2_RED_BAND, - &transpR); + rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data, + RL2_RED_BAND, &transpR); rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data, RL2_GREEN_BAND, &transpG); rl2_get_pixel_sample_uint8 ((rl2PixelPtr) no_data, RL2_BLUE_BAND, &transpB); break; @@ -1508,12 +1508,12 @@ *buf_size = sz; return RL2_OK; } RL2_DECLARE int -rl2_raster_band_to_uint16 (rl2RasterPtr ptr, int band, unsigned short **buffer, - int *buf_size) +rl2_raster_band_to_uint16 (rl2RasterPtr ptr, int band, + unsigned short **buffer, int *buf_size) { /* attempting to export Raster BAND data as a UINT-16 array */ unsigned short *buf; int sz; unsigned int row; @@ -1973,12 +1973,12 @@ } RL2_PRIVATE unsigned char * rl2_copy_endian_raw_pixels (const unsigned char *pixels, int pixels_sz, unsigned int width, unsigned int height, - unsigned char sample_type, unsigned char num_bands, - int big_endian) + unsigned char sample_type, + unsigned char num_bands, int big_endian) { /* copying RAW pixels (in endian safe mode) */ int sample_bytes = 0; int outsize = width * height * num_bands; unsigned char *outbuf = NULL; @@ -2024,12 +2024,12 @@ case RL2_SAMPLE_INT8: copy_endian_raw_i8 ((char *) outbuf, (const char *) pixels, width, height, num_bands); break; case RL2_SAMPLE_INT16: - copy_endian_raw_i16 ((short *) outbuf, (const short *) pixels, width, - height, num_bands, big_endian); + copy_endian_raw_i16 ((short *) outbuf, (const short *) pixels, + width, height, num_bands, big_endian); break; case RL2_SAMPLE_UINT16: copy_endian_raw_u16 ((unsigned short *) outbuf, (const unsigned short *) pixels, width, height, num_bands, big_endian); @@ -2042,12 +2042,12 @@ copy_endian_raw_u32 ((unsigned int *) outbuf, (const unsigned int *) pixels, width, height, num_bands, big_endian); break; case RL2_SAMPLE_FLOAT: - copy_endian_raw_flt ((float *) outbuf, (const float *) pixels, width, - height, num_bands, big_endian); + copy_endian_raw_flt ((float *) outbuf, (const float *) pixels, + width, height, num_bands, big_endian); break; case RL2_SAMPLE_DOUBLE: copy_endian_raw_dbl ((double *) outbuf, (const double *) pixels, width, height, num_bands, big_endian); break; @@ -2067,14 +2067,14 @@ fprintf (stderr, "Mismatching RAW pixels !!!\n"); return 0; } static void -copy_tile_raw_i8 (const char *in, unsigned int in_width, unsigned int in_height, - unsigned int startRow, unsigned int startCol, char *out, - unsigned int tileWidth, unsigned int tileHeight, - unsigned char num_bands) +copy_tile_raw_i8 (const char *in, unsigned int in_width, + unsigned int in_height, unsigned int startRow, + unsigned int startCol, char *out, unsigned int tileWidth, + unsigned int tileHeight, unsigned char num_bands) { /* signed int8 */ unsigned int x; unsigned int y; unsigned char b; @@ -2189,14 +2189,14 @@ } } } static void -copy_tile_raw_i32 (const int *in, unsigned int in_width, unsigned int in_height, - unsigned int startRow, unsigned int startCol, int *out, - unsigned int tileWidth, unsigned int tileHeight, - unsigned char num_bands) +copy_tile_raw_i32 (const int *in, unsigned int in_width, + unsigned int in_height, unsigned int startRow, + unsigned int startCol, int *out, unsigned int tileWidth, + unsigned int tileHeight, unsigned char num_bands) { /* signed int32 */ unsigned int x; unsigned int y; unsigned char b; @@ -2311,11 +2311,12 @@ } } static int build_tile_from_raw_pixels (rl2PrivRasterPtr origin, unsigned int tileWidth, - unsigned int tileHeight, unsigned char sample_type, + unsigned int tileHeight, + unsigned char sample_type, unsigned char num_bands, unsigned int startRow, unsigned int startCol, rl2PixelPtr no_data, unsigned char **pixels, int *pixels_sz) { /* extracting a Tile from the RAW buffer */ @@ -2351,39 +2352,43 @@ origin->width, origin->height, startRow, startCol, (char *) out, tileWidth, tileHeight, num_bands); break; case RL2_SAMPLE_INT16: copy_tile_raw_i16 ((const short *) (origin->rasterBuffer), - origin->width, origin->height, startRow, startCol, - (short *) out, tileWidth, tileHeight, num_bands); + origin->width, origin->height, startRow, + startCol, (short *) out, tileWidth, tileHeight, + num_bands); break; case RL2_SAMPLE_UINT16: copy_tile_raw_u16 ((const unsigned short *) (origin->rasterBuffer), - origin->width, origin->height, startRow, startCol, - (unsigned short *) out, tileWidth, tileHeight, - num_bands); + origin->width, origin->height, startRow, + startCol, (unsigned short *) out, tileWidth, + tileHeight, num_bands); break; case RL2_SAMPLE_INT32: copy_tile_raw_i32 ((const int *) (origin->rasterBuffer), - origin->width, origin->height, startRow, startCol, - (int *) out, tileWidth, tileHeight, num_bands); + origin->width, origin->height, startRow, + startCol, (int *) out, tileWidth, tileHeight, + num_bands); break; case RL2_SAMPLE_UINT32: copy_tile_raw_u32 ((const unsigned int *) (origin->rasterBuffer), - origin->width, origin->height, startRow, startCol, - (unsigned int *) out, tileWidth, tileHeight, - num_bands); + origin->width, origin->height, startRow, + startCol, (unsigned int *) out, tileWidth, + tileHeight, num_bands); break; case RL2_SAMPLE_FLOAT: copy_tile_raw_flt ((const float *) (origin->rasterBuffer), - origin->width, origin->height, startRow, startCol, - (float *) out, tileWidth, tileHeight, num_bands); + origin->width, origin->height, startRow, + startCol, (float *) out, tileWidth, tileHeight, + num_bands); break; case RL2_SAMPLE_DOUBLE: copy_tile_raw_dbl ((const double *) (origin->rasterBuffer), - origin->width, origin->height, startRow, startCol, - (double *) out, tileWidth, tileHeight, num_bands); + origin->width, origin->height, startRow, + startCol, (double *) out, tileWidth, tileHeight, + num_bands); break; default: copy_tile_raw_u8 ((const unsigned char *) (origin->rasterBuffer), origin->width, origin->height, startRow, startCol, (unsigned char *) out, tileWidth, tileHeight, Index: src/rl2sql.c ================================================================== --- src/rl2sql.c +++ src/rl2sql.c @@ -659,21 +659,21 @@ blob_even = sqlite3_value_blob (argv[3]); blob_even_sz = sqlite3_value_bytes (argv[3]); } if (!get_coverage_defs - (sqlite, coverage, &tile_width, &tile_height, &sample_type, &pixel_type, - &num_bands, &compression)) + (sqlite, coverage, &tile_width, &tile_height, &sample_type, + &pixel_type, &num_bands, &compression)) { sqlite3_result_int (context, -1); return; } ret = - rl2_is_valid_dbms_raster_tile (level, tile_width, tile_height, blob_odd, - blob_odd_sz, blob_even, blob_even_sz, - sample_type, pixel_type, num_bands, - compression); + rl2_is_valid_dbms_raster_tile (level, tile_width, tile_height, + blob_odd, blob_odd_sz, blob_even, + blob_even_sz, sample_type, pixel_type, + num_bands, compression); if (ret == RL2_OK) sqlite3_result_int (context, 1); else sqlite3_result_int (context, 0); } @@ -1535,12 +1535,12 @@ if (pxl2 != NULL) rl2_destroy_pixel (pxl2); } static void -fnct_GetRasterStatistics_NoDataPixelsCount (sqlite3_context * context, int argc, - sqlite3_value ** argv) +fnct_GetRasterStatistics_NoDataPixelsCount (sqlite3_context * context, + int argc, sqlite3_value ** argv) { /* SQL function: / GetRasterStatistics_NoDataPixelsCount(BLOBencoded statistics) / / will return the total count of NoData pixels @@ -1570,12 +1570,12 @@ sqlite3_result_int64 (context, st->no_data); rl2_destroy_raster_statistics (stats); } static void -fnct_GetRasterStatistics_ValidPixelsCount (sqlite3_context * context, int argc, - sqlite3_value ** argv) +fnct_GetRasterStatistics_ValidPixelsCount (sqlite3_context * context, + int argc, sqlite3_value ** argv) { /* SQL function: / GetRasterStatistics_ValidPixelsCount(BLOBencoded statistics) / / will return the total count of valid pixels @@ -3885,12 +3885,12 @@ if (rl2_get_coverage_srid (coverage, &srid) != RL2_OK) { sqlite3_result_int (context, -1); return; } - if (rl2_get_coverage_type (coverage, &sample_type, &pixel_type, &num_bands) - != RL2_OK) + if (rl2_get_coverage_type + (coverage, &sample_type, &pixel_type, &num_bands) != RL2_OK) { sqlite3_result_int (context, -1); return; } no_data = rl2_get_coverage_no_data (coverage); @@ -4049,11 +4049,12 @@ { for (x = minx; x < maxx; x += tilew) { char *err_msg = NULL; unsigned char *rgba_tile = - do_wms_GetMap_get (NULL, url, proxy, wms_version, wms_layer, + do_wms_GetMap_get (NULL, url, proxy, wms_version, + wms_layer, wms_crs, swap_xy, x, y - tileh, x + tilew, y, tile_width, tile_height, wms_style, wms_format, opaque, 0, &err_msg); if (rgba_tile == NULL) @@ -4111,15 +4112,16 @@ retry = retry->next; continue; } retry->count += 1; rgba_tile = - do_wms_GetMap_get (NULL, url, proxy, wms_version, wms_layer, - wms_crs, swap_xy, retry->minx, - retry->miny, retry->maxx, retry->maxy, - tile_width, tile_height, wms_style, - wms_format, opaque, 0, &err_msg); + do_wms_GetMap_get (NULL, url, proxy, wms_version, + wms_layer, wms_crs, swap_xy, + retry->minx, retry->miny, retry->maxx, + retry->maxy, tile_width, tile_height, + wms_style, wms_format, opaque, 0, + &err_msg); if (rgba_tile == NULL) { retry = retry->next; continue; } @@ -4487,12 +4489,12 @@ minx = pt_x - ext_x / 2.0; maxx = minx + ext_x; miny = pt_y - ext_y / 2.0; maxy = miny + ext_y; } - else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) - != RL2_OK) + else if (rl2_parse_bbox + (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK) { errcode = -1; goto error; } @@ -4517,14 +4519,15 @@ } else { /* whole Coverage */ ret = - rl2_export_geotiff_from_dbms (sqlite, max_threads, path, coverage, - horz_res, vert_res, minx, miny, - maxx, maxy, width, height, - compression, tile_sz, worldfile); + rl2_export_geotiff_from_dbms (sqlite, max_threads, path, + coverage, horz_res, vert_res, + minx, miny, maxx, maxy, width, + height, compression, tile_sz, + worldfile); } if (ret != RL2_OK) { errcode = 0; goto error; @@ -4866,12 +4869,12 @@ minx = pt_x - ext_x / 2.0; maxx = minx + ext_x; miny = pt_y - ext_y / 2.0; maxy = miny + ext_y; } - else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) - != RL2_OK) + else if (rl2_parse_bbox + (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK) { errcode = -1; goto error; } @@ -4889,14 +4892,14 @@ ret = rl2_export_section_triple_band_geotiff_from_dbms (sqlite, path, coverage, section_id, horz_res, - vert_res, minx, - miny, maxx, - maxy, width, - height, + vert_res, + minx, miny, + maxx, maxy, + width, height, red_band, green_band, blue_band, compression, tile_sz, @@ -4905,14 +4908,15 @@ else { /* whole Coverage */ ret = - rl2_export_triple_band_geotiff_from_dbms (sqlite, path, coverage, - horz_res, vert_res, - minx, miny, maxx, maxy, - width, height, red_band, + rl2_export_triple_band_geotiff_from_dbms (sqlite, path, + coverage, horz_res, + vert_res, minx, miny, + maxx, maxy, width, + height, red_band, green_band, blue_band, compression, tile_sz, worldfile); } if (ret != RL2_OK) @@ -5246,12 +5250,12 @@ minx = pt_x - ext_x / 2.0; maxx = minx + ext_x; miny = pt_y - ext_y / 2.0; maxy = miny + ext_y; } - else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) - != RL2_OK) + else if (rl2_parse_bbox + (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK) { errcode = -1; goto error; } @@ -5270,12 +5274,13 @@ rl2_export_section_mono_band_geotiff_from_dbms (sqlite, path, coverage, section_id, horz_res, vert_res, minx, - miny, maxx, maxy, - width, height, + miny, maxx, + maxy, width, + height, mono_band, compression, tile_sz, worldfile); } @@ -5282,15 +5287,15 @@ else { /* whole Coverage */ ret = rl2_export_mono_band_geotiff_from_dbms (sqlite, path, coverage, - horz_res, vert_res, minx, - miny, maxx, maxy, width, - height, mono_band, - compression, tile_sz, - worldfile); + horz_res, vert_res, + minx, miny, maxx, maxy, + width, height, + mono_band, compression, + tile_sz, worldfile); } if (ret != RL2_OK) { errcode = 0; @@ -5600,12 +5605,12 @@ minx = pt_x - ext_x / 2.0; maxx = minx + ext_x; miny = pt_y - ext_y / 2.0; maxy = miny + ext_y; } - else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) - != RL2_OK) + else if (rl2_parse_bbox + (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK) { errcode = -1; goto error; } @@ -5623,16 +5628,18 @@ { /* TIFF + Worldfile */ ret = rl2_export_section_tiff_worldfile_from_dbms (sqlite, max_threads, - path, coverage, + path, + coverage, section_id, horz_res, - vert_res, minx, - miny, maxx, - maxy, width, + vert_res, + minx, miny, + maxx, maxy, + width, height, compression, tile_sz); } else @@ -5656,12 +5663,12 @@ /* TIFF + Worldfile */ ret = rl2_export_tiff_worldfile_from_dbms (sqlite, max_threads, path, coverage, horz_res, vert_res, - minx, miny, maxx, maxy, - width, height, + minx, miny, maxx, + maxy, width, height, compression, tile_sz); } else { /* plain TIFF, no Worldfile */ @@ -5971,12 +5978,12 @@ minx = pt_x - ext_x / 2.0; maxx = minx + ext_x; miny = pt_y - ext_y / 2.0; maxy = miny + ext_y; } - else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) - != RL2_OK) + else if (rl2_parse_bbox + (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK) { errcode = -1; goto error; } @@ -5991,13 +5998,14 @@ if (by_section) { /* single Section */ ret = rl2_export_section_jpeg_from_dbms (sqlite, max_threads, path, - coverage, section_id, horz_res, - vert_res, minx, miny, maxx, - maxy, width, height, quality, + coverage, section_id, + horz_res, vert_res, minx, + miny, maxx, maxy, width, + height, quality, with_worldfile); } else { /* whole Coverage */ @@ -6368,12 +6376,12 @@ minx = pt_x - ext_x / 2.0; maxx = minx + ext_x; miny = pt_y - ext_y / 2.0; maxy = miny + ext_y; } - else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) - != RL2_OK) + else if (rl2_parse_bbox + (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK) { errcode = -1; goto error; } @@ -6399,11 +6407,12 @@ } else { /* plain TIFF, no Worldfile */ ret = - rl2_export_section_triple_band_tiff_from_dbms (sqlite, path, + rl2_export_section_triple_band_tiff_from_dbms (sqlite, + path, coverage, section_id, horz_res, vert_res, minx, miny, @@ -6427,12 +6436,14 @@ rl2_export_triple_band_tiff_worldfile_from_dbms (sqlite, path, coverage, horz_res, vert_res, - minx, miny, - maxx, maxy, + minx, + miny, + maxx, + maxy, width, height, red_band, green_band, blue_band, @@ -6443,13 +6454,14 @@ { /* plain TIFF, no Worldfile */ ret = rl2_export_triple_band_tiff_from_dbms (sqlite, path, coverage, horz_res, - vert_res, minx, miny, - maxx, maxy, width, - height, red_band, + vert_res, minx, + miny, maxx, maxy, + width, height, + red_band, green_band, blue_band, compression, tile_sz); } @@ -6817,12 +6829,12 @@ minx = pt_x - ext_x / 2.0; maxx = minx + ext_x; miny = pt_y - ext_y / 2.0; maxy = miny + ext_y; } - else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) - != RL2_OK) + else if (rl2_parse_bbox + (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK) { errcode = -1; goto error; } @@ -6852,13 +6864,14 @@ ret = rl2_export_section_mono_band_tiff_from_dbms (sqlite, path, coverage, section_id, horz_res, - vert_res, minx, - miny, maxx, - maxy, width, + vert_res, + minx, miny, + maxx, maxy, + width, height, mono_band, compression, tile_sz); } @@ -6868,11 +6881,12 @@ /* whole Coverage */ if (with_worldfile) { /* TIFF + Worldfile */ ret = - rl2_export_mono_band_tiff_worldfile_from_dbms (sqlite, path, + rl2_export_mono_band_tiff_worldfile_from_dbms (sqlite, + path, coverage, horz_res, vert_res, minx, miny, maxx, maxy, @@ -6884,16 +6898,16 @@ } else { /* plain TIFF, no Worldfile */ ret = - rl2_export_mono_band_tiff_from_dbms (sqlite, path, coverage, - horz_res, vert_res, - minx, miny, maxx, maxy, - width, height, - mono_band, compression, - tile_sz); + rl2_export_mono_band_tiff_from_dbms (sqlite, path, + coverage, horz_res, + vert_res, minx, miny, + maxx, maxy, width, + height, mono_band, + compression, tile_sz); } } if (ret != RL2_OK) { errcode = 0; @@ -7190,12 +7204,12 @@ minx = pt_x - ext_x / 2.0; maxx = minx + ext_x; miny = pt_y - ext_y / 2.0; maxy = miny + ext_y; } - else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) - != RL2_OK) + else if (rl2_parse_bbox + (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK) { errcode = -1; goto error; } @@ -7222,13 +7236,14 @@ else { /* whole Coverage */ ret = rl2_export_ascii_grid_from_dbms (sqlite, max_threads, path, - coverage, resolution, minx, miny, - maxx, maxy, width, height, - is_centered, decimal_digits); + coverage, resolution, minx, + miny, maxx, maxy, width, + height, is_centered, + decimal_digits); } if (ret != RL2_OK) { errcode = 0; goto error; @@ -7479,12 +7494,12 @@ minx = pt_x - ext_x / 2.0; maxx = minx + ext_x; miny = pt_y - ext_y / 2.0; maxy = miny + ext_y; } - else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) - != RL2_OK) + else if (rl2_parse_bbox + (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK) { errcode = -1; goto error; } @@ -7498,29 +7513,31 @@ if (by_section) { /* single Section */ ret = - rl2_export_section_ndvi_ascii_grid_from_dbms (sqlite, max_threads, - path, coverage, + rl2_export_section_ndvi_ascii_grid_from_dbms (sqlite, + max_threads, path, + coverage, section_id, resolution, minx, miny, maxx, maxy, width, height, - red_band, nir_band, + red_band, + nir_band, is_centered, decimal_digits); } else { /* whole Coverage */ ret = rl2_export_ndvi_ascii_grid_from_dbms (sqlite, max_threads, path, - coverage, resolution, minx, - miny, maxx, maxy, width, - height, red_band, nir_band, - is_centered, + coverage, resolution, + minx, miny, maxx, maxy, + width, height, red_band, + nir_band, is_centered, decimal_digits); } if (ret != RL2_OK) { errcode = 0; @@ -7581,10 +7598,65 @@ / or -1 (INVALID ARGS) / */ common_write_ndvi_ascii_grid (1, context, argc, argv); } + +static int +test_geographic_srid (sqlite3 * handle, int srid) +{ +/* testing if some SRID is of the Geographic type */ + int ret; + int is_geographic = 0; + sqlite3_stmt *stmt = NULL; + const char *sql; + + sql = "SELECT SridIsGeographic(?)"; + ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL); + if (ret != SQLITE_OK) + return 0; + + sqlite3_reset (stmt); + sqlite3_clear_bindings (stmt); + sqlite3_bind_int (stmt, 1, srid); + while (1) + { + /* scrolling the result set rows */ + ret = sqlite3_step (stmt); + if (ret == SQLITE_DONE) + break; /* end of result set */ + if (ret == SQLITE_ROW) + is_geographic = sqlite3_column_int (stmt, 0); + } + sqlite3_finalize (stmt); + return is_geographic; +} + +static double +standard_scale (sqlite3 * handle, int srid, int width, int height, + double ext_x, double ext_y) +{ +/* computing the standard (normalized) scale */ + double linear_res; + double factor; + int is_geographic = test_geographic_srid (handle, srid); + if (is_geographic) + { + /* geographic (long/lat) CRS */ + double metres = ext_x * (6378137.0 * 2.0 * 3.141592653589793) / 360.0; + linear_res = metres / (double) width; + } + else + { + /* planar (projected) CRS */ + double x_res = ext_x / (double) width; + double y_res = ext_y / (double) height; + linear_res = sqrt (x_res * y_res); + } + factor = linear_res / 0.000254; + return factor * (0.28 / 0.254); +} static void fnct_GetMapImageFromRaster (sqlite3_context * context, int argc, sqlite3_value ** argv) { @@ -7643,10 +7715,11 @@ double y_res; int srid; int level_id; int scale; int xscale; + double map_scale; double xx_res; double yy_res; double aspect_org; double aspect_dst; int ok_style; @@ -7792,10 +7865,11 @@ return; } x_res = ext_x / (double) width; y_res = ext_y / (double) height; + map_scale = standard_scale (sqlite, out_srid, width, height, ext_x, ext_y); /* validating the style */ ok_style = 0; if (strcasecmp (style, "default") == 0) ok_style = 1; else @@ -7803,13 +7877,21 @@ /* attempting to get a Coverage Style */ cvg_stl = rl2_create_coverage_style_from_dbms (sqlite, cvg_name, style); if (cvg_stl == NULL) goto error; - symbolizer = rl2_get_symbolizer_from_coverage_style (cvg_stl, 1.0); + symbolizer = + rl2_get_symbolizer_from_coverage_style (cvg_stl, map_scale); if (symbolizer == NULL) - goto error; + { + /* invisible at the currect scale */ + if (!rl2_aux_default_image + (width, height, bg_red, bg_green, bg_blue, format_id, + transparent, quality, &image, &image_size)) + goto error; + goto done; + } stats = rl2_create_raster_statistics_from_dbms (sqlite, cvg_name); if (stats == NULL) goto error; ok_style = 1; } @@ -7978,12 +8060,12 @@ { /* ordinary Coverage */ by_section = 0; /* retrieving the optimal resolution level */ if (!rl2_find_best_resolution_level - (sqlite, cvg_name, 0, 0, x_res, y_res, &level_id, &scale, &xscale, - &xx_res, &yy_res)) + (sqlite, cvg_name, 0, 0, x_res, y_res, &level_id, &scale, + &xscale, &xx_res, &yy_res)) goto error; } base_width = (int) (ext_x / xx_res); base_height = (int) (ext_y / yy_res); if ((base_width <= 0 && base_width >= USHRT_MAX) @@ -8098,10 +8180,12 @@ aux.outbuf = outbuf; aux.palette = palette; aux.out_pixel = out_pixel; if (!rl2_aux_render_image (&aux, &image, &image_size)) goto error; + + done: sqlite3_result_blob (context, image, image_size, free); rl2_destroy_coverage (coverage); if (palette != NULL) rl2_destroy_palette (palette); if (cvg_stl != NULL) @@ -8120,65 +8204,10 @@ if (stats != NULL) rl2_destroy_raster_statistics (stats); sqlite3_result_null (context); } -static int -test_geographic_srid (sqlite3 * handle, int srid) -{ -/* testing if some SRID is of the Geographic type */ - int ret; - int is_geographic = 0; - sqlite3_stmt *stmt = NULL; - const char *sql; - - sql = "SELECT SridIsGeographic(?)"; - ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL); - if (ret != SQLITE_OK) - return 0; - - sqlite3_reset (stmt); - sqlite3_clear_bindings (stmt); - sqlite3_bind_int (stmt, 1, srid); - while (1) - { - /* scrolling the result set rows */ - ret = sqlite3_step (stmt); - if (ret == SQLITE_DONE) - break; /* end of result set */ - if (ret == SQLITE_ROW) - is_geographic = sqlite3_column_int (stmt, 0); - } - sqlite3_finalize (stmt); - return is_geographic; -} - -static double -standard_scale (sqlite3 * handle, int srid, int width, int height, double ext_x, - double ext_y) -{ -/* computing the standard (normalized) scale */ - double linear_res; - double factor; - int is_geographic = test_geographic_srid (handle, srid); - if (is_geographic) - { - /* geographic (long/lat) CRS */ - double metres = ext_x * (6378137.0 * 2.0 * 3.141592653589793) / 360.0; - linear_res = metres / (double) width; - } - else - { - /* planar (projected) CRS */ - double x_res = ext_x / (double) width; - double y_res = ext_y / (double) height; - linear_res = sqrt (x_res * y_res); - } - factor = linear_res / 0.000254; - return factor * (0.28 / 0.254); -} - static void fnct_GetMapImageFromVector (sqlite3_context * context, int argc, sqlite3_value ** argv) { /* SQL function: @@ -8221,10 +8250,11 @@ int transparent = 0; int quality = 80; int reaspect = 0; sqlite3 *sqlite; sqlite3_stmt *stmt = NULL; + const void *data; double minx; double maxx; double miny; double maxy; double ext_x; @@ -8302,10 +8332,11 @@ if (argc > 9) reaspect = sqlite3_value_int (argv[9]); /* coarse args validation */ sqlite = sqlite3_context_db_handle (context); + data = sqlite3_user_data (context); if (width < 64) goto error; if (height < 64) goto error; /* validating the format */ @@ -8503,11 +8534,12 @@ rl2_set_variant_int (variant, i, col_name, sqlite3_column_int64 (stmt, i + 1)); break; case SQLITE_FLOAT: - rl2_set_variant_double (variant, i, col_name, + rl2_set_variant_double (variant, i, + col_name, sqlite3_column_double (stmt, i + 1)); break; case SQLITE_TEXT: rl2_set_variant_text (variant, i, col_name, @@ -8531,19 +8563,20 @@ } } if (geom != NULL) { /* drawing a styled Feature */ - int scale_forbidden; + int scale_forbidden = 0; symbolizer = NULL; if (lyr_stl != NULL) symbolizer = rl2_get_symbolizer_from_feature_type_style (lyr_stl, scale, variant, &scale_forbidden); if (!scale_forbidden) - rl2_draw_vector_feature (ctx, sqlite, symbolizer, - height, minx, miny, x_res, + rl2_draw_vector_feature (ctx, sqlite, data, + symbolizer, height, minx, + miny, maxx, maxy, x_res, y_res, geom, variant); rl2_destroy_geometry (geom); } } } @@ -8807,19 +8840,20 @@ } switch (pixel_type) { case RL2_PIXEL_MONOCHROME: ret = - get_rgba_from_monochrome_mask (width, height, buffer, - mask, no_data, rgba); + get_rgba_from_monochrome_mask (width, height, + buffer, mask, + no_data, rgba); buffer = NULL; mask = NULL; if (!ret) goto error; if (!build_rgb_alpha - (width, height, rgba, &rgb, &alpha, bg_red, bg_green, - bg_blue)) + (width, height, rgba, &rgb, &alpha, bg_red, + bg_green, bg_blue)) goto error; free (rgba); rgba = NULL; if (transparent) { @@ -8849,12 +8883,12 @@ buffer = NULL; mask = NULL; if (!ret) goto error; if (!build_rgb_alpha - (width, height, rgba, &rgb, &alpha, bg_red, bg_green, - bg_blue)) + (width, height, rgba, &rgb, &alpha, bg_red, + bg_green, bg_blue)) goto error; free (rgba); rgba = NULL; if (transparent) { @@ -8883,12 +8917,12 @@ buffer = NULL; mask = NULL; if (!ret) goto error; if (!build_rgb_alpha - (width, height, rgba, &rgb, &alpha, bg_red, bg_green, - bg_blue)) + (width, height, rgba, &rgb, &alpha, bg_red, + bg_green, bg_blue)) goto error; free (rgba); rgba = NULL; if (transparent) { @@ -8918,12 +8952,12 @@ buffer = NULL; mask = NULL; if (!ret) goto error; if (!build_rgb_alpha - (width, height, rgba, &rgb, &alpha, bg_red, bg_green, - bg_blue)) + (width, height, rgba, &rgb, &alpha, bg_red, + bg_green, bg_blue)) goto error; free (rgba); rgba = NULL; if (transparent) { @@ -8947,12 +8981,12 @@ break; case RL2_PIXEL_RGB: if (sample_type == RL2_SAMPLE_UINT16) { ret = - get_rgba_from_multiband16 (width, height, 0, 1, - 2, 3, + get_rgba_from_multiband16 (width, height, 0, + 1, 2, 3, (unsigned short *) buffer, mask, no_data, rgba); } else @@ -8964,12 +8998,12 @@ buffer = NULL; mask = NULL; if (!ret) goto error; if (!build_rgb_alpha - (width, height, rgba, &rgb, &alpha, bg_red, bg_green, - bg_blue)) + (width, height, rgba, &rgb, &alpha, bg_red, + bg_green, bg_blue)) goto error; free (rgba); rgba = NULL; if (transparent) { @@ -8992,20 +9026,20 @@ sqlite3_result_blob (context, image, image_size, free); break; case RL2_PIXEL_MULTIBAND: ret = get_rgba_from_multiband_mask (width, height, - sample_type, num_bands, - buffer, mask, no_data, - rgba); + sample_type, + num_bands, buffer, + mask, no_data, rgba); buffer = NULL; mask = NULL; if (!ret) goto error; if (!build_rgb_alpha - (width, height, rgba, &rgb, &alpha, bg_red, bg_green, - bg_blue)) + (width, height, rgba, &rgb, &alpha, bg_red, + bg_green, bg_blue)) goto error; free (rgba); rgba = NULL; if (transparent) { @@ -9240,12 +9274,12 @@ buffer = NULL; mask = NULL; if (!ret) goto error; if (!build_rgb_alpha - (width, height, rgba, &rgb, &alpha, bg_red, bg_green, - bg_blue)) + (width, height, rgba, &rgb, &alpha, bg_red, + bg_green, bg_blue)) goto error; free (rgba); rgba = NULL; if (transparent) { @@ -9270,15 +9304,16 @@ case RL2_SAMPLE_UINT16: ret = get_rgba_from_multiband16 (width, height, red_band, green_band, blue_band, num_bands, - (unsigned short *) buffer, - mask, no_data, rgba); + (unsigned short *) + buffer, mask, no_data, + rgba); if (!build_rgb_alpha - (width, height, rgba, &rgb, &alpha, bg_red, bg_green, - bg_blue)) + (width, height, rgba, &rgb, &alpha, bg_red, + bg_green, bg_blue)) goto error; free (rgba); rgba = NULL; if (transparent) { @@ -9663,12 +9698,12 @@ minx = pt_x - ext_x / 2.0; maxx = minx + ext_x; miny = pt_y - ext_y / 2.0; maxy = miny + ext_y; } - else if (rl2_parse_bbox (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) - != RL2_OK) + else if (rl2_parse_bbox + (sqlite, blob, blob_sz, &minx, &miny, &maxx, &maxy) != RL2_OK) goto error; /* attempting to load the Coverage definitions from the DBMS */ coverage = rl2_create_coverage_from_dbms (sqlite, cvg_name); if (coverage == NULL) @@ -9677,14 +9712,15 @@ { /* only a single Section */ ret = rl2_export_section_raw_pixels_from_dbms (sqlite, max_threads, coverage, section_id, - horz_res, vert_res, minx, - miny, maxx, maxy, width, - height, big_endian, - &xblob, &xblob_sz); + horz_res, vert_res, + minx, miny, maxx, maxy, + width, height, + big_endian, &xblob, + &xblob_sz); } else { /* whole Coverage */ ret = @@ -9880,12 +9916,12 @@ { errcode = -1; goto error; } - if (rl2_get_coverage_type (coverage, &sample_type, &pixel_type, &num_bands) - != RL2_OK) + if (rl2_get_coverage_type + (coverage, &sample_type, &pixel_type, &num_bands) != RL2_OK) { errcode = -1; goto error; } if (rl2_get_coverage_srid (coverage, &cov_srid) != RL2_OK) @@ -9949,12 +9985,12 @@ { errcode = -1; goto error; } /* georeferencing the raster */ - if (rl2_raster_georeference_frame (raster, srid, minx, miny, maxx, maxy) != - RL2_OK) + if (rl2_raster_georeference_frame (raster, srid, minx, miny, maxx, maxy) + != RL2_OK) { errcode = -1; goto error; } @@ -9969,12 +10005,12 @@ sqlite3_result_int (context, -1); return; } } ret = - rl2_load_raw_raster_into_dbms (sqlite, max_threads, coverage, sctn_name, - raster, pyramidize); + rl2_load_raw_raster_into_dbms (sqlite, max_threads, coverage, + sctn_name, raster, pyramidize); rl2_destroy_coverage (coverage); rl2_destroy_raster (raster); if (ret != RL2_OK) { if (transaction) @@ -10139,24 +10175,24 @@ SQLITE_UTF8, 0, fnct_DropRasterCoverage, 0, 0); sqlite3_create_function (db, "RL2_DropRasterCoverage", 2, SQLITE_UTF8, 0, fnct_DropRasterCoverage, 0, 0); sqlite3_create_function (db, "SetRasterCoverageInfos", 3, SQLITE_UTF8, 0, fnct_SetRasterCoverageInfos, 0, 0); - sqlite3_create_function (db, "RL2_SetRasterCoverageInfos", 3, - SQLITE_UTF8, 0, fnct_SetRasterCoverageInfos, 0, 0); + sqlite3_create_function (db, "RL2_SetRasterCoverageInfos", 3, SQLITE_UTF8, + 0, fnct_SetRasterCoverageInfos, 0, 0); sqlite3_create_function (db, "SetRasterCoverageDefaultBands", 5, - SQLITE_UTF8, 0, fnct_SetRasterCoverageDefaultBands, - 0, 0); + SQLITE_UTF8, 0, + fnct_SetRasterCoverageDefaultBands, 0, 0); sqlite3_create_function (db, "RL2_SetRasterCoverageDefaultBands", 5, - SQLITE_UTF8, 0, fnct_SetRasterCoverageDefaultBands, - 0, 0); + SQLITE_UTF8, 0, + fnct_SetRasterCoverageDefaultBands, 0, 0); sqlite3_create_function (db, "EnableRasterCoverageAutoNDVI", 2, - SQLITE_UTF8, 0, fnct_EnableRasterCoverageAutoNDVI, - 0, 0); + SQLITE_UTF8, 0, + fnct_EnableRasterCoverageAutoNDVI, 0, 0); sqlite3_create_function (db, "RL2_EnableRasterCoverageAutoNDVI", 2, - SQLITE_UTF8, 0, fnct_EnableRasterCoverageAutoNDVI, - 0, 0); + SQLITE_UTF8, 0, + fnct_EnableRasterCoverageAutoNDVI, 0, 0); sqlite3_create_function (db, "IsRasterCoverageAutoNdviEnabled", 1, SQLITE_UTF8, 0, fnct_IsRasterCoverageAutoNdviEnabled, 0, 0); sqlite3_create_function (db, "RL2_IsRasterCoverageAutoNdviEnabled", 1, SQLITE_UTF8, 0, @@ -10288,18 +10324,18 @@ SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, fnct_IsFontItalic, 0, 0); sqlite3_create_function (db, "GetRasterStatistics_NoDataPixelsCount", 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, fnct_GetRasterStatistics_NoDataPixelsCount, 0, 0); - sqlite3_create_function (db, "RL2_GetRasterStatistics_NoDataPixelsCount", 1, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + sqlite3_create_function (db, "RL2_GetRasterStatistics_NoDataPixelsCount", + 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, fnct_GetRasterStatistics_NoDataPixelsCount, 0, 0); sqlite3_create_function (db, "GetRasterStatistics_ValidPixelsCount", 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, fnct_GetRasterStatistics_ValidPixelsCount, 0, 0); - sqlite3_create_function (db, "RL2_GetRasterStatistics_ValidPixelsCount", 1, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + sqlite3_create_function (db, "RL2_GetRasterStatistics_ValidPixelsCount", + 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, fnct_GetRasterStatistics_ValidPixelsCount, 0, 0); sqlite3_create_function (db, "GetRasterStatistics_SampleType", 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, fnct_GetRasterStatistics_SampleType, 0, 0); sqlite3_create_function (db, "RL2_GetRasterStatistics_SampleType", 1, @@ -10370,20 +10406,20 @@ fnct_Pyramidize, 0, 0); sqlite3_create_function (db, "RL2_Pyramidize", 4, SQLITE_UTF8, priv_data, fnct_Pyramidize, 0, 0); sqlite3_create_function (db, "PyramidizeMonolithic", 1, SQLITE_UTF8, 0, fnct_PyramidizeMonolithic, 0, 0); - sqlite3_create_function (db, "RL2_PyramidizeMonolithic", 1, SQLITE_UTF8, 0, - fnct_PyramidizeMonolithic, 0, 0); + sqlite3_create_function (db, "RL2_PyramidizeMonolithic", 1, SQLITE_UTF8, + 0, fnct_PyramidizeMonolithic, 0, 0); sqlite3_create_function (db, "PyramidizeMonolithic", 2, SQLITE_UTF8, 0, fnct_PyramidizeMonolithic, 0, 0); - sqlite3_create_function (db, "RL2_PyramidizeMonolithic", 2, SQLITE_UTF8, 0, - fnct_PyramidizeMonolithic, 0, 0); + sqlite3_create_function (db, "RL2_PyramidizeMonolithic", 2, SQLITE_UTF8, + 0, fnct_PyramidizeMonolithic, 0, 0); sqlite3_create_function (db, "PyramidizeMonolithic", 3, SQLITE_UTF8, 0, fnct_PyramidizeMonolithic, 0, 0); - sqlite3_create_function (db, "RL2_PyramidizeMonolithic", 3, SQLITE_UTF8, 0, - fnct_PyramidizeMonolithic, 0, 0); + sqlite3_create_function (db, "RL2_PyramidizeMonolithic", 3, SQLITE_UTF8, + 0, fnct_PyramidizeMonolithic, 0, 0); sqlite3_create_function (db, "DePyramidize", 1, SQLITE_UTF8, 0, fnct_DePyramidize, 0, 0); sqlite3_create_function (db, "RL2_DePyramidize", 1, SQLITE_UTF8, 0, fnct_DePyramidize, 0, 0); sqlite3_create_function (db, "DePyramidize", 2, SQLITE_UTF8, 0, @@ -10441,56 +10477,56 @@ fnct_GetMapImageFromRaster, 0, 0); sqlite3_create_function (db, "RL2_GetMapImageFromRaster", 11, SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data, fnct_GetMapImageFromRaster, 0, 0); sqlite3_create_function (db, "GetMapImageFromVector", 4, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data, fnct_GetMapImageFromVector, 0, 0); sqlite3_create_function (db, "RL2_GetMapImageFromVector", 4, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data, fnct_GetMapImageFromVector, 0, 0); sqlite3_create_function (db, "GetMapImageFromVector", 5, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data, fnct_GetMapImageFromVector, 0, 0); sqlite3_create_function (db, "RL2_GetMapImageFromVector", 5, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data, fnct_GetMapImageFromVector, 0, 0); sqlite3_create_function (db, "GetMapImageFromVector", 6, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data, fnct_GetMapImageFromVector, 0, 0); sqlite3_create_function (db, "RL2_GetMapImageFromVector", 6, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data, fnct_GetMapImageFromVector, 0, 0); sqlite3_create_function (db, "GetMapImageFromVector", 7, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data, fnct_GetMapImageFromVector, 0, 0); sqlite3_create_function (db, "RL2_GetMapImageFromVector", 7, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data, fnct_GetMapImageFromVector, 0, 0); sqlite3_create_function (db, "GetMapImageFromVector", 8, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data, fnct_GetMapImageFromVector, 0, 0); sqlite3_create_function (db, "RL2_GetMapImageFromVector", 8, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data, fnct_GetMapImageFromVector, 0, 0); sqlite3_create_function (db, "GetMapImageFromVector", 9, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data, fnct_GetMapImageFromVector, 0, 0); sqlite3_create_function (db, "RL2_GetMapImageFromVector", 9, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data, fnct_GetMapImageFromVector, 0, 0); sqlite3_create_function (db, "GetMapImageFromVector", 10, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data, fnct_GetMapImageFromVector, 0, 0); sqlite3_create_function (db, "RL2_GetMapImageFromVector", 10, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data, fnct_GetMapImageFromVector, 0, 0); sqlite3_create_function (db, "GetMapImageFromVector", 11, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data, fnct_GetMapImageFromVector, 0, 0); sqlite3_create_function (db, "RL2_GetMapImageFromVector", 11, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data, fnct_GetMapImageFromVector, 0, 0); sqlite3_create_function (db, "GetTileImage", 2, SQLITE_UTF8 | SQLITE_DETERMINISTIC, priv_data, fnct_GetTileImage, 0, 0); sqlite3_create_function (db, "RL2_GetTileImage", 2, @@ -10637,20 +10673,20 @@ 0, fnct_LoadFontFromFile, 0, 0); sqlite3_create_function (db, "ExportFontToFile", 2, SQLITE_UTF8, 0, fnct_ExportFontToFile, 0, 0); sqlite3_create_function (db, "RL2_ExportFontToFile", 2, SQLITE_UTF8, 0, fnct_ExportFontToFile, 0, 0); - sqlite3_create_function (db, "LoadRaster", 2, SQLITE_UTF8, priv_data, - fnct_LoadRaster, 0, 0); - sqlite3_create_function (db, "LoadRaster", 3, SQLITE_UTF8, priv_data, - fnct_LoadRaster, 0, 0); - sqlite3_create_function (db, "LoadRaster", 4, SQLITE_UTF8, priv_data, - fnct_LoadRaster, 0, 0); - sqlite3_create_function (db, "LoadRaster", 5, SQLITE_UTF8, priv_data, - fnct_LoadRaster, 0, 0); - sqlite3_create_function (db, "LoadRaster", 6, SQLITE_UTF8, priv_data, - fnct_LoadRaster, 0, 0); + sqlite3_create_function (db, "LoadRaster", 2, SQLITE_UTF8, + priv_data, fnct_LoadRaster, 0, 0); + sqlite3_create_function (db, "LoadRaster", 3, SQLITE_UTF8, + priv_data, fnct_LoadRaster, 0, 0); + sqlite3_create_function (db, "LoadRaster", 4, SQLITE_UTF8, + priv_data, fnct_LoadRaster, 0, 0); + sqlite3_create_function (db, "LoadRaster", 5, SQLITE_UTF8, + priv_data, fnct_LoadRaster, 0, 0); + sqlite3_create_function (db, "LoadRaster", 6, SQLITE_UTF8, + priv_data, fnct_LoadRaster, 0, 0); sqlite3_create_function (db, "RL2_LoadRaster", 2, SQLITE_UTF8, priv_data, fnct_LoadRaster, 0, 0); sqlite3_create_function (db, "RL2_LoadRaster", 3, SQLITE_UTF8, priv_data, fnct_LoadRaster, 0, 0); sqlite3_create_function (db, "RL2_LoadRaster", 4, SQLITE_UTF8, @@ -10669,46 +10705,58 @@ priv_data, fnct_LoadRastersFromDir, 0, 0); sqlite3_create_function (db, "LoadRastersFromDir", 6, SQLITE_UTF8, priv_data, fnct_LoadRastersFromDir, 0, 0); sqlite3_create_function (db, "LoadRastersFromDir", 7, SQLITE_UTF8, priv_data, fnct_LoadRastersFromDir, 0, 0); - sqlite3_create_function (db, "RL2_LoadRastersFromDir", 2, SQLITE_UTF8, - priv_data, fnct_LoadRastersFromDir, 0, 0); - sqlite3_create_function (db, "RL2_LoadRastersFromDir", 3, SQLITE_UTF8, - priv_data, fnct_LoadRastersFromDir, 0, 0); - sqlite3_create_function (db, "RL2_LoadRastersFromDir", 4, SQLITE_UTF8, - priv_data, fnct_LoadRastersFromDir, 0, 0); - sqlite3_create_function (db, "RL2_LoadRastersFromDir", 5, SQLITE_UTF8, - priv_data, fnct_LoadRastersFromDir, 0, 0); - sqlite3_create_function (db, "RL2_LoadRastersFromDir", 6, SQLITE_UTF8, - priv_data, fnct_LoadRastersFromDir, 0, 0); - sqlite3_create_function (db, "RL2_LoadRastersFromDir", 7, SQLITE_UTF8, - priv_data, fnct_LoadRastersFromDir, 0, 0); + sqlite3_create_function (db, "RL2_LoadRastersFromDir", 2, + SQLITE_UTF8, priv_data, + fnct_LoadRastersFromDir, 0, 0); + sqlite3_create_function (db, "RL2_LoadRastersFromDir", 3, + SQLITE_UTF8, priv_data, + fnct_LoadRastersFromDir, 0, 0); + sqlite3_create_function (db, "RL2_LoadRastersFromDir", 4, + SQLITE_UTF8, priv_data, + fnct_LoadRastersFromDir, 0, 0); + sqlite3_create_function (db, "RL2_LoadRastersFromDir", 5, + SQLITE_UTF8, priv_data, + fnct_LoadRastersFromDir, 0, 0); + sqlite3_create_function (db, "RL2_LoadRastersFromDir", 6, + SQLITE_UTF8, priv_data, + fnct_LoadRastersFromDir, 0, 0); + sqlite3_create_function (db, "RL2_LoadRastersFromDir", 7, + SQLITE_UTF8, priv_data, + fnct_LoadRastersFromDir, 0, 0); sqlite3_create_function (db, "LoadRasterFromWMS", 9, SQLITE_UTF8, priv_data, fnct_LoadRasterFromWMS, 0, 0); - sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 9, SQLITE_UTF8, - priv_data, fnct_LoadRasterFromWMS, 0, 0); + sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 9, + SQLITE_UTF8, priv_data, + fnct_LoadRasterFromWMS, 0, 0); sqlite3_create_function (db, "LoadRasterFromWMS", 10, SQLITE_UTF8, priv_data, fnct_LoadRasterFromWMS, 0, 0); - sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 10, SQLITE_UTF8, - priv_data, fnct_LoadRasterFromWMS, 0, 0); + sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 10, + SQLITE_UTF8, priv_data, + fnct_LoadRasterFromWMS, 0, 0); sqlite3_create_function (db, "LoadRasterFromWMS", 11, SQLITE_UTF8, priv_data, fnct_LoadRasterFromWMS, 0, 0); - sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 11, SQLITE_UTF8, - priv_data, fnct_LoadRasterFromWMS, 0, 0); + sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 11, + SQLITE_UTF8, priv_data, + fnct_LoadRasterFromWMS, 0, 0); sqlite3_create_function (db, "LoadRasterFromWMS", 12, SQLITE_UTF8, priv_data, fnct_LoadRasterFromWMS, 0, 0); - sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 12, SQLITE_UTF8, - priv_data, fnct_LoadRasterFromWMS, 0, 0); + sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 12, + SQLITE_UTF8, priv_data, + fnct_LoadRasterFromWMS, 0, 0); sqlite3_create_function (db, "LoadRasterFromWMS", 13, SQLITE_UTF8, priv_data, fnct_LoadRasterFromWMS, 0, 0); - sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 13, SQLITE_UTF8, - priv_data, fnct_LoadRasterFromWMS, 0, 0); + sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 13, + SQLITE_UTF8, priv_data, + fnct_LoadRasterFromWMS, 0, 0); sqlite3_create_function (db, "LoadRasterFromWMS", 14, SQLITE_UTF8, priv_data, fnct_LoadRasterFromWMS, 0, 0); - sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 14, SQLITE_UTF8, - 0, fnct_LoadRasterFromWMS, 0, 0); + sqlite3_create_function (db, "RL2_LoadRasterFromWMS", 14, + SQLITE_UTF8, 0, fnct_LoadRasterFromWMS, 0, + 0); sqlite3_create_function (db, "WriteGeoTiff", 6, SQLITE_UTF8, priv_data, fnct_WriteGeoTiff, 0, 0); sqlite3_create_function (db, "RL2_WriteGeoTiff", 6, SQLITE_UTF8, priv_data, fnct_WriteGeoTiff, 0, 0); sqlite3_create_function (db, "WriteGeoTiff", 7, SQLITE_UTF8, @@ -10815,12 +10863,13 @@ priv_data, fnct_WriteSectionTiff, 0, 0); sqlite3_create_function (db, "RL2_WriteSectionTiff", 9, SQLITE_UTF8, priv_data, fnct_WriteSectionTiff, 0, 0); sqlite3_create_function (db, "WriteSectionTiff", 10, SQLITE_UTF8, priv_data, fnct_WriteSectionTiff, 0, 0); - sqlite3_create_function (db, "RL2_WriteSectionTiff", 10, SQLITE_UTF8, - priv_data, fnct_WriteSectionTiff, 0, 0); + sqlite3_create_function (db, "RL2_WriteSectionTiff", 10, + SQLITE_UTF8, priv_data, + fnct_WriteSectionTiff, 0, 0); sqlite3_create_function (db, "WriteJpegJgw", 6, SQLITE_UTF8, priv_data, fnct_WriteJpegJgw, 0, 0); sqlite3_create_function (db, "RL2_WriteJpegJgw", 6, SQLITE_UTF8, priv_data, fnct_WriteJpegJgw, 0, 0); sqlite3_create_function (db, "WriteJpegJgw", 7, SQLITE_UTF8, @@ -10868,13 +10917,13 @@ priv_data, fnct_WriteSectionJpeg, 0, 0); sqlite3_create_function (db, "WriteSectionJpeg", 9, SQLITE_UTF8, priv_data, fnct_WriteSectionJpeg, 0, 0); sqlite3_create_function (db, "RL2_WriteSectionJpeg", 9, SQLITE_UTF8, priv_data, fnct_WriteSectionJpeg, 0, 0); - sqlite3_create_function (db, "WriteTripleBandGeoTiff", 9, SQLITE_UTF8, - priv_data, fnct_WriteTripleBandGeoTiff, 0, - 0); + sqlite3_create_function (db, "WriteTripleBandGeoTiff", 9, + SQLITE_UTF8, priv_data, + fnct_WriteTripleBandGeoTiff, 0, 0); sqlite3_create_function (db, "RL2_WriteTripleBandGeoTiff", 9, SQLITE_UTF8, priv_data, fnct_WriteTripleBandGeoTiff, 0, 0); sqlite3_create_function (db, "WriteTripleBandGeoTiff", 10, SQLITE_UTF8, priv_data, @@ -10901,36 +10950,36 @@ SQLITE_UTF8, priv_data, fnct_WriteTripleBandGeoTiff, 0, 0); sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 10, SQLITE_UTF8, 0, fnct_WriteSectionTripleBandGeoTiff, 0, 0); - sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", 10, - SQLITE_UTF8, priv_data, + sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", + 10, SQLITE_UTF8, priv_data, fnct_WriteSectionTripleBandGeoTiff, 0, 0); sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 11, SQLITE_UTF8, priv_data, fnct_WriteSectionTripleBandGeoTiff, 0, 0); - sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", 11, - SQLITE_UTF8, priv_data, + sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", + 11, SQLITE_UTF8, priv_data, fnct_WriteSectionTripleBandGeoTiff, 0, 0); sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 12, SQLITE_UTF8, priv_data, fnct_WriteSectionTripleBandGeoTiff, 0, 0); - sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", 12, - SQLITE_UTF8, priv_data, + sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", + 12, SQLITE_UTF8, priv_data, fnct_WriteSectionTripleBandGeoTiff, 0, 0); sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 13, SQLITE_UTF8, priv_data, fnct_WriteSectionTripleBandGeoTiff, 0, 0); - sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", 13, - SQLITE_UTF8, priv_data, + sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", + 13, SQLITE_UTF8, priv_data, fnct_WriteSectionTripleBandGeoTiff, 0, 0); sqlite3_create_function (db, "WriteSectionTripleBandGeoTiff", 14, SQLITE_UTF8, priv_data, fnct_WriteSectionTripleBandGeoTiff, 0, 0); - sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", 14, - SQLITE_UTF8, priv_data, + sqlite3_create_function (db, "RL2_WriteSectionTripleBandGeoTiff", + 14, SQLITE_UTF8, priv_data, fnct_WriteSectionTripleBandGeoTiff, 0, 0); sqlite3_create_function (db, "WriteMonoBandGeoTiff", 7, SQLITE_UTF8, 0, fnct_WriteMonoBandGeoTiff, 0, 0); sqlite3_create_function (db, "RL2_WriteMonoBandGeoTiff", 7, SQLITE_UTF8, priv_data, @@ -10943,17 +10992,19 @@ sqlite3_create_function (db, "WriteMonoBandGeoTiff", 9, SQLITE_UTF8, 0, fnct_WriteMonoBandGeoTiff, 0, 0); sqlite3_create_function (db, "RL2_WriteMonoBandGeoTiff", 9, SQLITE_UTF8, priv_data, fnct_WriteMonoBandGeoTiff, 0, 0); - sqlite3_create_function (db, "WriteMonoBandGeoTiff", 10, SQLITE_UTF8, - 0, fnct_WriteMonoBandGeoTiff, 0, 0); + sqlite3_create_function (db, "WriteMonoBandGeoTiff", 10, + SQLITE_UTF8, 0, fnct_WriteMonoBandGeoTiff, + 0, 0); sqlite3_create_function (db, "RL2_WriteMonoBandGeoTiff", 10, SQLITE_UTF8, priv_data, fnct_WriteMonoBandGeoTiff, 0, 0); - sqlite3_create_function (db, "WriteMonoBandGeoTiff", 11, SQLITE_UTF8, - 0, fnct_WriteMonoBandGeoTiff, 0, 0); + sqlite3_create_function (db, "WriteMonoBandGeoTiff", 11, + SQLITE_UTF8, 0, fnct_WriteMonoBandGeoTiff, + 0, 0); sqlite3_create_function (db, "RL2_WriteMonoBandGeoTiff", 11, SQLITE_UTF8, priv_data, fnct_WriteMonoBandGeoTiff, 0, 0); sqlite3_create_function (db, "WriteSectionMonoBandGeoTiff", 8, SQLITE_UTF8, priv_data, @@ -10983,13 +11034,13 @@ SQLITE_UTF8, priv_data, fnct_WriteSectionMonoBandGeoTiff, 0, 0); sqlite3_create_function (db, "RL2_WriteSectionMonoBandGeoTiff", 12, SQLITE_UTF8, priv_data, fnct_WriteSectionMonoBandGeoTiff, 0, 0); - sqlite3_create_function (db, "WriteTripleBandTiffTfw", 9, SQLITE_UTF8, - priv_data, fnct_WriteTripleBandTiffTfw, 0, - 0); + sqlite3_create_function (db, "WriteTripleBandTiffTfw", 9, + SQLITE_UTF8, priv_data, + fnct_WriteTripleBandTiffTfw, 0, 0); sqlite3_create_function (db, "RL2_WriteTripleBandTiffTfw", 9, SQLITE_UTF8, priv_data, fnct_WriteTripleBandTiffTfw, 0, 0); sqlite3_create_function (db, "WriteTripleBandTiffTfw", 10, SQLITE_UTF8, priv_data, @@ -11010,30 +11061,30 @@ SQLITE_UTF8, priv_data, fnct_WriteTripleBandTiffTfw, 0, 0); sqlite3_create_function (db, "WriteSectionTripleBandTiffTfw", 10, SQLITE_UTF8, priv_data, fnct_WriteSectionTripleBandTiffTfw, 0, 0); - sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw", 10, - SQLITE_UTF8, priv_data, + sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw", + 10, SQLITE_UTF8, priv_data, fnct_WriteSectionTripleBandTiffTfw, 0, 0); sqlite3_create_function (db, "WriteSectionTripleBandTiffTfw", 11, SQLITE_UTF8, priv_data, fnct_WriteSectionTripleBandTiffTfw, 0, 0); - sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw", 11, - SQLITE_UTF8, priv_data, + sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw", + 11, SQLITE_UTF8, priv_data, fnct_WriteSectionTripleBandTiffTfw, 0, 0); sqlite3_create_function (db, "WriteSectionTripleBandTiffTfw", 12, SQLITE_UTF8, priv_data, fnct_WriteSectionTripleBandTiffTfw, 0, 0); - sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw", 12, - SQLITE_UTF8, priv_data, + sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw", + 12, SQLITE_UTF8, priv_data, fnct_WriteSectionTripleBandTiffTfw, 0, 0); sqlite3_create_function (db, "WriteSectionTripleBandTiffTfw", 13, SQLITE_UTF8, priv_data, fnct_WriteSectionTripleBandTiffTfw, 0, 0); - sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw", 13, - SQLITE_UTF8, priv_data, + sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiffTfw", + 13, SQLITE_UTF8, priv_data, fnct_WriteSectionTripleBandTiffTfw, 0, 0); sqlite3_create_function (db, "WriteSectionMonoBandTiffTfw", 8, SQLITE_UTF8, priv_data, fnct_WriteSectionMonoBandTiffTfw, 0, 0); sqlite3_create_function (db, "RL2_WriteSectionMonoBandTiffTfw", 8, @@ -11070,17 +11121,18 @@ sqlite3_create_function (db, "WriteMonoBandTiffTfw", 9, SQLITE_UTF8, priv_data, fnct_WriteMonoBandTiffTfw, 0, 0); sqlite3_create_function (db, "RL2_WriteMonoBandTiffTfw", 9, SQLITE_UTF8, priv_data, fnct_WriteMonoBandTiffTfw, 0, 0); - sqlite3_create_function (db, "WriteMonoBandTiffTfw", 10, SQLITE_UTF8, - priv_data, fnct_WriteMonoBandTiffTfw, 0, 0); + sqlite3_create_function (db, "WriteMonoBandTiffTfw", 10, + SQLITE_UTF8, priv_data, + fnct_WriteMonoBandTiffTfw, 0, 0); sqlite3_create_function (db, "RL2_WriteMonoBandTiffTfw", 10, SQLITE_UTF8, priv_data, fnct_WriteMonoBandTiffTfw, 0, 0); - sqlite3_create_function (db, "WriteTripleBandTiff", 9, SQLITE_UTF8, 0, - fnct_WriteTripleBandTiff, 0, 0); + sqlite3_create_function (db, "WriteTripleBandTiff", 9, SQLITE_UTF8, + 0, fnct_WriteTripleBandTiff, 0, 0); sqlite3_create_function (db, "RL2_WriteTripleBandTiff", 9, SQLITE_UTF8, priv_data, fnct_WriteTripleBandTiff, 0, 0); sqlite3_create_function (db, "WriteTripleBandTiff", 10, SQLITE_UTF8, 0, fnct_WriteTripleBandTiff, 0, 0); @@ -11121,24 +11173,28 @@ sqlite3_create_function (db, "RL2_WriteSectionTripleBandTiff", 13, SQLITE_UTF8, priv_data, fnct_WriteSectionTripleBandTiff, 0, 0); sqlite3_create_function (db, "WriteMonoBandTiff", 7, SQLITE_UTF8, 0, fnct_WriteMonoBandTiff, 0, 0); - sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 7, SQLITE_UTF8, - priv_data, fnct_WriteMonoBandTiff, 0, 0); + sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 7, + SQLITE_UTF8, priv_data, + fnct_WriteMonoBandTiff, 0, 0); sqlite3_create_function (db, "WriteMonoBandTiff", 8, SQLITE_UTF8, 0, fnct_WriteMonoBandTiff, 0, 0); - sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 8, SQLITE_UTF8, - priv_data, fnct_WriteMonoBandTiff, 0, 0); + sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 8, + SQLITE_UTF8, priv_data, + fnct_WriteMonoBandTiff, 0, 0); sqlite3_create_function (db, "WriteMonoBandTiff", 9, SQLITE_UTF8, priv_data, fnct_WriteMonoBandTiff, 0, 0); - sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 9, SQLITE_UTF8, - priv_data, fnct_WriteMonoBandTiff, 0, 0); + sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 9, + SQLITE_UTF8, priv_data, + fnct_WriteMonoBandTiff, 0, 0); sqlite3_create_function (db, "WriteMonoBandTiff", 10, SQLITE_UTF8, priv_data, fnct_WriteMonoBandTiff, 0, 0); - sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 10, SQLITE_UTF8, - priv_data, fnct_WriteMonoBandTiff, 0, 0); + sqlite3_create_function (db, "RL2_WriteMonoBandTiff", 10, + SQLITE_UTF8, priv_data, + fnct_WriteMonoBandTiff, 0, 0); sqlite3_create_function (db, "WriteSectionMonoBandTiff", 8, SQLITE_UTF8, priv_data, fnct_WriteSectionMonoBandTiff, 0, 0); sqlite3_create_function (db, "RL2_WriteSectionMonoBandTiff", 8, SQLITE_UTF8, priv_data, @@ -11171,33 +11227,38 @@ priv_data, fnct_WriteAsciiGrid, 0, 0); sqlite3_create_function (db, "WriteAsciiGrid", 8, SQLITE_UTF8, priv_data, fnct_WriteAsciiGrid, 0, 0); sqlite3_create_function (db, "RL2_WriteAsciiGrid", 8, SQLITE_UTF8, priv_data, fnct_WriteAsciiGrid, 0, 0); - sqlite3_create_function (db, "WriteSectionAsciiGrid", 7, SQLITE_UTF8, - priv_data, fnct_WriteSectionAsciiGrid, 0, 0); + sqlite3_create_function (db, "WriteSectionAsciiGrid", 7, + SQLITE_UTF8, priv_data, + fnct_WriteSectionAsciiGrid, 0, 0); sqlite3_create_function (db, "RL2_WriteSectionAsciiGrid", 7, SQLITE_UTF8, priv_data, fnct_WriteSectionAsciiGrid, 0, 0); - sqlite3_create_function (db, "WriteSectionAsciiGrid", 8, SQLITE_UTF8, - 0, fnct_WriteSectionAsciiGrid, 0, 0); + sqlite3_create_function (db, "WriteSectionAsciiGrid", 8, + SQLITE_UTF8, 0, fnct_WriteSectionAsciiGrid, + 0, 0); sqlite3_create_function (db, "RL2_WriteSectionAsciiGrid", 8, SQLITE_UTF8, priv_data, fnct_WriteSectionAsciiGrid, 0, 0); - sqlite3_create_function (db, "WriteSectionAsciiGrid", 9, SQLITE_UTF8, - 0, fnct_WriteSectionAsciiGrid, 0, 0); + sqlite3_create_function (db, "WriteSectionAsciiGrid", 9, + SQLITE_UTF8, 0, fnct_WriteSectionAsciiGrid, + 0, 0); sqlite3_create_function (db, "RL2_WriteSectionAsciiGrid", 9, SQLITE_UTF8, priv_data, fnct_WriteSectionAsciiGrid, 0, 0); sqlite3_create_function (db, "WriteNdviAsciiGrid", 8, SQLITE_UTF8, priv_data, fnct_WriteNdviAsciiGrid, 0, 0); - sqlite3_create_function (db, "RL2_WriteNdviAsciiGrid", 8, SQLITE_UTF8, - priv_data, fnct_WriteNdviAsciiGrid, 0, 0); + sqlite3_create_function (db, "RL2_WriteNdviAsciiGrid", 8, + SQLITE_UTF8, priv_data, + fnct_WriteNdviAsciiGrid, 0, 0); sqlite3_create_function (db, "WriteNdviAsciiGrid", 9, SQLITE_UTF8, priv_data, fnct_WriteNdviAsciiGrid, 0, 0); - sqlite3_create_function (db, "RL2_WriteNdviAsciiGrid", 9, SQLITE_UTF8, - priv_data, fnct_WriteNdviAsciiGrid, 0, 0); + sqlite3_create_function (db, "RL2_WriteNdviAsciiGrid", 9, + SQLITE_UTF8, priv_data, + fnct_WriteNdviAsciiGrid, 0, 0); sqlite3_create_function (db, "WriteNdviAsciiGrid", 10, SQLITE_UTF8, priv_data, fnct_WriteNdviAsciiGrid, 0, 0); sqlite3_create_function (db, "RL2_WriteNdviAsciiGrid", 10, SQLITE_UTF8, priv_data, fnct_WriteNdviAsciiGrid, 0, 0); Index: src/rl2sqlaux.c ================================================================== --- src/rl2sqlaux.c +++ src/rl2sqlaux.c @@ -83,12 +83,13 @@ int bands; unsigned char xsample_type = RL2_SAMPLE_UNKNOWN; unsigned char xnum_bands = RL2_BANDS_UNKNOWN; sql = - sqlite3_mprintf ("SELECT sample_type, num_bands FROM raster_coverages " - "WHERE Lower(coverage_name) = Lower(%Q)", coverage); + sqlite3_mprintf + ("SELECT sample_type, num_bands FROM raster_coverages " + "WHERE Lower(coverage_name) = Lower(%Q)", coverage); ret = sqlite3_get_table (sqlite, sql, &results, &rows, &columns, NULL); sqlite3_free (sql); if (ret != SQLITE_OK) return 0; if (rows < 1) @@ -736,18 +737,19 @@ sqlite3_finalize (stmt); return RL2_ERROR; } static int -do_insert_wms_tile (sqlite3 * handle, unsigned char *blob_odd, int blob_odd_sz, - unsigned char *blob_even, int blob_even_sz, - sqlite3_int64 section_id, int srid, double res_x, - double res_y, unsigned int tile_w, unsigned int tile_h, - double miny, double maxx, double tile_minx, - double tile_miny, double tile_maxx, double tile_maxy, - rl2PalettePtr aux_palette, rl2PixelPtr no_data, - sqlite3_stmt * stmt_tils, sqlite3_stmt * stmt_data, +do_insert_wms_tile (sqlite3 * handle, unsigned char *blob_odd, + int blob_odd_sz, unsigned char *blob_even, + int blob_even_sz, sqlite3_int64 section_id, int srid, + double res_x, double res_y, unsigned int tile_w, + unsigned int tile_h, double miny, double maxx, + double tile_minx, double tile_miny, double tile_maxx, + double tile_maxy, rl2PalettePtr aux_palette, + rl2PixelPtr no_data, sqlite3_stmt * stmt_tils, + sqlite3_stmt * stmt_data, rl2RasterStatisticsPtr section_stats) { /* INSERTing the tile */ int ret; sqlite3_int64 tile_id; @@ -1001,12 +1003,13 @@ RL2_PRIVATE int rl2_do_insert_section (sqlite3 * handle, const char *src_path, const char *section, int srid, unsigned int width, unsigned int height, double minx, double miny, double maxx, double maxy, char *xml_summary, - int section_paths, int section_md5, int section_summary, - sqlite3_stmt * stmt_sect, sqlite3_int64 * id) + int section_paths, int section_md5, + int section_summary, sqlite3_stmt * stmt_sect, + sqlite3_int64 * id) { /* INSERTing the section */ int ret; unsigned char *blob; int blob_size; @@ -1053,12 +1056,12 @@ if (xml_summary != NULL) free (xml_summary); } sqlite3_bind_int (stmt_sect, 5, width); sqlite3_bind_int (stmt_sect, 6, height); - if (rl2_build_bbox (handle, srid, minx, miny, maxx, maxy, &blob, &blob_size) - != RL2_OK) + if (rl2_build_bbox + (handle, srid, minx, miny, maxx, maxy, &blob, &blob_size) != RL2_OK) goto error; sqlite3_bind_blob (stmt_sect, 7, blob, blob_size, free); ret = sqlite3_step (stmt_sect); if (ret == SQLITE_DONE || ret == SQLITE_ROW) section_id = sqlite3_last_insert_rowid (handle); @@ -1215,22 +1218,23 @@ int blob_even_sz; rl2RasterPtr raster = NULL; double base_res_x; double base_res_y; - if (rl2_get_coverage_resolution (ptr->coverage, &base_res_x, &base_res_y) != - RL2_OK) + if (rl2_get_coverage_resolution (ptr->coverage, &base_res_x, &base_res_y) + != RL2_OK) goto error; if (*first) { /* INSERTing the section */ *first = 0; if (!rl2_do_insert_section (ptr->sqlite, "WMS Service", ptr->sect_name, ptr->srid, ptr->width, ptr->height, ptr->minx, ptr->miny, ptr->maxx, - ptr->maxy, ptr->xml_summary, ptr->sectionPaths, ptr->sectionMD5, - ptr->sectionSummary, ptr->stmt_sect, section_id)) + ptr->maxy, ptr->xml_summary, ptr->sectionPaths, + ptr->sectionMD5, ptr->sectionSummary, ptr->stmt_sect, + section_id)) goto error; *section_stats = rl2_create_raster_statistics (ptr->sample_type, ptr->num_bands); if (*section_stats == NULL) goto error; @@ -1273,13 +1277,13 @@ tile_maxx = tile_minx + ptr->tilew; tile_maxy = ptr->y; tile_miny = tile_maxy - ptr->tileh; if (!do_insert_wms_tile (ptr->sqlite, blob_odd, blob_odd_sz, blob_even, blob_even_sz, - *section_id, ptr->srid, ptr->horz_res, ptr->vert_res, ptr->tile_width, - ptr->tile_height, ptr->miny, ptr->maxx, tile_minx, tile_miny, - tile_maxx, tile_maxy, NULL, ptr->no_data, ptr->stmt_tils, + *section_id, ptr->srid, ptr->horz_res, ptr->vert_res, + ptr->tile_width, ptr->tile_height, ptr->miny, ptr->maxx, tile_minx, + tile_miny, tile_maxx, tile_maxy, NULL, ptr->no_data, ptr->stmt_tils, ptr->stmt_data, *section_stats)) goto error; blob_odd = NULL; blob_even = NULL; rl2_destroy_raster (raster); @@ -1403,12 +1407,12 @@ sql = sqlite3_mprintf ("SELECT pyramid_level, x_resolution_1_8, y_resolution_1_8, " "x_resolution_1_4, y_resolution_1_4, x_resolution_1_2, y_resolution_1_2, " "x_resolution_1_1, y_resolution_1_1 FROM \"%s\" " - "WHERE section_id = %s ORDER BY pyramid_level DESC", xxcoverage, - sctn); + "WHERE section_id = %s ORDER BY pyramid_level DESC", + xxcoverage, sctn); } else { /* ordinary Coverage */ xcoverage = sqlite3_mprintf ("%s_levels", coverage); @@ -1614,15 +1618,15 @@ return rgba; } RL2_PRIVATE int get_payload_from_monochrome_opaque (unsigned int width, unsigned int height, - sqlite3 * handle, double minx, double miny, - double maxx, double maxy, int srid, - unsigned char *pixels, unsigned char format, - int quality, unsigned char **image, - int *image_sz) + sqlite3 * handle, double minx, + double miny, double maxx, double maxy, + int srid, unsigned char *pixels, + unsigned char format, int quality, + unsigned char **image, int *image_sz) { /* input: Monochrome output: Grayscale */ int ret; unsigned char *p_in; unsigned char *p_out; @@ -1662,12 +1666,12 @@ else if (format == RL2_OUTPUT_FORMAT_TIFF) { if (srid > 0) { if (rl2_gray_to_geotiff - (width, height, handle, minx, miny, maxx, maxy, srid, gray, - image, image_sz) != RL2_OK) + (width, height, handle, minx, miny, maxx, maxy, srid, + gray, image, image_sz) != RL2_OK) goto error; } else { if (rl2_gray_to_tiff (width, height, gray, image, image_sz) != @@ -1831,18 +1835,18 @@ else if (format == RL2_OUTPUT_FORMAT_TIFF) { if (srid > 0) { if (rl2_rgb_to_geotiff - (width, height, handle, minx, miny, maxx, maxy, srid, - rgb, image, image_sz) != RL2_OK) + (width, height, handle, minx, miny, maxx, maxy, + srid, rgb, image, image_sz) != RL2_OK) goto error; } else { - if (rl2_rgb_to_tiff (width, height, rgb, image, image_sz) - != RL2_OK) + if (rl2_rgb_to_tiff + (width, height, rgb, image, image_sz) != RL2_OK) goto error; } } else if (format == RL2_OUTPUT_FORMAT_PDF) { @@ -1894,12 +1898,12 @@ else if (format == RL2_OUTPUT_FORMAT_TIFF) { if (srid > 0) { if (rl2_gray_to_geotiff - (width, height, handle, minx, miny, maxx, maxy, srid, - gray, image, image_sz) != RL2_OK) + (width, height, handle, minx, miny, maxx, maxy, + srid, gray, image, image_sz) != RL2_OK) goto error; } else { if (rl2_gray_to_tiff @@ -2072,22 +2076,22 @@ RL2_PRIVATE int get_payload_from_grayscale_opaque (unsigned int width, unsigned int height, sqlite3 * handle, double minx, double miny, double maxx, double maxy, int srid, - unsigned char *pixels, unsigned char format, - int quality, unsigned char **image, - int *image_sz) + unsigned char *pixels, + unsigned char format, int quality, + unsigned char **image, int *image_sz) { /* input: Grayscale output: Grayscale */ int ret; unsigned char *rgba = NULL; if (format == RL2_OUTPUT_FORMAT_JPEG) { - if (rl2_gray_to_jpeg (width, height, pixels, quality, image, image_sz) - != RL2_OK) + if (rl2_gray_to_jpeg + (width, height, pixels, quality, image, image_sz) != RL2_OK) goto error; } else if (format == RL2_OUTPUT_FORMAT_PNG) { if (rl2_gray_to_png (width, height, pixels, image, image_sz) != @@ -2103,12 +2107,12 @@ pixels, image, image_sz) != RL2_OK) goto error; } else { - if (rl2_gray_to_tiff (width, height, pixels, image, image_sz) != - RL2_OK) + if (rl2_gray_to_tiff (width, height, pixels, image, image_sz) + != RL2_OK) goto error; } } else if (format == RL2_OUTPUT_FORMAT_PDF) { @@ -2194,12 +2198,12 @@ int ret; unsigned char *rgba = NULL; if (format == RL2_OUTPUT_FORMAT_JPEG) { - if (rl2_rgb_to_jpeg (width, height, pixels, quality, image, image_sz) - != RL2_OK) + if (rl2_rgb_to_jpeg + (width, height, pixels, quality, image, image_sz) != RL2_OK) goto error; } else if (format == RL2_OUTPUT_FORMAT_PNG) { if (rl2_rgb_to_png (width, height, pixels, image, image_sz) != RL2_OK) @@ -2214,12 +2218,12 @@ pixels, image, image_sz) != RL2_OK) goto error; } else { - if (rl2_rgb_to_tiff (width, height, pixels, image, image_sz) != - RL2_OK) + if (rl2_rgb_to_tiff (width, height, pixels, image, image_sz) + != RL2_OK) goto error; } } else if (format == RL2_OUTPUT_FORMAT_PDF) { @@ -2246,12 +2250,12 @@ RL2_PRIVATE int get_payload_from_rgb_transparent (unsigned int width, unsigned int height, unsigned char *pixels, unsigned char format, int quality, unsigned char **image, int *image_sz, unsigned char bg_red, - unsigned char bg_green, unsigned char bg_blue, - double opacity) + unsigned char bg_green, + unsigned char bg_blue, double opacity) { /* input: RGB output: RGB */ unsigned char *p_in; unsigned char *p_msk; unsigned char *mask = NULL; @@ -2523,17 +2527,18 @@ /* input: Monochrome output: Grayscale */ unsigned char *p_in; unsigned char *p_out; unsigned int row; unsigned int col; + p_in = pixels; p_out = rgba; for (row = 0; row < height; row++) { for (col = 0; col < width; col++) { - if (*p_in++ == 1) + if (*p_in++ == 0) { *p_out++ = 0; /* Black */ *p_out++ = 0; *p_out++ = 0; *p_out++ = 255; /* alpha */ @@ -2567,11 +2572,11 @@ p_out = rgba; for (row = 0; row < height; row++) { for (col = 0; col < width; col++) { - if (*p_in++ == 1) + if (*p_in++ == 0) { *p_out++ = 0; /* Black */ *p_out++ = 0; *p_out++ = 0; *p_out++ = 255; /* alpha */ @@ -2770,12 +2775,13 @@ return 0; } RL2_PRIVATE int get_rgba_from_palette_transparent (unsigned int width, unsigned int height, - unsigned char *pixels, rl2PalettePtr palette, - unsigned char *rgba, unsigned char bg_red, + unsigned char *pixels, + rl2PalettePtr palette, unsigned char *rgba, + unsigned char bg_red, unsigned char bg_green, unsigned char bg_blue) { /* input: Palette output: Grayscale or RGB */ rl2PrivPalettePtr plt = (rl2PrivPalettePtr) palette; @@ -2927,12 +2933,12 @@ } RL2_PRIVATE int get_rgba_from_grayscale_transparent (unsigned int width, unsigned int height, - unsigned char *pixels, unsigned char *rgba, - unsigned char bg_gray) + unsigned char *pixels, + unsigned char *rgba, unsigned char bg_gray) { /* input: Grayscale output: Grayscale */ unsigned char *p_in; unsigned char *p_out; unsigned int row; @@ -3890,12 +3896,12 @@ return 1; } RL2_PRIVATE int rgba_from_double (unsigned int width, unsigned int height, - double *pixels, unsigned char *mask, rl2PrivPixelPtr no_data, - unsigned char *rgba) + double *pixels, unsigned char *mask, + rl2PrivPixelPtr no_data, unsigned char *rgba) { /* input: DataGrid DOUBLE output: Grayscale */ double *p_in; unsigned char *p_out; unsigned char *p_msk; @@ -4061,12 +4067,12 @@ rgba_from_int16 (width, height, (short *) pixels, mask, no_data, rgba); break; case RL2_SAMPLE_UINT16: ret = - rgba_from_uint16 (width, height, (unsigned short *) pixels, mask, - no_data, rgba); + rgba_from_uint16 (width, height, (unsigned short *) pixels, + mask, no_data, rgba); break; case RL2_SAMPLE_INT32: ret = rgba_from_int32 (width, height, (int *) pixels, mask, no_data, rgba); @@ -4081,12 +4087,12 @@ rgba_from_float (width, height, (float *) pixels, mask, no_data, rgba); break; case RL2_SAMPLE_DOUBLE: ret = - rgba_from_double (width, height, (double *) pixels, mask, no_data, - rgba); + rgba_from_double (width, height, (double *) pixels, mask, + no_data, rgba); break; }; return ret; } @@ -4307,12 +4313,12 @@ rgba); break; case RL2_SAMPLE_UINT16: ret = rgba_from_multi_uint16 (width, height, num_bands, - (unsigned short *) pixels, mask, no_data, - rgba); + (unsigned short *) pixels, mask, + no_data, rgba); break; }; return ret; } @@ -4359,12 +4365,12 @@ else if (format == RL2_OUTPUT_FORMAT_TIFF) { if (srid > 0) { if (rl2_gray_to_geotiff - (width, height, handle, minx, miny, maxx, maxy, srid, gray, - image, image_sz) != RL2_OK) + (width, height, handle, minx, miny, maxx, maxy, srid, + gray, image, image_sz) != RL2_OK) goto error; } else { if (rl2_gray_to_tiff (width, height, gray, image, image_sz) != @@ -4466,12 +4472,12 @@ int ret; unsigned char *rgba = NULL; if (format == RL2_OUTPUT_FORMAT_JPEG) { - if (rl2_rgb_to_jpeg (width, height, rgb, quality, image, image_sz) != - RL2_OK) + if (rl2_rgb_to_jpeg (width, height, rgb, quality, image, image_sz) + != RL2_OK) goto error; } else if (format == RL2_OUTPUT_FORMAT_PNG) { if (rl2_rgb_to_png (width, height, rgb, image, image_sz) != RL2_OK) @@ -4513,11 +4519,12 @@ } RL2_PRIVATE int get_payload_from_rgb_rgba_transparent (unsigned int width, unsigned int height, - unsigned char *rgb, unsigned char *alpha, + unsigned char *rgb, + unsigned char *alpha, unsigned char format, int quality, unsigned char **image, int *image_sz, double opacity, int half_transparency) { /* RGB, Transparent */ Index: src/rl2svg.c ================================================================== --- src/rl2svg.c +++ src/rl2svg.c @@ -229,12 +229,14 @@ grad->y2); svg_apply_gradient_transformations (pattern, grad); stop = grad->first_stop; while (stop) { - cairo_pattern_add_color_stop_rgba (pattern, stop->offset, - stop->red, stop->green, + cairo_pattern_add_color_stop_rgba (pattern, + stop->offset, + stop->red, + stop->green, stop->blue, stop->opacity * style->opacity); stop = stop->next; } @@ -259,12 +261,14 @@ grad->fx, grad->fy, grad->r); svg_apply_gradient_transformations (pattern, grad); stop = grad->first_stop; while (stop) { - cairo_pattern_add_color_stop_rgba (pattern, stop->offset, - stop->red, stop->green, + cairo_pattern_add_color_stop_rgba (pattern, + stop->offset, + stop->red, + stop->green, stop->blue, stop->opacity * style->opacity); stop = stop->next; } @@ -290,12 +294,12 @@ cairo_set_line_join (cairo, style->stroke_linejoin); cairo_set_miter_limit (cairo, style->stroke_miterlimit); if (style->stroke_dashitems == 0 || style->stroke_dasharray == NULL) cairo_set_dash (cairo, lengths, 0, 0.0); else - cairo_set_dash (cairo, style->stroke_dasharray, style->stroke_dashitems, - style->stroke_dashoffset); + cairo_set_dash (cairo, style->stroke_dasharray, + style->stroke_dashitems, style->stroke_dashoffset); } static void svg_set_brush (cairo_t * cairo, rl2PrivSvgStylePtr style) { @@ -312,12 +316,14 @@ grad->y2); svg_apply_gradient_transformations (pattern, grad); stop = grad->first_stop; while (stop) { - cairo_pattern_add_color_stop_rgba (pattern, stop->offset, - stop->red, stop->green, + cairo_pattern_add_color_stop_rgba (pattern, + stop->offset, + stop->red, + stop->green, stop->blue, stop->opacity * style->opacity); stop = stop->next; } @@ -332,12 +338,14 @@ grad->fx, grad->fy, grad->r); svg_apply_gradient_transformations (pattern, grad); stop = grad->first_stop; while (stop) { - cairo_pattern_add_color_stop_rgba (pattern, stop->offset, - stop->red, stop->green, + cairo_pattern_add_color_stop_rgba (pattern, + stop->offset, + stop->red, + stop->green, stop->blue, stop->opacity * style->opacity); stop = stop->next; } @@ -848,15 +856,17 @@ bezier->y2, bezier->x, bezier->y); break; case RL2_SVG_CURVE_4: bezier = item->data; cairo_get_current_point (cairo, &x0, &y0); - cairo_curve_to (cairo, 2.0 / 3.0 * bezier->x1 + 1.0 / 3.0 * x0, + cairo_curve_to (cairo, + 2.0 / 3.0 * bezier->x1 + 1.0 / 3.0 * x0, 2.0 / 3.0 * bezier->y1 + 1.0 / 3.0 * y0, - 2.0 / 3.0 * bezier->x1 + 1.0 / 3.0 * bezier->x2, - 2.0 / 3.0 * bezier->y1 + 1.0 / 3.0 * bezier->y2, - bezier->y1, bezier->y2); + 2.0 / 3.0 * bezier->x1 + + 1.0 / 3.0 * bezier->x2, + 2.0 / 3.0 * bezier->y1 + + 1.0 / 3.0 * bezier->y2, bezier->y1, bezier->y2); break; case RL2_SVG_ELLIPT_ARC: arc = item->data; cairo_get_current_point (cairo, &x0, &y0); svg_arc_to_cairo (arc, x0, y0, &xc, &yc, &rx, &rotation, @@ -945,15 +955,17 @@ bezier->y2, bezier->x, bezier->y); break; case RL2_SVG_CURVE_4: bezier = item->data; cairo_get_current_point (cairo, &x0, &y0); - cairo_curve_to (cairo, 2.0 / 3.0 * bezier->x1 + 1.0 / 3.0 * x0, + cairo_curve_to (cairo, + 2.0 / 3.0 * bezier->x1 + 1.0 / 3.0 * x0, 2.0 / 3.0 * bezier->y1 + 1.0 / 3.0 * y0, - 2.0 / 3.0 * bezier->x1 + 1.0 / 3.0 * bezier->x2, - 2.0 / 3.0 * bezier->y1 + 1.0 / 3.0 * bezier->y2, - bezier->y1, bezier->y2); + 2.0 / 3.0 * bezier->x1 + + 1.0 / 3.0 * bezier->x2, + 2.0 / 3.0 * bezier->y1 + + 1.0 / 3.0 * bezier->y2, bezier->y1, bezier->y2); break; case RL2_SVG_ELLIPT_ARC: arc = item->data; cairo_get_current_point (cairo, &x0, &y0); svg_arc_to_cairo (arc, x0, y0, &xc, &yc, &rx, &rotation, Index: src/rl2symbaux.c ================================================================== --- src/rl2symbaux.c +++ src/rl2symbaux.c @@ -784,18 +784,20 @@ eval_filter (rl2PrivStyleRulePtr rule, rl2VariantArrayPtr variant) { /* evaluating a Rule Filter */ int i; rl2PrivVariantArrayPtr var = (rl2PrivVariantArrayPtr) variant; - if (rule == NULL || var == NULL) - return 1; + if (rule->column_name == NULL) + return 1; /* there is no comparison: surely true */ + if (var == NULL) + return 0; for (i = 0; i < var->count; i++) { rl2PrivVariantValuePtr val = *(var->array + i); if (val == NULL) return 0; - if (rule->column_name == NULL || val->column_name == NULL) + if (val->column_name == NULL) return 0; if (strcasecmp (rule->column_name, val->column_name) != 0) continue; switch (rule->comparison_op) { @@ -826,11 +828,12 @@ } RL2_DECLARE rl2VectorSymbolizerPtr rl2_get_symbolizer_from_feature_type_style (rl2FeatureTypeStylePtr style, double scale, - rl2VariantArrayPtr variant, int *scale_forbidden) + rl2VariantArrayPtr variant, + int *scale_forbidden) { /* return the VectorSymbolizer matching a given scale/filter from a FeatureTypeStyle */ rl2PrivVectorSymbolizerPtr symbolizer = NULL; rl2PrivStyleRulePtr pR; rl2PrivFeatureTypeStylePtr stl = (rl2PrivFeatureTypeStylePtr) style; @@ -847,12 +850,14 @@ { /* skipping any invalid rule */ pR = pR->next; continue; } + if (eval_filter (pR, variant)) { + *scale_forbidden = 0; if (pR->min_scale != DBL_MAX && pR->max_scale != DBL_MAX) { if (scale >= pR->min_scale && scale < pR->max_scale) symbolizer = pR->style; } @@ -866,19 +871,21 @@ if (scale < pR->max_scale) symbolizer = pR->style; } else symbolizer = pR->style; - if (symbolizer == NULL) + if (symbolizer == NULL) *scale_forbidden = 1; - return (rl2VectorSymbolizerPtr) symbolizer; + else + return (rl2VectorSymbolizerPtr) symbolizer; } pR = pR->next; } if (stl->else_rule != NULL) { /* applyhing the ELSE rule */ + *scale_forbidden = 0; pR = stl->else_rule; if (pR->min_scale != DBL_MAX && pR->max_scale != DBL_MAX) { if (scale >= pR->min_scale && scale < pR->max_scale) symbolizer = pR->style; @@ -893,12 +900,12 @@ if (scale < pR->max_scale) symbolizer = pR->style; } else symbolizer = pR->style; - if (symbolizer == NULL) - *scale_forbidden = 1; + if (symbolizer == NULL) + *scale_forbidden = 1; } return (rl2VectorSymbolizerPtr) symbolizer; } RL2_DECLARE int @@ -909,10 +916,15 @@ int visible; rl2PrivStyleRulePtr pR; rl2PrivFeatureTypeStylePtr stl = (rl2PrivFeatureTypeStylePtr) style; if (stl == NULL) return 0; + if (stl->first_rule == NULL) + { + /* there are no rules: unconditional visibility */ + return 1; + } pR = stl->first_rule; while (pR != NULL) { if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL) @@ -1104,13 +1116,14 @@ *selected = 1; *categorize = 0; *interpolate = 1; return RL2_OK; } - if (stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NORMALIZE || - stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_HISTOGRAM || - stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_GAMMA) + if (stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NORMALIZE + || stl->contrastEnhancement == + RL2_CONTRAST_ENHANCEMENT_HISTOGRAM + || stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_GAMMA) { /* Contrast Enhancement */ *selected = 1; *categorize = 0; *interpolate = 0; @@ -1173,13 +1186,14 @@ rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style; if (stl == NULL) return RL2_ERROR; if (stl->bandSelection == NULL) { - if (stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NORMALIZE || - stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_HISTOGRAM || - stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_GAMMA) + if (stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NORMALIZE + || stl->contrastEnhancement == + RL2_CONTRAST_ENHANCEMENT_HISTOGRAM + || stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_GAMMA) { /* Contrast Enhancement */ *selected = 1; return RL2_OK; } @@ -1203,13 +1217,14 @@ rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style; if (stl == NULL) return RL2_ERROR; if (stl->bandSelection == NULL) { - if (stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NORMALIZE || - stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_HISTOGRAM || - stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_GAMMA) + if (stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_NORMALIZE + || stl->contrastEnhancement == + RL2_CONTRAST_ENHANCEMENT_HISTOGRAM + || stl->contrastEnhancement == RL2_CONTRAST_ENHANCEMENT_GAMMA) { /* Contrast Enhancement */ *red_band = 0; *green_band = 1; *blue_band = 2; @@ -1244,15 +1259,13 @@ *gamma_value = stl->gammaValue; return RL2_OK; } RL2_DECLARE int -rl2_get_raster_symbolizer_red_band_contrast_enhancement (rl2RasterSymbolizerPtr - style, - unsigned char - *contrast_enhancement, - double *gamma_value) + rl2_get_raster_symbolizer_red_band_contrast_enhancement + (rl2RasterSymbolizerPtr style, unsigned char *contrast_enhancement, + double *gamma_value) { /* return the RasterSymbolizer RedBand ContrastEnhancement */ rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style; if (stl == NULL) return RL2_ERROR; @@ -1286,15 +1299,13 @@ } return RL2_ERROR; } RL2_DECLARE int -rl2_get_raster_symbolizer_blue_band_contrast_enhancement (rl2RasterSymbolizerPtr - style, - unsigned char - *contrast_enhancement, - double *gamma_value) + rl2_get_raster_symbolizer_blue_band_contrast_enhancement + (rl2RasterSymbolizerPtr style, unsigned char *contrast_enhancement, + double *gamma_value) { /* return the RasterSymbolizer BlueBand ContrastEnhancement */ rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style; if (stl == NULL) return RL2_ERROR; @@ -1308,15 +1319,13 @@ } return RL2_ERROR; } RL2_DECLARE int -rl2_get_raster_symbolizer_gray_band_contrast_enhancement (rl2RasterSymbolizerPtr - style, - unsigned char - *contrast_enhancement, - double *gamma_value) + rl2_get_raster_symbolizer_gray_band_contrast_enhancement + (rl2RasterSymbolizerPtr style, unsigned char *contrast_enhancement, + double *gamma_value) { /* return the RasterSymbolizer GrayBand ContrastEnhancement */ rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style; if (stl == NULL) return RL2_ERROR; @@ -1360,12 +1369,12 @@ } return RL2_ERROR; } RL2_DECLARE int -rl2_has_raster_symbolizer_color_map_interpolated (rl2RasterSymbolizerPtr style, - int *interpolated) +rl2_has_raster_symbolizer_color_map_interpolated (rl2RasterSymbolizerPtr + style, int *interpolated) { /* return if the RasterSymbolizer has an Interpolated ColorMap */ rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style; if (stl == NULL) return RL2_ERROR; @@ -1417,12 +1426,12 @@ } return RL2_ERROR; } RL2_DECLARE int -rl2_get_raster_symbolizer_color_map_category_base (rl2RasterSymbolizerPtr style, - unsigned char *red, +rl2_get_raster_symbolizer_color_map_category_base (rl2RasterSymbolizerPtr + style, unsigned char *red, unsigned char *green, unsigned char *blue) { /* return the RasterSymbolizer ColorMap Category base-color */ rl2PrivRasterSymbolizerPtr stl = (rl2PrivRasterSymbolizerPtr) style; @@ -1579,12 +1588,12 @@ graphic->first = NULL; graphic->last = NULL; graphic->opacity = 1.0; graphic->size = 10.0; graphic->rotation = 0.0; - graphic->anchor_point_x = 0.0; - graphic->anchor_point_y = 0.0; + graphic->anchor_point_x = 0.5; + graphic->anchor_point_y = 0.5; graphic->displacement_x = 0.0; graphic->displacement_y = 0.0; return graphic; } @@ -1610,12 +1619,12 @@ RL2_PRIVATE rl2PrivPointPlacementPtr rl2_create_default_point_placement () { /* creating a default PointPlacement object */ rl2PrivPointPlacementPtr place = malloc (sizeof (rl2PrivPointPlacement)); - place->anchor_point_x = 0.0; - place->anchor_point_y = 0.0; + place->anchor_point_x = 0.5; + place->anchor_point_y = 0.5; place->displacement_x = 0.0; place->displacement_y = 0.0; place->rotation = 0.0; return place; } @@ -2265,12 +2274,12 @@ ext = (rl2PrivExternalGraphicPtr) (sym->stroke->graphic->first->item); return ext->xlink_href; } RL2_DECLARE int -rl2_polygon_symbolizer_get_graphic_stroke_recode_count (rl2PolygonSymbolizerPtr - symbolizer, int *count) + rl2_polygon_symbolizer_get_graphic_stroke_recode_count + (rl2PolygonSymbolizerPtr symbolizer, int *count) { /* return how many ColorReplacement items are in a Graphic Stroke (PolygonSymbolizer) */ rl2PrivPolygonSymbolizerPtr sym = (rl2PrivPolygonSymbolizerPtr) symbolizer; if (sym == NULL) return RL2_ERROR; @@ -2303,16 +2312,13 @@ } return RL2_OK; } RL2_DECLARE int -rl2_polygon_symbolizer_get_graphic_stroke_recode_color (rl2PolygonSymbolizerPtr - symbolizer, int index, - int *color_index, - unsigned char *red, - unsigned char *green, - unsigned char *blue) + rl2_polygon_symbolizer_get_graphic_stroke_recode_color + (rl2PolygonSymbolizerPtr symbolizer, int index, int *color_index, + unsigned char *red, unsigned char *green, unsigned char *blue) { /* return a ColorReplacement item from a Graphic Stroke (PolygonSymbolizer) */ rl2PrivPolygonSymbolizerPtr sym = (rl2PrivPolygonSymbolizerPtr) symbolizer; if (sym == NULL) return RL2_ERROR; @@ -2397,12 +2403,12 @@ *width = sym->stroke->width; return RL2_OK; } RL2_DECLARE int -rl2_polygon_symbolizer_get_stroke_linejoin (rl2PolygonSymbolizerPtr symbolizer, - unsigned char *linejoin) +rl2_polygon_symbolizer_get_stroke_linejoin (rl2PolygonSymbolizerPtr + symbolizer, unsigned char *linejoin) { /* return the Polygon Symbolizer Stroke Linejoin mode */ rl2PrivPolygonSymbolizerPtr sym = (rl2PrivPolygonSymbolizerPtr) symbolizer; if (sym == NULL) return RL2_ERROR; @@ -2439,12 +2445,13 @@ *count = sym->stroke->dash_count; return RL2_OK; } RL2_DECLARE int -rl2_polygon_symbolizer_get_stroke_dash_item (rl2PolygonSymbolizerPtr symbolizer, - int index, double *item) +rl2_polygon_symbolizer_get_stroke_dash_item (rl2PolygonSymbolizerPtr + symbolizer, int index, + double *item) { /* return a Polygon Symbolizer Stroke Dash item */ rl2PrivPolygonSymbolizerPtr sym = (rl2PrivPolygonSymbolizerPtr) symbolizer; if (sym == NULL) return RL2_ERROR; @@ -3113,11 +3120,12 @@ } RL2_DECLARE int rl2_point_symbolizer_get_graphic_recode_color (rl2PointSymbolizerPtr symbolizer, int index, - int repl_index, int *color_index, + int repl_index, + int *color_index, unsigned char *red, unsigned char *green, unsigned char *blue) { /* return a ColorReplacement item from an External Graphic (PointSymbolizer) */ @@ -3190,12 +3198,13 @@ } return RL2_ERROR; } RL2_DECLARE int -rl2_point_symbolizer_mark_get_well_known_type (rl2PointSymbolizerPtr symbolizer, - int index, unsigned char *type) +rl2_point_symbolizer_mark_get_well_known_type (rl2PointSymbolizerPtr + symbolizer, int index, + unsigned char *type) { /* return the Point Symbolizer Mark WellKnownType */ int count = 0; rl2PrivMarkPtr mark; rl2PrivGraphicItemPtr item; @@ -3338,12 +3347,12 @@ } return RL2_ERROR; } RL2_DECLARE int -rl2_point_symbolizer_mark_get_stroke_linejoin (rl2PointSymbolizerPtr symbolizer, - int index, +rl2_point_symbolizer_mark_get_stroke_linejoin (rl2PointSymbolizerPtr + symbolizer, int index, unsigned char *linejoin) { /* return the Point Symbolizer Mark Stroke Linejoin mode */ int count = 0; rl2PrivMarkPtr mark; @@ -3372,12 +3381,13 @@ } return RL2_ERROR; } RL2_DECLARE int -rl2_point_symbolizer_mark_get_stroke_linecap (rl2PointSymbolizerPtr symbolizer, - int index, unsigned char *linecap) +rl2_point_symbolizer_mark_get_stroke_linecap (rl2PointSymbolizerPtr + symbolizer, int index, + unsigned char *linecap) { /* return the Point Symbolizer Stroke Mark Linecap mode */ int count = 0; rl2PrivMarkPtr mark; rl2PrivGraphicItemPtr item; @@ -3513,12 +3523,12 @@ } return RL2_ERROR; } RL2_DECLARE int -rl2_point_symbolizer_mark_has_fill (rl2PointSymbolizerPtr symbolizer, int index, - int *fill) +rl2_point_symbolizer_mark_has_fill (rl2PointSymbolizerPtr symbolizer, + int index, int *fill) { /* checks if a Point Symbolizer Mark has a Fill */ int count = 0; rl2PrivMarkPtr mark; rl2PrivGraphicItemPtr item; @@ -4196,12 +4206,12 @@ *(var->array + index) = val; return RL2_OK; } RL2_DECLARE int -rl2_set_variant_double (rl2VariantArrayPtr variant, int index, const char *name, - double value) +rl2_set_variant_double (rl2VariantArrayPtr variant, int index, + const char *name, double value) { /* setting a DOUBLE VariantValue into a VariantArray object */ rl2PrivVariantArrayPtr var = (rl2PrivVariantArrayPtr) variant; rl2PrivVariantValuePtr val; if (var == NULL) Index: src/rl2symbolizer.c ================================================================== --- src/rl2symbolizer.c +++ src/rl2symbolizer.c @@ -542,12 +542,12 @@ *val = value; return 1; } static int -parse_sld_se_color (const char *color, unsigned char *red, unsigned char *green, - unsigned char *blue) +parse_sld_se_color (const char *color, unsigned char *red, + unsigned char *green, unsigned char *blue) { /* attempting to parse a #RRGGBB hexadecimal color */ unsigned char r; unsigned char g; unsigned char b; @@ -662,13 +662,12 @@ if (style->categorize->last == NULL) { style->categorize->baseRed = red; - style-> - categorize->baseGreen = - green; + style->categorize->baseGreen + = green; style-> categorize->baseBlue = blue; } else @@ -978,12 +977,12 @@ { const char *value = (const char *) (text->content); if (value != NULL) - style->brightnessOnly = - atoi (value); + style->brightnessOnly + = atoi (value); } text = text->next; } } if (strcmp (xmode, "ReliefFactor") == 0) @@ -1058,11 +1057,12 @@ name = (const char *) (child->name); if (strcmp (name, "RasterSymbolizer") == 0) { rl2PrivStyleRulePtr rule = rl2_create_default_style_rule (); - rl2PrivRasterSymbolizerPtr symbolizer = + rl2PrivRasterSymbolizerPtr symbolizer + = rl2_create_default_raster_symbolizer (); if (symbolizer == NULL || rule == NULL) { if (symbolizer != NULL) @@ -1374,12 +1374,12 @@ { unsigned char red; unsigned char green; unsigned char blue; if (parse_sld_se_color - ((const char *) (child->content), &red, &green, - &blue)) + ((const char *) (child->content), &red, + &green, &blue)) { repl->red = red; repl->green = green; repl->blue = blue; } @@ -1548,39 +1548,39 @@ mark->stroke->red = red; mark->stroke->green = green; mark->stroke->blue = blue; } } - if (strcmp (svg_name, "stroke-width") == - 0) + if (strcmp (svg_name, "stroke-width") + == 0) mark->stroke->width = atof ((const char *) svg_value); - if (strcmp (svg_name, "stroke-linejoin") - == 0) + if (strcmp + (svg_name, "stroke-linejoin") == 0) { - if (strcmp (svg_value, "mitre") == - 0) + if (strcmp (svg_value, "mitre") + == 0) mark->stroke->linejoin = RL2_STROKE_LINEJOIN_MITRE; - if (strcmp (svg_value, "round") == - 0) + if (strcmp (svg_value, "round") + == 0) mark->stroke->linejoin = RL2_STROKE_LINEJOIN_ROUND; - if (strcmp (svg_value, "bevel") == - 0) + if (strcmp (svg_value, "bevel") + == 0) mark->stroke->linejoin = RL2_STROKE_LINEJOIN_BEVEL; } - if (strcmp (svg_name, "stroke-linecap") - == 0) + if (strcmp + (svg_name, "stroke-linecap") == 0) { - if (strcmp (svg_value, "butt") == - 0) + if (strcmp (svg_value, "butt") + == 0) mark->stroke->linecap = RL2_STROKE_LINECAP_BUTT; - if (strcmp (svg_value, "round") == - 0) + if (strcmp (svg_value, "round") + == 0) mark->stroke->linecap = RL2_STROKE_LINECAP_ROUND; if (strcmp (svg_value, "square") == 0) mark->stroke->linecap = @@ -1827,43 +1827,43 @@ sym->stroke->red = red; sym->stroke->green = green; sym->stroke->blue = blue; } } - if (strcmp (svg_name, "stroke-opacity") - == 0) + if (strcmp + (svg_name, "stroke-opacity") == 0) sym->stroke->opacity = atof ((const char *) svg_value); - if (strcmp (svg_name, "stroke-width") == - 0) + if (strcmp (svg_name, "stroke-width") + == 0) sym->stroke->width = atof ((const char *) svg_value); - if (strcmp (svg_name, "stroke-linejoin") - == 0) + if (strcmp + (svg_name, "stroke-linejoin") == 0) { - if (strcmp (svg_value, "mitre") == - 0) + if (strcmp (svg_value, "mitre") + == 0) sym->stroke->linejoin = RL2_STROKE_LINEJOIN_MITRE; - if (strcmp (svg_value, "round") == - 0) + if (strcmp (svg_value, "round") + == 0) sym->stroke->linejoin = RL2_STROKE_LINEJOIN_ROUND; - if (strcmp (svg_value, "bevel") == - 0) + if (strcmp (svg_value, "bevel") + == 0) sym->stroke->linejoin = RL2_STROKE_LINEJOIN_BEVEL; } - if (strcmp (svg_name, "stroke-linecap") - == 0) + if (strcmp + (svg_name, "stroke-linecap") == 0) { - if (strcmp (svg_value, "butt") == - 0) + if (strcmp (svg_value, "butt") + == 0) sym->stroke->linecap = RL2_STROKE_LINECAP_BUTT; - if (strcmp (svg_value, "round") == - 0) + if (strcmp (svg_value, "round") + == 0) sym->stroke->linecap = RL2_STROKE_LINECAP_ROUND; if (strcmp (svg_value, "square") == 0) sym->stroke->linecap = @@ -2026,43 +2026,43 @@ sym->stroke->red = red; sym->stroke->green = green; sym->stroke->blue = blue; } } - if (strcmp (svg_name, "stroke-opacity") - == 0) + if (strcmp + (svg_name, "stroke-opacity") == 0) sym->stroke->opacity = atof ((const char *) svg_value); - if (strcmp (svg_name, "stroke-width") == - 0) + if (strcmp (svg_name, "stroke-width") + == 0) sym->stroke->width = atof ((const char *) svg_value); - if (strcmp (svg_name, "stroke-linejoin") - == 0) + if (strcmp + (svg_name, "stroke-linejoin") == 0) { - if (strcmp (svg_value, "mitre") == - 0) + if (strcmp (svg_value, "mitre") + == 0) sym->stroke->linejoin = RL2_STROKE_LINEJOIN_MITRE; - if (strcmp (svg_value, "round") == - 0) + if (strcmp (svg_value, "round") + == 0) sym->stroke->linejoin = RL2_STROKE_LINEJOIN_ROUND; - if (strcmp (svg_value, "bevel") == - 0) + if (strcmp (svg_value, "bevel") + == 0) sym->stroke->linejoin = RL2_STROKE_LINEJOIN_BEVEL; } - if (strcmp (svg_name, "stroke-linecap") - == 0) + if (strcmp + (svg_name, "stroke-linecap") == 0) { - if (strcmp (svg_value, "butt") == - 0) + if (strcmp (svg_value, "butt") + == 0) sym->stroke->linecap = RL2_STROKE_LINECAP_BUTT; - if (strcmp (svg_value, "round") == - 0) + if (strcmp (svg_value, "round") + == 0) sym->stroke->linecap = RL2_STROKE_LINECAP_ROUND; if (strcmp (svg_value, "square") == 0) sym->stroke->linecap = @@ -2168,12 +2168,12 @@ sym->fill->red = red; sym->fill->green = green; sym->fill->blue = blue; } } - if (strcmp (svg_name, "fill-opacity") == - 0) + if (strcmp (svg_name, "fill-opacity") + == 0) sym->fill->opacity = atof (svg_value); } } child = child->next; @@ -2619,12 +2619,12 @@ (child, &svg_name, &svg_value)) { child = child->next; continue; } - if (strcmp (svg_name, "font-family") == - 0) + if (strcmp (svg_name, "font-family") + == 0) { if (sym->font_families_count < RL2_MAX_FONT_FAMILIES) { int idx = @@ -2652,19 +2652,19 @@ if (strcasecmp (svg_value, "oblique") == 0) sym->font_style = RL2_FONT_STYLE_OBLIQUE; } - if (strcmp (svg_name, "font-weight") == - 0) + if (strcmp (svg_name, "font-weight") + == 0) { if (strcasecmp (svg_value, "normal") == 0) sym->font_weight = RL2_FONT_WEIGHT_NORMAL; - if (strcasecmp (svg_value, "bold") - == 0) + if (strcasecmp + (svg_value, "bold") == 0) sym->font_weight = RL2_FONT_WEIGHT_BOLD; } if (strcmp (svg_name, "font-size") == 0) sym->font_size = atof (svg_value); @@ -3018,14 +3018,16 @@ { const char *name = (const char *) (node->name); if (strcmp (name, "LabelPlacement") == 0) { xmlNodePtr child = node->children; - if (sym->label_placement_type == RL2_LABEL_PLACEMENT_POINT + if (sym->label_placement_type == + RL2_LABEL_PLACEMENT_POINT && sym->label_placement != NULL) rl2_destroy_point_placement ((rl2PrivPointPlacementPtr) (sym->label_placement)); - if (sym->label_placement_type == RL2_LABEL_PLACEMENT_LINE + if (sym->label_placement_type == + RL2_LABEL_PLACEMENT_LINE && sym->label_placement != NULL) rl2_destroy_line_placement ((rl2PrivLinePlacementPtr) (sym->label_placement)); sym->label_placement_type = RL2_LABEL_PLACEMENT_UNKNOWN; sym->label_placement = NULL; @@ -3995,56 +3997,50 @@ pR = style->first_rule; while (pR != NULL) { /* counting max column names */ if (pR->column_name != NULL) + count++; + if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL) { - count++; - if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL) + pV = (rl2PrivVectorSymbolizerPtr) (pR->style); + item = pV->first; + while (item != NULL) { - pV = (rl2PrivVectorSymbolizerPtr) (pR->style); - item = pV->first; - while (item != NULL) + if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER + && item->symbolizer != NULL) { - if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER - && item->symbolizer != NULL) - { - text = - (rl2PrivTextSymbolizerPtr) - (item->symbolizer); - if (text->label != NULL) - count++; - } - item = item->next; + text = + (rl2PrivTextSymbolizerPtr) (item->symbolizer); + if (text->label != NULL) + count++; } + item = item->next; } } pR = pR->next; } pR = style->else_rule; if (pR != NULL) { if (pR->column_name != NULL) + count++; + if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL) { - count++; - if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL) + pV = (rl2PrivVectorSymbolizerPtr) (pR->style); + item = pV->first; + while (item != NULL) { - pV = (rl2PrivVectorSymbolizerPtr) (pR->style); - item = pV->first; - while (item != NULL) + if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER + && item->symbolizer != NULL) { - if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER - && item->symbolizer != NULL) - { - text = - (rl2PrivTextSymbolizerPtr) - (item->symbolizer); - if (text->label != NULL) - count++; - } - item = item->next; + text = + (rl2PrivTextSymbolizerPtr) (item->symbolizer); + if (text->label != NULL) + count++; } + item = item->next; } } } if (count == 0) return; @@ -4061,33 +4057,32 @@ len = strlen (pR->column_name); *(strings + i) = malloc (len + 1); strcpy (*(strings + i), pR->column_name); *(dupl + i) = 'N'; i++; - if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL) + } + if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL) + { + pV = (rl2PrivVectorSymbolizerPtr) (pR->style); + item = pV->first; + while (item != NULL) { - pV = (rl2PrivVectorSymbolizerPtr) (pR->style); - item = pV->first; - while (item != NULL) + if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER + && item->symbolizer != NULL) { - if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER - && item->symbolizer != NULL) + text = + (rl2PrivTextSymbolizerPtr) (item->symbolizer); + if (text->label != NULL) { - text = - (rl2PrivTextSymbolizerPtr) - (item->symbolizer); - if (text->label != NULL) - { - len = strlen (text->label); - *(strings + i) = malloc (len + 1); - strcpy (*(strings + i), text->label); - *(dupl + i) = 'N'; - i++; - } + len = strlen (text->label); + *(strings + i) = malloc (len + 1); + strcpy (*(strings + i), text->label); + *(dupl + i) = 'N'; + i++; } - item = item->next; } + item = item->next; } } pR = pR->next; } pR = style->else_rule; @@ -4098,33 +4093,32 @@ len = strlen (pR->column_name); *(strings + i) = malloc (len + 1); strcpy (*(strings + i), pR->column_name); *(dupl + i) = 'N'; i++; - if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL) + } + if (pR->style_type == RL2_VECTOR_STYLE && pR->style != NULL) + { + pV = (rl2PrivVectorSymbolizerPtr) (pR->style); + item = pV->first; + while (item != NULL) { - pV = (rl2PrivVectorSymbolizerPtr) (pR->style); - item = pV->first; - while (item != NULL) + if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER + && item->symbolizer != NULL) { - if (item->symbolizer_type == RL2_TEXT_SYMBOLIZER - && item->symbolizer != NULL) + text = + (rl2PrivTextSymbolizerPtr) (item->symbolizer); + if (text->label != NULL) { - text = - (rl2PrivTextSymbolizerPtr) - (item->symbolizer); - if (text->label != NULL) - { - len = strlen (text->label); - *(strings + i) = malloc (len + 1); - strcpy (*(strings + i), text->label); - *(dupl + i) = 'N'; - i++; - } + len = strlen (text->label); + *(strings + i) = malloc (len + 1); + strcpy (*(strings + i), text->label); + *(dupl + i) = 'N'; + i++; } - item = item->next; } + item = item->next; } } } for (i = 0; i < count; i++) @@ -4436,11 +4430,12 @@ return ptr; } static int rl2_group_renderer_set_raster (rl2PrivGroupRendererPtr group, int index, - const char *layer_name, rl2CoveragePtr coverage, + const char *layer_name, + rl2CoveragePtr coverage, sqlite3_int64 style_id, rl2RasterSymbolizerPtr symbolizer, rl2RasterStatisticsPtr stats) { /* setting up one of the Layers within the Group */ Index: src/rl2tiff.c ================================================================== --- src/rl2tiff.c +++ src/rl2tiff.c @@ -549,10 +549,11 @@ double cy; GTIFDefn definition; char *pString; int len; int basic = 0; + short pixel_mode = RasterPixelIsArea; TIFF *in = (TIFF *) 0; GTIF *gtif = (GTIF *) 0; /* suppressing TIFF messages */ TIFFSetErrorHandler (NULL); @@ -642,10 +643,23 @@ /* computing the pixel resolution */ origin->hResolution = (origin->maxX - origin->minX) / (double) width; origin->vResolution = (origin->maxY - origin->minY) / (double) height; origin->isGeoReferenced = 1; origin->isGeoTiff = 1; + +/* retrieving GTRasterTypeGeoKey */ + if (!GTIFKeyGet (gtif, GTRasterTypeGeoKey, &pixel_mode, 0, 1)) + pixel_mode = RasterPixelIsArea; + if (pixel_mode == RasterPixelIsPoint) + { + /* adjusting the BBOX */ + origin->minX -= origin->hResolution / 2.0; + origin->minY -= origin->vResolution / 2.0; + origin->maxX += origin->hResolution / 2.0; + origin->maxY += origin->vResolution / 2.0; + + } error: if (basic && origin->isGeoTiff == 0) recover_incomplete_geotiff (origin, in, width, height, force_srid); if (in != (TIFF *) 0) @@ -1417,11 +1431,12 @@ origin->planarConfig = PLANARCONFIG_CONTIG; } else origin->planarConfig = value16; - if (origin->bitsPerSample == 16 && origin->sampleFormat == SAMPLEFORMAT_UINT + if (origin->bitsPerSample == 16 + && origin->sampleFormat == SAMPLEFORMAT_UINT && origin->planarConfig == PLANARCONFIG_SEPARATE) ; else if (origin->bitsPerSample == 8 && origin->sampleFormat == SAMPLEFORMAT_UINT && origin->planarConfig == PLANARCONFIG_SEPARATE) @@ -2171,18 +2186,22 @@ /* accepting any resolution */ } else if (coverage->strictResolution) { /* enforcing Strict Resolution check */ - if (hResolution != coverage->hResolution) + double x_diff = fabs (coverage->hResolution - hResolution); + double y_diff = fabs (coverage->vResolution - vResolution); + double x_lim = coverage->hResolution / 1000000.0; + double y_lim = coverage->vResolution / 1000000.0; + if (x_diff > x_lim) { if (verbose) fprintf (stderr, "Mismatching Horizontal Resolution (Strict) !!!\n"); return RL2_FALSE; } - if (vResolution != coverage->vResolution) + if (y_diff > y_lim) { if (verbose) fprintf (stderr, "Mismatching Vertical Resolution (Strict) !!!\n"); return RL2_FALSE; @@ -2734,12 +2753,12 @@ if (skip) { /* skipping any not required tile */ continue; } - if (TIFFReadTile (origin->in, tiff_tile, tile_x, tile_y, 0, 0) < - 0) + if (TIFFReadTile (origin->in, tiff_tile, tile_x, tile_y, 0, 0) + < 0) goto error; if (convert != RL2_CONVERT_NO) { /* applying some format conversion */ copy_convert_tile (origin, tiff_tile, pixels, startRow, @@ -2764,12 +2783,12 @@ p_in_8 = (char *) tiff_tile; p_in_8 += y * origin->tileWidth; p_in_8 += x; p_out_8 = (char *) pixels; p_out_8 += - ((dest_y - startRow) * width) + (dest_x - - startCol); + ((dest_y - startRow) * width) + + (dest_x - startCol); break; case RL2_SAMPLE_UINT8: p_in_u8 = (unsigned char *) tiff_tile; p_in_u8 += y * origin->tileWidth * num_bands; p_in_u8 += x * num_bands; @@ -2783,12 +2802,12 @@ p_in_16 = (short *) tiff_tile; p_in_16 += y * origin->tileWidth; p_in_16 += x; p_out_16 = (short *) pixels; p_out_16 += - ((dest_y - startRow) * width) + (dest_x - - startCol); + ((dest_y - startRow) * width) + + (dest_x - startCol); break; case RL2_SAMPLE_UINT16: p_in_u16 = (unsigned short *) tiff_tile; p_in_u16 += y * origin->tileWidth * num_bands; p_in_u16 += x * num_bands; @@ -2802,39 +2821,39 @@ p_in_32 = (int *) tiff_tile; p_in_32 += y * origin->tileWidth; p_in_32 += x; p_out_32 = (int *) pixels; p_out_32 += - ((dest_y - startRow) * width) + (dest_x - - startCol); + ((dest_y - startRow) * width) + + (dest_x - startCol); break; case RL2_SAMPLE_UINT32: p_in_u32 = (unsigned int *) tiff_tile; p_in_u32 += y * origin->tileWidth; p_in_u32 += x; p_out_u32 = (unsigned int *) pixels; p_out_u32 += - ((dest_y - startRow) * width) + (dest_x - - startCol); + ((dest_y - startRow) * width) + + (dest_x - startCol); break; case RL2_SAMPLE_FLOAT: p_in_flt = (float *) tiff_tile; p_in_flt += y * origin->tileWidth; p_in_flt += x; p_out_flt = (float *) pixels; p_out_flt += - ((dest_y - startRow) * width) + (dest_x - - startCol); + ((dest_y - startRow) * width) + + (dest_x - startCol); break; case RL2_SAMPLE_DOUBLE: p_in_dbl = (double *) tiff_tile; p_in_dbl += y * origin->tileWidth; p_in_dbl += x; p_out_dbl = (double *) pixels; p_out_dbl += - ((dest_y - startRow) * width) + (dest_x - - startCol); + ((dest_y - startRow) * width) + + (dest_x - startCol); break; }; for (bnd = 0; bnd < num_bands; bnd++) { switch (sample_type) @@ -3374,58 +3393,11 @@ for (y = 0; y < height; y++) { /* scanning scanlines by row */ line_no = y + startRow; if (line_no >= origin->height) - { - switch (sample_type) - { - case RL2_SAMPLE_INT8: - p_out_8 = (char *) pixels; - for (x = 0; x < width; x++) - *p_out_8++ = 0; - break; - case RL2_SAMPLE_UINT8: - p_out_u8 = (unsigned char *) pixels; - for (x = 0; x < width * num_bands; x++) - *p_out_u8++ = 0; - break; - case RL2_SAMPLE_INT16: - p_out_16 = (short *) pixels; - for (x = 0; x < width; x++) - *p_out_16++ = 0; - break; - case RL2_SAMPLE_UINT16: - p_out_u16 = (unsigned short *) pixels; - for (x = 0; x < width * num_bands; x++) - *p_out_u16++ = 0; - break; - case RL2_SAMPLE_INT32: - p_out_32 = (int *) pixels; - for (x = 0; x < width; x++) - *p_out_32++ = 0; - break; - case RL2_SAMPLE_UINT32: - p_out_u32 = (unsigned int *) pixels; - for (x = 0; x < width; x++) - *p_out_u32++ = 0; - break; - case RL2_SAMPLE_FLOAT: - p_out_flt = (float *) pixels; - for (x = 0; x < width; x++) - *p_out_flt++ = 0; - break; - case RL2_SAMPLE_DOUBLE: - p_out_dbl = (double *) pixels; - for (x = 0; x < width; x++) - *p_out_dbl++ = 0; - break; - default: - goto error; - }; - continue; - } + continue; if (TIFFReadScanline (in, tiff_scanline, line_no, 0) < 0) goto error; if (convert != RL2_CONVERT_NO) { /* applying some format conversion */ @@ -3643,12 +3615,12 @@ p_in_u16 += x; p_out_u16 = (unsigned short *) pixels; p_out_u16 += ((dest_y - startRow) * width * num_bands) + - ((dest_x - startCol) * num_bands) + - band; + ((dest_x - + startCol) * num_bands) + band; *p_out_u16 = *p_in_u16; } if (sample_type == RL2_SAMPLE_UINT8) { p_in_u8 = (unsigned char *) tiff_tile; @@ -3656,12 +3628,12 @@ p_in_u8 += x; p_out_u8 = (unsigned char *) pixels; p_out_u8 += ((dest_y - startRow) * width * num_bands) + - ((dest_x - startCol) * num_bands) + - band; + ((dest_x - + startCol) * num_bands) + band; *p_out_u8 = *p_in_u8; } } } } @@ -3675,12 +3647,13 @@ free (tiff_tile); return RL2_ERROR; } static int -read_raw_separate_scanlines (rl2PrivTiffOriginPtr origin, unsigned short width, - unsigned short height, unsigned char sample_type, +read_raw_separate_scanlines (rl2PrivTiffOriginPtr origin, + unsigned short width, unsigned short height, + unsigned char sample_type, unsigned char num_bands, unsigned int startRow, unsigned int startCol, void *pixels) { /* reading TIFF raw strips - separate planes */ uint32 line_no; @@ -4174,11 +4147,12 @@ else { /* contiguous planar configuration */ if (origin->bitsPerSample <= 8 && origin->sampleFormat == SAMPLEFORMAT_UINT - && (origin->samplesPerPixel == 1 || origin->samplesPerPixel == 3) + && (origin->samplesPerPixel == 1 + || origin->samplesPerPixel == 3) && (pixel_type == RL2_PIXEL_MONOCHROME || pixel_type == RL2_PIXEL_PALETTE || pixel_type == RL2_PIXEL_GRAYSCALE || pixel_type == RL2_PIXEL_RGB)) { @@ -4204,13 +4178,13 @@ read_raw_tiles (origin, width, height, sample_type, num_bands, startRow, startCol, bufPixels); else ret = - read_raw_scanlines (origin, width, height, sample_type, - num_bands, startRow, startCol, - bufPixels); + read_raw_scanlines (origin, width, height, + sample_type, num_bands, startRow, + startCol, bufPixels); if (ret != RL2_OK) goto error; } } @@ -4384,12 +4358,12 @@ } /* attempting to create the tile */ if (read_from_tiff (origin, coverage->tileWidth, coverage->tileHeight, - coverage->sampleType, coverage->pixelType, coverage->nBands, startRow, - startCol, &pixels, &pixels_sz, palette) != RL2_OK) + coverage->sampleType, coverage->pixelType, coverage->nBands, + startRow, startCol, &pixels, &pixels_sz, palette) != RL2_OK) goto error; if (startCol + coverage->tileWidth > origin->width) unused_width = (startCol + coverage->tileWidth) - origin->width; if (startRow + coverage->tileHeight > origin->height) unused_height = (startRow + coverage->tileHeight) - origin->height; @@ -5080,13 +5054,14 @@ } RL2_DECLARE rl2TiffDestinationPtr rl2_create_tiff_destination (const char *path, unsigned int width, unsigned int height, unsigned char sample_type, - unsigned char pixel_type, unsigned char num_bands, - rl2PalettePtr plt, unsigned char tiff_compression, - int tiled, unsigned int tile_size) + unsigned char pixel_type, + unsigned char num_bands, rl2PalettePtr plt, + unsigned char tiff_compression, int tiled, + unsigned int tile_size) { /* attempting to create a file-based TIFF destination (no georeferencing) */ rl2PrivTiffDestinationPtr destination = NULL; if (!check_color_model (sample_type, pixel_type, num_bands, plt, tiff_compression)) @@ -5762,12 +5737,12 @@ return 0; return 1; } static int -tiff_write_strip_gray (rl2PrivTiffDestinationPtr tiff, rl2PrivRasterPtr raster, - unsigned int row) +tiff_write_strip_gray (rl2PrivTiffDestinationPtr tiff, + rl2PrivRasterPtr raster, unsigned int row) { /* writing a TIFF Grayscale scanline */ unsigned int x; unsigned char *p_in = raster->rasterBuffer; unsigned char *p_out = tiff->tiffBuffer; @@ -6165,12 +6140,13 @@ } return 1; } static int -tiff_write_tile_rgb_u8 (rl2PrivTiffDestinationPtr tiff, rl2PrivRasterPtr raster, - unsigned int row, unsigned int col) +tiff_write_tile_rgb_u8 (rl2PrivTiffDestinationPtr tiff, + rl2PrivRasterPtr raster, unsigned int row, + unsigned int col) { /* writing a TIFF RGB tile - UINT8 */ unsigned int y; unsigned int x; unsigned char *p_in = raster->rasterBuffer; @@ -6541,11 +6517,12 @@ && destination->tileHeight == rst->height) ret = tiff_write_tile_multiband16 (destination, rst, startRow, startCol); else if (destination->sampleFormat == SAMPLEFORMAT_UINT && destination->samplesPerPixel == 1 - && destination->photometric < 2 && destination->bitsPerSample == 8 + && destination->photometric < 2 + && destination->bitsPerSample == 8 && rst->sampleType == RL2_SAMPLE_UINT8 && rst->pixelType == RL2_PIXEL_GRAYSCALE && rst->nBands == 1 && destination->tileWidth == rst->width && destination->tileHeight == rst->height) ret = tiff_write_tile_gray (destination, rst, startRow, startCol); @@ -6660,11 +6637,12 @@ return RL2_ERROR; tfw = fopen (destination->tfw_path, "w"); if (tfw == NULL) { - fprintf (stderr, "RL2-TIFF writer: unable to open Worldfile \"%s\"\n", + fprintf (stderr, + "RL2-TIFF writer: unable to open Worldfile \"%s\"\n", destination->tfw_path); return RL2_ERROR; } fprintf (tfw, " %1.16f\n", destination->hResolution); fprintf (tfw, " 0.0\n"); @@ -6977,12 +6955,12 @@ free (tiff_buffer); return RL2_ERROR; } static int -rgb_tiff_common (TIFF * out, const unsigned char *buffer, unsigned short width, - unsigned short height) +rgb_tiff_common (TIFF * out, const unsigned char *buffer, + unsigned short width, unsigned short height) { /* common implementation of RGB TIFF export */ tsize_t buf_size; void *tiff_buffer = NULL; int y; @@ -7260,12 +7238,12 @@ static int output_palette_tiff (const unsigned char *buffer, unsigned short width, unsigned short height, unsigned char *red, - unsigned char *green, unsigned char *blue, int max_palette, - unsigned char **blob, int *blob_size) + unsigned char *green, unsigned char *blue, + int max_palette, unsigned char **blob, int *blob_size) { /* generating a PALETTE TIFF - actual work */ struct memfile clientdata; TIFF *out = (TIFF *) 0; @@ -7509,12 +7487,12 @@ } return RL2_OK; } static int -gray_tiff_common (TIFF * out, const unsigned char *buffer, unsigned short width, - unsigned short height) +gray_tiff_common (TIFF * out, const unsigned char *buffer, + unsigned short width, unsigned short height) { /* common implementation of Grayscale TIFF export */ tsize_t buf_size; void *tiff_buffer = NULL; int y; @@ -7989,12 +7967,12 @@ org->compression); sqlite3_free (prev); prev = xml; if (org->sampleFormat == SAMPLEFORMAT_UINT) xml = - sqlite3_mprintf ("%sunsigned integer", - prev); + sqlite3_mprintf + ("%sunsigned integer", prev); else if (org->sampleFormat == SAMPLEFORMAT_INT) xml = sqlite3_mprintf ("%ssigned integer", prev); else if (org->sampleFormat == SAMPLEFORMAT_IEEEFP) @@ -8084,12 +8062,13 @@ prev = xml; xml = sqlite3_mprintf ("%s", prev); sqlite3_free (prev); prev = xml; xml = - sqlite3_mprintf ("%s%1.10f", - prev, org->maxX - org->minX); + sqlite3_mprintf + ("%s%1.10f", prev, + org->maxX - org->minX); sqlite3_free (prev); prev = xml; xml = sqlite3_mprintf ("%s%1.10f", prev, org->maxY - org->minY); Index: src/rl2webp.c ================================================================== --- src/rl2webp.c +++ src/rl2webp.c @@ -156,12 +156,12 @@ } return RL2_OK; } static void -copy_pixels (unsigned char *out, const unsigned char *in, int width, int height, - int num_bands) +copy_pixels (unsigned char *out, const unsigned char *in, int width, + int height, int num_bands) { /* copying pixels */ int x; int y; int ib; @@ -295,12 +295,12 @@ if (quality > 100) quality = 100; if (quality < 0) quality = 75; size = - WebPEncodeRGBA (rgba, rst->width, rst->height, rst->width * 4, quality, - &output); + WebPEncodeRGBA (rgba, rst->width, rst->height, rst->width * 4, + quality, &output); free (rgba); if (size == 0) return RL2_ERROR; *webp = output; *webp_size = size; Index: src/rl2wms.c ================================================================== --- src/rl2wms.c +++ src/rl2wms.c @@ -536,12 +536,12 @@ /* populating the array */ *(cache->SortedByUrl + pos) = pI; pos++; pI = pI->Next; } - qsort (cache->SortedByUrl, cache->NumCachedItems, sizeof (wmsCachedItemPtr), - compare_url); + qsort (cache->SortedByUrl, cache->NumCachedItems, + sizeof (wmsCachedItemPtr), compare_url); } static void wmsCacheSqueeze (wmsCachePtr cache, int limit) { @@ -594,12 +594,12 @@ cache->TotalDownload += (double) size; } static void -wmsAddCachedItem (wmsCachePtr cache, const char *url, const unsigned char *item, - int size, const char *image_format) +wmsAddCachedItem (wmsCachePtr cache, const char *url, + const unsigned char *item, int size, const char *image_format) { /* adding a new WMS Cached Item */ wmsCachedItemPtr ptr; if (cache == NULL) return; @@ -1101,12 +1101,12 @@ ptr->last->next = arg; ptr->last = arg; } static void -parse_pattern_bbox (const char *value, double *minx, double *miny, double *maxx, - double *maxy) +parse_pattern_bbox (const char *value, double *minx, double *miny, + double *maxx, double *maxy) { /* parsing a BBOX arg [minx,miny,maxx,maxy] */ int step = 0; const char *p_start = value; const char *p_end = value; @@ -2029,15 +2029,15 @@ } if (cdata) { /* masking XML special characters */ if (*(p_in + i) == '<') - wmsMemBufferAppend (&outbuf, (const unsigned char *) "<", - 4); + wmsMemBufferAppend (&outbuf, + (const unsigned char *) "<", 4); else if (*(p_in + i) == '>') - wmsMemBufferAppend (&outbuf, (const unsigned char *) ">", - 4); + wmsMemBufferAppend (&outbuf, + (const unsigned char *) ">", 4); else if (*(p_in + i) == '&') wmsMemBufferAppend (&outbuf, (const unsigned char *) "&", 5); else if (*(p_in + i) == '>') wmsMemBufferAppend (&outbuf, @@ -2121,15 +2121,15 @@ } if (cdata) { /* masking XML special characters */ if (*(p_in + i) == '<') - wmsMemBufferAppend (&outbuf, (const unsigned char *) "<", - 4); + wmsMemBufferAppend (&outbuf, + (const unsigned char *) "<", 4); else if (*(p_in + i) == '>') - wmsMemBufferAppend (&outbuf, (const unsigned char *) ">", - 4); + wmsMemBufferAppend (&outbuf, + (const unsigned char *) ">", 4); else if (*(p_in + i) == '&') wmsMemBufferAppend (&outbuf, (const unsigned char *) "&", 5); else if (*(p_in + i) == '>') wmsMemBufferAppend (&outbuf, @@ -2707,12 +2707,12 @@ if (child_node->type == XML_TEXT_NODE) *contact_organization = (const char *) (child_node->content); } } - if (strcmp ((const char *) (cur_node->name), "ContactPerson") == - 0) + if (strcmp ((const char *) (cur_node->name), "ContactPerson") + == 0) { child_node = cur_node->children; if (child_node != NULL) { if (child_node->type == XML_TEXT_NODE) @@ -2754,12 +2754,12 @@ { if (child_node->type == XML_TEXT_NODE) *city = (const char *) (child_node->content); } } - if (strcmp ((const char *) (cur_node->name), "StateOrProvince") - == 0) + if (strcmp + ((const char *) (cur_node->name), "StateOrProvince") == 0) { child_node = cur_node->children; if (child_node != NULL) { if (child_node->type == XML_TEXT_NODE) @@ -2807,12 +2807,12 @@ for (cur_node = node; cur_node; cur_node = cur_node->next) { if (cur_node->type == XML_ELEMENT_NODE) { - if (strcmp ((const char *) (cur_node->name), "ContactPosition") - == 0) + if (strcmp + ((const char *) (cur_node->name), "ContactPosition") == 0) { child_node = cur_node->children; if (child_node != NULL) { if (child_node->type == XML_TEXT_NODE) @@ -2936,12 +2936,13 @@ parse_wms_contact_information (cur_node->children, &contact_person, &contact_organization, &contact_position, &postal_address, &city, - &state_province, &post_code, - &country, &voice_telephone, + &state_province, + &post_code, &country, + &voice_telephone, &fax_telephone, &email_address); if (strcmp ((const char *) (cur_node->name), "Fees") == 0) { child_node = cur_node->children; @@ -3247,12 +3248,13 @@ p = (const char *) (text->content); len = strlen (p); cap->GetTileServiceURLGet = malloc (len + 1); - strcpy (cap->GetTileServiceURLGet, - p); + strcpy + (cap->GetTileServiceURLGet, + p); } } } attr = attr->next; } @@ -3286,12 +3288,12 @@ "href") == 0) { xmlNodePtr text = attr->children; if (text->type == XML_TEXT_NODE) { - if (cap->GetTileServiceURLPost != - NULL) + if (cap->GetTileServiceURLPost + != NULL) { free (cap-> GetTileServiceURLPost); cap->GetTileServiceURLPost = NULL; @@ -3351,12 +3353,13 @@ p = (const char *) (text->content); len = strlen (p); cap->GetFeatureInfoURLGet = malloc (len + 1); - strcpy (cap->GetFeatureInfoURLGet, - p); + strcpy + (cap->GetFeatureInfoURLGet, + p); } } } attr = attr->next; } @@ -3390,12 +3393,12 @@ "href") == 0) { xmlNodePtr text = attr->children; if (text->type == XML_TEXT_NODE) { - if (cap->GetFeatureInfoURLPost != - NULL) + if (cap->GetFeatureInfoURLPost + != NULL) { free (cap->GetFeatureInfoURLPost); cap->GetFeatureInfoURLPost = NULL; } @@ -3584,12 +3587,12 @@ (format, "application/vnd.ogc.gml") == 0) ok = 1; if (strcmp (format, - "application/vnd.ogc.gml/3.1.1") == - 0) + "application/vnd.ogc.gml/3.1.1") + == 0) ok = 1; if (ok) { int len = strlen (format); cap->GmlMimeType = @@ -4379,12 +4382,12 @@ { if (cur_node->type == XML_ELEMENT_NODE) { if (strcmp ((const char *) (cur_node->name), "Service") == 0) parse_tile_service_info (cur_node, cap); - if (strcmp ((const char *) (cur_node->name), "TiledPatterns") == - 0) + if (strcmp ((const char *) (cur_node->name), "TiledPatterns") + == 0) parse_tiled_patterns (cur_node, cap); } } } @@ -4761,12 +4764,12 @@ for (; cur_node; cur_node = cur_node->next) { if (cur_node->type == XML_ELEMENT_NODE) { - if (strcmp ((const char *) (cur_node->name), "featureMember") == - 0) + if (strcmp ((const char *) (cur_node->name), "featureMember") + == 0) parse_wms_feature_member (cur_node->children, coll); } } } @@ -4831,12 +4834,12 @@ return coll; } static int -query_TileService (rl2WmsCachePtr cache_handle, wmsCapabilitiesPtr capabilities, - const char *proxy) +query_TileService (rl2WmsCachePtr cache_handle, + wmsCapabilitiesPtr capabilities, const char *proxy) { /* attempting to get and parse a WMS GetTileService request */ CURL *curl = NULL; CURLcode res; wmsMemBuffer headerBuf; @@ -6947,11 +6950,12 @@ return NULL; } RL2_DECLARE int get_wms_feature_attribute_blob_geometry (rl2WmsFeatureMemberPtr handle, - int index, const unsigned char **blob, + int index, + const unsigned char **blob, int *blob_size) { /* attempting to get the Nth FeatureAttribute (Geometry) from some WMS-FeatureMember object */ int count = 0; wmsFeatureAttributePtr attr; @@ -7065,22 +7069,22 @@ request = sqlite3_mprintf ("%s?SERVICE=WMS&REQUEST=GetMap&VERSION=%s" "&LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f" "&WIDTH=%d&HEIGHT=%d&STYLES=%s&FORMAT=%s" "&TRANSPARENT=%s&BGCOLOR=0xFFFFFF", url, - version, layer, crs_prefix, crs, miny, minx, - maxy, maxx, width, height, style, format, - (opaque == 0) ? "TRUE" : "FALSE"); + version, layer, crs_prefix, crs, miny, + minx, maxy, maxx, width, height, style, + format, (opaque == 0) ? "TRUE" : "FALSE"); else request = sqlite3_mprintf ("%s?SERVICE=WMS&REQUEST=GetMap&VERSION=%s" "&LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f" "&WIDTH=%d&HEIGHT=%d&STYLES=%s&FORMAT=%s" "&TRANSPARENT=%s&BGCOLOR=0xFFFFFF", url, - version, layer, crs_prefix, crs, minx, miny, - maxx, maxy, width, height, style, format, - (opaque == 0) ? "TRUE" : "FALSE"); + version, layer, crs_prefix, crs, minx, + miny, maxx, maxy, width, height, style, + format, (opaque == 0) ? "TRUE" : "FALSE"); } else { /* "?" marker already defined */ if (swap_xy) @@ -7087,23 +7091,24 @@ request = sqlite3_mprintf ("%sSERVICE=WMS&REQUEST=GetMap&VERSION=%s" "&LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f" "&WIDTH=%d&HEIGHT=%d&STYLES=%s&FORMAT=%s" "&TRANSPARENT=%s&BGCOLOR=0xFFFFFF", url, - version, layer, crs_prefix, crs, miny, minx, - maxy, maxx, width, height, style, format, - (opaque == 0) ? "TRUE" : "FALSE"); + version, layer, crs_prefix, crs, miny, + minx, maxy, maxx, width, height, style, + format, (opaque == 0) ? "TRUE" : "FALSE"); else request = sqlite3_mprintf ("%sSERVICE=WMS&REQUEST=GetMap&VERSION=%s" "&LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f" "&WIDTH=%d&HEIGHT=%d&STYLES=%s&FORMAT=%s" "&TRANSPARENT=%s&BGCOLOR=0xFFFFFF", url, - version, layer, crs_prefix, crs, minx, miny, - maxx, maxy, width, height, style, format, - (opaque == 0) ? "TRUE" : "FALSE"); + version, layer, crs_prefix, crs, minx, + miny, maxx, maxy, width, height, style, + format, (opaque == 0) ? "TRUE" : "FALSE"); } + fprintf (stderr, "\n%s\n", request); if (cache != NULL) { /* checks if it's already stored into the WMS Cache */ wmsCachedItemPtr cachedItem = getWmsCachedItem (cache, request); @@ -7273,15 +7278,15 @@ int from_cache, char **err_msg) { /* attempting to execute a WMS GepMap request [method POST] */ /* not yet implemented: just a stupid placeholder always returning NULL */ - if (cache_handle == NULL || url == NULL || proxy == NULL || version == NULL - || layer == NULL || crs == NULL) + if (cache_handle == NULL || url == NULL || proxy == NULL + || version == NULL || layer == NULL || crs == NULL) return NULL; - if (minx == miny || maxx == maxy || width == height || opaque == from_cache - || width == swap_xy) + if (minx == miny || maxx == maxy || width == height + || opaque == from_cache || width == swap_xy) return NULL; if (style == NULL || format == NULL || err_msg == NULL) return NULL; return NULL; } @@ -7531,43 +7536,43 @@ request = sqlite3_mprintf ("%s?SERVICE=WMS&REQUEST=GetFeatureInfo&VERSION=%s&LAYERS=%s" "&QUERY_LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f" "&WIDTH=%d&HEIGHT=%d&X=%d&Y=%d&INFO_FORMAT=%s" - "&FEATURE_COUNT=50", url, version, layer, layer, crs_prefix, - crs, miny, minx, maxy, maxx, width, height, mouse_x, - mouse_y, format); + "&FEATURE_COUNT=50", url, version, layer, layer, + crs_prefix, crs, miny, minx, maxy, maxx, width, height, + mouse_x, mouse_y, format); else request = sqlite3_mprintf ("%s?SERVICE=WMS&REQUEST=GetFeatureInfo&VERSION=%s&LAYERS=%s" "&QUERY_LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f" "&WIDTH=%d&HEIGHT=%d&X=%d&Y=%d&INFO_FORMAT=%s" - "&FEATURE_COUNT=50", url, version, layer, layer, crs_prefix, - crs, minx, miny, maxx, maxy, width, height, mouse_x, - mouse_y, format); + "&FEATURE_COUNT=50", url, version, layer, layer, + crs_prefix, crs, minx, miny, maxx, maxy, width, height, + mouse_x, mouse_y, format); } else { if (swap_xy) request = sqlite3_mprintf ("%sSERVICE=WMS&REQUEST=GetFeatureInfo&VERSION=%s&LAYERS=%s" "&QUERY_LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f" "&WIDTH=%d&HEIGHT=%d&X=%d&Y=%d&INFO_FORMAT=%s" - "&FEATURE_COUNT=50", url, version, layer, layer, crs_prefix, - crs, miny, minx, maxy, maxx, width, height, mouse_x, - mouse_y, format); + "&FEATURE_COUNT=50", url, version, layer, layer, + crs_prefix, crs, miny, minx, maxy, maxx, width, height, + mouse_x, mouse_y, format); else request = sqlite3_mprintf ("%sSERVICE=WMS&REQUEST=GetFeatureInfo&VERSION=%s&LAYERS=%s" "&QUERY_LAYERS=%s&%s=%s&BBOX=%1.6f,%1.6f,%1.6f,%1.6f" "&WIDTH=%d&HEIGHT=%d&X=%d&Y=%d&INFO_FORMAT=%s" - "&FEATURE_COUNT=50", url, version, layer, layer, crs_prefix, - crs, minx, miny, maxx, maxy, width, height, mouse_x, - mouse_y, format); + "&FEATURE_COUNT=50", url, version, layer, layer, + crs_prefix, crs, minx, miny, maxx, maxy, width, height, + mouse_x, mouse_y, format); } curl = curl_easy_init (); if (curl) { @@ -7701,13 +7706,13 @@ RL2_DECLARE rl2WmsFeatureCollectionPtr do_wms_GetFeatureInfo_post (const char *url, const char *proxy, const char *version, const char *format, const char *layer, const char *crs, int swap_xy, - double minx, double miny, double maxx, double maxy, - int width, int height, int mouse_x, int mouse_y, - char **err_msg) + double minx, double miny, double maxx, + double maxy, int width, int height, int mouse_x, + int mouse_y, char **err_msg) { /* attempting to execute a WMS GepFeatureInfo request [method POST] */ /* not yet implemented: just a stupid placeholder always returning NULL */ if (url == NULL || proxy == NULL || version == NULL || format == NULL Index: test/Makefile.am ================================================================== --- test/Makefile.am +++ test/Makefile.am @@ -19,11 +19,12 @@ test_map_trieste test_map_infrared \ test_map_orbetello test_raster_symbolizer \ test_svg test_raw test_openjpeg \ test_line_symbolizer test_polygon_symbolizer \ test_point_symbolizer test_text_symbolizer \ - test_vectors test_font test_copy_rastercov + test_vectors test_font test_copy_rastercov \ + test_tile_callback AM_CPPFLAGS = -I@srcdir@/../headers @LIBXML2_CFLAGS@ AM_LDFLAGS = -L../src -lrasterlite2 @LIBCAIRO_LIBS@ @LIBPNG_LIBS@ \ @LIBWEBP_LIBS@ @LIBLZMA_LIBS@ @LIBSPATIALITE_LIBS@ \ @LIBCURL_LIBS@ @LIBXML2_LIBS@ @LIBFREETYPE2_LIBS@ \ Index: test/Makefile.in ================================================================== --- test/Makefile.in +++ test/Makefile.in @@ -1,9 +1,9 @@ -# Makefile.in generated by automake 1.14.1 from Makefile.am. +# Makefile.in generated by automake 1.15 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2013 Free Software Foundation, Inc. +# Copyright (C) 1994-2014 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -12,11 +12,21 @@ # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ @@ -100,21 +110,20 @@ test_map_orbetello$(EXEEXT) test_raster_symbolizer$(EXEEXT) \ test_svg$(EXEEXT) test_raw$(EXEEXT) test_openjpeg$(EXEEXT) \ test_line_symbolizer$(EXEEXT) test_polygon_symbolizer$(EXEEXT) \ test_point_symbolizer$(EXEEXT) test_text_symbolizer$(EXEEXT) \ test_vectors$(EXEEXT) test_font$(EXEEXT) \ - test_copy_rastercov$(EXEEXT) + test_copy_rastercov$(EXEEXT) test_tile_callback$(EXEEXT) subdir = test -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ - $(top_srcdir)/depcomp $(top_srcdir)/test-driver ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = check_sql_stmt_SOURCES = check_sql_stmt.c @@ -293,10 +302,13 @@ test_text_symbolizer_OBJECTS = test_text_symbolizer.$(OBJEXT) test_text_symbolizer_LDADD = $(LDADD) test_tifin_SOURCES = test_tifin.c test_tifin_OBJECTS = test_tifin.$(OBJEXT) test_tifin_LDADD = $(LDADD) +test_tile_callback_SOURCES = test_tile_callback.c +test_tile_callback_OBJECTS = test_tile_callback.$(OBJEXT) +test_tile_callback_LDADD = $(LDADD) test_vectors_SOURCES = test_vectors.c test_vectors_OBJECTS = test_vectors.$(OBJEXT) test_vectors_LDADD = $(LDADD) test_webp_SOURCES = test_webp.c test_webp_OBJECTS = test_webp.$(OBJEXT) @@ -357,12 +369,12 @@ test_map_srtm.c test_map_trento.c test_map_trieste.c \ test_mask.c test_openjpeg.c test_paint.c test_palette.c \ test_point_symbolizer.c test_polygon_symbolizer.c \ test_raster.c test_raster_symbolizer.c test_raw.c \ test_section.c test_svg.c test_text_symbolizer.c test_tifin.c \ - test_vectors.c test_webp.c test_wms1.c test_wms2.c \ - test_wr_tiff.c + test_tile_callback.c test_vectors.c test_webp.c test_wms1.c \ + test_wms2.c test_wr_tiff.c DIST_SOURCES = check_sql_stmt.c test1.c test10.c test11.c test12.c \ test13.c test14.c test15.c test16.c test17.c test18.c test19.c \ test2.c test20.c test3.c test4.c test5.c test6.c test7.c \ test8.c test9.c test_copy_rastercov.c test_coverage.c \ test_font.c test_gif.c test_line_symbolizer.c test_load_wms.c \ @@ -374,12 +386,12 @@ test_map_srtm.c test_map_trento.c test_map_trieste.c \ test_mask.c test_openjpeg.c test_paint.c test_palette.c \ test_point_symbolizer.c test_polygon_symbolizer.c \ test_raster.c test_raster_symbolizer.c test_raw.c \ test_section.c test_svg.c test_text_symbolizer.c test_tifin.c \ - test_vectors.c test_webp.c test_wms1.c test_wms2.c \ - test_wr_tiff.c + test_tile_callback.c test_vectors.c test_webp.c test_wms1.c \ + test_wms2.c test_wr_tiff.c RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ ctags-recursive dvi-recursive html-recursive info-recursive \ install-data-recursive install-dvi-recursive \ install-exec-recursive install-html-recursive \ install-info-recursive install-pdf-recursive \ @@ -620,10 +632,12 @@ TEST_LOGS = $(am__test_logs2:.test.log=.log) TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \ $(TEST_LOG_FLAGS) DIST_SUBDIRS = $(SUBDIRS) +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp \ + $(top_srcdir)/test-driver DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) am__relativize = \ dir0=`pwd`; \ sed_first='s,^\([^/]*\)/.*$$,\1,'; \ sed_rest='s,^[^/]*/*,,'; \ @@ -887,11 +901,10 @@ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu test/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu test/Makefile -.PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ @@ -1146,10 +1159,14 @@ $(AM_V_CCLD)$(LINK) $(test_text_symbolizer_OBJECTS) $(test_text_symbolizer_LDADD) $(LIBS) test_tifin$(EXEEXT): $(test_tifin_OBJECTS) $(test_tifin_DEPENDENCIES) $(EXTRA_test_tifin_DEPENDENCIES) @rm -f test_tifin$(EXEEXT) $(AM_V_CCLD)$(LINK) $(test_tifin_OBJECTS) $(test_tifin_LDADD) $(LIBS) + +test_tile_callback$(EXEEXT): $(test_tile_callback_OBJECTS) $(test_tile_callback_DEPENDENCIES) $(EXTRA_test_tile_callback_DEPENDENCIES) + @rm -f test_tile_callback$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(test_tile_callback_OBJECTS) $(test_tile_callback_LDADD) $(LIBS) test_vectors$(EXEEXT): $(test_vectors_OBJECTS) $(test_vectors_DEPENDENCIES) $(EXTRA_test_vectors_DEPENDENCIES) @rm -f test_vectors$(EXEEXT) $(AM_V_CCLD)$(LINK) $(test_vectors_OBJECTS) $(test_vectors_LDADD) $(LIBS) @@ -1231,10 +1248,11 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_raw.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_section.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_svg.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_text_symbolizer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_tifin.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_tile_callback.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_vectors.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_webp.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_wms1.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_wms2.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_wr_tiff.Po@am__quote@ @@ -1393,11 +1411,11 @@ fi; \ fi; \ if test -n "$$am__remaking_logs"; then \ echo "fatal: making $(TEST_SUITE_LOG): possible infinite" \ "recursion detected" >&2; \ - else \ + elif test -n "$$redo_logs"; then \ am__remaking_logs=yes $(MAKE) $(AM_MAKEFLAGS) $$redo_logs; \ fi; \ if $(am__make_dryrun); then :; else \ st=0; \ errmsg="fatal: making $(TEST_SUITE_LOG): failed to create"; \ @@ -1945,10 +1963,17 @@ b='test_copy_rastercov'; \ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) +test_tile_callback.log: test_tile_callback$(EXEEXT) + @p='test_tile_callback$(EXEEXT)'; \ + b='test_tile_callback'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) .test.log: @p='$<'; \ $(am__set_b); \ $(am__check_pre) $(TEST_LOG_DRIVER) --test-name "$$f" \ --log-file $$b.log --trs-file $$b.trs \ @@ -2143,10 +2168,12 @@ install-strip installcheck installcheck-am installdirs \ installdirs-am maintainer-clean maintainer-clean-generic \ mostlyclean mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool pdf pdf-am ps ps-am recheck tags tags-am \ uninstall uninstall-am + +.PRECIOUS: Makefile # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: Index: test/sql_stmt_security_tests/Makefile.in ================================================================== --- test/sql_stmt_security_tests/Makefile.in +++ test/sql_stmt_security_tests/Makefile.in @@ -1,9 +1,9 @@ -# Makefile.in generated by automake 1.14.1 from Makefile.am. +# Makefile.in generated by automake 1.15 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2013 Free Software Foundation, Inc. +# Copyright (C) 1994-2014 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -12,11 +12,21 @@ # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ @@ -76,18 +86,18 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ subdir = test/sql_stmt_security_tests -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = AM_V_P = $(am__v_P_@AM_V@) @@ -108,10 +118,11 @@ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +am__DIST_COMMON = $(srcdir)/Makefile.in DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ @@ -898,11 +909,10 @@ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu test/sql_stmt_security_tests/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu test/sql_stmt_security_tests/Makefile -.PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ @@ -1072,10 +1082,12 @@ install-pdf install-pdf-am install-ps install-ps-am \ install-strip installcheck installcheck-am installdirs \ maintainer-clean maintainer-clean-generic mostlyclean \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags-am uninstall uninstall-am + +.PRECIOUS: Makefile # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: Index: test/sql_stmt_tests/Makefile.in ================================================================== --- test/sql_stmt_tests/Makefile.in +++ test/sql_stmt_tests/Makefile.in @@ -1,9 +1,9 @@ -# Makefile.in generated by automake 1.14.1 from Makefile.am. +# Makefile.in generated by automake 1.15 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2013 Free Software Foundation, Inc. +# Copyright (C) 1994-2014 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -12,11 +12,21 @@ # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ @@ -76,18 +86,18 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ subdir = test/sql_stmt_tests -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = AM_V_P = $(am__v_P_@AM_V@) @@ -108,10 +118,11 @@ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +am__DIST_COMMON = $(srcdir)/Makefile.in DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ @@ -870,11 +881,10 @@ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu test/sql_stmt_tests/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu test/sql_stmt_tests/Makefile -.PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ @@ -1044,11 +1054,13 @@ install-pdf install-pdf-am install-ps install-ps-am \ install-strip installcheck installcheck-am installdirs \ maintainer-clean maintainer-clean-generic mostlyclean \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags-am uninstall uninstall-am + +.PRECIOUS: Makefile version.testcase # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: Index: test/symbolizers.sqlite ================================================================== --- test/symbolizers.sqlite +++ test/symbolizers.sqlite cannot compute difference between binary files Index: test/test_line_symbolizer.c ================================================================== --- test/test_line_symbolizer.c +++ test/test_line_symbolizer.c @@ -1074,11 +1074,11 @@ { fprintf (stderr, "Unable to get Line Symbolizer GetStrokeColor #4\n"); *retcode += 18; return 0; } - if (red != 0x00 || green != 0x00 || blue != 0xff) + if (red != 0x80 || green != 0x80 || blue != 0x80) { fprintf (stderr, "Unexpected Line Symbolizer GetStrokeColor #4: %02x%02x%02x\n", red, green, blue); *retcode += 19; @@ -1313,11 +1313,11 @@ { fprintf (stderr, "Unable to get Line Symbolizer GetStrokeColor #9\n"); *retcode += 48; return 0; } - if (red != 0x00 || green != 0x00 || blue != 0xff) + if (red != 0x80 || green != 0x80 || blue != 0x80) { fprintf (stderr, "Unexpected Line Symbolizer GetStrokeColor #9: %02x%02x%02x\n", red, green, blue); *retcode += 49; @@ -1361,11 +1361,11 @@ fprintf (stderr, "Unable to get Line Symbolizer GetStrokeColor #10\n"); *retcode += 54; return 0; } - if (red != 0x00 || green != 0x00 || blue != 0xff) + if (red != 0x80 || green != 0x80 || blue != 0x80) { fprintf (stderr, "Unexpected Line Symbolizer GetStrokeColor #10: %02x%02x%02x\n", red, green, blue); *retcode += 55; @@ -1409,11 +1409,11 @@ fprintf (stderr, "Unable to get Line Symbolizer GetStrokeColor #11\n"); *retcode += 60; return 0; } - if (red != 0x00 || green != 0x00 || blue != 0xff) + if (red != 0x80 || green != 0x80 || blue != 0x80) { fprintf (stderr, "Unexpected Line Symbolizer GetStrokeColor #11: %02x%02x%02x\n", red, green, blue); *retcode += 61; Index: test/test_point_symbolizer.c ================================================================== --- test/test_point_symbolizer.c +++ test/test_point_symbolizer.c @@ -788,11 +788,11 @@ if (dblval == 3.0 && dblval2 == 2.0) intval = 1; } else { - if (dblval == 0.0 && dblval2 == 0.0) + if (dblval == 0.5 && dblval2 == 0.5) intval = 1; } if (intval != 1) { fprintf (stderr, Index: test/test_polygon_symbolizer.c ================================================================== --- test/test_polygon_symbolizer.c +++ test/test_polygon_symbolizer.c @@ -1508,11 +1508,11 @@ fprintf (stderr, "Unexpected NULL VectorSymbolizer (%s) #6\n", style_name); *retcode += 22; return 0; } - polyg = rl2_get_polygon_symbolizer (symbolizer, 0); + polyg = rl2_get_polygon_symbolizer (symbolizer, 1); if (polyg == NULL) { fprintf (stderr, "Unable to get Polygon Symbolizer #5\n"); *retcode += 23; return 0; @@ -1523,11 +1523,11 @@ fprintf (stderr, "Unable to get Polygon Symbolizer GetFillColor #4\n"); *retcode += 24; return 0; } - if (red != 0x70 || green != 0xff || blue != 0xc0) + if (red != 0x37 || green != 0x81 || blue != 0xf2) { fprintf (stderr, "Unexpected Polygon Symbolizer GetStrokeColor #5: %02x%02x%02x\n", red, green, blue); *retcode += 25; ADDED test/test_tile_callback.c Index: test/test_tile_callback.c ================================================================== --- test/test_tile_callback.c +++ test/test_tile_callback.c @@ -0,0 +1,657 @@ +/* + + test_tile_callback.c -- RasterLite2 Test Case + + Author: Alessandro Furieri + + ------------------------------------------------------------------------------ + + Version: MPL 1.1/GPL 2.0/LGPL 2.1 + + The contents of this file are subject to the Mozilla Public License Version + 1.1 (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" basis, +WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +for the specific language governing rights and limitations under the +License. + +The Original Code is the RasterLite2 library + +The Initial Developer of the Original Code is Alessandro Furieri + +Portions created by the Initial Developer are Copyright (C) 2013 +the Initial Developer. All Rights Reserved. + +Contributor(s): + +Alternatively, the contents of this file may be used under the terms of +either the GNU General Public License Version 2 or later (the "GPL"), or +the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +in which case the provisions of the GPL or the LGPL are applicable instead +of those above. If you wish to allow use of your version of this file only +under the terms of either the GPL or the LGPL, and not to allow others to +use your version of this file under the terms of the MPL, indicate your +decision by deleting the provisions above and replace them with the notice +and other provisions required by the GPL or the LGPL. If you do not delete +the provisions above, a recipient may use your version of this file under +the terms of any one of the MPL, the GPL or the LGPL. +*/ +#include +#include +#include +#include + +#include "config.h" + +#include "sqlite3.h" +#include "spatialite.h" + +#include "rasterlite2/rasterlite2.h" + +struct tile_info +{ +/* a struct supporting the Tile Callback function */ + unsigned char sample; + unsigned char pixel; + unsigned char num_bands; + int srid; + const char *coverage; + unsigned int tile_w; + unsigned int tile_h; +}; + +static void +set_tile_pixel_gray8 (unsigned char *bufpix, unsigned int x, unsigned int y, + unsigned int tile_w, double map_x, double map_y) +{ +/* pixel generator - GRAYSCALE UINT8 */ + unsigned char *p = bufpix + ((y * tile_w) + x); + if (map_y >= -15.0 && map_y <= 15.0) + { + if (map_x < 0.0) + *p = 248; + else + *p = 216; + } + else if (map_y >= -60.0 && map_y <= 60.0) + { + if (map_x < 0.0) + *p = 208; + else + *p = 192; + } + else + { + if (map_x < 0.0) + *p = 128; + else + *p = 96; + } +} + +static void +set_tile_pixel_rgb8 (unsigned char *bufpix, unsigned int x, unsigned int y, + unsigned int tile_w, double map_x, double map_y, + unsigned int num_bands) +{ +/* pixel generator - RGB UINT8 */ + unsigned char *p = bufpix + (y * tile_w * num_bands) + (x * num_bands); + if (map_y >= -15.0 && map_y <= 15.0) + { + if (map_x < 0.0) + { + *p++ = 248; + *p++ = 255; + *p++ = 0; + } + else + { + *p++ = 216; + *p++ = 248; + *p++ = 0; + } + } + else if (map_y >= -60.0 && map_y <= 60.0) + { + if (map_x < 0.0) + { + *p++ = 0; + *p++ = 208; + *p++ = 248; + } + else + { + *p++ = 0; + *p++ = 192; + *p++ = 248; + } + } + else + { + if (map_x < 0.0) + { + *p++ = 192; + *p++ = 192; + *p++ = 128; + } + else + { + *p++ = 192; + *p++ = 192; + *p++ = 96; + } + } +} + +static void +set_tile_pixel_int16 (unsigned char *bufpix, unsigned int x, unsigned int y, + unsigned int tile_w, double map_x, double map_y) +{ +/* pixel generator - DATAGRID INT16 */ + short *p = (short *) bufpix; + p += ((y * tile_w) + x); + if (map_y >= -15.0 && map_y <= 15.0) + { + if (map_x < 0.0) + *p = -10; + else + *p = 50; + } + else if (map_y >= -60.0 && map_y <= 60.0) + { + if (map_x < 0.0) + *p = 100; + else + *p = 200; + } + else + { + if (map_x < 0.0) + *p = -100; + else + *p = -50; + } +} + +static void +set_tile_pixel_double (unsigned char *bufpix, unsigned int x, unsigned int y, + unsigned int tile_w, double map_x, double map_y) +{ +/* pixel generator - DATAGRID DOUBLE */ + double *p = (double *) bufpix; + p += ((y * tile_w) + x); + if (map_y >= -15.0 && map_y <= 15.0) + { + if (map_x < 0.0) + *p = -10.06; + else + *p = 50.02; + } + else if (map_y >= -60.0 && map_y <= 60.0) + { + if (map_x < 0.0) + *p = 100.03; + else + *p = 200.81; + } + else + { + if (map_x < 0.0) + *p = -100.23; + else + *p = -50.41; + } +} + +static void +set_tile_pixel_uint8 (unsigned char *bufpix, unsigned int x, unsigned int y, + unsigned int tile_w, double map_x, double map_y, + unsigned char pixel, unsigned char num_bands) +{ +/* pixel generator - UINT8 */ + switch (pixel) + { + case RL2_PIXEL_GRAYSCALE: + set_tile_pixel_gray8 (bufpix, x, y, tile_w, map_x, map_y); + break; + case RL2_PIXEL_RGB: + set_tile_pixel_rgb8 (bufpix, x, y, tile_w, map_x, map_y, num_bands); + break; + }; +} + +static void +set_tile_pixel (unsigned char *bufpix, unsigned int x, unsigned int y, + unsigned int tile_w, double map_x, double map_y, + unsigned char sample, unsigned char pixel, + unsigned int num_bands) +{ +/* generalized pixel generator */ + switch (sample) + { + case RL2_SAMPLE_UINT8: + set_tile_pixel_uint8 (bufpix, x, y, tile_w, map_x, map_y, pixel, + num_bands); + break; + case RL2_SAMPLE_INT16: + set_tile_pixel_int16 (bufpix, x, y, tile_w, map_x, map_y); + break; + case RL2_SAMPLE_DOUBLE: + set_tile_pixel_double (bufpix, x, y, tile_w, map_x, map_y); + break; + }; +} + +static int +tile_callback (void *data, double tile_minx, double tile_miny, double tile_maxx, + double tile_maxy, unsigned char *bufpix, rl2PalettePtr * palette) +{ +/* callback function initializing a Tile */ + struct tile_info *info = (struct tile_info *) data; + unsigned int x; + unsigned int y; + double res_x = (tile_maxx - tile_minx) / (double) (info->tile_w); + double res_y = (tile_maxy - tile_miny) / (double) (info->tile_h); + +/* setting tile pixels */ + for (y = 0; y < info->tile_h; y++) + { + double map_y = tile_maxy - ((double) y * res_y); + if (map_y < tile_miny) + continue; + for (x = 0; x < info->tile_w; x++) + { + double map_x = tile_minx + ((double) x * res_x); + if (map_x > tile_maxx) + continue; + set_tile_pixel (bufpix, x, y, info->tile_w, map_x, map_y, + info->sample, info->pixel, info->num_bands); + } + } + + return 1; +} + +static rl2PixelPtr +default_nodata (unsigned char sample, unsigned char pixel, + unsigned char num_bands) +{ +/* creating a default NO-DATA value */ + int nb; + rl2PixelPtr pxl = rl2_create_pixel (sample, pixel, num_bands); + if (pxl == NULL) + return NULL; + switch (pixel) + { + case RL2_PIXEL_MONOCHROME: + rl2_set_pixel_sample_1bit (pxl, 0); + break; + case RL2_PIXEL_PALETTE: + switch (sample) + { + case RL2_SAMPLE_1_BIT: + rl2_set_pixel_sample_1bit (pxl, 0); + break; + case RL2_SAMPLE_2_BIT: + rl2_set_pixel_sample_2bit (pxl, 0); + break; + case RL2_SAMPLE_4_BIT: + rl2_set_pixel_sample_4bit (pxl, 0); + break; + case RL2_SAMPLE_UINT8: + rl2_set_pixel_sample_uint8 (pxl, 0, 0); + break; + }; + break; + case RL2_PIXEL_GRAYSCALE: + switch (sample) + { + case RL2_SAMPLE_1_BIT: + rl2_set_pixel_sample_1bit (pxl, 1); + break; + case RL2_SAMPLE_2_BIT: + rl2_set_pixel_sample_2bit (pxl, 3); + break; + case RL2_SAMPLE_4_BIT: + rl2_set_pixel_sample_4bit (pxl, 15); + break; + case RL2_SAMPLE_UINT8: + rl2_set_pixel_sample_uint8 (pxl, 0, 255); + break; + case RL2_SAMPLE_UINT16: + rl2_set_pixel_sample_uint16 (pxl, 0, 0); + break; + }; + break; + case RL2_PIXEL_RGB: + switch (sample) + { + case RL2_SAMPLE_UINT8: + rl2_set_pixel_sample_uint8 (pxl, 0, 255); + rl2_set_pixel_sample_uint8 (pxl, 1, 255); + rl2_set_pixel_sample_uint8 (pxl, 2, 255); + break; + case RL2_SAMPLE_UINT16: + rl2_set_pixel_sample_uint16 (pxl, 0, 0); + rl2_set_pixel_sample_uint16 (pxl, 1, 0); + rl2_set_pixel_sample_uint16 (pxl, 2, 0); + break; + }; + break; + case RL2_PIXEL_DATAGRID: + switch (sample) + { + case RL2_SAMPLE_INT8: + rl2_set_pixel_sample_int8 (pxl, 0); + break; + case RL2_SAMPLE_UINT8: + rl2_set_pixel_sample_uint8 (pxl, 0, 0); + break; + case RL2_SAMPLE_INT16: + rl2_set_pixel_sample_int16 (pxl, 0); + break; + case RL2_SAMPLE_UINT16: + rl2_set_pixel_sample_uint16 (pxl, 0, 0); + break; + case RL2_SAMPLE_INT32: + rl2_set_pixel_sample_int32 (pxl, 0); + break; + case RL2_SAMPLE_UINT32: + rl2_set_pixel_sample_uint32 (pxl, 0); + break; + case RL2_SAMPLE_FLOAT: + rl2_set_pixel_sample_float (pxl, 0.0); + break; + case RL2_SAMPLE_DOUBLE: + rl2_set_pixel_sample_double (pxl, 0.0); + break; + }; + break; + case RL2_PIXEL_MULTIBAND: + switch (sample) + { + case RL2_SAMPLE_UINT8: + for (nb = 0; nb < num_bands; nb++) + rl2_set_pixel_sample_uint8 (pxl, nb, 255); + break; + case RL2_SAMPLE_UINT16: + for (nb = 0; nb < num_bands; nb++) + rl2_set_pixel_sample_uint16 (pxl, nb, 0); + break; + }; + break; + }; + return pxl; +} + +static int +test_uint8_gray (sqlite3 * handle) +{ +/* testing UINT8 GRAYSCALE */ + struct tile_info info; + rl2CoveragePtr cvg; + + info.sample = RL2_SAMPLE_UINT8; + info.pixel = RL2_PIXEL_GRAYSCALE; + info.num_bands = 1; + info.srid = 4326; + info.coverage = "UINT8_GRAYSCALE"; + info.tile_w = 512; + info.tile_h = 512; + + rl2PixelPtr no_data = + default_nodata (info.sample, info.pixel, info.num_bands); + if (rl2_create_dbms_coverage + (handle, info.coverage, info.sample, info.pixel, info.num_bands, + RL2_COMPRESSION_PNG, 100, info.tile_w, info.tile_h, info.srid, 0.1, + 0.1, no_data, NULL, 1, 0, 0, 0, 0) != RL2_OK) + { + fprintf (stderr, "Unable to create Coverage \"%s\"\n", info.coverage); + return 0; + } + + cvg = rl2_create_coverage_from_dbms (handle, info.coverage); + if (cvg == NULL) + { + rl2_destroy_coverage (cvg); + return 0; + } + + if (rl2_load_raw_tiles_into_dbms + (handle, cvg, "Alpha", 3600, 1800, info.srid, -180, -90, 180, 90, + tile_callback, &info, 1) != RL2_OK) + { + fprintf (stderr, "Unable to populate Tiles on Coverage \"%s\"\n", + info.coverage); + return 0; + } + + rl2_destroy_coverage (cvg); + rl2_destroy_pixel (no_data); + return 1; +} + +static int +test_uint8_rgb (sqlite3 * handle) +{ +/* testing UINT8 RGB */ + struct tile_info info; + rl2CoveragePtr cvg; + + info.sample = RL2_SAMPLE_UINT8; + info.pixel = RL2_PIXEL_RGB; + info.num_bands = 3; + info.srid = 4326; + info.coverage = "UINT8_RGB"; + info.tile_w = 512; + info.tile_h = 512; + + rl2PixelPtr no_data = + default_nodata (info.sample, info.pixel, info.num_bands); + if (rl2_create_dbms_coverage + (handle, info.coverage, info.sample, info.pixel, info.num_bands, + RL2_COMPRESSION_PNG, 100, info.tile_w, info.tile_h, info.srid, 0.1, + 0.1, no_data, NULL, 1, 0, 0, 0, 0) != RL2_OK) + { + fprintf (stderr, "Unable to create Coverage \"%s\"\n", info.coverage); + return 0; + } + + cvg = rl2_create_coverage_from_dbms (handle, info.coverage); + if (cvg == NULL) + { + rl2_destroy_coverage (cvg); + return 0; + } + + if (rl2_load_raw_tiles_into_dbms + (handle, cvg, "Alpha", 3600, 1800, info.srid, -180, -90, 180, 90, + tile_callback, &info, 1) != RL2_OK) + { + fprintf (stderr, "Unable to populate Tiles on Coverage \"%s\"\n", + info.coverage); + return 0; + } + + rl2_destroy_coverage (cvg); + rl2_destroy_pixel (no_data); + return 1; +} + +static int +test_int16_grid (sqlite3 * handle) +{ +/* testing INT8 DATAGRID */ + struct tile_info info; + rl2CoveragePtr cvg; + + info.sample = RL2_SAMPLE_INT16; + info.pixel = RL2_PIXEL_DATAGRID; + info.num_bands = 1; + info.srid = 4326; + info.coverage = "INT16_GRID"; + info.tile_w = 512; + info.tile_h = 512; + + rl2PixelPtr no_data = + default_nodata (info.sample, info.pixel, info.num_bands); + if (rl2_create_dbms_coverage + (handle, info.coverage, info.sample, info.pixel, info.num_bands, + RL2_COMPRESSION_DEFLATE, 100, info.tile_w, info.tile_h, info.srid, 0.1, + 0.1, no_data, NULL, 1, 0, 0, 0, 0) != RL2_OK) + { + fprintf (stderr, "Unable to create Coverage \"%s\"\n", info.coverage); + return 0; + } + + cvg = rl2_create_coverage_from_dbms (handle, info.coverage); + if (cvg == NULL) + { + rl2_destroy_coverage (cvg); + return 0; + } + + if (rl2_load_raw_tiles_into_dbms + (handle, cvg, "Alpha", 3600, 1800, info.srid, -180, -90, 180, 90, + tile_callback, &info, 1) != RL2_OK) + { + fprintf (stderr, "Unable to populate Tiles on Coverage \"%s\"\n", + info.coverage); + return 0; + } + + rl2_destroy_coverage (cvg); + rl2_destroy_pixel (no_data); + return 1; +} + +static int +test_double_grid (sqlite3 * handle) +{ +/* testing DOUBLE DATAGRID */ + struct tile_info info; + rl2CoveragePtr cvg; + + info.sample = RL2_SAMPLE_DOUBLE; + info.pixel = RL2_PIXEL_DATAGRID; + info.num_bands = 1; + info.srid = 4326; + info.coverage = "DOUBLE_GRID"; + info.tile_w = 512; + info.tile_h = 512; + + rl2PixelPtr no_data = + default_nodata (info.sample, info.pixel, info.num_bands); + if (rl2_create_dbms_coverage + (handle, info.coverage, info.sample, info.pixel, info.num_bands, + RL2_COMPRESSION_DEFLATE, 100, info.tile_w, info.tile_h, info.srid, 0.1, + 0.1, no_data, NULL, 1, 0, 0, 0, 0) != RL2_OK) + { + fprintf (stderr, "Unable to create Coverage \"%s\"\n", info.coverage); + return 0; + } + + cvg = rl2_create_coverage_from_dbms (handle, info.coverage); + if (cvg == NULL) + { + rl2_destroy_coverage (cvg); + return 0; + } + + if (rl2_load_raw_tiles_into_dbms + (handle, cvg, "Alpha", 3600, 1800, info.srid, -180, -90, 180, 90, + tile_callback, &info, 1) != RL2_OK) + { + fprintf (stderr, "Unable to populate Tiles on Coverage \"%s\"\n", + info.coverage); + return 0; + } + + rl2_destroy_coverage (cvg); + rl2_destroy_pixel (no_data); + return 1; +} + +int +main (int argc, char *argv[]) +{ + int ret; + sqlite3 *handle = NULL; + char *err_msg = NULL; + void *cache = spatialite_alloc_connection (); + void *priv_data = rl2_alloc_private (); + + if (argc > 1 || argv[0] == NULL) + argc = 1; /* silencing stupid compiler warnings */ + ret = + sqlite3_open_v2 ("callback.sqlite", &handle, + SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); + if (ret != SQLITE_OK) + { + fprintf (stderr, "cannot open in-memory db: %s\n", + sqlite3_errmsg (handle)); + return -1; + } + spatialite_init_ex (handle, cache, 0); + rl2_init (handle, priv_data, 0); + +/* the complete test is handled as an unique SQL Transaction */ + ret = sqlite3_exec (handle, "BEGIN", NULL, NULL, &err_msg); + if (ret != SQLITE_OK) + { + fprintf (stderr, "BEGIN TRANSACTION error: %s\n", err_msg); + sqlite3_free (err_msg); + return -2; + } + + ret = + sqlite3_exec (handle, "SELECT InitSpatialMetadata()", NULL, NULL, + &err_msg); + if (ret != SQLITE_OK) + { + fprintf (stderr, "InitSpatialMetadata() error: %s\n", err_msg); + sqlite3_free (err_msg); + sqlite3_close (handle); + return -3; + } + ret = + sqlite3_exec (handle, "SELECT CreateRasterCoveragesTable()", NULL, + NULL, &err_msg); + if (ret != SQLITE_OK) + { + fprintf (stderr, "CreateRasterCoveragesTable() error: %s\n", err_msg); + sqlite3_free (err_msg); + return -4; + } + + if (!test_uint8_gray (handle)) + return -5; + + if (!test_uint8_rgb (handle)) + return -6; + + if (!test_int16_grid (handle)) + return -7; + + if (!test_double_grid (handle)) + return -8; + +/* committing the SQL Transaction */ + ret = sqlite3_exec (handle, "COMMIT", NULL, NULL, &err_msg); + if (ret != SQLITE_OK) + { + fprintf (stderr, "COMMIT TRANSACTION error: %s\n", err_msg); + sqlite3_free (err_msg); + return -9; + } + + sqlite3_close (handle); + spatialite_cleanup_ex (cache); + rl2_cleanup_private (priv_data); + spatialite_shutdown (); + fprintf (stderr, "******** endok\n"); + return 0; +} Index: tools/Makefile.in ================================================================== --- tools/Makefile.in +++ tools/Makefile.in @@ -1,9 +1,9 @@ -# Makefile.in generated by automake 1.14.1 from Makefile.am. +# Makefile.in generated by automake 1.15 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2013 Free Software Foundation, Inc. +# Copyright (C) 1994-2014 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -13,11 +13,21 @@ # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ @@ -78,19 +88,18 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ bin_PROGRAMS = rl2sniff$(EXEEXT) rl2tool$(EXEEXT) wmslite$(EXEEXT) subdir = tools -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ - $(top_srcdir)/depcomp ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" @@ -167,10 +176,11 @@ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` ETAGS = etags CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ @@ -355,11 +365,10 @@ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu tools/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu tools/Makefile -.PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ @@ -676,10 +685,12 @@ install-pdf-am install-ps install-ps-am install-strip \ installcheck installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-compile \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags tags-am uninstall uninstall-am uninstall-binPROGRAMS + +.PRECIOUS: Makefile # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: Index: tools/rl2sniff.c ================================================================== --- tools/rl2sniff.c +++ tools/rl2sniff.c @@ -732,10 +732,11 @@ double minY; double maxX; double maxY; double x_res; double y_res; + short pixel_mode = RasterPixelIsArea; GTIFDefn definition; char *md5 = NULL; TIFF *in = (TIFF *) 0; GTIF *gtif = (GTIF *) 0; @@ -899,10 +900,23 @@ /* computing the pixel resolution */ x_res = (maxX - minX) / (double) width; y_res = (maxY - minY) / (double) height; is_geotiff = 1; + +/* retrieving GTRasterTypeGeoKey */ + if (!GTIFKeyGet (gtif, GTRasterTypeGeoKey, &pixel_mode, 0, 1)) + pixel_mode = RasterPixelIsArea; + if (pixel_mode == RasterPixelIsPoint) + { + /* adjusting the BBOX */ + minX -= x_res / 2.0; + minY -= y_res / 2.0; + maxX += x_res / 2.0; + maxY += y_res / 2.0; + + } goto print; recover: is_geotiff = recover_incomplete_geotiff (in, width, height, &minX, &minY, &maxX, Index: tools/rl2tool.c ================================================================== --- tools/rl2tool.c +++ tools/rl2tool.c @@ -1431,11 +1431,11 @@ "SELECT coverage_name, title, abstract, sample_type, pixel_type, " "num_bands, compression, quality, tile_width, tile_height, " "horz_resolution, vert_resolution, srid, auth_name, auth_srid, " "ref_sys_name, extent_minx, extent_miny, extent_maxx, extent_maxy, " "nodata_pixel, palette, statistics, red_band_index, green_band_index, " - "blue_band_index, nir_band_index, eneble_auto_ndvi " + "blue_band_index, nir_band_index, enable_auto_ndvi " "FROM raster_coverages_ref_sys ORDER BY coverage_name"; ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL); if (ret != SQLITE_OK) goto stop; @@ -1732,11 +1732,11 @@ } } if (palette != NULL) { /* printing an eventual Palette */ - unsigned char i; + unsigned short i; unsigned short num_entries; unsigned char *red = NULL; unsigned char *green = NULL; unsigned char *blue = NULL; rl2_get_palette_colors (palette, &num_entries, &red, Index: tools/wmslite.c ================================================================== --- tools/wmslite.c +++ tools/wmslite.c @@ -49,13 +49,14 @@ #include #include #define ARG_NONE 0 #define ARG_DB_PATH 1 -#define ARG_IP_PORT 2 -#define ARG_MAX_THREADS 3 -#define ARG_CACHE_SIZE 4 +#define ARG_IP_ADDR 2 +#define ARG_IP_PORT 3 +#define ARG_MAX_THREADS 4 +#define ARG_CACHE_SIZE 5 #define WMS_ILLEGAL_REQUEST 0 #define WMS_GET_CAPABILITIES 1 #define WMS_GET_MAP 2 @@ -307,10 +308,11 @@ struct http_request { /* a struct wrapping an HTTP request */ unsigned int id; /* request ID */ + const char *ip_addr; int port_no; #ifdef _WIN32 SOCKET socket; /* Socket on which to receive data */ #else int socket; /* Socket on which to receive data */ @@ -2568,11 +2570,12 @@ gaiaAppendToOutBuffer (xml_response, xml_text.Buffer); gaiaOutBufferReset (&xml_text); } static void -build_http_error (int http_status, gaiaOutBufferPtr xml_response, int port_no) +build_http_error (int http_status, gaiaOutBufferPtr xml_response, + const char *ip_addr, int port_no) { /* preparing an HTTP error */ char *dummy; gaiaOutBuffer http_text; gaiaOutBufferInitialize (&http_text); @@ -2595,14 +2598,20 @@ "500 Internal Server Error\r\n"); gaiaAppendToOutBuffer (&http_text, "\r\n"); gaiaAppendToOutBuffer (&http_text, "

Internal Server Error

\n"); } - dummy = - sqlite3_mprintf - ("
WmsLite/%s [%s] at localhost (127.0.0.1) Port %d
\r\n", - rl2_version (), rl2_target_cpu (), port_no); + if (strcmp (ip_addr, "127.0.0.1") == 0) + dummy = + sqlite3_mprintf + ("
WmsLite/%s [%s] at localhost (127.0.0.1) Port %d
\r\n", + rl2_version (), rl2_target_cpu (), port_no); + else + dummy = + sqlite3_mprintf + ("
WmsLite/%s [%s] at IP-addr %s Port %d
\r\n", + rl2_version (), rl2_target_cpu (), ip_addr, port_no); gaiaAppendToOutBuffer (&http_text, dummy); sqlite3_free (dummy); gaiaAppendToOutBuffer (&http_text, "\r\n"); gaiaAppendToOutBuffer (&http_text, ""); dummy = get_current_timestamp (); @@ -2618,11 +2627,11 @@ gaiaOutBufferReset (&http_text); } static void build_get_capabilities (struct wms_list *list, char **cached, int *cached_len, - int port_no) + const char *ip_addr, int port_no) { /* preparing the WMS GetCapabilities XML document */ struct wms_layer *lyr; struct wms_group *grp; struct wms_style *style; @@ -2645,14 +2654,19 @@ gaiaAppendToOutBuffer (&xml_text, "WmsLite test server\r\n"); gaiaAppendToOutBuffer (&xml_text, "A simple light-weight WMS server for testing RasterLite2 Coverages.\r\n"); gaiaAppendToOutBuffer (&xml_text, "\r\nmaps\r\n\r\n"); - dummy = - sqlite3_mprintf - ("\r\n"); gaiaAppendToOutBuffer (&xml_text, @@ -2684,14 +2698,20 @@ gaiaAppendToOutBuffer (&xml_text, "\r\n"); gaiaAppendToOutBuffer (&xml_text, "\r\n\r\n\r\n"); gaiaAppendToOutBuffer (&xml_text, "text/xml\r\n\r\n\r\n"); - dummy = - sqlite3_mprintf - ("\r\n"); gaiaAppendToOutBuffer (&xml_text, @@ -2700,14 +2720,19 @@ "\r\nimage/png\r\n"); gaiaAppendToOutBuffer (&xml_text, "image/jpeg\r\n"); gaiaAppendToOutBuffer (&xml_text, "application/x-pdf\r\n"); gaiaAppendToOutBuffer (&xml_text, "image/tiff\r\n"); gaiaAppendToOutBuffer (&xml_text, "\r\n\r\n"); - dummy = - sqlite3_mprintf - ("\r\n"); gaiaAppendToOutBuffer (&xml_text, @@ -3195,11 +3220,14 @@ if (args->has_bgcolor) sprintf (bgcolor, "#%02x%02x%02x", args->red, args->green, args->blue); else strcpy (bgcolor, "#ffffff"); sqlite3_bind_text (stmt, 10, bgcolor, strlen (bgcolor), SQLITE_TRANSIENT); - sqlite3_bind_int (stmt, 11, args->transparent); + if (args->transparent == WMS_OPAQUE) + sqlite3_bind_int (stmt, 11, 0); + else + sqlite3_bind_int (stmt, 11, 1); if (args->format == RL2_OUTPUT_FORMAT_JPEG) sqlite3_bind_int (stmt, 12, 80); else sqlite3_bind_int (stmt, 12, 100); while (1) @@ -3401,20 +3429,21 @@ } if (args->request_type == WMS_GET_MAP) { /* preparing the WMS GetMap payload */ args->db_handle = req->conn->handle; - args->stmt_get_map = req->conn->stmt_get_map; + args->stmt_get_map_raster = req->conn->stmt_get_map_raster; + args->stmt_get_map_vector = req->conn->stmt_get_map_vector; log_get_map_1 (req->log, timestamp, http_status, method, url, args); wms_get_map (args, req->socket, req->log); } goto end_request; /* preparing an HTTP error code */ http_error: gaiaOutBufferInitialize (&xml_response); - build_http_error (http_status, &xml_response, req->port_no); + build_http_error (http_status, &xml_response, req->ip_addr, req->port_no); curr = 0; while (1) { rd = get_xml_bytes (&xml_response, curr, SEND_BLOK_SZ); if (rd == 0) @@ -3522,11 +3551,11 @@ goto end_request; /* preparing an HTTP error code */ http_error: gaiaOutBufferInitialize (&xml_response); - build_http_error (http_status, &xml_response, req->port_no); + build_http_error (http_status, &xml_response, req->ip_addr, req->port_no); curr = 0; while (1) { rd = get_xml_bytes (&xml_response, curr, SEND_BLOK_SZ); if (rd == 0) @@ -3565,14 +3594,15 @@ pthread_exit (NULL); } #endif static void -do_accept_loop (struct neutral_socket *skt, struct wms_list *list, int port_no, - sqlite3 * db_handle, sqlite3_stmt * stmt_log, - struct connections_pool *pool, struct server_log *log, - char *cached_capab, int cached_capab_len) +do_accept_loop (struct neutral_socket *skt, struct wms_list *list, + const char *xip_addr, int port_no, sqlite3 * db_handle, + sqlite3_stmt * stmt_log, struct connections_pool *pool, + struct server_log *log, char *cached_capab, + int cached_capab_len) { /* implementing the ACCEPT loop */ unsigned int id = 0; struct read_connection *conn; int ic; @@ -3609,10 +3639,11 @@ return; } } req = malloc (sizeof (struct http_request)); req->id = id++; + req->ip_addr = xip_addr; req->port_no = port_no; req->socket = client; req->list = list; req->cached_capabilities = cached_capab; req->cached_capabilities_len = cached_capab_len; @@ -3694,10 +3725,11 @@ fprintf (stderr, "error from accept()\n"); return; } req = malloc (sizeof (struct http_request)); req->id = id++; + req->ip_addr = xip_addr; req->port_no = port_no; req->socket = client; req->list = list; req->cached_capabilities = cached_capab; req->cached_capabilities_len = cached_capab_len; @@ -3763,11 +3795,12 @@ } #endif } static int -do_start_http (int port_no, struct neutral_socket *srv_skt, int max_threads) +do_start_http (const char *ip_addr, int port_no, struct neutral_socket *srv_skt, + int max_threads) { /* starting the HTTP server */ #ifdef _WIN32 /* Winsockets */ WSADATA wd; @@ -3785,11 +3818,11 @@ fprintf (stderr, "unable to create a socket\n"); return 0; } addr.sin_family = AF_INET; addr.sin_port = htons (port_no); - addr.sin_addr.s_addr = inet_addr ("127.0.0.1"); + addr.sin_addr.s_addr = inet_addr (ip_addr); if (bind (skt, (struct sockaddr *) &addr, sizeof (addr)) == SOCKET_ERROR) { fprintf (stderr, "unable to bind the socket\n"); closesocket (skt); return 0; @@ -3812,11 +3845,12 @@ fprintf (stderr, "unable to create a socket\n"); return 0; } addr.sin_family = AF_INET; addr.sin_port = htons (port_no); - addr.sin_addr.s_addr = htonl (INADDR_ANY); + //addr.sin_addr.s_addr = htonl (INADDR_ANY); + addr.sin_addr.s_addr = inet_addr (ip_addr); if (bind (skt, (struct sockaddr *) &addr, sizeof (addr)) == -1) { fprintf (stderr, "unable to bind the socket\n"); close (skt); return 0; @@ -4442,11 +4476,11 @@ { /* retrieving all declared Raster Styles */ int ret; sqlite3_stmt *stmt; const char *sql = "SELECT coverage_name, name, title, abstract " - "FROM SE_raster_styled_layers_view ORDER BY coverage_name, style_id"; + "FROM SE_raster_styled_layers_view ORDER BY coverage_name, name"; ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL); if (ret != SQLITE_OK) return; while (1) { @@ -4477,11 +4511,11 @@ { /* retrieving all declared Vector Styles */ int ret; sqlite3_stmt *stmt; const char *sql = "SELECT coverage_name, name, title, abstract " - "FROM SE_vector_styled_layers_view ORDER BY coverage_name, style_id"; + "FROM SE_vector_styled_layers_view ORDER BY coverage_name, name"; ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL); if (ret != SQLITE_OK) return; while (1) { @@ -4748,10 +4782,12 @@ fprintf (stderr, "\n\nusage: wmslite ARGLIST ]\n"); fprintf (stderr, "==============================================================\n"); fprintf (stderr, "-db or --db-path pathname RasterLite2 DB path\n"); fprintf (stderr, + "-ip or --ip-addr ip-address IP address [default: 127.0.0.1]\n\n"); + fprintf (stderr, "-p or --ip-port number IP port number [default: 8080]\n\n"); fprintf (stderr, "-mt or --max-threads num max number of concurrent threads\n"); fprintf (stderr, "-cs or --cache-size num DB cache size (how many pages)\n"); @@ -4770,10 +4806,11 @@ int ret; int i; int error = 0; int next_arg = ARG_NONE; const char *db_path = NULL; + const char *ip_addr = "127.0.0.1"; int port_no = 8080; int cache_size = 0; void *cache; void *priv_data; struct wms_list *list = NULL; @@ -4807,10 +4844,13 @@ switch (next_arg) { case ARG_DB_PATH: db_path = argv[i]; break; + case ARG_IP_ADDR: + ip_addr = argv[i]; + break; case ARG_IP_PORT: port_no = atoi (argv[i]); break; case ARG_CACHE_SIZE: cache_size = atoi (argv[i]); @@ -4832,10 +4872,16 @@ if (strcmp (argv[i], "-db") == 0 || strcasecmp (argv[i], "--db-path") == 0) { next_arg = ARG_DB_PATH; continue; + } + if (strcmp (argv[i], "-ip") == 0 + || strcasecmp (argv[i], "--ip-addr") == 0) + { + next_arg = ARG_IP_ADDR; + continue; } if (strcmp (argv[i], "-p") == 0 || strcasecmp (argv[i], "--ip-port") == 0) { next_arg = ARG_IP_PORT; @@ -4934,11 +4980,11 @@ get_raster_keywords (handle, list); get_vector_keywords (handle, list); glob.list = list; complete_layer_config (handle, list); build_get_capabilities (list, &cached_capabilities, - &cached_capabilities_len, port_no); + &cached_capabilities_len, ip_addr, port_no); glob.cached_capabilities = cached_capabilities; /* creating the read connections pool */ pool = alloc_connections_pool (db_path, max_threads); if (pool == NULL) @@ -4956,11 +5002,11 @@ goto stop; } glob.log = log; /* starting the HTTP server */ - if (!do_start_http (port_no, &skt_ptr, max_threads)) + if (!do_start_http (ip_addr, port_no, &skt_ptr, max_threads)) goto stop; /* starting the logging facility */ sql = "CREATE TABLE IF NOT EXISTS wms_server_log (\n" "\tid INTEGER PRIMARY KEY AUTOINCREMENT,\n" @@ -5001,15 +5047,15 @@ goto stop; } glob.stmt_log = stmt_log; /* looping on requests */ - do_accept_loop (&skt_ptr, list, port_no, handle, stmt_log, pool, log, - cached_capabilities, cached_capabilities_len); + do_accept_loop (&skt_ptr, list, ip_addr, port_no, handle, stmt_log, pool, + log, cached_capabilities, cached_capabilities_len); stop: destroy_wms_list (list); list = NULL; glob.list = NULL; clean_shutdown (); return 0; }